By default, Bugzilla does not search the list of RESOLVED bugs.
You can force it to do so by putting the upper-case word ALL in front of your search query, e.g.: ALL tdelibs
We recommend searching for bugs this way, as you may discover that your bug has already been resolved and fixed in a later release. View | Details | Raw Unified | Return to bug 1597
Collapse All | Expand All

(-)a/ConfigureChecks.cmake (-3 / +3 lines)
Lines 51-60 if( NOT DBUS_FOUND ) Link Here
51
endif( )
51
endif( )
52
52
53
53
54
# check for dbus-tqt
54
# check for dbus-1-tqt
55
pkg_search_module( DBUS_TQT dbus-tqt )
55
pkg_search_module( DBUS_TQT dbus-1-tqt )
56
if( NOT DBUS_TQT_FOUND )
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
endif( )
58
endif( )
59
59
60
# check for msgfmt
60
# check for msgfmt
(-)a/src/CMakeLists.txt (-2 / +2 lines)
Lines 16-23 include_directories( Link Here
16
  ${CMAKE_BINARY_DIR}
16
  ${CMAKE_BINARY_DIR}
17
  ${TDE_INCLUDE_DIR}
17
  ${TDE_INCLUDE_DIR}
18
  ${TQT_INCLUDE_DIRS}
18
  ${TQT_INCLUDE_DIRS}
19
  ${DBUS_INCLUDE_DIRS}
19
  ${DBUS_TQT_INCLUDE_DIRS}
20
  ${DBUS_TQT_INCLUDE_DIRS}
20
  ${HAL_INCLUDE_DIRS}
21
)
21
)
22
22
23
link_directories(
23
link_directories(
Lines 48-53 tde_add_tdeinit_executable( tdepowersave AUTOMOC Link Here
48
    tdepowersave.skel log_viewer.ui logviewer.cpp main.cpp
48
    tdepowersave.skel log_viewer.ui logviewer.cpp main.cpp
49
    screen.cpp settings.cpp suspenddialog.cpp suspend_Dialog.ui
49
    screen.cpp settings.cpp suspenddialog.cpp suspend_Dialog.ui
50
  LINK
50
  LINK
51
    ${DBUS_TQT_LIBRARIES} tdeio-shared ${HAL_LIBRARIES}
51
    ${DBUS_TQT_LIBRARIES} tdeio-shared
52
    ${XEXT_LIBRARIES} ${XTST_LIBRARIES} ${XSCRNSAVER_LIBRARIES}
52
    ${XEXT_LIBRARIES} ${XTST_LIBRARIES} ${XSCRNSAVER_LIBRARIES}
53
)
53
)
(-)a/src/Makefile.am (-1 lines)
Lines 21-27 noinst_HEADERS = \ Link Here
21
		infodialog.h                    \
21
		infodialog.h                    \
22
		tdepowersave.h                    \
22
		tdepowersave.h                    \
23
		logviewer.h			\
23
		logviewer.h			\
24
		privileges.h			\
25
		screen.h                        \
24
		screen.h                        \
26
		settings.h                      \
25
		settings.h                      \
27
		suspenddialog.h
26
		suspenddialog.h
(-)a/src/dbusInterface.cpp (-515 / +233 lines)
Lines 19-27 Link Here
19
19
20
/*! 
20
/*! 
21
 * \file 	dbusInterface.cpp
21
 * \file 	dbusInterface.cpp
22
 * \brief 	In this file can be found the functionality to connect to 
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
23
 *		the D-Bus, to handle D-Bus session management
24
 *		provide wrapper to HAL lib and functions
25
 * \author 	Danny Kukawka, <dkukawka@suse.de>, <danny.kukawka@web.de>
24
 * \author 	Danny Kukawka, <dkukawka@suse.de>, <danny.kukawka@web.de>
26
 * \date    	2006-2007
25
 * \date    	2006-2007
27
 */
26
 */
Lines 30-56 Link Here
30
#include <tdelocale.h>
29
#include <tdelocale.h>
31
30
32
// DBUS - Header
31
// DBUS - Header
32
#include "dbus/dbus-shared.h"
33
#include "dbusInterface.h"
33
#include "dbusInterface.h"
34
#include <tqdbusdatalist.h>
35
#include <tqdbusdatamap.h>
36
#include <tqdbuserror.h>
37
#include <tqdbusmessage.h>
38
#include <tqdbusvariant.h>
34
39
35
// system headers
40
// system headers
36
#include <iostream>
41
#include <unistd.h>
37
42
38
static void* myInstance = 0;
43
static void* myInstance = 0;
39
44
40
/*! The default constructor of the class dbusInterface. */
45
/*! The default constructor of the class dbusInterface. */
41
dbusInterface::dbusInterface(){
46
dbusInterface::dbusInterface():
47
    dBusConn(),
48
    dBusWatch(0),
49
    systemdSession(),
50
    systemdSeat(0),
51
    systemdInhibit(-1),
52
    consolekitSession(),
53
    consolekitSeat(0)
54
    {
42
	kdDebugFuncIn(trace);
55
	kdDebugFuncIn(trace);
43
56
44
	dbus_is_connected = false;
45
	acquiredPolicyPower = false;
46
47
	// add pointer to this for filter_function()
57
	// add pointer to this for filter_function()
48
	myInstance=this;
58
	myInstance=this;
59
49
	// init connection to dbus
60
	// init connection to dbus
50
	if(!initDBUS()) {
61
	initDBUS();
51
		kdError() << "Can't connect to D-Bus" << endl;
52
		m_dBusQtConnection = NULL;
53
	}
54
62
55
	kdDebugFuncOut(trace);
63
	kdDebugFuncOut(trace);
56
}
64
}
Lines 72-101 dbusInterface::~dbusInterface(){ Link Here
72
 * \retval false if disconnected
80
 * \retval false if disconnected
73
 */
81
 */
74
bool dbusInterface::isConnectedToDBUS() {
82
bool dbusInterface::isConnectedToDBUS() {
75
	return dbus_is_connected;
83
	return dBusConn.isConnected();
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;
87
}
84
}
88
85
89
/*! 
86
/*! 
90
 * This function try a reconnect to D-Bus and HAL  daemon.
87
 * This function try a reconnect to D-Bus.
91
 * \return boolean with the result of the operation
88
 * \return boolean with the result of the operation
92
 * \retval true if successful reconnected to D-Bus and HAL
89
 * \retval true if successful reconnected to D-Bus
93
 * \retval false if unsuccessful
90
 * \retval false if unsuccessful
94
 */
91
 */
95
bool dbusInterface::reconnect() {
92
bool dbusInterface::reconnect() {
96
	// close D-Bus connection
93
	// close D-Bus connection
97
	close();
94
	close();
98
	// init D-Bus conntection and HAL context
95
	// init D-Bus conntection
99
	return (initDBUS());
96
	return (initDBUS());
100
}
97
}
101
98
Lines 106-123 bool dbusInterface::reconnect() { Link Here
106
 * \retval false if any problems
103
 * \retval false if any problems
107
 */
104
 */
108
bool dbusInterface::close() {
105
bool dbusInterface::close() {
109
	if ( m_dBusQtConnection != NULL ) {
106
	if( dBusConn.isConnected() ) {
110
		releasePolicyPowerIface();
107
		if( dBusWatch ) {
111
		m_dBusQtConnection->close();
108
			delete dBusWatch;
112
		m_dBusQtConnection = NULL;
109
		}
110
		if( systemdSeat ) {
111
			delete systemdSeat;
112
		}
113
		if( consolekitSeat ) {
114
			delete consolekitSeat;
115
		}
116
		dBusConn.closeConnection();
113
	}
117
	}
114
	dbus_is_connected = false;
115
116
	return true;
118
	return true;
117
}
119
}
118
120
119
/* ----> D-Bus section :: START <---- */
120
121
/*! 
121
/*! 
122
 * This function initialise the connection to the D-Bus daemon.
122
 * This function initialise the connection to the D-Bus daemon.
123
 * \return boolean with the result of the operation
123
 * \return boolean with the result of the operation
Lines 127-654 bool dbusInterface::close() { Link Here
127
bool dbusInterface::initDBUS(){
127
bool dbusInterface::initDBUS(){
128
	kdDebugFuncIn(trace);
128
	kdDebugFuncIn(trace);
129
129
130
	dbus_is_connected = false;
130
	dBusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
131
132
        DBusError error;
133
        dbus_error_init(&error);
134
	
135
	dbus_connection = dbus_bus_get( DBUS_BUS_SYSTEM, &error );
136
137
	if (dbus_connection == NULL){
138
		kdError() << "Failed to open connection to system message bus: " << error.message << endl;
139
		dbus_error_free (&error);
140
		return false;
141
	}
142
131
143
	if ( dbus_error_is_set( &error ) ) {
132
	if( !dBusConn.isConnected() ) {
144
		kdError() << "Failed to register connection with system message bus: " << error.message << endl;
133
		kdError() << "Failed to open connection to system message bus: " << dBusConn.lastError().name().local8Bit() << endl;
145
		return false;
134
		return false;
146
	}
135
	}
147
136
148
	acquirePolicyPowerIface();
137
	// watcher for NameOwnerChanged signals
149
138
	dBusWatch = new TQT_DBusProxy(DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, dBusConn);
150
	dbus_connection_set_exit_on_disconnect( dbus_connection, false );
139
	TQObject::connect(dBusWatch, TQT_SIGNAL(dbusSignal(const TQT_DBusMessage&)),
151
140
			  this, TQT_SLOT(handleDBusSignal(const TQT_DBusMessage&)));
152
        /* add the filter function which should be executed on events on the bus */
141
153
        if ( ! dbus_connection_add_filter( dbus_connection, filterFunction, this, NULL) ) {
142
	// find already running SystemD
154
                kdFatal() << "Error: Not enough memory to add filter to dbus connection" << endl;
143
	TQT_DBusProxy checkSystemD(DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, dBusConn);
155
                exit(EXIT_FAILURE);
144
	if( checkSystemD.canSend() ) {
156
        }
145
		TQValueList<TQT_DBusData> params;
157
146
		params << TQT_DBusData::fromString(SYSTEMD_LOGIN1_SERVICE);
158
        /* add a match rule to catch all signals going through the bus with D-Bus interface */
147
		TQT_DBusMessage reply = checkSystemD.sendWithReply("NameHasOwner", params);
159
	dbus_bus_add_match( dbus_connection, "type='signal',"
148
		if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1 && reply[0].toBool() ) {
160
			    "interface='org.freedesktop.DBus'," 
149
			onServiceRegistered(SYSTEMD_LOGIN1_SERVICE);
161
			    "member='NameOwnerChanged'", NULL);
150
		}
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;
189
	}
151
	}
190
152
191
	DBusError err;
153
	// find already running ConsoleKit
192
	dbus_error_init(&err);
154
	TQT_DBusProxy checkConsoleKit(DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, dBusConn);
193
	int ret = dbus_bus_request_name(dbus_connection, "org.freedesktop.Policy.Power",
155
	if( checkConsoleKit.canSend() ) {
194
					DBUS_NAME_FLAG_REPLACE_EXISTING, &err);
156
		TQValueList<TQT_DBusData> params;
195
	if (dbus_error_is_set(&err)) {
157
		params << TQT_DBusData::fromString(CK_SERVICE);
196
		kdWarning() << "Acquire org.freedesktop.Policy.Power interface failed with error: " << err.message << endl;
158
		TQT_DBusMessage reply = checkConsoleKit.sendWithReply("NameHasOwner", params);
197
		dbus_error_free(&err);
159
		if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1 && reply[0].toBool() ) {
198
	}
160
			onServiceRegistered(CK_SERVICE);
199
	switch (ret) {
161
		}
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;
211
	}
162
	}
212
163
213
	kdDebugFuncOut(trace);
164
	kdDebugFuncOut(trace);
214
	return acquiredPolicyPower;
165
	return true;
215
}
166
}
216
167
217
/*! 
168
/*! 
218
 * This function release the org.freedesktop.Policy.Power interface
169
 * This function handles signals from the D-Bus daemon.
219
 * \return boolean with the result of the operation
220
 * \retval true 	if successful acquired the interface
221
 * \retval false 	if unsuccessful
222
 */
170
 */
223
bool dbusInterface::releasePolicyPowerIface(){
171
void dbusInterface::handleDBusSignal(const TQT_DBusMessage& msg) {
224
	kdDebugFuncIn(trace);
172
	// service registered / unregistered
225
173
	if( msg.path() == DBUS_PATH_DBUS
226
	int result;
174
	 && msg.interface() == DBUS_INTERFACE_DBUS
227
	bool retval = false;
175
	 && msg.member() == "NameOwnerChanged" ) {
228
	DBusError error;
176
		if( msg[1].toString().isEmpty() ) {
229
177
			// old-owner is empty
230
	if (dbus_connection == NULL) {
178
			onServiceRegistered(msg[0].toString());
231
		kdDebugFuncOut(trace);
179
		}
232
		return false;
180
		if( msg[2].toString().isEmpty() ) {
233
	}
181
			// new-owner is empty
234
182
			onServiceUnregistered(msg[0].toString());
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;
258
		}
183
		}
184
		return;
259
	}
185
	}
260
		
261
	return retval;
262
	kdDebugFuncOut(trace);
263
}
264
186
265
/*! 
187
	// systemd session changed
266
 * This function check if the org.freedesktop.Policy.Power 
188
	if( systemdSeat
267
 * interface is owned by someone
189
	 && msg.path() == systemdSeat->path()
268
 * \return boolean with the result of the operation
190
	 && msg.interface() == DBUS_INTERFACE_PROPERTIES
269
 * \retval true 	if the interface is owned by someone
191
	 && msg.member() == "PropertiesChanged"
270
 * \retval false 	if else
192
	 && msg[0].toString() == SYSTEMD_LOGIN1_SEAT_IFACE) {
271
 */
193
		bool activeSessionProperty = false;
272
bool dbusInterface::isPolicyPowerIfaceOwned(){
194
		TQT_DBusDataMap<TQString> map = msg[1].toStringKeyMap();
273
	kdDebugFuncIn(trace);
195
		TQT_DBusDataMap<TQString>::const_iterator it = map.begin();
274
196
		for (; !activeSessionProperty && it != map.end(); ++it) {
275
	bool retval = false;
197
			if( it.key() != "ActiveSession" ) {
276
	DBusError error;
198
				activeSessionProperty = true;
277
199
			}
278
	if (dbus_connection == NULL) {
200
		}
279
		kdDebugFuncOut(trace);
201
		TQValueList<TQString> list = msg[2].toList().toStringList();
280
		return false;
202
		TQValueList<TQString>::const_iterator it1 = list.begin();
203
		for (; !activeSessionProperty && it1 != list.end(); ++it1) {
204
			if( (*it1) == "ActiveSession" ) {
205
				activeSessionProperty = true;
206
			}
207
		}
208
		if( activeSessionProperty ) {
209
			emit activeSessionChanged(checkActiveSession());
210
		}
211
		return;
281
	}
212
	}
282
213
283
        dbus_error_init(&error);
214
	// consolekit session changed
284
215
	if( consolekitSeat
285
	retval = dbus_bus_name_has_owner(dbus_connection, "org.freedesktop.Policy.Power", &error);
216
	 && msg.path() == consolekitSeat->path()
286
217
	 && msg.interface() == CK_SEAT_IFACE
287
	if ( dbus_error_is_set( &error ) ) {
218
	 && msg.member() == "ActiveSessionChanged") {
288
		kdError() << "Failed to check if org.freedesktop.Policy.Power has an owner: " << error.message << endl;
219
		emit activeSessionChanged(msg[0].toString() == TQString(consolekitSession));
289
		dbus_error_free(&error);
220
		return;
290
	}
221
	}
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
}
222
}
324
223
325
224
/*!
326
/*! 
225
 * This function handles dBus service registering
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
}
352
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
366
 */
226
 */
367
bool dbusInterface::dbusMethodCall( TQString interface, TQString path, TQString object, TQString method,
227
void dbusInterface::onServiceRegistered(const TQString& service) {
368
			      DBusBusType dbus_type, void *retvalue, int retval_type, int first_arg_type,
228
	if( service == SYSTEMD_LOGIN1_SERVICE ) {
369
			      va_list var_args ) {
229
		// get current session
370
	kdDebugFuncIn(trace);
230
		TQT_DBusProxy managerIface(SYSTEMD_LOGIN1_SERVICE, SYSTEMD_LOGIN1_PATH, SYSTEMD_LOGIN1_MANAGER_IFACE, dBusConn);
371
231
		systemdSession = TQT_DBusObjectPath();
372
	DBusMessage *message;
232
		if( managerIface.canSend() ) {
373
	DBusMessage *reply;
233
			TQValueList<TQT_DBusData> params;
374
	DBusError    error;
234
			params << TQT_DBusData::fromUInt32( getpid() );
375
	bool ret = false;
235
			TQT_DBusMessage reply = managerIface.sendWithReply("GetSessionByPID", params);
376
	
236
			if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1 ) {
377
	dbus_error_init(&error); 
237
				systemdSession = reply[0].toObjectPath();
378
238
			}
379
	dbus_connection = dbus_bus_get(dbus_type, &error);
239
		}
380
	
240
		if( !systemdSession.isValid() ) {
381
	if (dbus_error_is_set(&error)) {
241
			kdWarning() << "The session is not registered with systemd" << endl;
382
		kdError() << "Could not get dbus connection: " << error.message << endl;
242
			return;
383
		dbus_error_free(&error);
243
		}
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);
389
244
390
	if (retvalue == NULL) {
245
		// get session seat
391
		if (!dbus_connection_send(dbus_connection, message, NULL)) {
246
		TQT_DBusProxy sessionProperties(SYSTEMD_LOGIN1_SERVICE, systemdSession, DBUS_INTERFACE_PROPERTIES, dBusConn);
392
			kdError() << "Could not send method call." << endl;
247
		TQT_DBusObjectPath seat;
393
			dbus_message_unref( message );
248
		if( sessionProperties.canSend() ) {
394
			goto out;
249
			TQValueList<TQT_DBusData> params;
250
			params
251
			 << TQT_DBusData::fromString( SYSTEMD_LOGIN1_SESSION_IFACE )
252
			 << TQT_DBusData::fromString( "Seat" );
253
			TQT_DBusMessage reply = sessionProperties.sendWithReply("Get", params);
254
			if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1 ) {
255
				seat = reply[0].toVariant().value.toStruct()[1].toObjectPath();
256
			}
395
		}
257
		}
396
	} else {
258
		if( !seat.isValid() ) {
397
		reply = dbus_connection_send_with_reply_and_block(dbus_connection, message, -1, &error);
259
			kdWarning() << "Unable to associate systemd session with a seat" << endl;
398
260
			return;
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;
404
		}
261
		}
405
262
406
		int type = dbus_message_get_type(reply);
263
		// watch session changes
407
		if (type == DBUS_MESSAGE_TYPE_METHOD_RETURN) {
264
		systemdSeat = new TQT_DBusProxy(SYSTEMD_LOGIN1_SERVICE, seat, DBUS_INTERFACE_PROPERTIES, dBusConn);
408
			if (!dbus_message_get_args(reply, &error, retval_type, retvalue, DBUS_TYPE_INVALID)){
265
		TQObject::connect(systemdSeat, TQT_SIGNAL(dbusSignal(const TQT_DBusMessage&)),
409
				if (dbus_error_is_set(&error)) {
266
				  this, TQT_SLOT(handleDBusSignal(const TQT_DBusMessage&)));
410
					kdError() << "Could not get argument from reply: " 
267
411
						  << error.message << endl;
268
		// inhibit systemd handling of power/sleep/hibernate/lid buttons
412
					dbus_error_free(&error);
269
		// http://www.freedesktop.org/wiki/Software/systemd/inhibit
413
				}
270
		if( !systemdInhibit.isValid() && managerIface.canSend() ) {
414
				dbus_message_unref(reply);
271
			TQValueList<TQT_DBusData> params;
415
				dbus_message_unref(message);
272
			params
416
				goto out;
273
			 << TQT_DBusData::fromString("handle-power-key:handle-suspend-key:handle-hibernate-key:handle-lid-switch") // what
274
			 << TQT_DBusData::fromString("TDEPowersave") // who
275
			 << TQT_DBusData::fromString("TDE handles power events") // why
276
			 << TQT_DBusData::fromString("block"); // mode
277
			TQT_DBusMessage reply = managerIface.sendWithReply("Inhibit", params);
278
			if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1 ) {
279
				systemdInhibit = reply[0].toUnixFd();
417
			}
280
			}
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
		}
281
		}
282
		return;
425
	}
283
	}
284
	if( service == CK_SERVICE ) {
285
		// get current session
286
		TQT_DBusProxy managerIface(CK_SERVICE, CK_MANAGER_OBJECT, CK_MANAGER_IFACE, dBusConn);
287
		consolekitSession = TQT_DBusObjectPath();
288
		if( managerIface.canSend() ) {
289
			TQValueList<TQT_DBusData> params;
290
			params << TQT_DBusData::fromUInt32( getpid() );
291
			TQT_DBusMessage reply = managerIface.sendWithReply("GetSessionForUnixProcess", params);
292
			if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1 ) {
293
				consolekitSession = reply[0].toObjectPath();
294
			}
295
		}
296
		if( !consolekitSession.isValid() ) {
297
			kdWarning() << "The session is not registered with consolekit" << endl;
298
			return;
299
		}
426
300
427
	ret = true;	// if we are here, everything should be okay
301
		// get session seat
428
	dbus_message_unref(message);
302
		TQT_DBusObjectPath seat;
429
	dbus_connection_flush(dbus_connection);
303
		if( dBusConn.isConnected() ) {
430
304
			TQT_DBusMessage msg = TQT_DBusMessage::methodCall(CK_SERVICE, consolekitSession, CK_SESSION_IFACE, "GetSeatId");
431
out:
305
			TQT_DBusMessage reply = dBusConn.sendWithReply(msg);
432
	kdDebugFuncOut(trace);
306
			if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1 ) {
433
        return ret;
307
				seat = reply[0].toObjectPath();
434
}
308
			}
435
309
		}
436
/* ----> D-Bus methode calls functions :: END  <---- */
310
		if( !seat.isValid() ) {
437
/* ---> PolicyKit method call section :: START <--- */
311
			kdWarning() << "Unable to associate consolekit session with a seat" << endl;
438
312
			return;
439
/*!
313
		}
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);
452
314
453
	const char *_unique_name;
315
		// watch session changes
454
	const char *_user;
316
		consolekitSeat = new TQT_DBusProxy(CK_SERVICE, seat, CK_SEAT_IFACE, dBusConn);
455
	const char *_privilege;	
317
		TQObject::connect(consolekitSeat, TQT_SIGNAL(dbusSignal(const TQT_DBusMessage&)),
456
	
318
				  this, TQT_SLOT(handleDBusSignal(const TQT_DBusMessage&)));
457
	int retval = -1;
319
		return;
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;
488
	}
320
	}
489
490
out:
491
	kdDebugFuncOut(trace);
492
	return retval;
493
}
321
}
494
/* ---> PolicyKit method call section :: END   <--- */
495
322
496
/*!
323
/*!
497
 * Use this TQT_SLOT to emit a reviced messages to the tdepowersave.
324
 * This function handles dBus service unregistering
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
503
 */
325
 */
504
void dbusInterface::emitMsgReceived( msg_type type, TQString message, TQString string ) {
326
void dbusInterface::onServiceUnregistered(const TQString& service) {
505
	
327
	if( service == SYSTEMD_LOGIN1_SERVICE ) {
506
	if (message.startsWith("dbus.terminate"))
328
		systemdInhibit.setFileDescriptor(-1);
507
		dbus_is_connected = false;
329
		systemdSession = TQT_DBusObjectPath();
508
330
		if( systemdSeat ) {
509
	if (type == POLICY_POWER_OWNER_CHANGED) {
331
			delete systemdSeat;
510
		if (message.startsWith("NOW_OWNER"))
332
		}
511
			acquiredPolicyPower = true;
333
		return;
512
		else 
334
	}
513
			acquiredPolicyPower = false;
335
	if( service == CK_SERVICE ) {
336
		consolekitSession = TQT_DBusObjectPath();
337
		if( consolekitSeat ) {
338
			delete consolekitSeat;
339
		}
340
		return;
514
	}
341
	}
515
516
	emit msgReceived_withStringString( type, message, string );
517
}
342
}
518
343
519
#include "dbusInterface.moc"
344
/*!
520
// --> functions which are not member of the class ...
345
 * This functions is used to check if session is active
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
529
 */
346
 */
530
DBusHandlerResult 
347
bool dbusInterface::checkActiveSession() {
531
filterFunction (DBusConnection *connection, DBusMessage *message, void */*data*/) {
348
	if( systemdSeat && systemdSeat->canSend() ) {
532
 	kdDebugFuncIn(trace);
349
		TQT_DBusObjectPath activeSession;
533
	
350
		TQValueList<TQT_DBusData> params;
534
	bool reply_wanted;
351
		params
535
	char *value;
352
		 << TQT_DBusData::fromString( SYSTEMD_LOGIN1_SEAT_IFACE )
536
	TQString ifaceType;
353
		 << TQT_DBusData::fromString( "ActiveSession" );
537
354
		TQT_DBusMessage reply = systemdSeat->sendWithReply("Get", params);
538
	DBusError error;
355
		if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1 ) {
539
        dbus_error_init( &error );
356
			activeSession = reply[0].toVariant().value.toStruct()[1].toObjectPath();
540
357
			return (activeSession == systemdSession);
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;
578
		}
358
		}
579
	
359
	}
580
		if (trace) kdDebug() << "filter_function::SIGNAL=" << signal << " VALUE=" << value << endl;
360
	if( consolekitSeat && consolekitSeat->canSend() ) {
581
	
361
		TQT_DBusObjectPath activeSession;
582
		/* our name is... */
362
		TQValueList<TQT_DBusData> params;
583
		if ( ! strcmp( signal, "NameAcquired" ) ) {
363
		TQT_DBusMessage reply = consolekitSeat->sendWithReply("GetActiveSession", params);
584
			kdDebugFuncOut(trace);
364
		if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1 ) {
585
			return DBUS_HANDLER_RESULT_HANDLED;
365
			activeSession = reply[0].toObjectPath();
586
		}
366
			return (activeSession == consolekitSession);
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;
639
		}
367
		}
640
		kdDebugFuncOut(trace);
641
		return DBUS_HANDLER_RESULT_HANDLED;
642
	} else {
643
		kdDebugFuncOut(trace);
644
		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
645
	}
368
	}
369
	return false;
646
}
370
}
647
371
648
// --> some functions to get private members
372
#include "dbusInterface.moc"
649
650
//! to get the current connection to D-Bus
651
DBusConnection * dbusInterface::get_DBUS_connection() {
652
	return dbus_connection;
653
}
654
(-)a/src/dbusInterface.h (-74 / +38 lines)
Lines 23-35 Link Here
23
*/
23
*/
24
/*!
24
/*!
25
*  \class 	dbusInterface
25
*  \class 	dbusInterface
26
*  \brief 	class for connection to HAL via D-Bus
26
*  \brief 	class for connection to D-Bus
27
*  \author 	Danny Kukawka, <dkukawka@suse.de>, <danny.kukawka@web.de>
27
*  \author 	Danny Kukawka, <dkukawka@suse.de>, <danny.kukawka@web.de>
28
*  \date    	2006-2007
28
*  \date    	2006-2007
29
*/
29
*/
30
30
31
#ifndef _DBUSHAL_H_
31
#ifndef _DBUS_INTERFACE_H_
32
#define _DBUSHAL_H_
32
#define _DBUS_INTERFACE_H_
33
33
34
#ifndef DBUS_API_SUBJECT_TO_CHANGE
34
#ifndef DBUS_API_SUBJECT_TO_CHANGE
35
#define DBUS_API_SUBJECT_TO_CHANGE
35
#define DBUS_API_SUBJECT_TO_CHANGE
Lines 41-52 Link Here
41
#endif
41
#endif
42
42
43
// QT - Header
43
// QT - Header
44
#include <tqobject.h>
44
#include <tqstring.h>
45
#include <tqstring.h>
45
46
46
// D-Bus Header
47
// D-Bus Header
47
#include <dbus/dbus.h> // needed for dbus_bool_t
48
#include <tqdbusconnection.h>
48
#include <dbus/message.h>
49
#include <tqdbusobjectpath.h>
49
#include <dbus/connection.h>
50
#include <tqdbusproxy.h>
51
#include <tqdbusunixfd.h>
50
52
51
// tdepowersave - Header
53
// tdepowersave - Header
52
#include "tdepowersave_debug.h"
54
#include "tdepowersave_debug.h"
Lines 55-70 Link Here
55
#define CK_MANAGER_IFACE	"org.freedesktop.ConsoleKit.Manager"
57
#define CK_MANAGER_IFACE	"org.freedesktop.ConsoleKit.Manager"
56
#define CK_MANAGER_OBJECT	"/org/freedesktop/ConsoleKit/Manager"
58
#define CK_MANAGER_OBJECT	"/org/freedesktop/ConsoleKit/Manager"
57
#define CK_SESSION_IFACE	"org.freedesktop.ConsoleKit.Session"
59
#define CK_SESSION_IFACE	"org.freedesktop.ConsoleKit.Session"
60
#define CK_SEAT_IFACE		"org.freedesktop.ConsoleKit.Seat"
58
61
59
enum msg_type {
62
#define SYSTEMD_LOGIN1_SERVICE		"org.freedesktop.login1"
60
	ACPI_EVENT,
63
#define SYSTEMD_LOGIN1_PATH		"/org/freedesktop/login1"
61
	DBUS_EVENT,
64
#define SYSTEMD_LOGIN1_MANAGER_IFACE	"org.freedesktop.login1.Manager"
62
	HAL_DEVICE,
65
#define SYSTEMD_LOGIN1_SESSION_IFACE	"org.freedesktop.login1.Session"
63
	HAL_PROPERTY_CHANGED,
66
#define SYSTEMD_LOGIN1_SEAT_IFACE	"org.freedesktop.login1.Seat"
64
	HAL_CONDITION,
65
	CONSOLEKIT_SESSION_ACTIVE,
66
	POLICY_POWER_OWNER_CHANGED
67
};
68
67
69
class dbusInterface : public TQObject{
68
class dbusInterface : public TQObject{
70
	Q_OBJECT
69
	Q_OBJECT
Lines 72-106 class dbusInterface : public TQObject{ Link Here
72
71
73
private:
72
private:
74
73
75
	//! QT connection to D-Bus
74
	//! TQt connection to D-Bus
76
	DBusQt::Connection* m_dBusQtConnection;
75
	TQT_DBusConnection dBusConn;
77
	//! real connection to D-Bus
76
78
	DBusConnection *dbus_connection;
77
	//! TQt D-Bus proxy for watching signals
79
78
	TQT_DBusProxy* dBusWatch;
80
	//! to store information if TDEPowersave is connected to D-Bus
79
81
	/*!
80
	TQT_DBusObjectPath systemdSession;
82
	* This boolean represent information about the state of the connection to D-Bus
81
	TQT_DBusProxy* systemdSeat;
83
	* \li true:  if connected
82
	TQT_DBusUnixFd systemdInhibit;
84
	* \li false: if disconnected
83
85
	*/
84
	TQT_DBusObjectPath consolekitSession;
86
	bool dbus_is_connected;
85
	TQT_DBusProxy* consolekitSeat;
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;
96
86
97
	/* D-Bus helper functions */
87
	/* D-Bus helper functions */
98
	//! to initialise the connection to D-Bus 
88
	//! to initialise the connection to D-Bus 
99
	bool initDBUS();
89
	bool initDBUS();
100
	//! to call a methode on a dbus interface with reply
90
101
	bool dbusMethodCall( TQString interface, TQString path, TQString object, TQString method,
91
	//! handles signal service registred/unregistered
102
			     DBusBusType dbus_type, void *retvalue, int retval_type,
92
	void onServiceRegistered(const TQString&);
103
			     int first_arg_type, va_list var_args);
93
	void onServiceUnregistered(const TQString&);
104
94
105
public:
95
public:
106
96
Lines 109-160 public: Link Here
109
	//! default destructor
99
	//! default destructor
110
	~dbusInterface();
100
	~dbusInterface();
111
101
112
	//! to reconnect to D-Bus and HAL
102
	//! to reconnect to D-Bus
113
	bool reconnect();
103
	bool reconnect();
114
	//! to close the connection to D-Bus and HAL
104
	//! to close the connection to D-Bus
115
	bool close();
105
	bool close();
116
106
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
	// --- helper to get private members of the class --- //
107
	// --- helper to get private members of the class --- //
125
	//! to get information if TDEPowersave is connected to D-Bus
108
	//! to get information if TDEPowersave is connected to D-Bus
126
	bool isConnectedToDBUS();
109
	bool isConnectedToDBUS();
127
	//! to get info about claim org.freedesktop.Policy.Power interface
128
	bool acquiredPolicyPowerInterface();
129
110
130
	//! return the current DBus connection
111
	//! to check active session state
131
	DBusConnection *get_DBUS_connection();
112
	bool checkActiveSession();
132
113
133
	/* D-Bus helper functions */
114
public slots:
134
115
135
	/* functions to call methodes */
116
	void handleDBusSignal(const TQT_DBusMessage&);
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, ... );
142
117
143
	/* PolicyKit call helper */
118
signals:
144
	//! check if the user has a requested privilege
145
	int isUserPrivileged( TQString privilege, TQString udi, TQString ressource = "", TQString user = TQString());
146
119
147
	//! wrapper to emit a signal with a event from HAL
120
	void activeSessionChanged(bool);
148
	void emitMsgReceived( msg_type type, TQString message, TQString string );
149
121
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
};
122
};
156
123
157
//! filter function to filter out needed information from D-Bus messages
158
DBusHandlerResult filterFunction (DBusConnection *connection, DBusMessage *message, void *data);
159
160
#endif
124
#endif
(-)a/src/hardware.cpp (-252 / +17 lines)
Lines 37-43 Link Here
37
// include own header
37
// include own header
38
#include "hardware.h"
38
#include "hardware.h"
39
#include "tdepowersave_debug.h"
39
#include "tdepowersave_debug.h"
40
#include "privileges.h"
41
40
42
// #define USE_EVENT_DEVICES_DIRECTLY 1
41
// #define USE_EVENT_DEVICES_DIRECTLY 1
43
42
Lines 51-57 HardwareInfo::HardwareInfo() { Link Here
51
	laptop = false;
50
	laptop = false;
52
	brightness = false;
51
	brightness = false;
53
	brightness_in_hardware = false;
52
	brightness_in_hardware = false;
54
	schedPowerSavings = false;
55
	sessionIsActive = true;	 // assume as first we are active
53
	sessionIsActive = true;	 // assume as first we are active
56
54
57
	// initialize connection to the TDE hardware library
55
	// initialize connection to the TDE hardware library
Lines 79-98 HardwareInfo::HardwareInfo() { Link Here
79
	primaryBatteries = new BatteryCollection(BAT_PRIMARY);
77
	primaryBatteries = new BatteryCollection(BAT_PRIMARY);
80
	setPrimaryBatteriesWarningLevel(); // force default settings
78
	setPrimaryBatteriesWarningLevel(); // force default settings
81
79
82
	// connect to D-Bus and HAL
80
	// connect to D-Bus
83
	dbus_HAL = new dbusInterface();
81
	dbus_iface = new dbusInterface();
84
	if (dbus_HAL->isConnectedToDBUS()) {
82
	sessionIsActive = dbus_iface->checkActiveSession();
85
		dbus_terminated = false;
83
	connect(dbus_iface, TQT_SIGNAL(activeSessionChanged(bool)), this, TQT_SLOT(handleSessionState(bool)));
86
	} else {
87
		kdError() << "Could not connect to D-Bus & HAL" << endl;
88
	}
89
84
90
	checkConsoleKitSession();
91
	checkPowermanagement();
85
	checkPowermanagement();
92
	checkIsLaptop();
86
	checkIsLaptop();
93
	checkBrightness();
87
	checkBrightness();
94
	checkCPUFreq();
88
	checkCPUFreq();
95
	// getSchedPowerSavings();
96
	checkSuspend();
89
	checkSuspend();
97
	intialiseHWInfo();
90
	intialiseHWInfo();
98
91
Lines 141-155 bool HardwareInfo::reinitHardwareInfos () { Link Here
141
	checkCPUFreq();
134
	checkCPUFreq();
142
	checkSuspend();
135
	checkSuspend();
143
	intialiseHWInfo();
136
	intialiseHWInfo();
144
	// getSchedPowerSavings();
145
	updatePrimaryBatteries();
137
	updatePrimaryBatteries();
146
138
147
	kdDebugFuncOut(trace);
139
	kdDebugFuncOut(trace);
148
	return true;
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
 * \param device 	a \ref TDEGenericDevice* which should be processed
157
 * \param device 	a \ref TDEGenericDevice* which should be processed
154
 */
158
 */
155
void HardwareInfo::processHardwareChangedEvent (TDEGenericDevice* device) {
159
void HardwareInfo::processHardwareChangedEvent (TDEGenericDevice* device) {
Lines 216-314 void HardwareInfo::processKeyPressEvent(unsigned int keycode, TDEEventDevice* ed Link Here
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
 * This TQT_SLOT is used to fetch the resume signal and multiplex. If needed some
223
 * This TQT_SLOT is used to fetch the resume signal and multiplex. If needed some
313
 * actions after resume, do this here.
224
 * actions after resume, do this here.
314
 * \param result 	integer with the result of the resume/suspend
225
 * \param result 	integer with the result of the resume/suspend
Lines 331-391 void HardwareInfo::handleResumeSignal (int result) { Link Here
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
 * This function check for a given UDI, if we should handle a device
245
 * This function check for a given UDI, if we should handle a device
390
 * \param _udi		TQString with the UDI of the device
246
 * \param _udi		TQString with the UDI of the device
391
 * \param *type		pointer to a integer to return the type of the device, see \ref device_type
247
 * \param *type		pointer to a integer to return the type of the device, see \ref device_type
Lines 1090-1096 bool HardwareInfo::setCPUFreq ( cpufreq_type cpufreq, int limit ) { Link Here
1090
	TDEGenericHardwareList hwlist = m_hwdevices->listByDeviceClass(TDEGenericDeviceType::CPU);
946
	TDEGenericHardwareList hwlist = m_hwdevices->listByDeviceClass(TDEGenericDeviceType::CPU);
1091
947
1092
	if (hwlist.count() > 0) {
948
	if (hwlist.count() > 0) {
1093
		dbus_bool_t consider = (dbus_bool_t) getAcAdapter();
1094
		TQStringList dynamic;
949
		TQStringList dynamic;
1095
950
1096
		if (checkCurrentCPUFreqPolicy() == cpufreq) {
951
		if (checkCurrentCPUFreqPolicy() == cpufreq) {
Lines 1122-1141 bool HardwareInfo::setCPUFreq ( cpufreq_type cpufreq, int limit ) { Link Here
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
				// Set performance limits on all CPUs
980
				// Set performance limits on all CPUs
1140
				TDEGenericDevice *hwdevice;
981
				TDEGenericDevice *hwdevice;
1141
				TDECPUDevice *cpudevice;
982
				TDECPUDevice *cpudevice;
Lines 1185-1191 bool HardwareInfo::setCPUFreq ( cpufreq_type cpufreq, int limit ) { Link Here
1185
bool HardwareInfo::setCPUFreqGovernor( const char *governor ) {
1026
bool HardwareInfo::setCPUFreqGovernor( const char *governor ) {
1186
	kdDebugFuncIn(trace);
1027
	kdDebugFuncIn(trace);
1187
1028
1188
	int reply;
1189
	bool ret = true;
1029
	bool ret = true;
1190
1030
1191
	TDEGenericHardwareList hwlist = m_hwdevices->listByDeviceClass(TDEGenericDeviceType::CPU);
1031
	TDEGenericHardwareList hwlist = m_hwdevices->listByDeviceClass(TDEGenericDeviceType::CPU);
Lines 1205-1265 bool HardwareInfo::setCPUFreqGovernor( const char *governor ) { Link Here
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
// --> TDE hardware library method call (trigger actions) section -- END <---
1049
// --> TDE hardware library method call (trigger actions) section -- END <---
1265
1050
Lines 1304-1319 void HardwareInfo::emitS2diskButtonPressed() { Link Here
1304
 * Function to emit the signal about changes in the session state
1089
 * Function to emit the signal about changes in the session state
1305
 */
1090
 */
1306
void HardwareInfo::emitSessionActiveState() {
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
	emit desktopSessionIsActive(sessionIsActive);
1092
	emit desktopSessionIsActive(sessionIsActive);
1318
}
1093
}
1319
1094
Lines 1635-1650 int HardwareInfo::isCpuFreqAllowed () { Link Here
1635
	return cpuFreqAllowed;
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
// --> get private members section -- END <---
1413
// --> get private members section -- END <---
1649
1414
1650
#include "hardware.moc"
1415
#include "hardware.moc"
(-)a/src/hardware.h (-41 / +3 lines)
Lines 76-87 enum device_type { Link Here
76
	UNKNOWN_DEVICE
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
//! hold information if suspend/standby/pm actions are supported and allowed
79
//! hold information if suspend/standby/pm actions are supported and allowed
86
/*!
80
/*!
87
* This dictionary contains information about the available pm capabilities and
81
* This dictionary contains information about the available pm capabilities and
Lines 138-144 private: Link Here
138
	TDEHardwareDevices *m_hwdevices;
132
	TDEHardwareDevices *m_hwdevices;
139
133
140
	//! pointer to the dbusInterface connection class
134
	//! pointer to the dbusInterface connection class
141
	dbusInterface *dbus_HAL;
135
	dbusInterface *dbus_iface;
142
136
143
	//! hold udis of special hardware execpt batteries represented by a TQString pairs (name,udi)
137
	//! hold udis of special hardware execpt batteries represented by a TQString pairs (name,udi)
144
	/*!
138
	/*!
Lines 225-238 private: Link Here
225
	* \li false: 	else
219
	* \li false: 	else
226
	*/
220
	*/
227
	bool cpuFreq;
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
	//! if the machine support change brightness
222
	//! if the machine support change brightness
237
	/*!
223
	/*!
238
	* This boolean represent information if the machine support brightness changes.
224
	* This boolean represent information if the machine support brightness changes.
Lines 315-338 private: Link Here
315
	bool intialiseHWInfo();
301
	bool intialiseHWInfo();
316
	//! reinit all hardware information
302
	//! reinit all hardware information
317
	bool reinitHardwareInfos();
303
	bool reinitHardwareInfos();
318
	//! to check the current ConsoleKit session
319
	bool checkConsoleKitSession();
320
	//! to check if we should handle a device
304
	//! to check if we should handle a device
321
	bool checkIfHandleDevice ( TQString _udi, int *type );
305
	bool checkIfHandleDevice ( TQString _udi, int *type );
322
	//! to set the CPUFreq governor
306
	//! to set the CPUFreq governor
323
	bool setCPUFreqGovernor( const char *governor );
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
	//! find and update a battery information
309
	//! find and update a battery information
330
	void updateBatteryValues (TDEGenericDevice* device);
310
	void updateBatteryValues (TDEGenericDevice* device);
331
311
332
private slots:
312
private slots:
333
313
334
	//! to fetch events from D-Bus and handle them
314
	//! handle changes of the session state
335
	void processMessage (msg_type type, TQString message, TQString value);
315
	void handleSessionState (bool state);
336
	//! to fetch events from the TDE hardware library and handle them
316
	//! to fetch events from the TDE hardware library and handle them
337
	void processHardwareChangedEvent (TDEGenericDevice*);
317
	void processHardwareChangedEvent (TDEGenericDevice*);
338
	//! to fetch keypresses from the TDE hardware library and handle them
318
	//! to fetch keypresses from the TDE hardware library and handle them
Lines 392-401 signals: Link Here
392
	void batteryWARNState(int type, int state);
372
	void batteryWARNState(int type, int state);
393
373
394
	// Error signals
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
	//! signal if the IsActive state of
376
	//! signal if the IsActive state of
401
	void desktopSessionIsActive (bool);
377
	void desktopSessionIsActive (bool);
Lines 428-442 public: Link Here
428
	*/
404
	*/
429
	bool update_info_primBattery_changed;
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
	// --> functions
407
	// --> functions
441
	//! default constructor
408
	//! default constructor
442
	HardwareInfo();
409
	HardwareInfo();
Lines 463-471 public: Link Here
463
	//! if the user is allowed to change CPU Freq PolicyKit
430
	//! if the user is allowed to change CPU Freq PolicyKit
464
	int isCpuFreqAllowed ();
431
	int isCpuFreqAllowed ();
465
432
466
	//! if org.freedesktop.Policy.Power has a owner
467
	bool isPolicyPowerIfaceOwned();
468
469
	//! get state of the AC adapter
433
	//! get state of the AC adapter
470
	bool getAcAdapter() const;
434
	bool getAcAdapter() const;
471
	//! get the state of the lid button
435
	//! get the state of the lid button
Lines 498-505 public: Link Here
498
	bool setBrightnessUp(int percentageStep = -1);
462
	bool setBrightnessUp(int percentageStep = -1);
499
	//! set the CPU frequency policy/speed
463
	//! set the CPU frequency policy/speed
500
	bool setCPUFreq ( cpufreq_type cpufreq, int limit = 51 );
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
	//! function to set warning states for the primary battery collection
466
	//! function to set warning states for the primary battery collection
505
	void setPrimaryBatteriesWarningLevel (int _warn = -1, int _low = -1, int _crit = -1 );
467
	void setPrimaryBatteriesWarningLevel (int _warn = -1, int _low = -1, int _crit = -1 );
(-)a/src/hardware_battery.cpp (-29 lines)
Lines 279-313 bool Battery::checkBatteryType () { Link Here
279
	// For now just report any batteries as primary...
279
	// For now just report any batteries as primary...
280
	type = BAT_PRIMARY;
280
	type = BAT_PRIMARY;
281
	return true;
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
//! to check battery.technology
284
//! to check battery.technology
(-)a/src/hardware_battery.h (-1 / +1 lines)
Lines 45-51 Link Here
45
// TDE hardware library
45
// TDE hardware library
46
#include <tdehardwaredevices.h>
46
#include <tdehardwaredevices.h>
47
47
48
#include "dbusInterface.h"
48
#include "tdepowersave_debug.h"
49
49
50
class Battery : public TQObject {
50
class Battery : public TQObject {
51
51
(-)a/src/privileges.h (-46 lines)
Lines 1-46 Link Here
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
(-)a/src/settings.cpp (-3 lines)
Lines 61-67 Settings::~Settings() Link Here
61
bool Settings::load_scheme_settings(TQString schemeName){
61
bool Settings::load_scheme_settings(TQString schemeName){
62
62
63
	tdeconfig->reparseConfiguration();
63
	tdeconfig->reparseConfiguration();
64
	bool setToDefault = false;
65
64
66
	if( schemeName == "Performance" || schemeName == i18n("Performance"))
65
	if( schemeName == "Performance" || schemeName == i18n("Performance"))
67
		 schemeName = "Performance";
66
		 schemeName = "Performance";
Lines 78-84 bool Settings::load_scheme_settings(TQString schemeName){ Link Here
78
			// fallback to 'default-scheme'
77
			// fallback to 'default-scheme'
79
			tdeconfig->setGroup("default-scheme");
78
			tdeconfig->setGroup("default-scheme");
80
			schemeName = "default-scheme";
79
			schemeName = "default-scheme";
81
			setToDefault = true;
82
		}
80
		}
83
		currentScheme = schemeName;
81
		currentScheme = schemeName;
84
82
Lines 250-256 bool Settings::load_general_settings(){ Link Here
250
		psMsgAsPassivePopup = tdeconfig->readBoolEntry("psMsgAsPassivePopup",false);
248
		psMsgAsPassivePopup = tdeconfig->readBoolEntry("psMsgAsPassivePopup",false);
251
		forceDpmsOffOnLidClose = tdeconfig->readBoolEntry("forceDpmsOffOnLidClose",false);
249
		forceDpmsOffOnLidClose = tdeconfig->readBoolEntry("forceDpmsOffOnLidClose",false);
252
		unmountExternalOnSuspend = tdeconfig->readBoolEntry("unmountExternalOnSuspend",true);
250
		unmountExternalOnSuspend = tdeconfig->readBoolEntry("unmountExternalOnSuspend",true);
253
		callSetPowerSaveOnAC = tdeconfig->readBoolEntry("callSetPowerSaveOnAC",true);
254
251
255
		lockmethod = tdeconfig->readEntry("lockMethod", "NULL");
252
		lockmethod = tdeconfig->readEntry("lockMethod", "NULL");
256
		if(lockmethod == "NULL") lockmethod = "automatic";
253
		if(lockmethod == "NULL") lockmethod = "automatic";
(-)a/src/settings.h (-8 lines)
Lines 200-213 public: Link Here
200
	 * \li false: if not
200
	 * \li false: if not
201
	 */
201
	 */
202
	bool forceDpmsOffOnLidClose;
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
	//! time after resume to fake keyevent
204
	//! time after resume to fake keyevent
213
	/*!
205
	/*!
(-)a/src/tdepowersave.cpp (-14 / +8 lines)
Lines 1790-1803 void tdepowersave::setSchemeSettings(){ Link Here
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
	// --> set autosuspend settings
1793
	// --> set autosuspend settings
1802
	if(settings->autoSuspend) {
1794
	if(settings->autoSuspend) {
1803
		setAutoSuspend(false);
1795
		setAutoSuspend(false);
Lines 2176-2185 void tdepowersave::handleActionCall ( action action, int value , bool checkAC, b Link Here
2176
				break;
2168
				break;
2177
		}
2169
		}
2178
	} else if (batWarnCall) {
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
			switch (action) {
2174
			switch (action) {
2181
				case GO_SHUTDOWN:
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
					if ((checkAC && !hwinfo->getAcAdapter()) || !checkAC ) {
2177
					if ((checkAC && !hwinfo->getAcAdapter()) || !checkAC ) {
2184
						DCOPRef shutdown = DCOPRef( "ksmserver", "ksmserver" );
2178
						DCOPRef shutdown = DCOPRef( "ksmserver", "ksmserver" );
2185
						shutdown.send("logout", 0, 2, 2);
2179
						shutdown.send("logout", 0, 2, 2);
Lines 2509-2515 TQString tdepowersave::currentScheme (){ Link Here
2509
	if(hwinfo->isOnline()) {
2503
	if(hwinfo->isOnline()) {
2510
		return settings->currentScheme;
2504
		return settings->currentScheme;
2511
	} else {
2505
	} else {
2512
		return "ERROR: D-Bus and/or HAL not running";
2506
		return "ERROR: D-Bus not running";
2513
	}
2507
	}
2514
2508
2515
	kdDebugFuncOut(trace);
2509
	kdDebugFuncOut(trace);
Lines 2540-2546 TQString tdepowersave::currentCPUFreqPolicy() { Link Here
2540
		}
2534
		}
2541
		return _cpuFreq;
2535
		return _cpuFreq;
2542
	} else {
2536
	} else {
2543
		return "ERROR: HAL or/and DBus not running";
2537
		return "ERROR: DBus not running";
2544
	}
2538
	}
2545
2539
2546
	kdDebugFuncOut(trace);
2540
	kdDebugFuncOut(trace);
Lines 2630-2636 TQStringList tdepowersave::allowed_sleepingStates(){ Link Here
2630
		}
2624
		}
2631
	}
2625
	}
2632
	else {
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
	kdDebugFuncOut(trace);
2630
	kdDebugFuncOut(trace);
Lines 2651-2657 TQStringList tdepowersave::listSchemes(){ Link Here
2651
		}
2645
		}
2652
	}
2646
	}
2653
	else {
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
	kdDebugFuncOut(trace);
2651
	kdDebugFuncOut(trace);

Return to bug 1597