updated on Wed Jan 25 16:08:47 UTC 2012
[aur-mirror.git] / yasdp / fixes.patch
blob033a3121fc840b3283c6efea890fd72aeadb16f8
1 diff -Nurp yaSDP.orig//plasma-yasdp.cpp yaSDP/plasma-yasdp.cpp
2 --- yaSDP.orig//plasma-yasdp.cpp 2010-08-25 12:18:23.000000000 +0200
3 +++ yaSDP/plasma-yasdp.cpp 2011-01-28 19:08:27.000000000 +0100
4 @@ -1,49 +1,57 @@
5 -// this is my first c++ code, as you can see. I know it's very ugly and long.
6 -//I''m going to read a few book, then I will clean this code
7 +// this is my first c++ code, as you can see. I know it's very ugly and long.
8 +//I''m going to read a few book, then I will clean this code
9 //P.S. there are a lot of strange things in there...
11 +#include <KMessageBox>
12 +#include <KJob>
14 +#include <QtDBus/QDBusInterface>
15 +#include <QtDBus/QDBusReply>
17 #include "plasma-yasdp.h"
18 #include <QPainter>
19 #include <QFontMetrics>
20 #include <QSizeF>
21 #include <QRect>
22 #include <QComboBox>
25 #include <plasma/svg.h>
26 #include <plasma/theme.h>
28 #include <KConfigDialog>
29 #include <KGlobalSettings>
30 #include "kworkspace/kworkspace.h"
33 -PlasmaYasdp::PlasmaYasdp(QObject *parent, const QVariantList &args)
34 - : Plasma::Applet(parent, args)
36 +PlasmaYasdp::PlasmaYasdp(QObject *parent, const QVariantList &args)
37 + : Plasma::Applet(parent, args) {
40 + // Set all icon pointers to null to indicate there is no icon
41 + shutdown.m_icon = NULL;
42 + reboot.m_icon = NULL;
43 + suspend.m_icon = NULL;
44 + logout.m_icon = NULL;
45 + hibernate.m_icon = NULL;
46 + toscreen.m_icon = NULL;
47 + loscreen.m_icon = NULL;
49 + // Set up the plasmoid
50 setHasConfigurationInterface(true);
51 setAspectRatioMode(Plasma::IgnoreAspectRatio);
52 resize(429, 120);
57 -PlasmaYasdp::~PlasmaYasdp()
60 - if (shutdown.iconexist == true) delete shutdown.m_icon;
61 - if (reboot.iconexist == true) delete reboot.m_icon;
62 - if (suspend.iconexist == true) delete suspend.m_icon;
63 - if (logout.iconexist == true) delete logout.m_icon;
64 - if (hibernate.iconexist == true) delete hibernate.m_icon;
65 - if (toscreen.iconexist == true) delete toscreen.m_icon;
66 - if (loscreen.iconexist == true) delete loscreen.m_icon;
69 +PlasmaYasdp::~PlasmaYasdp() {
70 + if (shutdown.m_icon) shutdown.m_icon->deleteLater();
71 + if (reboot.m_icon) reboot.m_icon->deleteLater();
72 + if (suspend.m_icon) suspend.m_icon->deleteLater();
73 + if (logout.m_icon) logout.m_icon->deleteLater();
74 + if (hibernate.m_icon) hibernate.m_icon->deleteLater();
75 + if (toscreen.m_icon) toscreen.m_icon->deleteLater();
76 + if (loscreen.m_icon) loscreen.m_icon->deleteLater();
79 -void PlasmaYasdp::init()
82 +void PlasmaYasdp::init() {
84 shutdown.deficonname = "system-shutdown";
85 reboot.deficonname = "system-reboot";
86 @@ -52,10 +60,10 @@ void PlasmaYasdp::init()
87 hibernate.deficonname = "system-suspend-hibernate";
88 toscreen.deficonname = "video-display";
89 loscreen.deficonname = "system-lock-screen";
92 //read config
93 KConfigGroup cg = config();
96 shutdown.iconname = cg.readEntry("sh-iconname", shutdown.deficonname);
97 reboot.iconname = cg.readEntry("re-iconname", reboot.deficonname);
98 suspend.iconname = cg.readEntry("su-iconname", suspend.deficonname);
99 @@ -72,25 +80,18 @@ void PlasmaYasdp::init()
100 loscreen.iconshow = cg.readEntry("loscreen-iconshow", true);
101 vlayout = cg.readEntry("vlayout", false);
102 askconf = cg.readEntry("askconf", true);
103 - background = cg.readEntry("background", 0);
105 - layout = new QGraphicsLinearLayout(this);
106 + backgroundf( cg.readEntry("background", 0 ) );
108 + layout = new QGraphicsLinearLayout(this);
109 layout->setContentsMargins(0, 0, 0, 0);
110 layout->setSpacing(0);
111 - if (vlayout == 1) layout->setOrientation(Qt::Vertical);
112 - else layout->setOrientation(Qt::Horizontal);
114 - if (background == 0) setBackgroundHints(DefaultBackground);
115 - if (background == 1) setBackgroundHints(StandardBackground);
116 - if (background == 2) setBackgroundHints(TranslucentBackground);
117 - if (background == 3) setBackgroundHints(NoBackground);
119 - if (shutdown.iconshow == true) {
120 + layout->setOrientation( vlayout ? Qt::Vertical : Qt::Horizontal );
122 + if (shutdown.iconshow) {
123 shutdown.m_icon = new Plasma::IconWidget(KIcon(shutdown.iconname), QString(), this);
124 - shutdown.iconexist = true;
125 - layout->addItem(shutdown.m_icon);
127 - connect(shutdown.m_icon, SIGNAL(clicked()), this, SLOT(shutdownf()));
128 + layout->addItem(shutdown.m_icon);
130 + connect(shutdown.m_icon, SIGNAL(clicked()), this, SLOT(shutdownf()));
132 else {
133 QAction* shutdowna = new QAction(i18n("&Shutdown"), this);
134 @@ -98,58 +99,46 @@ void PlasmaYasdp::init()
135 m_actions.append(shutdowna);
136 connect(shutdowna, SIGNAL(triggered(bool)), SLOT(shutdownf()));
139 - if (reboot.iconshow == true) {
141 + if (reboot.iconshow) {
142 reboot.m_icon = new Plasma::IconWidget(KIcon(reboot.iconname), QString(), this);
143 - reboot.iconexist = true;
144 - layout->addItem(reboot.m_icon);
147 + layout->addItem(reboot.m_icon);
148 connect(reboot.m_icon, SIGNAL(clicked()), this, SLOT(rebootf()));
151 else {
152 QAction* reboota = new QAction(i18n("&Reboot"), this);
153 reboota->setIcon(KIcon(reboot.iconname));
154 m_actions.append(reboota);
155 connect(reboota, SIGNAL(triggered(bool)), SLOT(rebootf()));
158 - if (suspend.iconshow == true) {
160 + if (suspend.iconshow) {
161 suspend.m_icon = new Plasma::IconWidget(KIcon(suspend.iconname), QString(), this);
162 - suspend.iconexist = true;
163 - layout->addItem(suspend.m_icon);
165 + layout->addItem(suspend.m_icon);
166 connect(suspend.m_icon, SIGNAL(clicked()), this, SLOT(suspendf()));
169 else {
170 QAction* suspenda = new QAction(i18n("&Suspend"), this);
171 suspenda->setIcon(KIcon(suspend.iconname));
172 m_actions.append(suspenda);
173 connect(suspenda, SIGNAL(triggered(bool)), SLOT(suspendf()));
176 - if (logout.iconshow == true) {
178 + if (logout.iconshow) {
179 logout.m_icon = new Plasma::IconWidget(KIcon(logout.iconname), QString(), this);
180 - logout.iconexist = true;
181 - layout->addItem(logout.m_icon);
183 + layout->addItem(logout.m_icon);
184 connect(logout.m_icon, SIGNAL(clicked()), this, SLOT(logoutf()));
187 else {
188 QAction* logouta = new QAction(i18n("&Logout"), this);
189 logouta->setIcon(KIcon(logout.iconname));
190 m_actions.append(logouta);
191 connect(logouta, SIGNAL(triggered(bool)), SLOT(logoutf()));
194 - if (hibernate.iconshow == true) {
196 + if (hibernate.iconshow) {
197 hibernate.m_icon = new Plasma::IconWidget(KIcon(hibernate.iconname), QString(), this);
198 - hibernate.iconexist = true;
199 layout->addItem(hibernate.m_icon);
201 connect(hibernate.m_icon, SIGNAL(clicked()), this, SLOT(hibernatef()));
203 else {
204 @@ -158,27 +147,23 @@ void PlasmaYasdp::init()
205 m_actions.append(hibernatea);
206 connect(hibernatea, SIGNAL(triggered(bool)), SLOT(hibernatef()));
209 - if (toscreen.iconshow == true) {
211 + if (toscreen.iconshow) {
212 toscreen.m_icon = new Plasma::IconWidget(KIcon(toscreen.iconname), QString(), this);
213 - toscreen.iconexist = true;
214 - layout->addItem(toscreen.m_icon);
216 + layout->addItem(toscreen.m_icon);
217 connect(toscreen.m_icon, SIGNAL(clicked()), this, SLOT(toscreenf()));
221 else {
222 QAction* toscreena = new QAction(i18n("&Turn off screen"), this);
223 toscreena->setIcon(KIcon(toscreen.iconname));
224 m_actions.append(toscreena);
225 connect(toscreena, SIGNAL(triggered(bool)), SLOT(toscreenf()));
228 - if (loscreen.iconshow == true) {
230 + if (loscreen.iconshow) {
231 loscreen.m_icon = new Plasma::IconWidget(KIcon(loscreen.iconname), QString(), this);
232 - loscreen.iconexist = true;
233 layout->addItem(loscreen.m_icon);
235 connect(loscreen.m_icon, SIGNAL(clicked()), this, SLOT(loscreenf()));
237 else {
238 @@ -190,31 +175,25 @@ void PlasmaYasdp::init()
240 QAction* seperator = new QAction(this);
241 seperator->setSeparator(true);
246 -void PlasmaYasdp::paintInterface(QPainter *p,
247 - const QStyleOptionGraphicsItem *option, const QRect &contentsRect)
250 +void PlasmaYasdp::paintInterface(QPainter *p, const QStyleOptionGraphicsItem *option, const QRect &contentsRect) {
251 Q_UNUSED( p );
252 Q_UNUSED( option );
253 Q_UNUSED( contentsRect );
257 -void PlasmaYasdp::createConfigurationInterface(KConfigDialog *parent)
260 +void PlasmaYasdp::createConfigurationInterface(KConfigDialog *parent) {
261 //Appearance
262 QWidget *widgetAppear = new QWidget;
263 uiAppear.setupUi(widgetAppear);
266 uiAppear.kiconbutton->setIcon(KIcon(shutdown.iconname));
267 uiAppear.kiconbutton_2->setIcon(KIcon(reboot.iconname));
268 uiAppear.kiconbutton_3->setIcon(KIcon(suspend.iconname));
269 uiAppear.kiconbutton_4->setIcon(KIcon(logout.iconname));
270 - uiAppear.kiconbutton_5->setIcon(KIcon(hibernate.iconname));
271 + uiAppear.kiconbutton_5->setIcon(KIcon(hibernate.iconname));
272 uiAppear.kiconbutton_6->setIcon(KIcon(toscreen.iconname));
273 uiAppear.kiconbutton_7->setIcon(KIcon(loscreen.iconname));
274 uiAppear.checkBox->setChecked(shutdown.iconshow);
275 @@ -227,22 +206,18 @@ void PlasmaYasdp::createConfigurationInt
276 uiAppear.checkBox_8->setChecked(toscreen.iconshow);
277 uiAppear.checkBox_9->setChecked(loscreen.iconshow);
278 uiAppear.comboBox->setCurrentIndex(background);
281 connect(uiAppear.comboBox, SIGNAL (currentIndexChanged (int)), this, SLOT(backgroundf(int)));
284 //add everything to the settings
285 connect(parent, SIGNAL(okClicked()), this, SLOT(configAccepted()));
286 parent->addPage(widgetAppear, i18n("Appearance"), QString("video-display"));
289 -void PlasmaYasdp::configAccepted()
291 +void PlasmaYasdp::configAccepted() {
292 KConfigGroup cg = config();
295 - // Icons
298 + // Icons
299 if (uiAppear.kiconbutton->icon() != "") {
300 shutdown.iconname = uiAppear.kiconbutton->icon(); }
301 if (uiAppear.kiconbutton_2->icon() != "") {
302 @@ -265,11 +240,11 @@ void PlasmaYasdp::configAccepted()
303 hibernate.iconshow = uiAppear.checkBox_5->isChecked();
304 toscreen.iconshow = uiAppear.checkBox_8->isChecked();
305 loscreen.iconshow = uiAppear.checkBox_9->isChecked();
308 //other config
309 vlayout = uiAppear.checkBox_6->isChecked();
310 askconf = uiAppear.checkBox_7->isChecked();
313 cg.writeEntry("sh-iconname", shutdown.iconname);
314 cg.writeEntry("re-iconname", reboot.iconname);
315 cg.writeEntry("su-iconname", suspend.iconname);
316 @@ -287,122 +262,93 @@ void PlasmaYasdp::configAccepted()
317 cg.writeEntry("vlayout", vlayout);
318 cg.writeEntry("askconf", askconf);
319 cg.writeEntry("background", background);
325 // apply change
327 if (vlayout == 1) {
328 - layout->setOrientation(Qt::Vertical);
329 - resize(120, 429); }
330 + layout->setOrientation(Qt::Vertical);
331 + resize(120, 429);
333 else {
334 - layout->setOrientation(Qt::Horizontal);
335 - resize(429, 120);}
337 - // when I spoke about very ugly code, I meant this:
338 + layout->setOrientation(Qt::Horizontal);
339 + resize(429, 120);
342 + // when I spoke about very ugly code, I meant this:
343 m_actions.clear();
344 - if (shutdown.iconexist == true) {
345 - delete shutdown.m_icon;
346 - shutdown.iconexist = false;}
349 - if (reboot.iconexist == true) {
350 - delete reboot.m_icon;
351 - reboot.iconexist = false;}
353 - if (suspend.iconexist == true) {
354 - delete suspend.m_icon;
355 - suspend.iconexist = false;}
357 - if (logout.iconexist == true) {
358 - delete logout.m_icon;
359 - logout.iconexist = false;}
361 - if (hibernate.iconexist == true) {
362 - delete hibernate.m_icon;
363 - hibernate.iconexist = false;}
365 - if (toscreen.iconexist == true) {
366 - delete toscreen.m_icon;
367 - toscreen.iconexist = false;}
369 - if (loscreen.iconexist == true) {
370 - delete loscreen.m_icon;
371 - loscreen.iconexist = false;}
373 - if (shutdown.iconshow == true) {
375 - shutdown.m_icon = new Plasma::IconWidget(KIcon(shutdown.iconname), QString(), this);
376 - layout->addItem(shutdown.m_icon);
377 - shutdown.m_icon->setIcon(KIcon(shutdown.iconname));
378 - connect(shutdown.m_icon, SIGNAL(clicked()), this, SLOT(shutdownf()));
379 - shutdown.iconexist = true;
381 - else {
382 - QAction* shutdowna = new QAction(i18n("&Shutdown"), this);
383 - shutdowna->setIcon(KIcon(shutdown.iconname));
384 - m_actions.append(shutdowna);
385 - connect(shutdowna, SIGNAL(triggered(bool)), SLOT(shutdownf()));
389 - if (reboot.iconshow == true) {
391 + if (shutdown.iconshow) {
392 + if( shutdown.m_icon ) {
393 + shutdown.m_icon->deleteLater();
395 + shutdown.m_icon = new Plasma::IconWidget(KIcon(shutdown.iconname), QString(), this);
396 + layout->addItem(shutdown.m_icon);
397 + shutdown.m_icon->setIcon(KIcon(shutdown.iconname));
398 + connect(shutdown.m_icon, SIGNAL(clicked()), this, SLOT(shutdownf()));
400 + else {
401 + QAction* shutdowna = new QAction(i18n("&Shutdown"), this);
402 + shutdowna->setIcon(KIcon(shutdown.iconname));
403 + m_actions.append(shutdowna);
404 + connect(shutdowna, SIGNAL(triggered(bool)), SLOT(shutdownf()));
407 + if (reboot.iconshow) {
408 + if( reboot.m_icon ) {
409 + reboot.m_icon->deleteLater();
411 reboot.m_icon = new Plasma::IconWidget(KIcon(reboot.iconname), QString(), this);
412 layout->addItem(reboot.m_icon);
413 reboot.m_icon->setIcon(KIcon(reboot.iconname));
414 connect(reboot.m_icon, SIGNAL(clicked()), this, SLOT(rebootf()));
415 - reboot.iconexist = true;
417 - else {
418 - QAction* reboota = new QAction(i18n("&Reboot"), this);
419 - reboota->setIcon(KIcon(reboot.iconname));
420 - m_actions.append(reboota);
421 - connect(reboota, SIGNAL(triggered(bool)), SLOT(rebootf()));
422 + else {
423 + QAction* reboota = new QAction(i18n("&Reboot"), this);
424 + reboota->setIcon(KIcon(reboot.iconname));
425 + m_actions.append(reboota);
426 + connect(reboota, SIGNAL(triggered(bool)), SLOT(rebootf()));
430 - if (suspend.iconshow == true) {
432 + if (suspend.iconshow) {
433 + if( suspend.m_icon ) {
434 + suspend.m_icon->deleteLater();
436 suspend.m_icon = new Plasma::IconWidget(KIcon(suspend.iconname), QString(), this);
437 layout->addItem(suspend.m_icon);
438 suspend.m_icon->setIcon(KIcon(suspend.iconname));
439 connect(suspend.m_icon, SIGNAL(clicked()), this, SLOT(suspendf()));
440 - suspend.iconexist = true;
442 - else {
443 - QAction* suspenda = new QAction(i18n("&Suspend"), this);
444 - suspenda->setIcon(KIcon(suspend.iconname));
445 - m_actions.append(suspenda);
446 - connect(suspenda, SIGNAL(triggered(bool)), SLOT(suspendf()));
447 + else {
448 + QAction* suspenda = new QAction(i18n("&Suspend"), this);
449 + suspenda->setIcon(KIcon(suspend.iconname));
450 + m_actions.append(suspenda);
451 + connect(suspenda, SIGNAL(triggered(bool)), SLOT(suspendf()));
455 - if (logout.iconshow == true) {
457 + if (logout.iconshow) {
458 + if( logout.m_icon ) {
459 + logout.m_icon->deleteLater();
461 logout.m_icon = new Plasma::IconWidget(KIcon(logout.iconname), QString(), this);
462 layout->addItem(logout.m_icon);
463 logout.m_icon->setIcon(KIcon(logout.iconname));
464 connect(logout.m_icon, SIGNAL(clicked()), this, SLOT(logoutf()));
465 - logout.iconexist = true;
467 - else {
468 - QAction* logouta = new QAction(i18n("&Logout"), this);
469 - logouta->setIcon(KIcon(logout.iconname));
470 - m_actions.append(logouta);
471 - connect(logouta, SIGNAL(triggered(bool)), SLOT(logoutf()));
472 + else {
473 + QAction* logouta = new QAction(i18n("&Logout"), this);
474 + logouta->setIcon(KIcon(logout.iconname));
475 + m_actions.append(logouta);
476 + connect(logouta, SIGNAL(triggered(bool)), SLOT(logoutf()));
480 - if (hibernate.iconshow == true) {
482 + if (hibernate.iconshow) {
483 + if( hibernate.m_icon ) {
484 + hibernate.m_icon->deleteLater();
486 hibernate.m_icon = new Plasma::IconWidget(KIcon(hibernate.iconname), QString(), this);
487 layout->addItem(hibernate.m_icon);
488 hibernate.m_icon->setIcon(KIcon(hibernate.iconname));
489 connect(hibernate.m_icon, SIGNAL(clicked()), this, SLOT(hibernatef()));
490 - hibernate.iconexist = true;
492 else {
493 QAction* hibernatea = new QAction(i18n("&Hibernate"), this);
494 @@ -410,114 +356,145 @@ void PlasmaYasdp::configAccepted()
495 m_actions.append(hibernatea);
496 connect(hibernatea, SIGNAL(triggered(bool)), SLOT(hibernatef()));
499 - if (toscreen.iconshow == true) {
501 + if (toscreen.iconshow) {
502 + if( toscreen.m_icon ) {
503 + toscreen.m_icon->deleteLater();
505 toscreen.m_icon = new Plasma::IconWidget(KIcon(toscreen.iconname), QString(), this);
506 layout->addItem(toscreen.m_icon);
507 toscreen.m_icon->setIcon(KIcon(toscreen.iconname));
508 connect(toscreen.m_icon, SIGNAL(clicked()), this, SLOT(toscreenf()));
509 - toscreen.iconexist = true;
511 - else {
512 - QAction* toscreena = new QAction(i18n("&Turn off screen"), this);
513 - toscreena->setIcon(KIcon(toscreen.iconname));
514 - m_actions.append(toscreena);
515 - connect(toscreena, SIGNAL(triggered(bool)), SLOT(toscreenf()));
516 + else {
517 + QAction* toscreena = new QAction(i18n("&Turn off screen"), this);
518 + toscreena->setIcon(KIcon(toscreen.iconname));
519 + m_actions.append(toscreena);
520 + connect(toscreena, SIGNAL(triggered(bool)), SLOT(toscreenf()));
524 - if (loscreen.iconshow == true) {
526 + if (loscreen.iconshow) {
527 + if( loscreen.m_icon ) {
528 + loscreen.m_icon->deleteLater();
530 loscreen.m_icon = new Plasma::IconWidget(KIcon(loscreen.iconname), QString(), this);
531 layout->addItem(loscreen.m_icon);
532 loscreen.m_icon->setIcon(KIcon(loscreen.iconname));
533 connect(loscreen.m_icon, SIGNAL(clicked()), this, SLOT(loscreenf()));
534 - loscreen.iconexist = true;
536 else {
537 - QAction* loscreena = new QAction(i18n("&Lock screen"), this);
538 - loscreena->setIcon(KIcon(loscreen.iconname));
539 - m_actions.append(loscreena);
540 - connect(loscreena, SIGNAL(triggered(bool)), SLOT(loscreenf()));
541 + QAction* loscreena = new QAction(i18n("&Lock screen"), this);
542 + loscreena->setIcon(KIcon(loscreen.iconname));
543 + m_actions.append(loscreena);
544 + connect(loscreena, SIGNAL(triggered(bool)), SLOT(loscreenf()));
549 emit configNeedsSaving();
550 emit update();
554 void PlasmaYasdp::shutdownf() {
555 -if (askconf == 0) {
556 - KWorkSpace::requestShutDown(KWorkSpace::ShutdownConfirmNo,
557 - KWorkSpace::ShutdownTypeHalt ,
558 - KWorkSpace::ShutdownModeInteractive);
560 -else {
561 - KWorkSpace::requestShutDown(KWorkSpace::ShutdownConfirmYes,
562 - KWorkSpace::ShutdownTypeHalt ,
563 - KWorkSpace::ShutdownModeInteractive);
565 + KWorkSpace::requestShutDown( askconf ? KWorkSpace::ShutdownConfirmYes : KWorkSpace::ShutdownConfirmNo,
566 + KWorkSpace::ShutdownTypeHalt ,
567 + KWorkSpace::ShutdownModeInteractive );
569 void PlasmaYasdp::rebootf() {
570 -if (askconf == 0) {
571 - KWorkSpace::requestShutDown(KWorkSpace::ShutdownConfirmNo,
572 - KWorkSpace::ShutdownTypeReboot ,
573 - KWorkSpace::ShutdownModeInteractive);
575 -else {
576 - KWorkSpace::requestShutDown(KWorkSpace::ShutdownConfirmYes,
577 - KWorkSpace::ShutdownTypeReboot ,
578 - KWorkSpace::ShutdownModeInteractive);
581 -void PlasmaYasdp::suspendf() {
582 - system("qdbus org.kde.kded /modules/powerdevil suspend 2");
584 -void PlasmaYasdp::logoutf() {
585 -if (askconf == 0) {
586 - KWorkSpace::requestShutDown(KWorkSpace::ShutdownConfirmNo,
587 - KWorkSpace::ShutdownTypeNone ,
588 - KWorkSpace::ShutdownModeInteractive);
590 -else {
591 - KWorkSpace::requestShutDown(KWorkSpace::ShutdownConfirmYes,
592 - KWorkSpace::ShutdownTypeNone ,
593 - KWorkSpace::ShutdownModeInteractive);
594 + KWorkSpace::requestShutDown( askconf ? KWorkSpace::ShutdownConfirmYes : KWorkSpace::ShutdownConfirmNo,
595 + KWorkSpace::ShutdownTypeReboot ,
596 + KWorkSpace::ShutdownModeInteractive );
599 +void PlasmaYasdp::suspendf()
601 + if( askconf && KMessageBox::questionYesNo(0,
602 + i18n("Do you want to suspend to RAM (sleep)?"),
603 + i18n("Suspend") ) != KMessageBox::Yes) {
604 + return;
606 + system("qdbus org.kde.kded /modules/powerdevil suspend 2");
607 +//TODO: Use the above original code line until a kde-4.6-compatible and better way is found!
609 + // Check if powerdevil is running, and use its methods to suspend if available
610 + // otherwise go through Solid directly
611 + QStringList modules;
612 + QDBusInterface kdedInterface("org.kde.kded", "/kded", "org.kde.kded");
613 + QDBusReply<QStringList> reply = kdedInterface.call("loadedModules");
614 + if (reply.isValid() && reply.value().contains("powerdevil")) {
615 + kDebug() << "Using powerdevil to suspend";
616 + QDBusConnection dbus(QDBusConnection::sessionBus());
617 + QDBusInterface iface("org.kde.kded", "/modules/powerdevil", "org.kde.PowerDevil", dbus);
618 + iface.call("suspend", Solid::Control::PowerManager::ToRam);
619 + } else {
620 + kDebug() << "Powerdevil not available, using solid to suspend";
621 + KJob * job = Solid::Control::PowerManager::suspend(Solid::Control::PowerManager::ToRam);
622 + job->start();
627 +void PlasmaYasdp::logoutf() {
628 + KWorkSpace::requestShutDown( askconf ? KWorkSpace::ShutdownConfirmYes : KWorkSpace::ShutdownConfirmNo,
629 + KWorkSpace::ShutdownTypeNone ,
630 + KWorkSpace::ShutdownModeInteractive );
633 - void PlasmaYasdp::hibernatef() {
634 +void PlasmaYasdp::hibernatef()
636 + if ( askconf && KMessageBox::questionYesNo( 0,
637 + i18n("Do you want to suspend to disk (hibernate)?"),
638 + i18n("Suspend") ) != KMessageBox::Yes) {
639 + return;
641 system("qdbus org.kde.kded /modules/powerdevil suspend 4");
643 +//TODO: Use the above original code line until a kde-4.6-compatible and better way is found!
645 + // Check if powerdevil is running, and use its methods to hibernate if available
646 + // otherwise go through Solid directly
647 + QStringList modules;
648 + QDBusInterface kdedInterface("org.kde.kded", "/kded", "org.kde.kded");
649 + QDBusReply<QStringList> reply = kdedInterface.call("loadedModules");
650 + if (reply.isValid() && reply.value().contains("powerdevil")) {
651 + kDebug() << "Using powerdevil to hibernate";
652 + QDBusConnection dbus(QDBusConnection::sessionBus());
653 + QDBusInterface iface("org.kde.kded", "/modules/powerdevil", "org.kde.PowerDevil", dbus);
654 + iface.call("suspend", Solid::Control::PowerManager::ToDisk);
655 + } else {
656 + kDebug() << "Powerdevil not available, using solid to hibernate";
657 + KJob * job = Solid::Control::PowerManager::suspend(Solid::Control::PowerManager::ToDisk);
658 + job->start();
663 -void PlasmaYasdp::toscreenf() {
664 -system("xset dpms force off");
665 +void PlasmaYasdp::toscreenf() {
666 + system("xset dpms force off");
669 -void PlasmaYasdp::loscreenf() {
670 +void PlasmaYasdp::loscreenf() {
671 system("qdbus org.freedesktop.ScreenSaver /ScreenSaver Lock");
675 void PlasmaYasdp::backgroundf(const int &ca) {
676 - if (ca == 0) {
677 - background = 0;
678 - setBackgroundHints(DefaultBackground);
680 - if (ca == 1) {
681 - background = 1;
682 - setBackgroundHints(StandardBackground);
684 - if (ca == 2) {
685 - background = 2;
686 - setBackgroundHints(TranslucentBackground);
688 - if (ca == 3) {
689 - background = 3;
690 - setBackgroundHints(NoBackground);
692 + switch( ca ) {
693 + case 1:
694 + setBackgroundHints(StandardBackground);
695 + background = ca;
696 + break;
697 + case 2:
698 + setBackgroundHints(TranslucentBackground);
699 + background = ca;
700 + break;
701 + case 3:
702 + setBackgroundHints(NoBackground);
703 + background = ca;
704 + break;
705 + default:
706 + setBackgroundHints(DefaultBackground);
707 + background = 0;
708 + break;
712 QList<QAction*> PlasmaYasdp::contextualActions()
713 @@ -525,8 +502,8 @@ QList<QAction*> PlasmaYasdp::contextualA
714 return m_actions;
719 // This is the command that links your applet to the .desktop file
720 K_EXPORT_PLASMA_APPLET(yasdp, PlasmaYasdp)
723 #include "plasma-yasdp.moc"
724 \ No newline at end of file
725 diff -Nurp yaSDP.orig//plasma-yasdp.h yaSDP/plasma-yasdp.h
726 --- yaSDP.orig//plasma-yasdp.h 2010-08-20 21:01:37.000000000 +0200
727 +++ yaSDP/plasma-yasdp.h 2011-01-28 18:51:48.000000000 +0100
728 @@ -7,16 +7,16 @@
730 // We need the Plasma Applet headers
731 #include <KIcon>
734 #include <Plasma/Applet>
735 #include <Plasma/Svg>
736 #include <plasma/widgets/iconwidget.h>
737 #include <plasma/widgets/label.h>
739 #include "ui_AppearanceConfig.h"
742 class QSizeF;
745 // Define our plasma Applet
746 class PlasmaYasdp : public Plasma::Applet
748 @@ -25,15 +25,15 @@ class PlasmaYasdp : public Plasma::Apple
749 // Basic Create/Destroy
750 PlasmaYasdp(QObject *parent, const QVariantList &args);
751 ~PlasmaYasdp();
754 // The paintInterface procedure paints the applet to screen
755 void paintInterface(QPainter *p,
756 const QStyleOptionGraphicsItem *option,
757 const QRect& contentsRect);
758 void init();
764 public slots:
766 void configAccepted();
767 @@ -49,22 +49,21 @@ class PlasmaYasdp : public Plasma::Apple
768 protected:
769 void createConfigurationInterface(KConfigDialog *parent);
770 QList<QAction*> contextualActions();
773 private:
776 Ui::AppearanceConfig uiAppear;
777 Plasma::Svg m_svg;
782 typedef struct {
783 Plasma::IconWidget *m_icon;
784 QString iconname;
785 QString deficonname;
786 bool iconshow;
787 - bool iconexist;
788 } icon;
791 icon shutdown;
792 icon reboot;
793 icon suspend;
794 @@ -79,7 +78,7 @@ class PlasmaYasdp : public Plasma::Apple
795 QList<QAction*> m_actions;
797 QGraphicsLinearLayout *layout;
803 #endif
804 \ No newline at end of file