summaryrefslogtreecommitdiffstats
path: root/klaptopdaemon/laptop_daemon.h
blob: f5ba7677b11378795399f4a262a517406c37d445 (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
#ifndef LAPTOPDAEMON
#define LAPTOPDAEMON 1
/*
 * laptop_daemon.h
 * Copyright (C) 1999 Paul Campbell <[email protected]>
 *
 * This file contains the implementation of the main laptop battery monitoring daemon
 *
 * $Id$
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  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.
 */

#include "daemon_state.h"

#include <tqdir.h>
#include <unistd.h>
#include <time.h>
#include <tqmovie.h>
#include <tqptrlist.h>
#include <tqfileinfo.h>
#include <tqimage.h>

#include <kiconloader.h>
#include <kprocess.h>
//#include <kaudio.h>
#include <tqtooltip.h>

#include <X11/Xlib.h>
#include <X11/extensions/XTest.h>

#include <tqsocketnotifier.h>



#include <kdebug.h>
#include <tqthread.h>

#include "kpcmcia.h"

#include "daemondock.h"
#include "xautolock.h"
#include <kdedmodule.h>


class laptop_daemon;
class XWidget;

class ButtonThread : public TQThread {
public:
	ButtonThread() { quitting = 0; }
	void sethandle(laptop_daemon *h) { handle = h; }
	void quit() { quitting = 1; }				// make it quit
	void done() { while (!finished()) msleep(100); quitting = 0; }// wait 'till it's done
	virtual void run();
private:
	bool quitting;
	laptop_daemon *handle;
};

class laptop_dock;
class laptop_daemon: public KDEDModule
{
	Q_OBJECT
//	TQ_OBJECT
	K_DCOP
public:
    	laptop_daemon(const TQCString& obj);
    	~laptop_daemon();
        void 	setPollInterval(const int poll=60);
	void 	SetBrightness(bool blank, int v);	// routine to do it
	int	GetBrightness() { return brightness; }
	void    SetThrottle(TQString v);
	void    SetPerformance(TQString v);
	void	ButtonThreadInternals();
k_dcop:
	void	restart();
	void	quit();
signals:
        void 	signal_checkBattery();
protected:
	 void 	timerEvent(TQTimerEvent *);
protected slots:
	void 	checkBatteryNow();
	void 	timerDone();
	void	dock_quit();
        void    updatePCMCIA(int num);
	void 	sonyDataReceived();
	void	BackoffRestart();
	void	WakeCheck();
private:
	void 	haveBatteryLow(int t, const int num, const int type);
	int	calcBatteryTime(int percent, long time, bool restart);
	void 	start_monitor();
	void 	invokeStandby();
	void 	invokeSuspend();
	void 	invokeHibernate();
	void 	invokeShutdown();
	void 	invokeLogout();
	void	displayPixmap();
	void	setBlankSaver(bool);
        void setLoadAverage(bool enable, float value) {mLavEnabled=enable&&(value>=0.0); mLav=value;}

	laptop_dock *dock_widget;

	// Capability
	bool    hasAudio;
	//KAudio  audioServer;

	// General settings
public:
	int	val;
	int	powered;
	int	left;
	bool	x11Event(XEvent *event);
	bool	exists() { return s.exists; }
	TQString noBatteryIcon() { return s.noBatteryIcon; }
	TQString chargeIcon() { return s.chargeIcon; }
	TQString noChargeIcon() { return s.noChargeIcon; }
protected:
	int	triggered[2];

	int	oldval, oldexists, oldpowered, oldleft, knownFullyCharged;

	int	changed;

	int     oldTimer;
	bool	timer;		// autolock timer is active

	int	power_time;

        // PCMCIA related
        KPCMCIA *_pcmcia;

	// sony jog-bar support
	
	int  sony_fd;			// file desc form open /dev/sonypi
	Display *sony_disp;		// X display
	TQSocketNotifier *sony_notifier; // how we know data is waiting

	// brightness 
	
	int  brightness;		// actual brightness, -1 if not known

	bool lid_state;
	bool power_state;
	ButtonThread	buttonThread;


	//
	XAutoLock	autoLock;		// timer/UI maint
        float   mLav;
        bool    mLavEnabled;
	bool	need_wait;			// undo sleep stuff
	bool	saved_brightness, saved_throttle, saved_performance;
	int	saved_brightness_val;
	TQString saved_performance_val, saved_throttle_val;
	TQTimer  *wake_timer;		// the timer for the above running
	TQPoint	wakepos;		// the mouse pos at the beginning of time
	void	WakeUpAuto();
	TQTimer  *backoffTimer;		// backoff

	bool	power_button_off;			// imagined state of the power button
	bool 	button_bright_saved;			// saved button state
	int 	button_bright_val;
	bool	button_saved_performance;
	TQString button_saved_performance_val;
	bool 	button_saved_throttle;
	TQString button_saved_throttle_val;

	daemon_state	s;			// saved daemon state from config file

	XWidget 	*xwidget;
};
#endif