1 /***************************************************************************
2 * Copyright (C) 2007 by Alexis Ménard <darktears31@gmail.com> *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
18 ***************************************************************************/
23 #include <plasma/layouts/vboxlayout.h>
24 #include <plasma/widgets/icon.h>
27 #include <QtDBus/QDBusInterface>
28 #include <QtDBus/QDBusReply>
32 #include <kworkspace/kworkspace.h>
33 #include <ksmserver_interface.h>
34 #include <screensaver_interface.h>
38 LockOut::LockOut(QObject
*parent
, const QVariantList
&args
)
39 : Plasma::Applet(parent
, args
)
45 m_layout
= new Plasma::BoxLayout(Plasma::BoxLayout::TopToBottom
, this);
46 m_layout
->setMargin(0);
47 m_layout
->setSpacing(0);
49 Plasma::Icon
*icon_lock
= new Plasma::Icon(KIcon("system-lock-screen"), "", this);
50 m_layout
->addItem(icon_lock
);
51 connect(icon_lock
, SIGNAL(clicked()), this, SLOT(clickLock()));
53 Plasma::Icon
*icon_logout
= new Plasma::Icon(KIcon("system-log-out"), "", this);
54 m_layout
->addItem(icon_logout
);
55 connect(icon_logout
, SIGNAL(clicked()), this, SLOT(clickLogout()));
57 //It seems the layout geometry must be calculated by hand for the first time
58 m_layout
->setGeometry(QRectF(0,0, contentSize().width(), contentSize().height()));
66 void LockOut::checkLayout()
68 Plasma::BoxLayout::Direction direction
;
70 switch (formFactor()) {
71 case Plasma::Vertical
:
72 if (contentSize().width() >= MINSIZE
) {
73 direction
= Plasma::BoxLayout::LeftToRight
;
75 direction
= Plasma::BoxLayout::TopToBottom
;
78 case Plasma::Horizontal
:
79 if (contentSize().height() >= MINSIZE
) {
80 direction
= Plasma::BoxLayout::TopToBottom
;
82 direction
= Plasma::BoxLayout::LeftToRight
;
86 direction
= Plasma::BoxLayout::TopToBottom
;
88 if (direction
!= m_layout
->direction()) {
89 m_layout
->setDirection(direction
);
94 void LockOut::constraintsUpdated(Plasma::Constraints constraints
)
96 if (constraints
& Plasma::FormFactorConstraint
||
97 constraints
& Plasma::SizeConstraint
) {
102 QSizeF
LockOut::contentSizeHint() const
104 QSizeF sizeHint
= contentSize();
105 switch (formFactor()) {
106 case Plasma::Vertical
:
107 if (sizeHint
.width() >= MINSIZE
) {
108 sizeHint
.setHeight(sizeHint
.width() / 2);
110 sizeHint
.setHeight(sizeHint
.width() * 2);
113 case Plasma::Horizontal
:
114 if (sizeHint
.height() >= MINSIZE
) {
115 sizeHint
.setHeight(sizeHint
.height() / 2);
117 sizeHint
.setHeight(sizeHint
.height() * 2);
121 //totally arbitrary size
122 if (sizeHint
.width() < 10) {
123 sizeHint
= QSizeF(48,96);
130 Qt::Orientations
LockOut::expandingDirections() const
135 void LockOut::clickLock()
137 kDebug()<<"LockOut:: lock clicked ";
139 QString
interface("org.freedesktop.ScreenSaver");
140 org::freedesktop::ScreenSaver
screensaver(interface
, "/ScreenSaver",
141 QDBusConnection::sessionBus());
142 if (screensaver
.isValid()) {
147 void LockOut::clickLogout()
149 kDebug()<<"LockOut:: logout clicked ";
150 QString
interface("org.kde.ksmserver");
151 org::kde::KSMServerInterface
smserver(interface
, "/KSMServer",
152 QDBusConnection::sessionBus());
153 if (smserver
.isValid()) {
154 smserver
.logout(KWorkSpace::ShutdownConfirmDefault
,
155 KWorkSpace::ShutdownTypeDefault
,
156 KWorkSpace::ShutdownModeDefault
);
161 #include "lockout.moc"