Applets
leavemodel.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/leavemodel.h"
00022
00023
00024 #include <QFileInfo>
00025
00026
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
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
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
00103 QStandardItem *sessionOptions = new QStandardItem(i18n("Session"));
00104
00105
00106 QStandardItem *logoutOption = createStandardItem("leave:/logoutonly");
00107 sessionOptions->appendRow(logoutOption);
00108
00109
00110 QStandardItem *lockOption = createStandardItem("leave:/lock");
00111 sessionOptions->appendRow(lockOption);
00112
00113
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
00121 QStandardItem *switchUserOption = createStandardItem("leave:/switch");
00122 sessionOptions->appendRow(switchUserOption);
00123
00124
00125 QStandardItem *systemOptions = new QStandardItem(i18n("System"));
00126 bool addSystemSession = false;
00127
00128
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
00151 QStandardItem *restartOption = createStandardItem("leave:/restart");
00152 systemOptions->appendRow(restartOption);
00153 addSystemSession = true;
00154 }
00155
00156 if (KWorkSpace::canShutDown(KWorkSpace::ShutdownConfirmDefault, KWorkSpace::ShutdownTypeHalt)) {
00157
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