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/IconWidget>
26 #include <QtGui/QWidget> // QWIDGETSIZE_MAX
27 #include <QtDBus/QDBusInterface>
28 #include <QtDBus/QDBusReply>
29 #include <QGraphicsLinearLayout>
34 #include <kworkspace/kworkspace.h>
35 #include <screensaver_interface.h>
40 #define _WIN32_WINNT 0x0500 // require NT 5.0 (win 2k pro)
44 static const int MINBUTTONSIZE
= 8;
45 static const int MARGINSIZE
= 2;
47 LockOut::LockOut(QObject
*parent
, const QVariantList
&args
)
48 : Plasma::Applet(parent
, args
)
50 resize(MINBUTTONSIZE
, MINBUTTONSIZE
* 2 + MARGINSIZE
);
55 m_layout
= new QGraphicsLinearLayout(this);
56 m_layout
->setContentsMargins(0,0,0,0);
57 m_layout
->setSpacing(0);
59 Plasma::IconWidget
*icon_lock
= new Plasma::IconWidget(KIcon("system-lock-screen"), "", this);
60 m_layout
->addItem(icon_lock
);
61 connect(icon_lock
, SIGNAL(clicked()), this, SLOT(clickLock()));
63 Plasma::IconWidget
*icon_logout
= new Plasma::IconWidget(KIcon("system-shutdown"), "", this);
64 m_layout
->addItem(icon_logout
);
65 connect(icon_logout
, SIGNAL(clicked()), this, SLOT(clickLogout()));
73 void LockOut::checkLayout()
75 Qt::Orientation direction
;
76 qreal ratioToKeep
= 2;
78 switch (formFactor()) {
79 case Plasma::Vertical
:
80 if (geometry().width() >= MINBUTTONSIZE
* 2 + MARGINSIZE
) {
81 direction
= Qt::Horizontal
;
84 direction
= Qt::Vertical
;
88 case Plasma::Horizontal
:
89 if (geometry().height() >= MINBUTTONSIZE
* 2 + MARGINSIZE
) {
90 direction
= Qt::Vertical
;
93 direction
= Qt::Horizontal
;
98 direction
= Qt::Vertical
;
101 if (direction
== Qt::Horizontal
) {
102 setMinimumSize(MINBUTTONSIZE
* 2 + MARGINSIZE
, MINBUTTONSIZE
);
104 setMinimumSize(MINBUTTONSIZE
, MINBUTTONSIZE
* 2 + MARGINSIZE
);
107 if (direction
!= m_layout
->orientation()) {
108 m_layout
->setOrientation(direction
);
111 if (formFactor() == Plasma::Horizontal
) {
112 setSizePolicy(QSizePolicy(QSizePolicy::Maximum
, QSizePolicy::Expanding
));
113 qreal wsize
= size().height() * ratioToKeep
;
114 setMaximumSize(wsize
, QWIDGETSIZE_MAX
);
115 } else if (formFactor() == Plasma::Vertical
) {
116 setSizePolicy(QSizePolicy(QSizePolicy::Expanding
, QSizePolicy::Maximum
));
117 qreal hsize
= size().width() / ratioToKeep
;
118 setMaximumSize(QWIDGETSIZE_MAX
, hsize
);
120 setMaximumSize(QWIDGETSIZE_MAX
, QWIDGETSIZE_MAX
);
124 void LockOut::constraintsEvent(Plasma::Constraints constraints
)
126 if (constraints
& Plasma::FormFactorConstraint
||
127 constraints
& Plasma::SizeConstraint
) {
132 void LockOut::clickLock()
134 kDebug()<<"LockOut:: lock clicked ";
137 QString
interface("org.freedesktop.ScreenSaver");
138 org::freedesktop::ScreenSaver
screensaver(interface
, "/ScreenSaver",
139 QDBusConnection::sessionBus());
140 if (screensaver
.isValid()) {
148 void LockOut::clickLogout()
150 kDebug()<<"LockOut:: logout clicked ";
152 KWorkSpace::requestShutDown( KWorkSpace::ShutdownConfirmDefault
,
153 KWorkSpace::ShutdownTypeDefault
,
154 KWorkSpace::ShutdownModeDefault
);
159 #include "lockout.moc"