5
Copyright (C) 2002-2003 Oswald Buddenhagen <ossi@kde.org>
6
based on the chooser (C) 1999 by Harald Hoyer <Harald.Hoyer@RedHat.de>
8
This program is free software; you can redistribute it and/or modify
9
it under the terms of the GNU General Public License as published by
10
the Free Software Foundation; either version 2 of the License, or
11
(at your option) any later version.
13
This program is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
GNU General Public License for more details.
18
You should have received a copy of the GNU General Public License
19
along with this program; if not, write to the Free Software
20
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26
#include "kdmconfig.h"
27
#include "kdm_greet.h"
31
#include <QApplication>
34
#include <QPushButton>
35
#include <QSocketNotifier>
36
#include <QTreeWidget>
37
#include <QTreeWidgetItem>
38
#include <QHBoxLayout>
39
#include <QVBoxLayout>
41
#include <stdlib.h> // for free()
43
#define CHOOSE_TO 20 // inactivity timeout for reserve displays
44
#define SECONDS 1000 // reduce to 100 to speed up testing
47
class ChooserListViewItem : public QTreeWidgetItem {
49
ChooserListViewItem(QTreeWidget *parent, int _id, const QString &nam, const QString &sts)
50
: QTreeWidgetItem(parent, QStringList() << nam << sts) { id = _id; }
56
ChooserDlg::ChooserDlg()
59
completeMenu(LOGIN_REMOTE_ONLY, ex_greet, i18nc("@action:inmenu", "&Local Login"), Qt::ALT + Qt::Key_L);
61
QBoxLayout *vbox = new QVBoxLayout(this);
63
QLabel *title = new QLabel(i18n("XDMCP Host Menu"), this);
64
title->setAlignment(Qt::AlignCenter);
65
vbox->addWidget(title);
67
host_view = new QTreeWidget(this);
68
host_view->setRootIsDecorated(false);
69
host_view->setUniformRowHeights(true);
70
host_view->setEditTriggers(QAbstractItemView::NoEditTriggers);
71
host_view->setColumnCount(2);
72
host_view->setHeaderLabels(QStringList()
73
<< i18nc("@title:column", "Hostname")
74
<< i18nc("@title:column ... of named host", "Status"));
75
host_view->setColumnWidth(0, fontMetrics().width("login.domain.com"));
76
host_view->setMinimumWidth(fontMetrics().width("login.domain.com Display not authorized to connect this server"));
77
host_view->setAllColumnsShowFocus(true);
78
vbox->addWidget(host_view);
80
iline = new QLineEdit(this);
81
iline->setEnabled(true);
82
QLabel *itxt = new QLabel(i18nc("XDMCP server", "Hos&t:"), this);
83
itxt->setBuddy(iline);
84
QPushButton *addButton = new QPushButton(i18nc("@action:button", "A&dd"), this);
85
connect(addButton, SIGNAL(clicked()), SLOT(addHostname()));
86
QBoxLayout *hibox = new QHBoxLayout();
87
vbox->addLayout(hibox);
88
hibox->addWidget(itxt);
89
hibox->addWidget(iline);
90
hibox->addWidget(addButton);
93
QPushButton *acceptButton = new QPushButton(i18nc("@action:button", "&Accept"), this);
94
acceptButton->setDefault(true);
95
QPushButton *pingButton = new QPushButton(i18nc("@action:button", "&Refresh"), this);
97
QBoxLayout *hbox = new QHBoxLayout();
98
vbox->addLayout(hbox);
100
hbox->addWidget(acceptButton);
101
hbox->addWidget(pingButton);
105
QPushButton *menuButton = new QPushButton(i18nc("@action:button", "&Menu"), this);
106
menuButton->setMenu(optMenu);
107
hbox->addWidget(menuButton);
111
// QPushButton *helpButton = new QPushButton(i18nc("@action:button", "&Help"), this);
112
// hbox->addWidget(helpButton);
114
#ifdef WITH_KDM_XCONSOLE
116
vbox->addWidget(consoleView);
119
sn = new QSocketNotifier(rfd, QSocketNotifier::Read, this);
120
connect(sn, SIGNAL(activated(int)), SLOT(slotReadPipe()));
122
connect(pingButton, SIGNAL(clicked()), SLOT(pingHosts()));
123
connect(acceptButton, SIGNAL(clicked()), SLOT(accept()));
124
// connect(helpButton, SIGNAL(clicked()), SLOT(slotHelp()));
125
connect(host_view, SIGNAL(itemActivated(QTreeWidgetItem *, int)), SLOT(accept()));
128
connect(&timer, SIGNAL(timeout()), SLOT(slotTimeout()));
129
connect(qApp, SIGNAL(activity()), SLOT(slotActivity()));
135
ChooserDlg::slotTimeout()
141
ChooserDlg::slotActivity()
143
timer.start(CHOOSE_TO * SECONDS);
147
void ChooserDlg::slotHelp()
149
KMessageBox::information(0,
150
i18n("Choose a host, you want to work on,\n"
151
"in the list or add one.\n\n"
152
"After this box, you must press cancel\n"
153
"in the Host Menu to enter a host. :("));
158
void ChooserDlg::addHostname()
160
if (!iline->text().isEmpty()) {
161
gSendInt(G_Ch_RegisterHost);
162
gSendStr(iline->text().toLatin1());
167
void ChooserDlg::pingHosts()
169
gSendInt(G_Ch_Refresh);
172
void ChooserDlg::accept()
174
if (focusWidget() == iline) {
175
if (!iline->text().isEmpty()) {
176
gSendInt(G_Ch_DirectChoice);
177
gSendStr(iline->text().toLatin1());
181
} else /*if (focusWidget() == host_view)*/ {
182
QTreeWidgetItem *item = host_view->currentItem();
185
gSendInt(((ChooserListViewItem *)item)->id);
191
void ChooserDlg::reject()
195
QString ChooserDlg::recvStr()
197
char *arr = gRecvStr();
199
QString str = QString::fromLatin1(arr);
203
return i18nc("hostname or status", "<unknown>"); //krazy:exclude=i18ncheckarg
206
ChooserListViewItem *ChooserDlg::findItem(int id)
208
for (int i = 0, rc = host_view->model()->rowCount(); i < rc; i++) {
209
ChooserListViewItem *itm = static_cast<ChooserListViewItem *>(
210
host_view->topLevelItem(i));
217
void ChooserDlg::slotReadPipe()
222
int cmd = gRecvInt();
225
case G_Ch_ChangeHost:
229
gRecvInt(); /* swallow willing for now */
230
if (cmd == G_Ch_AddHost) {
231
new ChooserListViewItem(host_view, id, nam, sts);
233
QTreeWidgetItem *itm = findItem(id);
234
itm->setText(0, nam);
235
itm->setText(1, sts);
238
case G_Ch_RemoveHost:
239
delete findItem(gRecvInt());
242
KFMsgBox::box(this, QMessageBox::Warning, i18n("Unknown host %1", recvStr()));
247
default: /* XXX huuh ...? */
252
#include "kchooser.moc"