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.
28 #include "kdmshutdown.h"
29 #include "kdm_greet.h"
37 KGDialog::KGDialog( bool themed
) : inherited( 0, !themed
)
39 #ifdef WITH_KDM_XCONSOLE
40 consoleView
= _showLog
? new KConsole( this ) : 0;
49 KGDialog::completeMenu( int _switchIf
, int _switchCode
, const QString
&_switchMsg
, int _switchAccel
)
51 KGDialog::completeMenu()
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 )) );
64 connect( dpyMenu
, SIGNAL(triggered( QAction
* )),
65 SLOT(slotDisplaySelected( QAction
* )) );
66 connect( dpyMenu
, SIGNAL(aboutToShow()),
67 SLOT(slotPopulateDisplays()) );
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()) );
78 if (_isLocal
&& _loginMode
!= _switchIf
) {
79 switchCode
= _switchCode
;
80 inserten( _switchMsg
, _switchAccel
, SLOT(slotSwitch()) );
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
);
96 KGDialog::ensureMenu()
99 optMenu
= new QMenu( this );
100 connect( optMenu
, SIGNAL(triggered( QAction
* )), SLOT(slotActivateMenu( QAction
* )) );
102 } else if (needSep
) {
103 optMenu
->addSeparator();
109 KGDialog::inserten( const QKeySequence
&shortcut
, const char *member
, int data
)
111 QAction
*action
= new QAction( this );
112 action
->setShortcut( shortcut
);
114 action
->setData( data
);
115 connect( action
, SIGNAL(triggered()), member
);
120 KGDialog::inserten( const QString
&txt
, const QKeySequence
&shortcut
, const char *member
)
123 optMenu
->addAction( txt
, this, member
, shortcut
);
127 KGDialog::inserten( const QString
&txt
, const QKeySequence
&shortcut
, QMenu
*cmnu
)
130 QAction
*action
= optMenu
->addMenu( cmnu
);
131 action
->setShortcut( shortcut
);
132 action
->setText( txt
);
136 KGDialog::slotActivateMenu( QAction
*action
)
138 QMenu
*cmnu
= action
->menu();
140 QSize
sh( cmnu
->sizeHint() / 2 );
141 cmnu
->exec( geometry().center() - QPoint( sh
.width(), sh
.height() ) );
146 KGDialog::slotActivateMenu( bool )
148 slotActivateMenu( static_cast<QAction
*>(sender()) );
156 ::exit( _isReserve
? EX_RESERVE
: EX_RESERVER_DPY
);
160 KGDialog::slotSwitch()
168 KGDialog::slotConsole()
171 QList
<DpySpec
> sess
= fetchSessions( 0 );
172 if (!sess
.isEmpty()) {
175 int ret
= KDMConfShutdown( -1, sess
, SHUT_CONSOLE
, 0 ).exec();
186 gSendInt( G_Console
);
191 KGDialog::slotShutdown()
195 QAction
*action
= (QAction
*)sender();
196 if (action
->data().isNull()) {
197 if (_scheduledSd
== SHUT_ALWAYS
)
198 KDMShutdown::scheduleShutdown( this );
200 KDMSlimShutdown( this ).exec();
202 KDMSlimShutdown::externShutdown( action
->data().toInt(), 0, -1 );
208 KGDialog::slotDisplaySelected( QAction
*action
)
212 gSendInt( G_Activate
);
213 gSendInt( action
->data().toInt() );
221 KGDialog::slotPopulateDisplays()
225 QList
<DpySpec
> sessions
= fetchSessions( lstPassive
| lstTTY
);
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 );
234 action
->setEnabled( false );
235 if (sess
.flags
& isSelf
)
236 action
->setChecked( true );
241 #include "kgdialog.moc"