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

Applets

leavemodel.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/leavemodel.h"
00022 
00023 // Qt
00024 #include <QFileInfo>
00025 
00026 // KDE
00027 #include <KConfigGroup>
00028 #include <KDebug>
00029 #include <KLocalizedString>
00030 #include <KIcon>
00031 #include <solid/control/powermanager.h>
00032 #include <kworkspace/kworkspace.h>
00033 
00034 // Local
00035 #include "core/models.h"
00036 
00037 using namespace Kickoff;
00038 
00039 class LeaveModel::Private
00040 {
00041 };
00042 
00043 QStandardItem* LeaveModel::createStandardItem(const QString& url)
00044 {
00045     //Q_ASSERT(KUrl(url).scheme() == "leave");
00046     QStandardItem *item = new QStandardItem();
00047     const QString basename = QFileInfo(url).baseName();
00048     if (basename == "logoutonly") {
00049         item->setText(i18n("Logout"));
00050         item->setIcon(KIcon("system-log-out"));
00051         item->setData(i18n("End session"), Kickoff::SubTitleRole);
00052     } else if (basename == "lock") {
00053         item->setText(i18n("Lock"));
00054         item->setIcon(KIcon("system-lock-screen"));
00055         item->setData(i18n("Lock the screen"), Kickoff::SubTitleRole);
00056     } else if (basename == "switch") {
00057         item->setText(i18n("Switch User"));
00058         item->setIcon(KIcon("system-switch-user"));
00059         item->setData(i18n("Start a parallel session as a different user"), Kickoff::SubTitleRole);
00060     } else if (basename == "shutdown") {
00061         item->setText(i18n("Shutdown"));
00062         item->setIcon(KIcon("system-shutdown"));
00063         item->setData(i18n("Turn off the computer"), Kickoff::SubTitleRole);
00064     } else if (basename == "restart") {
00065         item->setText(i18nc("Restart the computer", "Restart"));
00066         item->setIcon(KIcon("system-restart"));
00067         item->setData(i18n("Restart the computer"), Kickoff::SubTitleRole);
00068     } else if (basename == "savesession") {
00069         item->setText(i18n("Save Session"));
00070         item->setIcon(KIcon("document-save"));
00071         item->setData(i18n("Save current session for next login"), Kickoff::SubTitleRole);
00072     } else if (basename == "standby") {
00073         item->setText(i18nc("Puts the system on standby", "Standby"));
00074         item->setIcon(KIcon("system-suspend"));
00075         item->setData(i18n("Pause without logging out"), Kickoff::SubTitleRole);
00076     } else if (basename == "suspenddisk") {
00077         item->setText(i18n("Suspend to Disk"));
00078         item->setIcon(KIcon("system-suspend-hibernate"));
00079         item->setData(i18n("Pause without logging out"), Kickoff::SubTitleRole);
00080     } else if (basename == "suspendram") {
00081         item->setText(i18n("Suspend to RAM"));
00082         item->setIcon(KIcon("system-suspend-hibernate"));
00083         item->setData(i18n("Pause without logging out"), Kickoff::SubTitleRole);
00084     } else {
00085         item->setText(basename);
00086         item->setData(url, Kickoff::SubTitleRole);
00087     }
00088     item->setData(url, Kickoff::UrlRole);
00089     return item;
00090 }
00091 
00092 LeaveModel::LeaveModel(QObject *parent)
00093         : QStandardItemModel(parent)
00094         , d(0)
00095 {
00096 }
00097 
00098 void LeaveModel::updateModel()
00099 {
00100     clear();
00101 
00102     // Session Options
00103     QStandardItem *sessionOptions = new QStandardItem(i18n("Session"));
00104 
00105     // Logout
00106     QStandardItem *logoutOption = createStandardItem("leave:/logoutonly");
00107     sessionOptions->appendRow(logoutOption);
00108 
00109     // Lock
00110     QStandardItem *lockOption = createStandardItem("leave:/lock");
00111     sessionOptions->appendRow(lockOption);
00112 
00113     // Save Session
00114     KConfigGroup c(KSharedConfig::openConfig("ksmserverrc", KConfig::NoGlobals), "General");
00115     if (c.readEntry("loginMode") == "restoreSavedSession") {
00116         QStandardItem *saveSessionOption = createStandardItem("leave:/savesession");
00117         sessionOptions->appendRow(saveSessionOption);
00118     }
00119 
00120     // Switch User
00121     QStandardItem *switchUserOption = createStandardItem("leave:/switch");
00122     sessionOptions->appendRow(switchUserOption);
00123 
00124     // System Options
00125     QStandardItem *systemOptions = new QStandardItem(i18n("System"));
00126     bool addSystemSession = false;
00127 
00128 //FIXME: the proper fix is to implement the KWorkSpace methods for Windows
00129 #ifndef Q_WS_WIN
00130     Solid::Control::PowerManager::SuspendMethods spdMethods = Solid::Control::PowerManager::supportedSuspendMethods();
00131     if (spdMethods & Solid::Control::PowerManager::Standby) {
00132         QStandardItem *standbyOption = createStandardItem("leave:/standby");
00133         systemOptions->appendRow(standbyOption);
00134         addSystemSession = true;
00135     }
00136 
00137     if (spdMethods & Solid::Control::PowerManager::ToRam) {
00138         QStandardItem *suspendramOption = createStandardItem("leave:/suspendram");
00139         systemOptions->appendRow(suspendramOption);
00140         addSystemSession = true;
00141     }
00142 
00143     if (spdMethods & Solid::Control::PowerManager::ToDisk) {
00144         QStandardItem *suspenddiskOption = createStandardItem("leave:/suspenddisk");
00145         systemOptions->appendRow(suspenddiskOption);
00146         addSystemSession = true;
00147     }
00148 
00149     if (KWorkSpace::canShutDown(KWorkSpace::ShutdownConfirmDefault, KWorkSpace::ShutdownTypeReboot)) {
00150         // Restart
00151         QStandardItem *restartOption = createStandardItem("leave:/restart");
00152         systemOptions->appendRow(restartOption);
00153         addSystemSession = true;
00154     }
00155 
00156     if (KWorkSpace::canShutDown(KWorkSpace::ShutdownConfirmDefault, KWorkSpace::ShutdownTypeHalt)) {
00157         // Shutdown
00158         QStandardItem *shutDownOption = createStandardItem("leave:/shutdown");
00159         systemOptions->appendRow(shutDownOption);
00160         addSystemSession = true;
00161     }
00162 #endif
00163 
00164     appendRow(sessionOptions);
00165     if (addSystemSession) {
00166         appendRow(systemOptions);
00167     } else {
00168         delete systemOptions;
00169     }
00170 }
00171 
00172 LeaveModel::~LeaveModel()
00173 {
00174     delete d;
00175 }
00176 
00177 #include "leavemodel.moc"
00178 

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
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.7
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