34 #include "knotesglobalconfig.h"
39 #include <khistorycombobox.h>
41 #include <kstandarddirs.h>
43 #include <dnssd/servicemodel.h>
44 #include <dnssd/servicebrowser.h>
50 #include <QSortFilterProxyModel>
51 #include <QHeaderView>
57 setCaption( caption );
58 setButtons( Ok|Cancel );
59 KVBox *page =
new KVBox(
this );
60 setMainWidget( page );
61 ( void )
new QLabel( i18n(
"Select recipient:"), page );
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)) );
76 ( void )
new QLabel( i18n(
"Hostname or IP address:"), page );
78 m_hostCombo =
new KHistoryComboBox(
true, page );
79 m_hostCombo->setMinimumWidth( fontMetrics().maxWidth() * 15 );
80 m_hostCombo->setDuplicatesEnabled(
false );
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() );
93 if ( result() == Accepted ) {
94 m_hostCombo->addToHistory( m_hostCombo->currentText().trimmed() );
98 KNotesGlobalConfig::setKnownHosts( m_hostCombo->historyItems() );
99 KNotesGlobalConfig::setNoteHostDialogSize(size());
100 KNotesGlobalConfig::self()->writeConfig();
103 void KNoteHostDialog::readConfig()
105 const QSize size = KNotesGlobalConfig::noteHostDialogSize();
106 if ( size.isValid() ) {
111 void KNoteHostDialog::slotTextChanged(
const QString &text )
113 enableButton( Ok, !text.isEmpty() );
116 void KNoteHostDialog::serviceSelected(
const QModelIndex& idx )
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() ) );
124 return m_hostCombo->currentText().section( QLatin1Char(
':'), 0, 0 );
129 return m_hostCombo->currentText().section( QLatin1Char(
':'), 1 ).toUShort();
132 #include "knotehostdialog.moc"
quint16 port() const
Returns 0 if port was not specified.
KNoteHostDialog(const QString &caption, QWidget *parent=0)