• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

Applets

itemhandlers.cpp

Go to the documentation of this file.
00001 /*  
00002     Copyright 2007 Robert Knight <robertknight@gmail.com>
00003 
00004     This library is free software; you can redistribute it and/or
00005     modify it under the terms of the GNU Library General Public
00006     License as published by the Free Software Foundation; either
00007     version 2 of the License, or (at your option) any later version.
00008 
00009     This library is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012     Library General Public License for more details.
00013 
00014     You should have received a copy of the GNU Library General Public License
00015     along with this library; see the file COPYING.LIB.  If not, write to
00016     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017     Boston, MA 02110-1301, USA.
00018 */
00019 
00020 // Own
00021 #include "core/itemhandlers.h"
00022 
00023 // Qt
00024 #include <QTimer>
00025 
00026 // KDE
00027 #include <KDebug>
00028 #include <KService>
00029 #include <KToolInvocation>
00030 #include <KUrl>
00031 #include <solid/powermanagement.h>
00032 
00033 // KDE Base
00034 #include <kworkspace/kworkspace.h>
00035 
00036 // Local
00037 #include "core/recentapplications.h"
00038 
00039 // DBus
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         // decouple dbus call, otherwise we'll run into a dead-lock
00075         QTimer::singleShot(0, this, SLOT(lock()));
00076         return true;
00077     } else if (m_logoutAction == "switch") {
00078         // decouple dbus call, otherwise we'll run into a dead-lock
00079         QTimer::singleShot(0, this, SLOT(switchUser()));
00080         return true;
00081     } else if (m_logoutAction == "logout" ||
00082                m_logoutAction == "restart" || m_logoutAction == "shutdown" ) {
00083         // decouple dbus call, otherwise we'll run into a dead-lock
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 }

Applets

Skip menu "Applets"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • KWin
  •   KWin Libraries
  • Libraries
  •   libkworkspace
  •   libplasma
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal