42
42
class ChooserListViewItem : public QTreeWidgetItem {
44
ChooserListViewItem( QTreeWidget *parent, int _id, const QString &nam, const QString &sts )
45
: QTreeWidgetItem( parent, QStringList() << nam << sts ) { id = _id; }
44
ChooserListViewItem(QTreeWidget *parent, int _id, const QString &nam, const QString &sts)
45
: QTreeWidgetItem(parent, QStringList() << nam << sts) { id = _id; }
51
51
ChooserDlg::ChooserDlg()
54
completeMenu( LOGIN_REMOTE_ONLY, ex_greet, i18nc("@action:inmenu", "&Local Login"), Qt::ALT+Qt::Key_L );
56
QBoxLayout *vbox = new QVBoxLayout( this );
58
QLabel *title = new QLabel( i18n("XDMCP Host Menu"), this );
59
title->setAlignment( Qt::AlignCenter );
60
vbox->addWidget( title );
62
host_view = new QTreeWidget( this );
63
host_view->setRootIsDecorated( false );
64
host_view->setUniformRowHeights( true );
65
host_view->setEditTriggers( QAbstractItemView::NoEditTriggers );
66
host_view->setColumnCount( 2 );
67
host_view->setHeaderLabels( QStringList()
68
<< i18nc("@title:column", "Hostname")
69
<< i18nc("@title:column ... of named host", "Status") );
70
host_view->setColumnWidth( 0, fontMetrics().width( "login.domain.com" ) );
71
host_view->setMinimumWidth( fontMetrics().width( "login.domain.com Display not authorized to connect this server" ) );
72
host_view->setAllColumnsShowFocus( true );
73
vbox->addWidget( host_view );
75
iline = new QLineEdit( this );
76
iline->setEnabled( true );
77
QLabel *itxt = new QLabel( i18nc("XDMCP server", "Hos&t:"), this );
78
itxt->setBuddy( iline );
79
QPushButton *addButton = new QPushButton( i18nc("@action:button", "A&dd"), this );
80
connect( addButton, SIGNAL(clicked()), SLOT(addHostname()) );
81
QBoxLayout *hibox = new QHBoxLayout();
82
vbox->addLayout( hibox );
83
hibox->addWidget( itxt );
84
hibox->addWidget( iline );
85
hibox->addWidget( addButton );
88
QPushButton *acceptButton = new QPushButton( i18nc("@action:button", "&Accept"), this );
89
acceptButton->setDefault( true );
90
QPushButton *pingButton = new QPushButton( i18nc("@action:button", "&Refresh"), this );
92
QBoxLayout *hbox = new QHBoxLayout();
93
vbox->addLayout( hbox );
94
hbox->setSpacing( 20 );
95
hbox->addWidget( acceptButton );
96
hbox->addWidget( pingButton );
97
hbox->addStretch( 1 );
100
QPushButton *menuButton = new QPushButton( i18nc("@action:button", "&Menu"), this );
101
menuButton->setMenu( optMenu );
102
hbox->addWidget( menuButton );
103
hbox->addStretch( 1 );
106
// QPushButton *helpButton = new QPushButton( i18nc("@action:button", "&Help"), this );
107
// hbox->addWidget( helpButton );
54
completeMenu(LOGIN_REMOTE_ONLY, ex_greet, i18nc("@action:inmenu", "&Local Login"), Qt::ALT + Qt::Key_L);
56
QBoxLayout *vbox = new QVBoxLayout(this);
58
QLabel *title = new QLabel(i18n("XDMCP Host Menu"), this);
59
title->setAlignment(Qt::AlignCenter);
60
vbox->addWidget(title);
62
host_view = new QTreeWidget(this);
63
host_view->setRootIsDecorated(false);
64
host_view->setUniformRowHeights(true);
65
host_view->setEditTriggers(QAbstractItemView::NoEditTriggers);
66
host_view->setColumnCount(2);
67
host_view->setHeaderLabels(QStringList()
68
<< i18nc("@title:column", "Hostname")
69
<< i18nc("@title:column ... of named host", "Status"));
70
host_view->setColumnWidth(0, fontMetrics().width("login.domain.com"));
71
host_view->setMinimumWidth(fontMetrics().width("login.domain.com Display not authorized to connect this server"));
72
host_view->setAllColumnsShowFocus(true);
73
vbox->addWidget(host_view);
75
iline = new QLineEdit(this);
76
iline->setEnabled(true);
77
QLabel *itxt = new QLabel(i18nc("XDMCP server", "Hos&t:"), this);
78
itxt->setBuddy(iline);
79
QPushButton *addButton = new QPushButton(i18nc("@action:button", "A&dd"), this);
80
connect(addButton, SIGNAL(clicked()), SLOT(addHostname()));
81
QBoxLayout *hibox = new QHBoxLayout();
82
vbox->addLayout(hibox);
83
hibox->addWidget(itxt);
84
hibox->addWidget(iline);
85
hibox->addWidget(addButton);
88
QPushButton *acceptButton = new QPushButton(i18nc("@action:button", "&Accept"), this);
89
acceptButton->setDefault(true);
90
QPushButton *pingButton = new QPushButton(i18nc("@action:button", "&Refresh"), this);
92
QBoxLayout *hbox = new QHBoxLayout();
93
vbox->addLayout(hbox);
95
hbox->addWidget(acceptButton);
96
hbox->addWidget(pingButton);
100
QPushButton *menuButton = new QPushButton(i18nc("@action:button", "&Menu"), this);
101
menuButton->setMenu(optMenu);
102
hbox->addWidget(menuButton);
106
// QPushButton *helpButton = new QPushButton(i18nc("@action:button", "&Help"), this);
107
// hbox->addWidget(helpButton);
109
109
#ifdef WITH_KDM_XCONSOLE
111
vbox->addWidget( consoleView );
111
vbox->addWidget(consoleView);
114
sn = new QSocketNotifier( rfd, QSocketNotifier::Read, this );
115
connect( sn, SIGNAL(activated( int )), SLOT(slotReadPipe()) );
114
sn = new QSocketNotifier(rfd, QSocketNotifier::Read, this);
115
connect(sn, SIGNAL(activated(int)), SLOT(slotReadPipe()));
117
connect( pingButton, SIGNAL(clicked()), SLOT(pingHosts()) );
118
connect( acceptButton, SIGNAL(clicked()), SLOT(accept()) );
119
// connect( helpButton, SIGNAL(clicked()), SLOT(slotHelp()) );
120
connect( host_view, SIGNAL(itemActivated( QTreeWidgetItem *, int )), SLOT(accept()) );
117
connect(pingButton, SIGNAL(clicked()), SLOT(pingHosts()));
118
connect(acceptButton, SIGNAL(clicked()), SLOT(accept()));
119
// connect(helpButton, SIGNAL(clicked()), SLOT(slotHelp()));
120
connect(host_view, SIGNAL(itemActivated(QTreeWidgetItem *, int)), SLOT(accept()));
124
124
void ChooserDlg::slotHelp()
126
KMessageBox::information( 0,
127
i18n("Choose a host, you want to work on,\n"
128
"in the list or add one.\n\n"
129
"After this box, you must press cancel\n"
130
"in the Host Menu to enter a host. :("));
126
KMessageBox::information(0,
127
i18n("Choose a host, you want to work on,\n"
128
"in the list or add one.\n\n"
129
"After this box, you must press cancel\n"
130
"in the Host Menu to enter a host. :("));
135
135
void ChooserDlg::addHostname()
137
if (!iline->text().isEmpty()) {
138
gSendInt( G_Ch_RegisterHost );
139
gSendStr( iline->text().toLatin1() );
137
if (!iline->text().isEmpty()) {
138
gSendInt(G_Ch_RegisterHost);
139
gSendStr(iline->text().toLatin1());
144
144
void ChooserDlg::pingHosts()
146
gSendInt( G_Ch_Refresh );
146
gSendInt(G_Ch_Refresh);
149
149
void ChooserDlg::accept()
151
if (focusWidget() == iline) {
152
if (!iline->text().isEmpty()) {
153
gSendInt( G_Ch_DirectChoice );
154
gSendStr( iline->text().toLatin1() );
158
} else /*if (focusWidget() == host_view)*/ {
159
QTreeWidgetItem *item = host_view->currentItem();
162
gSendInt( ((ChooserListViewItem *)item)->id );
151
if (focusWidget() == iline) {
152
if (!iline->text().isEmpty()) {
153
gSendInt(G_Ch_DirectChoice);
154
gSendStr(iline->text().toLatin1());
158
} else /*if (focusWidget() == host_view)*/ {
159
QTreeWidgetItem *item = host_view->currentItem();
162
gSendInt(((ChooserListViewItem *)item)->id);
168
168
void ChooserDlg::reject()
172
172
QString ChooserDlg::recvStr()
174
char *arr = gRecvStr();
176
QString str = QString::fromLatin1( arr );
180
return i18nc("hostname or status", "<unknown>"); //krazy:exclude=i18ncheckarg
174
char *arr = gRecvStr();
176
QString str = QString::fromLatin1(arr);
180
return i18nc("hostname or status", "<unknown>"); //krazy:exclude=i18ncheckarg
183
ChooserListViewItem *ChooserDlg::findItem( int id )
183
ChooserListViewItem *ChooserDlg::findItem(int id)
185
for (int i = 0, rc = host_view->model()->rowCount(); i < rc; i++) {
186
ChooserListViewItem *itm = static_cast<ChooserListViewItem *>(
187
host_view->topLevelItem( i ));
185
for (int i = 0, rc = host_view->model()->rowCount(); i < rc; i++) {
186
ChooserListViewItem *itm = static_cast<ChooserListViewItem *>(
187
host_view->topLevelItem(i));
194
194
void ChooserDlg::slotReadPipe()
199
int cmd = gRecvInt();
202
case G_Ch_ChangeHost:
206
gRecvInt(); /* swallow willing for now */
207
if (cmd == G_Ch_AddHost)
208
new ChooserListViewItem( host_view, id, nam, sts );
210
QTreeWidgetItem *itm = findItem( id );
211
itm->setText( 0, nam );
212
itm->setText( 1, sts );
215
case G_Ch_RemoveHost:
216
delete findItem( gRecvInt() );
219
KFMsgBox::box( this, QMessageBox::Warning, i18n("Unknown host %1", recvStr() ) );
224
default: /* XXX huuh ...? */
199
int cmd = gRecvInt();
202
case G_Ch_ChangeHost:
206
gRecvInt(); /* swallow willing for now */
207
if (cmd == G_Ch_AddHost) {
208
new ChooserListViewItem(host_view, id, nam, sts);
210
QTreeWidgetItem *itm = findItem(id);
211
itm->setText(0, nam);
212
itm->setText(1, sts);
215
case G_Ch_RemoveHost:
216
delete findItem(gRecvInt());
219
KFMsgBox::box(this, QMessageBox::Warning, i18n("Unknown host %1", recvStr()));
224
default: /* XXX huuh ...? */
229
229
#include "kchooser.moc"