Plasma
desktop.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 #include "desktop.h"
00021
00022 #include <QAction>
00023 #include <QApplication>
00024 #include <QDBusConnection>
00025 #include <QDBusInterface>
00026 #include <QDBusMessage>
00027
00028 #include <KDebug>
00029 #include <KIcon>
00030
00031 #include "plasma/corona.h"
00032 #include "plasma/theme.h"
00033
00034 using namespace Plasma;
00035
00036 SaverDesktop::SaverDesktop(QObject *parent, const QVariantList &args)
00037 : Containment(parent, args),
00038 m_lockDesktopAction(0),
00039 m_appletBrowserAction(0)
00040 {
00041 }
00042
00043 SaverDesktop::~SaverDesktop()
00044 {
00045 }
00046
00047 void SaverDesktop::init()
00048 {
00049 Containment::init();
00050
00051 bool unlocked = immutability() == Mutable;
00052
00053 QAction *lock = action("lock widgets");
00054 if (lock) {
00055 lock->disconnect(this);
00056 connect(lock, SIGNAL(triggered(bool)), this, SLOT(toggleLock()));
00057 lock->setText(unlocked ? i18n("Lock") : i18n("Unlock"));
00058 }
00059
00060
00061
00062 QAction *unwanted = action("zoom in");
00063 removeToolBoxAction(unwanted);
00064 delete unwanted;
00065 unwanted = action("zoom out");
00066 removeToolBoxAction(unwanted);
00067 delete unwanted;
00068 unwanted = action("add sibling containment");
00069 removeToolBoxAction(unwanted);
00070 delete unwanted;
00071
00072 lock = new QAction(unlocked ? i18n("Quit") : i18n("Unlock and Quit"), this);
00073 lock->setIcon(KIcon("system-lock-screen"));
00074
00075 lock->setShortcutContext(Qt::WidgetShortcut);
00076 lock->setShortcut(QKeySequence("esc"));
00077 connect(lock, SIGNAL(triggered(bool)), this, SLOT(unlockDesktop()));
00078 addAction("unlock desktop", lock);
00079 addToolBoxAction(lock);
00080
00081 QAction *a = action("configure");
00082 if (a) {
00083 a->setText(i18n("Settings"));
00084 addToolBoxAction(a);
00085 }
00086
00087
00088 a = action("add widgets");
00089 if (a) {
00090 removeToolBoxAction(a);
00091 addToolBoxAction(a);
00092 }
00093 }
00094
00095 void SaverDesktop::constraintsEvent(Plasma::Constraints constraints)
00096 {
00097 if (constraints & Plasma::ImmutableConstraint) {
00098 bool unlocked = immutability() == Mutable;
00099 QAction *a = action("lock widgets");
00100 if (a) {
00101 a->setText(unlocked ? i18n("Lock") : i18n("Unlock"));
00102 }
00103 a = action("unlock desktop");
00104 if (a) {
00105 a->setText(unlocked ? i18n("Quit") : i18n("Unlock and Quit"));
00106 }
00107 }
00108 }
00109
00110 QList<QAction*> SaverDesktop::contextualActions()
00111 {
00112 if (!m_appletBrowserAction) {
00113 m_appletBrowserAction = action("add widgets");
00114 m_lockDesktopAction = action("lock widgets");
00115 }
00116 QAction *config = action("configure");
00117 QAction *quit = action("unlock desktop");
00118
00119 QList<QAction*> actions;
00120 actions.append(m_appletBrowserAction);
00121 if (config) {
00122 actions.append(config);
00123 }
00124 actions.append(m_lockDesktopAction);
00125 actions.append(quit);
00126
00127 return actions;
00128 }
00129
00130 void SaverDesktop::toggleLock()
00131 {
00132
00133 if (!corona()) {
00134 return;
00135 }
00136 QDBusInterface lockprocess("org.kde.screenlocker", "/LockProcess",
00137 "org.kde.screenlocker.LockProcess", QDBusConnection::sessionBus(), this);
00138 if (corona()->immutability() == Mutable) {
00139 corona()->setImmutability(UserImmutable);
00140 lockprocess.call(QDBus::NoBlock, "startLock");
00141 kDebug() << "blaaaaaaaaaaaaaaaaa!!!!";
00142 emit locked();
00143 } else if (corona()->immutability() == UserImmutable) {
00144 QList<QVariant> args;
00145 args << i18n("Unlock Plasma Widgets");
00146 bool sent = lockprocess.callWithCallback("checkPass", args, this, SLOT(unlock(QDBusMessage)), SLOT(dbusError(QDBusError)));
00147 kDebug() << sent;
00148 }
00149 }
00150
00151 void SaverDesktop::unlock(QDBusMessage reply)
00152 {
00153
00154 if (reply.arguments().isEmpty()) {
00155 kDebug() << "quit succeeded, I guess";
00156 return;
00157 }
00158 bool success = reply.arguments().first().toBool();
00159 kDebug() << success;
00160 if (success) {
00161 corona()->setImmutability(Mutable);
00162 emit unlocked();
00163 }
00164 }
00165
00166 void SaverDesktop::dbusError(QDBusError error)
00167 {
00168
00169 kDebug() << error.errorString(error.type());
00170 kDebug() << "bailing out";
00171
00172
00173 qApp->quit();
00174 }
00175
00176 void SaverDesktop::unlockDesktop()
00177 {
00178 QDBusInterface lockprocess("org.kde.screenlocker", "/LockProcess",
00179 "org.kde.screenlocker.LockProcess", QDBusConnection::sessionBus(), this);
00180 bool sent = (lockprocess.isValid() &&
00181 lockprocess.callWithCallback("quit", QList<QVariant>(), this, SLOT(unlock(QDBusMessage)), SLOT(dbusError(QDBusError))));
00182
00183
00184 if (!sent) {
00185
00186 kDebug() << "bailing out!";
00187 qApp->quit();
00188 }
00189 }
00190
00191 K_EXPORT_PLASMA_APPLET(saverdesktop, SaverDesktop)
00192
00193 #include "desktop.moc"