1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
|
/*
Base class for various kdm greeter dialogs
Copyright (C) 1997, 1998 Steffen Hansen <hansen@kde.org>
Copyright (C) 2000-2004 Oswald Buddenhagen <ossi@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "kgdialog.h"
#include "kgverify.h"
#include "kconsole.h"
#include "kdmshutdown.h"
#include "kdm_greet.h"
#include <klocale.h>
#include <qaccel.h>
#include <qlayout.h>
#include <qpushbutton.h>
#include <qpopupmenu.h>
#include <qapplication.h>
#include <stdlib.h>
KGDialog::KGDialog( bool themed ) : inherited( 0, !themed )
{
#ifdef WITH_KDM_XCONSOLE
consoleView = _showLog ? new KConsole( this ) : 0;
#endif
optMenu = 0;
verify = 0;
}
void
#ifdef XDMCP
KGDialog::completeMenu( int _switchIf, int _switchCode, const QString &_switchMsg, int _switchAccel )
#else
KGDialog::completeMenu()
#endif
{
#ifdef HAVE_VTS
if (_isLocal) {
dpyMenu = new QPopupMenu( this );
int id = inserten( i18n("Sw&itch User"), ALT+Key_I, dpyMenu );
connect( dpyMenu, SIGNAL(activated( int )),
SLOT(slotDisplaySelected( int )) );
connect( dpyMenu, SIGNAL(aboutToShow()),
SLOT(slotPopulateDisplays()) );
QAccel *accel = new QAccel( this );
accel->insertItem( ALT+CTRL+Key_Insert, id );
connect( accel, SIGNAL(activated( int )), SLOT(slotActivateMenu( int )) );
}
#endif
if (_allowClose)
inserten( _isLocal ? i18n("R&estart X Server") : i18n("Clos&e Connection"),
ALT+Key_E, SLOT(slotExit()) );
#ifdef XDMCP
if (_isLocal && _loginMode != _switchIf) {
switchCode = _switchCode;
inserten( _switchMsg, _switchAccel, SLOT(slotSwitch()) );
}
#endif
if (_hasConsole)
inserten( i18n("Co&nsole Login"), ALT+Key_N, SLOT(slotConsole()) );
if (_allowShutdown != SHUT_NONE) {
inserten( i18n("&Shutdown..."), ALT+Key_S, SLOT(slotShutdown( int )) );
QAccel *accel = new QAccel( this );
accel->insertItem( ALT+CTRL+Key_Delete );
connect( accel, SIGNAL(activated( int )), SLOT(slotShutdown( int )) );
accel = new QAccel( this );
accel->insertItem( SHIFT+ALT+CTRL+Key_PageUp, SHUT_REBOOT );
connect( accel, SIGNAL(activated( int )), SLOT(slotShutdown( int )) );
accel = new QAccel( this );
accel->insertItem( SHIFT+ALT+CTRL+Key_PageDown, SHUT_HALT );
connect( accel, SIGNAL(activated( int )), SLOT(slotShutdown( int )) );
}
}
void
KGDialog::ensureMenu()
{
if (!optMenu) {
optMenu = new QPopupMenu( this );
optMenu->setCheckable( false );
needSep = false;
} else if (needSep) {
optMenu->insertSeparator();
needSep = false;
}
}
void
KGDialog::inserten( const QString& txt, int accel, const char *member )
{
ensureMenu();
optMenu->insertItem( txt, this, member, accel );
}
int
KGDialog::inserten( const QString& txt, int accel, QPopupMenu *cmnu )
{
ensureMenu();
int id = optMenu->insertItem( txt, cmnu );
optMenu->setAccel( accel, id );
optMenu->connectItem( id, this, SLOT(slotActivateMenu( int )) );
optMenu->setItemParameter( id, id );
return id;
}
void
KGDialog::slotActivateMenu( int id )
{
QPopupMenu *cmnu = optMenu->findItem( id )->popup();
QSize sh( cmnu->sizeHint() / 2 );
cmnu->exec( geometry().center() - QPoint( sh.width(), sh.height() ) );
}
void
KGDialog::slotExit()
{
if (verify)
verify->abort();
::exit( EX_RESERVER_DPY );
}
void
KGDialog::slotSwitch()
{
#ifdef XDMCP
// workaround for Qt bug
QTimer::singleShot( 0, this, SLOT(slotReallySwitch()) );
#endif
}
void
KGDialog::slotReallySwitch()
{
#ifdef XDMCP
done( switchCode );
#endif
}
void
KGDialog::slotConsole()
{
#ifdef HAVE_VTS
dpySpec *sess = fetchSessions( 0 );
if (sess) {
if (verify)
verify->suspend();
int ret = KDMConfShutdown( -1, sess, SHUT_CONSOLE, 0 ).exec();
if (verify)
verify->resume();
disposeSessions( sess );
if (!ret)
return;
}
#else
if (verify)
verify->abort();
#endif
GSet( 1 );
GSendInt( G_Console );
GSet( 0 );
}
void
KGDialog::slotShutdown( int id )
{
if (verify)
verify->suspend();
if (id < 0) {
if (_scheduledSd == SHUT_ALWAYS)
KDMShutdown::scheduleShutdown( this );
else
KDMSlimShutdown( this ).exec();
} else
KDMSlimShutdown::externShutdown( id, 0, -1 );
if (verify)
verify->resume();
}
void
KGDialog::slotDisplaySelected( int vt )
{
#ifdef HAVE_VTS
GSet( 1 );
GSendInt( G_Activate );
GSendInt( vt );
GSet( 0 );
#else
(void)vt;
#endif
}
void
KGDialog::slotPopulateDisplays()
{
#ifdef HAVE_VTS
dpyMenu->clear();
dpySpec *sessions = fetchSessions( lstPassive | lstTTY );
QString user, loc;
for (dpySpec *sess = sessions; sess; sess = sess->next) {
decodeSess( sess, user, loc );
int id = dpyMenu->insertItem(
i18n("session (location)", "%1 (%2)").arg( user ).arg( loc ),
sess->vt ? sess->vt : -1 );
if (!sess->vt)
dpyMenu->setItemEnabled( id, false );
if (sess->flags & isSelf)
dpyMenu->setItemChecked( id, true );
}
disposeSessions( sessions );
#endif
}
#include "kgdialog.moc"
|