Make a branch to make krunner Good Enough For Aaron™.
[kdebase/uwolfer.git] / workspace / kdm / kfrontend / kgdialog.cpp
blobfa96aa25e7f13d98d9f43f4b05f038a57c08c24b
1 /*
3 Base class for various kdm greeter dialogs
5 Copyright (C) 1997, 1998 Steffen Hansen <hansen@kde.org>
6 Copyright (C) 2000-2004 Oswald Buddenhagen <ossi@kde.org>
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 #include "kgdialog.h"
26 #include "kgverify.h"
27 #include "kconsole.h"
28 #include "kdmshutdown.h"
29 #include "kdm_greet.h"
30 #include "utils.h"
32 #include <klocale.h>
34 #include <QAction>
35 #include <QMenu>
37 KGDialog::KGDialog( bool themed ) : inherited( 0, !themed )
39 #ifdef WITH_KDM_XCONSOLE
40 consoleView = _showLog ? new KConsole( this ) : 0;
41 #endif
43 optMenu = 0;
44 verify = 0;
47 void
48 #ifdef XDMCP
49 KGDialog::completeMenu( int _switchIf, int _switchCode, const QString &_switchMsg, int _switchAccel )
50 #else
51 KGDialog::completeMenu()
52 #endif
54 #ifdef HAVE_VTS
55 if (_isLocal) {
56 dpyMenu = new QMenu( this );
57 inserten( i18n("Sw&itch User"), Qt::ALT + Qt::Key_I, dpyMenu );
58 QAction *action = new QAction( this );
59 action->setMenu( dpyMenu );
60 action->setShortcut( Qt::ALT+Qt::CTRL+Qt::Key_Insert );
61 connect( action, SIGNAL(triggered( bool )),
62 SLOT(slotActivateMenu( bool )) );
63 addAction( action );
64 connect( dpyMenu, SIGNAL(triggered( QAction * )),
65 SLOT(slotDisplaySelected( QAction * )) );
66 connect( dpyMenu, SIGNAL(aboutToShow()),
67 SLOT(slotPopulateDisplays()) );
69 #endif
71 if (_allowClose || _isReserve)
72 inserten( _isReserve ? i18n("Abort S&ession") :
73 _isLocal ? i18n("R&estart X Server") :
74 i18n("Clos&e Connection"),
75 Qt::ALT+Qt::Key_E, SLOT(slotExit()) );
77 #ifdef XDMCP
78 if (_isLocal && _loginMode != _switchIf) {
79 switchCode = _switchCode;
80 inserten( _switchMsg, _switchAccel, SLOT(slotSwitch()) );
82 #endif
84 if (_hasConsole)
85 inserten( i18n("Co&nsole Login"), Qt::ALT+Qt::Key_N, SLOT(slotConsole()) );
87 if (_allowShutdown != SHUT_NONE) {
88 inserten( i18n("&Shutdown..."), Qt::ALT + Qt::Key_S, SLOT(slotShutdown()) );
89 inserten( Qt::ALT + Qt::CTRL + Qt::Key_Delete, SLOT(slotShutdown()) );
90 inserten( Qt::SHIFT + Qt::ALT + Qt::CTRL + Qt::Key_PageUp, SLOT(slotShutdown()), SHUT_REBOOT );
91 inserten( Qt::SHIFT + Qt::ALT + Qt::CTRL + Qt::Key_PageDown, SLOT(slotShutdown()), SHUT_HALT );
95 void
96 KGDialog::ensureMenu()
98 if (!optMenu) {
99 optMenu = new QMenu( this );
100 connect( optMenu, SIGNAL(triggered( QAction * )), SLOT(slotActivateMenu( QAction * )) );
101 needSep = false;
102 } else if (needSep) {
103 optMenu->addSeparator();
104 needSep = false;
108 void
109 KGDialog::inserten( const QKeySequence &shortcut, const char *member, int data )
111 QAction *action = new QAction( this );
112 action->setShortcut( shortcut );
113 if (data != -1)
114 action->setData( data );
115 connect( action, SIGNAL(triggered()), member );
116 addAction( action );
119 void
120 KGDialog::inserten( const QString &txt, const QKeySequence &shortcut, const char *member )
122 ensureMenu();
123 optMenu->addAction( txt, this, member, shortcut );
126 void
127 KGDialog::inserten( const QString &txt, const QKeySequence &shortcut, QMenu *cmnu )
129 ensureMenu();
130 QAction *action = optMenu->addMenu( cmnu );
131 action->setShortcut( shortcut );
132 action->setText( txt );
135 void
136 KGDialog::slotActivateMenu( QAction *action )
138 QMenu *cmnu = action->menu();
139 if (cmnu) {
140 QSize sh( cmnu->sizeHint() / 2 );
141 cmnu->exec( geometry().center() - QPoint( sh.width(), sh.height() ) );
145 void
146 KGDialog::slotActivateMenu( bool )
148 slotActivateMenu( static_cast<QAction *>(sender()) );
151 void
152 KGDialog::slotExit()
154 if (verify)
155 verify->abort();
156 ::exit( _isReserve ? EX_RESERVE : EX_RESERVER_DPY );
159 void
160 KGDialog::slotSwitch()
162 #ifdef XDMCP
163 done( switchCode );
164 #endif
167 void
168 KGDialog::slotConsole()
170 #ifdef HAVE_VTS
171 dpySpec *sess = fetchSessions( 0 );
172 if (sess) {
173 if (verify)
174 verify->suspend();
175 int ret = KDMConfShutdown( -1, sess, SHUT_CONSOLE, 0 ).exec();
176 if (verify)
177 verify->resume();
178 disposeSessions( sess );
179 if (!ret)
180 return;
182 #else
183 if (verify)
184 verify->abort();
185 #endif
186 gSet( 1 );
187 gSendInt( G_Console );
188 gSet( 0 );
191 void
192 KGDialog::slotShutdown()
194 if (verify)
195 verify->suspend();
196 QAction *action = (QAction *)sender();
197 if (action->data().isNull()) {
198 if (_scheduledSd == SHUT_ALWAYS)
199 KDMShutdown::scheduleShutdown( this );
200 else
201 KDMSlimShutdown( this ).exec();
202 } else
203 KDMSlimShutdown::externShutdown( action->data().toInt(), 0, -1 );
204 if (verify)
205 verify->resume();
208 void
209 KGDialog::slotDisplaySelected( QAction *action )
211 #ifdef HAVE_VTS
212 gSet( 1 );
213 gSendInt( G_Activate );
214 gSendInt( action->data().toInt() );
215 gSet( 0 );
216 #else
217 (void)action;
218 #endif
221 void
222 KGDialog::slotPopulateDisplays()
224 #ifdef HAVE_VTS
225 dpyMenu->clear();
226 dpySpec *sessions = fetchSessions( lstPassive | lstTTY );
227 QString user, loc;
228 for (dpySpec *sess = sessions; sess; sess = sess->next) {
229 decodeSession( sess, user, loc );
230 QAction *action = dpyMenu->addAction(
231 i18nc( "session (location)", "%1 (%2)", user, loc ) );
232 action->setData( sess->vt ? sess->vt : -1 );
233 action->setCheckable( true );
234 if (!sess->vt)
235 action->setEnabled( false );
236 if (sess->flags & isSelf)
237 action->setChecked( true );
239 disposeSessions( sessions );
240 #endif
243 #include "kgdialog.moc"