~ubuntu-branches/ubuntu/oneiric/kde-workspace/oneiric

« back to all changes in this revision

Viewing changes to .pc/0023-fix-kiosk-restrictions-for-user-switching-and-logout.patch/plasma/desktop/applets/kickoff/core/leavemodel.cpp

  • Committer: Package Import Robot
  • Author(s): Scott Kitterman
  • Date: 2011-09-25 00:42:41 UTC
  • Revision ID: package-import@ubuntu.com-20110925004241-c5ck55dokn3yt1kg
Tags: 4:4.7.1-0ubuntu3
* Update debian/kdm.upstart to match latest gdm.upstart improvements:
  - Also export LC_MESSAGES with the rest of locale information
  - When kdm is shut down by a runlevel call, emit an upstart event that can
    be caught by plymouth so it can distinguish between the DM shutting down
    for a runlevel change vs. other causes (LP: #854329)
* Update patches for post-4.7.1 changes.  Add to debian/patches:
    0001-SVN_SILENT-made-messages-.desktop-file.patch
    0003-SVN_SILENT-made-messages-.desktop-file.patch
    0004-SVN_SILENT-made-messages-.desktop-file.patch
    0005-SVN_SILENT-made-messages-.desktop-file.patch
    0006-preferred-app-launchers-need-to-use-the-type-of-the-.patch
    0007-SVN_SILENT-made-messages-.desktop-file.patch
    0009-SVN_SILENT-made-messages-.desktop-file.patch
    0010-add-some-missing-connects-for-the-ruleswidget.patch
    0011-fix-yet-another-fun-with-pointers-tabbing-segfault.patch
    0013-catch-changeMaximize-recursion-from-setNoBorder.patch
    0014-Clear-thumbnails-for-deleted-windows.patch
    0015-Fix-pointer-accesses-in-tiling-code.patch
    0016-SVN_SILENT-made-messages-.desktop-file.patch
    0017-SVN_SILENT-made-messages-.desktop-file.patch
    0018-SVN_SILENT-made-messages-.desktop-file.patch
    0019-Test-for-widget-creation-before-deleting-property-at.patch
    0020-SVN_SILENT-made-messages-.desktop-file.patch
    0023-fix-kiosk-restrictions-for-user-switching-and-logout.patch
    0024-Fix-typo-use-the-right-signal-signature.patch
    0025-Repaint-old-area-of-the-thumbnail.patch
    0026-Use-Client-layoutMetric-to-access-shadowSize-instead.patch
    0027-ShowCalendarPopup-false-suppresses-calendar-popup-an.patch
    0028-show-the-keyboard-on-immediately-entering-a-text-are.patch
    0029-Repaint-the-whole-window-in-the-taskbar-thumbnail.patch
    0030-SVN_SILENT-made-messages-.desktop-file.patch
    0031-Fix-wrong-inital-tab-in-keyboard-kcm.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Copyright 2007 Robert Knight <robertknight@gmail.com>
 
3
 
 
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.
 
8
 
 
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.
 
13
 
 
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.
 
18
*/
 
19
 
 
20
// Own
 
21
#include "core/leavemodel.h"
 
22
 
 
23
// Qt
 
24
#include <QFileInfo>
 
25
 
 
26
// KDE
 
27
#include <KAuthorized>
 
28
#include <KConfigGroup>
 
29
#include <KDebug>
 
30
#include <KIcon>
 
31
#include <Solid/PowerManagement>
 
32
#include <kworkspace/kworkspace.h>
 
33
 
 
34
// Local
 
35
#include "core/models.h"
 
36
 
 
37
using namespace Kickoff;
 
38
 
 
39
class LeaveModel::Private
 
40
{
 
41
};
 
42
 
 
43
QStandardItem* LeaveModel::createStandardItem(const QString& url)
 
44
{
 
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);
 
84
    } else {
 
85
        item->setText(basename);
 
86
        item->setData(url, Kickoff::SubTitleRole);
 
87
    }
 
88
    item->setData(url, Kickoff::UrlRole);
 
89
    return item;
 
90
}
 
91
 
 
92
LeaveModel::LeaveModel(QObject *parent)
 
93
        : QStandardItemModel(parent)
 
94
        , d(0)
 
95
{
 
96
}
 
97
 
 
98
QVariant LeaveModel::headerData(int section, Qt::Orientation orientation, int role) const
 
99
{
 
100
    if (orientation != Qt::Horizontal || section != 0) {
 
101
        return QVariant();
 
102
    }
 
103
 
 
104
    switch (role) {
 
105
    case Qt::DisplayRole:
 
106
        return i18n("Leave");
 
107
        break;
 
108
    default:
 
109
        return QVariant();
 
110
    }
 
111
}
 
112
 
 
113
void LeaveModel::updateModel()
 
114
{
 
115
    clear();
 
116
 
 
117
    // Session Options
 
118
    QStandardItem *sessionOptions = new QStandardItem(i18n("Session"));
 
119
 
 
120
    // Logout
 
121
    if ( KAuthorized::authorizeKAction( "logout" ) ) {
 
122
        QStandardItem *logoutOption = createStandardItem("leave:/logoutonly");
 
123
        sessionOptions->appendRow(logoutOption);
 
124
    }
 
125
 
 
126
    // Lock
 
127
    if ( KAuthorized::authorizeKAction( "lock_screen" ) ) {
 
128
        QStandardItem *lockOption = createStandardItem("leave:/lock");
 
129
        sessionOptions->appendRow(lockOption);
 
130
    }
 
131
 
 
132
    // Save Session
 
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);
 
138
        }
 
139
    }
 
140
 
 
141
    // Switch User
 
142
    QStandardItem *switchUserOption = createStandardItem("leave:/switch");
 
143
    sessionOptions->appendRow(switchUserOption);
 
144
 
 
145
    // System Options
 
146
    QStandardItem *systemOptions = new QStandardItem(i18n("System"));
 
147
    bool addSystemSession = false;
 
148
 
 
149
//FIXME: the proper fix is to implement the KWorkSpace methods for Windows
 
150
#ifndef Q_WS_WIN
 
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;
 
157
        }
 
158
 
 
159
        if (spdMethods.contains(Solid::PowerManagement::SuspendState)) {
 
160
            QStandardItem *suspendramOption = createStandardItem("leave:/suspendram");
 
161
            systemOptions->appendRow(suspendramOption);
 
162
            addSystemSession = true;
 
163
        }
 
164
 
 
165
        if (spdMethods.contains(Solid::PowerManagement::HibernateState)) {
 
166
            QStandardItem *suspenddiskOption = createStandardItem("leave:/suspenddisk");
 
167
            systemOptions->appendRow(suspenddiskOption);
 
168
            addSystemSession = true;
 
169
        }
 
170
 
 
171
        if (KWorkSpace::canShutDown(KWorkSpace::ShutdownConfirmDefault, KWorkSpace::ShutdownTypeReboot)) {
 
172
            // Restart
 
173
            QStandardItem *restartOption = createStandardItem("leave:/restart");
 
174
            systemOptions->appendRow(restartOption);
 
175
            addSystemSession = true;
 
176
        }
 
177
 
 
178
        if (KWorkSpace::canShutDown(KWorkSpace::ShutdownConfirmDefault, KWorkSpace::ShutdownTypeHalt)) {
 
179
            // Shutdown
 
180
            QStandardItem *shutDownOption = createStandardItem("leave:/shutdown");
 
181
            systemOptions->appendRow(shutDownOption);
 
182
            addSystemSession = true;
 
183
        }
 
184
    }
 
185
#endif
 
186
 
 
187
    appendRow(sessionOptions);
 
188
    if (addSystemSession) {
 
189
        appendRow(systemOptions);
 
190
    } else {
 
191
        delete systemOptions;
 
192
    }
 
193
}
 
194
 
 
195
LeaveModel::~LeaveModel()
 
196
{
 
197
    delete d;
 
198
}
 
199
 
 
200
#include "leavemodel.moc"
 
201