• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

knotes

  • sources
  • kde-4.12
  • kdepim
  • knotes
  • network
knotehostdialog.cpp
Go to the documentation of this file.
1 /*******************************************************************
2  KNotes -- Notes for the KDE project
3 
4  Copyright (c) 2003, Daniel Martin <daniel.martin@pirack.com>
5  2004, Michael Brade <brade@kde.org>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License
9  as published by the Free Software Foundation; either version 2
10  of the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 
21  In addition, as a special exception, the copyright holders give
22  permission to link the code of this program with any edition of
23  the Qt library by Trolltech AS, Norway (or with modified versions
24  of Qt that use the same license as Qt), and distribute linked
25  combinations including the two. You must obey the GNU General
26  Public License in all respects for all of the code used other than
27  Qt. If you modify this file, you may extend this exception to
28  your version of the file, but you are not obligated to do so. If
29  you do not wish to do so, delete this exception statement from
30  your version.
31 *******************************************************************/
32 
33 #include "knotehostdialog.h"
34 #include "knotesglobalconfig.h"
35 
36 #include <kconfig.h>
37 #include <kdebug.h>
38 #include <kglobal.h>
39 #include <khistorycombobox.h>
40 #include <klocale.h>
41 #include <kstandarddirs.h>
42 #include <kvbox.h>
43 #include <dnssd/servicemodel.h>
44 #include <dnssd/servicebrowser.h>
45 
46 #include <QLabel>
47 #include <QString>
48 #include <QLineEdit>
49 #include <QTableView>
50 #include <QSortFilterProxyModel>
51 #include <QHeaderView>
52 
53 
54 KNoteHostDialog::KNoteHostDialog( const QString &caption, QWidget *parent )
55  : KDialog( parent )
56 {
57  setCaption( caption );
58  setButtons( Ok|Cancel );
59  KVBox *page = new KVBox( this );
60  setMainWidget( page );
61  ( void ) new QLabel( i18n("Select recipient:"), page );
62 
63  m_servicesView = new QTableView( page );
64  m_servicesView->setShowGrid( false );
65  DNSSD::ServiceModel* mdl = new DNSSD::ServiceModel( new DNSSD::ServiceBrowser( QLatin1String("_knotes._tcp"), true ), this );
66  m_servicesView->setModel( mdl );
67  m_servicesView->setSelectionBehavior( QAbstractItemView::SelectRows );
68  m_servicesView->hideColumn( DNSSD::ServiceModel::Port );
69  connect( m_servicesView->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)),
70  SLOT(serviceSelected(QModelIndex)) );
71  connect( m_servicesView, SIGNAL(activated(QModelIndex)),
72  SLOT(serviceSelected(QModelIndex)) );
73  connect( m_servicesView, SIGNAL(clicked(QModelIndex)),
74  SLOT(serviceSelected(QModelIndex)) );
75 
76  ( void ) new QLabel( i18n("Hostname or IP address:"), page );
77 
78  m_hostCombo = new KHistoryComboBox( true, page );
79  m_hostCombo->setMinimumWidth( fontMetrics().maxWidth() * 15 );
80  m_hostCombo->setDuplicatesEnabled( false );
81 
82  // Read known hosts from configfile
83  m_hostCombo->setHistoryItems( KNotesGlobalConfig::knownHosts(), true );
84  m_hostCombo->setFocus();
85  connect( m_hostCombo->lineEdit(), SIGNAL(textChanged(QString)),
86  this, SLOT(slotTextChanged(QString)) );
87  slotTextChanged( m_hostCombo->lineEdit()->text() );
88  readConfig();
89 }
90 
91 KNoteHostDialog::~KNoteHostDialog()
92 {
93  if ( result() == Accepted ) {
94  m_hostCombo->addToHistory( m_hostCombo->currentText().trimmed() );
95  }
96 
97  // Write known hosts to configfile
98  KNotesGlobalConfig::setKnownHosts( m_hostCombo->historyItems() );
99  KNotesGlobalConfig::setNoteHostDialogSize(size());
100  KNotesGlobalConfig::self()->writeConfig();
101 }
102 
103 void KNoteHostDialog::readConfig()
104 {
105  const QSize size = KNotesGlobalConfig::noteHostDialogSize();
106  if ( size.isValid() ) {
107  resize( size );
108  }
109 }
110 
111 void KNoteHostDialog::slotTextChanged( const QString &text )
112 {
113  enableButton( Ok, !text.isEmpty() );
114 }
115 
116 void KNoteHostDialog::serviceSelected( const QModelIndex& idx )
117 {
118  DNSSD::RemoteService::Ptr srv=idx.data( DNSSD::ServiceModel::ServicePtrRole ).value<DNSSD::RemoteService::Ptr>();
119  m_hostCombo->lineEdit()->setText( srv->hostName() + QLatin1String(":") + QString::number( srv->port() ) );
120 }
121 
122 QString KNoteHostDialog::host() const
123 {
124  return m_hostCombo->currentText().section( QLatin1Char(':'), 0, 0 );
125 }
126 
127 quint16 KNoteHostDialog::port() const
128 {
129  return m_hostCombo->currentText().section( QLatin1Char(':'), 1 ).toUShort();
130 }
131 
132 #include "knotehostdialog.moc"
knotehostdialog.h
QWidget
KDialog
KNoteHostDialog::~KNoteHostDialog
~KNoteHostDialog()
Definition: knotehostdialog.cpp:91
KNoteHostDialog::host
QString host() const
Definition: knotehostdialog.cpp:122
KNoteHostDialog::port
quint16 port() const
Returns 0 if port was not specified.
Definition: knotehostdialog.cpp:127
KNoteHostDialog::KNoteHostDialog
KNoteHostDialog(const QString &caption, QWidget *parent=0)
Definition: knotehostdialog.cpp:54
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:56:33 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

knotes

Skip menu "knotes"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal