File ksmserver-suspend_legacy-10.1.diff of Package kdebase3

--- ksmserver/Makefile.am
+++ ksmserver/Makefile.am
@@ -17,7 +17,7 @@
 
 SUBDIRS = .
 
-INCLUDES= -I$(top_srcdir)/kdmlib $(all_includes)
+INCLUDES= -I$(top_srcdir)/kdmlib $(all_includes) $(DBUS_INCS)
 
 bin_PROGRAMS =
 lib_LTLIBRARIES =
@@ -31,7 +31,7 @@
 	KSMServerInterface.skel server.skel
 
 ksmserver_la_LDFLAGS = $(all_libraries) -avoid-version -module
-ksmserver_la_LIBADD = ../kdmlib/libdmctl.la $(LIB_KDEUI)
+ksmserver_la_LIBADD = ../kdmlib/libdmctl.la $(LIB_KDEUI) -lpowersave_dbus -lpowersave $(DBUS_LIBS)
 
 picsdir = $(kde_datadir)/ksmserver/pics
 pics_DATA = shutdownkonq.png
@@ -44,7 +44,7 @@
 EXTRA_PROGRAMS = testsh
 testsh_SOURCES = test.cpp
 testsh_LDFLAGS = $(all_libraries) $(KDE_RPATH)
-testsh_LDADD = $(LIB_KDEUI) shutdowndlg.lo ../kdmlib/libdmctl.la
+testsh_LDADD = $(LIB_KDEUI) shutdowndlg.lo ../kdmlib/libdmctl.la -lpowersave_dbus $(DBUS_LIBS)
 
 messages:
 	$(XGETTEXT) *.cpp -o $(podir)/ksmserver.pot
--- ksmserver/shutdowndlg.cpp
+++ ksmserver/shutdowndlg.cpp
@@ -38,12 +38,15 @@
 #include <kpixmapeffect.h>
 #include <kdialog.h>
 #include <kseparator.h>
+#include <kmessagebox.h>
 
 #include <sys/types.h>
 #include <sys/utsname.h>
 #include <unistd.h>
 #include <stdlib.h>
 #include <dmctl.h>
+#include <powerlib.h>
+#include <powersave_dbus.h>
 
 #include <X11/Xlib.h>
 
@@ -234,8 +237,55 @@
 	  connect( targets, SIGNAL(activated(int)), SLOT(slotReboot(int)) );
 	} else
             QToolTip::add( btnReboot, i18n( "<qt><h3>Restart Computer</h3><p>Log out of the current session and restart the computer</p></qt>" ) );
-    }
 
+	int64_t supported_sleep_states = getSupportedSleepStates();
+	suspend_ram = ((supported_sleep_states & APM_SUSPEND) || 
+		       (supported_sleep_states & ACPI_S3) || 
+		       (supported_sleep_states & ACPI_S3_BIOS));
+	standby = ((supported_sleep_states & APM_STANDBY) || 
+		   (supported_sleep_states & ACPI_S1));
+	suspend_disk = ((supported_sleep_states & APM_SUSPEND) || 
+			(supported_sleep_states & ACPI_S4) || 
+			(supported_sleep_states & ACPI_S4_BIOS));
+	
+	int err_code = dbusSendSimpleMessage(REQUEST_MESSAGE,
+					 "suspend_to_disk_allowed");
+	//REPLY_DISABLED means disabled, there are also other errors we don't care ...
+	if (err_code != REPLY_SUCCESS)
+	  suspend_disk = false;
+	
+	err_code = dbusSendSimpleMessage(REQUEST_MESSAGE,
+					 "suspend_to_ram_allowed");
+	if (err_code != REPLY_SUCCESS)
+	  suspend_ram = false;
+	
+	err_code = dbusSendSimpleMessage(REQUEST_MESSAGE,
+					 "standby_allowed");
+	if (err_code != REPLY_SUCCESS)
+	  standby = false;
+        
+	int sum = standby + suspend_ram + suspend_disk;
+	if ( sum ) {
+	  QButton *btnSuspend;
+	  if (sum > 1) {
+	    btnSuspend = new KSMDelayedPushButton( KGuiItem( i18n("&Suspend Computer"), "player_pause"), frame );
+	    QPopupMenu *suspends = new QPopupMenu(frame);
+	    if (suspend_disk)
+	      suspends->insertItem(i18n("Suspend to Disk"), 1);
+	    if (suspend_ram)
+	      suspends->insertItem(i18n("Suspend to RAM"), 2);
+	    if (standby)
+	      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 );
+	  connect(btnSuspend, SIGNAL(clicked()), SLOT(slotSuspend()));
+	}
+    }
     buttonlay->addStretch( 1 );
 
     // Separator
@@ -248,6 +298,41 @@
 
 }
 
+void KSMShutdownDlg::slotSuspend()
+{
+  int res = REPLY_SUCCESS;
+  if (suspend_disk)
+    res = dbusSendSimpleMessage(ACTION_MESSAGE, "suspend_to_disk");
+  else if (suspend_ram)
+    res = dbusSendSimpleMessage(ACTION_MESSAGE, "suspend_to_ram");
+  else
+    res = dbusSendSimpleMessage(ACTION_MESSAGE, "standby");
+  
+  if (res != REPLY_SUCCESS)
+    KMessageBox::error(this, i18n("Suspend failed"));
+  
+  // possibly after resume :)
+  reject();
+}
+
+void KSMShutdownDlg::slotSuspend(int id)
+{
+  int res = REPLY_SUCCESS;
+  if (suspend_disk && id == 1)
+    res = dbusSendSimpleMessage(ACTION_MESSAGE, "suspend_to_disk");
+  else if (suspend_ram && id == 2)
+    res = dbusSendSimpleMessage(ACTION_MESSAGE, "suspend_to_ram");
+  else if (standby && id == 3)
+    res = dbusSendSimpleMessage(ACTION_MESSAGE, "standby");
+  else
+    return;
+
+  if (res != REPLY_SUCCESS)
+    KMessageBox::error(this, i18n("Suspend failed"));
+  
+  // possibly after resume :)
+  reject();
+}
 
 void KSMShutdownDlg::slotLogout()
 {
--- ksmserver/shutdowndlg.h
+++ ksmserver/shutdowndlg.h
@@ -59,6 +59,8 @@
     void slotHalt();
     void slotReboot();
     void slotReboot(int);
+    void slotSuspend();
+    void slotSuspend(int);
 
 protected:
     ~KSMShutdownDlg() {};
@@ -69,6 +71,7 @@
     QString m_bootOption;
     QPopupMenu *targets;
     QStringList rebootOptions;
+    bool suspend_disk, suspend_ram, standby;
 };
 
 class KSMDelayedPushButton : public KPushButton
openSUSE Build Service is sponsored by