Applets
lockout.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 "lockout.h"
00021
00022
00023 #include <plasma/widgets/icon.h>
00024
00025
00026 #include <QtDBus/QDBusInterface>
00027 #include <QtDBus/QDBusReply>
00028 #include <QGraphicsLinearLayout>
00029
00030
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"