summaryrefslogtreecommitdiffstats
path: root/src/kpowersave.h
blob: 4ff6a3dca397d5d726c2adb4592a74daa668fc74 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
/**************************************************************************
*   Copyright (C) 2004 by  Thomas Renninger                               *
*                            <trenn@suse.de> and                          *
*            2004-2007 by  Danny Kukawka                                  *
*                            <dkukawka@suse.de>, <danny.kukawka@web.de>   *
*                                                                         *
*   This program is free software; you can redistribute it and/or modify  *
*   it under the terms of version 2 of the GNU General Public License     *
*   as published by the Free Software Foundation.                         *
*                                                                         *
*   This program is distributed in the hope that it will be useful,       *
*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
*   GNU General Public License for more details.                          *
*                                                                         *
*   You should have received a copy of the GNU General Public License     *
*   along with this program; if not, write to the                         *
*   Free Software Foundation, Inc.,                                       *
*   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.          *
***************************************************************************/

#ifndef _KPOWERSAVE_H_
#define _KPOWERSAVE_H_

// this is needed to avoid typedef clash with X11/Xmd.h (X11/Xproto.h)
#ifndef TQT_CLEAN_NAMESPACE
#define TQT_CLEAN_NAMESPACE
#endif

// Global Header
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

// KDE - Header
#include <kprocess.h>
#include <ksystemtray.h>
#include <dcopobject.h>

// QT - Header
#include <tqpopupmenu.h>

// kpowersave - Header
#include "autosuspend.h"
#include "autodimm.h"
#include "configuredialog.h"
#include "countdowndialog.h"
#include "detaileddialog.h"
#include "hardware.h"
#include "kpowersave_debug.h"
#include "logviewer.h"
#include "screen.h"
#include "settings.h"


/*!
*  \file 	kpowersave.h
*  \brief 	Headerfile for kpowersave.cpp and the class \ref kpowersave.
*/
 /*!
 *  \class 	kpowersave
 *  \brief 	The central class for the kpowersave-applet
 *  \author 	Danny Kukawka, <dkukawka@suse.de>, <danny.kukawka@web.de>
 *  \author 	Thomas Renninger, <trenn@suse.de>
 *  \date    	2004 - 2007
 */

class kpowersave : public KSystemTray, public DCOPObject
{
	Q_OBJECT
//	
	K_DCOP

private:

	// permanent pointers
	//! to configure kpowersave
	KConfig *config;
	//! instance of \ref screen
	screen *display;
	//! instance of \ref settings
	Settings *settings;
	//! pointer to class HardwareInfo object
	HardwareInfo *hwinfo;
	//! instance of \ref autosuspend
	autosuspend *autoSuspend;
	//! instance of \ref autodimm
	autodimm * autoDimm;

	// temporary pointer, use them if needed
	//! TDEProcess to start YaST-module for configuration
	TDEProcess *yast2;
	//! instance of \ref ConfigureDialog
	/*! the implemtation and all related functions for the configure dialog*/
	ConfigureDialog *configDlg;
	//! instance of \ref LogViewer
	LogViewer *logview;
	//! instance of \ref countDownDialog
	countDownDialog *countdown;


	//! struct wth information about suspend states and permissions
	SuspendStates suspend;
	//! enum with the last called suspend, this need to be reset if needed
	int calledSuspend;

	//! instance of \ref detaileddialog
	detaileddialog *detailedDlg;

	//! represent the state of opened \ref detailedDlg
	/*!
	* This boolean represent information about the detailedDlg. Use this to inform
	* if the dialog is displayed.
	* \li true:  if dialog is displayed
	* \li false: if not
	*/
	bool detailedIsShown;
	//! represent the state of the configure dialog
	/*!
	* This boolean represent information about the configure dialog. Use this to inform
	* if the dialog is displayed.
	* \li true:  if dialog is displayed
	* \li false: if not
	*/
	bool config_dialog_shown;

	//! represent background status of the kickerapplet icon
	/*!
	* This boolean represent information about the background of the kickerapplet icon.
	* \li true:  if iconbackground is colored
	* \li false: if iconbackground is not colored
	*/
	bool icon_BG_is_colored;
	//! represent color status of the kickerapplet icon
	/*!
	* This boolean represent the state of the kickerapplet icon. It don't display
	* information about the icon backgrund like \ref icon_BG_is_colored . It say
	* only that the icon is in state to have a blinking background .
	* \li true:  if icon set to be colored
	* \li false: if icon isn't set to be colored
	*/
	bool icon_set_colored;
	//! represent the state of icon changing
	/*!
	* This boolean represent information about changing the icon background. It's used to
	* change the intervall of redraw the kickerapplet icon.
	* \li true:  if the state of icon is changed
	* \li false: if the state of icon isn't change
	*/
	bool icon_state_changed;
        //! represent the state of the suspend/progress dialog
	/*!
	* This boolean represent information about the current state of
        * visible of the suspend/progress dialog.
	* \li true:  if the dialog is shown
	* \li false: if not
	*/
	bool suspend_dialog_shown;
	//! represent display state of HAL error message
	/*!
	* This boolean represent information about the current state of
        * the HAL error message
	* \li true:  if the errormessage was already displayed in this context
	* \li false: if not
	*/
	bool hal_error_shown;

	//! tell if the display should get dimmed down
	/*!
	* This boolean represent information if the display should get dimmed down
	* within the \ref do_dimm() function or not.
	* \li true:  if the display should get dimmed down
	* \li false: if the display should get dimmed up
	*/
	bool autoDimmDown;

	//! to temporary hold the resume result
	int resume_result;

	//! a menu entry ID
	/*! contains the ID of the menuentry for kpowersave configure Dialog */
	int CONFIGURE_ID;

	int CONFIGURE_EVENTS_ID;

	//! a menu entry ID
	/*! contains the ID of the menuentry for YaST-configuration */
	int YAST_MODULE_MENU_ID;
	//! a menu seperator ID
	/*! contains the ID of the separator between YaST-entry and the sleep-states */
	int SLEEP_SEPARATOR_MENU_ID;
	//! a menu entry ID
	/*! contains the ID of the menuentry for suspend-to-disk */
	int SUSPEND2DISK_MENU_ID;
	//! a menu entry ID
	/*! contains the ID of the menuentry for suspend-to-ram */
	int SUSPEND2RAM_MENU_ID;
	//! a menu entry ID
	/*! contains the ID of the menuentry for stand-by */
	int STANDBY_MENU_ID;
	//! a menu seperator ID
	/*! contains the ID of the separator between sleep-states-entries and the cpufreq-submenu */
	int CPUFRETQ_SEPARATOR_MENU_ID;
	//! a submenu ID
	/*! contains the ID of the cpufreq sub menu*/
	int CPUFRETQ_MENU_ID;
	//! a menu seperator ID
	/*! contains the ID of the separator between cpufreq- and scheme-submenu*/
	int SCHEME_SEPARATOR_MENU_ID;
	//! a submenu ID
	/*! contains the ID of the scheme submenu*/
	int SCHEME_MENU_ID;
	//! a menu seperator ID
	/*! contains the ID of the separator between scheme-submenu and autosuspend*/
	int AUTOSUSPEND_SEPARATOR_MENU_ID;
	//! a menu entry ID
	/*! contains the ID of the menuentry for disable inactivity actions */
	int AUTOSUSPEND_MENU_ID;
	//! a menu seperator ID
	/*! contains the ID of the separator between autosuspend and Help*/
	int HELP_SEPARATOR_MENU_ID;
	//! a menu ID
	/*! contains the ID of the help menu*/
	int HELP_MENU;

	//! number of white pixel in the kickerapplet icon
	/*!
	* This integer value represent the number of white pixel in the icon for
	* the kickerapplet. with this 'global' variable we don't need to count the
	* white pixel on every redraw.
	*/
	int countWhiteIconPixel;

	//! TQTimer-interval for icon background
	/*!
	* Time intervall to set the colored background of the batteryicon on/off.
	* The value is 1000 msec/ 1 sec.
	*/
	static const int BAT_icon_BG_intervall = 1000;

	//! TQTimer-interval for display HAL error message
	/*!
	* Time intervall to delay display the HAL error message to prevent displayed
	* the message if only HAL or powersave is restarted. The value is 15000 msec/ 15 sec.
	*/
	static const int HAL_ERROR_MSG_intervall = 15000;

        //! type of current running suspend
        /*! TQString store the name of the current running suspend*/
	TQString suspendType;

	//! current name of the pixmap
	/*!
	* Contains the current name of the icon/pixmap. The value must be a filename of a existing iconfile.
	* \sa power_icon, no_battery_icon, charge_icon, battery, battery_RED or battery_ORANGE
	*/
	TQString pixmap_name;

	//! contains the 'real' schemenames
	/*!
	* This list store the real schemenames (not the i18n()-version)
	* regarding to position in the scheme-menu
	*/
	TQStringList org_schemenames;

	//! a sub-menu of the kickerapplet
	/*! TQPopupMenu for the cpufreq-entries. */
	TQPopupMenu *speed_menu;
	//! a sub-menu of the kickerapplet
	/*! TQPopupMenu for the scheme-entries. */
	TQPopupMenu *scheme_menu;
	//! a sub-menu of the kickerapplet
	/*! TQPopupMenu for the help-entries. */
	TQPopupMenu *help_menu;


	//! icon-pixmap
	/*! TQPixmap with the (pre-)loaded icon from \ref  pixmap_name .*/
	TQPixmap pixmap;
	//! icon-pixmap
	/*! TQPixmap with the full draw applet Icon (to be used in other classes) .*/
	TQPixmap fullIcon;


	//! Timer for the blinking Icon background
	/*!
	* This timer is used to let blink the background of a icon in kicker.
	* The timerinterval is defined in \ref BAT_icon_BG_intervall .
	*/
	TQTimer *BAT_WARN_ICON_Timer;
	//! Timer to delay the HAL error message
	/*!
	* This timer is used to add a delay befor display the HAL error message
	* The timerinterval is defined in \ref HAL_ERROR_MSG_intervall .
	*/
	TQTimer *DISPLAY_HAL_ERROR_Timer;
	//! Timer to dimm down/up the brightness
	/*!
	 * This timer is used dimm the display up and down. The timerinterval
         * depends on calculated timePerStep in the calling function.
	 */
	TQTimer *AUTODIMM_Timer;

	//! draw all icon related things for \ref redrawPixmap()
	void drawIcon();
	//! to intialise the menu for the kickerapplet
        void initMenu();
	//! load the icon for \ref redrawPixmap()
	void loadIcon(bool forceReload = false);
	//! draw/redraw the icon for the kickerapplet
	void redrawPixmap();
	//! to set the screensaver settings
	void setSchemeSettings();
	//! to update the Tooltip of the kickerapplet
	void updateTooltip();

	//! Eventhandler to catch mouse-press-events and react
	void mousePressEvent( TQMouseEvent *qme );
	//! Event handler to catch mouse wheel events and react
	void wheelEvent( TQWheelEvent *qwe );
	//! Eventhandler to catch mouse enter events and react
	void enterEvent( TQEvent *qee);

	//! to handle mount/umount on resume/suspend
	bool handleMounts ( bool suspend );

	//! to get the i18n string for a suspend type
	TQString getSuspendString (int type);

private slots:

	//! send command for stand-by to the HAL daemon
	bool do_standby();
	//! send command for suspend_to_disk to the HAL daemon
	bool do_suspend2disk();
	//! send command for suspend_to_RAM to the HAL daemon
	bool do_suspend2ram();

	//! show warning dialog or call autosuspend if signal \ref inactivity::inactivityTimeExpired() recieved
	void do_autosuspendWarn();
	//! execute the autosuspend
	bool do_autosuspend(bool chancel);
	//! starts the Yast2-power-management module
	void do_config();
	//! sets the new scheme with all settings
	void do_setActiveScheme( int );
	//! called if icon background must be changed
	void do_setIconBG();
	//! to set the autosuspend on/off over the menu
	void do_setAutosuspend();
	//! sets the CPU Freq policy via the HAL daemon
	void do_setSpeedPolicy( int );
	//! called if there are problems with starting yast module
	void slotConfigProcessExited( TDEProcess * );
	//! called to open the kpowersave help
	void slotHelp();
	//! called to open the kpowersave About dialog
	void slotAbout();
	//! called to open website to report bugs
	void slotReportBug();
	//! called if the configure dialog is destroyed
	void observeConfigDlg();
	//! called if user exit from kpowersave
	void _quit();

	//! called if the user get inactive and the display should get dimmed down
	void do_downDimm();
	//! called if the user get active again and the display should get dimmed up
	void do_upDimm();
	//! TQT_SLOT do do the dimmining for autodimm feature
	void do_dimm();
	//! TQT_SLOT to set autodimm related stuff and start autodimm monitoring
	void setAutoDimm( bool resumed );

	//! to update the main menu of the kickerapplet
	/*! this is bound to generalDataChanged singal in pdaemon */
	void update();
	//! to update the scheme-menu within the main menu
	void updateSchemeMenu();
	//! to update the menu with the cpu frequency within the main menu
	void updateCPUFreqMenu();

        //! this set \ref suspendType from signal
        void setSuspendType( TQString suspendtype );
	//! this set the autosuspend and start the monitoring
	void setAutoSuspend( bool );

	//! called for critical battery event SHUTDOWN
	void handleCriticalBatteryActionCall();
	//! set for a battery status the related actions
	void handleActionCall ( action action, int value, bool checkAC = false, bool batWarnCall = false );

	//! this lock/reactivate the screen if a lidclosetStatus() signal is triggered
	void handleLidEvent( bool closed );
	//! show the login dialog after locked the screen
	void activateLoginScreen();

	//! handle event for press power button and call action
	void handlePowerButtonEvent();
	//!  handle event for press s2ram/sleep button and call action
	void handleSleepButtonEvent();
	//!  handle event for press s2disk button and call action
	void handleS2DiskButtonEvent();

	//! handle changes of the session state
	void handleSessionState (bool state);

	//! to show the kpowersave configure_dialog
	void showConfigureDialog();
	//! to show the KNotify config dialog
	void showConfigureNotificationsDialog();

	//! this emit the KNotify event for a battery warning state state
	void notifyBatteryStatusChange ( int type, int state );
	//! this emit the KNotify event for change AC status
	void handleACStatusChange ( bool acstate, bool notifyEvent = true );
	//! this emit the KNotify events if scheme switched
	void notifySchemeSwitch();
	//! this emit the KNotify events if the machine go to suspend/Standby
	void notifySuspend( int );
	//! to independent  handleResumeSignal from event loop
	void forwardResumeSignal( int result );
	//! this emit the KNotify events if the machine resumed
	void handleResumeSignal();

	//! to display HAL error msg
	void showHalErrorMsg( );
	//! this is invoked to display powersave error message
	void showDBusErrorMsg( int );
	//! this show a blocking dialog from kpowersave with the given message
	void showErrorMessage( TQString msg );

	//! this is called when detailed dialog is closed
	void closedetaileddialog();

public:

	//! default constructor
	kpowersave( bool force_acpi_check = false, bool trace_func = false);
	//! default destructor
	virtual ~kpowersave();

k_dcop:
	//! dcop function to lock the screen
	bool lockScreen();
	//! dcop function to set a scheme
	bool do_setScheme( TQString );
	//! dcop function to set CPU Freq policy
	bool do_setCPUFreqPolicy( TQString );
	//! dcop function to send 'suspend to disk' command to powersaved
	bool do_suspendToDisk();
	//! dcop function to send 'suspend to RAM' command to powersaved
	bool do_suspendToRAM();
	//! dcop function to send 'standby' command to powersaved
	bool do_standBy();
	//! dcop function to set the brightness down
	bool do_brightnessDown(int percentageStep = -1);
	//! dcop function to set the brightness up
	bool do_brightnessUp(int percentageStep = -1);

	//! dcop function to disable/stop autosuspend
	void disableAutosuspend( bool );

	//! dcop function to show the detailed dialog
	void showDetailedDialog();
	//! dcop function to open the configure dialog
	bool openConfigureDialog();

        //! dcop function to find out if kpowersave manages DPMS
        bool currentSchemeManagesDPMS();
	//! dcop funtion to get the current brightness level
	int brightnessGet();

	//! dcop function to return the name of the current scheme
	TQString currentScheme ();
	//! dcop function to return the current cpufreqpolicy
	TQString currentCPUFreqPolicy();

	//! dcop function to return the supported sleeping states
	TQStringList allowed_sleepingStates();
	//! dcop function to return the schemes
	TQStringList listSchemes();
	//! dcop function to return the supported CPU
	TQStringList listCPUFreqPolicies();

protected:
	void resizeEvent ( TQResizeEvent * );
};

#endif // _KPOWERSAVE_H_