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

Applets

lockout.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2007 by Alexis Ménard <darktears31@gmail.com>           *
00003  *                                                                         *
00004  *   This program is free software; you can redistribute it and/or modify  *
00005  *   it under the terms of the GNU General Public License as published by  *
00006  *   the Free Software Foundation; either version 2 of the License, or     *
00007  *   (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 General Public License     *
00015  *   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 "lockout.h"
00021 
00022 // Plasma
00023 #include <plasma/widgets/icon.h>
00024 
00025 // Qt
00026 #include <QtDBus/QDBusInterface>
00027 #include <QtDBus/QDBusReply>
00028 #include <QGraphicsLinearLayout>
00029 
00030 // KDE
00031 #include <KIcon>
00032 #include <kworkspace/kworkspace.h>
00033 #include <screensaver_interface.h>
00034 
00035 #define MINSIZE 48
00036 
00037 LockOut::LockOut(QObject *parent, const QVariantList &args)
00038     : Plasma::Applet(parent, args)
00039 {
00040     resize(MINSIZE*2,MINSIZE*4);
00041 }
00042 
00043 void LockOut::init()
00044 {
00045     m_layout = new QGraphicsLinearLayout(this);
00046     m_layout->setContentsMargins(0,0,0,0);
00047     m_layout->setSpacing(0);
00048 
00049     Plasma::Icon *icon_lock = new Plasma::Icon(KIcon("system-lock-screen"), "", this);
00050     m_layout->addItem(icon_lock);
00051     connect(icon_lock, SIGNAL(clicked()), this, SLOT(clickLock()));
00052 
00053     Plasma::Icon *icon_logout = new Plasma::Icon(KIcon("system-shutdown"), "", this);
00054     m_layout->addItem(icon_logout);
00055     connect(icon_logout, SIGNAL(clicked()), this, SLOT(clickLogout()));
00056 }
00057 
00058 LockOut::~LockOut()
00059 {
00060 }
00061 
00062 void LockOut::checkLayout()
00063 {
00064     Qt::Orientation direction;
00065     qreal ratioToKeep = 2;
00066 
00067     switch (formFactor()) {
00068         case Plasma::Vertical:
00069             if (geometry().width() >= MINSIZE) {
00070                 direction = Qt::Horizontal;
00071                 ratioToKeep = 2;
00072             } else {
00073                 direction = Qt::Vertical;
00074                 ratioToKeep = 0.5;
00075             }
00076             break;
00077         case Plasma::Horizontal:
00078             if (geometry().height() >= MINSIZE) {
00079                 direction = Qt::Vertical;
00080                 ratioToKeep = 0.5;
00081             } else {
00082                 direction = Qt::Horizontal;
00083                 ratioToKeep = 2;
00084             }
00085             break;
00086         default:
00087             direction = Qt::Vertical;
00088     }
00089     if (direction != m_layout->orientation()) {
00090         m_layout->setOrientation(direction);
00091     }
00092 
00093     if (formFactor() == Plasma::Horizontal) {
00094         setSizePolicy(QSizePolicy(QSizePolicy::Maximum, QSizePolicy::Expanding));
00095         qreal wsize = size().height() * ratioToKeep;
00096         setMaximumSize(wsize, QWIDGETSIZE_MAX);
00097     } else if (formFactor() == Plasma::Vertical) {
00098         setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum));
00099         qreal hsize = size().width() / ratioToKeep;
00100         setMaximumSize(QWIDGETSIZE_MAX, hsize);
00101     } else {
00102         setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
00103     }
00104 }
00105 
00106 void LockOut::constraintsEvent(Plasma::Constraints constraints)
00107 {
00108     if (constraints & Plasma::FormFactorConstraint ||
00109         constraints & Plasma::SizeConstraint) {
00110         checkLayout();
00111     }
00112 }
00113 
00114 void LockOut::clickLock()
00115 {
00116     kDebug()<<"LockOut:: lock clicked ";
00117 
00118     QString interface("org.freedesktop.ScreenSaver");
00119     org::freedesktop::ScreenSaver screensaver(interface, "/ScreenSaver",
00120                                               QDBusConnection::sessionBus());
00121     if (screensaver.isValid()) {
00122         screensaver.Lock();
00123     }
00124 }
00125 
00126 void LockOut::clickLogout()
00127 {
00128     kDebug()<<"LockOut:: logout clicked ";
00129     KWorkSpace::requestShutDown( KWorkSpace::ShutdownConfirmDefault,
00130                                  KWorkSpace::ShutdownTypeDefault,
00131                                  KWorkSpace::ShutdownModeDefault);
00132 }
00133 
00134 
00135 #include "lockout.moc"

Applets

Skip menu "Applets"
  • 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
  •   libplasma
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.4
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