• Skip to content
  • Skip to link menu
KDE 4.2 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/IconWidget>
00024 
00025 // Qt
00026 #include <QtGui/QWidget> // QWIDGETSIZE_MAX
00027 #include <QtDBus/QDBusInterface>
00028 #include <QtDBus/QDBusReply>
00029 #include <QGraphicsLinearLayout>
00030 
00031 // KDE
00032 #include <KIcon>
00033 #ifndef Q_OS_WIN
00034 #include <kworkspace/kworkspace.h>
00035 #include <screensaver_interface.h>
00036 #endif
00037 
00038 // Windows
00039 #ifdef Q_OS_WIN
00040 #define _WIN32_WINNT 0x0500 // require NT 5.0 (win 2k pro)
00041 #include <windows.h>
00042 #endif // Q_OS_WIN
00043 
00044 static const int MINBUTTONSIZE = 8;
00045 static const int MARGINSIZE = 2;
00046 
00047 LockOut::LockOut(QObject *parent, const QVariantList &args)
00048     : Plasma::Applet(parent, args)
00049 {
00050     resize(MINBUTTONSIZE, MINBUTTONSIZE * 2 + MARGINSIZE);
00051 }
00052 
00053 void LockOut::init()
00054 {
00055     m_layout = new QGraphicsLinearLayout(this);
00056     m_layout->setContentsMargins(0,0,0,0);
00057     m_layout->setSpacing(0);
00058 
00059     Plasma::IconWidget *icon_lock = new Plasma::IconWidget(KIcon("system-lock-screen"), "", this);
00060     m_layout->addItem(icon_lock);
00061     connect(icon_lock, SIGNAL(clicked()), this, SLOT(clickLock()));
00062 #ifndef Q_OS_WIN
00063     Plasma::IconWidget *icon_logout = new Plasma::IconWidget(KIcon("system-shutdown"), "", this);
00064     m_layout->addItem(icon_logout);
00065     connect(icon_logout, SIGNAL(clicked()), this, SLOT(clickLogout()));
00066 #endif
00067 }
00068 
00069 LockOut::~LockOut()
00070 {
00071 }
00072 
00073 void LockOut::checkLayout()
00074 {
00075     Qt::Orientation direction;
00076     qreal ratioToKeep = 2;
00077 
00078     switch (formFactor()) {
00079         case Plasma::Vertical:
00080             if (geometry().width() >= MINBUTTONSIZE * 2 + MARGINSIZE) {
00081                 direction = Qt::Horizontal;
00082                 ratioToKeep = 2;
00083             } else {
00084                 direction = Qt::Vertical;
00085                 ratioToKeep = 0.5;
00086             }
00087             break;
00088         case Plasma::Horizontal:
00089             if (geometry().height() >= MINBUTTONSIZE * 2 + MARGINSIZE) {
00090                 direction = Qt::Vertical;
00091                 ratioToKeep = 0.5;
00092             } else {
00093                 direction = Qt::Horizontal;
00094                 ratioToKeep = 2;
00095             }
00096             break;
00097         default:
00098             direction = Qt::Vertical;
00099     }
00100 
00101     if (direction == Qt::Horizontal) {
00102         setMinimumSize(MINBUTTONSIZE * 2 + MARGINSIZE, MINBUTTONSIZE);
00103     } else {
00104         setMinimumSize(MINBUTTONSIZE, MINBUTTONSIZE * 2 + MARGINSIZE);
00105     }
00106 
00107     if (direction != m_layout->orientation()) {
00108         m_layout->setOrientation(direction);
00109     }
00110 
00111     if (formFactor() == Plasma::Horizontal) {
00112         setSizePolicy(QSizePolicy(QSizePolicy::Maximum, QSizePolicy::Expanding));
00113         qreal wsize = size().height() * ratioToKeep;
00114         setMaximumSize(wsize, QWIDGETSIZE_MAX);
00115     } else if (formFactor() == Plasma::Vertical) {
00116         setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum));
00117         qreal hsize = size().width() / ratioToKeep;
00118         setMaximumSize(QWIDGETSIZE_MAX, hsize);
00119     } else {
00120         setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
00121     }
00122 }
00123 
00124 void LockOut::constraintsEvent(Plasma::Constraints constraints)
00125 {
00126     if (constraints & Plasma::FormFactorConstraint ||
00127         constraints & Plasma::SizeConstraint) {
00128         checkLayout();
00129     }
00130 }
00131 
00132 void LockOut::clickLock()
00133 {
00134     kDebug()<<"LockOut:: lock clicked ";
00135 
00136 #ifndef Q_OS_WIN
00137     QString interface("org.freedesktop.ScreenSaver");
00138     org::freedesktop::ScreenSaver screensaver(interface, "/ScreenSaver",
00139                                               QDBusConnection::sessionBus());
00140     if (screensaver.isValid()) {
00141         screensaver.Lock();
00142     }
00143 #else
00144     LockWorkStation();
00145 #endif // !Q_OS_WIN
00146 }
00147 
00148 void LockOut::clickLogout()
00149 {
00150     kDebug()<<"LockOut:: logout clicked ";
00151 #ifndef Q_OS_WIN
00152     KWorkSpace::requestShutDown( KWorkSpace::ShutdownConfirmDefault,
00153                                  KWorkSpace::ShutdownTypeDefault,
00154                                  KWorkSpace::ShutdownModeDefault);
00155 #endif
00156 }
00157 
00158 
00159 #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
  •   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