[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdebase/workspace/plasma/applets/lock_logout
From:       Frederik Gladhorn <gladhorn () kde ! org>
Date:       2009-07-17 9:06:49
Message-ID: 1247821609.225732.31151.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 998234 by gladhorn:

add hibernate and suspend buttons
any button combination can be displayed, the new buttons are hidden by default \
(config) some minor cleanup


 M  +1 -1      CMakeLists.txt  
 M  +100 -9    lockout.cpp  
 M  +7 -0      lockout.h  
 M  +32 -17    lockoutConfig.ui  


--- trunk/KDE/kdebase/workspace/plasma/applets/lock_logout/CMakeLists.txt \
#998233:998234 @@ -15,7 +15,7 @@
 kde4_add_plugin(plasma_applet_lockout ${lockout_SRCS})
 target_link_libraries(plasma_applet_lockout ${KDE4_PLASMA_LIBS} ${KDE4_KIO_LIBS})
 if(NOT WIN32)
-target_link_libraries(plasma_applet_lockout kworkspace)
+target_link_libraries(plasma_applet_lockout kworkspace solidcontrol)
 endif(NOT WIN32)
 
 install(TARGETS plasma_applet_lockout DESTINATION ${PLUGIN_INSTALL_DIR})
--- trunk/KDE/kdebase/workspace/plasma/applets/lock_logout/lockout.cpp #998233:998234
@@ -1,5 +1,6 @@
 /***************************************************************************
  *   Copyright (C) 2007 by Alexis Ménard <darktears31@gmail.com>           *
+ *   Copyright (C) 2009 by Frederik Gladhorn <gladhorn@kde.org>            *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
  *   it under the terms of the GNU General Public License as published by  *
@@ -31,6 +32,7 @@
 
 // KDE
 #include <KIcon>
+#include <KJob>
 #ifndef Q_OS_WIN
 #include <KConfigDialog>
 #include <KSharedConfig>
@@ -38,6 +40,8 @@
 #include <screensaver_interface.h>
 #endif
 
+#include <solid/control/powermanager.h>
+
 // Windows
 #ifdef Q_OS_WIN
 #define _WIN32_WINNT 0x0500 // require NT 5.0 (win 2k pro)
@@ -66,6 +70,8 @@
     KConfigGroup cg = config();
     m_showLockButton = cg.readEntry("showLockButton", true);
     m_showLogoutButton = cg.readEntry("showLogoutButton", true);
+    m_showSleepButton = cg.readEntry("showSleepButton", false);
+    m_showHibernateButton = cg.readEntry("showHibernateButton", false);
 #endif
 
     //Tooltip strings maybe should be different (eg. "Leave..."->"Logout")?
@@ -79,6 +85,16 @@
     Plasma::ToolTipContent logoutToolTip(i18n("Leave..."),i18n("Logout, turn off or \
                restart the computer"),m_iconLogout->icon());
     Plasma::ToolTipManager::self()->setContent(m_iconLogout, logoutToolTip);
 
+    m_iconSleep = new Plasma::IconWidget(KIcon("system-suspend"), "", this);
+    connect(m_iconSleep, SIGNAL(clicked()), this, SLOT(clickSleep()));
+    Plasma::ToolTipContent sleepToolTip(i18n("Suspend"),i18n("Sleep (suspend to \
RAM)"),m_iconSleep->icon()); +    \
Plasma::ToolTipManager::self()->setContent(m_iconSleep, sleepToolTip); +    
+    m_iconHibernate = new Plasma::IconWidget(KIcon("system-suspend-hibernate"), "", \
this); +    connect(m_iconHibernate, SIGNAL(clicked()), this, \
SLOT(clickHibernate())); +    Plasma::ToolTipContent \
hibernateToolTip(i18n("Hibernate"),i18n("Hibernate (suspend to \
disk)"),m_iconHibernate->icon()); +    \
Plasma::ToolTipManager::self()->setContent(m_iconHibernate, hibernateToolTip); +   
     showButtons();
 }
 
@@ -115,7 +131,7 @@
     }
 
 #ifndef Q_OS_WIN
-    if (!m_showLockButton || !m_showLogoutButton) {
+    if (!m_showLockButton || !m_showLogoutButton || !m_showSleepButton || \
!m_showHibernateButton) {  ratioToKeep = 1;
     }
 #endif
@@ -177,6 +193,58 @@
 #endif
 }
 
+#include <KMessageBox>
+
+void LockOut::clickSleep()
+{
+    if (KMessageBox::questionYesNo(0,
+                                   i18n("Do you want to suspend to RAM (sleep)?"),
+                                   i18n("Suspend"))
+            != KMessageBox::Yes) {
+        return;
+    }
+    // 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 LockOut::clickHibernate()
+{
+    if (KMessageBox::questionYesNo(0,
+                                   i18n("Do you want to suspend to disk \
(hibernate)?"), +                                   i18n("Suspend"))
+            != KMessageBox::Yes) {
+        return;
+    }
+    // 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 LockOut::configAccepted()
 {
 #ifndef Q_OS_WIN
@@ -195,6 +263,18 @@
         changed = true;
     }
 
+    if (m_showSleepButton != ui.checkBox_sleep->isChecked()) {
+        m_showSleepButton = !m_showSleepButton;
+        cg.writeEntry("showSleepButton", m_showSleepButton);
+        changed = true;
+    }
+
+    if (m_showHibernateButton != ui.checkBox_hibernate->isChecked()) {
+        m_showHibernateButton = !m_showHibernateButton;
+        cg.writeEntry("showHibernateButton", m_showHibernateButton);
+        changed = true;
+    }
+
     if (changed) {
         showButtons();
         emit configNeedsSaving();
@@ -213,6 +293,8 @@
 
     ui.checkBox_lock->setChecked(m_showLockButton);
     ui.checkBox_logout->setChecked(m_showLogoutButton);
+    ui.checkBox_sleep->setChecked(m_showSleepButton);
+    ui.checkBox_hibernate->setChecked(m_showHibernateButton);
 #endif
 }
 
@@ -225,22 +307,31 @@
     //definitely not the best workaround...
     m_layout->removeItem(m_iconLock);
     m_layout->removeItem(m_iconLogout);
+    m_layout->removeItem(m_iconSleep);
+    m_layout->removeItem(m_iconHibernate);
 
-    if (m_showLockButton) {
-	m_iconLock->setVisible(true);
+    m_iconLock->setVisible(m_showLockButton);
+
+    if (m_showLockButton) { 
         m_layout->addItem(m_iconLock);
-    } else {
-	m_iconLock->setVisible(false);
     }
 
+    m_iconLogout->setVisible(m_showLogoutButton);
     if (m_showLogoutButton) {
-	m_iconLogout->setVisible(true);
         m_layout->addItem(m_iconLogout);
-    } else {
-	m_iconLogout->setVisible(false);
     }
 
-    setConfigurationRequired(!m_showLockButton && !m_showLogoutButton);
+    m_iconSleep->setVisible(m_showSleepButton);
+    if (m_showSleepButton) {
+        m_layout->addItem(m_iconSleep);
+    }
+
+    m_iconHibernate->setVisible(m_showHibernateButton);
+    if (m_showHibernateButton) {
+        m_layout->addItem(m_iconHibernate);
+    }
+
+    setConfigurationRequired(!m_showLockButton && !m_showLogoutButton && \
!m_showSleepButton && !m_showHibernateButton);  checkLayout();
 #endif // !Q_OS_WIN
 }
--- trunk/KDE/kdebase/workspace/plasma/applets/lock_logout/lockout.h #998233:998234
@@ -1,5 +1,6 @@
 /***************************************************************************
  *   Copyright (C) 2007 by Alexis Ménard <darktears31@gmail.com>           *
+ *   Copyright (C) 2009 by Frederik Gladhorn <gladhorn@kde.org>            *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
  *   it under the terms of the GNU General Public License as published by  *
@@ -46,6 +47,8 @@
     public slots:
         void clickLogout();
         void clickLock();
+        void clickSleep();
+        void clickHibernate();
 
     protected Q_SLOTS:
         void configAccepted();
@@ -58,9 +61,13 @@
         Ui::lockoutConfig ui;
         bool m_showLockButton;
         bool m_showLogoutButton;
+        bool m_showSleepButton;
+        bool m_showHibernateButton;
 #endif
         Plasma::IconWidget *m_iconLock;
         Plasma::IconWidget *m_iconLogout;
+        Plasma::IconWidget *m_iconSleep;
+        Plasma::IconWidget *m_iconHibernate;
         QGraphicsLinearLayout *m_layout;
         void checkLayout();
         void showButtons();
--- trunk/KDE/kdebase/workspace/plasma/applets/lock_logout/lockoutConfig.ui \
#998233:998234 @@ -1,38 +1,39 @@
-<ui version="4.0" >
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
  <class>lockoutConfig</class>
- <widget class="QWidget" name="lockoutConfig" >
-  <property name="geometry" >
+ <widget class="QWidget" name="lockoutConfig">
+  <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>159</width>
-    <height>102</height>
+    <width>177</width>
+    <height>116</height>
    </rect>
   </property>
-  <property name="windowTitle" >
+  <property name="windowTitle">
    <string>Configure Lock/Logout</string>
   </property>
-  <layout class="QGridLayout" name="gridLayout" >
-   <item row="0" column="0" >
-    <widget class="QCheckBox" name="checkBox_lock" >
-     <property name="text" >
+  <layout class="QGridLayout" name="gridLayout">
+   <item row="0" column="0">
+    <widget class="QCheckBox" name="checkBox_lock">
+     <property name="text">
       <string>Show lock button</string>
      </property>
     </widget>
    </item>
-   <item row="1" column="0" >
-    <widget class="QCheckBox" name="checkBox_logout" >
-     <property name="text" >
+   <item row="1" column="0">
+    <widget class="QCheckBox" name="checkBox_logout">
+     <property name="text">
       <string>Show logout button</string>
      </property>
     </widget>
    </item>
-   <item row="2" column="0" >
-    <spacer name="verticalSpacer" >
-     <property name="orientation" >
+   <item row="4" column="0">
+    <spacer name="verticalSpacer">
+     <property name="orientation">
       <enum>Qt::Vertical</enum>
      </property>
-     <property name="sizeHint" stdset="0" >
+     <property name="sizeHint" stdset="0">
       <size>
        <width>20</width>
        <height>40</height>
@@ -40,6 +41,20 @@
      </property>
     </spacer>
    </item>
+   <item row="3" column="0">
+    <widget class="QCheckBox" name="checkBox_hibernate">
+     <property name="text">
+      <string>Show hibernate button</string>
+     </property>
+    </widget>
+   </item>
+   <item row="2" column="0">
+    <widget class="QCheckBox" name="checkBox_sleep">
+     <property name="text">
+      <string>Show sleep button</string>
+     </property>
+    </widget>
+   </item>
   </layout>
  </widget>
  <resources/>


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic