2 * Copyright (C) 2006 Aaron Seigo <aseigo@kde.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Library General Public License version 2 as
6 * published by the Free Software Foundation
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details
13 * You should have received a copy of the GNU Library General Public
14 * License along with this program; if not, write to the
15 * Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #include "krunnerapp.h"
28 #include <QtDBus/QtDBus>
31 #include <KActionCollection>
33 #include <KAuthorized>
34 #include <KGlobalAccel>
35 #include <KGlobalSettings>
37 #include <KMessageBox>
38 #include <KWindowSystem>
40 #include "processui/ksysguardprocesslist.h"
42 #include "kworkspace.h"
43 #include "interfaceadaptor.h"
44 #include "interface.h"
45 #include "startupid.h"
46 #include "klaunchsettings.h"
48 #include <X11/extensions/Xrender.h>
51 Colormap colormap
= 0;
53 bool argbVisual
= false;
57 dpy
= XOpenDisplay(0); // open default display
60 kError() << "Cannot connect to the X server" << endl
;
64 KRunnerApp::s_haveCompositeManager
= XGetSelectionOwner(dpy
,
69 if (KRunnerApp::s_haveCompositeManager
)
71 int screen
= DefaultScreen(dpy
);
72 int eventBase
, errorBase
;
74 if (XRenderQueryExtension(dpy
, &eventBase
, &errorBase
))
78 templ
.screen
= screen
;
80 templ
.c_class
= TrueColor
;
81 XVisualInfo
*xvi
= XGetVisualInfo(dpy
, VisualScreenMask
|
85 for (int i
= 0; i
< nvi
; ++i
)
87 XRenderPictFormat
*format
= XRenderFindVisualFormat(dpy
,
89 if (format
->type
== PictTypeDirect
&& format
->direct
.alphaMask
)
91 visual
= xvi
[i
].visual
;
92 colormap
= XCreateColormap(dpy
, RootWindow(dpy
, screen
),
100 KRunnerApp::s_haveCompositeManager
= argbVisual
;
103 kDebug() << "KRunnerApp::s_haveCompositeManager: " << KRunnerApp::s_haveCompositeManager
<< endl
;
107 KRunnerApp::KRunnerApp(Display *display,
110 : RestartingApplication(display, visual, colormap ),
113 kDebug() << "new krunner app" << endl;
117 KRunnerApp::KRunnerApp()
118 : RestartingApplication(checkComposite() ? dpy
: dpy
, dpy
? Qt::HANDLE(visual
) : 0, dpy
? Qt::HANDLE(colormap
) : 0),
122 kDebug() << "new simple krunner app " << dpy
<< " " << argbVisual
<< endl
;
126 KRunnerApp::~KRunnerApp()
131 void KRunnerApp::initialize()
133 setQuitOnLastWindowClosed(false);
135 // Startup notification
136 KLaunchSettings::self()->readConfig();
137 StartupId
*startup_id( NULL
);
138 if( !KLaunchSettings::busyCursor() ) {
142 if( startup_id
== NULL
) {
143 startup_id
= new StartupId
;
146 startup_id
->configure();
149 kDebug() << "initliaze!()" << endl
;
150 m_interface
= new Interface
;
153 m_actionCollection
= new KActionCollection( m_interface
);
156 if ( KAuthorized::authorizeKAction( "run_command" ) ) {
157 a
= m_actionCollection
->addAction( I18N_NOOP("Run Command") );
158 a
->setText( i18n( I18N_NOOP( "Run Command" ) ) );
159 qobject_cast
<KAction
*>( a
)->setGlobalShortcut(KShortcut(Qt::ALT
+Qt::Key_F2
));
160 connect( a
, SIGNAL(triggered(bool)), m_interface
, SLOT(display()) );
162 QDialog* test = new QDialog;
163 connect( a, SIGNAL(triggered(bool)), test, SLOT(show()) );
167 a
= m_actionCollection
->addAction( I18N_NOOP( "Show Taskmanager" ) );
168 a
->setText( i18n( I18N_NOOP( "Show Taskmanager" ) ) );
169 qobject_cast
<KAction
*>( a
)->setGlobalShortcut( KShortcut( Qt::CTRL
+Qt::Key_Escape
) );
170 connect( a
, SIGNAL(triggered(bool)), SLOT(showTaskManager()) );
173 * TODO: doesn't this belong in the window manager?
174 a = m_actionCollection->addAction( I18N_NOOP( "Show Window List") );
175 a->setText( i18n( I18N_NOOP( "Show Window List") ) );
176 qobject_cast<KAction*>( a )->setGlobalShortcut( KShortcut( Qt::ALT+Qt::Key_F5 ) );
177 connect( a, SIGNAL(triggered(bool)), SLOT(slotShowWindowList()) );
179 a
= m_actionCollection
->addAction( I18N_NOOP("Switch User") );
180 a
->setText( i18n( I18N_NOOP("Switch User") ) );
181 qobject_cast
<KAction
*>( a
)->setGlobalShortcut( KShortcut( Qt::ALT
+Qt::CTRL
+Qt::Key_Insert
) );
182 connect(a
, SIGNAL(triggered(bool)), m_interface
, SLOT(switchUser()));
184 if ( KAuthorized::authorizeKAction( "lock_screen" ) ) {
185 a
= m_actionCollection
->addAction( I18N_NOOP( "Lock Session" ) );
186 a
->setText( i18n( I18N_NOOP( "Lock Session" ) ) );
187 qobject_cast
<KAction
*>( a
)->setGlobalShortcut( KShortcut( Qt::ALT
+Qt::CTRL
+Qt::Key_L
) );
188 connect( a
, SIGNAL(triggered(bool)), &m_saver
, SLOT(Lock()) );
191 if ( KAuthorized::authorizeKAction( "logout" ) ) {
192 a
= m_actionCollection
->addAction( I18N_NOOP("Log Out") );
193 a
->setText( i18n(I18N_NOOP("Log Out")) );
194 qobject_cast
<KAction
*>( a
)->setGlobalShortcut(KShortcut(Qt::ALT
+Qt::CTRL
+Qt::Key_Delete
));
195 connect(a
, SIGNAL(triggered(bool)), SLOT(logout()));
197 a
= m_actionCollection
->addAction( I18N_NOOP("Log Out Without Confirmation") );
198 a
->setText( i18n(I18N_NOOP("Log Out Without Confirmation")) );
199 qobject_cast
<KAction
*>( a
)->setGlobalShortcut(KShortcut(Qt::ALT
+Qt::CTRL
+Qt::SHIFT
+Qt::Key_Delete
));
200 connect(a
, SIGNAL(triggered(bool)), SLOT(logoutWithoutConfirmation()));
202 a
= m_actionCollection
->addAction( I18N_NOOP("Halt without Confirmation") );
203 a
->setText( i18n(I18N_NOOP("Halt without Confirmation")) );
204 qobject_cast
<KAction
*>( a
)->setGlobalShortcut(KShortcut(Qt::ALT
+Qt::CTRL
+Qt::SHIFT
+Qt::Key_PageDown
));
205 connect(a
, SIGNAL(triggered(bool)), SLOT(haltWithoutConfirmation()));
207 a
= m_actionCollection
->addAction( I18N_NOOP("Reboot without Confirmation") );
208 a
->setText( i18n(I18N_NOOP("Reboot without Confirmation")) );
209 qobject_cast
<KAction
*>( a
)->setGlobalShortcut(KShortcut(Qt::ALT
+Qt::CTRL
+Qt::SHIFT
+Qt::Key_PageUp
));
210 connect(a
, SIGNAL(triggered(bool)), SLOT(rebootWithoutConfirmation()));
213 m_actionCollection
->readSettings();
215 } // end void KRunnerApp::initializeBindings
218 /*TODO: fixme - move to kwin
219 void KRunnerApp::showWindowList()
221 //KRootWm::self()->slotWindowList();
225 void KRunnerApp::showTaskManager()
227 //kDebug(1204) << "Launching KSysGuard..." << endl;
229 //TODO: move this dialog into its own KDialog subclass
230 // add an expander widget (as seen in the main
231 // krunner window when options get shown)
232 // and put some basic feedback plasmoids there
233 // BLOCKEDBY: said plasmoids and the dataengine
234 // currently being worked on, so the
235 // wait shouldn't be too long =)
237 m_tasks
= new KDialog(0);
238 m_tasks
->setWindowTitle(i18n("System Activity"));
239 connect(m_tasks
, SIGNAL(finished()),
240 this, SLOT(taskDialogFinished()));
241 m_tasks
->setButtons(KDialog::Close
);
242 QWidget
* w
= new KSysGuardProcessList(m_tasks
);
243 m_tasks
->setMainWidget(w
);
245 m_tasks
->setInitialSize(QSize(650, 420));
246 KConfigGroup cg
= KGlobal::config()->group("TaskDialog");
247 m_tasks
->restoreDialogSize(cg
);
252 KWindowSystem::setOnDesktop(m_tasks
->winId(), KWindowSystem::currentDesktop());
253 KWindowSystem::forceActiveWindow(m_tasks
->winId());
256 void KRunnerApp::taskDialogFinished()
258 kDebug() << "task dialog finis" << endl
;
259 KConfigGroup cg
= KGlobal::config()->group("TaskDialog");
260 m_tasks
->saveDialogSize(cg
);
261 KGlobal::config()->sync();
262 m_tasks
->deleteLater();
264 kDebug() << "task dialog finis finis" << endl
;
267 void KRunnerApp::logout()
269 logout( KWorkSpace::ShutdownConfirmDefault
,
270 KWorkSpace::ShutdownTypeDefault
);
273 void KRunnerApp::logoutWithoutConfirmation()
275 logout( KWorkSpace::ShutdownConfirmNo
,
276 KWorkSpace::ShutdownTypeNone
);
279 void KRunnerApp::haltWithoutConfirmation()
281 logout( KWorkSpace::ShutdownConfirmNo
,
282 KWorkSpace::ShutdownTypeHalt
);
285 void KRunnerApp::rebootWithoutConfirmation()
287 logout( KWorkSpace::ShutdownConfirmNo
,
288 KWorkSpace::ShutdownTypeReboot
);
291 void KRunnerApp::logout( KWorkSpace::ShutdownConfirm confirm
,
292 KWorkSpace::ShutdownType sdtype
)
294 if ( !KWorkSpace::requestShutDown( confirm
, sdtype
) ) {
295 // TODO: should we show these errors in Interface?
296 KMessageBox::error( 0, i18n("Could not log out properly.\nThe session manager cannot "
297 "be contacted. You can try to force a shutdown by pressing "
298 "Ctrl+Alt+Backspace; note, however, that your current session "
299 "will not be saved with a forced shutdown." ) );
303 #include <KStartupInfo>
304 int KRunnerApp::newInstance()
306 static bool firstTime
= true;
308 // App startup: do nothing
311 //KStartupInfo::setNewStartupId( m_interface, KStartupInfo::createNewStartupId() );
312 m_interface
->display();
313 //kDebug() << "startup id is " << startupId() << endl;
316 return RestartingApplication::newInstance();
320 #include "krunnerapp.moc"