Don't like ads? PRO users don't see any ads ;-)
Guest

yaSDP patch for KDE 4.6- crash on exit

By: a guest on Jan 28th, 2011  |  syntax: C++  |  size: 26.94 KB  |  hits: 85  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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...
  10.  
  11. +#include <KMessageBox>
  12. +#include <KJob>
  13. +
  14. +#include <QtDBus/QDBusInterface>
  15. +#include <QtDBus/QDBusReply>
  16. +
  17.  #include "plasma-yasdp.h"
  18.  #include <QPainter>
  19.  #include <QFontMetrics>
  20.  #include <QSizeF>
  21.  #include <QRect>
  22.  #include <QComboBox>
  23. -
  24. +
  25.  #include <plasma/svg.h>
  26.  #include <plasma/theme.h>
  27.  
  28.  #include <KConfigDialog>
  29.  #include <KGlobalSettings>
  30.  #include "kworkspace/kworkspace.h"
  31. -
  32. -
  33. -PlasmaYasdp::PlasmaYasdp(QObject *parent, const QVariantList &args)
  34. -    : Plasma::Applet(parent, args)
  35.  
  36. +PlasmaYasdp::PlasmaYasdp(QObject *parent, const QVariantList &args)
  37. +    : Plasma::Applet(parent, args) {
  38.  
  39. -{
  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;
  48.  
  49. +       // Set up the plasmoid
  50.      setHasConfigurationInterface(true);
  51.      setAspectRatioMode(Plasma::IgnoreAspectRatio);
  52.      resize(429, 120);
  53. -
  54.  }
  55. -
  56. -
  57. -PlasmaYasdp::~PlasmaYasdp()
  58. -{
  59. -  
  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;
  67. +
  68. +
  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();
  77.  }
  78. -
  79. -void PlasmaYasdp::init()
  80. -{
  81. +
  82. +void PlasmaYasdp::init() {
  83.  
  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";
  90. -  
  91. +
  92.      //read config
  93.      KConfigGroup cg = config();
  94. -    
  95. +
  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);
  104. -    
  105. -    layout = new QGraphicsLinearLayout(this);
  106. +       backgroundf( cg.readEntry("background", 0 ) );
  107. +
  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);
  113. -    
  114. -    if (background == 0) setBackgroundHints(DefaultBackground);
  115. -    if (background == 1) setBackgroundHints(StandardBackground);
  116. -    if (background == 2) setBackgroundHints(TranslucentBackground);
  117. -    if (background == 3) setBackgroundHints(NoBackground);
  118. -    
  119. -    if (shutdown.iconshow == true)  {
  120. +    layout->setOrientation( vlayout ? Qt::Vertical : Qt::Horizontal );
  121. +
  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);
  126. -      
  127. -      connect(shutdown.m_icon, SIGNAL(clicked()), this, SLOT(shutdownf()));
  128. +      layout->addItem(shutdown.m_icon);
  129. +
  130. +      connect(shutdown.m_icon, SIGNAL(clicked()), this, SLOT(shutdownf()));
  131.      }
  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()));
  137.      }
  138. -    
  139. -    if (reboot.iconshow == true) {
  140. +
  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);
  145. -      
  146. -      
  147. +      layout->addItem(reboot.m_icon);
  148.        connect(reboot.m_icon, SIGNAL(clicked()), this, SLOT(rebootf()));
  149.      }
  150. -    
  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()));
  156.      }
  157. -    
  158. -    if (suspend.iconshow == true) {
  159. +
  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);
  164. -      
  165. +      layout->addItem(suspend.m_icon);
  166.        connect(suspend.m_icon, SIGNAL(clicked()), this, SLOT(suspendf()));
  167.      }
  168. -    
  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()));
  174.      }
  175. -    
  176. -    if (logout.iconshow == true) {
  177. +
  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);
  182. -      
  183. +      layout->addItem(logout.m_icon);
  184.        connect(logout.m_icon, SIGNAL(clicked()), this, SLOT(logoutf()));
  185.      }
  186. -    
  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()));
  192.      }
  193. -    
  194. -    if (hibernate.iconshow == true) {
  195. +
  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);
  200. -      
  201.        connect(hibernate.m_icon, SIGNAL(clicked()), this, SLOT(hibernatef()));
  202.      }
  203.      else {
  204. @@ -158,27 +147,23 @@ void PlasmaYasdp::init()
  205.        m_actions.append(hibernatea);
  206.        connect(hibernatea, SIGNAL(triggered(bool)), SLOT(hibernatef()));
  207.      }
  208. -    
  209. -        if (toscreen.iconshow == true) {
  210. +
  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);
  215. -      
  216. +      layout->addItem(toscreen.m_icon);
  217.        connect(toscreen.m_icon, SIGNAL(clicked()), this, SLOT(toscreenf()));
  218.      }
  219. -    
  220. +
  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()));
  226.      }
  227. -    
  228. -    if (loscreen.iconshow == true) {
  229. +
  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);
  234. -      
  235.        connect(loscreen.m_icon, SIGNAL(clicked()), this, SLOT(loscreenf()));
  236.      }
  237.      else {
  238. @@ -190,31 +175,25 @@ void PlasmaYasdp::init()
  239.  
  240.      QAction* seperator = new QAction(this);
  241.      seperator->setSeparator(true);
  242. -    
  243. +
  244.  }
  245. -
  246. -void PlasmaYasdp::paintInterface(QPainter *p,
  247. -        const QStyleOptionGraphicsItem *option, const QRect &contentsRect)
  248. -{
  249. +
  250. +void PlasmaYasdp::paintInterface(QPainter *p, const QStyleOptionGraphicsItem *option, const QRect &contentsRect) {
  251.      Q_UNUSED( p );
  252.      Q_UNUSED( option );
  253.      Q_UNUSED( contentsRect );
  254. -
  255.  }
  256.  
  257. -void PlasmaYasdp::createConfigurationInterface(KConfigDialog *parent)
  258. -{
  259. -
  260. +void PlasmaYasdp::createConfigurationInterface(KConfigDialog *parent) {
  261.      //Appearance
  262.      QWidget *widgetAppear = new QWidget;
  263.      uiAppear.setupUi(widgetAppear);
  264.  
  265. -  
  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);
  279. -    
  280. +
  281.      connect(uiAppear.comboBox, SIGNAL (currentIndexChanged (int)), this, SLOT(backgroundf(int)));
  282. -    
  283. +
  284.      //add everything to the settings
  285.      connect(parent, SIGNAL(okClicked()), this, SLOT(configAccepted()));
  286.      parent->addPage(widgetAppear, i18n("Appearance"), QString("video-display"));
  287.  }
  288.  
  289. -void PlasmaYasdp::configAccepted()
  290. -{
  291. +void PlasmaYasdp::configAccepted() {
  292.      KConfigGroup cg = config();
  293.  
  294. -    
  295. -    // Icons
  296. -    
  297. -    
  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();
  306. -    
  307. +
  308.      //other config
  309.      vlayout = uiAppear.checkBox_6->isChecked();
  310.      askconf = uiAppear.checkBox_7->isChecked();
  311. -    
  312. +
  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);
  320. -    
  321. -    
  322.  
  323. -
  324. -    
  325.      // apply change
  326. -    
  327.      if (vlayout == 1) {
  328. -    layout->setOrientation(Qt::Vertical);
  329. -    resize(120, 429); }
  330. +               layout->setOrientation(Qt::Vertical);
  331. +               resize(120, 429);
  332. +       }
  333.      else {
  334. -    layout->setOrientation(Qt::Horizontal);
  335. -    resize(429, 120);}
  336. -    
  337. -    // when I spoke about very ugly code, I meant this:
  338. +               layout->setOrientation(Qt::Horizontal);
  339. +               resize(429, 120);
  340. +       }
  341. +
  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;}
  347. -
  348. -      
  349. -    if (reboot.iconexist == true) {
  350. -      delete reboot.m_icon;
  351. -      reboot.iconexist = false;}
  352. -      
  353. -    if (suspend.iconexist == true) {
  354. -      delete suspend.m_icon;
  355. -      suspend.iconexist = false;}
  356. -      
  357. -    if (logout.iconexist == true) {
  358. -      delete logout.m_icon;
  359. -      logout.iconexist = false;}
  360. -      
  361. -    if (hibernate.iconexist == true) {
  362. -      delete hibernate.m_icon;
  363. -      hibernate.iconexist = false;}
  364. -      
  365. -    if (toscreen.iconexist == true) {
  366. -      delete toscreen.m_icon;
  367. -      toscreen.iconexist = false;}
  368. -      
  369. -    if (loscreen.iconexist == true) {
  370. -      delete loscreen.m_icon;
  371. -      loscreen.iconexist = false;}  
  372. -
  373. - if (shutdown.iconshow == true) {
  374. -      
  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;
  380. -    }
  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()));
  386. -    }
  387. -    
  388. -    
  389. -    if (reboot.iconshow == true) {
  390.  
  391. +       if (shutdown.iconshow) {
  392. +               if( shutdown.m_icon ) {
  393. +                       shutdown.m_icon->deleteLater();
  394. +               }
  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()));
  399. +    }
  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()));
  405. +    }
  406. +
  407. +    if (reboot.iconshow) {
  408. +               if( reboot.m_icon ) {
  409. +                       reboot.m_icon->deleteLater();
  410. +               }
  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;
  416.      }
  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()));
  427.      }
  428.  
  429. -    
  430. -    if (suspend.iconshow == true) {
  431. -
  432. +    if (suspend.iconshow) {
  433. +               if( suspend.m_icon ) {
  434. +                       suspend.m_icon->deleteLater();
  435. +               }
  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;
  441.      }
  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()));
  452.      }
  453.  
  454. -    
  455. -    if (logout.iconshow == true) {
  456. -
  457. +    if (logout.iconshow) {
  458. +               if( logout.m_icon ) {
  459. +                       logout.m_icon->deleteLater();
  460. +               }
  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;
  466.      }
  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()));
  477.      }
  478.  
  479.  
  480. -    if (hibernate.iconshow == true) {
  481. -
  482. +    if (hibernate.iconshow) {
  483. +               if( hibernate.m_icon ) {
  484. +                       hibernate.m_icon->deleteLater();
  485. +               }
  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;
  491.      }
  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()));
  497.      }
  498. -    
  499. -        if (toscreen.iconshow == true) {
  500.  
  501. +       if (toscreen.iconshow) {
  502. +               if( toscreen.m_icon ) {
  503. +                       toscreen.m_icon->deleteLater();
  504. +               }
  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;
  510.      }
  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()));
  521.      }
  522.  
  523.  
  524. -    if (loscreen.iconshow == true) {
  525. -
  526. +    if (loscreen.iconshow) {
  527. +               if( loscreen.m_icon ) {
  528. +                       loscreen.m_icon->deleteLater();
  529. +               }
  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;
  535.      }
  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()));
  545.      }
  546. -    
  547.  
  548. -    
  549.      emit configNeedsSaving();
  550.      emit update();
  551.  }
  552.  
  553.  
  554.  void PlasmaYasdp::shutdownf() {
  555. -if (askconf == 0) {
  556. -    KWorkSpace::requestShutDown(KWorkSpace::ShutdownConfirmNo,
  557. -                                KWorkSpace::ShutdownTypeHalt ,
  558. -                                KWorkSpace::ShutdownModeInteractive);
  559. -}
  560. -else {
  561. -      KWorkSpace::requestShutDown(KWorkSpace::ShutdownConfirmYes,
  562. -                                KWorkSpace::ShutdownTypeHalt ,
  563. -                                KWorkSpace::ShutdownModeInteractive);
  564. -}
  565. +    KWorkSpace::requestShutDown( askconf ? KWorkSpace::ShutdownConfirmYes : KWorkSpace::ShutdownConfirmNo,
  566. +                                 KWorkSpace::ShutdownTypeHalt ,
  567. +                                 KWorkSpace::ShutdownModeInteractive );
  568.  }
  569.  void PlasmaYasdp::rebootf() {
  570. -if (askconf == 0) {
  571. -    KWorkSpace::requestShutDown(KWorkSpace::ShutdownConfirmNo,
  572. -                                KWorkSpace::ShutdownTypeReboot ,
  573. -                                KWorkSpace::ShutdownModeInteractive);
  574. -}
  575. -else {
  576. -      KWorkSpace::requestShutDown(KWorkSpace::ShutdownConfirmYes,
  577. -                                KWorkSpace::ShutdownTypeReboot ,
  578. -                                KWorkSpace::ShutdownModeInteractive);
  579. -}
  580. -}
  581. -void PlasmaYasdp::suspendf() {  
  582. -  system("qdbus org.kde.kded /modules/powerdevil suspend 2");
  583. -}
  584. -void PlasmaYasdp::logoutf() {  
  585. -if (askconf == 0) {
  586. -    KWorkSpace::requestShutDown(KWorkSpace::ShutdownConfirmNo,
  587. -                                KWorkSpace::ShutdownTypeNone ,
  588. -                                KWorkSpace::ShutdownModeInteractive);
  589. -}
  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 );
  597.  }
  598. +
  599. +void PlasmaYasdp::suspendf()
  600. +{
  601. +    if( askconf && KMessageBox::questionYesNo(0,
  602. +                                               i18n("Do you want to suspend to RAM (sleep)?"),
  603. +                                               i18n("Suspend") ) != KMessageBox::Yes) {
  604. +        return;
  605. +    }
  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!
  608. +/*
  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();
  623. +    }
  624. +*/
  625. + }
  626. +
  627. +void PlasmaYasdp::logoutf() {
  628. +    KWorkSpace::requestShutDown( askconf ? KWorkSpace::ShutdownConfirmYes : KWorkSpace::ShutdownConfirmNo,
  629. +                                 KWorkSpace::ShutdownTypeNone ,
  630. +                                 KWorkSpace::ShutdownModeInteractive );
  631.  }
  632.  
  633. - void PlasmaYasdp::hibernatef() {  
  634. +void PlasmaYasdp::hibernatef()
  635. +{
  636. +    if ( askconf &&  KMessageBox::questionYesNo( 0,
  637. +                                   i18n("Do you want to suspend to disk (hibernate)?"),
  638. +                                   i18n("Suspend") ) != KMessageBox::Yes) {
  639. +        return;
  640. +    }
  641.     system("qdbus org.kde.kded /modules/powerdevil suspend 4");
  642. -}  
  643. +//TODO: Use the above original code line until a kde-4.6-compatible and better way is found!
  644. +/*
  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();
  659. +    }
  660. +*/
  661. +}
  662.  
  663. -void PlasmaYasdp::toscreenf() {  
  664. -system("xset dpms force off");
  665. +void PlasmaYasdp::toscreenf() {
  666. +       system("xset dpms force off");
  667.  }
  668.  
  669. -void PlasmaYasdp::loscreenf() {  
  670. +void PlasmaYasdp::loscreenf() {
  671.     system("qdbus org.freedesktop.ScreenSaver /ScreenSaver Lock");
  672. -}  
  673. +}
  674.  
  675.   void PlasmaYasdp::backgroundf(const int &ca) {
  676. -   if (ca == 0) {
  677. -     background = 0;
  678. -     setBackgroundHints(DefaultBackground);
  679. -   }
  680. -   if (ca == 1) {
  681. -     background = 1;
  682. -     setBackgroundHints(StandardBackground);
  683. -   }
  684. -   if (ca == 2) {
  685. -     background = 2;
  686. -     setBackgroundHints(TranslucentBackground);
  687. -   }
  688. -   if (ca == 3) {
  689. -     background = 3;
  690. -     setBackgroundHints(NoBackground);
  691. - }
  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;
  709. +       }
  710.  }
  711.  
  712.  QList<QAction*> PlasmaYasdp::contextualActions()
  713. @@ -525,8 +502,8 @@ QList<QAction*> PlasmaYasdp::contextualA
  714.      return m_actions;
  715.  }
  716.  
  717. -
  718. +
  719.  // This is the command that links your applet to the .desktop file
  720.  K_EXPORT_PLASMA_APPLET(yasdp, PlasmaYasdp)
  721. -
  722. +
  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 @@
  729.  
  730.  // We need the Plasma Applet headers
  731.  #include <KIcon>
  732. -
  733. +
  734.  #include <Plasma/Applet>
  735.  #include <Plasma/Svg>
  736.  #include <plasma/widgets/iconwidget.h>
  737.  #include <plasma/widgets/label.h>
  738.  
  739.  #include "ui_AppearanceConfig.h"
  740. -
  741. +
  742.  class QSizeF;
  743. -
  744. +
  745.  // Define our plasma Applet
  746.  class PlasmaYasdp : public Plasma::Applet
  747.  {
  748. @@ -25,15 +25,15 @@ class PlasmaYasdp : public Plasma::Apple
  749.          // Basic Create/Destroy
  750.          PlasmaYasdp(QObject *parent, const QVariantList &args);
  751.          ~PlasmaYasdp();
  752. -
  753. +
  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();
  759.  
  760. -
  761. -      
  762. +
  763. +
  764.       public slots:
  765.  
  766.       void configAccepted();
  767. @@ -49,22 +49,21 @@ class PlasmaYasdp : public Plasma::Apple
  768.      protected:
  769.      void createConfigurationInterface(KConfigDialog *parent);
  770.      QList<QAction*> contextualActions();
  771. -    
  772. +
  773.      private:
  774. -      
  775. +
  776.          Ui::AppearanceConfig uiAppear;
  777.          Plasma::Svg m_svg;
  778.  
  779.  
  780. -        
  781. +
  782.          typedef struct {
  783.            Plasma::IconWidget *m_icon;
  784.            QString iconname;
  785.            QString deficonname;
  786.            bool iconshow;
  787. -          bool iconexist;
  788.          } icon;
  789. -        
  790. +
  791.          icon shutdown;
  792.          icon reboot;
  793.          icon suspend;
  794. @@ -79,7 +78,7 @@ class PlasmaYasdp : public Plasma::Apple
  795.          QList<QAction*> m_actions;
  796.  
  797.          QGraphicsLinearLayout *layout;
  798. -        
  799. +
  800.  };
  801. -
  802. +
  803.  #endif
  804. \ No newline at end of file