• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

Plasma

desktop.cpp

Go to the documentation of this file.
00001 /*
00002 *   Copyright 2007 by Aaron Seigo <aseigo@kde.org>
00003 *   Copyright 2008 by Chani Armitage <chanika@gmail.com>
00004 *
00005 *   This program is free software; you can redistribute it and/or modify
00006 *   it under the terms of the GNU Library General Public License version 2,
00007 *   or (at your option) any later version.
00008 *
00009 *   This program is distributed in the hope that it will be useful,
00010 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 *   GNU General Public License for more details
00013 *
00014 *   You should have received a copy of the GNU Library General Public
00015 *   License along with this program; if not, write to the
00016 *   Free Software Foundation, Inc.,
00017 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
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     //re-wire the lock action so we can check for a password
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     //remove the desktop actions
00061     //FIXME do we really need to removeToolBoxAction?
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     //TODO kbd shortcut
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     //rearrange the toolboxtools
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     //requre a password to unlock
00133     if (!corona()) {
00134         return; //I'm lazy, I know this'll never happen
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     //assuming everything went as expected
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(); //FIXME bad code
00163     }
00164 }
00165 
00166 void SaverDesktop::dbusError(QDBusError error)
00167 {
00168     //Q_UNUSED(error)
00169     kDebug() << error.errorString(error.type());
00170     kDebug() << "bailing out";
00171     //ok, now i care. if it was the quit call and it failed, we shouldn't leave the user stuck in
00172     //plasma-overlay forever.
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     //the unlock slot above is a dummy that should never be called.
00183     //somehow I need a valid reply slot or the error slot is never ever used.
00184     if (!sent) {
00185         //ah crud.
00186         kDebug() << "bailing out!";
00187         qApp->quit();
00188     }
00189 }
00190 
00191 K_EXPORT_PLASMA_APPLET(saverdesktop, SaverDesktop)
00192 
00193 #include "desktop.moc"

Plasma

Skip menu "Plasma"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • KWin
  •   KWin Libraries
  • Libraries
  •   libkworkspace
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal