Applets
itemhandlers.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "core/itemhandlers.h"
00022
00023
00024 #include <QTimer>
00025
00026
00027 #include <KDebug>
00028 #include <KService>
00029 #include <KToolInvocation>
00030 #include <KUrl>
00031 #include <solid/powermanagement.h>
00032
00033
00034 #include <kworkspace/kworkspace.h>
00035
00036
00037 #include "core/recentapplications.h"
00038
00039
00040 #include "krunner_interface.h"
00041 #include "screensaver_interface.h"
00042
00043 using namespace Kickoff;
00044
00045 bool ServiceItemHandler::openUrl(const KUrl& url)
00046 {
00047 int result = KToolInvocation::startServiceByDesktopPath(url.pathOrUrl(),QStringList(),0,0,0,"",true);
00048
00049 if (result == 0) {
00050 KService::Ptr service = KService::serviceByDesktopPath(url.pathOrUrl());
00051
00052 if (!service.isNull()) {
00053 RecentApplications::self()->add(service);
00054 } else {
00055 qWarning() << "Failed to find service for" << url;
00056 return false;
00057 }
00058 }
00059
00060 return result == 0;
00061 }
00062
00063 bool LeaveItemHandler::openUrl(const KUrl& url)
00064 {
00065 m_logoutAction = url.path().remove('/');
00066
00067 if (m_logoutAction == "sleep") {
00068 Solid::PowerManagement::requestSleep(Solid::PowerManagement::SuspendState,0,0);
00069 return true;
00070 } else if (m_logoutAction == "hibernate") {
00071 Solid::PowerManagement::requestSleep(Solid::PowerManagement::HibernateState,0,0);
00072 return true;
00073 } else if (m_logoutAction == "lock") {
00074
00075 QTimer::singleShot(0, this, SLOT(lock()));
00076 return true;
00077 } else if (m_logoutAction == "switch") {
00078
00079 QTimer::singleShot(0, this, SLOT(switchUser()));
00080 return true;
00081 } else if (m_logoutAction == "logout" ||
00082 m_logoutAction == "restart" || m_logoutAction == "shutdown" ) {
00083
00084 QTimer::singleShot(0, this, SLOT(logout()));
00085 return true;
00086 }
00087
00088 return false;
00089 }
00090
00091 void LeaveItemHandler::logout()
00092 {
00093 KWorkSpace::ShutdownConfirm confirm = KWorkSpace::ShutdownConfirmDefault;
00094 KWorkSpace::ShutdownType type = KWorkSpace::ShutdownTypeNone;
00095
00096 if (m_logoutAction == "logout") {
00097 type = KWorkSpace::ShutdownTypeNone;
00098 } else if (m_logoutAction == "lock") {
00099 kDebug() << "Locking screen";
00100 } else if (m_logoutAction == "switch") {
00101 kDebug() << "Switching user";
00102 } else if (m_logoutAction == "restart") {
00103 type = KWorkSpace::ShutdownTypeReboot;
00104 } else if (m_logoutAction == "shutdown") {
00105 type = KWorkSpace::ShutdownTypeHalt;
00106 }
00107
00108 KWorkSpace::requestShutDown(confirm,type);
00109 }
00110
00111 void LeaveItemHandler::lock()
00112 {
00113 QString interface("org.freedesktop.ScreenSaver");
00114 org::freedesktop::ScreenSaver screensaver(interface, "/ScreenSaver",
00115 QDBusConnection::sessionBus());
00116 if (screensaver.isValid()) {
00117 screensaver.Lock();
00118 }
00119 }
00120
00121 void LeaveItemHandler::switchUser()
00122 {
00123 QString interface("org.kde.krunner");
00124
00125 org::kde::krunner::Interface krunner(interface, "/Interface",
00126 QDBusConnection::sessionBus());
00127 if (krunner.isValid()) {
00128 krunner.switchUser();
00129 }
00130 }