--- kdebase-3.5.8/ksmserver/Makefile.am +++ kdebase-3.5.8/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) -llazy $(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 -llazy $(DBUS_LIBS) messages: $(XGETTEXT) *.cpp -o $(podir)/ksmserver.pot diff -r -u kdebase-3.5.8.orig/ksmserver/shutdowndlg.cpp kdebase-3.5.8/ksmserver/shutdowndlg.cpp --- kdebase-3.5.8.orig/ksmserver/shutdowndlg.cpp 2006-12-04 08:48:05.000000000 -0200 +++ kdebase-3.5.8/ksmserver/shutdowndlg.cpp 2007-12-17 11:04:07.000000000 -0200 @@ -23,6 +23,7 @@ #include <qpopupmenu.h> #include <qtooltip.h> #include <qimage.h> +#include <kmessagebox.h> #include <klocale.h> #include <kapplication.h> @@ -43,11 +44,16 @@ #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" + KSMShutdownFeedback * KSMShutdownFeedback::s_pSelf = 0L; KSMShutdownFeedback::KSMShutdownFeedback() @@ -168,6 +174,51 @@ btnReboot->setPopup(targets); connect( targets, SIGNAL(activated(int)), SLOT(slotReboot(int)) ); + } + 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; + + if (liblazy_hal_is_caller_privileged("hal-power-hibernate") != 1) + suspend_disk = false; + if (liblazy_hal_is_caller_privileged("hal-power-suspend") != 1) + suspend_ram = false; + if (liblazy_hal_is_caller_privileged("hal-power-standby") != 1) + 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())); } } @@ -276,3 +327,79 @@ popt->stop(); setDown(false); } + +void KSMShutdownDlg::slotSuspend() +{ + int error = 0; + 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 (error) + KMessageBox::error(this, i18n("Suspend failed")); + + // possibly after resume :) + reject(); +} + +void KSMShutdownDlg::slotSuspend(int id) +{ + int error = 0; + 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); + } 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 (error) + KMessageBox::error(this, i18n("Suspend failed")); + + // possibly after resume :) + reject(); +} + Somente em kdebase-3.5.8/ksmserver: shutdowndlg.cpp~ diff -r -u kdebase-3.5.8.orig/ksmserver/shutdowndlg.h kdebase-3.5.8/ksmserver/shutdowndlg.h --- kdebase-3.5.8.orig/ksmserver/shutdowndlg.h 2005-12-02 06:36:18.000000000 -0200 +++ kdebase-3.5.8/ksmserver/shutdowndlg.h 2007-12-17 11:04:52.000000000 -0200 @@ -54,6 +54,8 @@ void slotHalt(); void slotReboot(); void slotReboot(int); + void slotSuspend(); + void slotSuspend(int); protected: ~KSMShutdownDlg() {}; @@ -64,6 +66,7 @@ QString m_bootOption; QPopupMenu *targets; QStringList rebootOptions; + bool suspend_disk, suspend_ram, standby; }; class KSMDelayedPushButton : public KPushButton Somente em kdebase-3.5.8/ksmserver: shutdowndlg.h~