summaryrefslogtreecommitdiffstats
path: root/kmilo/thinkpad/thinkpad.h
blob: 27d86edb272519cf1dceb990f3d443456fce0aad (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
/*
   This file is part of the KDE project

   Copyright (c) 2004 Jonathan Riddell <[email protected]>

   Based on Demo kmilo service by George Staikos
   Copyright (c) 2003 George Staikos <[email protected]>

   And tpb by Markus Braun http://www.nongnu.org/tpb/
   Copyright (C) 2002,2003 Markus Braun <[email protected]>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library 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
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.

*/
#ifndef _THINKPAD_H_
#define _THINKPAD_H_

#include <fcntl.h>
#include <unistd.h>

#include <tdeapplication.h>
#include <dcopref.h>

#include "monitor.h"

namespace KMilo {


const int defaultVolumeStep = 14;

// all nvram toggle values are stored in bit 0
// all xevents toggle values are stored in bit 1
// xevent and apm toggles are not used, kept for compatibility with tpb
typedef struct {
	unsigned int thinkpad_toggle;     // ThinkPad button
	unsigned int zoom_toggle;         // zoom toggle
	unsigned int display_toggle;      // display toggle
	unsigned int home_toggle;         // Home button
	unsigned int search_toggle;       // Search button
	unsigned int mail_toggle;         // Mail button
	unsigned int favorites_toggle;    // Favorites button (xevent)
	unsigned int reload_toggle;       // Reload button (xevent)
	unsigned int abort_toggle;        // Abort button (xevent)
	unsigned int backward_toggle;     // Backward button (xevent)
	unsigned int forward_toggle;      // Forward button (xevent)
	unsigned int fn_toggle;           // Fn button (xevent)
	unsigned int thinklight_toggle;   // ThinkLight
	unsigned int hibernate_toggle;    // hibernation/suspend toggle
	unsigned int display_state;       // display state
	unsigned int expand_toggle;       // hv expansion state
	unsigned int brightness_level;    // brightness level
	unsigned int brightness_toggle;   // brightness toggle
	unsigned int volume_level;        // volume level
	unsigned int volume_toggle;       // volume toggle
	unsigned int mute_toggle;         // mute toggle
	unsigned int ac_state;            // ac connected (apm)
	unsigned int powermgt_ac;         // power management mode ac
	unsigned int powermgt_battery;    // power management mode battery
	unsigned int wireless_toggle;     // wireless lan toggle
	unsigned int bluetooth_toggle;    // bluetooth toggle
} thinkpad_state_struct;

/**
 * KMilo plugin for IBM Thinkpads
 * Requires read access of nvram: insmod nvram; mknod /dev/nvram c 10 144; chmod 664 /dev/nvram
 *
 * Models R31 and R30 do not have hardware mixers, other models
 * probably want a smaller volume change than thinkpad's default, for
 * this you need write access to nvram: chmod 666 /dev/nvram
 */
class ThinkPadMonitor : public Monitor {
	public:
		ThinkPadMonitor(TQObject *parent, const char *name, const TQStringList&);
		virtual ~ThinkPadMonitor();

		/**
		 * Reimplemented from KMilo::Monitor.
		 * Loads configuration, clears struct, sets volume if necessary.
		 */
		virtual bool init();

		/**
		 * Reimplemented from KMilo::Monitor.
		 * Called by KMilo, this checks the nvram and acts on any changes
		 */
		virtual DisplayType poll();

		/**
		 * Reimplemented from KMilo::Monitor.
		 * Called by KMilo if poll() returns a volume or brightness change.
		 * Returns the new volume or brightness percentage.
		 */
		virtual int progress() const;

		/**
		 * Reimplemented from KMilo::Monitor.
		 * Not used, we just set the message ourselves using _interface->displayText()
		 */
		virtual TQString message() const;
	protected:
		/**
		 * Reimplemented from KMilo::Monitor.
		 * Loads configuration from kmilorc
		 */
		virtual void reconfigure(TDEConfig*);
	private:
		/**
		 * get the current state from the nvram
		 */
		bool getNvramState(thinkpad_state_struct* thinkpad_state);

		/**
		 * get the current state from the nvram
		 */
		void setNvramVolume();

		/**
		 * set all values of thinkpad_state to zero
		 */
		void clearStruct(thinkpad_state_struct& thinkpad_state);

		/**
		 * Displays paramater message followed by 'on' or
		 * 'off' depending on state
		 */
		void showToggleMessage(TQString onMessage, TQString offMessage, bool state);

		/**
		 * Returned by progress()
		 */
		int m_progress;

		/**
		 * The file to read data from, default is /dev/nvram
		 */
		TQString m_nvramFile;

		/**
		 * Some thinkpads change volume in hardware, others we
		 * have to do it ourselves
		 */
		bool m_softwareVolume;

		/**
		 * Config variable determines if this kmilo service is run or not
		 */
		bool m_run;

		/**
		 * Amount to change volume by each time, default is 14
		 * (as builtin to thinkpads)
		 */
		int m_volumeStep;

		/**
		 * Thinkpad button
		 */
		TQString m_buttonThinkpad;

		/**
		 * Home button
		 */
		TQString m_buttonHome;

		/**
		 * Search button
		 */
		TQString m_buttonSearch;

		/**
		 * Mail button
		 */
		TQString m_buttonMail;

		/**
		 * Zoom button
		 */
		TQString m_buttonZoom;

		/**
		 * Used for changing the volume if m_softwareVolume is true
		 */
		void setVolume(int volume);
		DCOPRef* kmixClient;
		DCOPRef* kmixWindow;
		bool retrieveVolume();
		int m_volume, m_oldVolume;

		thinkpad_state_struct thinkpad_state;
		thinkpad_state_struct last_thinkpad_state;
};

} //close namespace

#endif