2 Copyright 2007 Robert Knight <robertknight@gmail.com>
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
21 #include "core/leavemodel.h"
27 #include <KConfigGroup>
29 #include <KLocalizedString>
31 #include <solid/control/powermanager.h>
32 #include <kworkspace/kworkspace.h>
35 #include "core/models.h"
37 using namespace Kickoff
;
39 class LeaveModel::Private
43 QStandardItem
* LeaveModel::createStandardItem(const QString
& url
)
45 //Q_ASSERT(KUrl(url).scheme() == "leave");
46 QStandardItem
*item
= new QStandardItem();
47 const QString basename
= QFileInfo(url
).baseName();
48 if (basename
== "logoutonly") {
49 item
->setText(i18n("Logout"));
50 item
->setIcon(KIcon("system-log-out"));
51 item
->setData(i18n("End session"), Kickoff::SubTitleRole
);
52 } else if (basename
== "lock") {
53 item
->setText(i18n("Lock"));
54 item
->setIcon(KIcon("system-lock-screen"));
55 item
->setData(i18n("Lock the screen"), Kickoff::SubTitleRole
);
56 } else if (basename
== "switch") {
57 item
->setText(i18n("Switch User"));
58 item
->setIcon(KIcon("system-switch-user"));
59 item
->setData(i18n("Start a parallel session as a different user"), Kickoff::SubTitleRole
);
60 } else if (basename
== "shutdown") {
61 item
->setText(i18n("Shutdown"));
62 item
->setIcon(KIcon("system-shutdown"));
63 item
->setData(i18n("Turn off computer"), Kickoff::SubTitleRole
);
64 } else if (basename
== "restart") {
65 item
->setText(i18nc("Restart computer", "Restart"));
66 item
->setIcon(KIcon("system-restart"));
67 item
->setData(i18n("Restart computer"), Kickoff::SubTitleRole
);
68 } else if (basename
== "savesession") {
69 item
->setText(i18n("Save Session"));
70 item
->setIcon(KIcon("document-save"));
71 item
->setData(i18n("Save current session for next login"), Kickoff::SubTitleRole
);
72 } else if (basename
== "standby") {
73 item
->setText(i18nc("Puts the system on standby", "Standby"));
74 item
->setIcon(KIcon("system-suspend"));
75 item
->setData(i18n("Pause without logging out"), Kickoff::SubTitleRole
);
76 } else if (basename
== "suspenddisk") {
77 item
->setText(i18n("Suspend to Disk"));
78 item
->setIcon(KIcon("system-suspend-hibernate"));
79 item
->setData(i18n("Pause without logging out"), Kickoff::SubTitleRole
);
80 } else if (basename
== "suspendram") {
81 item
->setText(i18n("Suspend to RAM"));
82 item
->setIcon(KIcon("system-suspend-hibernate"));
83 item
->setData(i18n("Pause without logging out"), Kickoff::SubTitleRole
);
85 item
->setText(basename
);
86 item
->setData(url
, Kickoff::SubTitleRole
);
88 item
->setData(url
, Kickoff::UrlRole
);
92 LeaveModel::LeaveModel(QObject
*parent
)
93 : QStandardItemModel(parent
)
98 void LeaveModel::updateModel()
103 QStandardItem
*sessionOptions
= new QStandardItem(i18n("Session"));
106 QStandardItem
*logoutOption
= createStandardItem("leave:/logoutonly");
107 sessionOptions
->appendRow(logoutOption
);
110 QStandardItem
*lockOption
= createStandardItem("leave:/lock");
111 sessionOptions
->appendRow(lockOption
);
114 KConfigGroup
c(KSharedConfig::openConfig("ksmserverrc", KConfig::NoGlobals
), "General");
115 if (c
.readEntry("loginMode") == "restoreSavedSession") {
116 QStandardItem
*saveSessionOption
= createStandardItem("leave:/savesession");
117 sessionOptions
->appendRow(saveSessionOption
);
121 QStandardItem
*switchUserOption
= createStandardItem("leave:/switch");
122 sessionOptions
->appendRow(switchUserOption
);
125 QStandardItem
*systemOptions
= new QStandardItem(i18n("System"));
126 bool addSystemSession
= false;
128 //FIXME: the proper fix is to implement the KWorkSpace methods for Windows
130 Solid::Control::PowerManager::SuspendMethods spdMethods
= Solid::Control::PowerManager::supportedSuspendMethods();
131 if (spdMethods
& Solid::Control::PowerManager::Standby
) {
132 QStandardItem
*standbyOption
= createStandardItem("leave:/standby");
133 systemOptions
->appendRow(standbyOption
);
134 addSystemSession
= true;
137 if (spdMethods
& Solid::Control::PowerManager::ToRam
) {
138 QStandardItem
*suspendramOption
= createStandardItem("leave:/suspendram");
139 systemOptions
->appendRow(suspendramOption
);
140 addSystemSession
= true;
143 if (spdMethods
& Solid::Control::PowerManager::ToDisk
) {
144 QStandardItem
*suspenddiskOption
= createStandardItem("leave:/suspenddisk");
145 systemOptions
->appendRow(suspenddiskOption
);
146 addSystemSession
= true;
149 if (KWorkSpace::canShutDown(KWorkSpace::ShutdownConfirmDefault
, KWorkSpace::ShutdownTypeReboot
)) {
151 QStandardItem
*restartOption
= createStandardItem("leave:/restart");
152 systemOptions
->appendRow(restartOption
);
153 addSystemSession
= true;
156 if (KWorkSpace::canShutDown(KWorkSpace::ShutdownConfirmDefault
, KWorkSpace::ShutdownTypeHalt
)) {
158 QStandardItem
*shutDownOption
= createStandardItem("leave:/shutdown");
159 systemOptions
->appendRow(shutDownOption
);
160 addSystemSession
= true;
164 appendRow(sessionOptions
);
165 if (addSystemSession
) {
166 appendRow(systemOptions
);
168 delete systemOptions
;
172 LeaveModel::~LeaveModel()
177 #include "leavemodel.moc"