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"
33
#include <QPushButton>
34
#include <QSocketNotifier>
35
#include <QTreeWidget>
36
#include <QTreeWidgetItem>
37
#include <QHBoxLayout>
38
#include <QVBoxLayout>
40
#include <stdlib.h> // for free()
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; }
51
ChooserDlg::ChooserDlg()
54
completeMenu( LOGIN_REMOTE_ONLY, ex_greet, i18n("&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() << i18n("Hostname") << i18n("Status") );
68
host_view->setColumnWidth( 0, fontMetrics().width( "login.crap.net" ) );
69
host_view->setMinimumWidth( fontMetrics().width( "login.crap.com Display not authorized to connect this server" ) );
70
host_view->setAllColumnsShowFocus( true );
71
vbox->addWidget( host_view );
73
iline = new QLineEdit( this );
74
iline->setEnabled( true );
75
QLabel *itxt = new QLabel( i18n("Hos&t:"), this );
76
itxt->setBuddy( iline );
77
QPushButton *addButton = new QPushButton( i18n("A&dd"), this );
78
connect( addButton, SIGNAL(clicked()), SLOT(addHostname()) );
79
QBoxLayout *hibox = new QHBoxLayout();
80
vbox->addLayout( hibox );
81
hibox->setParent( vbox );
82
hibox->addWidget( itxt );
83
hibox->addWidget( iline );
84
hibox->addWidget( addButton );
87
QPushButton *acceptButton = new QPushButton( i18n("&Accept"), this );
88
acceptButton->setDefault( true );
89
QPushButton *pingButton = new QPushButton( i18n("&Refresh"), this );
91
QBoxLayout *hbox = new QHBoxLayout();
92
vbox->addLayout( hbox );
93
hbox->setParent( vbox );
94
hbox->setSpacing( 20 );
95
hbox->addWidget( acceptButton );
96
hbox->addWidget( pingButton );
97
hbox->addStretch( 1 );
100
QPushButton *menuButton = new QPushButton( i18n("&Menu"), this );
101
menuButton->setMenu( optMenu );
102
hbox->addWidget( menuButton );
103
hbox->addStretch( 1 );
106
// QPushButton *helpButton = new QPushButton( i18n("&Help"), this );
107
// hbox->addWidget( helpButton );
109
#ifdef WITH_KDM_XCONSOLE
111
vbox->addWidget( consoleView );
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()) );
126
void ChooserDlg::slotHelp()
128
KMessageBox::information( 0,
129
i18n("Choose a host, you want to work on,\n"
130
"in the list or add one.\n\n"
131
"After this box, you must press cancel\n"
132
"in the Host Menu to enter a host. :("));
137
void ChooserDlg::addHostname()
139
if (!iline->text().isEmpty()) {
140
gSendInt( G_Ch_RegisterHost );
141
gSendStr( iline->text().toLatin1() );
146
void ChooserDlg::pingHosts()
148
gSendInt( G_Ch_Refresh );
151
void ChooserDlg::accept()
153
if (focusWidget() == iline) {
154
if (!iline->text().isEmpty()) {
155
gSendInt( G_Ch_DirectChoice );
156
gSendStr( iline->text().toLatin1() );
160
} else /*if (focusWidget() == host_view)*/ {
161
QTreeWidgetItem *item = host_view->currentItem();
164
gSendInt( ((ChooserListViewItem *)item)->id );
170
void ChooserDlg::reject()
174
QString ChooserDlg::recvStr()
176
char *arr = gRecvStr();
178
QString str = QString::fromLatin1( arr );
182
return i18n("<unknown>"); //krazy:exclude=i18ncheckarg
185
ChooserListViewItem *ChooserDlg::findItem( int id )
187
for (int i = 0, rc = host_view->model()->rowCount(); i < rc; i++) {
188
ChooserListViewItem *itm = static_cast<ChooserListViewItem *>(
189
host_view->topLevelItem( i ));
196
void ChooserDlg::slotReadPipe()
201
int cmd = gRecvInt();
204
case G_Ch_ChangeHost:
208
gRecvInt(); /* swallow willing for now */
209
if (cmd == G_Ch_AddHost)
210
new ChooserListViewItem( host_view, id, nam, sts );
212
QTreeWidgetItem *itm = findItem( id );
213
itm->setText( 0, nam );
214
itm->setText( 1, sts );
217
case G_Ch_RemoveHost:
218
delete findItem( gRecvInt() );
221
KFMsgBox::box( this, QMessageBox::Warning, i18n("Unknown host %1", recvStr() ) );
226
default: /* XXX huuh ...? */
231
#include "kchooser.moc"