not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / kdm / kfrontend / kgdialog.cpp
blob9dbaad0c6b04440a9592faaf356a0f094395a0af
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 QList<DpySpec> sess = fetchSessions( 0 );
172 if (!sess.isEmpty()) {
173 if (verify)
174 verify->suspend();
175 int ret = KDMConfShutdown( -1, sess, SHUT_CONSOLE, 0 ).exec();
176 if (verify)
177 verify->resume();
178 if (!ret)
179 return;
181 #else
182 if (verify)
183 verify->abort();
184 #endif
185 gSet( 1 );
186 gSendInt( G_Console );
187 gSet( 0 );
190 void
191 KGDialog::slotShutdown()
193 if (verify)
194 verify->suspend();
195 QAction *action = (QAction *)sender();
196 if (action->data().isNull()) {
197 if (_scheduledSd == SHUT_ALWAYS)
198 KDMShutdown::scheduleShutdown( this );
199 else
200 KDMSlimShutdown( this ).exec();
201 } else
202 KDMSlimShutdown::externShutdown( action->data().toInt(), 0, -1 );
203 if (verify)
204 verify->resume();
207 void
208 KGDialog::slotDisplaySelected( QAction *action )
210 #ifdef HAVE_VTS
211 gSet( 1 );
212 gSendInt( G_Activate );
213 gSendInt( action->data().toInt() );
214 gSet( 0 );
215 #else
216 (void)action;
217 #endif
220 void
221 KGDialog::slotPopulateDisplays()
223 #ifdef HAVE_VTS
224 dpyMenu->clear();
225 QList<DpySpec> sessions = fetchSessions( lstPassive | lstTTY );
226 QString user, loc;
227 foreach (const DpySpec &sess, sessions) {
228 decodeSession( sess, user, loc );
229 QAction *action = dpyMenu->addAction(
230 i18nc( "session (location)", "%1 (%2)", user, loc ) );
231 action->setData( sess.vt ? sess.vt : -1 );
232 action->setCheckable( true );
233 if (!sess.vt)
234 action->setEnabled( false );
235 if (sess.flags & isSelf)
236 action->setChecked( true );
238 #endif
241 #include "kgdialog.moc"