LogoopenSUSE Build Service > Projects
Sign Up | Log In

View File ksmserver-shutdown-upower.patch of Package kdebase3 (Project openSUSE:Factory)

diff -wruN kdebase-3.5.10.orig/ksmserver/shutdowndlg.cpp kdebase-3.5.10/ksmserver/shutdowndlg.cpp
--- kdebase-3.5.10.orig/ksmserver/shutdowndlg.cpp	2012-02-22 08:17:40.342199124 +0400
+++ kdebase-3.5.10/ksmserver/shutdowndlg.cpp	2012-02-26 05:57:11.235726994 +0400
@@ -47,15 +47,15 @@
 #include <unistd.h>
 #include <stdlib.h>
 #include <dmctl.h>
-#include <liblazy.h>
 
 #include <X11/Xlib.h>
 
 #include "shutdowndlg.moc"
 
-#define DBUS_HAL_INTERFACE		"org.freedesktop.Hal"
-#define DBUS_HAL_SYSTEM_POWER_INTERFACE	"org.freedesktop.Hal.Device.SystemPowerManagement"
-#define HAL_UDI_COMPUTER		"/org/freedesktop/Hal/devices/computer"
+#include <dbus/qdbusdata.h>
+#include <dbus/qdbusmessage.h>
+#include <dbus/qdbusproxy.h>
+#include <dbus/qdbusvariant.h>
 
 static const int max_faded = 2300;
 static const int slice = 20;
@@ -265,43 +265,29 @@
 	} else
             QToolTip::add( btnReboot, i18n( "<qt><h3>Restart Computer</h3><p>Log out of the current session and restart the computer</p></qt>" ) );
 
-	DCOPRef kpowersave( "kpowersave", "KPowersaveIface" );
-	DCOPReply reply = kpowersave.call( "allowed_sleepingStates" );
-	if( reply.isValid()) {
-	    QStringList supported = reply;
-	    suspend_ram = supported.contains( "suspendToRAM" );
-	    suspend_disk = supported.contains( "suspendToDisk" );
-	    standby = supported.contains( "standBy" );
-	} else {
-	int supported = -1;
-	liblazy_hal_get_property_bool(HAL_UDI_COMPUTER, "power_management.can_suspend", &supported);
-	if (supported == 1)
-	     suspend_ram = true;
-	else
-	     suspend_ram = false;
-	liblazy_hal_get_property_bool(HAL_UDI_COMPUTER, "power_management.can_standby", &supported);
-	if (supported == 1)
-	     standby = true;
-	else
-	     standby = false;
-	liblazy_hal_get_property_bool(HAL_UDI_COMPUTER, "power_management.can_hibernate", &supported);
-	if (supported == 1)
-	     suspend_disk = true;
-	else
-	     suspend_disk = false;
+		m_dbusConn = QDBusConnection::addConnection(QDBusConnection::SystemBus);
+	
+		QDBusProxy upowerProperties("org.freedesktop.UPower", "/org/freedesktop/UPower", "org.freedesktop.DBus.Properties", m_dbusConn);
 	
-	if (liblazy_hal_is_caller_privileged("org.freedesktop.hal.power-management.hibernate") != 1) 
-	     suspend_disk = false;
-	if (liblazy_hal_is_caller_privileged("org.freedesktop.hal.power-management.suspend") != 1) 
-	     suspend_ram = false;
-	if (liblazy_hal_is_caller_privileged("org.freedesktop.hal.power-management.standby") != 1) 
+		// can suspend?
+		QValueList<QDBusData> params;
+		params << QDBusData::fromString(upowerProperties.interface()) << QDBusData::fromString("CanSuspend");
+		QDBusMessage reply = upowerProperties.sendWithReply("Get", params);
+		if(reply.type() == QDBusMessage::ReplyMessage && reply.count() == 1)
+			suspend_ram = reply[0].toVariant().value.toBool();
+
+		// can hibernate?
+		params.clear();
+		params << QDBusData::fromString(upowerProperties.interface()) << QDBusData::fromString("CanHibernate");
+		reply = upowerProperties.sendWithReply("Get", params);
+		if(reply.type() == QDBusMessage::ReplyMessage && reply.count() == 1)
+			suspend_disk = reply[0].toVariant().value.toBool();
 	    standby = false;
-	}
 	
 	int sum = standby + suspend_ram + suspend_disk;
 	if ( sum ) {
 	     QButton *btnSuspend;
-	     if (sum > 1) {
+	     if (sum >= 1) {
 		  btnSuspend = new KSMDelayedPushButton( KGuiItem( i18n("&Suspend Computer"), "player_pause"), frame );
 		  QPopupMenu *suspends = new QPopupMenu(frame);
 		  if (suspend_disk)
@@ -312,8 +298,6 @@
 		       suspends->insertItem(i18n("Standby"), 3);
 		  connect(suspends, SIGNAL(activated(int)), SLOT(slotSuspend(int)));
 		  static_cast<KSMDelayedPushButton*>(btnSuspend)->setPopup(suspends);
-	     } else {
-		  btnSuspend = new KPushButton( KGuiItem( i18n("&Suspend Computer"), "player_pause"), frame );
 	     }
 	     btnSuspend->setFont( btnFont );
 	     buttonlay->addWidget( btnSuspend );
@@ -334,55 +318,25 @@
 
 void KSMShutdownDlg::slotSuspend()
 {
-  int error = 0;
-    DCOPRef kpowersave( "kpowersave", "KPowersaveIface" );
-    DCOPReply reply = kpowersave.call( "allowed_sleepingStates" );
-    if( reply.isValid()) {
-	bool ok;
-	// so that screen locking can take place
-	extern Time qt_x_time;
-	XUngrabKeyboard( qt_xdisplay(), qt_x_time );
-	XUngrabPointer( qt_xdisplay(), qt_x_time );
-	XSync( qt_xdisplay(), False );
-	if( suspend_disk )
-	    ok = kpowersave.call( "do_suspendToDisk" );
-	else if( suspend_ram )
-	    ok = kpowersave.call( "do_suspendToRAM" );
-	else
-	    ok = kpowersave.call( "do_standBy" );
-	error = ok ? 0 : 1;
-    } else {
-  
-  int wake = 0;
-  DBusMessage *reply;
 
-  if (suspend_disk)
-       error = liblazy_dbus_system_send_method_call(DBUS_HAL_INTERFACE,
-						    HAL_UDI_COMPUTER,
-						    DBUS_HAL_SYSTEM_POWER_INTERFACE,
-						    "Hibernate",
-						    &reply,
-						    DBUS_TYPE_INVALID);
-  else if (suspend_ram)
-       error = liblazy_dbus_system_send_method_call(DBUS_HAL_INTERFACE,
-						    HAL_UDI_COMPUTER,
-						    DBUS_HAL_SYSTEM_POWER_INTERFACE,
-						    "Suspend",
-						    &reply,
-						    DBUS_TYPE_INT32,
-						    &wake,
-						    DBUS_TYPE_INVALID);
-  else
-       error = liblazy_dbus_system_send_method_call(DBUS_HAL_INTERFACE,
-						    HAL_UDI_COMPUTER,
-						    DBUS_HAL_SYSTEM_POWER_INTERFACE,
-						    "Standby",
-						    &reply,
-						    DBUS_TYPE_INVALID);
+  if (suspend_disk) {
+	if( m_dbusConn.isConnected() ) {
+		QDBusMessage msg = QDBusMessage::methodCall(
+					"org.freedesktop.UPower",
+					"/org/freedesktop/UPower",
+					"org.freedesktop.UPower",
+					"Hibernate");
+		m_dbusConn.sendWithReply(msg);
+	}
+  } else 
+	if( m_dbusConn.isConnected() ) {
+		QDBusMessage msg = QDBusMessage::methodCall(
+					"org.freedesktop.UPower",
+					"/org/freedesktop/UPower",
+					"org.freedesktop.UPower",
+					"Suspend");
+		m_dbusConn.sendWithReply(msg);
     }
-  
-  if (error)
-       KMessageBox::error(this, i18n("Suspend failed"));
   
   // possibly after resume :)
   reject();
@@ -390,60 +344,27 @@
 
 void KSMShutdownDlg::slotSuspend(int id)
 {
-  int error = 0;
-
-    DCOPRef kpowersave( "kpowersave", "KPowersaveIface" );
-    DCOPReply reply = kpowersave.call( "allowed_sleepingStates" );
-    if( reply.isValid()) {
-	bool ok;
-	extern Time qt_x_time;
-	XUngrabKeyboard( qt_xdisplay(), qt_x_time );
-	XUngrabPointer( qt_xdisplay(), qt_x_time );
-	XSync( qt_xdisplay(), False );
-	if( suspend_disk && id == 1 )
-	    ok = kpowersave.call( "do_suspendToDisk" );
-	else if( suspend_ram && id == 2 )
-	    ok = kpowersave.call( "do_suspendToRAM" );
-	else if( standby && id == 3 )
-	    ok = kpowersave.call( "do_standBy" );
-	else
-	    return;
-	error = ok ? 0 : 1;
-    } else {
-
-
-  int wake = 0;
-  DBusMessage *reply;
 
   if (suspend_disk && id == 1) {
-       error = liblazy_dbus_system_send_method_call(DBUS_HAL_INTERFACE,
-						    HAL_UDI_COMPUTER,
-						    DBUS_HAL_SYSTEM_POWER_INTERFACE,
-						    "Hibernate",
-						    &reply,
-						    DBUS_TYPE_INVALID);
+	if( m_dbusConn.isConnected() ) {
+		QDBusMessage msg = QDBusMessage::methodCall(
+					"org.freedesktop.UPower",
+					"/org/freedesktop/UPower",
+					"org.freedesktop.UPower",
+					"Hibernate");
+		m_dbusConn.sendWithReply(msg);
+	}
   } else if (suspend_ram && id == 2)
-       error = liblazy_dbus_system_send_method_call(DBUS_HAL_INTERFACE,
-						    HAL_UDI_COMPUTER,
-						    DBUS_HAL_SYSTEM_POWER_INTERFACE,
-						    "Suspend",
-						    &reply,
-						    DBUS_TYPE_INT32,
-						    &wake,
-						    DBUS_TYPE_INVALID);
-  else if (standby && id == 3)
-       error = liblazy_dbus_system_send_method_call(DBUS_HAL_INTERFACE,
-						    HAL_UDI_COMPUTER,
-						    DBUS_HAL_SYSTEM_POWER_INTERFACE,
-						    "Standby",
-						    &reply,
-						  DBUS_TYPE_INVALID);
-  else
-       return;
+	if( m_dbusConn.isConnected() ) {
+		QDBusMessage msg = QDBusMessage::methodCall(
+					"org.freedesktop.UPower",
+					"/org/freedesktop/UPower",
+					"org.freedesktop.UPower",
+					"Suspend");
+		m_dbusConn.sendWithReply(msg);
     }
-
-  if (error)
-       KMessageBox::error(this, i18n("Suspend failed"));
+  else
+       KSMShutdownDlg::slotSuspend(); return;
   
   // possibly after resume :)
   reject();
diff -wruN kdebase-3.5.10.orig/ksmserver/shutdowndlg.h kdebase-3.5.10/ksmserver/shutdowndlg.h
--- kdebase-3.5.10.orig/ksmserver/shutdowndlg.h	2012-02-20 01:01:49.084200000 +0400
+++ kdebase-3.5.10/ksmserver/shutdowndlg.h	2012-02-25 16:45:19.519737644 +0400
@@ -12,6 +12,7 @@
 #include <qdatetime.h>
 #include <kpushbutton.h>
 #include <qimage.h>
+#include <dbus/qdbusconnection.h>
 class QPushButton;
 class QVButtonGroup;
 class QPopupMenu;
@@ -74,6 +75,7 @@
     QPopupMenu *targets;
     QStringList rebootOptions;
     bool suspend_disk, suspend_ram, standby;
+    QDBusConnection m_dbusConn;
 };
 
 class KSMDelayedPushButton : public KPushButton