summaryrefslogtreecommitdiffstats
path: root/src/inactivity.h
blob: 7ad3eb5bba5ca29d603881bc1255a9410ea6a8a4 (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
 /**************************************************************************
 *   Copyright (C) 2006 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 _INACTIVITY_H_
#define _INACTIVITY_H_

// KDE Header
#include <kprocess.h>

// QT Header
#include <tqregexp.h>
#include <tqstring.h>
#include <tqwidget.h>
#include <tqtimer.h>
#include <tqevent.h>

// X11 Header
#include <X11/X.h>
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <X11/Xutil.h>

/* needed for lXext C library linkage */
extern "C" {
	#include <X11/extensions/scrnsaver.h>
}

// from project
#include "tdepowersave_debug.h"
#include "screen.h"

/*! 
*  \file 	inactivity.h
*  \brief 	Headerfile for inactivity.cpp and the class \ref inactivity.
*/
/*! 
*  \class 	inactivity
*  \brief 	class for detect inactivity related funtionality
*  \author 	Danny Kukawka, <dkukawka@suse.de>, <danny.kukawka@web.de>
*  \date    	2006
*/

class inactivity : public TQWidget
{
	Q_OBJECT
  
	
public:
	//! default constructor
	inactivity(screen *disp);
	//! default destructor
	~inactivity();
	
	//! to start the monitoring of the X-Server
	void start(int, TQStringList);
	//! to stop the monitoring of the X-Server
	void stop();
	
	//! to get the current user inactivity
	unsigned long getXInactivity();

signals:

	//! signal emited if the with \ref start() set time of inactivity is expired
	void inactivityTimeExpired();
	//! signal to emit error msg
	void displayErrorMsg( TQString );
	
private:

	//! pointer to the process to call pidof
	TDEProcess *proc;
	
	//! about the call result of pidof 
	/*!
	 * This boolean tells if call of the command pidof failed.
	 * \li true:  if failed
	 * \li false: if not
	 */
	bool pidof_call_failed;
	//! about the call of command pidof
	/*!
	 * This boolean tells if the call of the command pidof was started or if
	 * the command is running
	 * \li true:  if is started/running
	 * \li false: if not
	 */
	bool pidof_call_started;
	//! if pidof return value is recieved
	/*!
	 * This boolean tells if the call of the command pidof returned and the 
	 * returnvalue was parsed to set \ref blacklisted_running
	 * \li true:  if returned and parsed
	 * \li false: if not
	 */
	bool pidof_call_returned;
	//! if a blacklisted program/process is running
	/*! 
	 * This boolean tells if a blacklisted program/process is currently running.
	 * \li true:  if a blacklisted program/process is running
	 * \li false: if not
	 */
	bool blacklisted_running;

	//! TQStringList with blacklisted programs for autosuspend
	TQStringList blacklist;
	
	//! time which must expire before emit signal for autosuspend
	unsigned long timeToInactivity;
	//! time of inactivity from the last check 
	unsigned long idleTime;
	//! time of inactivity from the last check 
	unsigned long blacklisted_running_last;
	//! if the XServer-has XScreenSaverExtension
	int has_XSC_Extension;
	
	//! TQTimer intervall for the \ref checkInactivity Timer
	/*!
	 * The time intervall to check for the current status and time of
	 * userinactivity. The timeslice is currently 30 sec.
	 */
	static const int CHECK_for_INACTIVITY = 10000;

	//! TQTimer for check inactivity
	/*!
	 * This timer is used to check the currently status and time of
	 * user inactivity on the X-Server. The timer interval is defined through
	 * \ref CHECK_for_INACTIVITY .
	 */
	TQTimer *checkInactivity;

	screen *display;  // No ownership here!!
	bool prev_screensaver_enabled;
	unsigned long prev_idle_time;
	unsigned long correction_value;

	// -------- FUNCTIONS ------------
	
	//! to check the user-inactivity on the XServer
	void checkXInactivity();
	//! to check for running blacklisted programs
	void checkBlacklisted();
	//! to monitor the values
	void check( bool recheck ); 
	//! to workaround a strange behavior of the XScreenSaver extension
	unsigned long workaroundCreepyXServer(XScreenSaverInfo *_mitInfo);

private slots:

	//! to monitor the values
	void check();
	//! to monitor the values
	void recheck();
	//! to get the PIDs of blacklisted programs/processes
	void getPIDs(TDEProcess *, char *, int);
	//! to get the signal if the command call is exited
	void getPIDsExited(TDEProcess *);
};

#endif