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 <KAuthorized>
28
#include <KConfigGroup>
31
#include <Solid/PowerManagement>
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("Log out"));
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 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("Shut down"));
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-reboot"));
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("Hibernate"));
78
item->setIcon(KIcon("system-suspend-hibernate"));
79
item->setData(i18n("Suspend to disk"), Kickoff::SubTitleRole);
80
} else if (basename == "suspendram") {
81
item->setText(i18n("Sleep"));
82
item->setIcon(KIcon("system-suspend"));
83
item->setData(i18n("Suspend to RAM"), 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
QVariant LeaveModel::headerData(int section, Qt::Orientation orientation, int role) const
100
if (orientation != Qt::Horizontal || section != 0) {
105
case Qt::DisplayRole:
106
return i18n("Leave");
113
void LeaveModel::updateModel()
118
QStandardItem *sessionOptions = new QStandardItem(i18n("Session"));
121
if ( KAuthorized::authorizeKAction( "logout" ) ) {
122
QStandardItem *logoutOption = createStandardItem("leave:/logoutonly");
123
sessionOptions->appendRow(logoutOption);
127
if ( KAuthorized::authorizeKAction( "lock_screen" ) ) {
128
QStandardItem *lockOption = createStandardItem("leave:/lock");
129
sessionOptions->appendRow(lockOption);
133
if ( KAuthorized::authorizeKAction( "logout" ) ) {
134
KConfigGroup c(KSharedConfig::openConfig("ksmserverrc", KConfig::NoGlobals), "General");
135
if (c.readEntry("loginMode") == "restoreSavedSession") {
136
QStandardItem *saveSessionOption = createStandardItem("leave:/savesession");
137
sessionOptions->appendRow(saveSessionOption);
142
QStandardItem *switchUserOption = createStandardItem("leave:/switch");
143
sessionOptions->appendRow(switchUserOption);
146
QStandardItem *systemOptions = new QStandardItem(i18n("System"));
147
bool addSystemSession = false;
149
//FIXME: the proper fix is to implement the KWorkSpace methods for Windows
151
if ( KAuthorized::authorizeKAction( "logout" ) ) {
152
QSet< Solid::PowerManagement::SleepState > spdMethods = Solid::PowerManagement::supportedSleepStates();
153
if (spdMethods.contains(Solid::PowerManagement::StandbyState)) {
154
QStandardItem *standbyOption = createStandardItem("leave:/standby");
155
systemOptions->appendRow(standbyOption);
156
addSystemSession = true;
159
if (spdMethods.contains(Solid::PowerManagement::SuspendState)) {
160
QStandardItem *suspendramOption = createStandardItem("leave:/suspendram");
161
systemOptions->appendRow(suspendramOption);
162
addSystemSession = true;
165
if (spdMethods.contains(Solid::PowerManagement::HibernateState)) {
166
QStandardItem *suspenddiskOption = createStandardItem("leave:/suspenddisk");
167
systemOptions->appendRow(suspenddiskOption);
168
addSystemSession = true;
171
if (KWorkSpace::canShutDown(KWorkSpace::ShutdownConfirmDefault, KWorkSpace::ShutdownTypeReboot)) {
173
QStandardItem *restartOption = createStandardItem("leave:/restart");
174
systemOptions->appendRow(restartOption);
175
addSystemSession = true;
178
if (KWorkSpace::canShutDown(KWorkSpace::ShutdownConfirmDefault, KWorkSpace::ShutdownTypeHalt)) {
180
QStandardItem *shutDownOption = createStandardItem("leave:/shutdown");
181
systemOptions->appendRow(shutDownOption);
182
addSystemSession = true;
187
appendRow(sessionOptions);
188
if (addSystemSession) {
189
appendRow(systemOptions);
191
delete systemOptions;
195
LeaveModel::~LeaveModel()
200
#include "leavemodel.moc"