Browse Source

Switch from dbus-tqt do dbus-1-tqt

Add systemd session and inhibit support
Cleanup unused methods
This partially resolves Bug 1597
tags/r14.0.0
Slávek Banko 5 years ago
parent
commit
c68a1bac04
13 changed files with 332 additions and 989 deletions
  1. 3
    3
      ConfigureChecks.cmake
  2. 2
    2
      src/CMakeLists.txt
  3. 0
    1
      src/Makefile.am
  4. 255
    514
      src/dbusInterface.cpp
  5. 43
    75
      src/dbusInterface.h
  6. 17
    252
      src/hardware.cpp
  7. 3
    41
      src/hardware.h
  8. 0
    29
      src/hardware_battery.cpp
  9. 1
    1
      src/hardware_battery.h
  10. 0
    46
      src/privileges.h
  11. 0
    3
      src/settings.cpp
  12. 0
    8
      src/settings.h
  13. 8
    14
      src/tdepowersave.cpp

+ 3
- 3
ConfigureChecks.cmake View File

@@ -51,10 +51,10 @@ if( NOT DBUS_FOUND )
51 51
 endif( )
52 52
 
53 53
 
54
-# check for dbus-tqt
55
-pkg_search_module( DBUS_TQT dbus-tqt )
54
+# check for dbus-1-tqt
55
+pkg_search_module( DBUS_TQT dbus-1-tqt )
56 56
 if( NOT DBUS_TQT_FOUND )
57
-  tde_message_fatal( "dbus-tqt is required, but was not found on your system" )
57
+  tde_message_fatal( "dbus-1-tqt is required, but was not found on your system" )
58 58
 endif( )
59 59
 
60 60
 # check for msgfmt

+ 2
- 2
src/CMakeLists.txt View File

@@ -16,8 +16,8 @@ include_directories(
16 16
   ${CMAKE_BINARY_DIR}
17 17
   ${TDE_INCLUDE_DIR}
18 18
   ${TQT_INCLUDE_DIRS}
19
+  ${DBUS_INCLUDE_DIRS}
19 20
   ${DBUS_TQT_INCLUDE_DIRS}
20
-  ${HAL_INCLUDE_DIRS}
21 21
 )
22 22
 
23 23
 link_directories(
@@ -48,6 +48,6 @@ tde_add_tdeinit_executable( tdepowersave AUTOMOC
48 48
     tdepowersave.skel log_viewer.ui logviewer.cpp main.cpp
49 49
     screen.cpp settings.cpp suspenddialog.cpp suspend_Dialog.ui
50 50
   LINK
51
-    ${DBUS_TQT_LIBRARIES} tdeio-shared ${HAL_LIBRARIES}
51
+    ${DBUS_TQT_LIBRARIES} tdeio-shared
52 52
     ${XEXT_LIBRARIES} ${XTST_LIBRARIES} ${XSCRNSAVER_LIBRARIES}
53 53
 )

+ 0
- 1
src/Makefile.am View File

@@ -21,7 +21,6 @@ noinst_HEADERS =                                \
21 21
 		infodialog.h                    \
22 22
 		tdepowersave.h                    \
23 23
 		logviewer.h			\
24
-		privileges.h			\
25 24
 		screen.h                        \
26 25
 		settings.h                      \
27 26
 		suspenddialog.h

+ 255
- 514
src/dbusInterface.cpp View File

@@ -19,38 +19,52 @@
19 19
 
20 20
 /*! 
21 21
  * \file 	dbusInterface.cpp
22
- * \brief 	In this file can be found the functionality to connect to 
23
- *		the HAL daemon via D-Bus, to handle D-Bus calls/events and to
24
- *		provide wrapper to HAL lib and functions
22
+ * \brief 	In this file can be found the functionality to connect to
23
+ *		the D-Bus, to handle D-Bus session management
25 24
  * \author 	Danny Kukawka, <dkukawka@suse.de>, <danny.kukawka@web.de>
26 25
  * \date    	2006-2007
27 26
  */
28 27
  
29
-  // KDE Header
28
+// QT - Header
29
+#include <tqtimer.h>
30
+
31
+// KDE Header
30 32
 #include <tdelocale.h>
31 33
 
32 34
 // DBUS - Header
35
+#include "dbus/dbus-shared.h"
33 36
 #include "dbusInterface.h"
37
+#include <tqdbusdatalist.h>
38
+#include <tqdbusdatamap.h>
39
+#include <tqdbuserror.h>
40
+#include <tqdbusmessage.h>
41
+#include <tqdbusvariant.h>
34 42
 
35 43
 // system headers
36
-#include <iostream>
44
+#include <unistd.h>
45
+
46
+#define DBUS_CONN_NAME "TDEPowersave"
37 47
 
38 48
 static void* myInstance = 0;
39 49
 
40 50
 /*! The default constructor of the class dbusInterface. */
41
-dbusInterface::dbusInterface(){
51
+dbusInterface::dbusInterface():
52
+    dBusConn(),
53
+    dBusWatch(0),
54
+    dBusLocal(0),
55
+    systemdSession(),
56
+    systemdSeat(0),
57
+    systemdInhibit(-1),
58
+    consolekitSession(),
59
+    consolekitSeat(0)
60
+    {
42 61
 	kdDebugFuncIn(trace);
43 62
 
44
-	dbus_is_connected = false;
45
-	acquiredPolicyPower = false;
46
-
47 63
 	// add pointer to this for filter_function()
48 64
 	myInstance=this;
65
+
49 66
 	// init connection to dbus
50
-	if(!initDBUS()) {
51
-		kdError() << "Can't connect to D-Bus" << endl;
52
-		m_dBusQtConnection = NULL;
53
-	}
67
+	initDBUS();
54 68
 
55 69
 	kdDebugFuncOut(trace);
56 70
 }
@@ -72,30 +86,19 @@ dbusInterface::~dbusInterface(){
72 86
  * \retval false if disconnected
73 87
  */
74 88
 bool dbusInterface::isConnectedToDBUS() {
75
-	return dbus_is_connected;
76
-}
77
-
78
-/*! 
79
- * This function return information if the org.freedesktop.Policy.Power 
80
- * interface was claimed.
81
- * \return boolean with the status of claim the interface
82
- * \retval true if acquired 
83
- * \retval false if not
84
- */
85
-bool dbusInterface::acquiredPolicyPowerInterface() {
86
-	return acquiredPolicyPower;
89
+	return dBusConn.isConnected();
87 90
 }
88 91
 
89 92
 /*! 
90
- * This function try a reconnect to D-Bus and HAL  daemon.
93
+ * This function try a reconnect to D-Bus.
91 94
  * \return boolean with the result of the operation
92
- * \retval true if successful reconnected to D-Bus and HAL
95
+ * \retval true if successful reconnected to D-Bus
93 96
  * \retval false if unsuccessful
94 97
  */
95 98
 bool dbusInterface::reconnect() {
96 99
 	// close D-Bus connection
97 100
 	close();
98
-	// init D-Bus conntection and HAL context
101
+	// init D-Bus conntection
99 102
 	return (initDBUS());
100 103
 }
101 104
 
@@ -106,18 +109,24 @@ bool dbusInterface::reconnect() {
106 109
  * \retval false if any problems
107 110
  */
108 111
 bool dbusInterface::close() {
109
-	if ( m_dBusQtConnection != NULL ) {
110
-		releasePolicyPowerIface();
111
-		m_dBusQtConnection->close();
112
-		m_dBusQtConnection = NULL;
112
+	if( dBusConn.isConnected() ) {
113
+		if( dBusWatch ) {
114
+			delete dBusWatch;
115
+		}
116
+		if( dBusLocal ) {
117
+			delete dBusLocal;
118
+		}
119
+		if( systemdSeat ) {
120
+			delete systemdSeat;
121
+		}
122
+		if( consolekitSeat ) {
123
+			delete consolekitSeat;
124
+		}
113 125
 	}
114
-	dbus_is_connected = false;
115
-
126
+	dBusConn.closeConnection(DBUS_CONN_NAME);
116 127
 	return true;
117 128
 }
118 129
 
119
-/* ----> D-Bus section :: START <---- */
120
-
121 130
 /*! 
122 131
  * This function initialise the connection to the D-Bus daemon.
123 132
  * \return boolean with the result of the operation
@@ -127,528 +136,260 @@ bool dbusInterface::close() {
127 136
 bool dbusInterface::initDBUS(){
128 137
 	kdDebugFuncIn(trace);
129 138
 
130
-	dbus_is_connected = false;
131
-
132
-        DBusError error;
133
-        dbus_error_init(&error);
134
-	
135
-	dbus_connection = dbus_bus_get( DBUS_BUS_SYSTEM, &error );
139
+	dBusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus, DBUS_CONN_NAME);
136 140
 
137
-	if (dbus_connection == NULL){
138
-		kdError() << "Failed to open connection to system message bus: " << error.message << endl;
139
-		dbus_error_free (&error);
141
+	if( !dBusConn.isConnected() ) {
142
+		kdError() << "Failed to open connection to system message bus: " << dBusConn.lastError().message() << endl;
143
+		TQTimer::singleShot(4000, this, TQT_SLOT(reconnect()));
140 144
 		return false;
141 145
 	}
142 146
 
143
-	if ( dbus_error_is_set( &error ) ) {
144
-		kdError() << "Failed to register connection with system message bus: " << error.message << endl;
145
-		return false;
146
-	}
147
-
148
-	acquirePolicyPowerIface();
149
-
150
-	dbus_connection_set_exit_on_disconnect( dbus_connection, false );
151
-
152
-        /* add the filter function which should be executed on events on the bus */
153
-        if ( ! dbus_connection_add_filter( dbus_connection, filterFunction, this, NULL) ) {
154
-                kdFatal() << "Error: Not enough memory to add filter to dbus connection" << endl;
155
-                exit(EXIT_FAILURE);
156
-        }
157
-
158
-        /* add a match rule to catch all signals going through the bus with D-Bus interface */
159
-	dbus_bus_add_match( dbus_connection, "type='signal',"
160
-			    "interface='org.freedesktop.DBus'," 
161
-			    "member='NameOwnerChanged'", NULL);
162
-
163
-	/* add a match rule to catch all signals going through the bus with ConsoleKit Interface */
164
-	dbus_bus_add_match( dbus_connection, "type='signal',"
165
-			    "interface='org.freedesktop.ConsoleKit.Session'," 
166
-			    "member='ActiveChanged'", NULL);
167
-
168
-	m_dBusQtConnection = new DBusQt::Connection(this);
169
-        m_dBusQtConnection->dbus_connection_setup_with_qt_main(dbus_connection);
170
-
171
-	dbus_is_connected = true;
172
-
173
-	kdDebugFuncOut(trace);
174
-	return true;
175
-}
176
-
177
-/*!
178
- * This function acquire the org.freedesktop.Policy.Power interface
179
- * \return boolean with the result of the operation
180
- * \retval true 	if successful acquired the interface
181
- * \retval false 	if unsuccessful
182
- */
183
-bool dbusInterface::acquirePolicyPowerIface(){
184
-	kdDebugFuncIn(trace);
185
-
186
-	if (dbus_connection == NULL) {
187
-		kdDebugFuncOut(trace);
188
-		return false;
147
+	// watcher for NameOwnerChanged signals
148
+	dBusWatch = new TQT_DBusProxy(DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, dBusConn);
149
+	TQObject::connect(dBusWatch, TQT_SIGNAL(dbusSignal(const TQT_DBusMessage&)),
150
+			  this, TQT_SLOT(handleDBusSignal(const TQT_DBusMessage&)));
151
+
152
+	// watcher for Disconnect signal
153
+	dBusLocal = new TQT_DBusProxy(DBUS_SERVICE_DBUS, DBUS_PATH_LOCAL, DBUS_INTERFACE_LOCAL, dBusConn);
154
+	TQObject::connect(dBusLocal, TQT_SIGNAL(dbusSignal(const TQT_DBusMessage&)),
155
+			  this, TQT_SLOT(handleDBusSignal(const TQT_DBusMessage&)));
156
+
157
+	// find already running SystemD
158
+	TQT_DBusProxy checkSystemD(DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, dBusConn);
159
+	if( checkSystemD.canSend() ) {
160
+		TQValueList<TQT_DBusData> params;
161
+		params << TQT_DBusData::fromString(SYSTEMD_LOGIN1_SERVICE);
162
+		TQT_DBusMessage reply = checkSystemD.sendWithReply("NameHasOwner", params);
163
+		if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1 && reply[0].toBool() ) {
164
+			onServiceRegistered(SYSTEMD_LOGIN1_SERVICE);
165
+		}
189 166
 	}
190 167
 
191
-	DBusError err;
192
-	dbus_error_init(&err);
193
-	int ret = dbus_bus_request_name(dbus_connection, "org.freedesktop.Policy.Power",
194
-					DBUS_NAME_FLAG_REPLACE_EXISTING, &err);
195
-	if (dbus_error_is_set(&err)) {
196
-		kdWarning() << "Acquire org.freedesktop.Policy.Power interface failed with error: " << err.message << endl;
197
-		dbus_error_free(&err);
198
-	}
199
-	switch (ret) {
200
-		case DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER:
201
-			kdDebug() << "Acquired org.freedesktop.Policy.Power interface" << endl;
202
-			acquiredPolicyPower = true;
203
-			break;
204
-		case DBUS_REQUEST_NAME_REPLY_IN_QUEUE:
205
-			kdWarning() << "Queued to acquire org.freedesktop.Policy.Power interface" << endl;
206
-			acquiredPolicyPower = false;
207
-			break;
208
-		default:
209
-			acquiredPolicyPower = false;
210
-			break;
168
+	// find already running ConsoleKit
169
+	TQT_DBusProxy checkConsoleKit(DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, dBusConn);
170
+	if( checkConsoleKit.canSend() ) {
171
+		TQValueList<TQT_DBusData> params;
172
+		params << TQT_DBusData::fromString(CK_SERVICE);
173
+		TQT_DBusMessage reply = checkConsoleKit.sendWithReply("NameHasOwner", params);
174
+		if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1 && reply[0].toBool() ) {
175
+			onServiceRegistered(CK_SERVICE);
176
+		}
211 177
 	}
212 178
 
213 179
 	kdDebugFuncOut(trace);
214
-	return acquiredPolicyPower;
180
+	return true;
215 181
 }
216 182
 
217 183
 /*! 
218
- * This function release the org.freedesktop.Policy.Power interface
219
- * \return boolean with the result of the operation
220
- * \retval true 	if successful acquired the interface
221
- * \retval false 	if unsuccessful
184
+ * This function handles signals from the D-Bus daemon.
222 185
  */
223
-bool dbusInterface::releasePolicyPowerIface(){
224
-	kdDebugFuncIn(trace);
225
-
226
-	int result;
227
-	bool retval = false;
228
-	DBusError error;
229
-
230
-	if (dbus_connection == NULL) {
231
-		kdDebugFuncOut(trace);
232
-		return false;
186
+void dbusInterface::handleDBusSignal(const TQT_DBusMessage& msg) {
187
+	// dbus terminated
188
+	if( msg.path() == DBUS_PATH_LOCAL
189
+	 && msg.interface() == DBUS_INTERFACE_LOCAL
190
+	 && msg.member() == "Disconnected" ) {
191
+		close();
192
+		TQTimer::singleShot(1000, this, TQT_SLOT(reconnect()));
193
+		return;
233 194
 	}
234 195
 
235
-        dbus_error_init(&error);
236
-
237
-	result = dbus_bus_release_name(dbus_connection, "org.freedesktop.Policy.Power", &error);
238
-
239
-	if ( dbus_error_is_set( &error ) ) {
240
-		kdError() << "Failed to release org.freedesktop.Policy.Power: " << error.message << endl;
241
-		dbus_error_free(&error);
242
-	} else {
243
-		switch (result) {
244
-			case DBUS_RELEASE_NAME_REPLY_RELEASED:
245
-				kdDebug() << "Released org.freedesktop.Policy.Power interface" << endl;
246
-				retval = true;
247
-				acquiredPolicyPower = false;
248
-				break;
249
-			case DBUS_RELEASE_NAME_REPLY_NOT_OWNER:
250
-				kdWarning() << "Couldn't release org.freedesktop.Policy.Power, not the owner" << endl;
251
-				break;
252
-			case DBUS_RELEASE_NAME_REPLY_NON_EXISTENT:
253
-				kdWarning() << "Couldn't release org.freedesktop.Policy.Power, Iface not existing" << endl;
254
-				break;
255
-			default:
256
-				kdWarning() << "Couldn't release org.freedesktop.Policy.Power, unknown error" << endl;
257
-				break;
196
+	// service registered / unregistered
197
+	if( msg.path() == DBUS_PATH_DBUS
198
+	 && msg.interface() == DBUS_INTERFACE_DBUS
199
+	 && msg.member() == "NameOwnerChanged" ) {
200
+		if( msg[1].toString().isEmpty() ) {
201
+			// old-owner is empty
202
+			onServiceRegistered(msg[0].toString());
258 203
 		}
204
+		if( msg[2].toString().isEmpty() ) {
205
+			// new-owner is empty
206
+			onServiceUnregistered(msg[0].toString());
207
+		}
208
+		return;
259 209
 	}
260
-		
261
-	return retval;
262
-	kdDebugFuncOut(trace);
263
-}
264
-
265
-/*! 
266
- * This function check if the org.freedesktop.Policy.Power 
267
- * interface is owned by someone
268
- * \return boolean with the result of the operation
269
- * \retval true 	if the interface is owned by someone
270
- * \retval false 	if else
271
- */
272
-bool dbusInterface::isPolicyPowerIfaceOwned(){
273
-	kdDebugFuncIn(trace);
274 210
 
275
-	bool retval = false;
276
-	DBusError error;
277
-
278
-	if (dbus_connection == NULL) {
279
-		kdDebugFuncOut(trace);
280
-		return false;
211
+	// systemd session changed
212
+	if( systemdSeat && systemdSeat->canSend()
213
+	 && msg.path() == systemdSeat->path()
214
+	 && msg.interface() == DBUS_INTERFACE_PROPERTIES
215
+	 && msg.member() == "PropertiesChanged"
216
+	 && msg[0].toString() == SYSTEMD_LOGIN1_SEAT_IFACE) {
217
+		bool activeSessionProperty = false;
218
+		TQT_DBusDataMap<TQString> map = msg[1].toStringKeyMap();
219
+		TQT_DBusDataMap<TQString>::const_iterator it = map.begin();
220
+		for (; !activeSessionProperty && it != map.end(); ++it) {
221
+			if( it.key() != "ActiveSession" ) {
222
+				activeSessionProperty = true;
223
+			}
224
+		}
225
+		TQValueList<TQString> list = msg[2].toList().toStringList();
226
+		TQValueList<TQString>::const_iterator it1 = list.begin();
227
+		for (; !activeSessionProperty && it1 != list.end(); ++it1) {
228
+			if( (*it1) == "ActiveSession" ) {
229
+				activeSessionProperty = true;
230
+			}
231
+		}
232
+		if( activeSessionProperty ) {
233
+			emit activeSessionChanged(checkActiveSession());
234
+		}
235
+		return;
281 236
 	}
282 237
 
283
-        dbus_error_init(&error);
284
-
285
-	retval = dbus_bus_name_has_owner(dbus_connection, "org.freedesktop.Policy.Power", &error);
286
-
287
-	if ( dbus_error_is_set( &error ) ) {
288
-		kdError() << "Failed to check if org.freedesktop.Policy.Power has an owner: " << error.message << endl;
289
-		dbus_error_free(&error);
238
+	// consolekit session changed
239
+	if( consolekitSeat && consolekitSeat->canSend()
240
+	 && msg.path() == consolekitSeat->path()
241
+	 && msg.interface() == CK_SEAT_IFACE
242
+	 && msg.member() == "ActiveSessionChanged") {
243
+		emit activeSessionChanged(msg[0].toString() == TQString(consolekitSession));
244
+		return;
290 245
 	}
291
-
292
-	kdDebugFuncOut(trace);
293
-	return retval;
294
-}
295
-
296
-/* ----> DBUS section :: END   <---- */
297
-
298
-/* ----> D-Bus methode calls functions :: START <---- */
299
-/*! 
300
- * This function call a D-Bus method
301
- * \param interface	TQString with te dbus interface
302
- * \param path		TQString with the object path
303
- * \param object	TQString with the object name
304
- * \param method	TQString with the name of the methode
305
- * \param first_arg_type integer with the dbus type of the first argument
306
- * \param ... 		more arguments
307
- * \return 		If the query was successful or not
308
- */
309
-bool dbusInterface::dbusSystemMethodCall( TQString interface, TQString path, TQString object, TQString method,
310
-			   	    int first_arg_type, ... ) {
311
-	kdDebugFuncIn(trace);
312
-	
313
-	bool _ret = false;
314
-        va_list var_args;
315
-
316
-        va_start(var_args, first_arg_type);
317
-	_ret = dbusMethodCall( interface, path, object, method, DBUS_BUS_SYSTEM,
318
-			       NULL, -1, first_arg_type, var_args);
319
-	va_end(var_args);
320
-	
321
-	kdDebugFuncOut(trace);
322
-	return _ret;
323
-}
324
-
325
-
326
-/*! 
327
- * This overloaded function call a D-Bus method on the D-Bus system bus with a return value
328
- * \param interface	 TQString with the dbus interface
329
- * \param path		 TQString with the object path
330
- * \param object	 TQString with the object name
331
- * \param method	 TQString with the name of the method
332
- * \param retvalue	 void pointer to arguments, if NULL we make a simple call
333
- * \param retval_type    Integer with the dbus type of the return value, set to -1 if retvalue is NULL
334
- * \param first_arg_type Integer with the dbus type of the first argument followed by the value
335
- * \return 		 If the query was successful or not
336
- */
337
-bool dbusInterface::dbusSystemMethodCall( TQString interface, TQString path, TQString object, TQString method,
338
-				    void *retvalue, int retval_type, int first_arg_type, ... ) {
339
-	kdDebugFuncIn(trace);
340
-	
341
-	bool _ret = false;
342
-        va_list var_args;
343
-
344
-        va_start(var_args, first_arg_type);
345
-	_ret = dbusMethodCall( interface, path, object, method, DBUS_BUS_SYSTEM, 
346
-			       retvalue, retval_type, first_arg_type, var_args);
347
-	va_end(var_args);
348
-	
349
-	kdDebugFuncOut(trace);
350
-	return _ret;
351 246
 }
352 247
 
353
-
354
-/*! 
355
- * This function call a D-Bus method with a return value
356
- * \param interface	 TQString with the dbus interface
357
- * \param path		 TQString with the object path
358
- * \param object	 TQString with the object name
359
- * \param method	 TQString with the name of the method
360
- * \param dbus_type	 DBusBusType with the D-Bus BUS Type
361
- * \param retvalue	 void pointer to arguments, if NULL we make a simple call
362
- * \param retval_type    Integer with the dbus type of the return value, set to -1 if retvalue is NULL
363
- * \param first_arg_type Integer with the dbus type of the first argument followed by the value
364
- * \param var_args	 va_list with more arguments
365
- * \return 		 If the query was successful or not
248
+/*!
249
+ * This function handles dBus service registering
366 250
  */
367
-bool dbusInterface::dbusMethodCall( TQString interface, TQString path, TQString object, TQString method,
368
-			      DBusBusType dbus_type, void *retvalue, int retval_type, int first_arg_type,
369
-			      va_list var_args ) {
370
-	kdDebugFuncIn(trace);
371
-
372
-	DBusMessage *message;
373
-	DBusMessage *reply;
374
-	DBusError    error;
375
-	bool ret = false;
376
-	
377
-	dbus_error_init(&error); 
378
-
379
-	dbus_connection = dbus_bus_get(dbus_type, &error);
380
-	
381
-	if (dbus_error_is_set(&error)) {
382
-		kdError() << "Could not get dbus connection: " << error.message << endl;
383
-		dbus_error_free(&error);
384
-		goto out;
385
-	}
386
-
387
-	message = dbus_message_new_method_call( interface.ascii(), path.ascii(), object.ascii(), method.ascii() );
388
-	dbus_message_append_args_valist(message, first_arg_type, var_args);
251
+void dbusInterface::onServiceRegistered(const TQString& service) {
252
+	if( service == SYSTEMD_LOGIN1_SERVICE ) {
253
+		// get current session
254
+		TQT_DBusProxy managerIface(SYSTEMD_LOGIN1_SERVICE, SYSTEMD_LOGIN1_PATH, SYSTEMD_LOGIN1_MANAGER_IFACE, dBusConn);
255
+		systemdSession = TQT_DBusObjectPath();
256
+		if( managerIface.canSend() ) {
257
+			TQValueList<TQT_DBusData> params;
258
+			params << TQT_DBusData::fromUInt32( getpid() );
259
+			TQT_DBusMessage reply = managerIface.sendWithReply("GetSessionByPID", params);
260
+			if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1 ) {
261
+				systemdSession = reply[0].toObjectPath();
262
+			}
263
+		}
264
+		if( !systemdSession.isValid() ) {
265
+			kdWarning() << "The session is not registered with systemd" << endl;
266
+			return;
267
+		}
389 268
 
390
-	if (retvalue == NULL) {
391
-		if (!dbus_connection_send(dbus_connection, message, NULL)) {
392
-			kdError() << "Could not send method call." << endl;
393
-			dbus_message_unref( message );
394
-			goto out;
269
+		// get session seat
270
+		TQT_DBusProxy sessionProperties(SYSTEMD_LOGIN1_SERVICE, systemdSession, DBUS_INTERFACE_PROPERTIES, dBusConn);
271
+		TQT_DBusObjectPath seat;
272
+		if( sessionProperties.canSend() ) {
273
+			TQValueList<TQT_DBusData> params;
274
+			params
275
+			 << TQT_DBusData::fromString( SYSTEMD_LOGIN1_SESSION_IFACE )
276
+			 << TQT_DBusData::fromString( "Seat" );
277
+			TQT_DBusMessage reply = sessionProperties.sendWithReply("Get", params);
278
+			if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1 ) {
279
+				seat = reply[0].toVariant().value.toStruct()[1].toObjectPath();
280
+			}
395 281
 		}
396
-	} else {
397
-		reply = dbus_connection_send_with_reply_and_block(dbus_connection, message, -1, &error);
398
-
399
-		if (dbus_error_is_set(&error)) {
400
-			kdError() << "Could not send dbus message: " << error.message << endl;
401
-			dbus_message_unref(message);
402
-			dbus_error_free(&error);
403
-			goto out;
282
+		if( !seat.isValid() ) {
283
+			kdWarning() << "Unable to associate systemd session with a seat" << endl;
284
+			return;
404 285
 		}
405 286
 
406
-		int type = dbus_message_get_type(reply);
407
-		if (type == DBUS_MESSAGE_TYPE_METHOD_RETURN) {
408
-			if (!dbus_message_get_args(reply, &error, retval_type, retvalue, DBUS_TYPE_INVALID)){
409
-				if (dbus_error_is_set(&error)) {
410
-					kdError() << "Could not get argument from reply: " 
411
-						  << error.message << endl;
412
-					dbus_error_free(&error);
413
-				}
414
-				dbus_message_unref(reply);
415
-				dbus_message_unref(message);
416
-				goto out;
287
+		// watch session changes
288
+		systemdSeat = new TQT_DBusProxy(SYSTEMD_LOGIN1_SERVICE, seat, DBUS_INTERFACE_PROPERTIES, dBusConn);
289
+		TQObject::connect(systemdSeat, TQT_SIGNAL(dbusSignal(const TQT_DBusMessage&)),
290
+				  this, TQT_SLOT(handleDBusSignal(const TQT_DBusMessage&)));
291
+
292
+		// inhibit systemd handling of power/sleep/hibernate/lid buttons
293
+		// http://www.freedesktop.org/wiki/Software/systemd/inhibit
294
+		if( !systemdInhibit.isValid() && managerIface.canSend() ) {
295
+			TQValueList<TQT_DBusData> params;
296
+			params
297
+			 << TQT_DBusData::fromString("handle-power-key:handle-suspend-key:handle-hibernate-key:handle-lid-switch") // what
298
+			 << TQT_DBusData::fromString("TDEPowersave") // who
299
+			 << TQT_DBusData::fromString("TDE handles power events") // why
300
+			 << TQT_DBusData::fromString("block"); // mode
301
+			TQT_DBusMessage reply = managerIface.sendWithReply("Inhibit", params);
302
+			if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1 ) {
303
+				systemdInhibit = reply[0].toUnixFd();
417 304
 			}
418
-		} else {
419
-			kdError() << "Revieved invalid DBUS_MESSAGE_TYPE: " << type 
420
-				  << "expected: " << DBUS_MESSAGE_TYPE_METHOD_RETURN << endl;
421
-			dbus_message_unref(reply);
422
-			dbus_message_unref(message);
423
-			goto out;
424 305
 		}
306
+		return;
425 307
 	}
308
+	if( service == CK_SERVICE ) {
309
+		// get current session
310
+		TQT_DBusProxy managerIface(CK_SERVICE, CK_MANAGER_OBJECT, CK_MANAGER_IFACE, dBusConn);
311
+		consolekitSession = TQT_DBusObjectPath();
312
+		if( managerIface.canSend() ) {
313
+			TQValueList<TQT_DBusData> params;
314
+			params << TQT_DBusData::fromUInt32( getpid() );
315
+			TQT_DBusMessage reply = managerIface.sendWithReply("GetSessionForUnixProcess", params);
316
+			if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1 ) {
317
+				consolekitSession = reply[0].toObjectPath();
318
+			}
319
+		}
320
+		if( !consolekitSession.isValid() ) {
321
+			kdWarning() << "The session is not registered with consolekit" << endl;
322
+			return;
323
+		}
426 324
 
427
-	ret = true;	// if we are here, everything should be okay
428
-	dbus_message_unref(message);
429
-	dbus_connection_flush(dbus_connection);
430
-
431
-out:
432
-	kdDebugFuncOut(trace);
433
-        return ret;
434
-}
435
-
436
-/* ----> D-Bus methode calls functions :: END  <---- */
437
-/* ---> PolicyKit method call section :: START <--- */
438
-
439
-/*!
440
- * Check if the user is privileged to a special privilege
441
- * \param privilege	TQString with the name of the requested privilege
442
- * \param udi		TQString with the UDI.
443
- * \param ressource	TQString with the name of the ressource
444
- * \param user		TQString with the name of the user. If empty the current user is used.
445
- * \return int with info if the user is allowed or not.
446
- * \retval 0		if not allowed
447
- * \retval 1		if allowed
448
- * \retval -1		if a error occurs or we could not query the interface
449
- */
450
-int dbusInterface::isUserPrivileged(TQString privilege, TQString udi, TQString ressource, TQString user) {
451
-	kdDebugFuncIn(trace);
325
+		// get session seat
326
+		TQT_DBusObjectPath seat;
327
+		if( dBusConn.isConnected() ) {
328
+			TQT_DBusMessage msg = TQT_DBusMessage::methodCall(CK_SERVICE, consolekitSession, CK_SESSION_IFACE, "GetSeatId");
329
+			TQT_DBusMessage reply = dBusConn.sendWithReply(msg);
330
+			if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1 ) {
331
+				seat = reply[0].toObjectPath();
332
+			}
333
+		}
334
+		if( !seat.isValid() ) {
335
+			kdWarning() << "Unable to associate consolekit session with a seat" << endl;
336
+			return;
337
+		}
452 338
 
453
-	const char *_unique_name;
454
-	const char *_user;
455
-	const char *_privilege;	
456
-	
457
-	int retval = -1;
458
-
459
-	if (user.isEmpty() || user.isNull()) 
460
-		_user = getenv("USER"); 
461
-	else 
462
-		_user = user.latin1();
463
-
464
-	if (_user == NULL || privilege.isEmpty()) 
465
-		goto out;
466
-
467
-	_unique_name = dbus_bus_get_unique_name(dbus_connection);
468
-	_privilege = privilege.latin1();
469
-
470
-	// not sure if we need this, but to avoid problems
471
-	dbus_bool_t _retval;
472
-	const char *_ressource;
473
-	_ressource = ressource.latin1();
474
-
475
-	if (!dbusSystemMethodCall( "org.freedesktop.PolicyKit",
476
-				   "/org/freedesktop/PolicyKit/Manager",
477
-				   "org.freedesktop.PolicyKit.Manager",
478
-				   "IsUserPrivileged",
479
-				   &_retval, DBUS_TYPE_BOOLEAN,
480
-				   DBUS_TYPE_STRING, &_unique_name,
481
-				   DBUS_TYPE_STRING, &_user,
482
-				   DBUS_TYPE_STRING, &_privilege,
483
-				   DBUS_TYPE_STRING, &_ressource,
484
-				   DBUS_TYPE_INVALID)) {
485
-		retval = -1;	// only to be sure we have no changes trough the call
486
-	} else {
487
-		retval = (int) _retval;
339
+		// watch session changes
340
+		consolekitSeat = new TQT_DBusProxy(CK_SERVICE, seat, CK_SEAT_IFACE, dBusConn);
341
+		TQObject::connect(consolekitSeat, TQT_SIGNAL(dbusSignal(const TQT_DBusMessage&)),
342
+				  this, TQT_SLOT(handleDBusSignal(const TQT_DBusMessage&)));
343
+		return;
488 344
 	}
489
-
490
-out:
491
-	kdDebugFuncOut(trace);
492
-	return retval;
493 345
 }
494
-/* ---> PolicyKit method call section :: END   <--- */
495 346
 
496 347
 /*!
497
- * Use this TQT_SLOT to emit a reviced messages to the tdepowersave.
498
- * NOTE: Because of the filter function this need to be a public function.
499
- *       Don't use this function in any other place than this class.
500
- * \param  type enum with the type of the message
501
- * \param  message String with the message
502
- * \param  string String with additional info
348
+ * This function handles dBus service unregistering
503 349
  */
504
-void dbusInterface::emitMsgReceived( msg_type type, TQString message, TQString string ) {
505
-	
506
-	if (message.startsWith("dbus.terminate"))
507
-		dbus_is_connected = false;
508
-
509
-	if (type == POLICY_POWER_OWNER_CHANGED) {
510
-		if (message.startsWith("NOW_OWNER"))
511
-			acquiredPolicyPower = true;
512
-		else 
513
-			acquiredPolicyPower = false;
350
+void dbusInterface::onServiceUnregistered(const TQString& service) {
351
+	if( service == SYSTEMD_LOGIN1_SERVICE ) {
352
+		systemdSession = TQT_DBusObjectPath();
353
+		if( systemdSeat ) {
354
+			delete systemdSeat;
355
+		}
356
+		return;
357
+	}
358
+	if( service == CK_SERVICE ) {
359
+		consolekitSession = TQT_DBusObjectPath();
360
+		if( consolekitSeat ) {
361
+			delete consolekitSeat;
362
+		}
363
+		return;
514 364
 	}
515
-
516
-	emit msgReceived_withStringString( type, message, string );
517 365
 }
518 366
 
519
-#include "dbusInterface.moc"
520
-// --> functions which are not member of the class ...
521
-
522
-/*! 
523
- * This function is needed filter function for the D-Bus connection to filter
524
- * all needed messages from the bus which are needful for TDEPowersave. 
525
- * \param connection	existing connection to the D-Bus daemon
526
- * \param message 	the recieved message from the D-Bus daemon
527
- * \param data		void pointer (see dbus bindings for more information)
528
- * \return DBusHandlerResult
367
+/*!
368
+ * This functions is used to check if session is active
529 369
  */
530
-DBusHandlerResult 
531
-filterFunction (DBusConnection *connection, DBusMessage *message, void */*data*/) {
532
- 	kdDebugFuncIn(trace);
533
-	
534
-	bool reply_wanted;
535
-	char *value;
536
-	TQString ifaceType;
537
-
538
-	DBusError error;
539
-        dbus_error_init( &error );
540
-
541
-	if (dbus_message_is_signal (message,
542
-				    DBUS_INTERFACE_LOCAL,
543
-				    "Disconnected")){
544
-		((dbusInterface*) myInstance)->emitMsgReceived( DBUS_EVENT, "dbus.terminate", 0 );
545
-		dbus_connection_unref(connection);
546
-		kdDebugFuncOut(trace);
547
-		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
548
-	}
549
-
550
-        if ( dbus_message_get_type( message ) != DBUS_MESSAGE_TYPE_SIGNAL ) {
551
-                if (trace) kdDebug() << "recieved message, but wasn't from type DBUS_MESSAGE_TYPE_SIGNAL" << endl;
552
-		kdDebugFuncOut(trace);
553
-		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
554
-        }
555
-
556
-	ifaceType = dbus_message_get_interface( message );
557
-        if (ifaceType == NULL) {
558
-                kdDebug() << "Received message from invalid interface" << endl;
559
-                kdDebugFuncOut(trace);
560
-		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
561
-        }
562
-
563
-	reply_wanted = !dbus_message_get_no_reply( message );
564
-
565
-	if (ifaceType.startsWith(DBUS_INTERFACE_DBUS)) {
566
-		if(trace) kdDebug() << "Received from DBUS_INTERFACE_DBUS" << endl;
567
-		/* get the name of the signal */
568
-		const char *signal = dbus_message_get_member( message );
569
-		
570
-		/* get the first argument. This must be a string at the moment */
571
-		dbus_message_get_args( message, &error, DBUS_TYPE_STRING, &value, DBUS_TYPE_INVALID );
572
-	
573
-		if ( dbus_error_is_set( &error ) ) {
574
-			kdWarning() << "Received signal " << error.message << " but no string argument" << endl;
575
-			dbus_error_free( &error );
576
-			kdDebugFuncOut(trace);
577
-			return DBUS_HANDLER_RESULT_HANDLED;
370
+bool dbusInterface::checkActiveSession() {
371
+	if( systemdSeat && systemdSeat->canSend() ) {
372
+		TQT_DBusObjectPath activeSession;
373
+		TQValueList<TQT_DBusData> params;
374
+		params
375
+		 << TQT_DBusData::fromString( SYSTEMD_LOGIN1_SEAT_IFACE )
376
+		 << TQT_DBusData::fromString( "ActiveSession" );
377
+		TQT_DBusMessage reply = systemdSeat->sendWithReply("Get", params);
378
+		if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1 ) {
379
+			activeSession = reply[0].toVariant().value.toStruct()[1].toObjectPath();
380
+			return (activeSession == systemdSession);
578 381
 		}
579
-	
580
-		if (trace) kdDebug() << "filter_function::SIGNAL=" << signal << " VALUE=" << value << endl;
581
-	
582
-		/* our name is... */
583
-		if ( ! strcmp( signal, "NameAcquired" ) ) {
584
-			kdDebugFuncOut(trace);
585
-			return DBUS_HANDLER_RESULT_HANDLED;
586
-		}
587
-		
588
-		else if ( ! strcmp( signal, "NameOwnerChanged" )) {
589
-			char *service;
590
-			char *old_owner;
591
-			char *new_owner;
592
-			
593
-                	if (dbus_message_get_args (message, NULL, DBUS_TYPE_STRING, &service,
594
-                                                   DBUS_TYPE_STRING, &old_owner,
595
-                                                   DBUS_TYPE_STRING, &new_owner, DBUS_TYPE_INVALID)) {
596
-				if (!strcmp(service, "org.freedesktop.Policy.Power")) {
597
-					const char *own_name;
598
-					
599
-					own_name = dbus_bus_get_unique_name(((dbusInterface*) myInstance)->get_DBUS_connection());
600
-
601
-					if (!strcmp(new_owner, own_name)) {
602
-						kdDebug() << "=== now owner of org.freedesktop.Policy.Power ===" << endl;
603
-						// we have now again the ower of the name!
604
-						((dbusInterface*) myInstance)->emitMsgReceived( POLICY_POWER_OWNER_CHANGED,
605
-											  "NOW_OWNER", 
606
-											  NULL );
607
-					} else {
608
-						// some other has now the interface
609
-						kdDebug() << "=== someone owner of org.freedesktop.Policy.Power ===" << endl;
610
-						((dbusInterface*) myInstance)->emitMsgReceived( POLICY_POWER_OWNER_CHANGED,
611
-											  "OTHER_OWNER", 
612
-											  NULL );
613
-					}
614
-				}
615
-			}
616
-		}
617
-		kdDebugFuncOut(trace);
618
-		return DBUS_HANDLER_RESULT_HANDLED;	
619
-	} else if (ifaceType.startsWith("org.freedesktop.ConsoleKit.Session")) {
620
-		kdDebug() << "Received from org.freedesktop.ConsoleKit.Session" << endl;
621
-
622
-		const char *session = dbus_message_get_path (message);
623
-		const char *signal = dbus_message_get_member( message );
624
-		
625
-		if (! strcmp(signal, "ActiveChanged")) {
626
-			dbus_bool_t active;
627
-
628
-			if (dbus_message_get_args( message, &error, DBUS_TYPE_BOOLEAN, &active, DBUS_TYPE_INVALID )) {
629
-				((dbusInterface*) myInstance)->emitMsgReceived( CONSOLEKIT_SESSION_ACTIVE, 
630
-									  session, TQString("%1").arg((int)active));
631
-			} else {
632
-				if (dbus_error_is_set( &error )) dbus_error_free( &error );
633
-			}
634
-		} else {
635
-			kdDebug() << "Received unknown signal from org.freedesktop.ConsoleKit.Session: "
636
-				  << signal << endl;
637
-			kdDebugFuncOut(trace);
638
-			return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
382
+	}
383
+	if( consolekitSeat && consolekitSeat->canSend() ) {
384
+		TQT_DBusObjectPath activeSession;
385
+		TQValueList<TQT_DBusData> params;
386
+		TQT_DBusMessage reply = consolekitSeat->sendWithReply("GetActiveSession", params);
387
+		if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1 ) {
388
+			activeSession = reply[0].toObjectPath();
389
+			return (activeSession == consolekitSession);
639 390
 		}
640
-		kdDebugFuncOut(trace);
641
-		return DBUS_HANDLER_RESULT_HANDLED;
642
-	} else {
643
-		kdDebugFuncOut(trace);
644
-		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
645 391
 	}
392
+	return false;
646 393
 }
647 394
 
648
-// --> some functions to get private members
649
-
650
-//! to get the current connection to D-Bus
651
-DBusConnection * dbusInterface::get_DBUS_connection() {
652
-	return dbus_connection;
653
-}
654
-
395
+#include "dbusInterface.moc"

+ 43
- 75
src/dbusInterface.h View File

@@ -23,13 +23,13 @@
23 23
 */
24 24
 /*!
25 25
 *  \class 	dbusInterface
26
-*  \brief 	class for connection to HAL via D-Bus
26
+*  \brief 	class for connection to D-Bus
27 27
 *  \author 	Danny Kukawka, <dkukawka@suse.de>, <danny.kukawka@web.de>
28 28
 *  \date    	2006-2007
29 29
 */
30 30
 
31
-#ifndef _DBUSHAL_H_
32
-#define _DBUSHAL_H_
31
+#ifndef _DBUS_INTERFACE_H_
32
+#define _DBUS_INTERFACE_H_
33 33
 
34 34
 #ifndef DBUS_API_SUBJECT_TO_CHANGE
35 35
 #define DBUS_API_SUBJECT_TO_CHANGE
@@ -41,12 +41,14 @@
41 41
 #endif
42 42
 
43 43
 // QT - Header
44
+#include <tqobject.h>
44 45
 #include <tqstring.h>
45 46
 
46 47
 // D-Bus Header
47
-#include <dbus/dbus.h> // needed for dbus_bool_t
48
-#include <dbus/message.h>
49
-#include <dbus/connection.h>
48
+#include <tqdbusconnection.h>
49
+#include <tqdbusobjectpath.h>
50
+#include <tqdbusproxy.h>
51
+#include <tqdbusunixfd.h>
50 52
 
51 53
 // tdepowersave - Header
52 54
 #include "tdepowersave_debug.h"
@@ -55,16 +57,13 @@
55 57
 #define CK_MANAGER_IFACE	"org.freedesktop.ConsoleKit.Manager"
56 58
 #define CK_MANAGER_OBJECT	"/org/freedesktop/ConsoleKit/Manager"
57 59
 #define CK_SESSION_IFACE	"org.freedesktop.ConsoleKit.Session"
60
+#define CK_SEAT_IFACE		"org.freedesktop.ConsoleKit.Seat"
58 61
 
59
-enum msg_type {
60
-	ACPI_EVENT,
61
-	DBUS_EVENT,
62
-	HAL_DEVICE,
63
-	HAL_PROPERTY_CHANGED,
64
-	HAL_CONDITION,
65
-	CONSOLEKIT_SESSION_ACTIVE,
66
-	POLICY_POWER_OWNER_CHANGED
67
-};
62
+#define SYSTEMD_LOGIN1_SERVICE		"org.freedesktop.login1"
63
+#define SYSTEMD_LOGIN1_PATH		"/org/freedesktop/login1"
64
+#define SYSTEMD_LOGIN1_MANAGER_IFACE	"org.freedesktop.login1.Manager"
65
+#define SYSTEMD_LOGIN1_SESSION_IFACE	"org.freedesktop.login1.Session"
66
+#define SYSTEMD_LOGIN1_SEAT_IFACE	"org.freedesktop.login1.Seat"
68 67
 
69 68
 class dbusInterface : public TQObject{
70 69
 	Q_OBJECT
@@ -72,35 +71,32 @@ class dbusInterface : public TQObject{
72 71
 
73 72
 private:
74 73
 
75
-	//! QT connection to D-Bus
76
-	DBusQt::Connection* m_dBusQtConnection;
77
-	//! real connection to D-Bus
78
-	DBusConnection *dbus_connection;
79
-
80
-	//! to store information if TDEPowersave is connected to D-Bus
81
-	/*!
82
-	* This boolean represent information about the state of the connection to D-Bus
83
-	* \li true:  if connected
84
-	* \li false: if disconnected
85
-	*/
86
-	bool dbus_is_connected;
87
-
88
-	//! if we could claim the org.freedesktop.Policy.Power interface
89
-	/*!
90
-	* This boolean represent information if TDEPowersave could claim the 
91
-	* org.freedesktop.Policy.Power interface from the D-Bus
92
-	* \li true:  if acquired
93
-	* \li false: if not
94
-	*/
95
-	bool acquiredPolicyPower;
74
+	//! TQt connection to D-Bus
75
+	TQT_DBusConnection dBusConn;
76
+
77
+	//! TQt D-Bus proxy for watching signals
78
+	TQT_DBusProxy* dBusWatch;
79
+	TQT_DBusProxy* dBusLocal;
80
+
81
+	TQT_DBusObjectPath systemdSession;
82
+	TQT_DBusProxy* systemdSeat;
83
+	TQT_DBusUnixFd systemdInhibit;
84
+
85
+	TQT_DBusObjectPath consolekitSession;
86
+	TQT_DBusProxy* consolekitSeat;
96 87
 
97 88
 	/* D-Bus helper functions */
98 89
 	//! to initialise the connection to D-Bus 
99 90
 	bool initDBUS();
100
-	//! to call a methode on a dbus interface with reply
101
-	bool dbusMethodCall( TQString interface, TQString path, TQString object, TQString method,
102
-			     DBusBusType dbus_type, void *retvalue, int retval_type,
103
-			     int first_arg_type, va_list var_args);
91
+
92
+	//! handles signal service registred/unregistered
93
+	void onServiceRegistered(const TQString&);
94
+	void onServiceUnregistered(const TQString&);
95
+
96
+private slots:
97
+
98
+	//! to reconnect to D-Bus
99
+	bool reconnect();
104 100
 
105 101
 public:
106 102
 
@@ -109,52 +105,24 @@ public:
109 105
 	//! default destructor
110 106
 	~dbusInterface();
111 107
 
112
-	//! to reconnect to D-Bus and HAL
113
-	bool reconnect();
114
-	//! to close the connection to D-Bus and HAL
108
+	//! to close the connection to D-Bus
115 109
 	bool close();
116 110
 
117
-	//! to acquire the org.freedesktop.Policy.Power interface
118
-	bool acquirePolicyPowerIface();
119
-	//! to release the org.freedesktop.Policy.Power interface
120
-	bool releasePolicyPowerIface();
121
-	//! to check if the org.freedesktop.Policy.Power interface has an owner
122
-	bool isPolicyPowerIfaceOwned();
123
-
124 111
 	// --- helper to get private members of the class --- //
125 112
 	//! to get information if TDEPowersave is connected to D-Bus
126 113
 	bool isConnectedToDBUS();
127
-	//! to get info about claim org.freedesktop.Policy.Power interface
128
-	bool acquiredPolicyPowerInterface();
129 114
 
130
-	//! return the current DBus connection
131
-	DBusConnection *get_DBUS_connection();
115
+	//! to check active session state
116
+	bool checkActiveSession();
132 117
 
133
-	/* D-Bus helper functions */
118
+public slots:
134 119
 
135
-	/* functions to call methodes */
136
-	//! to call a methode on a dbus system bus method without reply
137
-	bool dbusSystemMethodCall( TQString interface, TQString path, TQString object, TQString method,
138
-				   int first_arg_type, ... );
139
-	//! to call a methode on a dbus system bus method with reply
140
-	bool dbusSystemMethodCall( TQString interface, TQString path, TQString object, TQString method, 
141
-				   void *retvalue, int retval_type, int first_arg_type, ... );
120
+	void handleDBusSignal(const TQT_DBusMessage&);
142 121
 
143
-	/* PolicyKit call helper */
144
-	//! check if the user has a requested privilege
145
-	int isUserPrivileged( TQString privilege, TQString udi, TQString ressource = "", TQString user = TQString());
122
+signals:
146 123
 
147
-	//! wrapper to emit a signal with a event from HAL
148
-	void emitMsgReceived( msg_type type, TQString message, TQString string );
124
+	void activeSessionChanged(bool);
149 125
 
150
-signals:
151
-        //! signal with message to forward from D-Bus to HAL
152
-	void msgReceived_withStringString( msg_type, TQString, TQString );
153
-	//! signal if we resumed!
154
-	void backFromSuspend( int result );
155 126
 };
156 127
 
157
-//! filter function to filter out needed information from D-Bus messages
158
-DBusHandlerResult filterFunction (DBusConnection *connection, DBusMessage *message, void *data);
159
-
160 128
 #endif

+ 17
- 252
src/hardware.cpp View File

@@ -37,7 +37,6 @@
37 37
 // include own header
38 38
 #include "hardware.h"
39 39
 #include "tdepowersave_debug.h"
40
-#include "privileges.h"
41 40
 
42 41
 // #define USE_EVENT_DEVICES_DIRECTLY 1
43 42
 
@@ -51,7 +50,6 @@ HardwareInfo::HardwareInfo() {
51 50
 	laptop = false;
52 51
 	brightness = false;
53 52
 	brightness_in_hardware = false;
54
-	schedPowerSavings = false;
55 53
 	sessionIsActive = true;	 // assume as first we are active
56 54
 
57 55
 	// initialize connection to the TDE hardware library
@@ -79,20 +77,15 @@ HardwareInfo::HardwareInfo() {
79 77
 	primaryBatteries = new BatteryCollection(BAT_PRIMARY);
80 78
 	setPrimaryBatteriesWarningLevel(); // force default settings
81 79
 
82
-	// connect to D-Bus and HAL
83
-	dbus_HAL = new dbusInterface();
84
-	if (dbus_HAL->isConnectedToDBUS()) {
85
-		dbus_terminated = false;
86
-	} else {
87
-		kdError() << "Could not connect to D-Bus & HAL" << endl;
88
-	}
80
+	// connect to D-Bus
81
+	dbus_iface = new dbusInterface();
82
+	sessionIsActive = dbus_iface->checkActiveSession();
83
+	connect(dbus_iface, TQT_SIGNAL(activeSessionChanged(bool)), this, TQT_SLOT(handleSessionState(bool)));
89 84
 
90
-	checkConsoleKitSession();
91 85
 	checkPowermanagement();
92 86
 	checkIsLaptop();
93 87
 	checkBrightness();
94 88
 	checkCPUFreq();
95
-	// getSchedPowerSavings();
96 89
 	checkSuspend();
97 90
 	intialiseHWInfo();
98 91
 
@@ -141,15 +134,26 @@ bool HardwareInfo::reinitHardwareInfos () {
141 134
 	checkCPUFreq();
142 135
 	checkSuspend();
143 136
 	intialiseHWInfo();
144
-	// getSchedPowerSavings();
145 137
 	updatePrimaryBatteries();
146 138
 
147 139
 	kdDebugFuncOut(trace);
148 140
 	return true;
149 141
 }
150 142
 
143
+
151 144
 /*!
152
- * This funtion is used to parse changed hardware nofifications from the TDE hardware library
145
+ * \b TQT_SLOT called if the state of the current session change
146
+ * \param state boolean represent the state of the session
147
+ */
148
+void HardwareInfo::handleSessionState( bool state ) {
149
+    if( state != sessionIsActive ) {
150
+	sessionIsActive = state;
151
+	TQTimer::singleShot(50, this, TQT_SLOT(emitSessionActiveState()));
152
+    }
153
+}
154
+
155
+/*!
156
+ * This function is used to parse changed hardware nofifications from the TDE hardware library
153 157
  * \param device 	a \ref TDEGenericDevice* which should be processed
154 158
  */
155 159
 void HardwareInfo::processHardwareChangedEvent (TDEGenericDevice* device) {
@@ -216,99 +220,6 @@ void HardwareInfo::processKeyPressEvent(unsigned int keycode, TDEEventDevice* ed
216 220
 }
217 221
 
218 222
 /*!
219
- * This funtion is used to parse a message from D-Bus for the different
220
- * messagetypes and events.
221
- * \param type 		a \ref msg_type which should be parse/processed
222
- * \param message 	the message
223
- * \param value 	an optional message value as e.g. message string
224
- */
225
-void HardwareInfo::processMessage (msg_type type, TQString message, TQString value) {
226
-	kdDebugFuncIn(trace);
227
-
228
-	switch(type) {
229
-		case ACPI_EVENT:
230
-			// we don't handle acpi events here atm
231
-			break;
232
-		case HAL_DEVICE:
233
-			// --> we can maybe ignore these events except for batteries, not shure atm
234
-			int _type;
235
-
236
-			if (message.startsWith("DeviceAdded")) {
237
-				if (checkIfHandleDevice(value, &_type)) {
238
-					switch (_type) {
239
-						case BATTERY:
240
-						case AC_ADAPTER:
241
-						case BUTTON_SLEEP:
242
-						case BUTTON_POWER:
243
-						case LID:
244
-							// TODO: handle code if needed actually not
245
-							break;
246
-						case LAPTOP_PANEL:
247
-							checkBrightness();
248
-							break;
249
-						default:
250
-							kdDebug() << "New device added Device udi: "
251
-								  << value << "type: " << _type << endl;
252
-							break;
253
-					}
254
-				}
255
-			} else if (message.startsWith("DeviceRemoved")) {
256
-				if (allUDIs.contains(value)) {
257
-					if (checkIfHandleDevice(value, &_type)) {
258
-						switch (_type) {
259
-							case BATTERY:
260
-							case AC_ADAPTER:
261
-							case BUTTON_SLEEP:
262
-							case BUTTON_POWER:
263
-							case LID:
264
-								// TODO: handle code if needed
265
-								break;
266
-							case LAPTOP_PANEL:
267
-								checkBrightness();
268
-								break;
269
-							default:
270
-								kdDebug() << "Couldn't handle unknown device" << endl;
271
-								break;
272
-						}
273
-					}
274
-				} else {
275
-					kdDebug() << "Not monitored device removed: " << value << endl;
276
-				}
277
-			} else {
278
-				kdDebug() << "Unknown HAL_DEVICE message: " << message << endl;
279
-			}
280
-			break;
281
-		case CONSOLEKIT_SESSION_ACTIVE:
282
-			if (!message.isEmpty() && !value.isEmpty()) {
283
-				if (message == consoleKitSession) {
284
-					if (value == "1") {
285
-						sessionIsActive = true;
286
-					} else {
287
-						sessionIsActive = false;
288
-					}
289
-					TQTimer::singleShot(50, this, TQT_SLOT(emitSessionActiveState()));
290
-				} else {
291
-					if (trace)
292
-						kdDebug() << "CONSOLEKIT_SESSION_ACTIVE: not our session" << endl;
293
-				}
294
-			}
295
-			break;
296
-		case POLICY_POWER_OWNER_CHANGED:
297
-			if (message.startsWith("NOW_OWNER")) {
298
-				// TODO: add code
299
-			} else if (message.startsWith("OTHER_OWNER")){
300
-				// TODO: add code
301
-			}
302
-			break;
303
-		default:
304
-			kdDebug() << "Recieved unknown package type: " << type << endl;
305
-			break;
306
-	}
307
-
308
-	kdDebugFuncOut(trace);
309
-}
310
-
311
-/*!
312 223
  * This TQT_SLOT is used to fetch the resume signal and multiplex. If needed some
313 224
  * actions after resume, do this here.
314 225
  * \param result 	integer with the result of the resume/suspend
@@ -331,61 +242,6 @@ void HardwareInfo::handleResumeSignal (int result) {
331 242
 }
332 243
 
333 244
 /*!
334
- * This function checks the session for the running TDEPowersave instance
335
- * \return 		Boolean with result of operation
336
- * \retval true		if the query/check could get finished
337
- * \retval false	on every error
338
- */
339
-bool HardwareInfo::checkConsoleKitSession () {
340
-	kdDebugFuncIn(trace);
341
-
342
-	bool retval = false;
343
-
344
-	if (dbus_HAL->isConnectedToDBUS()) {
345
-		char *reply;
346
-		char *cookie = getenv("XDG_SESSION_COOKIE");
347
-
348
-		if (cookie == NULL) {
349
-			kdDebug() << "Could not get XDG_SESSION_COOKIE from environment" << endl;
350
-			sessionIsActive = true;
351
-		} else {
352
-			if (dbus_HAL->dbusSystemMethodCall( CK_SERVICE, CK_MANAGER_OBJECT,
353
-							CK_MANAGER_IFACE, "GetSessionForCookie",
354
-							&reply, DBUS_TYPE_OBJECT_PATH,
355
-							DBUS_TYPE_STRING, &cookie,
356
-							DBUS_TYPE_INVALID)) {
357
-				if (trace)
358
-					kdDebug() << "GetSessionForCookie returned: " << reply << endl;
359
-
360
-				if (reply != NULL) {
361
-					dbus_bool_t i_reply;
362
-					consoleKitSession = reply;
363
-
364
-					if (dbus_HAL->dbusSystemMethodCall( CK_SERVICE, consoleKitSession,
365
-									    CK_SESSION_IFACE, "IsActive",
366
-									    &i_reply, DBUS_TYPE_BOOLEAN,
367
-									    DBUS_TYPE_INVALID)) {
368
-						sessionIsActive = ((i_reply != 0) ? true: false);
369
-						if (trace)
370
-							kdDebug() << "IsActive returned: " << sessionIsActive << endl;
371
-
372
-						retval = true;
373
-					} else {
374
-						kdError() << "Could get session cookie and session name, but not "
375
-							<< "but not the status of the session. Assume for now "
376
-							<< "the Session is inactive!" << endl;
377
-						sessionIsActive = false;
378
-					}
379
-				}
380
-			}
381
-		}
382
-	}
383
-
384
-	kdDebugFuncOut(trace);
385
-	return retval;
386
-}
387
-
388
-/*!
389 245
  * This function check for a given UDI, if we should handle a device
390 246
  * \param _udi		TQString with the UDI of the device
391 247
  * \param *type		pointer to a integer to return the type of the device, see \ref device_type
@@ -1090,7 +946,6 @@ bool HardwareInfo::setCPUFreq ( cpufreq_type cpufreq, int limit ) {
1090 946
 	TDEGenericHardwareList hwlist = m_hwdevices->listByDeviceClass(TDEGenericDeviceType::CPU);
1091 947
 
1092 948
 	if (hwlist.count() > 0) {
1093
-		dbus_bool_t consider = (dbus_bool_t) getAcAdapter();
1094 949
 		TQStringList dynamic;
1095 950
 
1096 951
 		if (checkCurrentCPUFreqPolicy() == cpufreq) {
@@ -1122,20 +977,6 @@ bool HardwareInfo::setCPUFreq ( cpufreq_type cpufreq, int limit ) {
1122 977
 					}
1123 978
 				}
1124 979
 
1125
-#if 0
1126
-				// FIXME
1127
-				// What does "SetCPUFreqConsiderNice" actually do??!?!
1128
-
1129
-				// correct set ondemand
1130
-				if (!dbus_HAL->dbusSystemMethodCall( HAL_SERVICE, HAL_COMPUTER_UDI,
1131
-								     HAL_CPUFREQ_IFACE,
1132
-								     "SetCPUFreqConsiderNice",
1133
-								     DBUS_TYPE_BOOLEAN, &consider,
1134
-								     DBUS_TYPE_INVALID)) {
1135
-					kdError() << "Couldn't set SetCPUFreqConsiderNice for DYNAMIC" << endl;
1136
-				}
1137
-
1138
-#endif
1139 980
 				// Set performance limits on all CPUs
1140 981
 				TDEGenericDevice *hwdevice;
1141 982
 				TDECPUDevice *cpudevice;
@@ -1185,7 +1026,6 @@ bool HardwareInfo::setCPUFreq ( cpufreq_type cpufreq, int limit ) {
1185 1026
 bool HardwareInfo::setCPUFreqGovernor( const char *governor ) {
1186 1027
 	kdDebugFuncIn(trace);
1187 1028
 
1188
-	int reply;
1189 1029
 	bool ret = true;
1190 1030
 
1191 1031
 	TDEGenericHardwareList hwlist = m_hwdevices->listByDeviceClass(TDEGenericDeviceType::CPU);
@@ -1205,61 +1045,6 @@ bool HardwareInfo::setCPUFreqGovernor( const char *governor ) {
1205 1045
 }
1206 1046
 
1207 1047
 
1208
-/*!
1209
- * Function to set the powersave mode (incl. e.g. disk settings) via TDE hardware library.
1210
- * \param  on		boolean which tell if enable/disable powersave mode
1211
- * \return boolean with result of the operation
1212
- * \retval true  	if successful
1213
- * \retval false 	else, if a error occurs
1214
- */
1215
-bool HardwareInfo::setPowerSave( bool on ) {
1216
-	kdDebugFuncIn(trace);
1217
-
1218
-	bool retval = false;
1219
-
1220
-	// FIXME
1221
-	// Set up power saving to the best of our ability using "raw" functions
1222
-	printf("[FIXME] HardwareInfo::setPowerSave unimplemented!\n"); fflush(stdout);
1223
-
1224
-	kdDebugFuncOut(trace);
1225
-	return retval;
1226
-}
1227
-
1228
-/*!
1229
- * Function to call GetSchedPowerSavings() via TDE hardware library.
1230
- * \return boolean with result of the operation
1231
- * \retval true  	if successful
1232
- * \retval false 	else, if a error occurs
1233
- */
1234
-bool HardwareInfo::getSchedPowerSavings() {
1235
-	kdDebugFuncIn(trace);
1236
-
1237
-	bool returnval = false;
1238
-
1239
-	// What does the HAL method GetSchedPowerSavings actually do?!?!?
1240
-
1241
-	kdDebugFuncOut(trace);
1242
-	return returnval;
1243
-}
1244
-
1245
-/*!
1246
- * Function to call SetSchedPowerSavings() via TDE hardware library.
1247
- * Note: this would only work on multiprocessor/-core machines.
1248
- * \return boolean with result of the operation
1249
- * \retval true  	if successful
1250
- * \retval false 	else, if a error occurs
1251
- */
1252
-bool HardwareInfo::setSchedPowerSavings( bool enable ) {
1253
-	kdDebugFuncIn(trace);
1254
-
1255
-	bool retval = false;
1256
-
1257
-	// What does the HAL method SetCPUFreqPerformance actually do?!?!?
1258
-
1259
-	kdDebugFuncOut(trace);
1260
-	return retval;
1261
-}
1262
-
1263 1048
 
1264 1049
 // --> TDE hardware library method call (trigger actions) section -- END <---
1265 1050
 
@@ -1304,16 +1089,6 @@ void HardwareInfo::emitS2diskButtonPressed() {
1304 1089
  * Function to emit the signal about changes in the session state
1305 1090
  */
1306 1091
 void HardwareInfo::emitSessionActiveState() {
1307
-	if (sessionIsActive) {
1308
-		if (!dbus_HAL->acquiredPolicyPowerInterface()) {
1309
-			dbus_HAL->acquirePolicyPowerIface();
1310
-		}
1311
-	} else {
1312
-		if (dbus_HAL->acquiredPolicyPowerInterface()) {
1313
-			dbus_HAL->releasePolicyPowerIface();
1314
-		}
1315
-	}
1316
-
1317 1092
 	emit desktopSessionIsActive(sessionIsActive);
1318 1093
 }
1319 1094
 
@@ -1635,16 +1410,6 @@ int HardwareInfo::isCpuFreqAllowed () {
1635 1410
 	return cpuFreqAllowed;
1636 1411
 }
1637 1412
 
1638
-/*! check if the org.freedesktop.Policy.Power interface has an owner
1639
- * \return boolean with info if org.freedesktop.Policy.Power interface has an owner or not
1640
- * \retval true 	if there is a owner
1641
- * \retval false 	else
1642
- */
1643
-bool HardwareInfo::isPolicyPowerIfaceOwned () {
1644
-	return dbus_HAL->isPolicyPowerIfaceOwned();
1645
-}
1646
-
1647
-
1648 1413
 // --> get private members section -- END <---
1649 1414
 
1650 1415
 #include "hardware.moc"

+ 3
- 41
src/hardware.h View File

@@ -76,12 +76,6 @@ enum device_type {
76 76
 	UNKNOWN_DEVICE
77 77
 };
78 78
 
79
-enum ERROR_MSG {
80
-	DBUS_NO_RIGHTS,
81
-	DBUS_NOT_RUNNING,
82
-	DBUS_RUNNING
83
-};
84
-
85 79
 //! hold information if suspend/standby/pm actions are supported and allowed
86 80
 /*!
87 81
 * This dictionary contains information about the available pm capabilities and
@@ -138,7 +132,7 @@ private:
138 132
 	TDEHardwareDevices *m_hwdevices;
139 133
 
140 134
 	//! pointer to the dbusInterface connection class
141
-	dbusInterface *dbus_HAL;
135
+	dbusInterface *dbus_iface;
142 136
 
143 137
 	//! hold udis of special hardware execpt batteries represented by a TQString pairs (name,udi)
144 138
 	/*!
@@ -225,14 +219,6 @@ private:
225 219
 	* \li false: 	else
226 220
 	*/
227 221
 	bool cpuFreq;
228
-	//! if the machine support change *SchedPowerSavings methodes via TDE hardware library
229
-	/*!
230
-	* This boolean represent information if the machine support change the
231
-	* SchedPowerSavings methodes via TDE hardware library.
232
-	* \li true: 	if supported
233
-	* \li false: 	else
234
-	*/
235
-	bool schedPowerSavings;
236 222
 	//! if the machine support change brightness
237 223
 	/*!
238 224
 	* This boolean represent information if the machine support brightness changes.
@@ -315,24 +301,18 @@ private:
315 301
 	bool intialiseHWInfo();
316 302
 	//! reinit all hardware information
317 303
 	bool reinitHardwareInfos();
318
-	//! to check the current ConsoleKit session
319
-	bool checkConsoleKitSession();
320 304
 	//! to check if we should handle a device
321 305
 	bool checkIfHandleDevice ( TQString _udi, int *type );
322 306
 	//! to set the CPUFreq governor
323 307
 	bool setCPUFreqGovernor( const char *governor );
324
-	//! to get the state of SchedPowerSave setting of kernel/TDE hardware library
325
-	bool getSchedPowerSavings();
326
-	//! to set the state of SchedPowerSave setting of kernel/TDE hardware library
327
-	bool setSchedPowerSavings( bool enable );
328 308
 
329 309
 	//! find and update a battery information
330 310
 	void updateBatteryValues (TDEGenericDevice* device);
331 311
 
332 312
 private slots:
333 313
 
334
-	//! to fetch events from D-Bus and handle them
335
-	void processMessage (msg_type type, TQString message, TQString value);
314
+	//! handle changes of the session state
315
+	void handleSessionState (bool state);
336 316
 	//! to fetch events from the TDE hardware library and handle them
337 317
 	void processHardwareChangedEvent (TDEGenericDevice*);
338 318
 	//! to fetch keypresses from the TDE hardware library and handle them
@@ -392,10 +372,6 @@ signals:
392 372
 	void batteryWARNState(int type, int state);
393 373
 
394 374
 	// Error signals
395
-	//! signal if the HAL daemon terminate and restart
396
-	void halRunning( bool );
397
-	//! signal if the D-Bus daemon terminate and restart
398
-	void dbusRunning( int );
399 375
 
400 376
 	//! signal if the IsActive state of
401 377
 	void desktopSessionIsActive (bool);
@@ -428,15 +404,6 @@ public:
428 404
 	*/
429 405
 	bool update_info_primBattery_changed;
430 406
 
431
-	//! boolean which tell us if the D-Bus daemon was terminated
432
-	/*!
433
-	* This boolean contains information if the D-Bus daemon terminated and
434
-	* we recieved "dbus.terminate"
435
-	* \li true:  If D-Bus terminated
436
-	* \li false: If D-Bus not terminated
437
-	*/
438
-	bool dbus_terminated;
439
-
440 407
 	// --> functions
441 408
 	//! default constructor
442 409
 	HardwareInfo();
@@ -463,9 +430,6 @@ public:
463 430
 	//! if the user is allowed to change CPU Freq PolicyKit
464 431
 	int isCpuFreqAllowed ();
465 432
 
466
-	//! if org.freedesktop.Policy.Power has a owner
467
-	bool isPolicyPowerIfaceOwned();
468
-
469 433
 	//! get state of the AC adapter
470 434
 	bool getAcAdapter() const;
471 435
 	//! get the state of the lid button
@@ -498,8 +462,6 @@ public:
498 462
 	bool setBrightnessUp(int percentageStep = -1);
499 463
 	//! set the CPU frequency policy/speed
500 464
 	bool setCPUFreq ( cpufreq_type cpufreq, int limit = 51 );
501
-	//! call SetPowerSave method on TDE hardware library.
502
-	bool setPowerSave( bool on );
503 465
 
504 466
 	//! function to set warning states for the primary battery collection
505 467
 	void setPrimaryBatteriesWarningLevel (int _warn = -1, int _low = -1, int _crit = -1 );

+ 0
- 29
src/hardware_battery.cpp View File

@@ -279,35 +279,6 @@ bool Battery::checkBatteryType () {
279 279
 	// For now just report any batteries as primary...
280 280
 	type = BAT_PRIMARY;
281 281
 	return true;
282
-
283
-#if 0
284
-	if (dbus_HAL->halGetPropertyString(udi,"battery.type", &tmp_qstring)) {
285
-		if (tmp_qstring.compare("primary") == 0) {
286
-			type = BAT_PRIMARY;
287
-		} else if (tmp_qstring.compare("mouse") == 0) {
288
-			type = BAT_MOUSE;
289
-		} else if (tmp_qstring.compare("keyboard") == 0) {
290
-			type = BAT_KEYBOARD;
291
-		} else if (tmp_qstring.compare("keyboard_mouse") == 0) {
292
-			type = BAT_KEY_MOUSE;
293
-		} else if (tmp_qstring.compare("camera") == 0) {
294
-			type = BAT_CAMERA;
295
-		} else if (tmp_qstring.compare("ups") == 0) {
296
-			type = BAT_UPS;
297
-		} else {
298
-			//anything else will currently be "UNKNOWN"
299
-			type = BAT_UNKNOWN;
300
-		}
301
-		kdDebugFuncOut(trace);
302
-		return true;
303
-	} else {
304
-		//query was not successfull
305
-		kdWarning() << "Query of battery.type of " << udi << " was not successfull." << endl;
306
-		type = BAT_UNKNOWN;
307
-		kdDebugFuncOut(trace);
308
-		return false;
309
-	}
310
-#endif
311 282
 }
312 283
 
313 284
 //! to check battery.technology

+ 1
- 1
src/hardware_battery.h View File

@@ -45,7 +45,7 @@
45 45
 // TDE hardware library
46 46
 #include <tdehardwaredevices.h>
47 47
 
48
-#include "dbusInterface.h"
48
+#include "tdepowersave_debug.h"
49 49
 
50 50
 class Battery : public TQObject {
51 51
 

+ 0
- 46
src/privileges.h View File

@@ -1,46 +0,0 @@
1
-/***************************************************************************
2
- *   Copyright (C) 2007 by Danny Kukawka                                   *
3
- *                         <dkukawka@suse.de, danny.kukawka@web.de>        *
4
- *                                                                         *
5
- *   This program is free software; you can redistribute it and/or modify  *
6
- *   it under the terms of version 2 of the GNU General Public License     *
7
- *   as published by the Free Software Foundation.                         *
8
- *                                                                         *
9
- *   This program is distributed in the hope that it will be useful,       *
10
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12
- *   GNU General Public License for more details.                          *
13
- *                                                                         *
14
- *   You should have received a copy of the GNU General Public License     *
15
- *   along with this program; if not, write to the                         *
16
- *   Free Software Foundation, Inc.,                                       *
17
- *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.             *
18
- ***************************************************************************/
19
-
20
-/*! 
21
-*  \file 	privileges.h
22
-*  \brief 	Headerfile containing defines for privileges
23
-*  \author 	Danny Kukawka, <dkukawka@suse.de, danny.kukawka@web.de>
24
-*  \date    	2007
25
-*/
26
-
27
-#ifndef _PRIVILEGES_H_
28
-#define _PRIVILEGES_H_
29
-
30
-#ifdef HAVE_HAL_0_5_10
31
- #define PRIV_SUSPEND		"org.freedesktop.hal.power-management.suspend"
32
- #define PRIV_HIBERNATE		"org.freedesktop.hal.power-management.hibernate"
33
- #define PRIV_STANDBY		"org.freedesktop.hal.power-management.standby"
34
- #define PRIV_CPUFREQ		"org.freedesktop.hal.power-management.cpufreq"
35
- #define PRIV_LAPTOP_PANEL	"org.freedesktop.hal.power-management.lcd-panel"
36
- #define PRIV_SETPOWERSAVE	"org.freedesktop.hal.power-management.set-powersave"
37
-#else
38
- #define PRIV_SUSPEND		"hal-power-suspend"
39
- #define PRIV_HIBERNATE		"hal-power-hibernate"
40
- #define PRIV_STANDBY		"hal-power-standby"
41
- #define PRIV_CPUFREQ		"hal-power-cpufreq"
42
- #define PRIV_LAPTOP_PANEL	"hal-power-lcd-panel"
43
- #define PRIV_SETPOWERSAVE	"hal-power-set-powersave"
44
-#endif
45
-
46
-#endif

+ 0
- 3
src/settings.cpp View File

@@ -61,7 +61,6 @@ Settings::~Settings()
61 61
 bool Settings::load_scheme_settings(TQString schemeName){
62 62
 
63 63
 	tdeconfig->reparseConfiguration();
64
-	bool setToDefault = false;
65 64
 
66 65
 	if( schemeName == "Performance" || schemeName == i18n("Performance"))
67 66
 		 schemeName = "Performance";
@@ -78,7 +77,6 @@ bool Settings::load_scheme_settings(TQString schemeName){
78 77
 			// fallback to 'default-scheme'
79 78
 			tdeconfig->setGroup("default-scheme");
80 79
 			schemeName = "default-scheme";
81
-			setToDefault = true;
82 80
 		}
83 81
 		currentScheme = schemeName;
84 82
 
@@ -250,7 +248,6 @@ bool Settings::load_general_settings(){
250 248
 		psMsgAsPassivePopup = tdeconfig->readBoolEntry("psMsgAsPassivePopup",false);
251 249
 		forceDpmsOffOnLidClose = tdeconfig->readBoolEntry("forceDpmsOffOnLidClose",false);
252 250
 		unmountExternalOnSuspend = tdeconfig->readBoolEntry("unmountExternalOnSuspend",true);
253
-		callSetPowerSaveOnAC = tdeconfig->readBoolEntry("callSetPowerSaveOnAC",true);
254 251
 
255 252
 		lockmethod = tdeconfig->readEntry("lockMethod", "NULL");
256 253
 		if(lockmethod == "NULL") lockmethod = "automatic";

+ 0
- 8
src/settings.h View File

@@ -200,14 +200,6 @@ public:
200 200
 	 * \li false: if not
201 201
 	 */
202 202
 	bool forceDpmsOffOnLidClose;
203
-	//! if tdepowersave should call SetPowerSave() on HAL
204
-	/*!
205
-	 * This boolean tells if tdepowersave should call SetPowerSave on HAL depending
206
-	 * on the AC state.
207
-	 * \li true:  if should call
208
-	 * \li false: if not
209
-	 */
210
-	bool callSetPowerSaveOnAC;
211 203
 
212 204
 	//! time after resume to fake keyevent
213 205
 	/*!

+ 8
- 14
src/tdepowersave.cpp View File

@@ -1790,14 +1790,6 @@ void tdepowersave::setSchemeSettings(){
1790 1790
 		}
1791 1791
 	}
1792 1792
 
1793
-	// call setPowerSave() depending on AC state
1794
-	if (settings->callSetPowerSaveOnAC) {
1795
-		if (hwinfo->getAcAdapter())
1796
-			hwinfo->setPowerSave(false);
1797
-		else
1798
-			hwinfo->setPowerSave(true);
1799
-	}
1800
-
1801 1793
 	// --> set autosuspend settings
1802 1794
 	if(settings->autoSuspend) {
1803 1795
 		setAutoSuspend(false);
@@ -2176,10 +2168,12 @@ void tdepowersave::handleActionCall ( action action, int value , bool checkAC, b
2176 2168
 				break;
2177 2169
 		}
2178 2170
 	} else if (batWarnCall) {
2179
-		if (!hwinfo->isPolicyPowerIfaceOwned()) {
2171
+		// FIXME
2172
+		// Is there a way to check if is active power manager on currently active session?
2173
+		if (true) {
2180 2174
 			switch (action) {
2181 2175
 				case GO_SHUTDOWN:
2182
-					// to be shure if we really need the shutdown
2176
+					// to be sure if we really need the shutdown
2183 2177
 					if ((checkAC && !hwinfo->getAcAdapter()) || !checkAC ) {
2184 2178
 						DCOPRef shutdown = DCOPRef( "ksmserver", "ksmserver" );
2185 2179
 						shutdown.send("logout", 0, 2, 2);
@@ -2509,7 +2503,7 @@ TQString tdepowersave::currentScheme (){
2509 2503
 	if(hwinfo->isOnline()) {
2510 2504
 		return settings->currentScheme;
2511 2505
 	} else {
2512
-		return "ERROR: D-Bus and/or HAL not running";
2506
+		return "ERROR: D-Bus not running";
2513 2507
 	}
2514 2508
 
2515 2509
 	kdDebugFuncOut(trace);
@@ -2540,7 +2534,7 @@ TQString tdepowersave::currentCPUFreqPolicy() {
2540 2534
 		}
2541 2535
 		return _cpuFreq;
2542 2536
 	} else {
2543
-		return "ERROR: HAL or/and DBus not running";
2537
+		return "ERROR: DBus not running";
2544 2538
 	}
2545 2539
 
2546 2540
 	kdDebugFuncOut(trace);
@@ -2630,7 +2624,7 @@ TQStringList tdepowersave::allowed_sleepingStates(){
2630 2624
 		}
2631 2625
 	}
2632 2626
 	else {
2633
-		sleepList.append("ERROR: D-Bus and/or HAL not running");
2627
+		sleepList.append("ERROR: D-Bus not running");
2634 2628
 	}
2635 2629
 
2636 2630
 	kdDebugFuncOut(trace);
@@ -2651,7 +2645,7 @@ TQStringList tdepowersave::listSchemes(){
2651 2645
 		}
2652 2646
 	}
2653 2647
 	else {
2654
-		_schemeList.append("ERROR: D-Bus and/or HAL not running");
2648
+		_schemeList.append("ERROR: D-Bus not running");
2655 2649
 	}
2656 2650
 
2657 2651
 	kdDebugFuncOut(trace);

Loading…
Cancel
Save