summaryrefslogtreecommitdiffstats
path: root/opensuse/core/tdebase/ksmserver-suspend.diff
blob: ef7a8803603850e22942c281e0f5450da5ba9b59 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
Index: ksmserver/Makefile.am
===================================================================
--- ksmserver/Makefile.am.orig
+++ 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 @@ ksmserver_la_SOURCES = main.cpp server.c
 	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 @@ updatedir = $(kde_datadir)/kconf_update
 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
Index: ksmserver/shutdowndlg.cpp
===================================================================
--- ksmserver/shutdowndlg.cpp.orig
+++ ksmserver/shutdowndlg.cpp
@@ -38,17 +38,23 @@ Copyright (C) 2000 Matthias Ettrich <ett
 #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 <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"
+
 static const int max_faded = 2300;
 static const int slice = 20;
 
@@ -215,8 +221,8 @@ KSMShutdownDlg::KSMShutdownDlg( QWidget*
     connect(btnLogout, SIGNAL(clicked()), SLOT(slotLogout()));
 
     if (maysd) {
-
-        // Shutdown
+	
+	// Shutdown
         KPushButton* btnHalt = new KPushButton( KGuiItem( i18n("&Turn Off Computer"), "exit"), frame );
         QToolTip::add( btnHalt, i18n( "<qt><h3>Turn Off Computer</h3><p>Log out of the current session and turn off the computer</p></qt>" ) );
         btnHalt->setFont( btnFont );
@@ -251,13 +257,58 @@ KSMShutdownDlg::KSMShutdownDlg( QWidget*
 	      else
 		targets->insertItem( label, index );
 	    }
-
+	  
 	  btnReboot->setPopup(targets);
 	  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>" ) );
-    }
 
+	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("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) 
+	    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
@@ -270,6 +321,80 @@ KSMShutdownDlg::KSMShutdownDlg( QWidget*
 
 }
 
+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();
+}
 
 void KSMShutdownDlg::slotLogout()
 {
Index: ksmserver/shutdowndlg.h
===================================================================
--- ksmserver/shutdowndlg.h.orig
+++ ksmserver/shutdowndlg.h
@@ -60,6 +60,8 @@ public slots:
     void slotHalt();
     void slotReboot();
     void slotReboot(int);
+    void slotSuspend();
+    void slotSuspend(int);
 
 protected:
     ~KSMShutdownDlg() {};
@@ -70,6 +72,7 @@ private:
     QString m_bootOption;
     QPopupMenu *targets;
     QStringList rebootOptions;
+    bool suspend_disk, suspend_ram, standby;
 };
 
 class KSMDelayedPushButton : public KPushButton