diff -Nurp yaSDP.orig//plasma-yasdp.cpp yaSDP/plasma-yasdp.cpp
--- yaSDP.orig//plasma-yasdp.cpp 2010-08-25 12:18:23.000000000 +0200
+++ yaSDP/plasma-yasdp.cpp 2011-01-28 19:08:27.000000000 +0100
@@ -1,49 +1,57 @@
-// this is my first c++ code, as you can see. I know it's very ugly and long.
-//I''m going to read a few book, then I will clean this code
+// this is my first c++ code, as you can see. I know it's very ugly and long.
+//I''m going to read a few book, then I will clean this code
//P.S. there are a lot of strange things in there...
+#include <KMessageBox>
+#include <KJob>
+
+#include <QtDBus/QDBusInterface>
+#include <QtDBus/QDBusReply>
+
#include "plasma-yasdp.h"
#include <QPainter>
#include <QFontMetrics>
#include <QSizeF>
#include <QRect>
#include <QComboBox>
-
+
#include <plasma/svg.h>
#include <plasma/theme.h>
#include <KConfigDialog>
#include <KGlobalSettings>
#include "kworkspace/kworkspace.h"
-
-
-PlasmaYasdp::PlasmaYasdp(QObject *parent, const QVariantList &args)
- : Plasma::Applet(parent, args)
+PlasmaYasdp::PlasmaYasdp(QObject *parent, const QVariantList &args)
+ : Plasma::Applet(parent, args) {
-{
+ // Set all icon pointers to null to indicate there is no icon
+ shutdown.m_icon = NULL;
+ reboot.m_icon = NULL;
+ suspend.m_icon = NULL;
+ logout.m_icon = NULL;
+ hibernate.m_icon = NULL;
+ toscreen.m_icon = NULL;
+ loscreen.m_icon = NULL;
+ // Set up the plasmoid
setHasConfigurationInterface(true);
setAspectRatioMode(Plasma::IgnoreAspectRatio);
resize(429, 120);
-
}
-
-
-PlasmaYasdp::~PlasmaYasdp()
-{
-
- if (shutdown.iconexist == true) delete shutdown.m_icon;
- if (reboot.iconexist == true) delete reboot.m_icon;
- if (suspend.iconexist == true) delete suspend.m_icon;
- if (logout.iconexist == true) delete logout.m_icon;
- if (hibernate.iconexist == true) delete hibernate.m_icon;
- if (toscreen.iconexist == true) delete toscreen.m_icon;
- if (loscreen.iconexist == true) delete loscreen.m_icon;
+
+
+PlasmaYasdp::~PlasmaYasdp() {
+ if (shutdown.m_icon) shutdown.m_icon->deleteLater();
+ if (reboot.m_icon) reboot.m_icon->deleteLater();
+ if (suspend.m_icon) suspend.m_icon->deleteLater();
+ if (logout.m_icon) logout.m_icon->deleteLater();
+ if (hibernate.m_icon) hibernate.m_icon->deleteLater();
+ if (toscreen.m_icon) toscreen.m_icon->deleteLater();
+ if (loscreen.m_icon) loscreen.m_icon->deleteLater();
}
-
-void PlasmaYasdp::init()
-{
+
+void PlasmaYasdp::init() {
shutdown.deficonname = "system-shutdown";
reboot.deficonname = "system-reboot";
@@ -52,10 +60,10 @@ void PlasmaYasdp::init()
hibernate.deficonname = "system-suspend-hibernate";
toscreen.deficonname = "video-display";
loscreen.deficonname = "system-lock-screen";
-
+
//read config
KConfigGroup cg = config();
-
+
shutdown.iconname = cg.readEntry("sh-iconname", shutdown.deficonname);
reboot.iconname = cg.readEntry("re-iconname", reboot.deficonname);
suspend.iconname = cg.readEntry("su-iconname", suspend.deficonname);
@@ -72,25 +80,18 @@ void PlasmaYasdp::init()
loscreen.iconshow = cg.readEntry("loscreen-iconshow", true);
vlayout = cg.readEntry("vlayout", false);
askconf = cg.readEntry("askconf", true);
- background = cg.readEntry("background", 0);
-
- layout = new QGraphicsLinearLayout(this);
+ backgroundf( cg.readEntry("background", 0 ) );
+
+ layout = new QGraphicsLinearLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
- if (vlayout == 1) layout->setOrientation(Qt::Vertical);
- else layout->setOrientation(Qt::Horizontal);
-
- if (background == 0) setBackgroundHints(DefaultBackground);
- if (background == 1) setBackgroundHints(StandardBackground);
- if (background == 2) setBackgroundHints(TranslucentBackground);
- if (background == 3) setBackgroundHints(NoBackground);
-
- if (shutdown.iconshow == true) {
+ layout->setOrientation( vlayout ? Qt::Vertical : Qt::Horizontal );
+
+ if (shutdown.iconshow) {
shutdown.m_icon = new Plasma::IconWidget(KIcon(shutdown.iconname), QString(), this);
- shutdown.iconexist = true;
- layout->addItem(shutdown.m_icon);
-
- connect(shutdown.m_icon, SIGNAL(clicked()), this, SLOT(shutdownf()));
+ layout->addItem(shutdown.m_icon);
+
+ connect(shutdown.m_icon, SIGNAL(clicked()), this, SLOT(shutdownf()));
}
else {
QAction* shutdowna = new QAction(i18n("&Shutdown"), this);
@@ -98,58 +99,46 @@ void PlasmaYasdp::init()
m_actions.append(shutdowna);
connect(shutdowna, SIGNAL(triggered(bool)), SLOT(shutdownf()));
}
-
- if (reboot.iconshow == true) {
+
+ if (reboot.iconshow) {
reboot.m_icon = new Plasma::IconWidget(KIcon(reboot.iconname), QString(), this);
- reboot.iconexist = true;
- layout->addItem(reboot.m_icon);
-
-
+ layout->addItem(reboot.m_icon);
connect(reboot.m_icon, SIGNAL(clicked()), this, SLOT(rebootf()));
}
-
else {
QAction* reboota = new QAction(i18n("&Reboot"), this);
reboota->setIcon(KIcon(reboot.iconname));
m_actions.append(reboota);
connect(reboota, SIGNAL(triggered(bool)), SLOT(rebootf()));
}
-
- if (suspend.iconshow == true) {
+
+ if (suspend.iconshow) {
suspend.m_icon = new Plasma::IconWidget(KIcon(suspend.iconname), QString(), this);
- suspend.iconexist = true;
- layout->addItem(suspend.m_icon);
-
+ layout->addItem(suspend.m_icon);
connect(suspend.m_icon, SIGNAL(clicked()), this, SLOT(suspendf()));
}
-
else {
QAction* suspenda = new QAction(i18n("&Suspend"), this);
suspenda->setIcon(KIcon(suspend.iconname));
m_actions.append(suspenda);
connect(suspenda, SIGNAL(triggered(bool)), SLOT(suspendf()));
}
-
- if (logout.iconshow == true) {
+
+ if (logout.iconshow) {
logout.m_icon = new Plasma::IconWidget(KIcon(logout.iconname), QString(), this);
- logout.iconexist = true;
- layout->addItem(logout.m_icon);
-
+ layout->addItem(logout.m_icon);
connect(logout.m_icon, SIGNAL(clicked()), this, SLOT(logoutf()));
}
-
else {
QAction* logouta = new QAction(i18n("&Logout"), this);
logouta->setIcon(KIcon(logout.iconname));
m_actions.append(logouta);
connect(logouta, SIGNAL(triggered(bool)), SLOT(logoutf()));
}
-
- if (hibernate.iconshow == true) {
+
+ if (hibernate.iconshow) {
hibernate.m_icon = new Plasma::IconWidget(KIcon(hibernate.iconname), QString(), this);
- hibernate.iconexist = true;
layout->addItem(hibernate.m_icon);
-
connect(hibernate.m_icon, SIGNAL(clicked()), this, SLOT(hibernatef()));
}
else {
@@ -158,27 +147,23 @@ void PlasmaYasdp::init()
m_actions.append(hibernatea);
connect(hibernatea, SIGNAL(triggered(bool)), SLOT(hibernatef()));
}
-
- if (toscreen.iconshow == true) {
+
+ if (toscreen.iconshow) {
toscreen.m_icon = new Plasma::IconWidget(KIcon(toscreen.iconname), QString(), this);
- toscreen.iconexist = true;
- layout->addItem(toscreen.m_icon);
-
+ layout->addItem(toscreen.m_icon);
connect(toscreen.m_icon, SIGNAL(clicked()), this, SLOT(toscreenf()));
}
-
+
else {
QAction* toscreena = new QAction(i18n("&Turn off screen"), this);
toscreena->setIcon(KIcon(toscreen.iconname));
m_actions.append(toscreena);
connect(toscreena, SIGNAL(triggered(bool)), SLOT(toscreenf()));
}
-
- if (loscreen.iconshow == true) {
+
+ if (loscreen.iconshow) {
loscreen.m_icon = new Plasma::IconWidget(KIcon(loscreen.iconname), QString(), this);
- loscreen.iconexist = true;
layout->addItem(loscreen.m_icon);
-
connect(loscreen.m_icon, SIGNAL(clicked()), this, SLOT(loscreenf()));
}
else {
@@ -190,31 +175,25 @@ void PlasmaYasdp::init()
QAction* seperator = new QAction(this);
seperator->setSeparator(true);
-
+
}
-
-void PlasmaYasdp::paintInterface(QPainter *p,
- const QStyleOptionGraphicsItem *option, const QRect &contentsRect)
-{
+
+void PlasmaYasdp::paintInterface(QPainter *p, const QStyleOptionGraphicsItem *option, const QRect &contentsRect) {
Q_UNUSED( p );
Q_UNUSED( option );
Q_UNUSED( contentsRect );
-
}
-void PlasmaYasdp::createConfigurationInterface(KConfigDialog *parent)
-{
-
+void PlasmaYasdp::createConfigurationInterface(KConfigDialog *parent) {
//Appearance
QWidget *widgetAppear = new QWidget;
uiAppear.setupUi(widgetAppear);
-
uiAppear.kiconbutton->setIcon(KIcon(shutdown.iconname));
uiAppear.kiconbutton_2->setIcon(KIcon(reboot.iconname));
uiAppear.kiconbutton_3->setIcon(KIcon(suspend.iconname));
uiAppear.kiconbutton_4->setIcon(KIcon(logout.iconname));
- uiAppear.kiconbutton_5->setIcon(KIcon(hibernate.iconname));
+ uiAppear.kiconbutton_5->setIcon(KIcon(hibernate.iconname));
uiAppear.kiconbutton_6->setIcon(KIcon(toscreen.iconname));
uiAppear.kiconbutton_7->setIcon(KIcon(loscreen.iconname));
uiAppear.checkBox->setChecked(shutdown.iconshow);
@@ -227,22 +206,18 @@ void PlasmaYasdp::createConfigurationInt
uiAppear.checkBox_8->setChecked(toscreen.iconshow);
uiAppear.checkBox_9->setChecked(loscreen.iconshow);
uiAppear.comboBox->setCurrentIndex(background);
-
+
connect(uiAppear.comboBox, SIGNAL (currentIndexChanged (int)), this, SLOT(backgroundf(int)));
-
+
//add everything to the settings
connect(parent, SIGNAL(okClicked()), this, SLOT(configAccepted()));
parent->addPage(widgetAppear, i18n("Appearance"), QString("video-display"));
}
-void PlasmaYasdp::configAccepted()
-{
+void PlasmaYasdp::configAccepted() {
KConfigGroup cg = config();
-
- // Icons
-
-
+ // Icons
if (uiAppear.kiconbutton->icon() != "") {
shutdown.iconname = uiAppear.kiconbutton->icon(); }
if (uiAppear.kiconbutton_2->icon() != "") {
@@ -265,11 +240,11 @@ void PlasmaYasdp::configAccepted()
hibernate.iconshow = uiAppear.checkBox_5->isChecked();
toscreen.iconshow = uiAppear.checkBox_8->isChecked();
loscreen.iconshow = uiAppear.checkBox_9->isChecked();
-
+
//other config
vlayout = uiAppear.checkBox_6->isChecked();
askconf = uiAppear.checkBox_7->isChecked();
-
+
cg.writeEntry("sh-iconname", shutdown.iconname);
cg.writeEntry("re-iconname", reboot.iconname);
cg.writeEntry("su-iconname", suspend.iconname);
@@ -287,122 +262,93 @@ void PlasmaYasdp::configAccepted()
cg.writeEntry("vlayout", vlayout);
cg.writeEntry("askconf", askconf);
cg.writeEntry("background", background);
-
-
-
-
// apply change
-
if (vlayout == 1) {
- layout->setOrientation(Qt::Vertical);
- resize(120, 429); }
+ layout->setOrientation(Qt::Vertical);
+ resize(120, 429);
+ }
else {
- layout->setOrientation(Qt::Horizontal);
- resize(429, 120);}
-
- // when I spoke about very ugly code, I meant this:
+ layout->setOrientation(Qt::Horizontal);
+ resize(429, 120);
+ }
+
+ // when I spoke about very ugly code, I meant this:
m_actions.clear();
- if (shutdown.iconexist == true) {
- delete shutdown.m_icon;
- shutdown.iconexist = false;}
-
-
- if (reboot.iconexist == true) {
- delete reboot.m_icon;
- reboot.iconexist = false;}
-
- if (suspend.iconexist == true) {
- delete suspend.m_icon;
- suspend.iconexist = false;}
-
- if (logout.iconexist == true) {
- delete logout.m_icon;
- logout.iconexist = false;}
-
- if (hibernate.iconexist == true) {
- delete hibernate.m_icon;
- hibernate.iconexist = false;}
-
- if (toscreen.iconexist == true) {
- delete toscreen.m_icon;
- toscreen.iconexist = false;}
-
- if (loscreen.iconexist == true) {
- delete loscreen.m_icon;
- loscreen.iconexist = false;}
-
- if (shutdown.iconshow == true) {
-
- shutdown.m_icon = new Plasma::IconWidget(KIcon(shutdown.iconname), QString(), this);
- layout->addItem(shutdown.m_icon);
- shutdown.m_icon->setIcon(KIcon(shutdown.iconname));
- connect(shutdown.m_icon, SIGNAL(clicked()), this, SLOT(shutdownf()));
- shutdown.iconexist = true;
- }
- else {
- QAction* shutdowna = new QAction(i18n("&Shutdown"), this);
- shutdowna->setIcon(KIcon(shutdown.iconname));
- m_actions.append(shutdowna);
- connect(shutdowna, SIGNAL(triggered(bool)), SLOT(shutdownf()));
- }
-
-
- if (reboot.iconshow == true) {
+ if (shutdown.iconshow) {
+ if( shutdown.m_icon ) {
+ shutdown.m_icon->deleteLater();
+ }
+ shutdown.m_icon = new Plasma::IconWidget(KIcon(shutdown.iconname), QString(), this);
+ layout->addItem(shutdown.m_icon);
+ shutdown.m_icon->setIcon(KIcon(shutdown.iconname));
+ connect(shutdown.m_icon, SIGNAL(clicked()), this, SLOT(shutdownf()));
+ }
+ else {
+ QAction* shutdowna = new QAction(i18n("&Shutdown"), this);
+ shutdowna->setIcon(KIcon(shutdown.iconname));
+ m_actions.append(shutdowna);
+ connect(shutdowna, SIGNAL(triggered(bool)), SLOT(shutdownf()));
+ }
+
+ if (reboot.iconshow) {
+ if( reboot.m_icon ) {
+ reboot.m_icon->deleteLater();
+ }
reboot.m_icon = new Plasma::IconWidget(KIcon(reboot.iconname), QString(), this);
layout->addItem(reboot.m_icon);
reboot.m_icon->setIcon(KIcon(reboot.iconname));
connect(reboot.m_icon, SIGNAL(clicked()), this, SLOT(rebootf()));
- reboot.iconexist = true;
}
- else {
- QAction* reboota = new QAction(i18n("&Reboot"), this);
- reboota->setIcon(KIcon(reboot.iconname));
- m_actions.append(reboota);
- connect(reboota, SIGNAL(triggered(bool)), SLOT(rebootf()));
+ else {
+ QAction* reboota = new QAction(i18n("&Reboot"), this);
+ reboota->setIcon(KIcon(reboot.iconname));
+ m_actions.append(reboota);
+ connect(reboota, SIGNAL(triggered(bool)), SLOT(rebootf()));
}
-
- if (suspend.iconshow == true) {
-
+ if (suspend.iconshow) {
+ if( suspend.m_icon ) {
+ suspend.m_icon->deleteLater();
+ }
suspend.m_icon = new Plasma::IconWidget(KIcon(suspend.iconname), QString(), this);
layout->addItem(suspend.m_icon);
suspend.m_icon->setIcon(KIcon(suspend.iconname));
connect(suspend.m_icon, SIGNAL(clicked()), this, SLOT(suspendf()));
- suspend.iconexist = true;
}
- else {
- QAction* suspenda = new QAction(i18n("&Suspend"), this);
- suspenda->setIcon(KIcon(suspend.iconname));
- m_actions.append(suspenda);
- connect(suspenda, SIGNAL(triggered(bool)), SLOT(suspendf()));
+ else {
+ QAction* suspenda = new QAction(i18n("&Suspend"), this);
+ suspenda->setIcon(KIcon(suspend.iconname));
+ m_actions.append(suspenda);
+ connect(suspenda, SIGNAL(triggered(bool)), SLOT(suspendf()));
}
-
- if (logout.iconshow == true) {
-
+ if (logout.iconshow) {
+ if( logout.m_icon ) {
+ logout.m_icon->deleteLater();
+ }
logout.m_icon = new Plasma::IconWidget(KIcon(logout.iconname), QString(), this);
layout->addItem(logout.m_icon);
logout.m_icon->setIcon(KIcon(logout.iconname));
connect(logout.m_icon, SIGNAL(clicked()), this, SLOT(logoutf()));
- logout.iconexist = true;
}
- else {
- QAction* logouta = new QAction(i18n("&Logout"), this);
- logouta->setIcon(KIcon(logout.iconname));
- m_actions.append(logouta);
- connect(logouta, SIGNAL(triggered(bool)), SLOT(logoutf()));
+ else {
+ QAction* logouta = new QAction(i18n("&Logout"), this);
+ logouta->setIcon(KIcon(logout.iconname));
+ m_actions.append(logouta);
+ connect(logouta, SIGNAL(triggered(bool)), SLOT(logoutf()));
}
- if (hibernate.iconshow == true) {
-
+ if (hibernate.iconshow) {
+ if( hibernate.m_icon ) {
+ hibernate.m_icon->deleteLater();
+ }
hibernate.m_icon = new Plasma::IconWidget(KIcon(hibernate.iconname), QString(), this);
layout->addItem(hibernate.m_icon);
hibernate.m_icon->setIcon(KIcon(hibernate.iconname));
connect(hibernate.m_icon, SIGNAL(clicked()), this, SLOT(hibernatef()));
- hibernate.iconexist = true;
}
else {
QAction* hibernatea = new QAction(i18n("&Hibernate"), this);
@@ -410,114 +356,145 @@ void PlasmaYasdp::configAccepted()
m_actions.append(hibernatea);
connect(hibernatea, SIGNAL(triggered(bool)), SLOT(hibernatef()));
}
-
- if (toscreen.iconshow == true) {
+ if (toscreen.iconshow) {
+ if( toscreen.m_icon ) {
+ toscreen.m_icon->deleteLater();
+ }
toscreen.m_icon = new Plasma::IconWidget(KIcon(toscreen.iconname), QString(), this);
layout->addItem(toscreen.m_icon);
toscreen.m_icon->setIcon(KIcon(toscreen.iconname));
connect(toscreen.m_icon, SIGNAL(clicked()), this, SLOT(toscreenf()));
- toscreen.iconexist = true;
}
- else {
- QAction* toscreena = new QAction(i18n("&Turn off screen"), this);
- toscreena->setIcon(KIcon(toscreen.iconname));
- m_actions.append(toscreena);
- connect(toscreena, SIGNAL(triggered(bool)), SLOT(toscreenf()));
+ else {
+ QAction* toscreena = new QAction(i18n("&Turn off screen"), this);
+ toscreena->setIcon(KIcon(toscreen.iconname));
+ m_actions.append(toscreena);
+ connect(toscreena, SIGNAL(triggered(bool)), SLOT(toscreenf()));
}
- if (loscreen.iconshow == true) {
-
+ if (loscreen.iconshow) {
+ if( loscreen.m_icon ) {
+ loscreen.m_icon->deleteLater();
+ }
loscreen.m_icon = new Plasma::IconWidget(KIcon(loscreen.iconname), QString(), this);
layout->addItem(loscreen.m_icon);
loscreen.m_icon->setIcon(KIcon(loscreen.iconname));
connect(loscreen.m_icon, SIGNAL(clicked()), this, SLOT(loscreenf()));
- loscreen.iconexist = true;
}
else {
- QAction* loscreena = new QAction(i18n("&Lock screen"), this);
- loscreena->setIcon(KIcon(loscreen.iconname));
- m_actions.append(loscreena);
- connect(loscreena, SIGNAL(triggered(bool)), SLOT(loscreenf()));
+ QAction* loscreena = new QAction(i18n("&Lock screen"), this);
+ loscreena->setIcon(KIcon(loscreen.iconname));
+ m_actions.append(loscreena);
+ connect(loscreena, SIGNAL(triggered(bool)), SLOT(loscreenf()));
}
-
-
emit configNeedsSaving();
emit update();
}
void PlasmaYasdp::shutdownf() {
-if (askconf == 0) {
- KWorkSpace::requestShutDown(KWorkSpace::ShutdownConfirmNo,
- KWorkSpace::ShutdownTypeHalt ,
- KWorkSpace::ShutdownModeInteractive);
-}
-else {
- KWorkSpace::requestShutDown(KWorkSpace::ShutdownConfirmYes,
- KWorkSpace::ShutdownTypeHalt ,
- KWorkSpace::ShutdownModeInteractive);
-}
+ KWorkSpace::requestShutDown( askconf ? KWorkSpace::ShutdownConfirmYes : KWorkSpace::ShutdownConfirmNo,
+ KWorkSpace::ShutdownTypeHalt ,
+ KWorkSpace::ShutdownModeInteractive );
}
void PlasmaYasdp::rebootf() {
-if (askconf == 0) {
- KWorkSpace::requestShutDown(KWorkSpace::ShutdownConfirmNo,
- KWorkSpace::ShutdownTypeReboot ,
- KWorkSpace::ShutdownModeInteractive);
-}
-else {
- KWorkSpace::requestShutDown(KWorkSpace::ShutdownConfirmYes,
- KWorkSpace::ShutdownTypeReboot ,
- KWorkSpace::ShutdownModeInteractive);
-}
-}
-void PlasmaYasdp::suspendf() {
- system("qdbus org.kde.kded /modules/powerdevil suspend 2");
-}
-void PlasmaYasdp::logoutf() {
-if (askconf == 0) {
- KWorkSpace::requestShutDown(KWorkSpace::ShutdownConfirmNo,
- KWorkSpace::ShutdownTypeNone ,
- KWorkSpace::ShutdownModeInteractive);
-}
-else {
- KWorkSpace::requestShutDown(KWorkSpace::ShutdownConfirmYes,
- KWorkSpace::ShutdownTypeNone ,
- KWorkSpace::ShutdownModeInteractive);
+ KWorkSpace::requestShutDown( askconf ? KWorkSpace::ShutdownConfirmYes : KWorkSpace::ShutdownConfirmNo,
+ KWorkSpace::ShutdownTypeReboot ,
+ KWorkSpace::ShutdownModeInteractive );
}
+
+void PlasmaYasdp::suspendf()
+{
+ if( askconf && KMessageBox::questionYesNo(0,
+ i18n("Do you want to suspend to RAM (sleep)?"),
+ i18n("Suspend") ) != KMessageBox::Yes) {
+ return;
+ }
+ system("qdbus org.kde.kded /modules/powerdevil suspend 2");
+//TODO: Use the above original code line until a kde-4.6-compatible and better way is found!
+/*
+ // Check if powerdevil is running, and use its methods to suspend if available
+ // otherwise go through Solid directly
+ QStringList modules;
+ QDBusInterface kdedInterface("org.kde.kded", "/kded", "org.kde.kded");
+ QDBusReply<QStringList> reply = kdedInterface.call("loadedModules");
+ if (reply.isValid() && reply.value().contains("powerdevil")) {
+ kDebug() << "Using powerdevil to suspend";
+ QDBusConnection dbus(QDBusConnection::sessionBus());
+ QDBusInterface iface("org.kde.kded", "/modules/powerdevil", "org.kde.PowerDevil", dbus);
+ iface.call("suspend", Solid::Control::PowerManager::ToRam);
+ } else {
+ kDebug() << "Powerdevil not available, using solid to suspend";
+ KJob * job = Solid::Control::PowerManager::suspend(Solid::Control::PowerManager::ToRam);
+ job->start();
+ }
+*/
+ }
+
+void PlasmaYasdp::logoutf() {
+ KWorkSpace::requestShutDown( askconf ? KWorkSpace::ShutdownConfirmYes : KWorkSpace::ShutdownConfirmNo,
+ KWorkSpace::ShutdownTypeNone ,
+ KWorkSpace::ShutdownModeInteractive );
}
- void PlasmaYasdp::hibernatef() {
+void PlasmaYasdp::hibernatef()
+{
+ if ( askconf && KMessageBox::questionYesNo( 0,
+ i18n("Do you want to suspend to disk (hibernate)?"),
+ i18n("Suspend") ) != KMessageBox::Yes) {
+ return;
+ }
system("qdbus org.kde.kded /modules/powerdevil suspend 4");
-}
+//TODO: Use the above original code line until a kde-4.6-compatible and better way is found!
+/*
+ // Check if powerdevil is running, and use its methods to hibernate if available
+ // otherwise go through Solid directly
+ QStringList modules;
+ QDBusInterface kdedInterface("org.kde.kded", "/kded", "org.kde.kded");
+ QDBusReply<QStringList> reply = kdedInterface.call("loadedModules");
+ if (reply.isValid() && reply.value().contains("powerdevil")) {
+ kDebug() << "Using powerdevil to hibernate";
+ QDBusConnection dbus(QDBusConnection::sessionBus());
+ QDBusInterface iface("org.kde.kded", "/modules/powerdevil", "org.kde.PowerDevil", dbus);
+ iface.call("suspend", Solid::Control::PowerManager::ToDisk);
+ } else {
+ kDebug() << "Powerdevil not available, using solid to hibernate";
+ KJob * job = Solid::Control::PowerManager::suspend(Solid::Control::PowerManager::ToDisk);
+ job->start();
+ }
+*/
+}
-void PlasmaYasdp::toscreenf() {
-system("xset dpms force off");
+void PlasmaYasdp::toscreenf() {
+ system("xset dpms force off");
}
-void PlasmaYasdp::loscreenf() {
+void PlasmaYasdp::loscreenf() {
system("qdbus org.freedesktop.ScreenSaver /ScreenSaver Lock");
-}
+}
void PlasmaYasdp::backgroundf(const int &ca) {
- if (ca == 0) {
- background = 0;
- setBackgroundHints(DefaultBackground);
- }
- if (ca == 1) {
- background = 1;
- setBackgroundHints(StandardBackground);
- }
- if (ca == 2) {
- background = 2;
- setBackgroundHints(TranslucentBackground);
- }
- if (ca == 3) {
- background = 3;
- setBackgroundHints(NoBackground);
- }
+ switch( ca ) {
+ case 1:
+ setBackgroundHints(StandardBackground);
+ background = ca;
+ break;
+ case 2:
+ setBackgroundHints(TranslucentBackground);
+ background = ca;
+ break;
+ case 3:
+ setBackgroundHints(NoBackground);
+ background = ca;
+ break;
+ default:
+ setBackgroundHints(DefaultBackground);
+ background = 0;
+ break;
+ }
}
QList<QAction*> PlasmaYasdp::contextualActions()
@@ -525,8 +502,8 @@ QList<QAction*> PlasmaYasdp::contextualA
return m_actions;
}
-
+
// This is the command that links your applet to the .desktop file
K_EXPORT_PLASMA_APPLET(yasdp, PlasmaYasdp)
-
+
#include "plasma-yasdp.moc"
\ No newline at end of file
diff -Nurp yaSDP.orig//plasma-yasdp.h yaSDP/plasma-yasdp.h
--- yaSDP.orig//plasma-yasdp.h 2010-08-20 21:01:37.000000000 +0200
+++ yaSDP/plasma-yasdp.h 2011-01-28 18:51:48.000000000 +0100
@@ -7,16 +7,16 @@
// We need the Plasma Applet headers
#include <KIcon>
-
+
#include <Plasma/Applet>
#include <Plasma/Svg>
#include <plasma/widgets/iconwidget.h>
#include <plasma/widgets/label.h>
#include "ui_AppearanceConfig.h"
-
+
class QSizeF;
-
+
// Define our plasma Applet
class PlasmaYasdp : public Plasma::Applet
{
@@ -25,15 +25,15 @@ class PlasmaYasdp : public Plasma::Apple
// Basic Create/Destroy
PlasmaYasdp(QObject *parent, const QVariantList &args);
~PlasmaYasdp();
-
+
// The paintInterface procedure paints the applet to screen
void paintInterface(QPainter *p,
const QStyleOptionGraphicsItem *option,
const QRect& contentsRect);
void init();
-
-
+
+
public slots:
void configAccepted();
@@ -49,22 +49,21 @@ class PlasmaYasdp : public Plasma::Apple
protected:
void createConfigurationInterface(KConfigDialog *parent);
QList<QAction*> contextualActions();
-
+
private:
-
+
Ui::AppearanceConfig uiAppear;
Plasma::Svg m_svg;
-
+
typedef struct {
Plasma::IconWidget *m_icon;
QString iconname;
QString deficonname;
bool iconshow;
- bool iconexist;
} icon;
-
+
icon shutdown;
icon reboot;
icon suspend;
@@ -79,7 +78,7 @@ class PlasmaYasdp : public Plasma::Apple
QList<QAction*> m_actions;
QGraphicsLinearLayout *layout;
-
+
};
-
+
#endif
\ No newline at end of file