summaryrefslogtreecommitdiff
authorschurig <schurig>2004-09-10 12:18:17 (UTC)
committer schurig <schurig>2004-09-10 12:18:17 (UTC)
commit9d0ccc1c5ca687bc017b2b515a9d3a47e98ce521 (patch) (unidiff)
tree53927c6a19c69d54bb3d0e092ac57180bcb60222
parented70ec4945c7816ec6e899207ec8b99e20e10da5 (diff)
downloadopie-9d0ccc1c5ca687bc017b2b515a9d3a47e98ce521.zip
opie-9d0ccc1c5ca687bc017b2b515a9d3a47e98ce521.tar.gz
opie-9d0ccc1c5ca687bc017b2b515a9d3a47e98ce521.tar.bz2
added support for DEVFS
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/vmemo/vmemo.cpp10
-rw-r--r--core/applets/vtapplet/vt.cpp8
-rw-r--r--libopie/odevice.cpp4
-rw-r--r--libopie2/opiemm/osoundsystem.cpp5
-rw-r--r--library/qpeapplication.cpp16
5 files changed, 40 insertions, 3 deletions
diff --git a/core/applets/vmemo/vmemo.cpp b/core/applets/vmemo/vmemo.cpp
index e747a19..07ef15c 100644
--- a/core/applets/vmemo/vmemo.cpp
+++ b/core/applets/vmemo/vmemo.cpp
@@ -1,665 +1,669 @@
1/************************************************************************************ 1/************************************************************************************
2 ** 2 **
3 ** This file may be distributed and/or modified under the terms of the 3 ** This file may be distributed and/or modified under the terms of the
4 ** GNU General Public License version 2 as published by the Free Software 4 ** GNU General Public License version 2 as published by the Free Software
5 ** Foundation and appearing in the file LICENSE.GPL included in the 5 ** Foundation and appearing in the file LICENSE.GPL included in the
6 ** packaging of this file. 6 ** packaging of this file.
7 ** 7 **
8 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 8 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
9 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 9 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
10 ** 10 **
11 ************************************************************************************/ 11 ************************************************************************************/
12// copyright 2002 Jeremy Cowgar <jc@cowgar.com> 12// copyright 2002 Jeremy Cowgar <jc@cowgar.com>
13// copyright 2002 and 2003 L.J.Potter <ljp@llornkcor.com> 13// copyright 2002 and 2003 L.J.Potter <ljp@llornkcor.com>
14 14
15/* OPIE */ 15/* OPIE */
16#include <opie2/odebug.h> 16#include <opie2/odebug.h>
17using namespace Opie::Core; 17using namespace Opie::Core;
18 18
19extern "C" { 19extern "C" {
20#include "adpcm.h" 20#include "adpcm.h"
21} 21}
22 22
23#include <unistd.h> 23#include <unistd.h>
24#include <stdio.h> 24#include <stdio.h>
25#include <fcntl.h> 25#include <fcntl.h>
26#include <sys/ioctl.h> 26#include <sys/ioctl.h>
27#include <linux/soundcard.h> 27#include <linux/soundcard.h>
28 28
29#include <errno.h> 29#include <errno.h>
30 30
31typedef struct _waveheader { 31typedef struct _waveheader {
32 u_long main_chunk; /* 'RIFF' */ 32 u_long main_chunk; /* 'RIFF' */
33 u_long length; /* filelen */ 33 u_long length; /* filelen */
34 u_long chunk_type; /* 'WAVE' */ 34 u_long chunk_type; /* 'WAVE' */
35 u_long sub_chunk; /* 'fmt ' */ 35 u_long sub_chunk; /* 'fmt ' */
36 u_long sc_len; /* length of sub_chunk, =16 36 u_long sc_len; /* length of sub_chunk, =16
37 (chunckSize) format len */ 37 (chunckSize) format len */
38 u_short format; /* should be 1 for PCM-code (formatTag) */ 38 u_short format; /* should be 1 for PCM-code (formatTag) */
39 39
40 u_short modus; /* 1 Mono, 2 Stereo (channels) */ 40 u_short modus; /* 1 Mono, 2 Stereo (channels) */
41 u_long sample_fq; /* samples per second (samplesPerSecond) */ 41 u_long sample_fq; /* samples per second (samplesPerSecond) */
42 u_long byte_p_sec; /* avg bytes per second (avgBytePerSecond) */ 42 u_long byte_p_sec; /* avg bytes per second (avgBytePerSecond) */
43 u_short byte_p_spl; /* samplesize; 1 or 2 bytes (blockAlign) */ 43 u_short byte_p_spl; /* samplesize; 1 or 2 bytes (blockAlign) */
44 u_short bit_p_spl; /* 8, 12 or 16 bit (bitsPerSample) */ 44 u_short bit_p_spl; /* 8, 12 or 16 bit (bitsPerSample) */
45 45
46 u_long data_chunk; /* 'data' */ 46 u_long data_chunk; /* 'data' */
47 47
48 u_long data_length;/* samplecount */ 48 u_long data_length;/* samplecount */
49} WaveHeader; 49} WaveHeader;
50 50
51#define RIFF 0x46464952 51#define RIFF 0x46464952
52#define WAVE 0x45564157 52#define WAVE 0x45564157
53#define FMT 0x20746D66 53#define FMT 0x20746D66
54#define DATA 0x61746164 54#define DATA 0x61746164
55#define PCM_CODE 1 55#define PCM_CODE 1
56#define WAVE_MONO 1 56#define WAVE_MONO 1
57#define WAVE_STEREO 2 57#define WAVE_STEREO 2
58 58
59struct adpcm_state encoder_state; 59struct adpcm_state encoder_state;
60//struct adpcm_state decoder_state; 60//struct adpcm_state decoder_state;
61 61
62#define WAVE_FORMAT_DVI_ADPCM (0x0011) 62#define WAVE_FORMAT_DVI_ADPCM (0x0011)
63#define WAVE_FORMAT_PCM (0x0001) 63#define WAVE_FORMAT_PCM (0x0001)
64 64
65 65
66#include "vmemo.h" 66#include "vmemo.h"
67 67
68#include <opie2/otaskbarapplet.h> 68#include <opie2/otaskbarapplet.h>
69#include <qpe/qpeapplication.h> 69#include <qpe/qpeapplication.h>
70#include <qpe/config.h> 70#include <qpe/config.h>
71 71
72#include <qpainter.h> 72#include <qpainter.h>
73#include <qmessagebox.h> 73#include <qmessagebox.h>
74 74
75int seq = 0; 75int seq = 0;
76 76
77/* XPM */ 77/* XPM */
78static char * vmemo_xpm[] = { 78static char * vmemo_xpm[] = {
79 "16 16 102 2", 79 "16 16 102 2",
80 " c None", 80 " c None",
81 ". c #60636A", 81 ". c #60636A",
82 "+ c #6E6E72", 82 "+ c #6E6E72",
83 "@ c #68696E", 83 "@ c #68696E",
84 "# c #4D525C", 84 "# c #4D525C",
85 "$ c #6B6C70", 85 "$ c #6B6C70",
86 "% c #E3E3E8", 86 "% c #E3E3E8",
87 "& c #EEEEF2", 87 "& c #EEEEF2",
88 "* c #EAEAEF", 88 "* c #EAEAEF",
89 "= c #CACAD0", 89 "= c #CACAD0",
90 "- c #474A51", 90 "- c #474A51",
91 "; c #171819", 91 "; c #171819",
92 "> c #9B9B9F", 92 "> c #9B9B9F",
93 ", c #EBEBF0", 93 ", c #EBEBF0",
94 "' c #F4F4F7", 94 "' c #F4F4F7",
95 ") c #F1F1F5", 95 ") c #F1F1F5",
96 "! c #DEDEE4", 96 "! c #DEDEE4",
97 "~ c #57575C", 97 "~ c #57575C",
98 "{ c #010101", 98 "{ c #010101",
99 "] c #A2A2A6", 99 "] c #A2A2A6",
100 "^ c #747477", 100 "^ c #747477",
101 "/ c #B5B5B8", 101 "/ c #B5B5B8",
102 "( c #AEAEB2", 102 "( c #AEAEB2",
103 "_ c #69696D", 103 "_ c #69696D",
104 ": c #525256", 104 ": c #525256",
105 "< c #181C24", 105 "< c #181C24",
106 "[ c #97979B", 106 "[ c #97979B",
107 "} c #A7A7AC", 107 "} c #A7A7AC",
108 "| c #B0B0B4", 108 "| c #B0B0B4",
109 "1 c #C8C8D1", 109 "1 c #C8C8D1",
110 "2 c #75757B", 110 "2 c #75757B",
111 "3 c #46464A", 111 "3 c #46464A",
112 "4 c #494A4F", 112 "4 c #494A4F",
113 "5 c #323234", 113 "5 c #323234",
114 "6 c #909095", 114 "6 c #909095",
115 "7 c #39393B", 115 "7 c #39393B",
116 "8 c #757578", 116 "8 c #757578",
117 "9 c #87878E", 117 "9 c #87878E",
118 "0 c #222224", 118 "0 c #222224",
119 "a c #414144", 119 "a c #414144",
120 "b c #6A6A6E", 120 "b c #6A6A6E",
121 "c c #020C16", 121 "c c #020C16",
122 "d c #6B6B6F", 122 "d c #6B6B6F",
123 "e c #68686D", 123 "e c #68686D",
124 "f c #5B5B60", 124 "f c #5B5B60",
125 "g c #8A8A8F", 125 "g c #8A8A8F",
126 "h c #6B6B6E", 126 "h c #6B6B6E",
127 "i c #ADADB2", 127 "i c #ADADB2",
128 "j c #828289", 128 "j c #828289",
129 "k c #3E3E41", 129 "k c #3E3E41",
130 "l c #CFCFD7", 130 "l c #CFCFD7",
131 "m c #4C4C50", 131 "m c #4C4C50",
132 "n c #000000", 132 "n c #000000",
133 "o c #66666A", 133 "o c #66666A",
134 "p c #505054", 134 "p c #505054",
135 "q c #838388", 135 "q c #838388",
136 "r c #A1A1A7", 136 "r c #A1A1A7",
137 "s c #A9A9AE", 137 "s c #A9A9AE",
138 "t c #A8A8B0", 138 "t c #A8A8B0",
139 "u c #5E5E63", 139 "u c #5E5E63",
140 "v c #3A3A3E", 140 "v c #3A3A3E",
141 "w c #BDBDC6", 141 "w c #BDBDC6",
142 "x c #59595E", 142 "x c #59595E",
143 "y c #76767C", 143 "y c #76767C",
144 "z c #373738", 144 "z c #373738",
145 "A c #717174", 145 "A c #717174",
146 "B c #727278", 146 "B c #727278",
147 "C c #1C1C1E", 147 "C c #1C1C1E",
148 "D c #3C3C3F", 148 "D c #3C3C3F",
149 "E c #ADADB6", 149 "E c #ADADB6",
150 "F c #54555A", 150 "F c #54555A",
151 "G c #8B8C94", 151 "G c #8B8C94",
152 "H c #5A5A5F", 152 "H c #5A5A5F",
153 "I c #BBBBC3", 153 "I c #BBBBC3",
154 "J c #C4C4CB", 154 "J c #C4C4CB",
155 "K c #909098", 155 "K c #909098",
156 "L c #737379", 156 "L c #737379",
157 "M c #343437", 157 "M c #343437",
158 "N c #8F8F98", 158 "N c #8F8F98",
159 "O c #000407", 159 "O c #000407",
160 "P c #2D3137", 160 "P c #2D3137",
161 "Q c #B0B1BC", 161 "Q c #B0B1BC",
162 "R c #3B3C40", 162 "R c #3B3C40",
163 "S c #6E6E74", 163 "S c #6E6E74",
164 "T c #95959C", 164 "T c #95959C",
165 "U c #74747A", 165 "U c #74747A",
166 "V c #1D1D1E", 166 "V c #1D1D1E",
167 "W c #91929A", 167 "W c #91929A",
168 "X c #42444A", 168 "X c #42444A",
169 "Y c #22282E", 169 "Y c #22282E",
170 "Z c #B0B2BC", 170 "Z c #B0B2BC",
171 "` c #898A90", 171 "` c #898A90",
172 " . c #65656A", 172 " . c #65656A",
173 ".. c #999AA2", 173 ".. c #999AA2",
174 "+. c #52535A", 174 "+. c #52535A",
175 "@. c #151B21", 175 "@. c #151B21",
176 "#. c #515257", 176 "#. c #515257",
177 "$. c #B5B5BE", 177 "$. c #B5B5BE",
178 "%. c #616167", 178 "%. c #616167",
179 "&. c #1A1D22", 179 "&. c #1A1D22",
180 "*. c #000713", 180 "*. c #000713",
181 "=. c #1F1F21", 181 "=. c #1F1F21",
182 " ", 182 " ",
183 " . + @ # ", 183 " . + @ # ",
184 " $ % & * = - ", 184 " $ % & * = - ",
185 " ; > , ' ) ! ~ ", 185 " ; > , ' ) ! ~ ",
186 " { ] ^ / ( _ : ", 186 " { ] ^ / ( _ : ",
187 " < [ } | 1 2 3 ", 187 " < [ } | 1 2 3 ",
188 " 4 5 6 7 8 9 0 a b c ", 188 " 4 5 6 7 8 9 0 a b c ",
189 " d e f g h i j 3 k l m n ", 189 " d e f g h i j 3 k l m n ",
190 " o p q r s t u v w n ", 190 " o p q r s t u v w n ",
191 " o x y z A B C D E n ", 191 " o x y z A B C D E n ",
192 " F G H I J K L M N O ", 192 " F G H I J K L M N O ",
193 " P Q R S T U V W X ", 193 " P Q R S T U V W X ",
194 " Y Z ` b ...+. ", 194 " Y Z ` b ...+. ",
195 " @.#.$.%.&. ", 195 " @.#.$.%.&. ",
196 " *.B =. ", 196 " *.B =. ",
197 " n n n n n n n n n "}; 197 " n n n n n n n n n "};
198 198
199 199
200using namespace Opie::Ui; 200using namespace Opie::Ui;
201VMemo::VMemo( QWidget *parent, const char *_name ) 201VMemo::VMemo( QWidget *parent, const char *_name )
202 : QWidget( parent, _name ) { 202 : QWidget( parent, _name ) {
203 setFixedHeight( 18 ); 203 setFixedHeight( 18 );
204 setFixedWidth( 14 ); 204 setFixedWidth( 14 );
205 205
206 t_timer = new QTimer( this ); 206 t_timer = new QTimer( this );
207 connect( t_timer, SIGNAL( timeout() ), SLOT( timerBreak() ) ); 207 connect( t_timer, SIGNAL( timeout() ), SLOT( timerBreak() ) );
208 208
209 Config vmCfg("Vmemo"); 209 Config vmCfg("Vmemo");
210 vmCfg.setGroup("Defaults"); 210 vmCfg.setGroup("Defaults");
211 int toggleKey = setToggleButton(vmCfg.readNumEntry("toggleKey", -1)); 211 int toggleKey = setToggleButton(vmCfg.readNumEntry("toggleKey", -1));
212 useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0); 212 useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0);
213 213
214 odebug << "toggleKey " << toggleKey << "" << oendl; 214 odebug << "toggleKey " << toggleKey << "" << oendl;
215 215
216// if ( QFile::exists ( "/dev/sharp_buz" ) || QFile::exists ( "/dev/sharp_led" )) 216// if ( QFile::exists ( "/dev/sharp_buz" ) || QFile::exists ( "/dev/sharp_led" ))
217// systemZaurus=TRUE; 217// systemZaurus=TRUE;
218// else 218// else
219 systemZaurus = FALSE; 219 systemZaurus = FALSE;
220 220
221 myChannel = new QCopChannel( "QPE/VMemo", this ); 221 myChannel = new QCopChannel( "QPE/VMemo", this );
222 connect( myChannel, SIGNAL(received(const QCString&,const QByteArray&)), 222 connect( myChannel, SIGNAL(received(const QCString&,const QByteArray&)),
223 this, SLOT(receive(const QCString&,const QByteArray&)) ); 223 this, SLOT(receive(const QCString&,const QByteArray&)) );
224 224
225 if( toggleKey != -1 ) { 225 if( toggleKey != -1 ) {
226 odebug << "Register key " << toggleKey << "" << oendl; 226 odebug << "Register key " << toggleKey << "" << oendl;
227 QCopEnvelope e("QPE/Launcher", "keyRegister(int,QCString,QCString)"); 227 QCopEnvelope e("QPE/Launcher", "keyRegister(int,QCString,QCString)");
228 // e << 4096; // Key_Escape 228 // e << 4096; // Key_Escape
229 // e << Key_F5; //4148 229 // e << Key_F5; //4148
230 e << toggleKey; 230 e << toggleKey;
231 e << QString("QPE/VMemo"); 231 e << QString("QPE/VMemo");
232 e << QString("toggleRecord()"); 232 e << QString("toggleRecord()");
233 } 233 }
234 if(toggleKey == 1) 234 if(toggleKey == 1)
235 usingIcon = TRUE; 235 usingIcon = TRUE;
236 else 236 else
237 usingIcon = FALSE; 237 usingIcon = FALSE;
238// if( vmCfg.readNumEntry("hideIcon",0) == 1) 238// if( vmCfg.readNumEntry("hideIcon",0) == 1)
239 if (!usingIcon) 239 if (!usingIcon)
240 hide(); 240 hide();
241 recording = FALSE; 241 recording = FALSE;
242 // } 242 // }
243} 243}
244 244
245VMemo::~VMemo() { 245VMemo::~VMemo() {
246} 246}
247 247
248int VMemo::position() 248int VMemo::position()
249{ 249{
250 return 6; 250 return 6;
251} 251}
252 252
253void VMemo::receive( const QCString &msg, const QByteArray &data ) { 253void VMemo::receive( const QCString &msg, const QByteArray &data ) {
254 odebug << "Vmemo receive" << oendl; 254 odebug << "Vmemo receive" << oendl;
255 QDataStream stream( data, IO_ReadOnly ); 255 QDataStream stream( data, IO_ReadOnly );
256 256
257 if (msg == "toggleRecord()") { 257 if (msg == "toggleRecord()") {
258 if (recording) { 258 if (recording) {
259 fromToggle = TRUE; 259 fromToggle = TRUE;
260 stopRecording(); 260 stopRecording();
261 } else { 261 } else {
262 fromToggle = TRUE; 262 fromToggle = TRUE;
263 startRecording(); 263 startRecording();
264 } 264 }
265 } 265 }
266} 266}
267 267
268void VMemo::paintEvent( QPaintEvent* ) { 268void VMemo::paintEvent( QPaintEvent* ) {
269 QPainter p(this); 269 QPainter p(this);
270 p.drawPixmap( 0, 1,( const char** ) vmemo_xpm ); 270 p.drawPixmap( 0, 1,( const char** ) vmemo_xpm );
271} 271}
272 272
273void VMemo::mousePressEvent( QMouseEvent * /*me*/) { 273void VMemo::mousePressEvent( QMouseEvent * /*me*/) {
274 /* No mousePress/mouseRelease recording on the iPAQ. The REC button on the iPAQ calls these functions 274 /* No mousePress/mouseRelease recording on the iPAQ. The REC button on the iPAQ calls these functions
275 mousePressEvent and mouseReleaseEvent with a NULL parameter. */ 275 mousePressEvent and mouseReleaseEvent with a NULL parameter. */
276 276
277// if (!systemZaurus && me != NULL) 277// if (!systemZaurus && me != NULL)
278// return; 278// return;
279// } 279// }
280 280
281 if(!recording) 281 if(!recording)
282 startRecording(); 282 startRecording();
283 else 283 else
284 stopRecording(); 284 stopRecording();
285} 285}
286 286
287void VMemo::mouseReleaseEvent( QMouseEvent * ) { 287void VMemo::mouseReleaseEvent( QMouseEvent * ) {
288} 288}
289 289
290bool VMemo::startRecording() { 290bool VMemo::startRecording() {
291 Config config( "Vmemo" ); 291 Config config( "Vmemo" );
292 config.setGroup( "System" ); 292 config.setGroup( "System" );
293 293
294 useAlerts = config.readBoolEntry("Alert",1); 294 useAlerts = config.readBoolEntry("Alert",1);
295 if(useAlerts) { 295 if(useAlerts) {
296 296
297 msgLabel = new QLabel( 0, "alertLabel" ); 297 msgLabel = new QLabel( 0, "alertLabel" );
298 msgLabel->setText("<B><P><font size=+2>VMemo-Recording</font></B>"); 298 msgLabel->setText("<B><P><font size=+2>VMemo-Recording</font></B>");
299 msgLabel->show(); 299 msgLabel->show();
300 } 300 }
301 301
302 odebug << "Start recording engines" << oendl; 302 odebug << "Start recording engines" << oendl;
303 recording = TRUE; 303 recording = TRUE;
304 304
305 if (openDSP() == -1) { 305 if (openDSP() == -1) {
306 recording = FALSE; 306 recording = FALSE;
307 return FALSE; 307 return FALSE;
308 } 308 }
309 309
310 config.setGroup("Defaults"); 310 config.setGroup("Defaults");
311 311
312 date = TimeString::dateString( QDateTime::currentDateTime(),false,true); 312 date = TimeString::dateString( QDateTime::currentDateTime(),false,true);
313 date.replace(QRegExp("'"),""); 313 date.replace(QRegExp("'"),"");
314 date.replace(QRegExp(" "),"_"); 314 date.replace(QRegExp(" "),"_");
315 date.replace(QRegExp(":"),"-"); 315 date.replace(QRegExp(":"),"-");
316 date.replace(QRegExp(","),""); 316 date.replace(QRegExp(","),"");
317 317
318 QString fName; 318 QString fName;
319 config.setGroup( "System" ); 319 config.setGroup( "System" );
320 fName = QPEApplication::documentDir() ; 320 fName = QPEApplication::documentDir() ;
321 fileName = config.readEntry("RecLocation", fName); 321 fileName = config.readEntry("RecLocation", fName);
322 322
323 int s; 323 int s;
324 s=fileName.find(':'); 324 s=fileName.find(':');
325 if(s) 325 if(s)
326 fileName=fileName.right(fileName.length()-s-2); 326 fileName=fileName.right(fileName.length()-s-2);
327 odebug << "pathname will be "+fileName << oendl; 327 odebug << "pathname will be "+fileName << oendl;
328 328
329 if( fileName.left(1).find('/') == -1) 329 if( fileName.left(1).find('/') == -1)
330 fileName="/"+fileName; 330 fileName="/"+fileName;
331 if( fileName.right(1).find('/') == -1) 331 if( fileName.right(1).find('/') == -1)
332 fileName+="/"; 332 fileName+="/";
333 fName = "vm_"+ date + ".wav"; 333 fName = "vm_"+ date + ".wav";
334 334
335 fileName+=fName; 335 fileName+=fName;
336 odebug << "filename is " + fileName << oendl; 336 odebug << "filename is " + fileName << oendl;
337// open tmp file here 337// open tmp file here
338 char *pointer; 338 char *pointer;
339 pointer=tmpnam(NULL); 339 pointer=tmpnam(NULL);
340 odebug << "Opening tmp file " << pointer << "" << oendl; 340 odebug << "Opening tmp file " << pointer << "" << oendl;
341 341
342 if(openWAV(pointer ) == -1) { 342 if(openWAV(pointer ) == -1) {
343 343
344 QString err("Could not open the temp file\n"); 344 QString err("Could not open the temp file\n");
345 err += fileName; 345 err += fileName;
346 QMessageBox::critical(0, "vmemo", err, "Abort"); 346 QMessageBox::critical(0, "vmemo", err, "Abort");
347 ::close(dsp); 347 ::close(dsp);
348 return FALSE; 348 return FALSE;
349 } 349 }
350 if( record() ) { 350 if( record() ) {
351 351
352 QString cmd; 352 QString cmd;
353 if( fileName.find(".wav",0,TRUE) == -1) 353 if( fileName.find(".wav",0,TRUE) == -1)
354 fileName += ".wav"; 354 fileName += ".wav";
355 355
356 cmd.sprintf("mv %s "+fileName, pointer); 356 cmd.sprintf("mv %s "+fileName, pointer);
357// move tmp file to regular file here 357// move tmp file to regular file here
358 358
359 system(cmd.latin1()); 359 system(cmd.latin1());
360 360
361 QArray<int> cats(1); 361 QArray<int> cats(1);
362 cats[0] = config.readNumEntry("Category", 0); 362 cats[0] = config.readNumEntry("Category", 0);
363 363
364 QString dlName("vm_"); 364 QString dlName("vm_");
365 dlName += date; 365 dlName += date;
366 DocLnk l; 366 DocLnk l;
367 l.setFile(fileName); 367 l.setFile(fileName);
368 l.setName(dlName); 368 l.setName(dlName);
369 l.setType("audio/x-wav"); 369 l.setType("audio/x-wav");
370 l.setCategories(cats); 370 l.setCategories(cats);
371 l.writeLink(); 371 l.writeLink();
372 return TRUE; 372 return TRUE;
373 } else 373 } else
374 return FALSE; 374 return FALSE;
375 375
376} 376}
377 377
378void VMemo::stopRecording() { 378void VMemo::stopRecording() {
379// show(); 379// show();
380 odebug << "Stopped recording" << oendl; 380 odebug << "Stopped recording" << oendl;
381 recording = FALSE; 381 recording = FALSE;
382 if(useAlerts) { 382 if(useAlerts) {
383 msgLabel->close(); 383 msgLabel->close();
384 msgLabel=0; 384 msgLabel=0;
385 delete msgLabel; 385 delete msgLabel;
386 } 386 }
387 t_timer->stop(); 387 t_timer->stop();
388 Config cfg("Vmemo"); 388 Config cfg("Vmemo");
389 cfg.setGroup("Defaults"); 389 cfg.setGroup("Defaults");
390// if( cfg.readNumEntry("hideIcon",0) == 1 ) 390// if( cfg.readNumEntry("hideIcon",0) == 1 )
391// hide(); 391// hide();
392} 392}
393 393
394int VMemo::openDSP() { 394int VMemo::openDSP() {
395 Config cfg("Vmemo"); 395 Config cfg("Vmemo");
396 cfg.setGroup("Record"); 396 cfg.setGroup("Record");
397 397
398 speed = cfg.readNumEntry("SampleRate", 22050); 398 speed = cfg.readNumEntry("SampleRate", 22050);
399 channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1) 399 channels = cfg.readNumEntry("Stereo", 1) ? 2 : 1; // 1 = stereo(2), 0 = mono(1)
400 if (cfg.readNumEntry("SixteenBit", 1)==1) { 400 if (cfg.readNumEntry("SixteenBit", 1)==1) {
401 format = AFMT_S16_LE; 401 format = AFMT_S16_LE;
402 resolution = 16; 402 resolution = 16;
403 } else { 403 } else {
404 format = AFMT_U8; 404 format = AFMT_U8;
405 resolution = 8; 405 resolution = 8;
406 } 406 }
407 407
408 odebug << "samplerate: " << speed << ", channels " << channels << ", resolution " << resolution << "" << oendl; 408 odebug << "samplerate: " << speed << ", channels " << channels << ", resolution " << resolution << "" << oendl;
409 409
410 if(systemZaurus) { 410 if(systemZaurus) {
411 dsp = open("/dev/dsp1", O_RDONLY); //Zaurus needs /dev/dsp1 411 dsp = open("/dev/dsp1", O_RDONLY); //Zaurus needs /dev/dsp1
412 channels=1; //zaurus has one input channel 412 channels=1; //zaurus has one input channel
413 } else { 413 } else {
414#ifdef QT_QWS_DEVFS
415 dsp = open("/dev/sound/dsp", O_RDONLY);
416#else
414 dsp = open("/dev/dsp", O_RDONLY); 417 dsp = open("/dev/dsp", O_RDONLY);
418#endif
415 } 419 }
416 420
417 if(dsp == -1) { 421 if (dsp == -1) {
418 msgLabel->close(); 422 msgLabel->close();
419 msgLabel=0; 423 msgLabel=0;
420 delete msgLabel; 424 delete msgLabel;
421 425
422 perror("open(\"/dev/dsp\")"); 426 perror("open(\"/dev/dsp\")");
423 errorMsg="open(\"/dev/dsp\")\n "+(QString)strerror(errno); 427 errorMsg="open(\"/dev/dsp\")\n "+(QString)strerror(errno);
424 QMessageBox::critical(0, "vmemo", errorMsg, "Abort"); 428 QMessageBox::critical(0, "vmemo", errorMsg, "Abort");
425 return -1; 429 return -1;
426 } 430 }
427 431
428 if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) { 432 if(ioctl(dsp, SNDCTL_DSP_SETFMT , &format)==-1) {
429 perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); 433 perror("ioctl(\"SNDCTL_DSP_SETFMT\")");
430 return -1; 434 return -1;
431 } 435 }
432 if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) { 436 if(ioctl(dsp, SNDCTL_DSP_CHANNELS , &channels)==-1) {
433 perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); 437 perror("ioctl(\"SNDCTL_DSP_CHANNELS\")");
434 return -1; 438 return -1;
435 } 439 }
436 if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) { 440 if(ioctl(dsp, SNDCTL_DSP_SPEED , &speed)==-1) {
437 perror("ioctl(\"SNDCTL_DSP_SPEED\")"); 441 perror("ioctl(\"SNDCTL_DSP_SPEED\")");
438 return -1; 442 return -1;
439 } 443 }
440 if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) { 444 if(ioctl(dsp, SOUND_PCM_READ_RATE , &rate)==-1) {
441 perror("ioctl(\"SOUND_PCM_READ_RATE\")"); 445 perror("ioctl(\"SOUND_PCM_READ_RATE\")");
442 return -1; 446 return -1;
443 } 447 }
444 448
445 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; //mute 449 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; //mute
446 450
447 return 1; 451 return 1;
448} 452}
449 453
450int VMemo::openWAV(const char *filename) { 454int VMemo::openWAV(const char *filename) {
451 track.setName(filename); 455 track.setName(filename);
452 if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) { 456 if(!track.open(IO_WriteOnly|IO_Truncate|IO_Raw)) {
453 errorMsg=filename; 457 errorMsg=filename;
454 return -1; 458 return -1;
455 } 459 }
456 460
457 wav=track.handle(); 461 wav=track.handle();
458 Config vmCfg("Vmemo"); 462 Config vmCfg("Vmemo");
459 vmCfg.setGroup("Defaults"); 463 vmCfg.setGroup("Defaults");
460 useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0); 464 useADPCM = vmCfg.readBoolEntry("use_ADPCM", 0);
461 465
462 WaveHeader wh; 466 WaveHeader wh;
463 467
464 wh.main_chunk = RIFF; 468 wh.main_chunk = RIFF;
465 wh.length=0; 469 wh.length=0;
466 wh.chunk_type = WAVE; 470 wh.chunk_type = WAVE;
467 wh.sub_chunk = FMT; 471 wh.sub_chunk = FMT;
468 wh.sc_len = 16; 472 wh.sc_len = 16;
469 if(useADPCM) 473 if(useADPCM)
470 wh.format = WAVE_FORMAT_DVI_ADPCM;//PCM_CODE; 474 wh.format = WAVE_FORMAT_DVI_ADPCM;//PCM_CODE;
471 else 475 else
472 wh.format = PCM_CODE; 476 wh.format = PCM_CODE;
473 wh.modus = channels; 477 wh.modus = channels;
474 wh.sample_fq = speed; 478 wh.sample_fq = speed;
475 wh.byte_p_sec = speed * channels * resolution/8; 479 wh.byte_p_sec = speed * channels * resolution/8;
476 wh.byte_p_spl = channels * (resolution / 8); 480 wh.byte_p_spl = channels * (resolution / 8);
477 wh.bit_p_spl = resolution; 481 wh.bit_p_spl = resolution;
478 wh.data_chunk = DATA; 482 wh.data_chunk = DATA;
479 wh.data_length= 0; 483 wh.data_length= 0;
480 // odebug << "Write header channels " << wh.modus << ", speed " << wh.sample_fq << ", b/s " 484 // odebug << "Write header channels " << wh.modus << ", speed " << wh.sample_fq << ", b/s "
481 // << wh.byte_p_sec << ", blockalign " << wh.byte_p_spl << ", bitrate " << wh.bit_p_spl << oendl; 485 // << wh.byte_p_sec << ", blockalign " << wh.byte_p_spl << ", bitrate " << wh.bit_p_spl << oendl;
482 write (wav, &wh, sizeof(WaveHeader)); 486 write (wav, &wh, sizeof(WaveHeader));
483 487
484 return 1; 488 return 1;
485} 489}
486 490
487bool VMemo::record() { 491bool VMemo::record() {
488 length = 0; 492 length = 0;
489 int bytesWritten = 0; 493 int bytesWritten = 0;
490 int result = 0; 494 int result = 0;
491 int value = 0; 495 int value = 0;
492 496
493 QString msg; 497 QString msg;
494 msg.sprintf("Recording format %d", format); 498 msg.sprintf("Recording format %d", format);
495 odebug << msg << oendl; 499 odebug << msg << oendl;
496 500
497 Config config("Vmemo"); 501 Config config("Vmemo");
498 config.setGroup("Record"); 502 config.setGroup("Record");
499 int sRate = config.readNumEntry("SizeLimit", 30); 503 int sRate = config.readNumEntry("SizeLimit", 30);
500 odebug << "VMEMO rate" << sRate << oendl; 504 odebug << "VMEMO rate" << sRate << oendl;
501 505
502 if(sRate > 0) { 506 if(sRate > 0) {
503 t_timer->start( sRate * 1000+1000, TRUE); 507 t_timer->start( sRate * 1000+1000, TRUE);
504 } 508 }
505 509
506 msg.sprintf("Recording format other"); 510 msg.sprintf("Recording format other");
507 odebug << msg << oendl; 511 odebug << msg << oendl;
508 512
509 config.setGroup("Defaults"); 513 config.setGroup("Defaults");
510 useADPCM = config.readBoolEntry("use_ADPCM", 0); 514 useADPCM = config.readBoolEntry("use_ADPCM", 0);
511 515
512 int bufsize = config.readNumEntry("BufferSize",1024); 516 int bufsize = config.readNumEntry("BufferSize",1024);
513 unsigned short sound[bufsize]; //, monoBuffer[bufsize]; 517 unsigned short sound[bufsize]; //, monoBuffer[bufsize];
514 char abuf[bufsize / 2]; 518 char abuf[bufsize / 2];
515 short sbuf[bufsize]; 519 short sbuf[bufsize];
516 odebug << "ready to record"<< oendl; 520 odebug << "ready to record"<< oendl;
517 if(useADPCM) { 521 if(useADPCM) {
518 odebug << "usr ADPCM" << oendl; 522 odebug << "usr ADPCM" << oendl;
519 523
520 while(recording) { 524 while(recording) {
521 result = ::read(dsp, sbuf, bufsize); // adpcm read 525 result = ::read(dsp, sbuf, bufsize); // adpcm read
522 if( result <= 0) { 526 if( result <= 0) {
523 perror("recording error "); 527 perror("recording error ");
524 QMessageBox::message(tr("Note"),tr("error recording")); 528 QMessageBox::message(tr("Note"),tr("error recording"));
525 recording = FALSE; 529 recording = FALSE;
526 break; 530 break;
527 return FALSE; 531 return FALSE;
528 } 532 }
529 adpcm_coder( sbuf, abuf, result/2, &encoder_state); 533 adpcm_coder( sbuf, abuf, result/2, &encoder_state);
530 bytesWritten = ::write(wav, abuf, result/4); // adpcm write 534 bytesWritten = ::write(wav, abuf, result/4); // adpcm write
531 length += bytesWritten; 535 length += bytesWritten;
532 536
533 if(length < 0) { 537 if(length < 0) {
534 recording = false; 538 recording = false;
535 perror("dev/dsp's is a lookin' messy"); 539 perror("dev/dsp's is a lookin' messy");
536 QMessageBox::message("Vmemo","Error writing to file\n"+ fileName); 540 QMessageBox::message("Vmemo","Error writing to file\n"+ fileName);
537 break; 541 break;
538 return FALSE; 542 return FALSE;
539 } 543 }
540 printf("%d\r", length); 544 printf("%d\r", length);
541 fflush(stdout); 545 fflush(stdout);
542 qApp->processEvents(); 546 qApp->processEvents();
543 } 547 }
544 } else { 548 } else {
545 odebug << "use regular wav" << oendl; 549 odebug << "use regular wav" << oendl;
546 while(recording) { 550 while(recording) {
547 result = ::read(dsp, sound, bufsize); // read 551 result = ::read(dsp, sound, bufsize); // read
548 if( result <= 0) { 552 if( result <= 0) {
549 perror("recording error "); 553 perror("recording error ");
550 QMessageBox::message(tr("Note"),tr("error recording")); 554 QMessageBox::message(tr("Note"),tr("error recording"));
551 recording = FALSE; 555 recording = FALSE;
552 break; 556 break;
553 return FALSE; 557 return FALSE;
554 } 558 }
555 559
556 bytesWritten = ::write(wav, sound, result); // write 560 bytesWritten = ::write(wav, sound, result); // write
557 length += bytesWritten; 561 length += bytesWritten;
558 562
559 if(length < 0) { 563 if(length < 0) {
560 recording = false; 564 recording = false;
561 perror("dev/dsp's is a lookin' messy"); 565 perror("dev/dsp's is a lookin' messy");
562 QMessageBox::message("Vmemo","Error writing to file\n"+ fileName); 566 QMessageBox::message("Vmemo","Error writing to file\n"+ fileName);
563 break; 567 break;
564 return FALSE; 568 return FALSE;
565 } 569 }
566// printf("%d\r", length); 570// printf("%d\r", length);
567// fflush(stdout); 571// fflush(stdout);
568 qApp->processEvents(); 572 qApp->processEvents();
569 } 573 }
570 // odebug << "result is " << result << oendl; 574 // odebug << "result is " << result << oendl;
571 } 575 }
572 odebug << "file has length of " << length << " lasting " << (( length / speed) / channels) / 2 << " seconds" << oendl; 576 odebug << "file has length of " << length << " lasting " << (( length / speed) / channels) / 2 << " seconds" << oendl;
573 577
574 value = length + 36; 578 value = length + 36;
575 579
576 lseek(wav, 4, SEEK_SET); 580 lseek(wav, 4, SEEK_SET);
577 write(wav, &value, 4); 581 write(wav, &value, 4);
578 lseek(wav, 40, SEEK_SET); 582 lseek(wav, 40, SEEK_SET);
579 583
580 write(wav, &length, 4); 584 write(wav, &length, 4);
581 585
582 track.close(); 586 track.close();
583 odebug << "Track closed" << oendl; 587 odebug << "Track closed" << oendl;
584 588
585 if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1) 589 if( ioctl( dsp, SNDCTL_DSP_RESET,0) == -1)
586 perror("ioctl(\"SNDCTL_DSP_RESET\")"); 590 perror("ioctl(\"SNDCTL_DSP_RESET\")");
587 591
588 ::close(dsp); 592 ::close(dsp);
589 593
590 Config cfgO("OpieRec"); 594 Config cfgO("OpieRec");
591 cfgO.setGroup("Sounds"); 595 cfgO.setGroup("Sounds");
592 596
593 int nFiles = cfgO.readNumEntry( "NumberofFiles",0); 597 int nFiles = cfgO.readNumEntry( "NumberofFiles",0);
594 598
595 QString currentFileName = fileName; 599 QString currentFileName = fileName;
596 QString currentFile = "vm_"+ date; 600 QString currentFile = "vm_"+ date;
597 601
598 float numberOfRecordedSeconds = (float) length / (float)speed * (float)2; 602 float numberOfRecordedSeconds = (float) length / (float)speed * (float)2;
599 603
600 cfgO.writeEntry( "NumberofFiles", nFiles + 1); 604 cfgO.writeEntry( "NumberofFiles", nFiles + 1);
601 cfgO.writeEntry( QString::number( nFiles + 1), currentFile); 605 cfgO.writeEntry( QString::number( nFiles + 1), currentFile);
602 cfgO.writeEntry( currentFile, currentFileName); 606 cfgO.writeEntry( currentFile, currentFileName);
603 607
604 QString time; 608 QString time;
605 time.sprintf("%.2f", numberOfRecordedSeconds); 609 time.sprintf("%.2f", numberOfRecordedSeconds);
606 cfgO.writeEntry( currentFileName, time ); 610 cfgO.writeEntry( currentFileName, time );
607 // odebug << "writing config numberOfRecordedSeconds "+time << oendl; 611 // odebug << "writing config numberOfRecordedSeconds "+time << oendl;
608 612
609 cfgO.write(); 613 cfgO.write();
610 614
611 odebug << "done recording "+fileName << oendl; 615 odebug << "done recording "+fileName << oendl;
612 616
613 Config cfg("qpe"); 617 Config cfg("qpe");
614 cfg.setGroup("Volume"); 618 cfg.setGroup("Volume");
615 QString foo = cfg.readEntry("Mute","TRUE"); 619 QString foo = cfg.readEntry("Mute","TRUE");
616 if(foo.find("TRUE",0,TRUE) != -1) 620 if(foo.find("TRUE",0,TRUE) != -1)
617 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; //mute 621 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; //mute
618 return TRUE; 622 return TRUE;
619} 623}
620 624
621int VMemo::setToggleButton(int tog) { 625int VMemo::setToggleButton(int tog) {
622 626
623 for( int i=0; i < 10;i++) { 627 for( int i=0; i < 10;i++) {
624 switch (tog) { 628 switch (tog) {
625 case 0: 629 case 0:
626 return -1; 630 return -1;
627 break; 631 break;
628 case 1: 632 case 1:
629 return 0; 633 return 0;
630 break; 634 break;
631 case 2: 635 case 2:
632 return Key_F24; //was Escape 636 return Key_F24; //was Escape
633 break; 637 break;
634 case 3: 638 case 3:
635 return Key_Space; 639 return Key_Space;
636 break; 640 break;
637 case 4: 641 case 4:
638 return Key_F12; 642 return Key_F12;
639 break; 643 break;
640 case 5: 644 case 5:
641 return Key_F9; 645 return Key_F9;
642 break; 646 break;
643 case 6: 647 case 6:
644 return Key_F10; 648 return Key_F10;
645 break; 649 break;
646 case 7: 650 case 7:
647 return Key_F11; 651 return Key_F11;
648 break; 652 break;
649 case 8: 653 case 8:
650 return Key_F13; 654 return Key_F13;
651 break; 655 break;
652 }; 656 };
653 } 657 }
654 return -1; 658 return -1;
655} 659}
656 660
657void VMemo::timerBreak() { 661void VMemo::timerBreak() {
658 //stop 662 //stop
659 stopRecording(); 663 stopRecording();
660 QMessageBox::message("Vmemo","Vmemo recording has ended"); 664 QMessageBox::message("Vmemo","Vmemo recording has ended");
661} 665}
662 666
663 667
664EXPORT_OPIE_APPLET_v1( VMemo ) 668EXPORT_OPIE_APPLET_v1( VMemo )
665 669
diff --git a/core/applets/vtapplet/vt.cpp b/core/applets/vtapplet/vt.cpp
index aec63c3..7832ee0 100644
--- a/core/applets/vtapplet/vt.cpp
+++ b/core/applets/vtapplet/vt.cpp
@@ -1,164 +1,172 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2003-2004 Michael 'Mickey' Lauer <mickey@Vanille.de> 2** Copyright (C) 2003-2004 Michael 'Mickey' Lauer <mickey@Vanille.de>
3** 3**
4** This file may be distributed and/or modified under the terms of the 4** This file may be distributed and/or modified under the terms of the
5** GNU General Public License version 2 as published by the Free Software 5** GNU General Public License version 2 as published by the Free Software
6** Foundation and appearing in the file LICENSE.GPL included in the 6** Foundation and appearing in the file LICENSE.GPL included in the
7** packaging of this file. 7** packaging of this file.
8** 8**
9** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 9** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
10** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 10** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
11** 11**
12**********************************************************************/ 12**********************************************************************/
13 13
14#include "vt.h" 14#include "vt.h"
15 15
16/* OPIE */ 16/* OPIE */
17#include <opie2/odebug.h> 17#include <opie2/odebug.h>
18#include <qpe/resource.h> 18#include <qpe/resource.h>
19using namespace Opie::Core; 19using namespace Opie::Core;
20 20
21/* QT */ 21/* QT */
22#include <qpopupmenu.h> 22#include <qpopupmenu.h>
23 23
24/* STD */ 24/* STD */
25#include <fcntl.h> 25#include <fcntl.h>
26#include <unistd.h> 26#include <unistd.h>
27#include <sys/types.h> 27#include <sys/types.h>
28#include <sys/stat.h> 28#include <sys/stat.h>
29#include <sys/ioctl.h> 29#include <sys/ioctl.h>
30#include <linux/vt.h> 30#include <linux/vt.h>
31 31
32VTApplet::VTApplet ( ) 32VTApplet::VTApplet ( )
33 : QObject ( 0, "VTApplet" ) 33 : QObject ( 0, "VTApplet" )
34{ 34{
35} 35}
36 36
37VTApplet::~VTApplet ( ) 37VTApplet::~VTApplet ( )
38{ 38{
39} 39}
40 40
41int VTApplet::position ( ) const 41int VTApplet::position ( ) const
42{ 42{
43 return 2; 43 return 2;
44} 44}
45 45
46QString VTApplet::name ( ) const 46QString VTApplet::name ( ) const
47{ 47{
48 return tr( "VT shortcut" ); 48 return tr( "VT shortcut" );
49} 49}
50 50
51QString VTApplet::text ( ) const 51QString VTApplet::text ( ) const
52{ 52{
53 return tr( "Terminal" ); 53 return tr( "Terminal" );
54} 54}
55 55
56/* 56/*
57QString VTApplet::tr( const char* s ) const 57QString VTApplet::tr( const char* s ) const
58{ 58{
59 return qApp->translate( "VTApplet", s, 0 ); 59 return qApp->translate( "VTApplet", s, 0 );
60} 60}
61 61
62QString VTApplet::tr( const char* s, const char* p ) const 62QString VTApplet::tr( const char* s, const char* p ) const
63{ 63{
64 return qApp->translate( "VTApplet", s, p ); 64 return qApp->translate( "VTApplet", s, p );
65} 65}
66*/ 66*/
67 67
68QIconSet VTApplet::icon ( ) const 68QIconSet VTApplet::icon ( ) const
69{ 69{
70 QPixmap pix; 70 QPixmap pix;
71 QImage img = Resource::loadImage ( "terminal" ); 71 QImage img = Resource::loadImage ( "terminal" );
72 72
73 if ( !img. isNull ( )) 73 if ( !img. isNull ( ))
74 pix. convertFromImage ( img. smoothScale ( 14, 14 )); 74 pix. convertFromImage ( img. smoothScale ( 14, 14 ));
75 return pix; 75 return pix;
76} 76}
77 77
78QPopupMenu *VTApplet::popup ( QWidget* parent ) const 78QPopupMenu *VTApplet::popup ( QWidget* parent ) const
79{ 79{
80 odebug << "VTApplet::popup" << oendl; 80 odebug << "VTApplet::popup" << oendl;
81 81
82 struct vt_stat vtstat; 82 struct vt_stat vtstat;
83#ifdef QT_QWS_DEVFS
84 int fd = ::open( "/dev/vc/0", O_RDWR );
85#else
83 int fd = ::open( "/dev/tty0", O_RDWR ); 86 int fd = ::open( "/dev/tty0", O_RDWR );
87#endif
84 if ( fd == -1 ) return 0; 88 if ( fd == -1 ) return 0;
85 if ( ioctl( fd, VT_GETSTATE, &vtstat ) == -1 ) return 0; 89 if ( ioctl( fd, VT_GETSTATE, &vtstat ) == -1 ) return 0;
86 90
87 m_subMenu = new QPopupMenu( parent ); 91 m_subMenu = new QPopupMenu( parent );
88 m_subMenu->setCheckable( true ); 92 m_subMenu->setCheckable( true );
89 for ( int i = 1; i < 10; ++i ) 93 for ( int i = 1; i < 10; ++i )
90 { 94 {
91 int id = m_subMenu->insertItem( QString::number( i ), 500+i ); 95 int id = m_subMenu->insertItem( QString::number( i ), 500+i );
92 m_subMenu->setItemChecked( id, id-500 == vtstat.v_active ); 96 m_subMenu->setItemChecked( id, id-500 == vtstat.v_active );
93 } 97 }
94 ::close( fd ); 98 ::close( fd );
95 99
96 connect( m_subMenu, SIGNAL( activated(int) ), this, SLOT( changeVT(int) ) ); 100 connect( m_subMenu, SIGNAL( activated(int) ), this, SLOT( changeVT(int) ) );
97 connect( m_subMenu, SIGNAL( aboutToShow() ), this, SLOT( updateMenu() ) ); 101 connect( m_subMenu, SIGNAL( aboutToShow() ), this, SLOT( updateMenu() ) );
98 102
99 return m_subMenu; 103 return m_subMenu;
100} 104}
101 105
102 106
103void VTApplet::changeVT( int index ) 107void VTApplet::changeVT( int index )
104{ 108{
105 //odebug << "VTApplet::changeVT( " << index-500 << " )" << oendl; 109 //odebug << "VTApplet::changeVT( " << index-500 << " )" << oendl;
106 110
111#ifdef QT_QWS_DEVFS
112 int fd = ::open("/dev/vc/0", O_RDWR);
113#else
107 int fd = ::open("/dev/tty0", O_RDWR); 114 int fd = ::open("/dev/tty0", O_RDWR);
115#endif
108 if ( fd == -1 ) return; 116 if ( fd == -1 ) return;
109 ioctl( fd, VT_ACTIVATE, index-500 ); 117 ioctl( fd, VT_ACTIVATE, index-500 );
110} 118}
111 119
112 120
113void VTApplet::updateMenu() 121void VTApplet::updateMenu()
114{ 122{
115 //odebug << "VTApplet::updateMenu()" << oendl; 123 //odebug << "VTApplet::updateMenu()" << oendl;
116 124
117 int fd = ::open( "/dev/console", O_RDONLY ); 125 int fd = ::open( "/dev/console", O_RDONLY );
118 if ( fd == -1 ) return; 126 if ( fd == -1 ) return;
119 127
120 for ( int i = 1; i < 10; ++i ) 128 for ( int i = 1; i < 10; ++i )
121 { 129 {
122 int result = ioctl( fd, VT_DISALLOCATE, i ); 130 int result = ioctl( fd, VT_DISALLOCATE, i );
123 131
124 /* 132 /*
125 if ( result == -1 ) 133 if ( result == -1 )
126 odebug << "VT " << i << " disallocated == free" << oendl; 134 odebug << "VT " << i << " disallocated == free" << oendl;
127 else 135 else
128 odebug << "VT " << i << " _not_ disallocated == busy" << oendl; 136 odebug << "VT " << i << " _not_ disallocated == busy" << oendl;
129 */ 137 */
130 138
131 m_subMenu->setItemEnabled( 500+i, result == -1 ); 139 m_subMenu->setItemEnabled( 500+i, result == -1 );
132 } 140 }
133 141
134 ::close( fd ); 142 ::close( fd );
135} 143}
136 144
137 145
138void VTApplet::activated() 146void VTApplet::activated()
139{ 147{
140 odebug << "VTApplet::activated()" << oendl; 148 odebug << "VTApplet::activated()" << oendl;
141} 149}
142 150
143 151
144QRESULT VTApplet::queryInterface ( const QUuid &uuid, QUnknownInterface **iface ) 152QRESULT VTApplet::queryInterface ( const QUuid &uuid, QUnknownInterface **iface )
145{ 153{
146 *iface = 0; 154 *iface = 0;
147 if ( uuid == IID_QUnknown ) 155 if ( uuid == IID_QUnknown )
148 *iface = this; 156 *iface = this;
149 else if ( uuid == IID_MenuApplet ) 157 else if ( uuid == IID_MenuApplet )
150 *iface = this; 158 *iface = this;
151 else 159 else
152 return QS_FALSE; 160 return QS_FALSE;
153 161
154 if ( *iface ) 162 if ( *iface )
155 (*iface)-> addRef ( ); 163 (*iface)-> addRef ( );
156 return QS_OK; 164 return QS_OK;
157} 165}
158 166
159Q_EXPORT_INTERFACE( ) 167Q_EXPORT_INTERFACE( )
160{ 168{
161 Q_CREATE_INSTANCE( VTApplet ) 169 Q_CREATE_INSTANCE( VTApplet )
162} 170}
163 171
164 172
diff --git a/libopie/odevice.cpp b/libopie/odevice.cpp
index 21070bf..9d0bbbf 100644
--- a/libopie/odevice.cpp
+++ b/libopie/odevice.cpp
@@ -1,2134 +1,2138 @@
1/* This file is part of the OPIE libraries 1/* This file is part of the OPIE libraries
2 Copyright (C) 2002 Robert Griebl (sandman@handhelds.org) 2 Copyright (C) 2002 Robert Griebl (sandman@handhelds.org)
3 3
4 This library is free software; you can redistribute it and/or 4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public 5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either 6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version. 7 version 2 of the License, or (at your option) any later version.
8 8
9 This library is distributed in the hope that it will be useful, 9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of 10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details. 12 Library General Public License for more details.
13 13
14 You should have received a copy of the GNU Library General Public License 14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to 15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 16 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. 17 Boston, MA 02111-1307, USA.
18*/ 18*/
19 19
20#include <stdlib.h> 20#include <stdlib.h>
21#include <unistd.h> 21#include <unistd.h>
22#include <fcntl.h> 22#include <fcntl.h>
23#include <sys/ioctl.h> 23#include <sys/ioctl.h>
24#include <signal.h> 24#include <signal.h>
25#include <sys/time.h> 25#include <sys/time.h>
26#ifndef QT_NO_SOUND 26#ifndef QT_NO_SOUND
27#include <linux/soundcard.h> 27#include <linux/soundcard.h>
28#endif 28#endif
29#include <math.h> 29#include <math.h>
30 30
31 31
32#include <qfile.h> 32#include <qfile.h>
33#include <qtextstream.h> 33#include <qtextstream.h>
34#include <qpe/sound.h> 34#include <qpe/sound.h>
35#include <qpe/resource.h> 35#include <qpe/resource.h>
36#include <qpe/config.h> 36#include <qpe/config.h>
37#include <qpe/qcopenvelope_qws.h> 37#include <qpe/qcopenvelope_qws.h>
38 38
39#include "odevice.h" 39#include "odevice.h"
40 40
41#include <qwindowsystem_qws.h> 41#include <qwindowsystem_qws.h>
42 42
43#ifndef ARRAY_SIZE 43#ifndef ARRAY_SIZE
44#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) 44#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
45#endif 45#endif
46 46
47// _IO and friends are only defined in kernel headers ... 47// _IO and friends are only defined in kernel headers ...
48 48
49#define OD_IOC(dir,type,number,size) (( dir << 30 ) | ( type << 8 ) | ( number ) | ( size << 16 )) 49#define OD_IOC(dir,type,number,size) (( dir << 30 ) | ( type << 8 ) | ( number ) | ( size << 16 ))
50 50
51#define OD_IO(type,number) OD_IOC(0,type,number,0) 51#define OD_IO(type,number) OD_IOC(0,type,number,0)
52#define OD_IOW(type,number,size) OD_IOC(1,type,number,sizeof(size)) 52#define OD_IOW(type,number,size) OD_IOC(1,type,number,sizeof(size))
53#define OD_IOR(type,number,size) OD_IOC(2,type,number,sizeof(size)) 53#define OD_IOR(type,number,size) OD_IOC(2,type,number,sizeof(size))
54#define OD_IORW(type,number,size) OD_IOC(3,type,number,sizeof(size)) 54#define OD_IORW(type,number,size) OD_IOC(3,type,number,sizeof(size))
55 55
56using namespace Opie; 56using namespace Opie;
57 57
58class ODeviceData { 58class ODeviceData {
59public: 59public:
60 QString m_vendorstr; 60 QString m_vendorstr;
61 OVendor m_vendor; 61 OVendor m_vendor;
62 62
63 QString m_modelstr; 63 QString m_modelstr;
64 OModel m_model; 64 OModel m_model;
65 65
66 QString m_systemstr; 66 QString m_systemstr;
67 OSystem m_system; 67 OSystem m_system;
68 68
69 QString m_sysverstr; 69 QString m_sysverstr;
70 70
71 Transformation m_rotation; 71 Transformation m_rotation;
72 ODirection m_direction; 72 ODirection m_direction;
73 73
74 QValueList <ODeviceButton> *m_buttons; 74 QValueList <ODeviceButton> *m_buttons;
75 uint m_holdtime; 75 uint m_holdtime;
76 QStrList *m_cpu_frequencies; 76 QStrList *m_cpu_frequencies;
77 77
78}; 78};
79 79
80class iPAQ : public ODevice, public QWSServer::KeyboardFilter { 80class iPAQ : public ODevice, public QWSServer::KeyboardFilter {
81protected: 81protected:
82 virtual void init ( ); 82 virtual void init ( );
83 virtual void initButtons ( ); 83 virtual void initButtons ( );
84 84
85public: 85public:
86 virtual bool setSoftSuspend ( bool soft ); 86 virtual bool setSoftSuspend ( bool soft );
87 87
88 virtual bool setDisplayBrightness ( int b ); 88 virtual bool setDisplayBrightness ( int b );
89 virtual int displayBrightnessResolution ( ) const; 89 virtual int displayBrightnessResolution ( ) const;
90 90
91 virtual void alarmSound ( ); 91 virtual void alarmSound ( );
92 92
93 virtual QValueList <OLed> ledList ( ) const; 93 virtual QValueList <OLed> ledList ( ) const;
94 virtual QValueList <OLedState> ledStateList ( OLed led ) const; 94 virtual QValueList <OLedState> ledStateList ( OLed led ) const;
95 virtual OLedState ledState ( OLed led ) const; 95 virtual OLedState ledState ( OLed led ) const;
96 virtual bool setLedState ( OLed led, OLedState st ); 96 virtual bool setLedState ( OLed led, OLedState st );
97 97
98 virtual bool hasLightSensor ( ) const; 98 virtual bool hasLightSensor ( ) const;
99 virtual int readLightSensor ( ); 99 virtual int readLightSensor ( );
100 virtual int lightSensorResolution ( ) const; 100 virtual int lightSensorResolution ( ) const;
101 101
102protected: 102protected:
103 virtual bool filter ( int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat ); 103 virtual bool filter ( int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat );
104 virtual void timerEvent ( QTimerEvent *te ); 104 virtual void timerEvent ( QTimerEvent *te );
105 105
106 int m_power_timer; 106 int m_power_timer;
107 107
108 OLedState m_leds [2]; 108 OLedState m_leds [2];
109}; 109};
110 110
111class Jornada : public ODevice { 111class Jornada : public ODevice {
112protected: 112protected:
113 virtual void init ( ); 113 virtual void init ( );
114 //virtual void initButtons ( ); 114 //virtual void initButtons ( );
115public: 115public:
116 virtual bool setSoftSuspend ( bool soft ); 116 virtual bool setSoftSuspend ( bool soft );
117 virtual bool setDisplayBrightness ( int b ); 117 virtual bool setDisplayBrightness ( int b );
118 virtual int displayBrightnessResolution ( ) const; 118 virtual int displayBrightnessResolution ( ) const;
119 static bool isJornada(); 119 static bool isJornada();
120 120
121}; 121};
122 122
123class Zaurus : public ODevice { 123class Zaurus : public ODevice {
124protected: 124protected:
125 virtual void init ( ); 125 virtual void init ( );
126 virtual void initButtons ( ); 126 virtual void initButtons ( );
127 127
128public: 128public:
129 virtual bool setSoftSuspend ( bool soft ); 129 virtual bool setSoftSuspend ( bool soft );
130 130
131 virtual bool setDisplayBrightness ( int b ); 131 virtual bool setDisplayBrightness ( int b );
132 virtual int displayBrightnessResolution ( ) const; 132 virtual int displayBrightnessResolution ( ) const;
133 133
134 virtual void alarmSound ( ); 134 virtual void alarmSound ( );
135 virtual void keySound ( ); 135 virtual void keySound ( );
136 virtual void touchSound ( ); 136 virtual void touchSound ( );
137 137
138 virtual QValueList <OLed> ledList ( ) const; 138 virtual QValueList <OLed> ledList ( ) const;
139 virtual QValueList <OLedState> ledStateList ( OLed led ) const; 139 virtual QValueList <OLedState> ledStateList ( OLed led ) const;
140 virtual OLedState ledState ( OLed led ) const; 140 virtual OLedState ledState ( OLed led ) const;
141 virtual bool setLedState ( OLed led, OLedState st ); 141 virtual bool setLedState ( OLed led, OLedState st );
142 142
143 bool hasHingeSensor() const; 143 bool hasHingeSensor() const;
144 OHingeStatus readHingeSensor(); 144 OHingeStatus readHingeSensor();
145 145
146 static bool isZaurus(); 146 static bool isZaurus();
147 147
148 // Does this break BC? 148 // Does this break BC?
149 virtual bool suspend ( ); 149 virtual bool suspend ( );
150 Transformation rotation ( ) const; 150 Transformation rotation ( ) const;
151 ODirection direction ( ) const; 151 ODirection direction ( ) const;
152 152
153protected: 153protected:
154 virtual void buzzer ( int snd ); 154 virtual void buzzer ( int snd );
155 155
156 OLedState m_leds [1]; 156 OLedState m_leds [1];
157 bool m_embedix; 157 bool m_embedix;
158 void virtual_hook( int id, void *data ); 158 void virtual_hook( int id, void *data );
159}; 159};
160 160
161class SIMpad : public ODevice, public QWSServer::KeyboardFilter { 161class SIMpad : public ODevice, public QWSServer::KeyboardFilter {
162protected: 162protected:
163 virtual void init ( ); 163 virtual void init ( );
164 virtual void initButtons ( ); 164 virtual void initButtons ( );
165 165
166public: 166public:
167 virtual bool setSoftSuspend ( bool soft ); 167 virtual bool setSoftSuspend ( bool soft );
168 virtual bool suspend(); 168 virtual bool suspend();
169 169
170 virtual bool setDisplayStatus( bool on ); 170 virtual bool setDisplayStatus( bool on );
171 virtual bool setDisplayBrightness ( int b ); 171 virtual bool setDisplayBrightness ( int b );
172 virtual int displayBrightnessResolution ( ) const; 172 virtual int displayBrightnessResolution ( ) const;
173 173
174 virtual void alarmSound ( ); 174 virtual void alarmSound ( );
175 175
176 virtual QValueList <OLed> ledList ( ) const; 176 virtual QValueList <OLed> ledList ( ) const;
177 virtual QValueList <OLedState> ledStateList ( OLed led ) const; 177 virtual QValueList <OLedState> ledStateList ( OLed led ) const;
178 virtual OLedState ledState ( OLed led ) const; 178 virtual OLedState ledState ( OLed led ) const;
179 virtual bool setLedState ( OLed led, OLedState st ); 179 virtual bool setLedState ( OLed led, OLedState st );
180 180
181protected: 181protected:
182 virtual bool filter ( int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat ); 182 virtual bool filter ( int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat );
183 virtual void timerEvent ( QTimerEvent *te ); 183 virtual void timerEvent ( QTimerEvent *te );
184 184
185 int m_power_timer; 185 int m_power_timer;
186 186
187 OLedState m_leds [1]; //FIXME check if really only one 187 OLedState m_leds [1]; //FIXME check if really only one
188}; 188};
189 189
190class Ramses : public ODevice, public QWSServer::KeyboardFilter { 190class Ramses : public ODevice, public QWSServer::KeyboardFilter {
191protected: 191protected:
192 virtual void init ( ); 192 virtual void init ( );
193 193
194public: 194public:
195 virtual bool setSoftSuspend ( bool soft ); 195 virtual bool setSoftSuspend ( bool soft );
196 virtual bool suspend ( ); 196 virtual bool suspend ( );
197 197
198 virtual bool setDisplayStatus( bool on ); 198 virtual bool setDisplayStatus( bool on );
199 virtual bool setDisplayBrightness ( int b ); 199 virtual bool setDisplayBrightness ( int b );
200 virtual int displayBrightnessResolution ( ) const; 200 virtual int displayBrightnessResolution ( ) const;
201 virtual bool setDisplayContrast ( int b ); 201 virtual bool setDisplayContrast ( int b );
202 virtual int displayContrastResolution ( ) const; 202 virtual int displayContrastResolution ( ) const;
203 203
204protected: 204protected:
205 virtual bool filter ( int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat ); 205 virtual bool filter ( int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat );
206 virtual void timerEvent ( QTimerEvent *te ); 206 virtual void timerEvent ( QTimerEvent *te );
207 207
208 int m_power_timer; 208 int m_power_timer;
209}; 209};
210 210
211struct i_button { 211struct i_button {
212 uint model; 212 uint model;
213 Qt::Key code; 213 Qt::Key code;
214 char *utext; 214 char *utext;
215 char *pix; 215 char *pix;
216 char *fpressedservice; 216 char *fpressedservice;
217 char *fpressedaction; 217 char *fpressedaction;
218 char *fheldservice; 218 char *fheldservice;
219 char *fheldaction; 219 char *fheldaction;
220} ipaq_buttons [] = { 220} ipaq_buttons [] = {
221 { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx | Model_iPAQ_H5xxx, 221 { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx | Model_iPAQ_H5xxx,
222 Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"), 222 Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"),
223 "devicebuttons/ipaq_calendar", 223 "devicebuttons/ipaq_calendar",
224 "datebook", "nextView()", 224 "datebook", "nextView()",
225 "today", "raise()" }, 225 "today", "raise()" },
226 { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx | Model_iPAQ_H5xxx, 226 { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx | Model_iPAQ_H5xxx,
227 Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"), 227 Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"),
228 "devicebuttons/ipaq_contact", 228 "devicebuttons/ipaq_contact",
229 "addressbook", "raise()", 229 "addressbook", "raise()",
230 "addressbook", "beamBusinessCard()" }, 230 "addressbook", "beamBusinessCard()" },
231 { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx, 231 { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx,
232 Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"), 232 Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"),
233 "devicebuttons/ipaq_menu", 233 "devicebuttons/ipaq_menu",
234 "QPE/TaskBar", "toggleMenu()", 234 "QPE/TaskBar", "toggleMenu()",
235 "QPE/TaskBar", "toggleStartMenu()" }, 235 "QPE/TaskBar", "toggleStartMenu()" },
236 { Model_iPAQ_H38xx | Model_iPAQ_H39xx | Model_iPAQ_H5xxx, 236 { Model_iPAQ_H38xx | Model_iPAQ_H39xx | Model_iPAQ_H5xxx,
237 Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Mail Button"), 237 Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Mail Button"),
238 "devicebuttons/ipaq_mail", 238 "devicebuttons/ipaq_mail",
239 "mail", "raise()", 239 "mail", "raise()",
240 "mail", "newMail()" }, 240 "mail", "newMail()" },
241 { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx | Model_iPAQ_H5xxx, 241 { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx | Model_iPAQ_H5xxx,
242 Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"), 242 Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"),
243 "devicebuttons/ipaq_home", 243 "devicebuttons/ipaq_home",
244 "QPE/Launcher", "home()", 244 "QPE/Launcher", "home()",
245 "buttonsettings", "raise()" }, 245 "buttonsettings", "raise()" },
246 { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx | Model_iPAQ_H5xxx, 246 { Model_iPAQ_H31xx | Model_iPAQ_H36xx | Model_iPAQ_H37xx | Model_iPAQ_H38xx | Model_iPAQ_H39xx | Model_iPAQ_H5xxx,
247 Qt::Key_F24, QT_TRANSLATE_NOOP("Button", "Record Button"), 247 Qt::Key_F24, QT_TRANSLATE_NOOP("Button", "Record Button"),
248 "devicebuttons/ipaq_record", 248 "devicebuttons/ipaq_record",
249 "QPE/VMemo", "toggleRecord()", 249 "QPE/VMemo", "toggleRecord()",
250 "sound", "raise()" }, 250 "sound", "raise()" },
251}; 251};
252 252
253struct z_button { 253struct z_button {
254 Qt::Key code; 254 Qt::Key code;
255 char *utext; 255 char *utext;
256 char *pix; 256 char *pix;
257 char *fpressedservice; 257 char *fpressedservice;
258 char *fpressedaction; 258 char *fpressedaction;
259 char *fheldservice; 259 char *fheldservice;
260 char *fheldaction; 260 char *fheldaction;
261} z_buttons [] = { 261} z_buttons [] = {
262 { Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"), 262 { Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"),
263 "devicebuttons/z_calendar", 263 "devicebuttons/z_calendar",
264 "datebook", "nextView()", 264 "datebook", "nextView()",
265 "today", "raise()" }, 265 "today", "raise()" },
266 { Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"), 266 { Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"),
267 "devicebuttons/z_contact", 267 "devicebuttons/z_contact",
268 "addressbook", "raise()", 268 "addressbook", "raise()",
269 "addressbook", "beamBusinessCard()" }, 269 "addressbook", "beamBusinessCard()" },
270 { Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"), 270 { Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"),
271 "devicebuttons/z_home", 271 "devicebuttons/z_home",
272 "QPE/Launcher", "home()", 272 "QPE/Launcher", "home()",
273 "buttonsettings", "raise()" }, 273 "buttonsettings", "raise()" },
274 { Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"), 274 { Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"),
275 "devicebuttons/z_menu", 275 "devicebuttons/z_menu",
276 "QPE/TaskBar", "toggleMenu()", 276 "QPE/TaskBar", "toggleMenu()",
277 "QPE/TaskBar", "toggleStartMenu()" }, 277 "QPE/TaskBar", "toggleStartMenu()" },
278 { Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Mail Button"), 278 { Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Mail Button"),
279 "devicebuttons/z_mail", 279 "devicebuttons/z_mail",
280 "mail", "raise()", 280 "mail", "raise()",
281 "mail", "newMail()" }, 281 "mail", "newMail()" },
282}; 282};
283 283
284struct z_button z_buttons_c700 [] = { 284struct z_button z_buttons_c700 [] = {
285 { Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"), 285 { Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Calendar Button"),
286 "devicebuttons/z_calendar", 286 "devicebuttons/z_calendar",
287 "datebook", "nextView()", 287 "datebook", "nextView()",
288 "today", "raise()" }, 288 "today", "raise()" },
289 { Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"), 289 { Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Contacts Button"),
290 "devicebuttons/z_contact", 290 "devicebuttons/z_contact",
291 "addressbook", "raise()", 291 "addressbook", "raise()",
292 "addressbook", "beamBusinessCard()" }, 292 "addressbook", "beamBusinessCard()" },
293 { Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"), 293 { Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Home Button"),
294 "devicebuttons/z_home", 294 "devicebuttons/z_home",
295 "QPE/Launcher", "home()", 295 "QPE/Launcher", "home()",
296 "buttonsettings", "raise()" }, 296 "buttonsettings", "raise()" },
297 { Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"), 297 { Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Menu Button"),
298 "devicebuttons/z_menu", 298 "devicebuttons/z_menu",
299 "QPE/TaskBar", "toggleMenu()", 299 "QPE/TaskBar", "toggleMenu()",
300 "QPE/TaskBar", "toggleStartMenu()" }, 300 "QPE/TaskBar", "toggleStartMenu()" },
301 { Qt::Key_F14, QT_TRANSLATE_NOOP("Button", "Display Rotate"), 301 { Qt::Key_F14, QT_TRANSLATE_NOOP("Button", "Display Rotate"),
302 "devicebuttons/z_hinge", 302 "devicebuttons/z_hinge",
303 "QPE/Rotation", "rotateDefault()", 303 "QPE/Rotation", "rotateDefault()",
304 "QPE/Dummy", "doNothing()" }, 304 "QPE/Dummy", "doNothing()" },
305}; 305};
306 306
307struct s_button { 307struct s_button {
308 uint model; 308 uint model;
309 Qt::Key code; 309 Qt::Key code;
310 char *utext; 310 char *utext;
311 char *pix; 311 char *pix;
312 char *fpressedservice; 312 char *fpressedservice;
313 char *fpressedaction; 313 char *fpressedaction;
314 char *fheldservice; 314 char *fheldservice;
315 char *fheldaction; 315 char *fheldaction;
316} simpad_buttons [] = { 316} simpad_buttons [] = {
317 { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, 317 { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus,
318 Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Lower+Up"), 318 Qt::Key_F9, QT_TRANSLATE_NOOP("Button", "Lower+Up"),
319 "devicebuttons/simpad_lower_up", 319 "devicebuttons/simpad_lower_up",
320 "datebook", "nextView()", 320 "datebook", "nextView()",
321 "today", "raise()" }, 321 "today", "raise()" },
322 { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, 322 { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus,
323 Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Lower+Down"), 323 Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Lower+Down"),
324 "devicebuttons/simpad_lower_down", 324 "devicebuttons/simpad_lower_down",
325 "addressbook", "raise()", 325 "addressbook", "raise()",
326 "addressbook", "beamBusinessCard()" }, 326 "addressbook", "beamBusinessCard()" },
327 { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, 327 { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus,
328 Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Lower+Right"), 328 Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "Lower+Right"),
329 "devicebuttons/simpad_lower_right", 329 "devicebuttons/simpad_lower_right",
330 "QPE/TaskBar", "toggleMenu()", 330 "QPE/TaskBar", "toggleMenu()",
331 "QPE/TaskBar", "toggleStartMenu()" }, 331 "QPE/TaskBar", "toggleStartMenu()" },
332 { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, 332 { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus,
333 Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Lower+Left"), 333 Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Lower+Left"),
334 "devicebuttons/simpad_lower_left", 334 "devicebuttons/simpad_lower_left",
335 "mail", "raise()", 335 "mail", "raise()",
336 "mail", "newMail()" }, 336 "mail", "newMail()" },
337 337
338 { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, 338 { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus,
339 Qt::Key_F5, QT_TRANSLATE_NOOP("Button", "Upper+Up"), 339 Qt::Key_F5, QT_TRANSLATE_NOOP("Button", "Upper+Up"),
340 "devicebuttons/simpad_upper_up", 340 "devicebuttons/simpad_upper_up",
341 "QPE/Launcher", "home()", 341 "QPE/Launcher", "home()",
342 "buttonsettings", "raise()" }, 342 "buttonsettings", "raise()" },
343 { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, 343 { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus,
344 Qt::Key_F6, QT_TRANSLATE_NOOP("Button", "Upper+Down"), 344 Qt::Key_F6, QT_TRANSLATE_NOOP("Button", "Upper+Down"),
345 "devicebuttons/simpad_upper_down", 345 "devicebuttons/simpad_upper_down",
346 "addressbook", "raise()", 346 "addressbook", "raise()",
347 "addressbook", "beamBusinessCard()" }, 347 "addressbook", "beamBusinessCard()" },
348 { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, 348 { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus,
349 Qt::Key_F7, QT_TRANSLATE_NOOP("Button", "Upper+Right"), 349 Qt::Key_F7, QT_TRANSLATE_NOOP("Button", "Upper+Right"),
350 "devicebuttons/simpad_upper_right", 350 "devicebuttons/simpad_upper_right",
351 "QPE/TaskBar", "toggleMenu()", 351 "QPE/TaskBar", "toggleMenu()",
352 "QPE/TaskBar", "toggleStartMenu()" }, 352 "QPE/TaskBar", "toggleStartMenu()" },
353 { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, 353 { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus,
354 Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Upper+Left"), 354 Qt::Key_F13, QT_TRANSLATE_NOOP("Button", "Upper+Left"),
355 "devicebuttons/simpad_upper_left", 355 "devicebuttons/simpad_upper_left",
356 "QPE/Rotation", "flip()", 356 "QPE/Rotation", "flip()",
357 "QPE/Rotation", "flip()" }, 357 "QPE/Rotation", "flip()" },
358 /* 358 /*
359 { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, 359 { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus,
360 Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Lower+Upper"), 360 Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Lower+Upper"),
361 "devicebuttons/simpad_lower_upper", 361 "devicebuttons/simpad_lower_upper",
362 "QPE/Launcher", "home()", 362 "QPE/Launcher", "home()",
363 "buttonsettings", "raise()" }, 363 "buttonsettings", "raise()" },
364 { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus, 364 { Model_SIMpad_CL4 | Model_SIMpad_SL4 | Model_SIMpad_SLC | Model_SIMpad_TSinus,
365 Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Lower+Upper"), 365 Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "Lower+Upper"),
366 "devicebuttons/simpad_upper_lower", 366 "devicebuttons/simpad_upper_lower",
367 "QPE/Launcher", "home()", 367 "QPE/Launcher", "home()",
368 "buttonsettings", "raise()" }, 368 "buttonsettings", "raise()" },
369 */ 369 */
370}; 370};
371 371
372class Yopy : public ODevice { 372class Yopy : public ODevice {
373protected: 373protected:
374 virtual void init ( ); 374 virtual void init ( );
375 virtual void initButtons ( ); 375 virtual void initButtons ( );
376 376
377public: 377public:
378 virtual bool suspend ( ); 378 virtual bool suspend ( );
379 379
380 virtual bool setDisplayBrightness ( int b ); 380 virtual bool setDisplayBrightness ( int b );
381 virtual int displayBrightnessResolution ( ) const; 381 virtual int displayBrightnessResolution ( ) const;
382 382
383 static bool isYopy ( ); 383 static bool isYopy ( );
384}; 384};
385 385
386struct yopy_button { 386struct yopy_button {
387 Qt::Key code; 387 Qt::Key code;
388 char *utext; 388 char *utext;
389 char *pix; 389 char *pix;
390 char *fpressedservice; 390 char *fpressedservice;
391 char *fpressedaction; 391 char *fpressedaction;
392 char *fheldservice; 392 char *fheldservice;
393 char *fheldaction; 393 char *fheldaction;
394} yopy_buttons [] = { 394} yopy_buttons [] = {
395 { Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Action Button"), 395 { Qt::Key_F10, QT_TRANSLATE_NOOP("Button", "Action Button"),
396 "devicebuttons/yopy_action", 396 "devicebuttons/yopy_action",
397 "datebook", "nextView()", 397 "datebook", "nextView()",
398 "today", "raise()" }, 398 "today", "raise()" },
399 { Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "OK Button"), 399 { Qt::Key_F11, QT_TRANSLATE_NOOP("Button", "OK Button"),
400 "devicebuttons/yopy_ok", 400 "devicebuttons/yopy_ok",
401 "addressbook", "raise()", 401 "addressbook", "raise()",
402 "addressbook", "beamBusinessCard()" }, 402 "addressbook", "beamBusinessCard()" },
403 { Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "End Button"), 403 { Qt::Key_F12, QT_TRANSLATE_NOOP("Button", "End Button"),
404 "devicebuttons/yopy_end", 404 "devicebuttons/yopy_end",
405 "QPE/Launcher", "home()", 405 "QPE/Launcher", "home()",
406 "buttonsettings", "raise()" }, 406 "buttonsettings", "raise()" },
407}; 407};
408 408
409static QCString makeChannel ( const char *str ) 409static QCString makeChannel ( const char *str )
410{ 410{
411 if ( str && !::strchr ( str, '/' )) 411 if ( str && !::strchr ( str, '/' ))
412 return QCString ( "QPE/Application/" ) + str; 412 return QCString ( "QPE/Application/" ) + str;
413 else 413 else
414 return str; 414 return str;
415} 415}
416 416
417static inline bool isQWS() 417static inline bool isQWS()
418{ 418{
419 return qApp ? ( qApp-> type ( ) == QApplication::GuiServer ) : false; 419 return qApp ? ( qApp-> type ( ) == QApplication::GuiServer ) : false;
420} 420}
421 421
422ODevice *ODevice::inst ( ) 422ODevice *ODevice::inst ( )
423{ 423{
424 static ODevice *dev = 0; 424 static ODevice *dev = 0;
425 425
426 if ( !dev ) { 426 if ( !dev ) {
427 if ( QFile::exists ( "/proc/hal/model" )) 427 if ( QFile::exists ( "/proc/hal/model" ))
428 dev = new iPAQ ( ); 428 dev = new iPAQ ( );
429 else if ( Zaurus::isZaurus() ) 429 else if ( Zaurus::isZaurus() )
430 dev = new Zaurus ( ); 430 dev = new Zaurus ( );
431 else if ( QFile::exists ( "/proc/ucb1x00" ) && QFile::exists ( "/proc/cs3" )) 431 else if ( QFile::exists ( "/proc/ucb1x00" ) && QFile::exists ( "/proc/cs3" ))
432 dev = new SIMpad ( ); 432 dev = new SIMpad ( );
433 else if ( Yopy::isYopy() ) 433 else if ( Yopy::isYopy() )
434 dev = new Yopy ( ); 434 dev = new Yopy ( );
435 else if ( Jornada::isJornada() ) 435 else if ( Jornada::isJornada() )
436 dev = new Jornada ( ); 436 dev = new Jornada ( );
437 else if ( QFile::exists ( "/proc/sys/board/sys_name" )) 437 else if ( QFile::exists ( "/proc/sys/board/sys_name" ))
438 dev = new Ramses ( ); 438 dev = new Ramses ( );
439 else 439 else
440 dev = new ODevice ( ); 440 dev = new ODevice ( );
441 dev-> init ( ); 441 dev-> init ( );
442 } 442 }
443 return dev; 443 return dev;
444} 444}
445 445
446 446
447/************************************************** 447/**************************************************
448 * 448 *
449 * common 449 * common
450 * 450 *
451 **************************************************/ 451 **************************************************/
452 452
453 453
454ODevice::ODevice ( ) 454ODevice::ODevice ( )
455{ 455{
456 d = new ODeviceData; 456 d = new ODeviceData;
457 457
458 d-> m_modelstr = "Unknown"; 458 d-> m_modelstr = "Unknown";
459 d-> m_model = Model_Unknown; 459 d-> m_model = Model_Unknown;
460 d-> m_vendorstr = "Unknown"; 460 d-> m_vendorstr = "Unknown";
461 d-> m_vendor = Vendor_Unknown; 461 d-> m_vendor = Vendor_Unknown;
462 d-> m_systemstr = "Unknown"; 462 d-> m_systemstr = "Unknown";
463 d-> m_system = System_Unknown; 463 d-> m_system = System_Unknown;
464 d-> m_sysverstr = "0.0"; 464 d-> m_sysverstr = "0.0";
465 d-> m_rotation = Rot0; 465 d-> m_rotation = Rot0;
466 d-> m_direction = CW; 466 d-> m_direction = CW;
467 467
468 d-> m_holdtime = 1000; // 1000ms 468 d-> m_holdtime = 1000; // 1000ms
469 d-> m_buttons = 0; 469 d-> m_buttons = 0;
470 d-> m_cpu_frequencies = new QStrList; 470 d-> m_cpu_frequencies = new QStrList;
471} 471}
472 472
473void ODevice::systemMessage ( const QCString &msg, const QByteArray & ) 473void ODevice::systemMessage ( const QCString &msg, const QByteArray & )
474{ 474{
475 if ( msg == "deviceButtonMappingChanged()" ) { 475 if ( msg == "deviceButtonMappingChanged()" ) {
476 reloadButtonMapping ( ); 476 reloadButtonMapping ( );
477 } 477 }
478} 478}
479 479
480void ODevice::init ( ) 480void ODevice::init ( )
481{ 481{
482} 482}
483 483
484/** 484/**
485 * This method initialises the button mapping 485 * This method initialises the button mapping
486 */ 486 */
487void ODevice::initButtons ( ) 487void ODevice::initButtons ( )
488{ 488{
489 if ( d-> m_buttons ) 489 if ( d-> m_buttons )
490 return; 490 return;
491 491
492 // Simulation uses iPAQ 3660 device buttons 492 // Simulation uses iPAQ 3660 device buttons
493 493
494 qDebug ( "init Buttons" ); 494 qDebug ( "init Buttons" );
495 d-> m_buttons = new QValueList <ODeviceButton>; 495 d-> m_buttons = new QValueList <ODeviceButton>;
496 496
497 for ( uint i = 0; i < ( sizeof( ipaq_buttons ) / sizeof( i_button )); i++ ) { 497 for ( uint i = 0; i < ( sizeof( ipaq_buttons ) / sizeof( i_button )); i++ ) {
498 i_button *ib = ipaq_buttons + i; 498 i_button *ib = ipaq_buttons + i;
499 ODeviceButton b; 499 ODeviceButton b;
500 500
501 if (( ib-> model & Model_iPAQ_H36xx ) == Model_iPAQ_H36xx ) { 501 if (( ib-> model & Model_iPAQ_H36xx ) == Model_iPAQ_H36xx ) {
502 b. setKeycode ( ib-> code ); 502 b. setKeycode ( ib-> code );
503 b. setUserText ( QObject::tr ( "Button", ib-> utext )); 503 b. setUserText ( QObject::tr ( "Button", ib-> utext ));
504 b. setPixmap ( Resource::loadPixmap ( ib-> pix )); 504 b. setPixmap ( Resource::loadPixmap ( ib-> pix ));
505 b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( ib-> fpressedservice ), ib-> fpressedaction )); 505 b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( ib-> fpressedservice ), ib-> fpressedaction ));
506 b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( ib-> fheldservice ), ib-> fheldaction )); 506 b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( ib-> fheldservice ), ib-> fheldaction ));
507 d-> m_buttons-> append ( b ); 507 d-> m_buttons-> append ( b );
508 } 508 }
509 } 509 }
510 reloadButtonMapping ( ); 510 reloadButtonMapping ( );
511 511
512 QCopChannel *sysch = new QCopChannel ( "QPE/System", this ); 512 QCopChannel *sysch = new QCopChannel ( "QPE/System", this );
513 connect ( sysch, SIGNAL( received(const QCString&,const QByteArray&)), this, SLOT( systemMessage(const QCString&,const QByteArray&))); 513 connect ( sysch, SIGNAL( received(const QCString&,const QByteArray&)), this, SLOT( systemMessage(const QCString&,const QByteArray&)));
514} 514}
515 515
516ODevice::~ODevice ( ) 516ODevice::~ODevice ( )
517{ 517{
518// we leak m_devicebuttons and m_cpu_frequency 518// we leak m_devicebuttons and m_cpu_frequency
519// but it's a singleton and it is not so importantant 519// but it's a singleton and it is not so importantant
520// -zecke 520// -zecke
521 delete d; 521 delete d;
522} 522}
523 523
524bool ODevice::setSoftSuspend ( bool /*soft*/ ) 524bool ODevice::setSoftSuspend ( bool /*soft*/ )
525{ 525{
526 return false; 526 return false;
527} 527}
528 528
529//#include <linux/apm_bios.h> 529//#include <linux/apm_bios.h>
530 530
531#define APM_IOC_SUSPEND OD_IO( 'A', 2 ) 531#define APM_IOC_SUSPEND OD_IO( 'A', 2 )
532 532
533/** 533/**
534 * This method will try to suspend the device 534 * This method will try to suspend the device
535 * It only works if the user is the QWS Server and the apm application 535 * It only works if the user is the QWS Server and the apm application
536 * is installed. 536 * is installed.
537 * It tries to suspend and then waits some time cause some distributions 537 * It tries to suspend and then waits some time cause some distributions
538 * do have asynchronus apm implementations. 538 * do have asynchronus apm implementations.
539 * This method will either fail and return false or it'll suspend the 539 * This method will either fail and return false or it'll suspend the
540 * device and return once the device got woken up 540 * device and return once the device got woken up
541 * 541 *
542 * @return if the device got suspended 542 * @return if the device got suspended
543 */ 543 */
544bool ODevice::suspend ( ) 544bool ODevice::suspend ( )
545{ 545{
546 qDebug("ODevice::suspend"); 546 qDebug("ODevice::suspend");
547 if ( !isQWS( ) ) // only qwsserver is allowed to suspend 547 if ( !isQWS( ) ) // only qwsserver is allowed to suspend
548 return false; 548 return false;
549 549
550 if ( d-> m_model == Model_Unknown ) // better don't suspend in qvfb / on unkown devices 550 if ( d-> m_model == Model_Unknown ) // better don't suspend in qvfb / on unkown devices
551 return false; 551 return false;
552 552
553 bool res = false; 553 bool res = false;
554 554
555 struct timeval tvs, tvn; 555 struct timeval tvs, tvn;
556 ::gettimeofday ( &tvs, 0 ); 556 ::gettimeofday ( &tvs, 0 );
557 557
558 ::sync ( ); // flush fs caches 558 ::sync ( ); // flush fs caches
559 res = ( ::system ( "apm --suspend" ) == 0 ); 559 res = ( ::system ( "apm --suspend" ) == 0 );
560 560
561 // This is needed because the iPAQ apm implementation is asynchronous and we 561 // This is needed because the iPAQ apm implementation is asynchronous and we
562 // can not be sure when exactly the device is really suspended 562 // can not be sure when exactly the device is really suspended
563 // This can be deleted as soon as a stable familiar with a synchronous apm implementation exists. 563 // This can be deleted as soon as a stable familiar with a synchronous apm implementation exists.
564 564
565 if ( res ) { 565 if ( res ) {
566 do { // wait at most 1.5 sec: either suspend didn't work or the device resumed 566 do { // wait at most 1.5 sec: either suspend didn't work or the device resumed
567 ::usleep ( 200 * 1000 ); 567 ::usleep ( 200 * 1000 );
568 ::gettimeofday ( &tvn, 0 ); 568 ::gettimeofday ( &tvn, 0 );
569 } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < 1500 ); 569 } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < 1500 );
570 } 570 }
571 571
572 return res; 572 return res;
573} 573}
574 574
575//#include <linux/fb.h> better not rely on kernel headers in userspace ... 575//#include <linux/fb.h> better not rely on kernel headers in userspace ...
576 576
577#define FBIOBLANK OD_IO( 'F', 0x11 ) // 0x4611 577#define FBIOBLANK OD_IO( 'F', 0x11 ) // 0x4611
578 578
579/* VESA Blanking Levels */ 579/* VESA Blanking Levels */
580#define VESA_NO_BLANKING 0 580#define VESA_NO_BLANKING 0
581#define VESA_VSYNC_SUSPEND 1 581#define VESA_VSYNC_SUSPEND 1
582#define VESA_HSYNC_SUSPEND 2 582#define VESA_HSYNC_SUSPEND 2
583#define VESA_POWERDOWN 3 583#define VESA_POWERDOWN 3
584 584
585/** 585/**
586 * This sets the display on or off 586 * This sets the display on or off
587 */ 587 */
588bool ODevice::setDisplayStatus ( bool on ) 588bool ODevice::setDisplayStatus ( bool on )
589{ 589{
590 qDebug("ODevice::setDisplayStatus(%d)", on); 590 qDebug("ODevice::setDisplayStatus(%d)", on);
591 591
592 if ( d-> m_model == Model_Unknown ) 592 if ( d-> m_model == Model_Unknown )
593 return false; 593 return false;
594 594
595 bool res = false; 595 bool res = false;
596 int fd; 596 int fd;
597 597
598#ifdef QT_QWS_DEVFS
599 if (( fd = ::open ( "/dev/fb/0", O_RDWR )) >= 0 ) {
600#else
598 if (( fd = ::open ( "/dev/fb0", O_RDWR )) >= 0 ) { 601 if (( fd = ::open ( "/dev/fb0", O_RDWR )) >= 0 ) {
602#endif
599 res = ( ::ioctl ( fd, FBIOBLANK, on ? VESA_NO_BLANKING : VESA_POWERDOWN ) == 0 ); 603 res = ( ::ioctl ( fd, FBIOBLANK, on ? VESA_NO_BLANKING : VESA_POWERDOWN ) == 0 );
600 ::close ( fd ); 604 ::close ( fd );
601 } 605 }
602 return res; 606 return res;
603} 607}
604 608
605/** 609/**
606 * This sets the display brightness 610 * This sets the display brightness
607 * 611 *
608 * @param p The brightness to be set on a scale from 0 to 255 612 * @param p The brightness to be set on a scale from 0 to 255
609 * @return success or failure 613 * @return success or failure
610 */ 614 */
611bool ODevice::setDisplayBrightness ( int p) 615bool ODevice::setDisplayBrightness ( int p)
612{ 616{
613 Q_UNUSED( p ) 617 Q_UNUSED( p )
614 return false; 618 return false;
615} 619}
616 620
617/** 621/**
618 * @return returns the number of steppings on the brightness slider 622 * @return returns the number of steppings on the brightness slider
619 * in the Light-'n-Power settings. 623 * in the Light-'n-Power settings.
620 */ 624 */
621int ODevice::displayBrightnessResolution ( ) const 625int ODevice::displayBrightnessResolution ( ) const
622{ 626{
623 return 16; 627 return 16;
624} 628}
625 629
626/** 630/**
627 * This sets the display contrast 631 * This sets the display contrast
628 * @param p The contrast to be set on a scale from 0 to 255 632 * @param p The contrast to be set on a scale from 0 to 255
629 * @return success or failure 633 * @return success or failure
630 */ 634 */
631bool ODevice::setDisplayContrast ( int p) 635bool ODevice::setDisplayContrast ( int p)
632{ 636{
633 Q_UNUSED( p ) 637 Q_UNUSED( p )
634 return false; 638 return false;
635} 639}
636 640
637/** 641/**
638 * @return return the max value for the brightness settings slider 642 * @return return the max value for the brightness settings slider
639 * or 0 if the device doesn't support setting of a contrast 643 * or 0 if the device doesn't support setting of a contrast
640 */ 644 */
641int ODevice::displayContrastResolution ( ) const 645int ODevice::displayContrastResolution ( ) const
642{ 646{
643 return 0; 647 return 0;
644} 648}
645 649
646/** 650/**
647 * This returns the vendor as string 651 * This returns the vendor as string
648 * @return Vendor as QString 652 * @return Vendor as QString
649 */ 653 */
650QString ODevice::vendorString ( ) const 654QString ODevice::vendorString ( ) const
651{ 655{
652 return d-> m_vendorstr; 656 return d-> m_vendorstr;
653} 657}
654 658
655/** 659/**
656 * This returns the vendor as one of the values of OVendor 660 * This returns the vendor as one of the values of OVendor
657 * @return OVendor 661 * @return OVendor
658 */ 662 */
659OVendor ODevice::vendor ( ) const 663OVendor ODevice::vendor ( ) const
660{ 664{
661 return d-> m_vendor; 665 return d-> m_vendor;
662} 666}
663 667
664/** 668/**
665 * This returns the model as a string 669 * This returns the model as a string
666 * @return A string representing the model 670 * @return A string representing the model
667 */ 671 */
668QString ODevice::modelString ( ) const 672QString ODevice::modelString ( ) const
669{ 673{
670 return d-> m_modelstr; 674 return d-> m_modelstr;
671} 675}
672 676
673/** 677/**
674 * This does return the OModel used 678 * This does return the OModel used
675 */ 679 */
676OModel ODevice::model ( ) const 680OModel ODevice::model ( ) const
677{ 681{
678 return d-> m_model; 682 return d-> m_model;
679} 683}
680 684
681/** 685/**
682 * This does return the systen name 686 * This does return the systen name
683 */ 687 */
684QString ODevice::systemString ( ) const 688QString ODevice::systemString ( ) const
685{ 689{
686 return d-> m_systemstr; 690 return d-> m_systemstr;
687} 691}
688 692
689/** 693/**
690 * Return System as OSystem value 694 * Return System as OSystem value
691 */ 695 */
692OSystem ODevice::system ( ) const 696OSystem ODevice::system ( ) const
693{ 697{
694 return d-> m_system; 698 return d-> m_system;
695} 699}
696 700
697/** 701/**
698 * @return the version string of the base system 702 * @return the version string of the base system
699 */ 703 */
700QString ODevice::systemVersionString ( ) const 704QString ODevice::systemVersionString ( ) const
701{ 705{
702 return d-> m_sysverstr; 706 return d-> m_sysverstr;
703} 707}
704 708
705/** 709/**
706 * @return the current Transformation 710 * @return the current Transformation
707 */ 711 */
708Transformation ODevice::rotation ( ) const 712Transformation ODevice::rotation ( ) const
709{ 713{
710 VirtRotation rot; 714 VirtRotation rot;
711 ODevice* that =(ODevice* )this; 715 ODevice* that =(ODevice* )this;
712 that->virtual_hook( VIRTUAL_ROTATION, &rot ); 716 that->virtual_hook( VIRTUAL_ROTATION, &rot );
713 return rot.trans; 717 return rot.trans;
714} 718}
715 719
716/** 720/**
717 * @return the current rotation direction 721 * @return the current rotation direction
718 */ 722 */
719ODirection ODevice::direction ( ) const 723ODirection ODevice::direction ( ) const
720{ 724{
721 VirtDirection dir; 725 VirtDirection dir;
722 ODevice* that =(ODevice* )this; 726 ODevice* that =(ODevice* )this;
723 that->virtual_hook( VIRTUAL_DIRECTION, &dir ); 727 that->virtual_hook( VIRTUAL_DIRECTION, &dir );
724 return dir.direct; 728 return dir.direct;
725} 729}
726 730
727/** 731/**
728 * This plays an alarmSound 732 * This plays an alarmSound
729 */ 733 */
730void ODevice::alarmSound ( ) 734void ODevice::alarmSound ( )
731{ 735{
732#ifndef QT_NO_SOUND 736#ifndef QT_NO_SOUND
733 static Sound snd ( "alarm" ); 737 static Sound snd ( "alarm" );
734 738
735 if ( snd. isFinished ( )) 739 if ( snd. isFinished ( ))
736 snd. play ( ); 740 snd. play ( );
737#endif 741#endif
738} 742}
739 743
740/** 744/**
741 * This plays a key sound 745 * This plays a key sound
742 */ 746 */
743void ODevice::keySound ( ) 747void ODevice::keySound ( )
744{ 748{
745#ifndef QT_NO_SOUND 749#ifndef QT_NO_SOUND
746 static Sound snd ( "keysound" ); 750 static Sound snd ( "keysound" );
747 751
748 if ( snd. isFinished ( )) 752 if ( snd. isFinished ( ))
749 snd. play ( ); 753 snd. play ( );
750#endif 754#endif
751} 755}
752 756
753/** 757/**
754 * This plays a touch sound 758 * This plays a touch sound
755 */ 759 */
756void ODevice::touchSound ( ) 760void ODevice::touchSound ( )
757{ 761{
758#ifndef QT_NO_SOUND 762#ifndef QT_NO_SOUND
759 static Sound snd ( "touchsound" ); 763 static Sound snd ( "touchsound" );
760 764
761 if ( snd. isFinished ( )) 765 if ( snd. isFinished ( ))
762 snd. play ( ); 766 snd. play ( );
763#endif 767#endif
764} 768}
765 769
766/** 770/**
767 * This method will return a list of leds 771 * This method will return a list of leds
768 * available on this device 772 * available on this device
769 * @return a list of LEDs. 773 * @return a list of LEDs.
770 */ 774 */
771QValueList <OLed> ODevice::ledList ( ) const 775QValueList <OLed> ODevice::ledList ( ) const
772{ 776{
773 return QValueList <OLed> ( ); 777 return QValueList <OLed> ( );
774} 778}
775 779
776/** 780/**
777 * This does return the state of the LEDs 781 * This does return the state of the LEDs
778 */ 782 */
779QValueList <OLedState> ODevice::ledStateList ( OLed /*which*/ ) const 783QValueList <OLedState> ODevice::ledStateList ( OLed /*which*/ ) const
780{ 784{
781 return QValueList <OLedState> ( ); 785 return QValueList <OLedState> ( );
782} 786}
783 787
784/** 788/**
785 * @return the state for a given OLed 789 * @return the state for a given OLed
786 */ 790 */
787OLedState ODevice::ledState ( OLed /*which*/ ) const 791OLedState ODevice::ledState ( OLed /*which*/ ) const
788{ 792{
789 return Led_Off; 793 return Led_Off;
790} 794}
791 795
792/** 796/**
793 * Set the state for a LED 797 * Set the state for a LED
794 * @param which Which OLed to use 798 * @param which Which OLed to use
795 * @param st The state to set 799 * @param st The state to set
796 * @return success or failure 800 * @return success or failure
797 */ 801 */
798bool ODevice::setLedState ( OLed which, OLedState st ) 802bool ODevice::setLedState ( OLed which, OLedState st )
799{ 803{
800 Q_UNUSED( which ) 804 Q_UNUSED( which )
801 Q_UNUSED( st ) 805 Q_UNUSED( st )
802 return false; 806 return false;
803} 807}
804 808
805/** 809/**
806 * @return if the device has a light sensor 810 * @return if the device has a light sensor
807 */ 811 */
808bool ODevice::hasLightSensor ( ) const 812bool ODevice::hasLightSensor ( ) const
809{ 813{
810 return false; 814 return false;
811} 815}
812 816
813/** 817/**
814 * @return a value from the light sensor 818 * @return a value from the light sensor
815 */ 819 */
816int ODevice::readLightSensor ( ) 820int ODevice::readLightSensor ( )
817{ 821{
818 return -1; 822 return -1;
819} 823}
820 824
821/** 825/**
822 * @return the light sensor resolution 826 * @return the light sensor resolution
823 */ 827 */
824int ODevice::lightSensorResolution ( ) const 828int ODevice::lightSensorResolution ( ) const
825{ 829{
826 return 0; 830 return 0;
827} 831}
828 832
829/** 833/**
830 * @return if the device has a hinge sensor 834 * @return if the device has a hinge sensor
831 */ 835 */
832bool ODevice::hasHingeSensor ( ) const 836bool ODevice::hasHingeSensor ( ) const
833{ 837{
834 VirtHasHinge hing; 838 VirtHasHinge hing;
835 ODevice* that =(ODevice* )this; 839 ODevice* that =(ODevice* )this;
836 that->virtual_hook( VIRTUAL_HAS_HINGE, &hing ); 840 that->virtual_hook( VIRTUAL_HAS_HINGE, &hing );
837 return hing.hasHinge; 841 return hing.hasHinge;
838} 842}
839 843
840/** 844/**
841 * @return a value from the hinge sensor 845 * @return a value from the hinge sensor
842 */ 846 */
843OHingeStatus ODevice::readHingeSensor ( ) 847OHingeStatus ODevice::readHingeSensor ( )
844{ 848{
845 VirtHingeStatus hing; 849 VirtHingeStatus hing;
846 virtual_hook( VIRTUAL_HINGE, &hing ); 850 virtual_hook( VIRTUAL_HINGE, &hing );
847 return hing.hingeStat; 851 return hing.hingeStat;
848} 852}
849 853
850/** 854/**
851 * @return a list with CPU frequencies supported by the hardware 855 * @return a list with CPU frequencies supported by the hardware
852 */ 856 */
853const QStrList &ODevice::allowedCpuFrequencies ( ) const 857const QStrList &ODevice::allowedCpuFrequencies ( ) const
854{ 858{
855 return *d->m_cpu_frequencies; 859 return *d->m_cpu_frequencies;
856} 860}
857 861
858 862
859/** 863/**
860 * Set desired CPU frequency 864 * Set desired CPU frequency
861 * 865 *
862 * @param index index into d->m_cpu_frequencies of the frequency to be set 866 * @param index index into d->m_cpu_frequencies of the frequency to be set
863 */ 867 */
864bool ODevice::setCurrentCpuFrequency(uint index) 868bool ODevice::setCurrentCpuFrequency(uint index)
865{ 869{
866 if (index >= d->m_cpu_frequencies->count()) 870 if (index >= d->m_cpu_frequencies->count())
867 return false; 871 return false;
868 872
869 char *freq = d->m_cpu_frequencies->at(index); 873 char *freq = d->m_cpu_frequencies->at(index);
870 qWarning("set freq to %s", freq); 874 qWarning("set freq to %s", freq);
871 875
872 int fd; 876 int fd;
873 877
874 if ((fd = ::open("/proc/sys/cpu/0/speed", O_WRONLY)) >= 0) { 878 if ((fd = ::open("/proc/sys/cpu/0/speed", O_WRONLY)) >= 0) {
875 char writeCommand[50]; 879 char writeCommand[50];
876 const int count = sprintf(writeCommand, "%s\n", freq); 880 const int count = sprintf(writeCommand, "%s\n", freq);
877 int res = (::write(fd, writeCommand, count) != -1); 881 int res = (::write(fd, writeCommand, count) != -1);
878 ::close(fd); 882 ::close(fd);
879 return res; 883 return res;
880 } 884 }
881 885
882 return false; 886 return false;
883} 887}
884 888
885 889
886/** 890/**
887 * @return a list of hardware buttons 891 * @return a list of hardware buttons
888 */ 892 */
889const QValueList <ODeviceButton> &ODevice::buttons ( ) 893const QValueList <ODeviceButton> &ODevice::buttons ( )
890{ 894{
891 initButtons ( ); 895 initButtons ( );
892 896
893 return *d-> m_buttons; 897 return *d-> m_buttons;
894} 898}
895 899
896/** 900/**
897 * @return The amount of time that would count as a hold 901 * @return The amount of time that would count as a hold
898 */ 902 */
899uint ODevice::buttonHoldTime ( ) const 903uint ODevice::buttonHoldTime ( ) const
900{ 904{
901 return d-> m_holdtime; 905 return d-> m_holdtime;
902} 906}
903 907
904/** 908/**
905 * This method return a ODeviceButton for a key code 909 * This method return a ODeviceButton for a key code
906 * or 0 if no special hardware button is available for the device 910 * or 0 if no special hardware button is available for the device
907 * 911 *
908 * @return The devicebutton or 0l 912 * @return The devicebutton or 0l
909 * @see ODeviceButton 913 * @see ODeviceButton
910 */ 914 */
911const ODeviceButton *ODevice::buttonForKeycode ( ushort code ) 915const ODeviceButton *ODevice::buttonForKeycode ( ushort code )
912{ 916{
913 initButtons ( ); 917 initButtons ( );
914 918
915 for ( QValueListConstIterator<ODeviceButton> it = d-> m_buttons-> begin ( ); it != d-> m_buttons-> end ( ); ++it ) { 919 for ( QValueListConstIterator<ODeviceButton> it = d-> m_buttons-> begin ( ); it != d-> m_buttons-> end ( ); ++it ) {
916 if ( (*it). keycode ( ) == code ) 920 if ( (*it). keycode ( ) == code )
917 return &(*it); 921 return &(*it);
918 } 922 }
919 return 0; 923 return 0;
920} 924}
921 925
922void ODevice::reloadButtonMapping ( ) 926void ODevice::reloadButtonMapping ( )
923{ 927{
924 initButtons ( ); 928 initButtons ( );
925 929
926 Config cfg ( "ButtonSettings" ); 930 Config cfg ( "ButtonSettings" );
927 931
928 for ( uint i = 0; i < d-> m_buttons-> count ( ); i++ ) { 932 for ( uint i = 0; i < d-> m_buttons-> count ( ); i++ ) {
929 ODeviceButton &b = ( *d-> m_buttons ) [i]; 933 ODeviceButton &b = ( *d-> m_buttons ) [i];
930 QString group = "Button" + QString::number ( i ); 934 QString group = "Button" + QString::number ( i );
931 935
932 QCString pch, hch; 936 QCString pch, hch;
933 QCString pm, hm; 937 QCString pm, hm;
934 QByteArray pdata, hdata; 938 QByteArray pdata, hdata;
935 939
936 if ( cfg. hasGroup ( group )) { 940 if ( cfg. hasGroup ( group )) {
937 cfg. setGroup ( group ); 941 cfg. setGroup ( group );
938 pch = cfg. readEntry ( "PressedActionChannel" ). latin1 ( ); 942 pch = cfg. readEntry ( "PressedActionChannel" ). latin1 ( );
939 pm = cfg. readEntry ( "PressedActionMessage" ). latin1 ( ); 943 pm = cfg. readEntry ( "PressedActionMessage" ). latin1 ( );
940 // pdata = decodeBase64 ( buttonFile. readEntry ( "PressedActionArgs" )); 944 // pdata = decodeBase64 ( buttonFile. readEntry ( "PressedActionArgs" ));
941 945
942 hch = cfg. readEntry ( "HeldActionChannel" ). latin1 ( ); 946 hch = cfg. readEntry ( "HeldActionChannel" ). latin1 ( );
943 hm = cfg. readEntry ( "HeldActionMessage" ). latin1 ( ); 947 hm = cfg. readEntry ( "HeldActionMessage" ). latin1 ( );
944 // hdata = decodeBase64 ( buttonFile. readEntry ( "HeldActionArgs" )); 948 // hdata = decodeBase64 ( buttonFile. readEntry ( "HeldActionArgs" ));
945 } 949 }
946 950
947 b. setPressedAction ( OQCopMessage ( pch, pm, pdata )); 951 b. setPressedAction ( OQCopMessage ( pch, pm, pdata ));
948 952
949 b. setHeldAction ( OQCopMessage ( hch, hm, hdata )); 953 b. setHeldAction ( OQCopMessage ( hch, hm, hdata ));
950 } 954 }
951} 955}
952 956
953void ODevice::remapPressedAction ( int button, const OQCopMessage &action ) 957void ODevice::remapPressedAction ( int button, const OQCopMessage &action )
954{ 958{
955 initButtons ( ); 959 initButtons ( );
956 960
957 QString mb_chan; 961 QString mb_chan;
958 962
959 if ( button >= (int) d-> m_buttons-> count ( )) 963 if ( button >= (int) d-> m_buttons-> count ( ))
960 return; 964 return;
961 965
962 ODeviceButton &b = ( *d-> m_buttons ) [button]; 966 ODeviceButton &b = ( *d-> m_buttons ) [button];
963 b. setPressedAction ( action ); 967 b. setPressedAction ( action );
964 968
965 mb_chan=b. pressedAction ( ). channel ( ); 969 mb_chan=b. pressedAction ( ). channel ( );
966 970
967 Config buttonFile ( "ButtonSettings" ); 971 Config buttonFile ( "ButtonSettings" );
968 buttonFile. setGroup ( "Button" + QString::number ( button )); 972 buttonFile. setGroup ( "Button" + QString::number ( button ));
969 buttonFile. writeEntry ( "PressedActionChannel", (const char*) mb_chan); 973 buttonFile. writeEntry ( "PressedActionChannel", (const char*) mb_chan);
970 buttonFile. writeEntry ( "PressedActionMessage", (const char*) b. pressedAction ( ). message ( )); 974 buttonFile. writeEntry ( "PressedActionMessage", (const char*) b. pressedAction ( ). message ( ));
971 975
972 //buttonFile. writeEntry ( "PressedActionArgs", encodeBase64 ( b. pressedAction ( ). data ( ))); 976 //buttonFile. writeEntry ( "PressedActionArgs", encodeBase64 ( b. pressedAction ( ). data ( )));
973 977
974 QCopEnvelope ( "QPE/System", "deviceButtonMappingChanged()" ); 978 QCopEnvelope ( "QPE/System", "deviceButtonMappingChanged()" );
975} 979}
976 980
977void ODevice::remapHeldAction ( int button, const OQCopMessage &action ) 981void ODevice::remapHeldAction ( int button, const OQCopMessage &action )
978{ 982{
979 initButtons ( ); 983 initButtons ( );
980 984
981 if ( button >= (int) d-> m_buttons-> count ( )) 985 if ( button >= (int) d-> m_buttons-> count ( ))
982 return; 986 return;
983 987
984 ODeviceButton &b = ( *d-> m_buttons ) [button]; 988 ODeviceButton &b = ( *d-> m_buttons ) [button];
985 b. setHeldAction ( action ); 989 b. setHeldAction ( action );
986 990
987 Config buttonFile ( "ButtonSettings" ); 991 Config buttonFile ( "ButtonSettings" );
988 buttonFile. setGroup ( "Button" + QString::number ( button )); 992 buttonFile. setGroup ( "Button" + QString::number ( button ));
989 buttonFile. writeEntry ( "HeldActionChannel", (const char *) b. heldAction ( ). channel ( )); 993 buttonFile. writeEntry ( "HeldActionChannel", (const char *) b. heldAction ( ). channel ( ));
990 buttonFile. writeEntry ( "HeldActionMessage", (const char *) b. heldAction ( ). message ( )); 994 buttonFile. writeEntry ( "HeldActionMessage", (const char *) b. heldAction ( ). message ( ));
991 995
992 //buttonFile. writeEntry ( "HeldActionArgs", decodeBase64 ( b. heldAction ( ). data ( ))); 996 //buttonFile. writeEntry ( "HeldActionArgs", decodeBase64 ( b. heldAction ( ). data ( )));
993 997
994 QCopEnvelope ( "QPE/System", "deviceButtonMappingChanged()" ); 998 QCopEnvelope ( "QPE/System", "deviceButtonMappingChanged()" );
995} 999}
996void ODevice::virtual_hook(int id, void* data){ 1000void ODevice::virtual_hook(int id, void* data){
997 switch( id ) { 1001 switch( id ) {
998 case VIRTUAL_ROTATION:{ 1002 case VIRTUAL_ROTATION:{
999 VirtRotation* rot = reinterpret_cast<VirtRotation*>( data ); 1003 VirtRotation* rot = reinterpret_cast<VirtRotation*>( data );
1000 rot->trans = d->m_rotation; 1004 rot->trans = d->m_rotation;
1001 break; 1005 break;
1002 } 1006 }
1003 case VIRTUAL_DIRECTION:{ 1007 case VIRTUAL_DIRECTION:{
1004 VirtDirection *dir = reinterpret_cast<VirtDirection*>( data ); 1008 VirtDirection *dir = reinterpret_cast<VirtDirection*>( data );
1005 dir->direct = d->m_direction; 1009 dir->direct = d->m_direction;
1006 break; 1010 break;
1007 } 1011 }
1008 case VIRTUAL_HAS_HINGE:{ 1012 case VIRTUAL_HAS_HINGE:{
1009 VirtHasHinge *hin = reinterpret_cast<VirtHasHinge*>( data ); 1013 VirtHasHinge *hin = reinterpret_cast<VirtHasHinge*>( data );
1010 hin->hasHinge = false; 1014 hin->hasHinge = false;
1011 break; 1015 break;
1012 } 1016 }
1013 case VIRTUAL_HINGE:{ 1017 case VIRTUAL_HINGE:{
1014 VirtHingeStatus *hin = reinterpret_cast<VirtHingeStatus*>( data ); 1018 VirtHingeStatus *hin = reinterpret_cast<VirtHingeStatus*>( data );
1015 hin->hingeStat = CASE_UNKNOWN; 1019 hin->hingeStat = CASE_UNKNOWN;
1016 break; 1020 break;
1017 } 1021 }
1018 } 1022 }
1019} 1023}
1020 1024
1021/************************************************** 1025/**************************************************
1022 * 1026 *
1023 * Yopy 3500/3700 1027 * Yopy 3500/3700
1024 * 1028 *
1025 **************************************************/ 1029 **************************************************/
1026 1030
1027bool Yopy::isYopy ( ) 1031bool Yopy::isYopy ( )
1028{ 1032{
1029 QFile f( "/proc/cpuinfo" ); 1033 QFile f( "/proc/cpuinfo" );
1030 if ( f. open ( IO_ReadOnly ) ) { 1034 if ( f. open ( IO_ReadOnly ) ) {
1031 QTextStream ts ( &f ); 1035 QTextStream ts ( &f );
1032 QString line; 1036 QString line;
1033 while( line = ts. readLine ( ) ) { 1037 while( line = ts. readLine ( ) ) {
1034 if ( line. left ( 8 ) == "Hardware" ) { 1038 if ( line. left ( 8 ) == "Hardware" ) {
1035 int loc = line. find ( ":" ); 1039 int loc = line. find ( ":" );
1036 if ( loc != -1 ) { 1040 if ( loc != -1 ) {
1037 QString model = 1041 QString model =
1038 line. mid ( loc + 2 ). simplifyWhiteSpace( ); 1042 line. mid ( loc + 2 ). simplifyWhiteSpace( );
1039 return ( model == "Yopy" ); 1043 return ( model == "Yopy" );
1040 } 1044 }
1041 } 1045 }
1042 } 1046 }
1043 } 1047 }
1044 return false; 1048 return false;
1045} 1049}
1046 1050
1047void Yopy::init ( ) 1051void Yopy::init ( )
1048{ 1052{
1049 d-> m_vendorstr = "G.Mate"; 1053 d-> m_vendorstr = "G.Mate";
1050 d-> m_vendor = Vendor_GMate; 1054 d-> m_vendor = Vendor_GMate;
1051 d-> m_modelstr = "Yopy3700"; 1055 d-> m_modelstr = "Yopy3700";
1052 d-> m_model = Model_Yopy_3700; 1056 d-> m_model = Model_Yopy_3700;
1053 d-> m_rotation = Rot0; 1057 d-> m_rotation = Rot0;
1054 1058
1055 d-> m_systemstr = "Linupy"; 1059 d-> m_systemstr = "Linupy";
1056 d-> m_system = System_Linupy; 1060 d-> m_system = System_Linupy;
1057 1061
1058 QFile f ( "/etc/issue" ); 1062 QFile f ( "/etc/issue" );
1059 if ( f. open ( IO_ReadOnly )) { 1063 if ( f. open ( IO_ReadOnly )) {
1060 QTextStream ts ( &f ); 1064 QTextStream ts ( &f );
1061 ts.readLine(); 1065 ts.readLine();
1062 d-> m_sysverstr = ts. readLine ( ); 1066 d-> m_sysverstr = ts. readLine ( );
1063 f. close ( ); 1067 f. close ( );
1064 } 1068 }
1065} 1069}
1066 1070
1067void Yopy::initButtons ( ) 1071void Yopy::initButtons ( )
1068{ 1072{
1069 if ( d-> m_buttons ) 1073 if ( d-> m_buttons )
1070 return; 1074 return;
1071 1075
1072 d-> m_buttons = new QValueList <ODeviceButton>; 1076 d-> m_buttons = new QValueList <ODeviceButton>;
1073 1077
1074 for (uint i = 0; i < ( sizeof( yopy_buttons ) / sizeof(yopy_button)); i++) { 1078 for (uint i = 0; i < ( sizeof( yopy_buttons ) / sizeof(yopy_button)); i++) {
1075 1079
1076 yopy_button *ib = yopy_buttons + i; 1080 yopy_button *ib = yopy_buttons + i;
1077 1081
1078 ODeviceButton b; 1082 ODeviceButton b;
1079 1083
1080 b. setKeycode ( ib-> code ); 1084 b. setKeycode ( ib-> code );
1081 b. setUserText ( QObject::tr ( "Button", ib-> utext )); 1085 b. setUserText ( QObject::tr ( "Button", ib-> utext ));
1082 b. setPixmap ( Resource::loadPixmap ( ib-> pix )); 1086 b. setPixmap ( Resource::loadPixmap ( ib-> pix ));
1083 b. setFactoryPresetPressedAction 1087 b. setFactoryPresetPressedAction
1084 (OQCopMessage(makeChannel(ib->fpressedservice), ib->fpressedaction)); 1088 (OQCopMessage(makeChannel(ib->fpressedservice), ib->fpressedaction));
1085 b. setFactoryPresetHeldAction 1089 b. setFactoryPresetHeldAction
1086 (OQCopMessage(makeChannel(ib->fheldservice), ib->fheldaction)); 1090 (OQCopMessage(makeChannel(ib->fheldservice), ib->fheldaction));
1087 1091
1088 d-> m_buttons-> append ( b ); 1092 d-> m_buttons-> append ( b );
1089 } 1093 }
1090 reloadButtonMapping ( ); 1094 reloadButtonMapping ( );
1091 1095
1092 QCopChannel *sysch = new QCopChannel("QPE/System", this); 1096 QCopChannel *sysch = new QCopChannel("QPE/System", this);
1093 connect(sysch, SIGNAL(received(const QCString&,const QByteArray&)), 1097 connect(sysch, SIGNAL(received(const QCString&,const QByteArray&)),
1094 this, SLOT(systemMessage(const QCString&,const QByteArray&))); 1098 this, SLOT(systemMessage(const QCString&,const QByteArray&)));
1095} 1099}
1096 1100
1097bool Yopy::suspend() 1101bool Yopy::suspend()
1098{ 1102{
1099 /* Opie for Yopy does not implement its own power management at the 1103 /* Opie for Yopy does not implement its own power management at the
1100 moment. The public version runs parallel to X, and relies on the 1104 moment. The public version runs parallel to X, and relies on the
1101 existing power management features. */ 1105 existing power management features. */
1102 return false; 1106 return false;
1103} 1107}
1104 1108
1105bool Yopy::setDisplayBrightness(int /*bright*/) 1109bool Yopy::setDisplayBrightness(int /*bright*/)
1106{ 1110{
1107 /* The code here works, but is disabled as the current version runs 1111 /* The code here works, but is disabled as the current version runs
1108 parallel to X, and relies on the existing backlight demon. */ 1112 parallel to X, and relies on the existing backlight demon. */
1109#if 0 1113#if 0
1110 if ( QFile::exists("/proc/sys/pm/light") ) { 1114 if ( QFile::exists("/proc/sys/pm/light") ) {
1111 int fd = ::open("/proc/sys/pm/light", O_WRONLY); 1115 int fd = ::open("/proc/sys/pm/light", O_WRONLY);
1112 if (fd >= 0 ) { 1116 if (fd >= 0 ) {
1113 if (bright) 1117 if (bright)
1114 ::write(fd, "1\n", 2); 1118 ::write(fd, "1\n", 2);
1115 else 1119 else
1116 ::write(fd, "0\n", 2); 1120 ::write(fd, "0\n", 2);
1117 ::close(fd); 1121 ::close(fd);
1118 return true; 1122 return true;
1119 } 1123 }
1120 } 1124 }
1121#endif 1125#endif
1122 return false; 1126 return false;
1123} 1127}
1124 1128
1125int Yopy::displayBrightnessResolution() const 1129int Yopy::displayBrightnessResolution() const
1126{ 1130{
1127 return 2; 1131 return 2;
1128} 1132}
1129 1133
1130/************************************************** 1134/**************************************************
1131 * 1135 *
1132 * iPAQ 1136 * iPAQ
1133 * 1137 *
1134 **************************************************/ 1138 **************************************************/
1135 1139
1136void iPAQ::init ( ) 1140void iPAQ::init ( )
1137{ 1141{
1138 d-> m_vendorstr = "HP"; 1142 d-> m_vendorstr = "HP";
1139 d-> m_vendor = Vendor_HP; 1143 d-> m_vendor = Vendor_HP;
1140 1144
1141 QFile f ( "/proc/hal/model" ); 1145 QFile f ( "/proc/hal/model" );
1142 1146
1143 if ( f. open ( IO_ReadOnly )) { 1147 if ( f. open ( IO_ReadOnly )) {
1144 QTextStream ts ( &f ); 1148 QTextStream ts ( &f );
1145 1149
1146 d-> m_modelstr = "H" + ts. readLine ( ); 1150 d-> m_modelstr = "H" + ts. readLine ( );
1147 1151
1148 if ( d-> m_modelstr == "H3100" ) 1152 if ( d-> m_modelstr == "H3100" )
1149 d-> m_model = Model_iPAQ_H31xx; 1153 d-> m_model = Model_iPAQ_H31xx;
1150 else if ( d-> m_modelstr == "H3600" ) 1154 else if ( d-> m_modelstr == "H3600" )
1151 d-> m_model = Model_iPAQ_H36xx; 1155 d-> m_model = Model_iPAQ_H36xx;
1152 else if ( d-> m_modelstr == "H3700" ) 1156 else if ( d-> m_modelstr == "H3700" )
1153 d-> m_model = Model_iPAQ_H37xx; 1157 d-> m_model = Model_iPAQ_H37xx;
1154 else if ( d-> m_modelstr == "H3800" ) 1158 else if ( d-> m_modelstr == "H3800" )
1155 d-> m_model = Model_iPAQ_H38xx; 1159 d-> m_model = Model_iPAQ_H38xx;
1156 else if ( d-> m_modelstr == "H3900" ) 1160 else if ( d-> m_modelstr == "H3900" )
1157 d-> m_model = Model_iPAQ_H39xx; 1161 d-> m_model = Model_iPAQ_H39xx;
1158 else if ( d-> m_modelstr == "H5400" ) 1162 else if ( d-> m_modelstr == "H5400" )
1159 d-> m_model = Model_iPAQ_H5xxx; 1163 d-> m_model = Model_iPAQ_H5xxx;
1160 else 1164 else
1161 d-> m_model = Model_Unknown; 1165 d-> m_model = Model_Unknown;
1162 1166
1163 f. close ( ); 1167 f. close ( );
1164 } 1168 }
1165 1169
1166 switch ( d-> m_model ) { 1170 switch ( d-> m_model ) {
1167 case Model_iPAQ_H31xx: 1171 case Model_iPAQ_H31xx:
1168 case Model_iPAQ_H38xx: 1172 case Model_iPAQ_H38xx:
1169 d-> m_rotation = Rot90; 1173 d-> m_rotation = Rot90;
1170 break; 1174 break;
1171 case Model_iPAQ_H36xx: 1175 case Model_iPAQ_H36xx:
1172 case Model_iPAQ_H37xx: 1176 case Model_iPAQ_H37xx:
1173 case Model_iPAQ_H39xx: 1177 case Model_iPAQ_H39xx:
1174 1178
1175 default: 1179 default:
1176 d-> m_rotation = Rot270; 1180 d-> m_rotation = Rot270;
1177 break; 1181 break;
1178 case Model_iPAQ_H5xxx: 1182 case Model_iPAQ_H5xxx:
1179 d-> m_rotation = Rot0; 1183 d-> m_rotation = Rot0;
1180 } 1184 }
1181 1185
1182 f. setName ( "/etc/familiar-version" ); 1186 f. setName ( "/etc/familiar-version" );
1183 if ( f. open ( IO_ReadOnly )) { 1187 if ( f. open ( IO_ReadOnly )) {
1184 d-> m_systemstr = "Familiar"; 1188 d-> m_systemstr = "Familiar";
1185 d-> m_system = System_Familiar; 1189 d-> m_system = System_Familiar;
1186 1190
1187 QTextStream ts ( &f ); 1191 QTextStream ts ( &f );
1188 d-> m_sysverstr = ts. readLine ( ). mid ( 10 ); 1192 d-> m_sysverstr = ts. readLine ( ). mid ( 10 );
1189 1193
1190 f. close ( ); 1194 f. close ( );
1191 } else { 1195 } else {
1192 f. setName ( "/etc/oz_version" ); 1196 f. setName ( "/etc/oz_version" );
1193 1197
1194 if ( f. open ( IO_ReadOnly )) { 1198 if ( f. open ( IO_ReadOnly )) {
1195 d-> m_systemstr = "OpenEmbedded/iPaq"; 1199 d-> m_systemstr = "OpenEmbedded/iPaq";
1196 d-> m_system = System_Familiar; 1200 d-> m_system = System_Familiar;
1197 1201
1198 QTextStream ts ( &f ); 1202 QTextStream ts ( &f );
1199 ts.setDevice ( &f ); 1203 ts.setDevice ( &f );
1200 d-> m_sysverstr = ts. readLine ( ); 1204 d-> m_sysverstr = ts. readLine ( );
1201 f. close ( ); 1205 f. close ( );
1202 } 1206 }
1203 } 1207 }
1204 1208
1205 1209
1206 1210
1207 1211
1208 1212
1209 m_leds [0] = m_leds [1] = Led_Off; 1213 m_leds [0] = m_leds [1] = Led_Off;
1210 1214
1211 m_power_timer = 0; 1215 m_power_timer = 0;
1212 1216
1213} 1217}
1214 1218
1215void iPAQ::initButtons ( ) 1219void iPAQ::initButtons ( )
1216{ 1220{
1217 if ( d-> m_buttons ) 1221 if ( d-> m_buttons )
1218 return; 1222 return;
1219 1223
1220 if ( isQWS( ) ) 1224 if ( isQWS( ) )
1221 QWSServer::setKeyboardFilter ( this ); 1225 QWSServer::setKeyboardFilter ( this );
1222 1226
1223 d-> m_buttons = new QValueList <ODeviceButton>; 1227 d-> m_buttons = new QValueList <ODeviceButton>;
1224 1228
1225 for ( uint i = 0; i < ( sizeof( ipaq_buttons ) / sizeof( i_button )); i++ ) { 1229 for ( uint i = 0; i < ( sizeof( ipaq_buttons ) / sizeof( i_button )); i++ ) {
1226 i_button *ib = ipaq_buttons + i; 1230 i_button *ib = ipaq_buttons + i;
1227 ODeviceButton b; 1231 ODeviceButton b;
1228 1232
1229 if (( ib-> model & d-> m_model ) == d-> m_model ) { 1233 if (( ib-> model & d-> m_model ) == d-> m_model ) {
1230 b. setKeycode ( ib-> code ); 1234 b. setKeycode ( ib-> code );
1231 b. setUserText ( QObject::tr ( "Button", ib-> utext )); 1235 b. setUserText ( QObject::tr ( "Button", ib-> utext ));
1232 b. setPixmap ( Resource::loadPixmap ( ib-> pix )); 1236 b. setPixmap ( Resource::loadPixmap ( ib-> pix ));
1233 b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( ib-> fpressedservice ), ib-> fpressedaction )); 1237 b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( ib-> fpressedservice ), ib-> fpressedaction ));
1234 b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( ib-> fheldservice ), ib-> fheldaction )); 1238 b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( ib-> fheldservice ), ib-> fheldaction ));
1235 1239
1236 d-> m_buttons-> append ( b ); 1240 d-> m_buttons-> append ( b );
1237 } 1241 }
1238 } 1242 }
1239 reloadButtonMapping ( ); 1243 reloadButtonMapping ( );
1240 1244
1241 QCopChannel *sysch = new QCopChannel ( "QPE/System", this ); 1245 QCopChannel *sysch = new QCopChannel ( "QPE/System", this );
1242 connect ( sysch, SIGNAL( received(const QCString&,const QByteArray&)), this, SLOT( systemMessage(const QCString&,const QByteArray&))); 1246 connect ( sysch, SIGNAL( received(const QCString&,const QByteArray&)), this, SLOT( systemMessage(const QCString&,const QByteArray&)));
1243} 1247}
1244 1248
1245 1249
1246//#include <linux/h3600_ts.h> // including kernel headers is evil ... 1250//#include <linux/h3600_ts.h> // including kernel headers is evil ...
1247 1251
1248typedef struct { 1252typedef struct {
1249 unsigned char OffOnBlink; /* 0=off 1=on 2=Blink */ 1253 unsigned char OffOnBlink; /* 0=off 1=on 2=Blink */
1250 unsigned char TotalTime; /* Units of 5 seconds */ 1254 unsigned char TotalTime; /* Units of 5 seconds */
1251 unsigned char OnTime; /* units of 100m/s */ 1255 unsigned char OnTime; /* units of 100m/s */
1252 unsigned char OffTime; /* units of 100m/s */ 1256 unsigned char OffTime; /* units of 100m/s */
1253} LED_IN; 1257} LED_IN;
1254 1258
1255typedef struct { 1259typedef struct {
1256 unsigned char mode; 1260 unsigned char mode;
1257 unsigned char pwr; 1261 unsigned char pwr;
1258 unsigned char brightness; 1262 unsigned char brightness;
1259} FLITE_IN; 1263} FLITE_IN;
1260 1264
1261#define LED_ON OD_IOW( 'f', 5, LED_IN ) 1265#define LED_ON OD_IOW( 'f', 5, LED_IN )
1262#define FLITE_ON OD_IOW( 'f', 7, FLITE_IN ) 1266#define FLITE_ON OD_IOW( 'f', 7, FLITE_IN )
1263 1267
1264 1268
1265QValueList <OLed> iPAQ::ledList ( ) const 1269QValueList <OLed> iPAQ::ledList ( ) const
1266{ 1270{
1267 QValueList <OLed> vl; 1271 QValueList <OLed> vl;
1268 vl << Led_Power; 1272 vl << Led_Power;
1269 1273
1270 if ( d-> m_model == Model_iPAQ_H38xx ) 1274 if ( d-> m_model == Model_iPAQ_H38xx )
1271 vl << Led_BlueTooth; 1275 vl << Led_BlueTooth;
1272 return vl; 1276 return vl;
1273} 1277}
1274 1278
1275QValueList <OLedState> iPAQ::ledStateList ( OLed l ) const 1279QValueList <OLedState> iPAQ::ledStateList ( OLed l ) const
1276{ 1280{
1277 QValueList <OLedState> vl; 1281 QValueList <OLedState> vl;
1278 1282
1279 if ( l == Led_Power ) 1283 if ( l == Led_Power )
1280 vl << Led_Off << Led_On << Led_BlinkSlow << Led_BlinkFast; 1284 vl << Led_Off << Led_On << Led_BlinkSlow << Led_BlinkFast;
1281 else if ( l == Led_BlueTooth && d-> m_model == Model_iPAQ_H38xx ) 1285 else if ( l == Led_BlueTooth && d-> m_model == Model_iPAQ_H38xx )
1282 vl << Led_Off; // << Led_On << ??? 1286 vl << Led_Off; // << Led_On << ???
1283 1287
1284 return vl; 1288 return vl;
1285} 1289}
1286 1290
1287OLedState iPAQ::ledState ( OLed l ) const 1291OLedState iPAQ::ledState ( OLed l ) const
1288{ 1292{
1289 switch ( l ) { 1293 switch ( l ) {
1290 case Led_Power: 1294 case Led_Power:
1291 return m_leds [0]; 1295 return m_leds [0];
1292 case Led_BlueTooth: 1296 case Led_BlueTooth:
1293 return m_leds [1]; 1297 return m_leds [1];
1294 default: 1298 default:
1295 return Led_Off; 1299 return Led_Off;
1296 } 1300 }
1297} 1301}
1298 1302
1299bool iPAQ::setLedState ( OLed l, OLedState st ) 1303bool iPAQ::setLedState ( OLed l, OLedState st )
1300{ 1304{
1301 static int fd = ::open ( "/dev/touchscreen/0", O_RDWR | O_NONBLOCK ); 1305 static int fd = ::open ( "/dev/touchscreen/0", O_RDWR | O_NONBLOCK );
1302 1306
1303 if ( l == Led_Power ) { 1307 if ( l == Led_Power ) {
1304 if ( fd >= 0 ) { 1308 if ( fd >= 0 ) {
1305 LED_IN leds; 1309 LED_IN leds;
1306 ::memset ( &leds, 0, sizeof( leds )); 1310 ::memset ( &leds, 0, sizeof( leds ));
1307 leds. TotalTime = 0; 1311 leds. TotalTime = 0;
1308 leds. OnTime = 0; 1312 leds. OnTime = 0;
1309 leds. OffTime = 1; 1313 leds. OffTime = 1;
1310 leds. OffOnBlink = 2; 1314 leds. OffOnBlink = 2;
1311 1315
1312 switch ( st ) { 1316 switch ( st ) {
1313 case Led_Off : leds. OffOnBlink = 0; break; 1317 case Led_Off : leds. OffOnBlink = 0; break;
1314 case Led_On : leds. OffOnBlink = 1; break; 1318 case Led_On : leds. OffOnBlink = 1; break;
1315 case Led_BlinkSlow: leds. OnTime = 10; leds. OffTime = 10; break; 1319 case Led_BlinkSlow: leds. OnTime = 10; leds. OffTime = 10; break;
1316 case Led_BlinkFast: leds. OnTime = 5; leds. OffTime = 5; break; 1320 case Led_BlinkFast: leds. OnTime = 5; leds. OffTime = 5; break;
1317 } 1321 }
1318 1322
1319 if ( ::ioctl ( fd, LED_ON, &leds ) >= 0 ) { 1323 if ( ::ioctl ( fd, LED_ON, &leds ) >= 0 ) {
1320 m_leds [0] = st; 1324 m_leds [0] = st;
1321 return true; 1325 return true;
1322 } 1326 }
1323 } 1327 }
1324 } 1328 }
1325 return false; 1329 return false;
1326} 1330}
1327 1331
1328 1332
1329bool iPAQ::filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat ) 1333bool iPAQ::filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat )
1330{ 1334{
1331 int newkeycode = keycode; 1335 int newkeycode = keycode;
1332 1336
1333 switch ( keycode ) { 1337 switch ( keycode ) {
1334 // H38xx/H39xx have no "Q" key anymore - this is now the Mail key 1338 // H38xx/H39xx have no "Q" key anymore - this is now the Mail key
1335 case HardKey_Menu: { 1339 case HardKey_Menu: {
1336 if (( d-> m_model == Model_iPAQ_H38xx ) || 1340 if (( d-> m_model == Model_iPAQ_H38xx ) ||
1337 ( d-> m_model == Model_iPAQ_H39xx ) || 1341 ( d-> m_model == Model_iPAQ_H39xx ) ||
1338 ( d-> m_model == Model_iPAQ_H5xxx)) { 1342 ( d-> m_model == Model_iPAQ_H5xxx)) {
1339 newkeycode = HardKey_Mail; 1343 newkeycode = HardKey_Mail;
1340 } 1344 }
1341 break; 1345 break;
1342 } 1346 }
1343 1347
1344 // Rotate cursor keys 180° or 270° 1348 // Rotate cursor keys 180° or 270°
1345 case Key_Left : 1349 case Key_Left :
1346 case Key_Right: 1350 case Key_Right:
1347 case Key_Up : 1351 case Key_Up :
1348 case Key_Down : { 1352 case Key_Down : {
1349 1353
1350 if (( d-> m_model == Model_iPAQ_H31xx ) || 1354 if (( d-> m_model == Model_iPAQ_H31xx ) ||
1351 ( d-> m_model == Model_iPAQ_H38xx )) { 1355 ( d-> m_model == Model_iPAQ_H38xx )) {
1352 newkeycode = Key_Left + ( keycode - Key_Left + 2 ) % 4; 1356 newkeycode = Key_Left + ( keycode - Key_Left + 2 ) % 4;
1353 } 1357 }
1354 // Rotate the cursor keys by 270° 1358 // Rotate the cursor keys by 270°
1355 // keycode - Key_Left = position of the button starting from left clockwise 1359 // keycode - Key_Left = position of the button starting from left clockwise
1356 // add the rotation to it and modolo. No we've the original offset 1360 // add the rotation to it and modolo. No we've the original offset
1357 // add the offset to the Key_Left key 1361 // add the offset to the Key_Left key
1358 if ( d-> m_model == Model_iPAQ_H5xxx ) 1362 if ( d-> m_model == Model_iPAQ_H5xxx )
1359 newkeycode = Key_Left + ( keycode - Key_Left + 3 ) % 4; 1363 newkeycode = Key_Left + ( keycode - Key_Left + 3 ) % 4;
1360 break; 1364 break;
1361 } 1365 }
1362 1366
1363 // map Power Button short/long press to F34/F35 1367 // map Power Button short/long press to F34/F35
1364 case Key_SysReq: { 1368 case Key_SysReq: {
1365 if ( isPress ) { 1369 if ( isPress ) {
1366 if ( m_power_timer ) 1370 if ( m_power_timer )
1367 killTimer ( m_power_timer ); 1371 killTimer ( m_power_timer );
1368 m_power_timer = startTimer ( 500 ); 1372 m_power_timer = startTimer ( 500 );
1369 } 1373 }
1370 else if ( m_power_timer ) { 1374 else if ( m_power_timer ) {
1371 killTimer ( m_power_timer ); 1375 killTimer ( m_power_timer );
1372 m_power_timer = 0; 1376 m_power_timer = 0;
1373 QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, true, false ); 1377 QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, true, false );
1374 QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, false, false ); 1378 QWSServer::sendKeyEvent ( -1, HardKey_Suspend, 0, false, false );
1375 } 1379 }
1376 newkeycode = Key_unknown; 1380 newkeycode = Key_unknown;
1377 break; 1381 break;
1378 } 1382 }
1379 } 1383 }
1380 1384
1381 if ( newkeycode != keycode ) { 1385 if ( newkeycode != keycode ) {
1382 if ( newkeycode != Key_unknown ) 1386 if ( newkeycode != Key_unknown )
1383 QWSServer::sendKeyEvent ( -1, newkeycode, modifiers, isPress, autoRepeat ); 1387 QWSServer::sendKeyEvent ( -1, newkeycode, modifiers, isPress, autoRepeat );
1384 return true; 1388 return true;
1385 } 1389 }
1386 else 1390 else
1387 return false; 1391 return false;
1388} 1392}
1389 1393
1390void iPAQ::timerEvent ( QTimerEvent * ) 1394void iPAQ::timerEvent ( QTimerEvent * )
1391{ 1395{
1392 killTimer ( m_power_timer ); 1396 killTimer ( m_power_timer );
1393 m_power_timer = 0; 1397 m_power_timer = 0;
1394 QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, true, false ); 1398 QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, true, false );
1395 QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, false, false ); 1399 QWSServer::sendKeyEvent ( -1, HardKey_Backlight, 0, false, false );
1396} 1400}
1397 1401
1398 1402
1399void iPAQ::alarmSound ( ) 1403void iPAQ::alarmSound ( )
1400{ 1404{
1401#ifndef QT_NO_SOUND 1405#ifndef QT_NO_SOUND
1402 static Sound snd ( "alarm" ); 1406 static Sound snd ( "alarm" );
1403 int fd; 1407 int fd;
1404 int vol; 1408 int vol;
1405 bool vol_reset = false; 1409 bool vol_reset = false;
1406 1410
1407 if (( fd = ::open ( "/dev/sound/mixer", O_RDWR )) >= 0 ) { 1411 if (( fd = ::open ( "/dev/sound/mixer", O_RDWR )) >= 0 ) {
1408 if ( ::ioctl ( fd, MIXER_READ( 0 ), &vol ) >= 0 ) { 1412 if ( ::ioctl ( fd, MIXER_READ( 0 ), &vol ) >= 0 ) {
1409 Config cfg ( "qpe" ); 1413 Config cfg ( "qpe" );
1410 cfg. setGroup ( "Volume" ); 1414 cfg. setGroup ( "Volume" );
1411 1415
1412 int volalarm = cfg. readNumEntry ( "AlarmPercent", 50 ); 1416 int volalarm = cfg. readNumEntry ( "AlarmPercent", 50 );
1413 if ( volalarm < 0 ) 1417 if ( volalarm < 0 )
1414 volalarm = 0; 1418 volalarm = 0;
1415 else if ( volalarm > 100 ) 1419 else if ( volalarm > 100 )
1416 volalarm = 100; 1420 volalarm = 100;
1417 volalarm |= ( volalarm << 8 ); 1421 volalarm |= ( volalarm << 8 );
1418 1422
1419 if ( ::ioctl ( fd, MIXER_WRITE( 0 ), &volalarm ) >= 0 ) 1423 if ( ::ioctl ( fd, MIXER_WRITE( 0 ), &volalarm ) >= 0 )
1420 vol_reset = true; 1424 vol_reset = true;
1421 } 1425 }
1422 } 1426 }
1423 1427
1424 snd. play ( ); 1428 snd. play ( );
1425 while ( !snd. isFinished ( )) 1429 while ( !snd. isFinished ( ))
1426 qApp-> processEvents ( ); 1430 qApp-> processEvents ( );
1427 1431
1428 if ( fd >= 0 ) { 1432 if ( fd >= 0 ) {
1429 if ( vol_reset ) 1433 if ( vol_reset )
1430 ::ioctl ( fd, MIXER_WRITE( 0 ), &vol ); 1434 ::ioctl ( fd, MIXER_WRITE( 0 ), &vol );
1431 ::close ( fd ); 1435 ::close ( fd );
1432 } 1436 }
1433#endif 1437#endif
1434} 1438}
1435 1439
1436 1440
1437bool iPAQ::setSoftSuspend ( bool soft ) 1441bool iPAQ::setSoftSuspend ( bool soft )
1438{ 1442{
1439 bool res = false; 1443 bool res = false;
1440 int fd; 1444 int fd;
1441 1445
1442 if (( fd = ::open ( "/proc/sys/ts/suspend_button_mode", O_WRONLY )) >= 0 ) { 1446 if (( fd = ::open ( "/proc/sys/ts/suspend_button_mode", O_WRONLY )) >= 0 ) {
1443 if ( ::write ( fd, soft ? "1" : "0", 1 ) == 1 ) 1447 if ( ::write ( fd, soft ? "1" : "0", 1 ) == 1 )
1444 res = true; 1448 res = true;
1445 else 1449 else
1446 ::perror ( "write to /proc/sys/ts/suspend_button_mode" ); 1450 ::perror ( "write to /proc/sys/ts/suspend_button_mode" );
1447 1451
1448 ::close ( fd ); 1452 ::close ( fd );
1449 } 1453 }
1450 else 1454 else
1451 ::perror ( "/proc/sys/ts/suspend_button_mode" ); 1455 ::perror ( "/proc/sys/ts/suspend_button_mode" );
1452 1456
1453 return res; 1457 return res;
1454} 1458}
1455 1459
1456 1460
1457bool iPAQ::setDisplayBrightness ( int bright ) 1461bool iPAQ::setDisplayBrightness ( int bright )
1458{ 1462{
1459 bool res = false; 1463 bool res = false;
1460 int fd; 1464 int fd;
1461 1465
1462 if ( bright > 255 ) 1466 if ( bright > 255 )
1463 bright = 255; 1467 bright = 255;
1464 if ( bright < 0 ) 1468 if ( bright < 0 )
1465 bright = 0; 1469 bright = 0;
1466 1470
1467 if (( fd = ::open ( "/dev/touchscreen/0", O_WRONLY )) >= 0 ) { 1471 if (( fd = ::open ( "/dev/touchscreen/0", O_WRONLY )) >= 0 ) {
1468 FLITE_IN bl; 1472 FLITE_IN bl;
1469 bl. mode = 1; 1473 bl. mode = 1;
1470 bl. pwr = bright ? 1 : 0; 1474 bl. pwr = bright ? 1 : 0;
1471 bl. brightness = ( bright * ( displayBrightnessResolution ( ) - 1 ) + 127 ) / 255; 1475 bl. brightness = ( bright * ( displayBrightnessResolution ( ) - 1 ) + 127 ) / 255;
1472 res = ( ::ioctl ( fd, FLITE_ON, &bl ) == 0 ); 1476 res = ( ::ioctl ( fd, FLITE_ON, &bl ) == 0 );
1473 ::close ( fd ); 1477 ::close ( fd );
1474 } 1478 }
1475 return res; 1479 return res;
1476} 1480}
1477 1481
1478int iPAQ::displayBrightnessResolution ( ) const 1482int iPAQ::displayBrightnessResolution ( ) const
1479{ 1483{
1480 switch ( model ( )) { 1484 switch ( model ( )) {
1481 case Model_iPAQ_H31xx: 1485 case Model_iPAQ_H31xx:
1482 case Model_iPAQ_H36xx: 1486 case Model_iPAQ_H36xx:
1483 case Model_iPAQ_H37xx: 1487 case Model_iPAQ_H37xx:
1484 return 128; // really 256, but >128 could damage the LCD 1488 return 128; // really 256, but >128 could damage the LCD
1485 1489
1486 case Model_iPAQ_H38xx: 1490 case Model_iPAQ_H38xx:
1487 case Model_iPAQ_H39xx: 1491 case Model_iPAQ_H39xx:
1488 return 64; 1492 return 64;
1489 case Model_iPAQ_H5xxx: 1493 case Model_iPAQ_H5xxx:
1490 return 255; 1494 return 255;
1491 1495
1492 default: 1496 default:
1493 return 2; 1497 return 2;
1494 } 1498 }
1495} 1499}
1496 1500
1497 1501
1498bool iPAQ::hasLightSensor ( ) const 1502bool iPAQ::hasLightSensor ( ) const
1499{ 1503{
1500 return true; 1504 return true;
1501} 1505}
1502 1506
1503int iPAQ::readLightSensor ( ) 1507int iPAQ::readLightSensor ( )
1504{ 1508{
1505 int fd; 1509 int fd;
1506 int val = -1; 1510 int val = -1;
1507 1511
1508 if (( fd = ::open ( "/proc/hal/light_sensor", O_RDONLY )) >= 0 ) { 1512 if (( fd = ::open ( "/proc/hal/light_sensor", O_RDONLY )) >= 0 ) {
1509 char buffer [8]; 1513 char buffer [8];
1510 1514
1511 if ( ::read ( fd, buffer, 5 ) == 5 ) { 1515 if ( ::read ( fd, buffer, 5 ) == 5 ) {
1512 char *endptr; 1516 char *endptr;
1513 1517
1514 buffer [4] = 0; 1518 buffer [4] = 0;
1515 val = ::strtol ( buffer + 2, &endptr, 16 ); 1519 val = ::strtol ( buffer + 2, &endptr, 16 );
1516 1520
1517 if ( *endptr != 0 ) 1521 if ( *endptr != 0 )
1518 val = -1; 1522 val = -1;
1519 } 1523 }
1520 ::close ( fd ); 1524 ::close ( fd );
1521 } 1525 }
1522 1526
1523 return val; 1527 return val;
1524} 1528}
1525 1529
1526int iPAQ::lightSensorResolution ( ) const 1530int iPAQ::lightSensorResolution ( ) const
1527{ 1531{
1528 return 256; 1532 return 256;
1529} 1533}
1530 1534
1531/************************************************** 1535/**************************************************
1532 * 1536 *
1533 * Zaurus 1537 * Zaurus
1534 * 1538 *
1535 **************************************************/ 1539 **************************************************/
1536 1540
1537// Check whether this device is the sharp zaurus.. 1541// Check whether this device is the sharp zaurus..
1538// FIXME This gets unnecessary complicated. We should think about splitting the Zaurus 1542// FIXME This gets unnecessary complicated. We should think about splitting the Zaurus
1539// class up into individual classes. We need three classes 1543// class up into individual classes. We need three classes
1540// 1544//
1541// Zaurus-Collie (SA-model w/ 320x240 lcd, for SL5500 and SL5000) 1545// Zaurus-Collie (SA-model w/ 320x240 lcd, for SL5500 and SL5000)
1542// Zaurus-Poodle (PXA-model w/ 320x240 lcd, for SL5600) 1546// Zaurus-Poodle (PXA-model w/ 320x240 lcd, for SL5600)
1543// Zaurus-Corgi (PXA-model w/ 640x480 lcd, for C700, C750, C760, and C860) 1547// Zaurus-Corgi (PXA-model w/ 640x480 lcd, for C700, C750, C760, and C860)
1544// 1548//
1545// Only question right now is: Do we really need to do it? Because as soon 1549// Only question right now is: Do we really need to do it? Because as soon
1546// as the OpenZaurus kernel is ready, there will be a unified interface for all 1550// as the OpenZaurus kernel is ready, there will be a unified interface for all
1547// Zaurus models (concerning apm, backlight, buttons, etc.) 1551// Zaurus models (concerning apm, backlight, buttons, etc.)
1548// 1552//
1549// Comments? - mickeyl. 1553// Comments? - mickeyl.
1550 1554
1551bool Zaurus::isZaurus() 1555bool Zaurus::isZaurus()
1552{ 1556{
1553 1557
1554 // If the special devices by embedix exist, it is quite simple: it is a Zaurus ! 1558 // If the special devices by embedix exist, it is quite simple: it is a Zaurus !
1555 if ( QFile::exists ( "/dev/sharp_buz" ) || QFile::exists ( "/dev/sharp_led" ) ){ 1559 if ( QFile::exists ( "/dev/sharp_buz" ) || QFile::exists ( "/dev/sharp_led" ) ){
1556 return true; 1560 return true;
1557 } 1561 }
1558 1562
1559 // On non-embedix kernels, we have to look closer. 1563 // On non-embedix kernels, we have to look closer.
1560 bool is_zaurus = false; 1564 bool is_zaurus = false;
1561 QFile f ( "/proc/cpuinfo" ); 1565 QFile f ( "/proc/cpuinfo" );
1562 if ( f. open ( IO_ReadOnly ) ) { 1566 if ( f. open ( IO_ReadOnly ) ) {
1563 QString model; 1567 QString model;
1564 QFile f ( "/proc/cpuinfo" ); 1568 QFile f ( "/proc/cpuinfo" );
1565 1569
1566 QTextStream ts ( &f ); 1570 QTextStream ts ( &f );
1567 QString line; 1571 QString line;
1568 while( line = ts. readLine ( ) ) { 1572 while( line = ts. readLine ( ) ) {
1569 if ( line. left ( 8 ) == "Hardware" ) 1573 if ( line. left ( 8 ) == "Hardware" )
1570 break; 1574 break;
1571 } 1575 }
1572 int loc = line. find ( ":" ); 1576 int loc = line. find ( ":" );
1573 if ( loc != -1 ) 1577 if ( loc != -1 )
1574 model = line. mid ( loc + 2 ). simplifyWhiteSpace( ); 1578 model = line. mid ( loc + 2 ). simplifyWhiteSpace( );
1575 1579
1576 if ( model == "Sharp-Collie" 1580 if ( model == "Sharp-Collie"
1577 || model == "Collie" 1581 || model == "Collie"
1578 || model == "SHARP Corgi" 1582 || model == "SHARP Corgi"
1579 || model == "SHARP Shepherd" 1583 || model == "SHARP Shepherd"
1580 || model == "SHARP Poodle" 1584 || model == "SHARP Poodle"
1581 || model == "SHARP Husky" 1585 || model == "SHARP Husky"
1582 ) 1586 )
1583 is_zaurus = true; 1587 is_zaurus = true;
1584 1588
1585 } 1589 }
1586 return is_zaurus; 1590 return is_zaurus;
1587} 1591}
1588 1592
1589 1593
1590void Zaurus::init ( ) 1594void Zaurus::init ( )
1591{ 1595{
1592 d-> m_vendorstr = "Sharp"; 1596 d-> m_vendorstr = "Sharp";
1593 d-> m_vendor = Vendor_Sharp; 1597 d-> m_vendor = Vendor_Sharp;
1594 m_embedix = true; // Not openzaurus means: It has an embedix kernel ! 1598 m_embedix = true; // Not openzaurus means: It has an embedix kernel !
1595 1599
1596 // QFile f ( "/proc/filesystems" ); 1600 // QFile f ( "/proc/filesystems" );
1597 QString model; 1601 QString model;
1598 1602
1599 // It isn't a good idea to check the system configuration to 1603 // It isn't a good idea to check the system configuration to
1600 // detect the distribution ! 1604 // detect the distribution !
1601 // Otherwise it may happen that any other distribution is detected as openzaurus, just 1605 // Otherwise it may happen that any other distribution is detected as openzaurus, just
1602 // because it uses a jffs2 filesystem.. 1606 // because it uses a jffs2 filesystem..
1603 // (eilers) 1607 // (eilers)
1604 // if ( f. open ( IO_ReadOnly ) && ( QTextStream ( &f ). read ( ). find ( "\tjffs2\n" ) >= 0 )) { 1608 // if ( f. open ( IO_ReadOnly ) && ( QTextStream ( &f ). read ( ). find ( "\tjffs2\n" ) >= 0 )) {
1605 QFile f ("/etc/oz_version"); 1609 QFile f ("/etc/oz_version");
1606 if ( f.exists() ){ 1610 if ( f.exists() ){
1607 d-> m_vendorstr = "OpenZaurus Team"; 1611 d-> m_vendorstr = "OpenZaurus Team";
1608 d-> m_systemstr = "OpenZaurus"; 1612 d-> m_systemstr = "OpenZaurus";
1609 d-> m_system = System_OpenZaurus; 1613 d-> m_system = System_OpenZaurus;
1610 1614
1611 if ( f. open ( IO_ReadOnly )) { 1615 if ( f. open ( IO_ReadOnly )) {
1612 QTextStream ts ( &f ); 1616 QTextStream ts ( &f );
1613 d-> m_sysverstr = ts. readLine ( );//. mid ( 10 ); 1617 d-> m_sysverstr = ts. readLine ( );//. mid ( 10 );
1614 f. close ( ); 1618 f. close ( );
1615 } 1619 }
1616 1620
1617 // Openzaurus sometimes uses the embedix kernel! 1621 // Openzaurus sometimes uses the embedix kernel!
1618 // => Check whether this is an embedix kernel 1622 // => Check whether this is an embedix kernel
1619 FILE *uname = popen("uname -r", "r"); 1623 FILE *uname = popen("uname -r", "r");
1620 QString line; 1624 QString line;
1621 if ( f.open(IO_ReadOnly, uname) ) { 1625 if ( f.open(IO_ReadOnly, uname) ) {
1622 QTextStream ts ( &f ); 1626 QTextStream ts ( &f );
1623 line = ts. readLine ( ); 1627 line = ts. readLine ( );
1624 int loc = line. find ( "embedix" ); 1628 int loc = line. find ( "embedix" );
1625 if ( loc != -1 ) 1629 if ( loc != -1 )
1626 m_embedix = true; 1630 m_embedix = true;
1627 else 1631 else
1628 m_embedix = false; 1632 m_embedix = false;
1629 f. close ( ); 1633 f. close ( );
1630 } 1634 }
1631 pclose(uname); 1635 pclose(uname);
1632 } 1636 }
1633 else { 1637 else {
1634 d-> m_systemstr = "Zaurus"; 1638 d-> m_systemstr = "Zaurus";
1635 d-> m_system = System_Zaurus; 1639 d-> m_system = System_Zaurus;
1636 } 1640 }
1637 1641
1638 f. setName ( "/proc/cpuinfo" ); 1642 f. setName ( "/proc/cpuinfo" );
1639 if ( f. open ( IO_ReadOnly ) ) { 1643 if ( f. open ( IO_ReadOnly ) ) {
1640 QTextStream ts ( &f ); 1644 QTextStream ts ( &f );
1641 QString line; 1645 QString line;
1642 while( line = ts. readLine ( ) ) { 1646 while( line = ts. readLine ( ) ) {
1643 if ( line. left ( 8 ) == "Hardware" ) 1647 if ( line. left ( 8 ) == "Hardware" )
1644 break; 1648 break;
1645 } 1649 }
1646 int loc = line. find ( ":" ); 1650 int loc = line. find ( ":" );
1647 if ( loc != -1 ) 1651 if ( loc != -1 )
1648 model = line. mid ( loc + 2 ). simplifyWhiteSpace( ); 1652 model = line. mid ( loc + 2 ). simplifyWhiteSpace( );
1649 } 1653 }
1650 1654
1651 if ( model == "SHARP Corgi" ) { 1655 if ( model == "SHARP Corgi" ) {
1652 d-> m_model = Model_Zaurus_SLC7x0; 1656 d-> m_model = Model_Zaurus_SLC7x0;
1653 d-> m_modelstr = "Zaurus SL-C700"; 1657 d-> m_modelstr = "Zaurus SL-C700";
1654 } else if ( model == "SHARP Shepherd" ) { 1658 } else if ( model == "SHARP Shepherd" ) {
1655 d-> m_model = Model_Zaurus_SLC7x0; 1659 d-> m_model = Model_Zaurus_SLC7x0;
1656 d-> m_modelstr = "Zaurus SL-C750"; 1660 d-> m_modelstr = "Zaurus SL-C750";
1657 } else if ( model == "SHARP Husky" ) { 1661 } else if ( model == "SHARP Husky" ) {
1658 d-> m_model = Model_Zaurus_SLC7x0; 1662 d-> m_model = Model_Zaurus_SLC7x0;
1659 d-> m_modelstr = "Zaurus SL-C760"; 1663 d-> m_modelstr = "Zaurus SL-C760";
1660 } else if ( model == "SHARP Poodle" ) { 1664 } else if ( model == "SHARP Poodle" ) {
1661 d-> m_model = Model_Zaurus_SLB600; 1665 d-> m_model = Model_Zaurus_SLB600;
1662 d-> m_modelstr = "Zaurus SL-B500 or SL-5600"; 1666 d-> m_modelstr = "Zaurus SL-B500 or SL-5600";
1663 } else if ( model == "Sharp-Collie" || model == "Collie" ) { 1667 } else if ( model == "Sharp-Collie" || model == "Collie" ) {
1664 d-> m_model = Model_Zaurus_SL5500; 1668 d-> m_model = Model_Zaurus_SL5500;
1665 d-> m_modelstr = "Zaurus SL-5500 or SL-5000d"; 1669 d-> m_modelstr = "Zaurus SL-5500 or SL-5000d";
1666 } else { 1670 } else {
1667 d-> m_model = Model_Zaurus_SL5500; 1671 d-> m_model = Model_Zaurus_SL5500;
1668 d-> m_modelstr = "Zaurus (Model unknown)"; 1672 d-> m_modelstr = "Zaurus (Model unknown)";
1669 } 1673 }
1670 1674
1671 switch ( d-> m_model ) { 1675 switch ( d-> m_model ) {
1672 case Model_Zaurus_SLA300: 1676 case Model_Zaurus_SLA300:
1673 d-> m_rotation = Rot0; 1677 d-> m_rotation = Rot0;
1674 break; 1678 break;
1675 case Model_Zaurus_SLC7x0: 1679 case Model_Zaurus_SLC7x0:
1676 d-> m_rotation = rotation(); 1680 d-> m_rotation = rotation();
1677 d-> m_direction = direction(); 1681 d-> m_direction = direction();
1678 break; 1682 break;
1679 case Model_Zaurus_SLB600: 1683 case Model_Zaurus_SLB600:
1680 case Model_Zaurus_SL5500: 1684 case Model_Zaurus_SL5500:
1681 case Model_Zaurus_SL5000: 1685 case Model_Zaurus_SL5000:
1682 default: 1686 default:
1683 d-> m_rotation = Rot270; 1687 d-> m_rotation = Rot270;
1684 break; 1688 break;
1685 } 1689 }
1686 m_leds [0] = Led_Off; 1690 m_leds [0] = Led_Off;
1687} 1691}
1688 1692
1689void Zaurus::initButtons ( ) 1693void Zaurus::initButtons ( )
1690{ 1694{
1691 if ( d-> m_buttons ) 1695 if ( d-> m_buttons )
1692 return; 1696 return;
1693 1697
1694 d-> m_buttons = new QValueList <ODeviceButton>; 1698 d-> m_buttons = new QValueList <ODeviceButton>;
1695 1699
1696 struct z_button * pz_buttons; 1700 struct z_button * pz_buttons;
1697 int buttoncount; 1701 int buttoncount;
1698 switch ( d-> m_model ) { 1702 switch ( d-> m_model ) {
1699 case Model_Zaurus_SLC7x0: 1703 case Model_Zaurus_SLC7x0:
1700 pz_buttons = z_buttons_c700; 1704 pz_buttons = z_buttons_c700;
1701 buttoncount = ARRAY_SIZE(z_buttons_c700); 1705 buttoncount = ARRAY_SIZE(z_buttons_c700);
1702 break; 1706 break;
1703 default: 1707 default:
1704 pz_buttons = z_buttons; 1708 pz_buttons = z_buttons;
1705 buttoncount = ARRAY_SIZE(z_buttons); 1709 buttoncount = ARRAY_SIZE(z_buttons);
1706 break; 1710 break;
1707 } 1711 }
1708 1712
1709 for ( int i = 0; i < buttoncount; i++ ) { 1713 for ( int i = 0; i < buttoncount; i++ ) {
1710 struct z_button *zb = pz_buttons + i; 1714 struct z_button *zb = pz_buttons + i;
1711 ODeviceButton b; 1715 ODeviceButton b;
1712 1716
1713 b. setKeycode ( zb-> code ); 1717 b. setKeycode ( zb-> code );
1714 b. setUserText ( QObject::tr ( "Button", zb-> utext )); 1718 b. setUserText ( QObject::tr ( "Button", zb-> utext ));
1715 b. setPixmap ( Resource::loadPixmap ( zb-> pix )); 1719 b. setPixmap ( Resource::loadPixmap ( zb-> pix ));
1716 b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( zb-> fpressedservice ), 1720 b. setFactoryPresetPressedAction ( OQCopMessage ( makeChannel ( zb-> fpressedservice ),
1717 zb-> fpressedaction )); 1721 zb-> fpressedaction ));
1718 b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( zb-> fheldservice ), 1722 b. setFactoryPresetHeldAction ( OQCopMessage ( makeChannel ( zb-> fheldservice ),
1719 zb-> fheldaction )); 1723 zb-> fheldaction ));
1720 1724
1721 d-> m_buttons-> append ( b ); 1725 d-> m_buttons-> append ( b );
1722 } 1726 }
1723 1727
1724 reloadButtonMapping ( ); 1728 reloadButtonMapping ( );
1725 1729
1726 QCopChannel *sysch = new QCopChannel ( "QPE/System", this ); 1730 QCopChannel *sysch = new QCopChannel ( "QPE/System", this );
1727 connect ( sysch, SIGNAL( received(const QCString&,const QByteArray&)), 1731 connect ( sysch, SIGNAL( received(const QCString&,const QByteArray&)),
1728 this, SLOT( systemMessage(const QCString&,const QByteArray&))); 1732 this, SLOT( systemMessage(const QCString&,const QByteArray&)));
1729} 1733}
1730 1734
1731#include <unistd.h> 1735#include <unistd.h>
1732#include <fcntl.h> 1736#include <fcntl.h>
1733#include <sys/ioctl.h> 1737#include <sys/ioctl.h>
1734 1738
1735//#include <asm/sharp_char.h> // including kernel headers is evil ... 1739//#include <asm/sharp_char.h> // including kernel headers is evil ...
1736 1740
1737#define SHARP_DEV_IOCTL_COMMAND_START 0x5680 1741#define SHARP_DEV_IOCTL_COMMAND_START 0x5680
1738 1742
1739 #defineSHARP_BUZZER_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START) 1743 #defineSHARP_BUZZER_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START)
1740#define SHARP_BUZZER_MAKESOUND (SHARP_BUZZER_IOCTL_START) 1744#define SHARP_BUZZER_MAKESOUND (SHARP_BUZZER_IOCTL_START)
1741 1745
1742#define SHARP_BUZ_TOUCHSOUND 1 /* touch panel sound */ 1746#define SHARP_BUZ_TOUCHSOUND 1 /* touch panel sound */
1743#define SHARP_BUZ_KEYSOUND 2 /* key sound */ 1747#define SHARP_BUZ_KEYSOUND 2 /* key sound */
1744#define SHARP_BUZ_SCHEDULE_ALARM 11 /* schedule alarm */ 1748#define SHARP_BUZ_SCHEDULE_ALARM 11 /* schedule alarm */
1745 1749
1746/* --- for SHARP_BUZZER device --- */ 1750/* --- for SHARP_BUZZER device --- */
1747 1751
1748 //#defineSHARP_BUZZER_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START) 1752 //#defineSHARP_BUZZER_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START)
1749//#define SHARP_BUZZER_MAKESOUND (SHARP_BUZZER_IOCTL_START) 1753//#define SHARP_BUZZER_MAKESOUND (SHARP_BUZZER_IOCTL_START)
1750 1754
1751#define SHARP_BUZZER_SETVOLUME (SHARP_BUZZER_IOCTL_START+1) 1755#define SHARP_BUZZER_SETVOLUME (SHARP_BUZZER_IOCTL_START+1)
1752#define SHARP_BUZZER_GETVOLUME (SHARP_BUZZER_IOCTL_START+2) 1756#define SHARP_BUZZER_GETVOLUME (SHARP_BUZZER_IOCTL_START+2)
1753#define SHARP_BUZZER_ISSUPPORTED (SHARP_BUZZER_IOCTL_START+3) 1757#define SHARP_BUZZER_ISSUPPORTED (SHARP_BUZZER_IOCTL_START+3)
1754#define SHARP_BUZZER_SETMUTE (SHARP_BUZZER_IOCTL_START+4) 1758#define SHARP_BUZZER_SETMUTE (SHARP_BUZZER_IOCTL_START+4)
1755#define SHARP_BUZZER_STOPSOUND (SHARP_BUZZER_IOCTL_START+5) 1759#define SHARP_BUZZER_STOPSOUND (SHARP_BUZZER_IOCTL_START+5)
1756 1760
1757//#define SHARP_BUZ_TOUCHSOUND 1 /* touch panel sound */ 1761//#define SHARP_BUZ_TOUCHSOUND 1 /* touch panel sound */
1758//#define SHARP_BUZ_KEYSOUND 2 /* key sound */ 1762//#define SHARP_BUZ_KEYSOUND 2 /* key sound */
1759 1763
1760//#define SHARP_PDA_ILLCLICKSOUND 3 /* illegal click */ 1764//#define SHARP_PDA_ILLCLICKSOUND 3 /* illegal click */
1761//#define SHARP_PDA_WARNSOUND 4 /* warning occurred */ 1765//#define SHARP_PDA_WARNSOUND 4 /* warning occurred */
1762//#define SHARP_PDA_ERRORSOUND 5 /* error occurred */ 1766//#define SHARP_PDA_ERRORSOUND 5 /* error occurred */
1763//#define SHARP_PDA_CRITICALSOUND 6 /* critical error occurred */ 1767//#define SHARP_PDA_CRITICALSOUND 6 /* critical error occurred */
1764//#define SHARP_PDA_SYSSTARTSOUND 7 /* system start */ 1768//#define SHARP_PDA_SYSSTARTSOUND 7 /* system start */
1765//#define SHARP_PDA_SYSTEMENDSOUND 8 /* system shutdown */ 1769//#define SHARP_PDA_SYSTEMENDSOUND 8 /* system shutdown */
1766//#define SHARP_PDA_APPSTART 9 /* application start */ 1770//#define SHARP_PDA_APPSTART 9 /* application start */
1767//#define SHARP_PDA_APPQUIT 10 /* application ends */ 1771//#define SHARP_PDA_APPQUIT 10 /* application ends */
1768 1772
1769//#define SHARP_BUZ_SCHEDULE_ALARM 11 /* schedule alarm */ 1773//#define SHARP_BUZ_SCHEDULE_ALARM 11 /* schedule alarm */
1770//#define SHARP_BUZ_DAILY_ALARM 12 /* daily alarm */ 1774//#define SHARP_BUZ_DAILY_ALARM 12 /* daily alarm */
1771//#define SHARP_BUZ_GOT_PHONE_CALL 13 /* phone call sound */ 1775//#define SHARP_BUZ_GOT_PHONE_CALL 13 /* phone call sound */
1772//#define SHARP_BUZ_GOT_MAIL 14 /* mail sound */ 1776//#define SHARP_BUZ_GOT_MAIL 14 /* mail sound */
1773// 1777//
1774 1778
1775 #defineSHARP_LED_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START) 1779 #defineSHARP_LED_IOCTL_START (SHARP_DEV_IOCTL_COMMAND_START)
1776#define SHARP_LED_SETSTATUS (SHARP_LED_IOCTL_START+1) 1780#define SHARP_LED_SETSTATUS (SHARP_LED_IOCTL_START+1)
1777 1781
1778#define SHARP_IOCTL_GET_ROTATION 0x413c 1782#define SHARP_IOCTL_GET_ROTATION 0x413c
1779 1783
1780typedef struct sharp_led_status { 1784typedef struct sharp_led_status {
1781 int which; /* select which LED status is wanted. */ 1785 int which; /* select which LED status is wanted. */
1782 int status; /* set new led status if you call SHARP_LED_SETSTATUS */ 1786 int status; /* set new led status if you call SHARP_LED_SETSTATUS */
1783} sharp_led_status; 1787} sharp_led_status;
1784 1788
1785#define SHARP_LED_MAIL_EXISTS 9 /* mail status (exists or not) */ 1789#define SHARP_LED_MAIL_EXISTS 9 /* mail status (exists or not) */
1786 1790
1787#define LED_MAIL_NO_UNREAD_MAIL 0 /* for SHARP_LED_MAIL_EXISTS */ 1791#define LED_MAIL_NO_UNREAD_MAIL 0 /* for SHARP_LED_MAIL_EXISTS */
1788#define LED_MAIL_NEWMAIL_EXISTS 1 /* for SHARP_LED_MAIL_EXISTS */ 1792#define LED_MAIL_NEWMAIL_EXISTS 1 /* for SHARP_LED_MAIL_EXISTS */
1789#define LED_MAIL_UNREAD_MAIL_EX 2 /* for SHARP_LED_MAIL_EXISTS */ 1793#define LED_MAIL_UNREAD_MAIL_EX 2 /* for SHARP_LED_MAIL_EXISTS */
1790 1794
1791// #include <asm/sharp_apm.h> // including kernel headers is evil ... 1795// #include <asm/sharp_apm.h> // including kernel headers is evil ...
1792 1796
1793#define APM_IOCGEVTSRC OD_IOR( 'A', 203, int ) 1797#define APM_IOCGEVTSRC OD_IOR( 'A', 203, int )
1794#define APM_IOCSEVTSRC OD_IORW( 'A', 204, int ) 1798#define APM_IOCSEVTSRC OD_IORW( 'A', 204, int )
1795#define APM_EVT_POWER_BUTTON (1 << 0) 1799#define APM_EVT_POWER_BUTTON (1 << 0)
1796 1800
1797#define FL_IOCTL_STEP_CONTRAST 100 1801#define FL_IOCTL_STEP_CONTRAST 100
1798 1802
1799 1803
1800void Zaurus::buzzer ( int sound ) 1804void Zaurus::buzzer ( int sound )
1801{ 1805{
1802#ifndef QT_NO_SOUND 1806#ifndef QT_NO_SOUND
1803 QString soundname; 1807 QString soundname;
1804 1808
1805 // Not all devices have real sound 1809 // Not all devices have real sound
1806 if ( d->m_model == Model_Zaurus_SLC7x0 1810 if ( d->m_model == Model_Zaurus_SLC7x0
1807 || d->m_model == Model_Zaurus_SLB600 ){ 1811 || d->m_model == Model_Zaurus_SLB600 ){
1808 1812
1809 switch ( sound ){ 1813 switch ( sound ){
1810 case SHARP_BUZ_SCHEDULE_ALARM: 1814 case SHARP_BUZ_SCHEDULE_ALARM:
1811 soundname = "alarm"; 1815 soundname = "alarm";
1812 break; 1816 break;
1813 case SHARP_BUZ_TOUCHSOUND: 1817 case SHARP_BUZ_TOUCHSOUND:
1814 soundname = "touchsound"; 1818 soundname = "touchsound";
1815 break; 1819 break;
1816 case SHARP_BUZ_KEYSOUND: 1820 case SHARP_BUZ_KEYSOUND:
1817 soundname = "keysound"; 1821 soundname = "keysound";
1818 break; 1822 break;
1819 default: 1823 default:
1820 soundname = "alarm"; 1824 soundname = "alarm";
1821 1825
1822 } 1826 }
1823 } 1827 }
1824 1828
1825 // If a soundname is defined, we expect that this device has 1829 // If a soundname is defined, we expect that this device has
1826 // sound capabilities.. Otherwise we expect to have the buzzer 1830 // sound capabilities.. Otherwise we expect to have the buzzer
1827 // device.. 1831 // device..
1828 if ( !soundname.isEmpty() ){ 1832 if ( !soundname.isEmpty() ){
1829 int fd; 1833 int fd;
1830 int vol; 1834 int vol;
1831 bool vol_reset = false; 1835 bool vol_reset = false;
1832 1836
1833 Sound snd ( soundname ); 1837 Sound snd ( soundname );
1834 1838
1835 if (( fd = ::open ( "/dev/sound/mixer", O_RDWR )) >= 0 ) { 1839 if (( fd = ::open ( "/dev/sound/mixer", O_RDWR )) >= 0 ) {
1836 if ( ::ioctl ( fd, MIXER_READ( 0 ), &vol ) >= 0 ) { 1840 if ( ::ioctl ( fd, MIXER_READ( 0 ), &vol ) >= 0 ) {
1837 Config cfg ( "qpe" ); 1841 Config cfg ( "qpe" );
1838 cfg. setGroup ( "Volume" ); 1842 cfg. setGroup ( "Volume" );
1839 1843
1840 int volalarm = cfg. readNumEntry ( "AlarmPercent", 50 ); 1844 int volalarm = cfg. readNumEntry ( "AlarmPercent", 50 );
1841 if ( volalarm < 0 ) 1845 if ( volalarm < 0 )
1842 volalarm = 0; 1846 volalarm = 0;
1843 else if ( volalarm > 100 ) 1847 else if ( volalarm > 100 )
1844 volalarm = 100; 1848 volalarm = 100;
1845 volalarm |= ( volalarm << 8 ); 1849 volalarm |= ( volalarm << 8 );
1846 1850
1847 if ( ::ioctl ( fd, MIXER_WRITE( 0 ), &volalarm ) >= 0 ) 1851 if ( ::ioctl ( fd, MIXER_WRITE( 0 ), &volalarm ) >= 0 )
1848 vol_reset = true; 1852 vol_reset = true;
1849 } 1853 }
1850 } 1854 }
1851 1855
1852 snd. play ( ); 1856 snd. play ( );
1853 while ( !snd. isFinished ( )) 1857 while ( !snd. isFinished ( ))
1854 qApp-> processEvents ( ); 1858 qApp-> processEvents ( );
1855 1859
1856 if ( fd >= 0 ) { 1860 if ( fd >= 0 ) {
1857 if ( vol_reset ) 1861 if ( vol_reset )
1858 ::ioctl ( fd, MIXER_WRITE( 0 ), &vol ); 1862 ::ioctl ( fd, MIXER_WRITE( 0 ), &vol );
1859 ::close ( fd ); 1863 ::close ( fd );
1860 } 1864 }
1861 } else { 1865 } else {
1862 int fd = ::open ( "/dev/sharp_buz", O_WRONLY|O_NONBLOCK ); 1866 int fd = ::open ( "/dev/sharp_buz", O_WRONLY|O_NONBLOCK );
1863 1867
1864 if ( fd >= 0 ) { 1868 if ( fd >= 0 ) {
1865 ::ioctl ( fd, SHARP_BUZZER_MAKESOUND, sound ); 1869 ::ioctl ( fd, SHARP_BUZZER_MAKESOUND, sound );
1866 ::close ( fd ); 1870 ::close ( fd );
1867 } 1871 }
1868 1872
1869 } 1873 }
1870#endif 1874#endif
1871} 1875}
1872 1876
1873 1877
1874void Zaurus::alarmSound ( ) 1878void Zaurus::alarmSound ( )
1875{ 1879{
1876 buzzer ( SHARP_BUZ_SCHEDULE_ALARM ); 1880 buzzer ( SHARP_BUZ_SCHEDULE_ALARM );
1877} 1881}
1878 1882
1879void Zaurus::touchSound ( ) 1883void Zaurus::touchSound ( )
1880{ 1884{
1881 buzzer ( SHARP_BUZ_TOUCHSOUND ); 1885 buzzer ( SHARP_BUZ_TOUCHSOUND );
1882} 1886}
1883 1887
1884void Zaurus::keySound ( ) 1888void Zaurus::keySound ( )
1885{ 1889{
1886 buzzer ( SHARP_BUZ_KEYSOUND ); 1890 buzzer ( SHARP_BUZ_KEYSOUND );
1887} 1891}
1888 1892
1889 1893
1890QValueList <OLed> Zaurus::ledList ( ) const 1894QValueList <OLed> Zaurus::ledList ( ) const
1891{ 1895{
1892 QValueList <OLed> vl; 1896 QValueList <OLed> vl;
1893 vl << Led_Mail; 1897 vl << Led_Mail;
1894 return vl; 1898 return vl;
1895} 1899}
1896 1900
1897QValueList <OLedState> Zaurus::ledStateList ( OLed l ) const 1901QValueList <OLedState> Zaurus::ledStateList ( OLed l ) const
1898{ 1902{
1899 QValueList <OLedState> vl; 1903 QValueList <OLedState> vl;
1900 1904
1901 if ( l == Led_Mail ) 1905 if ( l == Led_Mail )
1902 vl << Led_Off << Led_On << Led_BlinkSlow; 1906 vl << Led_Off << Led_On << Led_BlinkSlow;
1903 return vl; 1907 return vl;
1904} 1908}
1905 1909
1906OLedState Zaurus::ledState ( OLed which ) const 1910OLedState Zaurus::ledState ( OLed which ) const
1907{ 1911{
1908 if ( which == Led_Mail ) 1912 if ( which == Led_Mail )
1909 return m_leds [0]; 1913 return m_leds [0];
1910 else 1914 else
1911 return Led_Off; 1915 return Led_Off;
1912} 1916}
1913 1917
1914bool Zaurus::setLedState ( OLed which, OLedState st ) 1918bool Zaurus::setLedState ( OLed which, OLedState st )
1915{ 1919{
1916 if (!m_embedix) // Currently not supported on non_embedix kernels 1920 if (!m_embedix) // Currently not supported on non_embedix kernels
1917 return false; 1921 return false;
1918 1922
1919 static int fd = ::open ( "/dev/sharp_led", O_RDWR|O_NONBLOCK ); 1923 static int fd = ::open ( "/dev/sharp_led", O_RDWR|O_NONBLOCK );
1920 1924
1921 if ( which == Led_Mail ) { 1925 if ( which == Led_Mail ) {
1922 if ( fd >= 0 ) { 1926 if ( fd >= 0 ) {
1923 struct sharp_led_status leds; 1927 struct sharp_led_status leds;
1924 ::memset ( &leds, 0, sizeof( leds )); 1928 ::memset ( &leds, 0, sizeof( leds ));
1925 leds. which = SHARP_LED_MAIL_EXISTS; 1929 leds. which = SHARP_LED_MAIL_EXISTS;
1926 bool ok = true; 1930 bool ok = true;
1927 1931
1928 switch ( st ) { 1932 switch ( st ) {
1929 case Led_Off : leds. status = LED_MAIL_NO_UNREAD_MAIL; break; 1933 case Led_Off : leds. status = LED_MAIL_NO_UNREAD_MAIL; break;
1930 case Led_On : leds. status = LED_MAIL_NEWMAIL_EXISTS; break; 1934 case Led_On : leds. status = LED_MAIL_NEWMAIL_EXISTS; break;
1931 case Led_BlinkSlow: leds. status = LED_MAIL_UNREAD_MAIL_EX; break; 1935 case Led_BlinkSlow: leds. status = LED_MAIL_UNREAD_MAIL_EX; break;
1932 default : ok = false; 1936 default : ok = false;
1933 } 1937 }
1934 1938
1935 if ( ok && ( ::ioctl ( fd, SHARP_LED_SETSTATUS, &leds ) >= 0 )) { 1939 if ( ok && ( ::ioctl ( fd, SHARP_LED_SETSTATUS, &leds ) >= 0 )) {
1936 m_leds [0] = st; 1940 m_leds [0] = st;
1937 return true; 1941 return true;
1938 } 1942 }
1939 } 1943 }
1940 } 1944 }
1941 return false; 1945 return false;
1942} 1946}
1943 1947
1944bool Zaurus::setSoftSuspend ( bool soft ) 1948bool Zaurus::setSoftSuspend ( bool soft )
1945{ 1949{
1946 if (!m_embedix) { 1950 if (!m_embedix) {
1947 /* non-Embedix kernels dont have kernel autosuspend */ 1951 /* non-Embedix kernels dont have kernel autosuspend */
1948 return ODevice::setSoftSuspend( soft ); 1952 return ODevice::setSoftSuspend( soft );
1949 } 1953 }
1950 1954
1951 bool res = false; 1955 bool res = false;
1952 int fd; 1956 int fd;
1953 1957
1954 if ((( fd = ::open ( "/dev/apm_bios", O_RDWR )) >= 0 ) || 1958 if ((( fd = ::open ( "/dev/apm_bios", O_RDWR )) >= 0 ) ||
1955 (( fd = ::open ( "/dev/misc/apm_bios",O_RDWR )) >= 0 )) { 1959 (( fd = ::open ( "/dev/misc/apm_bios",O_RDWR )) >= 0 )) {
1956 1960
1957 int sources = ::ioctl ( fd, APM_IOCGEVTSRC, 0 ); // get current event sources 1961 int sources = ::ioctl ( fd, APM_IOCGEVTSRC, 0 ); // get current event sources
1958 1962
1959 if ( sources >= 0 ) { 1963 if ( sources >= 0 ) {
1960 if ( soft ) 1964 if ( soft )
1961 sources &= ~APM_EVT_POWER_BUTTON; 1965 sources &= ~APM_EVT_POWER_BUTTON;
1962 else 1966 else
1963 sources |= APM_EVT_POWER_BUTTON; 1967 sources |= APM_EVT_POWER_BUTTON;
1964 1968
1965 if ( ::ioctl ( fd, APM_IOCSEVTSRC, sources ) >= 0 ) // set new event sources 1969 if ( ::ioctl ( fd, APM_IOCSEVTSRC, sources ) >= 0 ) // set new event sources
1966 res = true; 1970 res = true;
1967 else 1971 else
1968 perror ( "APM_IOCGEVTSRC" ); 1972 perror ( "APM_IOCGEVTSRC" );
1969 } 1973 }
1970 else 1974 else
1971 perror ( "APM_IOCGEVTSRC" ); 1975 perror ( "APM_IOCGEVTSRC" );
1972 1976
1973 ::close ( fd ); 1977 ::close ( fd );
1974 } 1978 }
1975 else 1979 else
1976 perror ( "/dev/apm_bios or /dev/misc/apm_bios" ); 1980 perror ( "/dev/apm_bios or /dev/misc/apm_bios" );
1977 1981
1978 return res; 1982 return res;
1979} 1983}
1980 1984
1981 1985
1982bool Zaurus::setDisplayBrightness ( int bright ) 1986bool Zaurus::setDisplayBrightness ( int bright )
1983{ 1987{
1984 //qDebug( "Zaurus::setDisplayBrightness( %d )", bright ); 1988 //qDebug( "Zaurus::setDisplayBrightness( %d )", bright );
1985 bool res = false; 1989 bool res = false;
1986 int fd; 1990 int fd;
1987 1991
1988 if ( bright > 255 ) bright = 255; 1992 if ( bright > 255 ) bright = 255;
1989 if ( bright < 0 ) bright = 0; 1993 if ( bright < 0 ) bright = 0;
1990 1994
1991 if ( m_embedix ) 1995 if ( m_embedix )
1992 { 1996 {
1993 if ( d->m_model == Model_Zaurus_SLC7x0 ) 1997 if ( d->m_model == Model_Zaurus_SLC7x0 )
1994 { 1998 {
1995 //qDebug( "using special treatment for devices with the corgi backlight interface" ); 1999 //qDebug( "using special treatment for devices with the corgi backlight interface" );
1996 // special treatment for devices with the corgi backlight interface 2000 // special treatment for devices with the corgi backlight interface
1997 if (( fd = ::open ( "/proc/driver/fl/corgi-bl", O_WRONLY )) >= 0 ) 2001 if (( fd = ::open ( "/proc/driver/fl/corgi-bl", O_WRONLY )) >= 0 )
1998 { 2002 {
1999 int value = ( bright == 1 ) ? 1 : bright * ( 17.0 / 255.0 ); 2003 int value = ( bright == 1 ) ? 1 : bright * ( 17.0 / 255.0 );
2000 char writeCommand[100]; 2004 char writeCommand[100];
2001 const int count = sprintf( writeCommand, "0x%x\n", value ); 2005 const int count = sprintf( writeCommand, "0x%x\n", value );
2002 res = ( ::write ( fd, writeCommand, count ) != -1 ); 2006 res = ( ::write ( fd, writeCommand, count ) != -1 );
2003 ::close ( fd ); 2007 ::close ( fd );
2004 } 2008 }
2005 return res; 2009 return res;
2006 } 2010 }
2007 else 2011 else
2008 { 2012 {
2009 // standard treatment for devices with the dumb embedix frontlight interface 2013 // standard treatment for devices with the dumb embedix frontlight interface
2010 if (( fd = ::open ( "/dev/fl", O_WRONLY )) >= 0 ) { 2014 if (( fd = ::open ( "/dev/fl", O_WRONLY )) >= 0 ) {
2011 int bl = ( bright * 4 + 127 ) / 255; // only 4 steps on zaurus 2015 int bl = ( bright * 4 + 127 ) / 255; // only 4 steps on zaurus
2012 if ( bright && !bl ) 2016 if ( bright && !bl )
2013 bl = 1; 2017 bl = 1;
2014 res = ( ::ioctl ( fd, FL_IOCTL_STEP_CONTRAST, bl ) == 0 ); 2018 res = ( ::ioctl ( fd, FL_IOCTL_STEP_CONTRAST, bl ) == 0 );
2015 ::close ( fd ); 2019 ::close ( fd );
2016 } 2020 }
2017 } 2021 }
2018 } 2022 }
2019 else 2023 else
2020 { 2024 {
2021 // special treatment for the OpenZaurus unified interface 2025 // special treatment for the OpenZaurus unified interface
2022 #define FB_BACKLIGHT_SET_BRIGHTNESS _IOW('F', 1, u_int) /* set brightness */ 2026 #define FB_BACKLIGHT_SET_BRIGHTNESS _IOW('F', 1, u_int) /* set brightness */
2023 if (( fd = ::open ( "/dev/fb0", O_WRONLY )) >= 0 ) { 2027 if (( fd = ::open ( "/dev/fb0", O_WRONLY )) >= 0 ) {
2024 res = ( ::ioctl ( fd , FB_BACKLIGHT_SET_BRIGHTNESS, bright ) == 0 ); 2028 res = ( ::ioctl ( fd , FB_BACKLIGHT_SET_BRIGHTNESS, bright ) == 0 );
2025 ::close ( fd ); 2029 ::close ( fd );
2026 } 2030 }
2027 } 2031 }
2028 return res; 2032 return res;
2029} 2033}
2030 2034
2031bool Zaurus::suspend ( ) 2035bool Zaurus::suspend ( )
2032{ 2036{
2033 qDebug("ODevice::suspend"); 2037 qDebug("ODevice::suspend");
2034 if ( !isQWS( ) ) // only qwsserver is allowed to suspend 2038 if ( !isQWS( ) ) // only qwsserver is allowed to suspend
2035 return false; 2039 return false;
2036 2040
2037 if ( d-> m_model == Model_Unknown ) // better don't suspend in qvfb / on unkown devices 2041 if ( d-> m_model == Model_Unknown ) // better don't suspend in qvfb / on unkown devices
2038 return false; 2042 return false;
2039 2043
2040 bool res = false; 2044 bool res = false;
2041 2045
2042 struct timeval tvs, tvn; 2046 struct timeval tvs, tvn;
2043 ::gettimeofday ( &tvs, 0 ); 2047 ::gettimeofday ( &tvs, 0 );
2044 2048
2045 ::sync ( ); // flush fs caches 2049 ::sync ( ); // flush fs caches
2046 res = ( ::system ( "apm --suspend" ) == 0 ); 2050 res = ( ::system ( "apm --suspend" ) == 0 );
2047 2051
2048 // This is needed because the iPAQ apm implementation is asynchronous and we 2052 // This is needed because the iPAQ apm implementation is asynchronous and we
2049 // can not be sure when exactly the device is really suspended 2053 // can not be sure when exactly the device is really suspended
2050 // This can be deleted as soon as a stable familiar with a synchronous apm implementation exists. 2054 // This can be deleted as soon as a stable familiar with a synchronous apm implementation exists.
2051 2055
2052 if ( res ) { 2056 if ( res ) {
2053 do { // Yes, wait 15 seconds. This APM bug sucks big time. 2057 do { // Yes, wait 15 seconds. This APM bug sucks big time.
2054 ::usleep ( 200 * 1000 ); 2058 ::usleep ( 200 * 1000 );
2055 ::gettimeofday ( &tvn, 0 ); 2059 ::gettimeofday ( &tvn, 0 );
2056 } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < 15000 ); 2060 } while ((( tvn. tv_sec - tvs. tv_sec ) * 1000 + ( tvn. tv_usec - tvs. tv_usec ) / 1000 ) < 15000 );
2057 } 2061 }
2058 2062
2059 QCopEnvelope ( "QPE/Rotation", "rotateDefault()" ); 2063 QCopEnvelope ( "QPE/Rotation", "rotateDefault()" );
2060 return res; 2064 return res;
2061} 2065}
2062 2066
2063 2067
2064Transformation Zaurus::rotation ( ) const 2068Transformation Zaurus::rotation ( ) const
2065{ 2069{
2066 Transformation rot; 2070 Transformation rot;
2067 int handle = 0; 2071 int handle = 0;
2068 int retval = 0; 2072 int retval = 0;
2069 2073
2070 switch ( d-> m_model ) { 2074 switch ( d-> m_model ) {
2071 case Model_Zaurus_SLC7x0: 2075 case Model_Zaurus_SLC7x0:
2072 handle = ::open("/dev/apm_bios", O_RDWR|O_NONBLOCK); 2076 handle = ::open("/dev/apm_bios", O_RDWR|O_NONBLOCK);
2073 if (handle == -1) { 2077 if (handle == -1) {
2074 return Rot270; 2078 return Rot270;
2075 } else { 2079 } else {
2076 retval = ::ioctl(handle, SHARP_IOCTL_GET_ROTATION); 2080 retval = ::ioctl(handle, SHARP_IOCTL_GET_ROTATION);
2077 ::close (handle); 2081 ::close (handle);
2078 2082
2079 if (retval == 2 ) 2083 if (retval == 2 )
2080 rot = Rot0; 2084 rot = Rot0;
2081 else 2085 else
2082 rot = Rot270; 2086 rot = Rot270;
2083 } 2087 }
2084 break; 2088 break;
2085 case Model_Zaurus_SLA300: 2089 case Model_Zaurus_SLA300:
2086 case Model_Zaurus_SLB600: 2090 case Model_Zaurus_SLB600:
2087 case Model_Zaurus_SL5500: 2091 case Model_Zaurus_SL5500:
2088 case Model_Zaurus_SL5000: 2092 case Model_Zaurus_SL5000:
2089 default: 2093 default:
2090 rot = d-> m_rotation; 2094 rot = d-> m_rotation;
2091 break; 2095 break;
2092 } 2096 }
2093 2097
2094 return rot; 2098 return rot;
2095} 2099}
2096ODirection Zaurus::direction ( ) const 2100ODirection Zaurus::direction ( ) const
2097{ 2101{
2098 ODirection dir; 2102 ODirection dir;
2099 int handle = 0; 2103 int handle = 0;
2100 int retval = 0; 2104 int retval = 0;
2101 switch ( d-> m_model ) { 2105 switch ( d-> m_model ) {
2102 case Model_Zaurus_SLC7x0: 2106 case Model_Zaurus_SLC7x0:
2103 handle = ::open("/dev/apm_bios", O_RDWR|O_NONBLOCK); 2107 handle = ::open("/dev/apm_bios", O_RDWR|O_NONBLOCK);
2104 if (handle == -1) { 2108 if (handle == -1) {
2105 dir = CW; 2109 dir = CW;
2106 } else { 2110 } else {
2107 retval = ::ioctl(handle, SHARP_IOCTL_GET_ROTATION); 2111 retval = ::ioctl(handle, SHARP_IOCTL_GET_ROTATION);
2108 ::close (handle); 2112 ::close (handle);
2109 if (retval == 2 ) 2113 if (retval == 2 )
2110 dir = CCW; 2114 dir = CCW;
2111 else 2115 else
2112 dir = CW; 2116 dir = CW;
2113 } 2117 }
2114 break; 2118 break;
2115 case Model_Zaurus_SLA300: 2119 case Model_Zaurus_SLA300:
2116 case Model_Zaurus_SLB600: 2120 case Model_Zaurus_SLB600:
2117 case Model_Zaurus_SL5500: 2121 case Model_Zaurus_SL5500:
2118 case Model_Zaurus_SL5000: 2122 case Model_Zaurus_SL5000:
2119 default: 2123 default:
2120 dir = d-> m_direction; 2124 dir = d-> m_direction;
2121 break; 2125 break;
2122 } 2126 }
2123 return dir; 2127 return dir;
2124 2128
2125} 2129}
2126 2130
2127int Zaurus::displayBrightnessResolution ( ) const 2131int Zaurus::displayBrightnessResolution ( ) const
2128{ 2132{
2129 if (m_embedix) 2133 if (m_embedix)
2130 return d->m_model == Model_Zaurus_SLC7x0 ? 18 : 5; 2134 return d->m_model == Model_Zaurus_SLC7x0 ? 18 : 5;
2131 else 2135 else
2132 return 256; 2136 return 256;
2133} 2137}
2134 2138
diff --git a/libopie2/opiemm/osoundsystem.cpp b/libopie2/opiemm/osoundsystem.cpp
index 763ff65..17e5cb0 100644
--- a/libopie2/opiemm/osoundsystem.cpp
+++ b/libopie2/opiemm/osoundsystem.cpp
@@ -1,317 +1,322 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3 3
4              (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 4              (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
5 =. 5 =.
6 .=l. 6 .=l.
7           .>+-= 7           .>+-=
8 _;:,     .>    :=|. This program is free software; you can 8 _;:,     .>    :=|. This program is free software; you can
9.> <`_,   >  .   <= redistribute it and/or modify it under 9.> <`_,   >  .   <= redistribute it and/or modify it under
10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
11.="- .-=="i,     .._ License as published by the Free Software 11.="- .-=="i,     .._ License as published by the Free Software
12 - .   .-<_>     .<> Foundation; either version 2 of the License, 12 - .   .-<_>     .<> Foundation; either version 2 of the License,
13     ._= =}       : or (at your option) any later version. 13     ._= =}       : or (at your option) any later version.
14    .%`+i>       _;_. 14    .%`+i>       _;_.
15    .i_,=:_.      -<s. This program is distributed in the hope that 15    .i_,=:_.      -<s. This program is distributed in the hope that
16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
17    : ..    .:,     . . . without even the implied warranty of 17    : ..    .:,     . . . without even the implied warranty of
18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
20..}^=.=       =       ; Library General Public License for more 20..}^=.=       =       ; Library General Public License for more
21++=   -.     .`     .: details. 21++=   -.     .`     .: details.
22 :     =  ...= . :.=- 22 :     =  ...= . :.=-
23 -.   .:....=;==+<; You should have received a copy of the GNU 23 -.   .:....=;==+<; You should have received a copy of the GNU
24  -_. . .   )=.  = Library General Public License along with 24  -_. . .   )=.  = Library General Public License along with
25    --        :-=` this library; see the file COPYING.LIB. 25    --        :-=` this library; see the file COPYING.LIB.
26 If not, write to the Free Software Foundation, 26 If not, write to the Free Software Foundation,
27 Inc., 59 Temple Place - Suite 330, 27 Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. 28 Boston, MA 02111-1307, USA.
29 29
30*/ 30*/
31 31
32#include <opie2/osoundsystem.h> 32#include <opie2/osoundsystem.h>
33#include <opie2/odebug.h> 33#include <opie2/odebug.h>
34 34
35#include <errno.h> 35#include <errno.h>
36#include <fcntl.h> 36#include <fcntl.h>
37#include <string.h> 37#include <string.h>
38#include <sys/ioctl.h> 38#include <sys/ioctl.h>
39#include <sys/types.h> 39#include <sys/types.h>
40#include <sys/soundcard.h> 40#include <sys/soundcard.h>
41#include <sys/stat.h> 41#include <sys/stat.h>
42 42
43 43
44using namespace Opie::Core; 44using namespace Opie::Core;
45using namespace Opie::MM; 45using namespace Opie::MM;
46/*====================================================================================== 46/*======================================================================================
47 * OSoundSystem 47 * OSoundSystem
48 *======================================================================================*/ 48 *======================================================================================*/
49 49
50OSoundSystem* OSoundSystem::_instance = 0; 50OSoundSystem* OSoundSystem::_instance = 0;
51 51
52OSoundSystem::OSoundSystem() 52OSoundSystem::OSoundSystem()
53{ 53{
54 odebug << "OSoundSystem::OSoundSystem()" << oendl; 54 odebug << "OSoundSystem::OSoundSystem()" << oendl;
55 synchronize(); 55 synchronize();
56} 56}
57 57
58void OSoundSystem::synchronize() 58void OSoundSystem::synchronize()
59{ 59{
60 // gather available interfaces by inspecting /dev 60 // gather available interfaces by inspecting /dev
61 //FIXME: we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices 61 //FIXME: we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices
62 //FIXME: Use SIOCGIFCONF anway, because we can disable listing of aliased devices 62 //FIXME: Use SIOCGIFCONF anway, because we can disable listing of aliased devices
63 63
64 _interfaces.clear(); 64 _interfaces.clear();
65 _interfaces.insert( "soundcard", new OSoundCard( this, "soundcard" ) ); 65 _interfaces.insert( "soundcard", new OSoundCard( this, "soundcard" ) );
66 66
67 67
68 /* 68 /*
69 69
70 QString str; 70 QString str;
71 QFile f( "/dev/sound" ); 71 QFile f( "/dev/sound" );
72 bool hasFile = f.open( IO_ReadOnly ); 72 bool hasFile = f.open( IO_ReadOnly );
73 if ( !hasFile ) 73 if ( !hasFile )
74 { 74 {
75 odebug << "OSoundSystem: /dev/sound not existing. No sound devices available" << oendl; 75 odebug << "OSoundSystem: /dev/sound not existing. No sound devices available" << oendl;
76 return; 76 return;
77 } 77 }
78 QTextStream s( &f ); 78 QTextStream s( &f );
79 s.readLine(); 79 s.readLine();
80 s.readLine(); 80 s.readLine();
81 while ( !s.atEnd() ) 81 while ( !s.atEnd() )
82 { 82 {
83 s >> str; 83 s >> str;
84 str.truncate( str.find( ':' ) ); 84 str.truncate( str.find( ':' ) );
85 odebug << "OSoundSystem: found interface '" << str << "'" << oendl; 85 odebug << "OSoundSystem: found interface '" << str << "'" << oendl;
86 OAudioInterface* iface; 86 OAudioInterface* iface;
87 iface = new OAudioInterface( this, (const char*) str ); 87 iface = new OAudioInterface( this, (const char*) str );
88 88
89 _interfaces.insert( str, iface ); 89 _interfaces.insert( str, iface );
90 s.readLine(); 90 s.readLine();
91 } 91 }
92*/ 92*/
93} 93}
94 94
95 95
96int OSoundSystem::count() const 96int OSoundSystem::count() const
97{ 97{
98 return _interfaces.count(); 98 return _interfaces.count();
99} 99}
100 100
101 101
102OSoundCard* OSoundSystem::card( const QString& iface ) const 102OSoundCard* OSoundSystem::card( const QString& iface ) const
103{ 103{
104 return _interfaces[iface]; 104 return _interfaces[iface];
105} 105}
106 106
107 107
108OSoundSystem* OSoundSystem::instance() 108OSoundSystem* OSoundSystem::instance()
109{ 109{
110 if ( !_instance ) _instance = new OSoundSystem(); 110 if ( !_instance ) _instance = new OSoundSystem();
111 return _instance; 111 return _instance;
112} 112}
113 113
114 114
115OSoundSystem::CardIterator OSoundSystem::iterator() const 115OSoundSystem::CardIterator OSoundSystem::iterator() const
116{ 116{
117 return OSoundSystem::CardIterator( _interfaces ); 117 return OSoundSystem::CardIterator( _interfaces );
118} 118}
119 119
120 120
121/*====================================================================================== 121/*======================================================================================
122 * OSoundCard 122 * OSoundCard
123 *======================================================================================*/ 123 *======================================================================================*/
124 124
125OSoundCard::OSoundCard( QObject* parent, const char* name ) 125OSoundCard::OSoundCard( QObject* parent, const char* name )
126 :QObject( parent, name ), _audio( 0 ), _mixer( 0 ) 126 :QObject( parent, name ), _audio( 0 ), _mixer( 0 )
127{ 127{
128 odebug << "OSoundCard::OSoundCard()" << oendl; 128 odebug << "OSoundCard::OSoundCard()" << oendl;
129 init(); 129 init();
130} 130}
131 131
132 132
133OSoundCard::~OSoundCard() 133OSoundCard::~OSoundCard()
134{ 134{
135} 135}
136 136
137 137
138void OSoundCard::init() 138void OSoundCard::init()
139{ 139{
140#ifdef QT_QWS_DEVFS
141 _audio = new OAudioInterface( this, "/dev/sound/dsp" );
142 _mixer = new OMixerInterface( this, "/dev/sound/mixer" );
143#else
140 _audio = new OAudioInterface( this, "/dev/dsp" ); 144 _audio = new OAudioInterface( this, "/dev/dsp" );
141 _mixer = new OMixerInterface( this, "/dev/mixer" ); 145 _mixer = new OMixerInterface( this, "/dev/mixer" );
146#endif
142} 147}
143 148
144 149
145/*====================================================================================== 150/*======================================================================================
146 * OAudioInterface 151 * OAudioInterface
147 *======================================================================================*/ 152 *======================================================================================*/
148 153
149OAudioInterface::OAudioInterface( QObject* parent, const char* name ) 154OAudioInterface::OAudioInterface( QObject* parent, const char* name )
150 :QObject( parent, name ), _sfd(0) 155 :QObject( parent, name ), _sfd(0)
151{ 156{
152 odebug << "OAudioInterface::OAudioInterface()" << oendl; 157 odebug << "OAudioInterface::OAudioInterface()" << oendl;
153 init(); 158 init();
154} 159}
155 160
156 161
157OAudioInterface::~OAudioInterface() 162OAudioInterface::~OAudioInterface()
158{ 163{
159} 164}
160 165
161 166
162void OAudioInterface::init() 167void OAudioInterface::init()
163{ 168{
164 169
165 170
166} 171}
167 172
168 173
169/*====================================================================================== 174/*======================================================================================
170 * OMixerInterface 175 * OMixerInterface
171 *======================================================================================*/ 176 *======================================================================================*/
172 177
173OMixerInterface::OMixerInterface( QObject* parent, const char* name ) 178OMixerInterface::OMixerInterface( QObject* parent, const char* name )
174 :QObject( parent, name ) 179 :QObject( parent, name )
175{ 180{
176 odebug << "OMixerInterface::OMixerInterface()" << oendl; 181 odebug << "OMixerInterface::OMixerInterface()" << oendl;
177 init(); 182 init();
178} 183}
179 184
180 185
181OMixerInterface::~OMixerInterface() 186OMixerInterface::~OMixerInterface()
182{ 187{
183} 188}
184 189
185 190
186void OMixerInterface::init() 191void OMixerInterface::init()
187{ 192{
188 // open the device 193 // open the device
189 _fd = ::open( name(), O_RDWR ); 194 _fd = ::open( name(), O_RDWR );
190 if ( _fd == -1 ) 195 if ( _fd == -1 )
191 { 196 {
192 owarn << "OMixerInterface::init(): Can't open mixer." << oendl; 197 owarn << "OMixerInterface::init(): Can't open mixer." << oendl;
193 return; 198 return;
194 } 199 }
195 200
196 // construct the device capabilities 201 // construct the device capabilities
197 int devmask = 0; 202 int devmask = 0;
198 if ( ioctl( _fd, SOUND_MIXER_READ_DEVMASK, &devmask ) != -1 ) 203 if ( ioctl( _fd, SOUND_MIXER_READ_DEVMASK, &devmask ) != -1 )
199 { 204 {
200 if ( devmask & ( 1 << SOUND_MIXER_VOLUME ) ) _channels.insert( "PlayVolume", SOUND_MIXER_VOLUME ); 205 if ( devmask & ( 1 << SOUND_MIXER_VOLUME ) ) _channels.insert( "PlayVolume", SOUND_MIXER_VOLUME );
201 if ( devmask & ( 1 << SOUND_MIXER_BASS ) ) _channels.insert( "PlayBass", SOUND_MIXER_BASS ); 206 if ( devmask & ( 1 << SOUND_MIXER_BASS ) ) _channels.insert( "PlayBass", SOUND_MIXER_BASS );
202 if ( devmask & ( 1 << SOUND_MIXER_TREBLE ) ) _channels.insert( "PlayTreble", SOUND_MIXER_TREBLE ); 207 if ( devmask & ( 1 << SOUND_MIXER_TREBLE ) ) _channels.insert( "PlayTreble", SOUND_MIXER_TREBLE );
203 if ( devmask & ( 1 << SOUND_MIXER_SYNTH ) ) _channels.insert( "PlaySynth", SOUND_MIXER_SYNTH ); 208 if ( devmask & ( 1 << SOUND_MIXER_SYNTH ) ) _channels.insert( "PlaySynth", SOUND_MIXER_SYNTH );
204 if ( devmask & ( 1 << SOUND_MIXER_PCM ) ) _channels.insert( "PlayPCM", SOUND_MIXER_PCM ); 209 if ( devmask & ( 1 << SOUND_MIXER_PCM ) ) _channels.insert( "PlayPCM", SOUND_MIXER_PCM );
205 if ( devmask & ( 1 << SOUND_MIXER_SPEAKER ) ) _channels.insert( "PlaySpeaker", SOUND_MIXER_SPEAKER ); 210 if ( devmask & ( 1 << SOUND_MIXER_SPEAKER ) ) _channels.insert( "PlaySpeaker", SOUND_MIXER_SPEAKER );
206 if ( devmask & ( 1 << SOUND_MIXER_LINE ) ) _channels.insert( "PlayLine", SOUND_MIXER_LINE ); 211 if ( devmask & ( 1 << SOUND_MIXER_LINE ) ) _channels.insert( "PlayLine", SOUND_MIXER_LINE );
207 if ( devmask & ( 1 << SOUND_MIXER_MIC ) ) _channels.insert( "PlayMic", SOUND_MIXER_MIC ); 212 if ( devmask & ( 1 << SOUND_MIXER_MIC ) ) _channels.insert( "PlayMic", SOUND_MIXER_MIC );
208 if ( devmask & ( 1 << SOUND_MIXER_CD ) ) _channels.insert( "PlayCD", SOUND_MIXER_CD ); 213 if ( devmask & ( 1 << SOUND_MIXER_CD ) ) _channels.insert( "PlayCD", SOUND_MIXER_CD );
209 if ( devmask & ( 1 << SOUND_MIXER_IMIX ) ) _channels.insert( "PlayInputMix", SOUND_MIXER_IMIX ); 214 if ( devmask & ( 1 << SOUND_MIXER_IMIX ) ) _channels.insert( "PlayInputMix", SOUND_MIXER_IMIX );
210 if ( devmask & ( 1 << SOUND_MIXER_ALTPCM ) ) _channels.insert( "PlayAltPCM", SOUND_MIXER_ALTPCM ); 215 if ( devmask & ( 1 << SOUND_MIXER_ALTPCM ) ) _channels.insert( "PlayAltPCM", SOUND_MIXER_ALTPCM );
211 if ( devmask & ( 1 << SOUND_MIXER_RECLEV ) ) _channels.insert( "PlayRecord", SOUND_MIXER_RECLEV ); 216 if ( devmask & ( 1 << SOUND_MIXER_RECLEV ) ) _channels.insert( "PlayRecord", SOUND_MIXER_RECLEV );
212 if ( devmask & ( 1 << SOUND_MIXER_IGAIN ) ) _channels.insert( "PlayInputGain", SOUND_MIXER_IGAIN ); 217 if ( devmask & ( 1 << SOUND_MIXER_IGAIN ) ) _channels.insert( "PlayInputGain", SOUND_MIXER_IGAIN );
213 if ( devmask & ( 1 << SOUND_MIXER_OGAIN ) ) _channels.insert( "PlayOutputGain", SOUND_MIXER_OGAIN ); 218 if ( devmask & ( 1 << SOUND_MIXER_OGAIN ) ) _channels.insert( "PlayOutputGain", SOUND_MIXER_OGAIN );
214 //odebug << "devmask available and constructed." << oendl; 219 //odebug << "devmask available and constructed." << oendl;
215 } 220 }
216 221
217 devmask = 0; 222 devmask = 0;
218 if ( ioctl( _fd, SOUND_MIXER_READ_RECMASK, &devmask ) != -1 ) 223 if ( ioctl( _fd, SOUND_MIXER_READ_RECMASK, &devmask ) != -1 )
219 { 224 {
220 if ( devmask & ( 1 << SOUND_MIXER_VOLUME ) ) _channels.insert( "RecVolume", SOUND_MIXER_VOLUME ); 225 if ( devmask & ( 1 << SOUND_MIXER_VOLUME ) ) _channels.insert( "RecVolume", SOUND_MIXER_VOLUME );
221 if ( devmask & ( 1 << SOUND_MIXER_BASS ) ) _channels.insert( "RecBass", SOUND_MIXER_BASS ); 226 if ( devmask & ( 1 << SOUND_MIXER_BASS ) ) _channels.insert( "RecBass", SOUND_MIXER_BASS );
222 if ( devmask & ( 1 << SOUND_MIXER_TREBLE ) ) _channels.insert( "RecTreble", SOUND_MIXER_TREBLE ); 227 if ( devmask & ( 1 << SOUND_MIXER_TREBLE ) ) _channels.insert( "RecTreble", SOUND_MIXER_TREBLE );
223 if ( devmask & ( 1 << SOUND_MIXER_SYNTH ) ) _channels.insert( "RecSynth", SOUND_MIXER_SYNTH ); 228 if ( devmask & ( 1 << SOUND_MIXER_SYNTH ) ) _channels.insert( "RecSynth", SOUND_MIXER_SYNTH );
224 if ( devmask & ( 1 << SOUND_MIXER_PCM ) ) _channels.insert( "RecPCM", SOUND_MIXER_PCM ); 229 if ( devmask & ( 1 << SOUND_MIXER_PCM ) ) _channels.insert( "RecPCM", SOUND_MIXER_PCM );
225 if ( devmask & ( 1 << SOUND_MIXER_SPEAKER ) ) _channels.insert( "RecSpeaker", SOUND_MIXER_SPEAKER ); 230 if ( devmask & ( 1 << SOUND_MIXER_SPEAKER ) ) _channels.insert( "RecSpeaker", SOUND_MIXER_SPEAKER );
226 if ( devmask & ( 1 << SOUND_MIXER_LINE ) ) _channels.insert( "RecLine", SOUND_MIXER_LINE ); 231 if ( devmask & ( 1 << SOUND_MIXER_LINE ) ) _channels.insert( "RecLine", SOUND_MIXER_LINE );
227 if ( devmask & ( 1 << SOUND_MIXER_MIC ) ) _channels.insert( "RecMic", SOUND_MIXER_MIC ); 232 if ( devmask & ( 1 << SOUND_MIXER_MIC ) ) _channels.insert( "RecMic", SOUND_MIXER_MIC );
228 if ( devmask & ( 1 << SOUND_MIXER_CD ) ) _channels.insert( "RecCD", SOUND_MIXER_CD ); 233 if ( devmask & ( 1 << SOUND_MIXER_CD ) ) _channels.insert( "RecCD", SOUND_MIXER_CD );
229 if ( devmask & ( 1 << SOUND_MIXER_IMIX ) ) _channels.insert( "RecInputMix", SOUND_MIXER_IMIX ); 234 if ( devmask & ( 1 << SOUND_MIXER_IMIX ) ) _channels.insert( "RecInputMix", SOUND_MIXER_IMIX );
230 if ( devmask & ( 1 << SOUND_MIXER_ALTPCM ) ) _channels.insert( "RecAltPCM", SOUND_MIXER_ALTPCM ); 235 if ( devmask & ( 1 << SOUND_MIXER_ALTPCM ) ) _channels.insert( "RecAltPCM", SOUND_MIXER_ALTPCM );
231 if ( devmask & ( 1 << SOUND_MIXER_RECLEV ) ) _channels.insert( "RecRecord", SOUND_MIXER_RECLEV ); 236 if ( devmask & ( 1 << SOUND_MIXER_RECLEV ) ) _channels.insert( "RecRecord", SOUND_MIXER_RECLEV );
232 if ( devmask & ( 1 << SOUND_MIXER_IGAIN ) ) _channels.insert( "RecInputGain", SOUND_MIXER_IGAIN ); 237 if ( devmask & ( 1 << SOUND_MIXER_IGAIN ) ) _channels.insert( "RecInputGain", SOUND_MIXER_IGAIN );
233 if ( devmask & ( 1 << SOUND_MIXER_OGAIN ) ) _channels.insert( "RecOutputGain", SOUND_MIXER_OGAIN ); 238 if ( devmask & ( 1 << SOUND_MIXER_OGAIN ) ) _channels.insert( "RecOutputGain", SOUND_MIXER_OGAIN );
234 //odebug << "recmask available and constructed." << oendl; 239 //odebug << "recmask available and constructed." << oendl;
235 } 240 }
236 241
237/* ChannelIterator it; 242/* ChannelIterator it;
238 for ( it = _channels.begin(); it != _channels.end(); ++it ) 243 for ( it = _channels.begin(); it != _channels.end(); ++it )
239 { 244 {
240 odebug << "Channel " << it.key() << " available (bit " << it.data() << ")" << oendl; 245 odebug << "Channel " << it.key() << " available (bit " << it.data() << ")" << oendl;
241 odebug << " +--- Volume: " << volume( it.key() ) & 0xff << " | " << volume( it.key() ) >> 8 << "" << oendl; 246 odebug << " +--- Volume: " << volume( it.key() ) & 0xff << " | " << volume( it.key() ) >> 8 << "" << oendl;
242 } 247 }
243*/ 248*/
244} 249}
245 250
246QStringList OMixerInterface::allChannels() const 251QStringList OMixerInterface::allChannels() const
247{ 252{
248 ChannelIterator it = _channels.begin(); 253 ChannelIterator it = _channels.begin();
249 QStringList channels; 254 QStringList channels;
250 while ( it != _channels.end() ) 255 while ( it != _channels.end() )
251 { 256 {
252 channels += it.key(); 257 channels += it.key();
253 it++; 258 it++;
254 } 259 }
255 return channels; 260 return channels;
256} 261}
257 262
258 263
259QStringList OMixerInterface::recChannels() const 264QStringList OMixerInterface::recChannels() const
260{ 265{
261 owarn << "NYI" << oendl; 266 owarn << "NYI" << oendl;
262 return QStringList(); 267 return QStringList();
263} 268}
264 269
265 270
266QStringList OMixerInterface::playChannels() const 271QStringList OMixerInterface::playChannels() const
267{ 272{
268 owarn << "NYI" << oendl; 273 owarn << "NYI" << oendl;
269 return QStringList(); 274 return QStringList();
270} 275}
271 276
272 277
273bool OMixerInterface::hasChannel( const QString& channel ) 278bool OMixerInterface::hasChannel( const QString& channel )
274{ 279{
275 return _channels.contains( channel ); 280 return _channels.contains( channel );
276} 281}
277 282
278 283
279void OMixerInterface::setVolume( const QString& channel, int left, int right ) 284void OMixerInterface::setVolume( const QString& channel, int left, int right )
280{ 285{
281 int volume = left; 286 int volume = left;
282 volume |= ( right == -1 ) ? left << 8 : right << 8; 287 volume |= ( right == -1 ) ? left << 8 : right << 8;
283 288
284 if ( _channels.contains( channel ) ) 289 if ( _channels.contains( channel ) )
285 { 290 {
286 int result = ioctl( _fd, MIXER_WRITE( _channels[channel] ), &volume ); 291 int result = ioctl( _fd, MIXER_WRITE( _channels[channel] ), &volume );
287 if ( result == -1 ) 292 if ( result == -1 )
288 { 293 {
289 owarn << "Can't set volume: " << strerror( errno ) << oendl; 294 owarn << "Can't set volume: " << strerror( errno ) << oendl;
290 } 295 }
291 else 296 else
292 { 297 {
293 if ( result & 0xff != left ) 298 if ( result & 0xff != left )
294 { 299 {
295 owarn << "Device adjusted volume from " << left << " to " << (result & 0xff) << oendl; 300 owarn << "Device adjusted volume from " << left << " to " << (result & 0xff) << oendl;
296 } 301 }
297 } 302 }
298 } 303 }
299} 304}
300 305
301 306
302int OMixerInterface::volume( const QString& channel ) const 307int OMixerInterface::volume( const QString& channel ) const
303{ 308{
304 int volume; 309 int volume;
305 310
306 if ( _channels.contains( channel ) ) 311 if ( _channels.contains( channel ) )
307 { 312 {
308 if ( ioctl( _fd, MIXER_READ( _channels[channel] ), &volume ) == -1 ) 313 if ( ioctl( _fd, MIXER_READ( _channels[channel] ), &volume ) == -1 )
309 { 314 {
310 owarn << "Can't get volume: " << strerror( errno ) << oendl; 315 owarn << "Can't get volume: " << strerror( errno ) << oendl;
311 } 316 }
312 else return volume; 317 else return volume;
313 } 318 }
314 return -1; 319 return -1;
315} 320}
316 321
317 322
diff --git a/library/qpeapplication.cpp b/library/qpeapplication.cpp
index c6d9cfd..ca90427 100644
--- a/library/qpeapplication.cpp
+++ b/library/qpeapplication.cpp
@@ -1,2175 +1,2191 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19*/ 19*/
20#define QTOPIA_INTERNAL_LANGLIST 20#define QTOPIA_INTERNAL_LANGLIST
21#include <stdlib.h> 21#include <stdlib.h>
22#include <unistd.h> 22#include <unistd.h>
23#ifndef Q_OS_MACX 23#ifndef Q_OS_MACX
24#include <linux/limits.h> // needed for some toolchains (PATH_MAX) 24#include <linux/limits.h> // needed for some toolchains (PATH_MAX)
25#endif 25#endif
26#include <qfile.h> 26#include <qfile.h>
27#include <qqueue.h> 27#include <qqueue.h>
28#ifdef Q_WS_QWS 28#ifdef Q_WS_QWS
29#ifndef QT_NO_COP 29#ifndef QT_NO_COP
30#if QT_VERSION <= 231 30#if QT_VERSION <= 231
31#define private public 31#define private public
32#define sendLocally processEvent 32#define sendLocally processEvent
33#include "qcopenvelope_qws.h" 33#include "qcopenvelope_qws.h"
34#undef private 34#undef private
35#else 35#else
36#include "qcopenvelope_qws.h" 36#include "qcopenvelope_qws.h"
37#endif 37#endif
38#endif 38#endif
39#include <qwindowsystem_qws.h> 39#include <qwindowsystem_qws.h>
40#endif 40#endif
41#include <qtextstream.h> 41#include <qtextstream.h>
42#include <qpalette.h> 42#include <qpalette.h>
43#include <qbuffer.h> 43#include <qbuffer.h>
44#include <qptrdict.h> 44#include <qptrdict.h>
45#include <qregexp.h> 45#include <qregexp.h>
46#include <qdir.h> 46#include <qdir.h>
47#include <qlabel.h> 47#include <qlabel.h>
48#include <qdialog.h> 48#include <qdialog.h>
49#include <qdragobject.h> 49#include <qdragobject.h>
50#include <qtextcodec.h> 50#include <qtextcodec.h>
51#include <qevent.h> 51#include <qevent.h>
52#include <qtooltip.h> 52#include <qtooltip.h>
53#include <qsignal.h> 53#include <qsignal.h>
54#include <qmainwindow.h> 54#include <qmainwindow.h>
55#include <qwidgetlist.h> 55#include <qwidgetlist.h>
56#include <qpixmapcache.h> 56#include <qpixmapcache.h>
57 57
58#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 58#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
59#define QTOPIA_INTERNAL_INITAPP 59#define QTOPIA_INTERNAL_INITAPP
60#include "qpeapplication.h" 60#include "qpeapplication.h"
61#include "qpestyle.h" 61#include "qpestyle.h"
62#include "styleinterface.h" 62#include "styleinterface.h"
63#if QT_VERSION >= 300 63#if QT_VERSION >= 300
64#include <qstylefactory.h> 64#include <qstylefactory.h>
65#else 65#else
66#include <qplatinumstyle.h> 66#include <qplatinumstyle.h>
67#include <qwindowsstyle.h> 67#include <qwindowsstyle.h>
68#include <qmotifstyle.h> 68#include <qmotifstyle.h>
69#include <qmotifplusstyle.h> 69#include <qmotifplusstyle.h>
70#include "lightstyle.h" 70#include "lightstyle.h"
71 71
72#include <qpe/qlibrary.h> 72#include <qpe/qlibrary.h>
73#endif 73#endif
74#include "global.h" 74#include "global.h"
75#include "resource.h" 75#include "resource.h"
76#if QT_VERSION <= 230 && defined(QT_NO_CODECS) 76#if QT_VERSION <= 230 && defined(QT_NO_CODECS)
77#include "qutfcodec.h" 77#include "qutfcodec.h"
78#endif 78#endif
79#include "config.h" 79#include "config.h"
80#include "network.h" 80#include "network.h"
81#ifdef QWS 81#ifdef QWS
82#include "fontmanager.h" 82#include "fontmanager.h"
83#include "fontdatabase.h" 83#include "fontdatabase.h"
84#endif 84#endif
85 85
86#include "alarmserver.h" 86#include "alarmserver.h"
87#include "applnk.h" 87#include "applnk.h"
88#include "qpemenubar.h" 88#include "qpemenubar.h"
89#include "textcodecinterface.h" 89#include "textcodecinterface.h"
90#include "imagecodecinterface.h" 90#include "imagecodecinterface.h"
91 91
92#include <unistd.h> 92#include <unistd.h>
93#include <sys/file.h> 93#include <sys/file.h>
94#include <sys/ioctl.h> 94#include <sys/ioctl.h>
95#ifndef QT_NO_SOUND 95#ifndef QT_NO_SOUND
96#include <sys/soundcard.h> 96#include <sys/soundcard.h>
97#endif 97#endif
98#include "qt_override_p.h" 98#include "qt_override_p.h"
99 99
100#include <backend/rohfeedback.h> 100#include <backend/rohfeedback.h>
101 101
102 102
103static bool useBigPixmaps = 0; 103static bool useBigPixmaps = 0;
104 104
105class HackWidget : public QWidget 105class HackWidget : public QWidget
106{ 106{
107public: 107public:
108 bool needsOk() 108 bool needsOk()
109 { return (getWState() & WState_Reserved1 ); } 109 { return (getWState() & WState_Reserved1 ); }
110 110
111 QRect normalGeometry() 111 QRect normalGeometry()
112 { return topData()->normalGeometry; }; 112 { return topData()->normalGeometry; };
113}; 113};
114 114
115class QPEApplicationData 115class QPEApplicationData
116{ 116{
117public: 117public:
118 QPEApplicationData ( ) : 118 QPEApplicationData ( ) :
119 presstimer( 0 ), presswidget( 0 ), rightpressed( false ), kbgrabbed( false ), 119 presstimer( 0 ), presswidget( 0 ), rightpressed( false ), kbgrabbed( false ),
120 notbusysent( false ), preloaded( false ), forceshow( false ), nomaximize( false ), 120 notbusysent( false ), preloaded( false ), forceshow( false ), nomaximize( false ),
121 keep_running( true ), qcopQok( false ), 121 keep_running( true ), qcopQok( false ),
122 fontFamily( "Vera" ), fontSize( 10 ), smallIconSize( 14 ), 122 fontFamily( "Vera" ), fontSize( 10 ), smallIconSize( 14 ),
123 bigIconSize( 32 ), qpe_main_widget( 0 ) 123 bigIconSize( 32 ), qpe_main_widget( 0 )
124 { 124 {
125 Config cfg( "qpe" ); 125 Config cfg( "qpe" );
126 cfg.setGroup( "Appearance" ); 126 cfg.setGroup( "Appearance" );
127 useBigPixmaps = cfg.readBoolEntry( "useBigPixmaps", false ); 127 useBigPixmaps = cfg.readBoolEntry( "useBigPixmaps", false );
128 fontFamily = cfg.readEntry( "FontFamily", "Vera" ); 128 fontFamily = cfg.readEntry( "FontFamily", "Vera" );
129 fontSize = cfg.readNumEntry( "FontSize", 10 ); 129 fontSize = cfg.readNumEntry( "FontSize", 10 );
130 smallIconSize = cfg.readNumEntry( "SmallIconSize", 14 ); 130 smallIconSize = cfg.readNumEntry( "SmallIconSize", 14 );
131 bigIconSize = cfg.readNumEntry( "BigIconSize", 32 ); 131 bigIconSize = cfg.readNumEntry( "BigIconSize", 32 );
132#ifdef OPIE_WITHROHFEEDBACK 132#ifdef OPIE_WITHROHFEEDBACK
133 RoH = 0; 133 RoH = 0;
134#endif 134#endif
135 } 135 }
136 136
137 int presstimer; 137 int presstimer;
138 QWidget* presswidget; 138 QWidget* presswidget;
139 QPoint presspos; 139 QPoint presspos;
140#ifdef OPIE_WITHROHFEEDBACK 140#ifdef OPIE_WITHROHFEEDBACK
141 Opie::Internal::RoHFeedback *RoH; 141 Opie::Internal::RoHFeedback *RoH;
142#endif 142#endif
143 143
144 bool rightpressed : 1; 144 bool rightpressed : 1;
145 bool kbgrabbed : 1; 145 bool kbgrabbed : 1;
146 bool notbusysent : 1; 146 bool notbusysent : 1;
147 bool preloaded : 1; 147 bool preloaded : 1;
148 bool forceshow : 1; 148 bool forceshow : 1;
149 bool nomaximize : 1; 149 bool nomaximize : 1;
150 bool keep_running : 1; 150 bool keep_running : 1;
151 bool qcopQok : 1; 151 bool qcopQok : 1;
152 152
153 QCString fontFamily; 153 QCString fontFamily;
154 int fontSize; 154 int fontSize;
155 int smallIconSize; 155 int smallIconSize;
156 int bigIconSize; 156 int bigIconSize;
157 157
158 QStringList langs; 158 QStringList langs;
159 QString appName; 159 QString appName;
160 struct QCopRec 160 struct QCopRec
161 { 161 {
162 QCopRec( const QCString &ch, const QCString &msg, 162 QCopRec( const QCString &ch, const QCString &msg,
163 const QByteArray &d ) : 163 const QByteArray &d ) :
164 channel( ch ), message( msg ), data( d ) 164 channel( ch ), message( msg ), data( d )
165 { } 165 { }
166 166
167 QCString channel; 167 QCString channel;
168 QCString message; 168 QCString message;
169 QByteArray data; 169 QByteArray data;
170 }; 170 };
171 QWidget* qpe_main_widget; 171 QWidget* qpe_main_widget;
172 QGuardedPtr<QWidget> lastraised; 172 QGuardedPtr<QWidget> lastraised;
173 QQueue<QCopRec> qcopq; 173 QQueue<QCopRec> qcopq;
174 QString styleName; 174 QString styleName;
175 QString decorationName; 175 QString decorationName;
176 176
177 void enqueueQCop( const QCString &ch, const QCString &msg, 177 void enqueueQCop( const QCString &ch, const QCString &msg,
178 const QByteArray &data ) 178 const QByteArray &data )
179 { 179 {
180 qcopq.enqueue( new QCopRec( ch, msg, data ) ); 180 qcopq.enqueue( new QCopRec( ch, msg, data ) );
181 } 181 }
182 void sendQCopQ() 182 void sendQCopQ()
183 { 183 {
184 if (!qcopQok ) 184 if (!qcopQok )
185 return; 185 return;
186 186
187 QCopRec * r; 187 QCopRec * r;
188 188
189 while((r=qcopq.dequeue())) { 189 while((r=qcopq.dequeue())) {
190 // remove from queue before sending... 190 // remove from queue before sending...
191 // event loop can come around again before getting 191 // event loop can come around again before getting
192 // back from sendLocally 192 // back from sendLocally
193#ifndef QT_NO_COP 193#ifndef QT_NO_COP
194 QCopChannel::sendLocally( r->channel, r->message, r->data ); 194 QCopChannel::sendLocally( r->channel, r->message, r->data );
195#endif 195#endif
196 196
197 delete r; 197 delete r;
198 } 198 }
199 } 199 }
200 200
201 static void show_mx(QWidget* mw, bool nomaximize, QString &strName) 201 static void show_mx(QWidget* mw, bool nomaximize, QString &strName)
202 { 202 {
203 if ( mw->inherits("QMainWindow") || mw->isA("QMainWindow") ) 203 if ( mw->inherits("QMainWindow") || mw->isA("QMainWindow") )
204 { 204 {
205 ( ( QMainWindow* ) mw )->setUsesBigPixmaps( useBigPixmaps ); 205 ( ( QMainWindow* ) mw )->setUsesBigPixmaps( useBigPixmaps );
206 } 206 }
207 QPoint p; 207 QPoint p;
208 QSize s; 208 QSize s;
209 bool max; 209 bool max;
210 if ( mw->isVisible() ) { 210 if ( mw->isVisible() ) {
211 if ( read_widget_rect(strName, max, p, s) && validate_widget_size(mw, p, s) ) { 211 if ( read_widget_rect(strName, max, p, s) && validate_widget_size(mw, p, s) ) {
212 mw->resize(s); 212 mw->resize(s);
213 mw->move(p); 213 mw->move(p);
214 } 214 }
215 mw->raise(); 215 mw->raise();
216 } else { 216 } else {
217 217
218 if ( mw->layout() && mw->inherits("QDialog") ) { 218 if ( mw->layout() && mw->inherits("QDialog") ) {
219 if ( read_widget_rect(strName, max, p, s) && validate_widget_size(mw, p, s) ) { 219 if ( read_widget_rect(strName, max, p, s) && validate_widget_size(mw, p, s) ) {
220 mw->resize(s); 220 mw->resize(s);
221 mw->move(p); 221 mw->move(p);
222 222
223 if ( max && !nomaximize ) { 223 if ( max && !nomaximize ) {
224 mw->showMaximized(); 224 mw->showMaximized();
225 } else { 225 } else {
226 mw->show(); 226 mw->show();
227 } 227 }
228 } else { 228 } else {
229 qpe_show_dialog((QDialog*)mw,nomaximize); 229 qpe_show_dialog((QDialog*)mw,nomaximize);
230 } 230 }
231 } else { 231 } else {
232 if ( read_widget_rect(strName, max, p, s) && validate_widget_size(mw, p, s) ) { 232 if ( read_widget_rect(strName, max, p, s) && validate_widget_size(mw, p, s) ) {
233 mw->resize(s); 233 mw->resize(s);
234 mw->move(p); 234 mw->move(p);
235 } else { //no stored rectangle, make an estimation 235 } else { //no stored rectangle, make an estimation
236 int x = (qApp->desktop()->width()-mw->frameGeometry().width())/2; 236 int x = (qApp->desktop()->width()-mw->frameGeometry().width())/2;
237 int y = (qApp->desktop()->height()-mw->frameGeometry().height())/2; 237 int y = (qApp->desktop()->height()-mw->frameGeometry().height())/2;
238 mw->move( QMAX(x,0), QMAX(y,0) ); 238 mw->move( QMAX(x,0), QMAX(y,0) );
239#ifdef Q_WS_QWS 239#ifdef Q_WS_QWS
240 if ( !nomaximize ) 240 if ( !nomaximize )
241 mw->showMaximized(); 241 mw->showMaximized();
242#endif 242#endif
243 } 243 }
244 if ( max && !nomaximize ) 244 if ( max && !nomaximize )
245 mw->showMaximized(); 245 mw->showMaximized();
246 else 246 else
247 mw->show(); 247 mw->show();
248 } 248 }
249 } 249 }
250 } 250 }
251 251
252static void qpe_show_dialog( QDialog* d, bool nomax ) 252static void qpe_show_dialog( QDialog* d, bool nomax )
253{ 253{
254 QSize sh = d->sizeHint(); 254 QSize sh = d->sizeHint();
255 int w = QMAX(sh.width(),d->width()); 255 int w = QMAX(sh.width(),d->width());
256 int h = QMAX(sh.height(),d->height()); 256 int h = QMAX(sh.height(),d->height());
257 257
258 if ( d->parentWidget() && !d->parentWidget()->topLevelWidget()->isMaximized() ) 258 if ( d->parentWidget() && !d->parentWidget()->topLevelWidget()->isMaximized() )
259 nomax = TRUE; 259 nomax = TRUE;
260 260
261#ifndef Q_WS_QWS 261#ifndef Q_WS_QWS
262 QSize s(qApp->desktop()->width(), qApp->desktop()->height() ); 262 QSize s(qApp->desktop()->width(), qApp->desktop()->height() );
263#else 263#else
264 QSize s(qt_maxWindowRect.width(), qt_maxWindowRect.height() ); 264 QSize s(qt_maxWindowRect.width(), qt_maxWindowRect.height() );
265#endif 265#endif
266 266
267 int maxX = s.width() - (d->frameGeometry().width() - d->geometry().width()); 267 int maxX = s.width() - (d->frameGeometry().width() - d->geometry().width());
268 int maxY = s.height() - (d->frameGeometry().height() - d->geometry().height()); 268 int maxY = s.height() - (d->frameGeometry().height() - d->geometry().height());
269 269
270 if ( (w >= maxX && h >= maxY) || ( (!nomax) && ( w > s.width()*3/4 || h > s.height()*3/4 ) ) ) { 270 if ( (w >= maxX && h >= maxY) || ( (!nomax) && ( w > s.width()*3/4 || h > s.height()*3/4 ) ) ) {
271 d->showMaximized(); 271 d->showMaximized();
272 } else { 272 } else {
273 // try centering the dialog around its parent 273 // try centering the dialog around its parent
274 QPoint p(0,0); 274 QPoint p(0,0);
275 if ( d->parentWidget() ) { 275 if ( d->parentWidget() ) {
276 QPoint pp = d->parentWidget()->mapToGlobal( QPoint(0,0) ); 276 QPoint pp = d->parentWidget()->mapToGlobal( QPoint(0,0) );
277 p = QPoint( pp.x() + d->parentWidget()->width()/2, 277 p = QPoint( pp.x() + d->parentWidget()->width()/2,
278 pp.y() + d->parentWidget()->height()/ 2 ); 278 pp.y() + d->parentWidget()->height()/ 2 );
279 } else { 279 } else {
280 p = QPoint( maxX/2, maxY/2 ); 280 p = QPoint( maxX/2, maxY/2 );
281 } 281 }
282 282
283 p = QPoint( p.x() - w/2, p.y() - h/2 ); 283 p = QPoint( p.x() - w/2, p.y() - h/2 );
284// qDebug("p(x,y) is %d %d", p.x(), p.y() ); 284// qDebug("p(x,y) is %d %d", p.x(), p.y() );
285 285
286 if ( w >= maxX ) { 286 if ( w >= maxX ) {
287 if ( p.y() < 0 ) 287 if ( p.y() < 0 )
288 p.setY(0); 288 p.setY(0);
289 if ( p.y() + h > maxY ) 289 if ( p.y() + h > maxY )
290 p.setY( maxY - h); 290 p.setY( maxY - h);
291 291
292 d->resize(maxX, h); 292 d->resize(maxX, h);
293 d->move(0, p.y() ); 293 d->move(0, p.y() );
294 } else if ( h >= maxY ) { 294 } else if ( h >= maxY ) {
295 if ( p.x() < 0 ) 295 if ( p.x() < 0 )
296 p.setX(0); 296 p.setX(0);
297 if ( p.x() + w > maxX ) 297 if ( p.x() + w > maxX )
298 p.setX( maxX - w); 298 p.setX( maxX - w);
299 299
300 d->resize(w, maxY); 300 d->resize(w, maxY);
301 d->move(p.x(),0); 301 d->move(p.x(),0);
302 } else { 302 } else {
303 d->resize(w, h); 303 d->resize(w, h);
304 } 304 }
305 305
306 d->show(); 306 d->show();
307 } 307 }
308} 308}
309 309
310 static bool read_widget_rect(const QString &app, bool &maximized, QPoint &p, QSize &s) 310 static bool read_widget_rect(const QString &app, bool &maximized, QPoint &p, QSize &s)
311 { 311 {
312 maximized = TRUE; 312 maximized = TRUE;
313 // 350 is the trigger in qwsdefaultdecoration for providing a resize button 313 // 350 is the trigger in qwsdefaultdecoration for providing a resize button
314 if ( qApp->desktop()->width() <= 350 ) 314 if ( qApp->desktop()->width() <= 350 )
315 return FALSE; 315 return FALSE;
316 316
317 Config cfg( "qpe" ); 317 Config cfg( "qpe" );
318 cfg.setGroup("ApplicationPositions"); 318 cfg.setGroup("ApplicationPositions");
319 QString str = cfg.readEntry( app, QString::null ); 319 QString str = cfg.readEntry( app, QString::null );
320 QStringList l = QStringList::split(",", str); 320 QStringList l = QStringList::split(",", str);
321 321
322 if ( l.count() == 5) { 322 if ( l.count() == 5) {
323 p.setX( l[0].toInt() ); 323 p.setX( l[0].toInt() );
324 p.setY( l[1].toInt() ); 324 p.setY( l[1].toInt() );
325 325
326 s.setWidth( l[2].toInt() ); 326 s.setWidth( l[2].toInt() );
327 s.setHeight( l[3].toInt() ); 327 s.setHeight( l[3].toInt() );
328 328
329 maximized = l[4].toInt(); 329 maximized = l[4].toInt();
330 330
331 return TRUE; 331 return TRUE;
332 } 332 }
333 333
334 return FALSE; 334 return FALSE;
335 } 335 }
336 336
337 337
338 static bool validate_widget_size(const QWidget *w, QPoint &p, QSize &s) 338 static bool validate_widget_size(const QWidget *w, QPoint &p, QSize &s)
339 { 339 {
340#ifndef Q_WS_QWS 340#ifndef Q_WS_QWS
341 QRect qt_maxWindowRect = qApp->desktop()->geometry(); 341 QRect qt_maxWindowRect = qApp->desktop()->geometry();
342#endif 342#endif
343 int maxX = qt_maxWindowRect.width(); 343 int maxX = qt_maxWindowRect.width();
344 int maxY = qt_maxWindowRect.height(); 344 int maxY = qt_maxWindowRect.height();
345 int wWidth = s.width() + ( w->frameGeometry().width() - w->geometry().width() ); 345 int wWidth = s.width() + ( w->frameGeometry().width() - w->geometry().width() );
346 int wHeight = s.height() + ( w->frameGeometry().height() - w->geometry().height() ); 346 int wHeight = s.height() + ( w->frameGeometry().height() - w->geometry().height() );
347 347
348 // total window size is not allowed to be larger than desktop window size 348 // total window size is not allowed to be larger than desktop window size
349 if ( ( wWidth >= maxX ) && ( wHeight >= maxY ) ) 349 if ( ( wWidth >= maxX ) && ( wHeight >= maxY ) )
350 return FALSE; 350 return FALSE;
351 351
352 if ( wWidth > maxX ) { 352 if ( wWidth > maxX ) {
353 s.setWidth( maxX - (w->frameGeometry().width() - w->geometry().width() ) ); 353 s.setWidth( maxX - (w->frameGeometry().width() - w->geometry().width() ) );
354 wWidth = maxX; 354 wWidth = maxX;
355 } 355 }
356 356
357 if ( wHeight > maxY ) { 357 if ( wHeight > maxY ) {
358 s.setHeight( maxY - (w->frameGeometry().height() - w->geometry().height() ) ); 358 s.setHeight( maxY - (w->frameGeometry().height() - w->geometry().height() ) );
359 wHeight = maxY; 359 wHeight = maxY;
360 } 360 }
361 361
362 // any smaller than this and the maximize/close/help buttons will be overlapping 362 // any smaller than this and the maximize/close/help buttons will be overlapping
363 if ( wWidth < 80 || wHeight < 60 ) 363 if ( wWidth < 80 || wHeight < 60 )
364 return FALSE; 364 return FALSE;
365 365
366 if ( p.x() < 0 ) 366 if ( p.x() < 0 )
367 p.setX(0); 367 p.setX(0);
368 if ( p.y() < 0 ) 368 if ( p.y() < 0 )
369 p.setY(0); 369 p.setY(0);
370 370
371 if ( p.x() + wWidth > maxX ) 371 if ( p.x() + wWidth > maxX )
372 p.setX( maxX - wWidth ); 372 p.setX( maxX - wWidth );
373 if ( p.y() + wHeight > maxY ) 373 if ( p.y() + wHeight > maxY )
374 p.setY( maxY - wHeight ); 374 p.setY( maxY - wHeight );
375 375
376 return TRUE; 376 return TRUE;
377 } 377 }
378 378
379 static void store_widget_rect(QWidget *w, QString &app) 379 static void store_widget_rect(QWidget *w, QString &app)
380 { 380 {
381 // 350 is the trigger in qwsdefaultdecoration for providing a resize button 381 // 350 is the trigger in qwsdefaultdecoration for providing a resize button
382 if ( qApp->desktop()->width() <= 350 ) 382 if ( qApp->desktop()->width() <= 350 )
383 return; 383 return;
384 // we use these to map the offset of geometry and pos. ( we can only use normalGeometry to 384 // we use these to map the offset of geometry and pos. ( we can only use normalGeometry to
385 // get the non-maximized version, so we have to do it the hard way ) 385 // get the non-maximized version, so we have to do it the hard way )
386 int offsetX = w->x() - w->geometry().left(); 386 int offsetX = w->x() - w->geometry().left();
387 int offsetY = w->y() - w->geometry().top(); 387 int offsetY = w->y() - w->geometry().top();
388 388
389 QRect r; 389 QRect r;
390 if ( w->isMaximized() ) 390 if ( w->isMaximized() )
391 r = ( (HackWidget *) w)->normalGeometry(); 391 r = ( (HackWidget *) w)->normalGeometry();
392 else 392 else
393 r = w->geometry(); 393 r = w->geometry();
394 394
395 // Stores the window placement as pos(), size() (due to the offset mapping) 395 // Stores the window placement as pos(), size() (due to the offset mapping)
396 Config cfg( "qpe" ); 396 Config cfg( "qpe" );
397 cfg.setGroup("ApplicationPositions"); 397 cfg.setGroup("ApplicationPositions");
398 QString s; 398 QString s;
399 s.sprintf("%d,%d,%d,%d,%d", r.left() + offsetX, r.top() + offsetY, r.width(), r.height(), w->isMaximized() ); 399 s.sprintf("%d,%d,%d,%d,%d", r.left() + offsetX, r.top() + offsetY, r.width(), r.height(), w->isMaximized() );
400 cfg.writeEntry( app, s ); 400 cfg.writeEntry( app, s );
401 } 401 }
402 402
403 static bool setWidgetCaptionFromAppName( QWidget* /*mw*/, const QString& /*appName*/, const QString& /*appsPath*/ ) 403 static bool setWidgetCaptionFromAppName( QWidget* /*mw*/, const QString& /*appName*/, const QString& /*appsPath*/ )
404 { 404 {
405 /* 405 /*
406 // This works but disable it for now until it is safe to apply 406 // This works but disable it for now until it is safe to apply
407 // What is does is scan the .desktop files of all the apps for 407 // What is does is scan the .desktop files of all the apps for
408 // the applnk that has the corresponding argv[0] as this program 408 // the applnk that has the corresponding argv[0] as this program
409 // then it uses the name stored in the .desktop file as the caption 409 // then it uses the name stored in the .desktop file as the caption
410 // for the main widget. This saves duplicating translations for 410 // for the main widget. This saves duplicating translations for
411 // the app name in the program and in the .desktop files. 411 // the app name in the program and in the .desktop files.
412 412
413 AppLnkSet apps( appsPath ); 413 AppLnkSet apps( appsPath );
414 414
415 QList<AppLnk> appsList = apps.children(); 415 QList<AppLnk> appsList = apps.children();
416 for ( QListIterator<AppLnk> it(appsList); it.current(); ++it ) { 416 for ( QListIterator<AppLnk> it(appsList); it.current(); ++it ) {
417 if ( (*it)->exec() == appName ) { 417 if ( (*it)->exec() == appName ) {
418 mw->setCaption( (*it)->name() ); 418 mw->setCaption( (*it)->name() );
419 return TRUE; 419 return TRUE;
420 } 420 }
421 } 421 }
422 */ 422 */
423 return FALSE; 423 return FALSE;
424 } 424 }
425 425
426 426
427 void show(QWidget* mw, bool nomax) 427 void show(QWidget* mw, bool nomax)
428 { 428 {
429 setWidgetCaptionFromAppName( mw, appName, QPEApplication::qpeDir() + "apps" ); 429 setWidgetCaptionFromAppName( mw, appName, QPEApplication::qpeDir() + "apps" );
430 nomaximize = nomax; 430 nomaximize = nomax;
431 qpe_main_widget = mw; 431 qpe_main_widget = mw;
432 qcopQok = TRUE; 432 qcopQok = TRUE;
433#ifndef QT_NO_COP 433#ifndef QT_NO_COP
434 434
435 sendQCopQ(); 435 sendQCopQ();
436#endif 436#endif
437 437
438 if ( preloaded ) { 438 if ( preloaded ) {
439 if (forceshow) 439 if (forceshow)
440 show_mx(mw, nomax, appName); 440 show_mx(mw, nomax, appName);
441 } 441 }
442 else if ( keep_running ) { 442 else if ( keep_running ) {
443 show_mx(mw, nomax, appName); 443 show_mx(mw, nomax, appName);
444 } 444 }
445 } 445 }
446 446
447 void loadTextCodecs() 447 void loadTextCodecs()
448 { 448 {
449 QString path = QPEApplication::qpeDir() + "/plugins/textcodecs"; 449 QString path = QPEApplication::qpeDir() + "/plugins/textcodecs";
450#ifdef Q_OS_MACX 450#ifdef Q_OS_MACX
451 QDir dir( path, "lib*.dylib" ); 451 QDir dir( path, "lib*.dylib" );
452#else 452#else
453 QDir dir( path, "lib*.so" ); 453 QDir dir( path, "lib*.so" );
454#endif 454#endif
455 QStringList list; 455 QStringList list;
456 if ( dir. exists ( )) 456 if ( dir. exists ( ))
457 list = dir.entryList(); 457 list = dir.entryList();
458 QStringList::Iterator it; 458 QStringList::Iterator it;
459 for ( it = list.begin(); it != list.end(); ++it ) { 459 for ( it = list.begin(); it != list.end(); ++it ) {
460 TextCodecInterface *iface = 0; 460 TextCodecInterface *iface = 0;
461 QLibrary *lib = new QLibrary( path + "/" + *it ); 461 QLibrary *lib = new QLibrary( path + "/" + *it );
462 if ( lib->queryInterface( IID_QtopiaTextCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) { 462 if ( lib->queryInterface( IID_QtopiaTextCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) {
463 QValueList<int> mibs = iface->mibEnums(); 463 QValueList<int> mibs = iface->mibEnums();
464 for (QValueList<int>::ConstIterator i = mibs.begin(); i != mibs.end(); ++i) { 464 for (QValueList<int>::ConstIterator i = mibs.begin(); i != mibs.end(); ++i) {
465 (void)iface->createForMib(*i); 465 (void)iface->createForMib(*i);
466 // ### it exists now; need to remember if we can delete it 466 // ### it exists now; need to remember if we can delete it
467 } 467 }
468 } 468 }
469 else { 469 else {
470 lib->unload(); 470 lib->unload();
471 delete lib; 471 delete lib;
472 } 472 }
473 } 473 }
474 } 474 }
475 475
476 void loadImageCodecs() 476 void loadImageCodecs()
477 { 477 {
478 QString path = QPEApplication::qpeDir() + "/plugins/imagecodecs"; 478 QString path = QPEApplication::qpeDir() + "/plugins/imagecodecs";
479#ifdef Q_OS_MACX 479#ifdef Q_OS_MACX
480 QDir dir( path, "lib*.dylib" ); 480 QDir dir( path, "lib*.dylib" );
481#else 481#else
482 QDir dir( path, "lib*.so" ); 482 QDir dir( path, "lib*.so" );
483#endif 483#endif
484 QStringList list; 484 QStringList list;
485 if ( dir. exists ( )) 485 if ( dir. exists ( ))
486 list = dir.entryList(); 486 list = dir.entryList();
487 QStringList::Iterator it; 487 QStringList::Iterator it;
488 for ( it = list.begin(); it != list.end(); ++it ) { 488 for ( it = list.begin(); it != list.end(); ++it ) {
489 ImageCodecInterface *iface = 0; 489 ImageCodecInterface *iface = 0;
490 QLibrary *lib = new QLibrary( path + "/" + *it ); 490 QLibrary *lib = new QLibrary( path + "/" + *it );
491 if ( lib->queryInterface( IID_QtopiaImageCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) { 491 if ( lib->queryInterface( IID_QtopiaImageCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) {
492 QStringList formats = iface->keys(); 492 QStringList formats = iface->keys();
493 for (QStringList::ConstIterator i = formats.begin(); i != formats.end(); ++i) { 493 for (QStringList::ConstIterator i = formats.begin(); i != formats.end(); ++i) {
494 (void)iface->installIOHandler(*i); 494 (void)iface->installIOHandler(*i);
495 // ### it exists now; need to remember if we can delete it 495 // ### it exists now; need to remember if we can delete it
496 } 496 }
497 } 497 }
498 else { 498 else {
499 lib->unload(); 499 lib->unload();
500 delete lib; 500 delete lib;
501 } 501 }
502 } 502 }
503 } 503 }
504 504
505}; 505};
506 506
507class ResourceMimeFactory : public QMimeSourceFactory 507class ResourceMimeFactory : public QMimeSourceFactory
508{ 508{
509public: 509public:
510 ResourceMimeFactory() : resImage( 0 ) 510 ResourceMimeFactory() : resImage( 0 )
511 { 511 {
512 setFilePath( Global::helpPath() ); 512 setFilePath( Global::helpPath() );
513 setExtensionType( "html", "text/html;charset=UTF-8" ); 513 setExtensionType( "html", "text/html;charset=UTF-8" );
514 } 514 }
515 ~ResourceMimeFactory() { 515 ~ResourceMimeFactory() {
516 delete resImage; 516 delete resImage;
517 } 517 }
518 518
519 const QMimeSource* data( const QString& abs_name ) const 519 const QMimeSource* data( const QString& abs_name ) const
520 { 520 {
521 const QMimeSource * r = QMimeSourceFactory::data( abs_name ); 521 const QMimeSource * r = QMimeSourceFactory::data( abs_name );
522 if ( !r ) { 522 if ( !r ) {
523 int sl = abs_name.length(); 523 int sl = abs_name.length();
524 do { 524 do {
525 sl = abs_name.findRev( '/', sl - 1 ); 525 sl = abs_name.findRev( '/', sl - 1 );
526 QString name = sl >= 0 ? abs_name.mid( sl + 1 ) : abs_name; 526 QString name = sl >= 0 ? abs_name.mid( sl + 1 ) : abs_name;
527 int dot = name.findRev( '.' ); 527 int dot = name.findRev( '.' );
528 if ( dot >= 0 ) 528 if ( dot >= 0 )
529 name = name.left( dot ); 529 name = name.left( dot );
530 QImage img = Resource::loadImage( name ); 530 QImage img = Resource::loadImage( name );
531 if ( !img.isNull() ) { 531 if ( !img.isNull() ) {
532 delete resImage; 532 delete resImage;
533 resImage = new QImageDrag( img ); 533 resImage = new QImageDrag( img );
534 r = resImage; 534 r = resImage;
535 } 535 }
536 } 536 }
537 while ( !r && sl > 0 ); 537 while ( !r && sl > 0 );
538 } 538 }
539 return r; 539 return r;
540 } 540 }
541private: 541private:
542 mutable QImageDrag *resImage; 542 mutable QImageDrag *resImage;
543}; 543};
544 544
545static int& hack(int& i) 545static int& hack(int& i)
546{ 546{
547#if QT_VERSION <= 230 && defined(QT_NO_CODECS) 547#if QT_VERSION <= 230 && defined(QT_NO_CODECS)
548 // These should be created, but aren't in Qt 2.3.0 548 // These should be created, but aren't in Qt 2.3.0
549 (void)new QUtf8Codec; 549 (void)new QUtf8Codec;
550 (void)new QUtf16Codec; 550 (void)new QUtf16Codec;
551#endif 551#endif
552 return i; 552 return i;
553} 553}
554 554
555static int muted = 0; 555static int muted = 0;
556static int micMuted = 0; 556static int micMuted = 0;
557 557
558static void setVolume( int t = 0, int percent = -1 ) 558static void setVolume( int t = 0, int percent = -1 )
559{ 559{
560 switch ( t ) { 560 switch ( t ) {
561 case 0: { 561 case 0: {
562 Config cfg( "qpe" ); 562 Config cfg( "qpe" );
563 cfg.setGroup( "Volume" ); 563 cfg.setGroup( "Volume" );
564 if ( percent < 0 ) 564 if ( percent < 0 )
565 percent = cfg.readNumEntry( "VolumePercent", 50 ); 565 percent = cfg.readNumEntry( "VolumePercent", 50 );
566#ifndef QT_NO_SOUND 566#ifndef QT_NO_SOUND
567 int fd = 0; 567 int fd = 0;
568#ifdef QT_QWS_DEVFS
569 if ( ( fd = open( "/dev/sound/mixer", O_RDWR ) ) >= 0 ) {
570#else
568 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { 571 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
572#endif
569 int vol = muted ? 0 : percent; 573 int vol = muted ? 0 : percent;
570 // set both channels to same volume 574 // set both channels to same volume
571 vol |= vol << 8; 575 vol |= vol << 8;
572 ioctl( fd, MIXER_WRITE( SOUND_MIXER_VOLUME ), &vol ); 576 ioctl( fd, MIXER_WRITE( SOUND_MIXER_VOLUME ), &vol );
573 ::close( fd ); 577 ::close( fd );
574 } 578 }
575#endif 579#endif
576 } 580 }
577 break; 581 break;
578 } 582 }
579} 583}
580 584
581static void setMic( int t = 0, int percent = -1 ) 585static void setMic( int t = 0, int percent = -1 )
582{ 586{
583 switch ( t ) { 587 switch ( t ) {
584 case 0: { 588 case 0: {
585 Config cfg( "qpe" ); 589 Config cfg( "qpe" );
586 cfg.setGroup( "Volume" ); 590 cfg.setGroup( "Volume" );
587 if ( percent < 0 ) 591 if ( percent < 0 )
588 percent = cfg.readNumEntry( "Mic", 50 ); 592 percent = cfg.readNumEntry( "Mic", 50 );
589 593
590#ifndef QT_NO_SOUND 594#ifndef QT_NO_SOUND
591 int fd = 0; 595 int fd = 0;
592 int mic = micMuted ? 0 : percent; 596 int mic = micMuted ? 0 : percent;
597#ifdef QT_QWS_DEVFS
598 if ( ( fd = open( "/dev/sound/mixer", O_RDWR ) ) >= 0 ) {
599#else
593 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { 600 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
601#endif
594 ioctl( fd, MIXER_WRITE( SOUND_MIXER_MIC ), &mic ); 602 ioctl( fd, MIXER_WRITE( SOUND_MIXER_MIC ), &mic );
595 ::close( fd ); 603 ::close( fd );
596 } 604 }
597#endif 605#endif
598 } 606 }
599 break; 607 break;
600 } 608 }
601} 609}
602 610
603 611
604static void setBass( int t = 0, int percent = -1 ) 612static void setBass( int t = 0, int percent = -1 )
605{ 613{
606 switch ( t ) { 614 switch ( t ) {
607 case 0: { 615 case 0: {
608 Config cfg( "qpe" ); 616 Config cfg( "qpe" );
609 cfg.setGroup( "Volume" ); 617 cfg.setGroup( "Volume" );
610 if ( percent < 0 ) 618 if ( percent < 0 )
611 percent = cfg.readNumEntry( "BassPercent", 50 ); 619 percent = cfg.readNumEntry( "BassPercent", 50 );
612 620
613#ifndef QT_NO_SOUND 621#ifndef QT_NO_SOUND
614 int fd = 0; 622 int fd = 0;
615 int bass = percent; 623 int bass = percent;
624#ifdef QT_QWS_DEVFS
625 if ( ( fd = open( "/dev/sound/mixer", O_RDWR ) ) >= 0 ) {
626#else
616 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { 627 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
628#endif
617 ioctl( fd, MIXER_WRITE( SOUND_MIXER_BASS ), &bass ); 629 ioctl( fd, MIXER_WRITE( SOUND_MIXER_BASS ), &bass );
618 ::close( fd ); 630 ::close( fd );
619 } 631 }
620#endif 632#endif
621 } 633 }
622 break; 634 break;
623 } 635 }
624} 636}
625 637
626 638
627static void setTreble( int t = 0, int percent = -1 ) 639static void setTreble( int t = 0, int percent = -1 )
628{ 640{
629 switch ( t ) { 641 switch ( t ) {
630 case 0: { 642 case 0: {
631 Config cfg( "qpe" ); 643 Config cfg( "qpe" );
632 cfg.setGroup( "Volume" ); 644 cfg.setGroup( "Volume" );
633 if ( percent < 0 ) 645 if ( percent < 0 )
634 percent = cfg.readNumEntry( "TreblePercent", 50 ); 646 percent = cfg.readNumEntry( "TreblePercent", 50 );
635 647
636#ifndef QT_NO_SOUND 648#ifndef QT_NO_SOUND
637 int fd = 0; 649 int fd = 0;
638 int treble = percent; 650 int treble = percent;
651#ifdef QT_QWS_DEVFS
652 if ( ( fd = open( "/dev/sound/mixer", O_RDWR ) ) >= 0 ) {
653#else
639 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { 654 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
655#endif
640 ioctl( fd, MIXER_WRITE( SOUND_MIXER_TREBLE ), &treble ); 656 ioctl( fd, MIXER_WRITE( SOUND_MIXER_TREBLE ), &treble );
641 ::close( fd ); 657 ::close( fd );
642 } 658 }
643#endif 659#endif
644 } 660 }
645 break; 661 break;
646 } 662 }
647} 663}
648 664
649 665
650/** 666/**
651 \class QPEApplication 667 \class QPEApplication
652 \brief The QPEApplication class implements various system services 668 \brief The QPEApplication class implements various system services
653 that are available to all Qtopia applications. 669 that are available to all Qtopia applications.
654 670
655 Simply by using QPEApplication instead of QApplication, a standard Qt 671 Simply by using QPEApplication instead of QApplication, a standard Qt
656 application becomes a Qtopia application. It automatically follows 672 application becomes a Qtopia application. It automatically follows
657 style changes, quits and raises, and in the 673 style changes, quits and raises, and in the
658 case of \link docwidget.html document-oriented\endlink applications, 674 case of \link docwidget.html document-oriented\endlink applications,
659 changes the currently displayed document in response to the environment. 675 changes the currently displayed document in response to the environment.
660 676
661 To create a \link docwidget.html document-oriented\endlink 677 To create a \link docwidget.html document-oriented\endlink
662 application use showMainDocumentWidget(); to create a 678 application use showMainDocumentWidget(); to create a
663 non-document-oriented application use showMainWidget(). The 679 non-document-oriented application use showMainWidget(). The
664 keepRunning() function indicates whether the application will 680 keepRunning() function indicates whether the application will
665 continue running after it's processed the last \link qcop.html 681 continue running after it's processed the last \link qcop.html
666 QCop\endlink message. This can be changed using setKeepRunning(). 682 QCop\endlink message. This can be changed using setKeepRunning().
667 683
668 A variety of signals are emitted when certain events occur, for 684 A variety of signals are emitted when certain events occur, for
669 example, timeChanged(), clockChanged(), weekChanged(), 685 example, timeChanged(), clockChanged(), weekChanged(),
670 dateFormatChanged() and volumeChanged(). If the application receives 686 dateFormatChanged() and volumeChanged(). If the application receives
671 a \link qcop.html QCop\endlink message on the application's 687 a \link qcop.html QCop\endlink message on the application's
672 QPE/Application/\e{appname} channel, the appMessage() signal is 688 QPE/Application/\e{appname} channel, the appMessage() signal is
673 emitted. There are also flush() and reload() signals, which 689 emitted. There are also flush() and reload() signals, which
674 are emitted when synching begins and ends respectively - upon these 690 are emitted when synching begins and ends respectively - upon these
675 signals, the application should save and reload any data 691 signals, the application should save and reload any data
676 files that are involved in synching. Most of these signals will initially 692 files that are involved in synching. Most of these signals will initially
677 be received and unfiltered through the appMessage() signal. 693 be received and unfiltered through the appMessage() signal.
678 694
679 This class also provides a set of useful static functions. The 695 This class also provides a set of useful static functions. The
680 qpeDir() and documentDir() functions return the respective paths. 696 qpeDir() and documentDir() functions return the respective paths.
681 The grabKeyboard() and ungrabKeyboard() functions are used to 697 The grabKeyboard() and ungrabKeyboard() functions are used to
682 control whether the application takes control of the device's 698 control whether the application takes control of the device's
683 physical buttons (e.g. application launch keys). The stylus' mode of 699 physical buttons (e.g. application launch keys). The stylus' mode of
684 operation is set with setStylusOperation() and retrieved with 700 operation is set with setStylusOperation() and retrieved with
685 stylusOperation(). There are also setInputMethodHint() and 701 stylusOperation(). There are also setInputMethodHint() and
686 inputMethodHint() functions. 702 inputMethodHint() functions.
687 703
688 \ingroup qtopiaemb 704 \ingroup qtopiaemb
689*/ 705*/
690 706
691/*! 707/*!
692 \fn void QPEApplication::clientMoused() 708 \fn void QPEApplication::clientMoused()
693 709
694 \internal 710 \internal
695*/ 711*/
696 712
697/*! 713/*!
698 \fn void QPEApplication::timeChanged(); 714 \fn void QPEApplication::timeChanged();
699 This signal is emitted when the time changes outside the normal 715 This signal is emitted when the time changes outside the normal
700 passage of time, i.e. if the time is set backwards or forwards. 716 passage of time, i.e. if the time is set backwards or forwards.
701*/ 717*/
702 718
703/*! 719/*!
704 \fn void QPEApplication::clockChanged( bool ampm ); 720 \fn void QPEApplication::clockChanged( bool ampm );
705 721
706 This signal is emitted when the user changes the clock's style. If 722 This signal is emitted when the user changes the clock's style. If
707 \a ampm is TRUE, the user wants a 12-hour AM/PM clock, otherwise, 723 \a ampm is TRUE, the user wants a 12-hour AM/PM clock, otherwise,
708 they want a 24-hour clock. 724 they want a 24-hour clock.
709*/ 725*/
710 726
711/*! 727/*!
712 \fn void QPEApplication::volumeChanged( bool muted ) 728 \fn void QPEApplication::volumeChanged( bool muted )
713 729
714 This signal is emitted whenever the mute state is changed. If \a 730 This signal is emitted whenever the mute state is changed. If \a
715 muted is TRUE, then sound output has been muted. 731 muted is TRUE, then sound output has been muted.
716*/ 732*/
717 733
718/*! 734/*!
719 \fn void QPEApplication::weekChanged( bool startOnMonday ) 735 \fn void QPEApplication::weekChanged( bool startOnMonday )
720 736
721 This signal is emitted if the week start day is changed. If \a 737 This signal is emitted if the week start day is changed. If \a
722 startOnMonday is TRUE then the first day of the week is Monday; if 738 startOnMonday is TRUE then the first day of the week is Monday; if
723 \a startOnMonday is FALSE then the first day of the week is 739 \a startOnMonday is FALSE then the first day of the week is
724 Sunday. 740 Sunday.
725*/ 741*/
726 742
727/*! 743/*!
728 \fn void QPEApplication::dateFormatChanged(DateFormat) 744 \fn void QPEApplication::dateFormatChanged(DateFormat)
729 745
730 This signal is emitted whenever the date format is changed. 746 This signal is emitted whenever the date format is changed.
731*/ 747*/
732 748
733/*! 749/*!
734 \fn void QPEApplication::flush() 750 \fn void QPEApplication::flush()
735 751
736 ### 752 ###
737*/ 753*/
738 754
739/*! 755/*!
740 \fn void QPEApplication::reload() 756 \fn void QPEApplication::reload()
741 757
742*/ 758*/
743 759
744 760
745 761
746void QPEApplication::processQCopFile() 762void QPEApplication::processQCopFile()
747{ 763{
748 QString qcopfn("/tmp/qcop-msg-"); 764 QString qcopfn("/tmp/qcop-msg-");
749 qcopfn += d->appName; // append command name 765 qcopfn += d->appName; // append command name
750 766
751 QFile f(qcopfn); 767 QFile f(qcopfn);
752 if ( f.open(IO_ReadWrite) ) { 768 if ( f.open(IO_ReadWrite) ) {
753#ifndef Q_OS_WIN32 769#ifndef Q_OS_WIN32
754 flock(f.handle(), LOCK_EX); 770 flock(f.handle(), LOCK_EX);
755#endif 771#endif
756 QDataStream ds(&f); 772 QDataStream ds(&f);
757 QCString channel, message; 773 QCString channel, message;
758 QByteArray data; 774 QByteArray data;
759 while(!ds.atEnd()) { 775 while(!ds.atEnd()) {
760 ds >> channel >> message >> data; 776 ds >> channel >> message >> data;
761 d->enqueueQCop(channel,message,data); 777 d->enqueueQCop(channel,message,data);
762 } 778 }
763 ::ftruncate(f.handle(), 0); 779 ::ftruncate(f.handle(), 0);
764#ifndef Q_OS_WIN32 780#ifndef Q_OS_WIN32
765 f.flush(); 781 f.flush();
766 flock(f.handle(), LOCK_UN); 782 flock(f.handle(), LOCK_UN);
767#endif 783#endif
768 } 784 }
769#endif 785#endif
770} 786}
771 787
772 788
773/*! 789/*!
774 \fn void QPEApplication::appMessage( const QCString& msg, const QByteArray& data ) 790 \fn void QPEApplication::appMessage( const QCString& msg, const QByteArray& data )
775 791
776 This signal is emitted when a message is received on this 792 This signal is emitted when a message is received on this
777 application's QPE/Application/<i>appname</i> \link qcop.html 793 application's QPE/Application/<i>appname</i> \link qcop.html
778 QCop\endlink channel. 794 QCop\endlink channel.
779 795
780 The slot to which you connect this signal uses \a msg and \a data 796 The slot to which you connect this signal uses \a msg and \a data
781 in the following way: 797 in the following way:
782 798
783\code 799\code
784 void MyWidget::receive( const QCString& msg, const QByteArray& data ) 800 void MyWidget::receive( const QCString& msg, const QByteArray& data )
785 { 801 {
786 QDataStream stream( data, IO_ReadOnly ); 802 QDataStream stream( data, IO_ReadOnly );
787 if ( msg == "someMessage(int,int,int)" ) { 803 if ( msg == "someMessage(int,int,int)" ) {
788 int a,b,c; 804 int a,b,c;
789 stream >> a >> b >> c; 805 stream >> a >> b >> c;
790 ... 806 ...
791 } else if ( msg == "otherMessage(QString)" ) { 807 } else if ( msg == "otherMessage(QString)" ) {
792 ... 808 ...
793 } 809 }
794 } 810 }
795\endcode 811\endcode
796 812
797 \sa qcop.html 813 \sa qcop.html
798 Note that messages received here may be processed by qpe application 814 Note that messages received here may be processed by qpe application
799 and emitted as signals, such as flush() and reload(). 815 and emitted as signals, such as flush() and reload().
800*/ 816*/
801 817
802/*! 818/*!
803 Constructs a QPEApplication just as you would construct 819 Constructs a QPEApplication just as you would construct
804 a QApplication, passing \a argc, \a argv, and \a t. 820 a QApplication, passing \a argc, \a argv, and \a t.
805 821
806 For applications, \a t should be the default, GuiClient. Only 822 For applications, \a t should be the default, GuiClient. Only
807 the Qtopia server passes GuiServer. 823 the Qtopia server passes GuiServer.
808*/ 824*/
809QPEApplication::QPEApplication( int & argc, char **argv, Type t ) 825QPEApplication::QPEApplication( int & argc, char **argv, Type t )
810 : QApplication( hack(argc), argv, t ), pidChannel( 0 ) 826 : QApplication( hack(argc), argv, t ), pidChannel( 0 )
811{ 827{
812 QPixmapCache::setCacheLimit(256); // sensible default for smaller devices. 828 QPixmapCache::setCacheLimit(256); // sensible default for smaller devices.
813 829
814 d = new QPEApplicationData; 830 d = new QPEApplicationData;
815 d->loadTextCodecs(); 831 d->loadTextCodecs();
816 d->loadImageCodecs(); 832 d->loadImageCodecs();
817 833
818 setFont( QFont( d->fontFamily, d->fontSize ) ); 834 setFont( QFont( d->fontFamily, d->fontSize ) );
819 AppLnk::setSmallIconSize( d->smallIconSize ); 835 AppLnk::setSmallIconSize( d->smallIconSize );
820 AppLnk::setBigIconSize( d->bigIconSize ); 836 AppLnk::setBigIconSize( d->bigIconSize );
821 837
822 QMimeSourceFactory::setDefaultFactory( new ResourceMimeFactory ); 838 QMimeSourceFactory::setDefaultFactory( new ResourceMimeFactory );
823 839
824 connect( this, SIGNAL( lastWindowClosed() ), this, SLOT( hideOrQuit() ) ); 840 connect( this, SIGNAL( lastWindowClosed() ), this, SLOT( hideOrQuit() ) );
825 841
826 842
827 sysChannel = new QCopChannel( "QPE/System", this ); 843 sysChannel = new QCopChannel( "QPE/System", this );
828 connect( sysChannel, SIGNAL( received(const QCString&,const QByteArray&) ), 844 connect( sysChannel, SIGNAL( received(const QCString&,const QByteArray&) ),
829 this, SLOT( systemMessage(const QCString&,const QByteArray&) ) ); 845 this, SLOT( systemMessage(const QCString&,const QByteArray&) ) );
830 846
831/* COde now in initapp */ 847/* COde now in initapp */
832#if 0 848#if 0
833#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 849#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
834 850
835 QString qcopfn( "/tmp/qcop-msg-" ); 851 QString qcopfn( "/tmp/qcop-msg-" );
836 qcopfn += QString( argv[ 0 ] ); // append command name 852 qcopfn += QString( argv[ 0 ] ); // append command name
837 853
838 QFile f( qcopfn ); 854 QFile f( qcopfn );
839 if ( f.open( IO_ReadOnly ) ) { 855 if ( f.open( IO_ReadOnly ) ) {
840 flock( f.handle(), LOCK_EX ); 856 flock( f.handle(), LOCK_EX );
841 } 857 }
842 858
843 859
844 860
845 QCString channel = QCString( argv[ 0 ] ); 861 QCString channel = QCString( argv[ 0 ] );
846 channel.replace( QRegExp( ".*/" ), "" ); 862 channel.replace( QRegExp( ".*/" ), "" );
847 d->appName = channel; 863 d->appName = channel;
848 channel = "QPE/Application/" + channel; 864 channel = "QPE/Application/" + channel;
849 pidChannel = new QCopChannel( channel, this ); 865 pidChannel = new QCopChannel( channel, this );
850 connect( pidChannel, SIGNAL( received(const QCString&,const QByteArray&) ), 866 connect( pidChannel, SIGNAL( received(const QCString&,const QByteArray&) ),
851 this, SLOT( pidMessage(const QCString&,const QByteArray&) ) ); 867 this, SLOT( pidMessage(const QCString&,const QByteArray&) ) );
852 868
853 if ( f.isOpen() ) { 869 if ( f.isOpen() ) {
854 d->keep_running = FALSE; 870 d->keep_running = FALSE;
855 QDataStream ds( &f ); 871 QDataStream ds( &f );
856 QCString channel, message; 872 QCString channel, message;
857 QByteArray data; 873 QByteArray data;
858 while ( !ds.atEnd() ) { 874 while ( !ds.atEnd() ) {
859 ds >> channel >> message >> data; 875 ds >> channel >> message >> data;
860 d->enqueueQCop( channel, message, data ); 876 d->enqueueQCop( channel, message, data );
861 } 877 }
862 878
863 flock( f.handle(), LOCK_UN ); 879 flock( f.handle(), LOCK_UN );
864 f.close(); 880 f.close();
865 f.remove(); 881 f.remove();
866 } 882 }
867 883
868 for ( int a = 0; a < argc; a++ ) { 884 for ( int a = 0; a < argc; a++ ) {
869 if ( qstrcmp( argv[ a ], "-preload" ) == 0 ) { 885 if ( qstrcmp( argv[ a ], "-preload" ) == 0 ) {
870 argv[ a ] = argv[ a + 1 ]; 886 argv[ a ] = argv[ a + 1 ];
871 a++; 887 a++;
872 d->preloaded = TRUE; 888 d->preloaded = TRUE;
873 argc -= 1; 889 argc -= 1;
874 } 890 }
875 else if ( qstrcmp( argv[ a ], "-preload-show" ) == 0 ) { 891 else if ( qstrcmp( argv[ a ], "-preload-show" ) == 0 ) {
876 argv[ a ] = argv[ a + 1 ]; 892 argv[ a ] = argv[ a + 1 ];
877 a++; 893 a++;
878 d->preloaded = TRUE; 894 d->preloaded = TRUE;
879 d->forceshow = TRUE; 895 d->forceshow = TRUE;
880 argc -= 1; 896 argc -= 1;
881 } 897 }
882 } 898 }
883 899
884 /* overide stored arguments */ 900 /* overide stored arguments */
885 setArgs( argc, argv ); 901 setArgs( argc, argv );
886 902
887#endif 903#endif
888#else 904#else
889 initApp( argc, argv ); 905 initApp( argc, argv );
890#endif 906#endif
891#ifdef Q_WS_QWS 907#ifdef Q_WS_QWS
892 /* load the font renderer factories */ 908 /* load the font renderer factories */
893 FontDatabase::loadRenderers(); 909 FontDatabase::loadRenderers();
894#endif 910#endif
895#ifndef QT_NO_TRANSLATION 911#ifndef QT_NO_TRANSLATION
896 912
897 d->langs = Global::languageList(); 913 d->langs = Global::languageList();
898 for ( QStringList::ConstIterator it = d->langs.begin(); it != d->langs.end(); ++it ) { 914 for ( QStringList::ConstIterator it = d->langs.begin(); it != d->langs.end(); ++it ) {
899 QString lang = *it; 915 QString lang = *it;
900 916
901 installTranslation( lang + "/libopie.qm"); 917 installTranslation( lang + "/libopie.qm");
902 installTranslation( lang + "/libqpe.qm" ); 918 installTranslation( lang + "/libqpe.qm" );
903 installTranslation( lang + "/" + d->appName + ".qm" ); 919 installTranslation( lang + "/" + d->appName + ".qm" );
904 920
905 921
906 //###language/font hack; should look it up somewhere 922 //###language/font hack; should look it up somewhere
907#ifdef QWS 923#ifdef QWS
908 924
909 if ( lang == "ja" || lang == "zh_CN" || lang == "zh_TW" || lang == "ko" ) { 925 if ( lang == "ja" || lang == "zh_CN" || lang == "zh_TW" || lang == "ko" ) {
910 QFont fn = FontManager::unicodeFont( FontManager::Proportional ); 926 QFont fn = FontManager::unicodeFont( FontManager::Proportional );
911 setFont( fn ); 927 setFont( fn );
912 } 928 }
913#endif 929#endif
914 } 930 }
915#endif 931#endif
916 932
917 applyStyle(); 933 applyStyle();
918 934
919 if ( type() == GuiServer ) { 935 if ( type() == GuiServer ) {
920 setVolume(); 936 setVolume();
921 } 937 }
922 938
923 installEventFilter( this ); 939 installEventFilter( this );
924 940
925 QPEMenuToolFocusManager::initialize(); 941 QPEMenuToolFocusManager::initialize();
926 942
927#ifdef QT_NO_QWS_CURSOR 943#ifdef QT_NO_QWS_CURSOR
928 // if we have no cursor, probably don't want tooltips 944 // if we have no cursor, probably don't want tooltips
929 QToolTip::setEnabled( FALSE ); 945 QToolTip::setEnabled( FALSE );
930#endif 946#endif
931} 947}
932 948
933 949
934#ifdef QTOPIA_INTERNAL_INITAPP 950#ifdef QTOPIA_INTERNAL_INITAPP
935void QPEApplication::initApp( int argc, char **argv ) 951void QPEApplication::initApp( int argc, char **argv )
936{ 952{
937 delete pidChannel; 953 delete pidChannel;
938 d->keep_running = TRUE; 954 d->keep_running = TRUE;
939 d->preloaded = FALSE; 955 d->preloaded = FALSE;
940 d->forceshow = FALSE; 956 d->forceshow = FALSE;
941 957
942 QCString channel = QCString(argv[0]); 958 QCString channel = QCString(argv[0]);
943 959
944 channel.replace(QRegExp(".*/"),""); 960 channel.replace(QRegExp(".*/"),"");
945 d->appName = channel; 961 d->appName = channel;
946 962
947 #if QT_VERSION > 235 963 #if QT_VERSION > 235
948 qt_fbdpy->setIdentity( channel ); // In Qt/E 2.3.6 964 qt_fbdpy->setIdentity( channel ); // In Qt/E 2.3.6
949 #endif 965 #endif
950 966
951 channel = "QPE/Application/" + channel; 967 channel = "QPE/Application/" + channel;
952 pidChannel = new QCopChannel( channel, this); 968 pidChannel = new QCopChannel( channel, this);
953 connect( pidChannel, SIGNAL(received(const QCString&,const QByteArray&)), 969 connect( pidChannel, SIGNAL(received(const QCString&,const QByteArray&)),
954 this, SLOT(pidMessage(const QCString&,const QByteArray&))); 970 this, SLOT(pidMessage(const QCString&,const QByteArray&)));
955 971
956 972
957 973
958 processQCopFile(); 974 processQCopFile();
959 d->keep_running = d->qcopq.isEmpty(); 975 d->keep_running = d->qcopq.isEmpty();
960 976
961 for (int a=0; a<argc; a++) { 977 for (int a=0; a<argc; a++) {
962 if ( qstrcmp(argv[a],"-preload")==0 ) { 978 if ( qstrcmp(argv[a],"-preload")==0 ) {
963 argv[a] = argv[a+1]; 979 argv[a] = argv[a+1];
964 a++; 980 a++;
965 d->preloaded = TRUE; 981 d->preloaded = TRUE;
966 argc-=1; 982 argc-=1;
967 } else if ( qstrcmp(argv[a],"-preload-show")==0 ) { 983 } else if ( qstrcmp(argv[a],"-preload-show")==0 ) {
968 argv[a] = argv[a+1]; 984 argv[a] = argv[a+1];
969 a++; 985 a++;
970 d->preloaded = TRUE; 986 d->preloaded = TRUE;
971 d->forceshow = TRUE; 987 d->forceshow = TRUE;
972 argc-=1; 988 argc-=1;
973 } 989 }
974 } 990 }
975 991
976 /* overide stored arguments */ 992 /* overide stored arguments */
977 setArgs(argc, argv); 993 setArgs(argc, argv);
978 994
979 /* install translation here */ 995 /* install translation here */
980 for ( QStringList::ConstIterator it = d->langs.begin(); it != d->langs.end(); ++it ) 996 for ( QStringList::ConstIterator it = d->langs.begin(); it != d->langs.end(); ++it )
981 installTranslation( (*it) + "/" + d->appName + ".qm" ); 997 installTranslation( (*it) + "/" + d->appName + ".qm" );
982} 998}
983#endif 999#endif
984 1000
985 1001
986static QPtrDict<void>* inputMethodDict = 0; 1002static QPtrDict<void>* inputMethodDict = 0;
987static void createInputMethodDict() 1003static void createInputMethodDict()
988{ 1004{
989 if ( !inputMethodDict ) 1005 if ( !inputMethodDict )
990 inputMethodDict = new QPtrDict<void>; 1006 inputMethodDict = new QPtrDict<void>;
991} 1007}
992 1008
993/*! 1009/*!
994 Returns the currently set hint to the system as to whether 1010 Returns the currently set hint to the system as to whether
995 widget \a w has any use for text input methods. 1011 widget \a w has any use for text input methods.
996 1012
997 1013
998 \sa setInputMethodHint() InputMethodHint 1014 \sa setInputMethodHint() InputMethodHint
999*/ 1015*/
1000QPEApplication::InputMethodHint QPEApplication::inputMethodHint( QWidget * w ) 1016QPEApplication::InputMethodHint QPEApplication::inputMethodHint( QWidget * w )
1001{ 1017{
1002 if ( inputMethodDict && w ) 1018 if ( inputMethodDict && w )
1003 return ( InputMethodHint ) ( int ) inputMethodDict->find( w ); 1019 return ( InputMethodHint ) ( int ) inputMethodDict->find( w );
1004 return Normal; 1020 return Normal;
1005} 1021}
1006 1022
1007/*! 1023/*!
1008 \enum QPEApplication::InputMethodHint 1024 \enum QPEApplication::InputMethodHint
1009 1025
1010 \value Normal the application sometimes needs text input (the default). 1026 \value Normal the application sometimes needs text input (the default).
1011 \value AlwaysOff the application never needs text input. 1027 \value AlwaysOff the application never needs text input.
1012 \value AlwaysOn the application always needs text input. 1028 \value AlwaysOn the application always needs text input.
1013*/ 1029*/
1014 1030
1015/*! 1031/*!
1016 Hints to the system that widget \a w has use for text input methods 1032 Hints to the system that widget \a w has use for text input methods
1017 as specified by \a mode. 1033 as specified by \a mode.
1018 1034
1019 \sa inputMethodHint() InputMethodHint 1035 \sa inputMethodHint() InputMethodHint
1020*/ 1036*/
1021void QPEApplication::setInputMethodHint( QWidget * w, InputMethodHint mode ) 1037void QPEApplication::setInputMethodHint( QWidget * w, InputMethodHint mode )
1022{ 1038{
1023 createInputMethodDict(); 1039 createInputMethodDict();
1024 if ( mode == Normal ) { 1040 if ( mode == Normal ) {
1025 inputMethodDict->remove 1041 inputMethodDict->remove
1026 ( w ); 1042 ( w );
1027 } 1043 }
1028 else { 1044 else {
1029 inputMethodDict->insert( w, ( void* ) mode ); 1045 inputMethodDict->insert( w, ( void* ) mode );
1030 } 1046 }
1031} 1047}
1032 1048
1033class HackDialog : public QDialog 1049class HackDialog : public QDialog
1034{ 1050{
1035public: 1051public:
1036 void acceptIt() 1052 void acceptIt()
1037 { 1053 {
1038 accept(); 1054 accept();
1039 } 1055 }
1040 void rejectIt() 1056 void rejectIt()
1041 { 1057 {
1042 reject(); 1058 reject();
1043 } 1059 }
1044}; 1060};
1045 1061
1046 1062
1047void QPEApplication::mapToDefaultAction( QWSKeyEvent * ke, int key ) 1063void QPEApplication::mapToDefaultAction( QWSKeyEvent * ke, int key )
1048{ 1064{
1049 // specialised actions for certain widgets. May want to 1065 // specialised actions for certain widgets. May want to
1050 // add more stuff here. 1066 // add more stuff here.
1051 if ( activePopupWidget() && activePopupWidget() ->inherits( "QListBox" ) 1067 if ( activePopupWidget() && activePopupWidget() ->inherits( "QListBox" )
1052 && activePopupWidget() ->parentWidget() 1068 && activePopupWidget() ->parentWidget()
1053 && activePopupWidget() ->parentWidget() ->inherits( "QComboBox" ) ) 1069 && activePopupWidget() ->parentWidget() ->inherits( "QComboBox" ) )
1054 key = Qt::Key_Return; 1070 key = Qt::Key_Return;
1055 1071
1056 if ( activePopupWidget() && activePopupWidget() ->inherits( "QPopupMenu" ) ) 1072 if ( activePopupWidget() && activePopupWidget() ->inherits( "QPopupMenu" ) )
1057 key = Qt::Key_Return; 1073 key = Qt::Key_Return;
1058 1074
1059#ifdef QWS 1075#ifdef QWS
1060 1076
1061 ke->simpleData.keycode = key; 1077 ke->simpleData.keycode = key;
1062#endif 1078#endif
1063} 1079}
1064 1080
1065 1081
1066/*! 1082/*!
1067 \internal 1083 \internal
1068*/ 1084*/
1069 1085
1070#ifdef QWS 1086#ifdef QWS
1071bool QPEApplication::qwsEventFilter( QWSEvent * e ) 1087bool QPEApplication::qwsEventFilter( QWSEvent * e )
1072{ 1088{
1073 if ( !d->notbusysent && e->type == QWSEvent::Focus ) { 1089 if ( !d->notbusysent && e->type == QWSEvent::Focus ) {
1074 if ( qApp->type() != QApplication::GuiServer ) { 1090 if ( qApp->type() != QApplication::GuiServer ) {
1075 QCopEnvelope e( "QPE/System", "notBusy(QString)" ); 1091 QCopEnvelope e( "QPE/System", "notBusy(QString)" );
1076 e << d->appName; 1092 e << d->appName;
1077 } 1093 }
1078 d->notbusysent = TRUE; 1094 d->notbusysent = TRUE;
1079 } 1095 }
1080 if ( type() == GuiServer ) { 1096 if ( type() == GuiServer ) {
1081 switch ( e->type ) { 1097 switch ( e->type ) {
1082 case QWSEvent::Mouse: 1098 case QWSEvent::Mouse:
1083 if ( e->asMouse() ->simpleData.state && !QWidget::find( e->window() ) ) 1099 if ( e->asMouse() ->simpleData.state && !QWidget::find( e->window() ) )
1084 emit clientMoused(); 1100 emit clientMoused();
1085 break; 1101 break;
1086 default: 1102 default:
1087 break; 1103 break;
1088 } 1104 }
1089 } 1105 }
1090 if ( e->type == QWSEvent::Key ) { 1106 if ( e->type == QWSEvent::Key ) {
1091 QWSKeyEvent *ke = ( QWSKeyEvent * ) e; 1107 QWSKeyEvent *ke = ( QWSKeyEvent * ) e;
1092 if ( ke->simpleData.keycode == Qt::Key_F33 ) { 1108 if ( ke->simpleData.keycode == Qt::Key_F33 ) {
1093 // Use special "OK" key to press "OK" on top level widgets 1109 // Use special "OK" key to press "OK" on top level widgets
1094 QWidget * active = activeWindow(); 1110 QWidget * active = activeWindow();
1095 QWidget *popup = 0; 1111 QWidget *popup = 0;
1096 if ( active && active->isPopup() ) { 1112 if ( active && active->isPopup() ) {
1097 popup = active; 1113 popup = active;
1098 active = active->parentWidget(); 1114 active = active->parentWidget();
1099 } 1115 }
1100 if ( active && ( int ) active->winId() == ke->simpleData.window && 1116 if ( active && ( int ) active->winId() == ke->simpleData.window &&
1101 !active->testWFlags( WStyle_Customize | WType_Popup | WType_Desktop ) ) { 1117 !active->testWFlags( WStyle_Customize | WType_Popup | WType_Desktop ) ) {
1102 if ( ke->simpleData.is_press ) { 1118 if ( ke->simpleData.is_press ) {
1103 if ( popup ) 1119 if ( popup )
1104 popup->close(); 1120 popup->close();
1105 if ( active->inherits( "QDialog" ) ) { 1121 if ( active->inherits( "QDialog" ) ) {
1106 HackDialog * d = ( HackDialog * ) active; 1122 HackDialog * d = ( HackDialog * ) active;
1107 d->acceptIt(); 1123 d->acceptIt();
1108 return TRUE; 1124 return TRUE;
1109 } 1125 }
1110 else if ( ( ( HackWidget * ) active ) ->needsOk() ) { 1126 else if ( ( ( HackWidget * ) active ) ->needsOk() ) {
1111 QSignal s; 1127 QSignal s;
1112 s.connect( active, SLOT( accept() ) ); 1128 s.connect( active, SLOT( accept() ) );
1113 s.activate(); 1129 s.activate();
1114 } 1130 }
1115 else { 1131 else {
1116 // do the same as with the select key: Map to the default action of the widget: 1132 // do the same as with the select key: Map to the default action of the widget:
1117 mapToDefaultAction( ke, Qt::Key_Return ); 1133 mapToDefaultAction( ke, Qt::Key_Return );
1118 } 1134 }
1119 } 1135 }
1120 } 1136 }
1121 } 1137 }
1122 else if ( ke->simpleData.keycode == Qt::Key_F30 ) { 1138 else if ( ke->simpleData.keycode == Qt::Key_F30 ) {
1123 // Use special "select" key to do whatever default action a widget has 1139 // Use special "select" key to do whatever default action a widget has
1124 mapToDefaultAction( ke, Qt::Key_Space ); 1140 mapToDefaultAction( ke, Qt::Key_Space );
1125 } 1141 }
1126 else if ( ke->simpleData.keycode == Qt::Key_Escape && 1142 else if ( ke->simpleData.keycode == Qt::Key_Escape &&
1127 ke->simpleData.is_press ) { 1143 ke->simpleData.is_press ) {
1128 // Escape key closes app if focus on toplevel 1144 // Escape key closes app if focus on toplevel
1129 QWidget * active = activeWindow(); 1145 QWidget * active = activeWindow();
1130 if ( active && active->testWFlags( WType_TopLevel ) && 1146 if ( active && active->testWFlags( WType_TopLevel ) &&
1131 ( int ) active->winId() == ke->simpleData.window && 1147 ( int ) active->winId() == ke->simpleData.window &&
1132 !active->testWFlags( WStyle_Dialog | WStyle_Customize | WType_Popup | WType_Desktop ) ) { 1148 !active->testWFlags( WStyle_Dialog | WStyle_Customize | WType_Popup | WType_Desktop ) ) {
1133 if ( active->inherits( "QDialog" ) ) { 1149 if ( active->inherits( "QDialog" ) ) {
1134 HackDialog * d = ( HackDialog * ) active; 1150 HackDialog * d = ( HackDialog * ) active;
1135 d->rejectIt(); 1151 d->rejectIt();
1136 return TRUE; 1152 return TRUE;
1137 } else /*if ( strcmp( argv() [ 0 ], "embeddedkonsole" ) != 0 )*/ { 1153 } else /*if ( strcmp( argv() [ 0 ], "embeddedkonsole" ) != 0 )*/ {
1138 active->close(); 1154 active->close();
1139 } 1155 }
1140 } 1156 }
1141 1157
1142 } 1158 }
1143 else if ( ke->simpleData.keycode >= Qt::Key_F1 && ke->simpleData.keycode <= Qt::Key_F29 ) { 1159 else if ( ke->simpleData.keycode >= Qt::Key_F1 && ke->simpleData.keycode <= Qt::Key_F29 ) {
1144 // this should be if ( ODevice::inst ( )-> buttonForKeycode ( ... )) 1160 // this should be if ( ODevice::inst ( )-> buttonForKeycode ( ... ))
1145 // but we cannot access libopie function within libqpe :( 1161 // but we cannot access libopie function within libqpe :(
1146 1162
1147 QWidget * active = activeWindow ( ); 1163 QWidget * active = activeWindow ( );
1148 if ( active && ((int) active-> winId ( ) == ke-> simpleData.window )) { 1164 if ( active && ((int) active-> winId ( ) == ke-> simpleData.window )) {
1149 if ( d-> kbgrabbed ) { // we grabbed the keyboard 1165 if ( d-> kbgrabbed ) { // we grabbed the keyboard
1150 QChar ch ( ke-> simpleData.unicode ); 1166 QChar ch ( ke-> simpleData.unicode );
1151 QKeyEvent qke ( ke-> simpleData. is_press ? QEvent::KeyPress : QEvent::KeyRelease, 1167 QKeyEvent qke ( ke-> simpleData. is_press ? QEvent::KeyPress : QEvent::KeyRelease,
1152 ke-> simpleData.keycode, 1168 ke-> simpleData.keycode,
1153 ch. latin1 ( ), 1169 ch. latin1 ( ),
1154 ke-> simpleData.modifiers, 1170 ke-> simpleData.modifiers,
1155 QString ( ch ), 1171 QString ( ch ),
1156 ke-> simpleData.is_auto_repeat, 1 ); 1172 ke-> simpleData.is_auto_repeat, 1 );
1157 1173
1158 QObject *which = QWidget::keyboardGrabber ( ); 1174 QObject *which = QWidget::keyboardGrabber ( );
1159 if ( !which ) 1175 if ( !which )
1160 which = QApplication::focusWidget ( ); 1176 which = QApplication::focusWidget ( );
1161 if ( !which ) 1177 if ( !which )
1162 which = QApplication::activeWindow ( ); 1178 which = QApplication::activeWindow ( );
1163 if ( !which ) 1179 if ( !which )
1164 which = qApp; 1180 which = qApp;
1165 1181
1166 QApplication::sendEvent ( which, &qke ); 1182 QApplication::sendEvent ( which, &qke );
1167 } 1183 }
1168 else { // we didn't grab the keyboard, so send the event to the launcher 1184 else { // we didn't grab the keyboard, so send the event to the launcher
1169 QCopEnvelope e ( "QPE/Launcher", "deviceButton(int,int,int)" ); 1185 QCopEnvelope e ( "QPE/Launcher", "deviceButton(int,int,int)" );
1170 e << int( ke-> simpleData.keycode ) << int( ke-> simpleData. is_press ) << int( ke-> simpleData.is_auto_repeat ); 1186 e << int( ke-> simpleData.keycode ) << int( ke-> simpleData. is_press ) << int( ke-> simpleData.is_auto_repeat );
1171 } 1187 }
1172 } 1188 }
1173 return true; 1189 return true;
1174 } 1190 }
1175 } 1191 }
1176 if ( e->type == QWSEvent::Focus ) { 1192 if ( e->type == QWSEvent::Focus ) {
1177 QWSFocusEvent * fe = ( QWSFocusEvent* ) e; 1193 QWSFocusEvent * fe = ( QWSFocusEvent* ) e;
1178 if ( !fe->simpleData.get_focus ) { 1194 if ( !fe->simpleData.get_focus ) {
1179 QWidget * active = activeWindow(); 1195 QWidget * active = activeWindow();
1180 while ( active && active->isPopup() ) { 1196 while ( active && active->isPopup() ) {
1181 active->close(); 1197 active->close();
1182 active = activeWindow(); 1198 active = activeWindow();
1183 } 1199 }
1184 } 1200 }
1185 else { 1201 else {
1186 // make sure our modal widget is ALWAYS on top 1202 // make sure our modal widget is ALWAYS on top
1187 QWidget *topm = activeModalWidget(); 1203 QWidget *topm = activeModalWidget();
1188 if ( topm && static_cast<int>( topm->winId() ) != fe->simpleData.window) { 1204 if ( topm && static_cast<int>( topm->winId() ) != fe->simpleData.window) {
1189 topm->raise(); 1205 topm->raise();
1190 } 1206 }
1191 } 1207 }
1192 if ( fe->simpleData.get_focus && inputMethodDict ) { 1208 if ( fe->simpleData.get_focus && inputMethodDict ) {
1193 InputMethodHint m = inputMethodHint( QWidget::find( e->window() ) ); 1209 InputMethodHint m = inputMethodHint( QWidget::find( e->window() ) );
1194 if ( m == AlwaysOff ) 1210 if ( m == AlwaysOff )
1195 Global::hideInputMethod(); 1211 Global::hideInputMethod();
1196 if ( m == AlwaysOn ) 1212 if ( m == AlwaysOn )
1197 Global::showInputMethod(); 1213 Global::showInputMethod();
1198 } 1214 }
1199 } 1215 }
1200 1216
1201 1217
1202 return QApplication::qwsEventFilter( e ); 1218 return QApplication::qwsEventFilter( e );
1203} 1219}
1204#endif 1220#endif
1205 1221
1206/*! 1222/*!
1207 Destroys the QPEApplication. 1223 Destroys the QPEApplication.
1208*/ 1224*/
1209QPEApplication::~QPEApplication() 1225QPEApplication::~QPEApplication()
1210{ 1226{
1211 ungrabKeyboard(); 1227 ungrabKeyboard();
1212#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 1228#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
1213 // Need to delete QCopChannels early, since the display will 1229 // Need to delete QCopChannels early, since the display will
1214 // be gone by the time we get to ~QObject(). 1230 // be gone by the time we get to ~QObject().
1215 delete sysChannel; 1231 delete sysChannel;
1216 delete pidChannel; 1232 delete pidChannel;
1217#endif 1233#endif
1218 1234
1219#ifdef OPIE_WITHROHFEEDBACK 1235#ifdef OPIE_WITHROHFEEDBACK
1220 if( d->RoH ) 1236 if( d->RoH )
1221 delete d->RoH; 1237 delete d->RoH;
1222#endif 1238#endif
1223 delete d; 1239 delete d;
1224} 1240}
1225 1241
1226/*! 1242/*!
1227 Returns <tt>$OPIEDIR/</tt>. 1243 Returns <tt>$OPIEDIR/</tt>.
1228*/ 1244*/
1229QString QPEApplication::qpeDir() 1245QString QPEApplication::qpeDir()
1230{ 1246{
1231 const char * base = getenv( "OPIEDIR" ); 1247 const char * base = getenv( "OPIEDIR" );
1232 if ( base ) 1248 if ( base )
1233 return QString( base ) + "/"; 1249 return QString( base ) + "/";
1234 1250
1235 return QString( "../" ); 1251 return QString( "../" );
1236} 1252}
1237 1253
1238/*! 1254/*!
1239 Returns the user's current Document directory. There is a trailing "/". 1255 Returns the user's current Document directory. There is a trailing "/".
1240 .. well, it does now,, and there's no trailing '/' 1256 .. well, it does now,, and there's no trailing '/'
1241*/ 1257*/
1242QString QPEApplication::documentDir() 1258QString QPEApplication::documentDir()
1243{ 1259{
1244 const char* base = getenv( "HOME"); 1260 const char* base = getenv( "HOME");
1245 if ( base ) 1261 if ( base )
1246 return QString( base ) + "/Documents"; 1262 return QString( base ) + "/Documents";
1247 1263
1248 return QString( "../Documents" ); 1264 return QString( "../Documents" );
1249} 1265}
1250 1266
1251static int deforient = -1; 1267static int deforient = -1;
1252 1268
1253/*! 1269/*!
1254 \internal 1270 \internal
1255*/ 1271*/
1256int QPEApplication::defaultRotation() 1272int QPEApplication::defaultRotation()
1257{ 1273{
1258 if ( deforient < 0 ) { 1274 if ( deforient < 0 ) {
1259 QString d = getenv( "QWS_DISPLAY" ); 1275 QString d = getenv( "QWS_DISPLAY" );
1260 if ( d.contains( "Rot90" ) ) { 1276 if ( d.contains( "Rot90" ) ) {
1261 deforient = 90; 1277 deforient = 90;
1262 } 1278 }
1263 else if ( d.contains( "Rot180" ) ) { 1279 else if ( d.contains( "Rot180" ) ) {
1264 deforient = 180; 1280 deforient = 180;
1265 } 1281 }
1266 else if ( d.contains( "Rot270" ) ) { 1282 else if ( d.contains( "Rot270" ) ) {
1267 deforient = 270; 1283 deforient = 270;
1268 } 1284 }
1269 else { 1285 else {
1270 deforient = 0; 1286 deforient = 0;
1271 } 1287 }
1272 } 1288 }
1273 return deforient; 1289 return deforient;
1274} 1290}
1275 1291
1276/*! 1292/*!
1277 \internal 1293 \internal
1278*/ 1294*/
1279void QPEApplication::setDefaultRotation( int r ) 1295void QPEApplication::setDefaultRotation( int r )
1280{ 1296{
1281 if ( qApp->type() == GuiServer ) { 1297 if ( qApp->type() == GuiServer ) {
1282 deforient = r; 1298 deforient = r;
1283 setenv( "QWS_DISPLAY", QString( "Transformed:Rot%1:0" ).arg( r ).latin1(), 1 ); 1299 setenv( "QWS_DISPLAY", QString( "Transformed:Rot%1:0" ).arg( r ).latin1(), 1 );
1284 Config config("qpe"); 1300 Config config("qpe");
1285 config.setGroup( "Rotation" ); 1301 config.setGroup( "Rotation" );
1286 config.writeEntry( "Rot", r ); 1302 config.writeEntry( "Rot", r );
1287 } 1303 }
1288 else { 1304 else {
1289#ifndef QT_NO_COP 1305#ifndef QT_NO_COP
1290 { QCopEnvelope e( "QPE/System", "setDefaultRotation(int)" ); 1306 { QCopEnvelope e( "QPE/System", "setDefaultRotation(int)" );
1291 e << r; 1307 e << r;
1292 } 1308 }
1293#endif 1309#endif
1294 1310
1295 } 1311 }
1296} 1312}
1297 1313
1298#include <qgfx_qws.h> 1314#include <qgfx_qws.h>
1299#include <qwindowsystem_qws.h> 1315#include <qwindowsystem_qws.h>
1300 1316
1301#if QT_VERSION > 236 1317#if QT_VERSION > 236
1302extern void qws_clearLoadedFonts(); 1318extern void qws_clearLoadedFonts();
1303#endif 1319#endif
1304 1320
1305void QPEApplication::setCurrentMode( int x, int y, int depth ) 1321void QPEApplication::setCurrentMode( int x, int y, int depth )
1306{ 1322{
1307 // Reset the caches 1323 // Reset the caches
1308#if QT_VERSION > 236 1324#if QT_VERSION > 236
1309 qws_clearLoadedFonts(); 1325 qws_clearLoadedFonts();
1310#endif 1326#endif
1311 QPixmapCache::clear(); 1327 QPixmapCache::clear();
1312 1328
1313 // Change the screen mode 1329 // Change the screen mode
1314 qt_screen->setMode(x, y, depth); 1330 qt_screen->setMode(x, y, depth);
1315 1331
1316 if ( qApp->type() == GuiServer ) { 1332 if ( qApp->type() == GuiServer ) {
1317#if QT_VERSION > 236 1333#if QT_VERSION > 236
1318 // Reconfigure the GuiServer 1334 // Reconfigure the GuiServer
1319 qwsServer->beginDisplayReconfigure(); 1335 qwsServer->beginDisplayReconfigure();
1320 qwsServer->endDisplayReconfigure(); 1336 qwsServer->endDisplayReconfigure();
1321#endif 1337#endif
1322 // Get all the running apps to reset 1338 // Get all the running apps to reset
1323 QCopEnvelope env( "QPE/System", "reset()" ); 1339 QCopEnvelope env( "QPE/System", "reset()" );
1324 } 1340 }
1325} 1341}
1326 1342
1327void QPEApplication::reset() { 1343void QPEApplication::reset() {
1328 // Reconnect to the screen 1344 // Reconnect to the screen
1329 qt_screen->disconnect(); 1345 qt_screen->disconnect();
1330 qt_screen->connect( QString::null ); 1346 qt_screen->connect( QString::null );
1331 1347
1332 // Redraw everything 1348 // Redraw everything
1333 applyStyle(); 1349 applyStyle();
1334} 1350}
1335 1351
1336#if (QT_VERSION < 238) && defined Q_OS_MACX 1352#if (QT_VERSION < 238) && defined Q_OS_MACX
1337bool qt_left_hand_scrollbars = false; 1353bool qt_left_hand_scrollbars = false;
1338#else 1354#else
1339#ifdef Q_OS_MACX 1355#ifdef Q_OS_MACX
1340#define WEAK_SYMBOL __attribute__((weak_import)) 1356#define WEAK_SYMBOL __attribute__((weak_import))
1341#else 1357#else
1342#define WEAK_SYMBOL __attribute__((weak)) 1358#define WEAK_SYMBOL __attribute__((weak))
1343#endif 1359#endif
1344extern bool qt_left_hand_scrollbars WEAK_SYMBOL; 1360extern bool qt_left_hand_scrollbars WEAK_SYMBOL;
1345#endif 1361#endif
1346 1362
1347/*! 1363/*!
1348 \internal 1364 \internal
1349*/ 1365*/
1350void QPEApplication::applyStyle() 1366void QPEApplication::applyStyle()
1351{ 1367{
1352 Config config( "qpe" ); 1368 Config config( "qpe" );
1353 config.setGroup( "Appearance" ); 1369 config.setGroup( "Appearance" );
1354 1370
1355#if QT_VERSION > 233 1371#if QT_VERSION > 233
1356#if !defined(OPIE_NO_OVERRIDE_QT) 1372#if !defined(OPIE_NO_OVERRIDE_QT)
1357 // don't block ourselves ... 1373 // don't block ourselves ...
1358 Opie::force_appearance = 0; 1374 Opie::force_appearance = 0;
1359 1375
1360 static QString appname = Opie::binaryName ( ); 1376 static QString appname = Opie::binaryName ( );
1361 1377
1362 QStringList ex = config. readListEntry ( "NoStyle", ';' ); 1378 QStringList ex = config. readListEntry ( "NoStyle", ';' );
1363 int nostyle = 0; 1379 int nostyle = 0;
1364 for ( QStringList::Iterator it = ex. begin ( ); it != ex. end ( ); ++it ) { 1380 for ( QStringList::Iterator it = ex. begin ( ); it != ex. end ( ); ++it ) {
1365 if ( QRegExp (( *it ). mid ( 1 ), false, true ). find ( appname, 0 ) >= 0 ) { 1381 if ( QRegExp (( *it ). mid ( 1 ), false, true ). find ( appname, 0 ) >= 0 ) {
1366 nostyle = ( *it ). left ( 1 ). toInt ( 0, 32 ); 1382 nostyle = ( *it ). left ( 1 ). toInt ( 0, 32 );
1367 break; 1383 break;
1368 } 1384 }
1369 } 1385 }
1370#else 1386#else
1371 int nostyle = 0; 1387 int nostyle = 0;
1372#endif 1388#endif
1373 1389
1374 // Widget style 1390 // Widget style
1375 QString style = config.readEntry( "Style", "FlatStyle" ); 1391 QString style = config.readEntry( "Style", "FlatStyle" );
1376 1392
1377 // don't set a custom style 1393 // don't set a custom style
1378 if ( nostyle & Opie::Force_Style ) 1394 if ( nostyle & Opie::Force_Style )
1379 style = "FlatStyle"; 1395 style = "FlatStyle";
1380 1396
1381 internalSetStyle ( style ); 1397 internalSetStyle ( style );
1382 1398
1383 // Colors - from /etc/colors/Liquid.scheme 1399 // Colors - from /etc/colors/Liquid.scheme
1384 QColor bgcolor( config.readEntry( "Background", "#E0E0E0" ) ); 1400 QColor bgcolor( config.readEntry( "Background", "#E0E0E0" ) );
1385 QColor btncolor( config.readEntry( "Button", "#96c8fa" ) ); 1401 QColor btncolor( config.readEntry( "Button", "#96c8fa" ) );
1386 QPalette pal( btncolor, bgcolor ); 1402 QPalette pal( btncolor, bgcolor );
1387 QString color = config.readEntry( "Highlight", "#73adef" ); 1403 QString color = config.readEntry( "Highlight", "#73adef" );
1388 pal.setColor( QColorGroup::Highlight, QColor( color ) ); 1404 pal.setColor( QColorGroup::Highlight, QColor( color ) );
1389 color = config.readEntry( "HighlightedText", "#FFFFFF" ); 1405 color = config.readEntry( "HighlightedText", "#FFFFFF" );
1390 pal.setColor( QColorGroup::HighlightedText, QColor( color ) ); 1406 pal.setColor( QColorGroup::HighlightedText, QColor( color ) );
1391 color = config.readEntry( "Text", "#000000" ); 1407 color = config.readEntry( "Text", "#000000" );
1392 pal.setColor( QColorGroup::Text, QColor( color ) ); 1408 pal.setColor( QColorGroup::Text, QColor( color ) );
1393 color = config.readEntry( "ButtonText", "#000000" ); 1409 color = config.readEntry( "ButtonText", "#000000" );
1394 pal.setColor( QPalette::Active, QColorGroup::ButtonText, QColor( color ) ); 1410 pal.setColor( QPalette::Active, QColorGroup::ButtonText, QColor( color ) );
1395 color = config.readEntry( "Base", "#FFFFFF" ); 1411 color = config.readEntry( "Base", "#FFFFFF" );
1396 pal.setColor( QColorGroup::Base, QColor( color ) ); 1412 pal.setColor( QColorGroup::Base, QColor( color ) );
1397 1413
1398 pal.setColor( QPalette::Disabled, QColorGroup::Text, 1414 pal.setColor( QPalette::Disabled, QColorGroup::Text,
1399 pal.color( QPalette::Active, QColorGroup::Background ).dark() ); 1415 pal.color( QPalette::Active, QColorGroup::Background ).dark() );
1400 1416
1401 setPalette( pal, TRUE ); 1417 setPalette( pal, TRUE );
1402 1418
1403 1419
1404 // Set the ScrollBar on the 'right' side but only if the weak symbol is present 1420 // Set the ScrollBar on the 'right' side but only if the weak symbol is present
1405 if (&qt_left_hand_scrollbars ) 1421 if (&qt_left_hand_scrollbars )
1406 qt_left_hand_scrollbars = config.readBoolEntry( "LeftHand", false ); 1422 qt_left_hand_scrollbars = config.readBoolEntry( "LeftHand", false );
1407 1423
1408 // Window Decoration 1424 // Window Decoration
1409 QString dec = config.readEntry( "Decoration", "Flat" ); 1425 QString dec = config.readEntry( "Decoration", "Flat" );
1410 1426
1411 // don't set a custom deco 1427 // don't set a custom deco
1412 if ( nostyle & Opie::Force_Decoration ) 1428 if ( nostyle & Opie::Force_Decoration )
1413 dec = ""; 1429 dec = "";
1414 1430
1415 1431
1416 if ( dec != d->decorationName ) { 1432 if ( dec != d->decorationName ) {
1417 qwsSetDecoration( new QPEDecoration( dec ) ); 1433 qwsSetDecoration( new QPEDecoration( dec ) );
1418 d->decorationName = dec; 1434 d->decorationName = dec;
1419 } 1435 }
1420 1436
1421 // Font 1437 // Font
1422 QString ff = config.readEntry( "FontFamily", font().family() ); 1438 QString ff = config.readEntry( "FontFamily", font().family() );
1423 int fs = config.readNumEntry( "FontSize", font().pointSize() ); 1439 int fs = config.readNumEntry( "FontSize", font().pointSize() );
1424 1440
1425 // don't set a custom font 1441 // don't set a custom font
1426 if ( nostyle & Opie::Force_Font ) { 1442 if ( nostyle & Opie::Force_Font ) {
1427 ff = "Vera"; 1443 ff = "Vera";
1428 fs = 10; 1444 fs = 10;
1429 } 1445 }
1430 1446
1431 setFont ( QFont ( ff, fs ), true ); 1447 setFont ( QFont ( ff, fs ), true );
1432 1448
1433#if !defined(OPIE_NO_OVERRIDE_QT) 1449#if !defined(OPIE_NO_OVERRIDE_QT)
1434 // revert to global blocking policy ... 1450 // revert to global blocking policy ...
1435 Opie::force_appearance = config. readBoolEntry ( "ForceStyle", false ) ? Opie::Force_All : Opie::Force_None; 1451 Opie::force_appearance = config. readBoolEntry ( "ForceStyle", false ) ? Opie::Force_All : Opie::Force_None;
1436 Opie::force_appearance &= ~nostyle; 1452 Opie::force_appearance &= ~nostyle;
1437#endif 1453#endif
1438#endif 1454#endif
1439} 1455}
1440 1456
1441void QPEApplication::systemMessage( const QCString& msg, const QByteArray& data ) 1457void QPEApplication::systemMessage( const QCString& msg, const QByteArray& data )
1442{ 1458{
1443#ifdef Q_WS_QWS 1459#ifdef Q_WS_QWS
1444 QDataStream stream( data, IO_ReadOnly ); 1460 QDataStream stream( data, IO_ReadOnly );
1445 if ( msg == "applyStyle()" ) { 1461 if ( msg == "applyStyle()" ) {
1446 applyStyle(); 1462 applyStyle();
1447 } 1463 }
1448 else if ( msg == "toggleApplicationMenu()" ) { 1464 else if ( msg == "toggleApplicationMenu()" ) {
1449 QWidget *active = activeWindow ( ); 1465 QWidget *active = activeWindow ( );
1450 1466
1451 if ( active ) { 1467 if ( active ) {
1452 QPEMenuToolFocusManager *man = QPEMenuToolFocusManager::manager ( ); 1468 QPEMenuToolFocusManager *man = QPEMenuToolFocusManager::manager ( );
1453 bool oldactive = man-> isActive ( ); 1469 bool oldactive = man-> isActive ( );
1454 1470
1455 man-> setActive( !man-> isActive() ); 1471 man-> setActive( !man-> isActive() );
1456 1472
1457 if ( !oldactive && !man-> isActive ( )) { // no menubar to toggle -> try O-Menu 1473 if ( !oldactive && !man-> isActive ( )) { // no menubar to toggle -> try O-Menu
1458 QCopEnvelope e ( "QPE/TaskBar", "toggleStartMenu()" ); 1474 QCopEnvelope e ( "QPE/TaskBar", "toggleStartMenu()" );
1459 } 1475 }
1460 } 1476 }
1461 } 1477 }
1462 else if ( msg == "setDefaultRotation(int)" ) { 1478 else if ( msg == "setDefaultRotation(int)" ) {
1463 if ( type() == GuiServer ) { 1479 if ( type() == GuiServer ) {
1464 int r; 1480 int r;
1465 stream >> r; 1481 stream >> r;
1466 setDefaultRotation( r ); 1482 setDefaultRotation( r );
1467 } 1483 }
1468 } 1484 }
1469 else if ( msg == "setCurrentMode(int,int,int)" ) { // Added: 2003-06-11 by Tim Ansell <mithro@mithis.net> 1485 else if ( msg == "setCurrentMode(int,int,int)" ) { // Added: 2003-06-11 by Tim Ansell <mithro@mithis.net>
1470 if ( type() == GuiServer ) { 1486 if ( type() == GuiServer ) {
1471 int x, y, depth; 1487 int x, y, depth;
1472 stream >> x; 1488 stream >> x;
1473 stream >> y; 1489 stream >> y;
1474 stream >> depth; 1490 stream >> depth;
1475 setCurrentMode( x, y, depth ); 1491 setCurrentMode( x, y, depth );
1476 } 1492 }
1477 } 1493 }
1478 else if ( msg == "reset()" ) { 1494 else if ( msg == "reset()" ) {
1479 if ( type() != GuiServer ) 1495 if ( type() != GuiServer )
1480 reset(); 1496 reset();
1481 } 1497 }
1482 else if ( msg == "setCurrentRotation(int)" ) { 1498 else if ( msg == "setCurrentRotation(int)" ) {
1483 int r; 1499 int r;
1484 stream >> r; 1500 stream >> r;
1485 setCurrentRotation( r ); 1501 setCurrentRotation( r );
1486 } 1502 }
1487 else if ( msg == "shutdown()" ) { 1503 else if ( msg == "shutdown()" ) {
1488 if ( type() == GuiServer ) 1504 if ( type() == GuiServer )
1489 shutdown(); 1505 shutdown();
1490 } 1506 }
1491 else if ( msg == "quit()" ) { 1507 else if ( msg == "quit()" ) {
1492 if ( type() != GuiServer ) 1508 if ( type() != GuiServer )
1493 tryQuit(); 1509 tryQuit();
1494 } 1510 }
1495 else if ( msg == "forceQuit()" ) { 1511 else if ( msg == "forceQuit()" ) {
1496 if ( type() != GuiServer ) 1512 if ( type() != GuiServer )
1497 quit(); 1513 quit();
1498 } 1514 }
1499 else if ( msg == "restart()" ) { 1515 else if ( msg == "restart()" ) {
1500 if ( type() == GuiServer ) 1516 if ( type() == GuiServer )
1501 restart(); 1517 restart();
1502 } 1518 }
1503 else if ( msg == "language(QString)" ) { 1519 else if ( msg == "language(QString)" ) {
1504 if ( type() == GuiServer ) { 1520 if ( type() == GuiServer ) {
1505 QString l; 1521 QString l;
1506 stream >> l; 1522 stream >> l;
1507 QString cl = getenv( "LANG" ); 1523 QString cl = getenv( "LANG" );
1508 if ( cl != l ) { 1524 if ( cl != l ) {
1509 if ( l.isNull() ) 1525 if ( l.isNull() )
1510 unsetenv( "LANG" ); 1526 unsetenv( "LANG" );
1511 else 1527 else
1512 setenv( "LANG", l.latin1(), 1 ); 1528 setenv( "LANG", l.latin1(), 1 );
1513 restart(); 1529 restart();
1514 } 1530 }
1515 } 1531 }
1516 } 1532 }
1517 else if ( msg == "timeChange(QString)" ) { 1533 else if ( msg == "timeChange(QString)" ) {
1518 QString t; 1534 QString t;
1519 stream >> t; 1535 stream >> t;
1520 if ( t.isNull() ) 1536 if ( t.isNull() )
1521 unsetenv( "TZ" ); 1537 unsetenv( "TZ" );
1522 else 1538 else
1523 setenv( "TZ", t.latin1(), 1 ); 1539 setenv( "TZ", t.latin1(), 1 );
1524 // emit the signal so everyone else knows... 1540 // emit the signal so everyone else knows...
1525 emit timeChanged(); 1541 emit timeChanged();
1526 } 1542 }
1527 else if ( msg == "addAlarm(QDateTime,QCString,QCString,int)" ) { 1543 else if ( msg == "addAlarm(QDateTime,QCString,QCString,int)" ) {
1528 if ( type() == GuiServer ) { 1544 if ( type() == GuiServer ) {
1529 QDateTime when; 1545 QDateTime when;
1530 QCString channel, message; 1546 QCString channel, message;
1531 int data; 1547 int data;
1532 stream >> when >> channel >> message >> data; 1548 stream >> when >> channel >> message >> data;
1533 AlarmServer::addAlarm( when, channel, message, data ); 1549 AlarmServer::addAlarm( when, channel, message, data );
1534 } 1550 }
1535 } 1551 }
1536 else if ( msg == "deleteAlarm(QDateTime,QCString,QCString,int)" ) { 1552 else if ( msg == "deleteAlarm(QDateTime,QCString,QCString,int)" ) {
1537 if ( type() == GuiServer ) { 1553 if ( type() == GuiServer ) {
1538 QDateTime when; 1554 QDateTime when;
1539 QCString channel, message; 1555 QCString channel, message;
1540 int data; 1556 int data;
1541 stream >> when >> channel >> message >> data; 1557 stream >> when >> channel >> message >> data;
1542 AlarmServer::deleteAlarm( when, channel, message, data ); 1558 AlarmServer::deleteAlarm( when, channel, message, data );
1543 } 1559 }
1544 } 1560 }
1545 else if ( msg == "clockChange(bool)" ) { 1561 else if ( msg == "clockChange(bool)" ) {
1546 int tmp; 1562 int tmp;
1547 stream >> tmp; 1563 stream >> tmp;
1548 emit clockChanged( tmp ); 1564 emit clockChanged( tmp );
1549 } 1565 }
1550 else if ( msg == "weekChange(bool)" ) { 1566 else if ( msg == "weekChange(bool)" ) {
1551 int tmp; 1567 int tmp;
1552 stream >> tmp; 1568 stream >> tmp;
1553 emit weekChanged( tmp ); 1569 emit weekChanged( tmp );
1554 } 1570 }
1555 else if ( msg == "setDateFormat(DateFormat)" ) { 1571 else if ( msg == "setDateFormat(DateFormat)" ) {
1556 DateFormat tmp; 1572 DateFormat tmp;
1557 stream >> tmp; 1573 stream >> tmp;
1558 emit dateFormatChanged( tmp ); 1574 emit dateFormatChanged( tmp );
1559 } 1575 }
1560 else if ( msg == "setVolume(int,int)" ) { 1576 else if ( msg == "setVolume(int,int)" ) {
1561 int t, v; 1577 int t, v;
1562 stream >> t >> v; 1578 stream >> t >> v;
1563 setVolume( t, v ); 1579 setVolume( t, v );
1564 emit volumeChanged( muted ); 1580 emit volumeChanged( muted );
1565 } 1581 }
1566 else if ( msg == "volumeChange(bool)" ) { 1582 else if ( msg == "volumeChange(bool)" ) {
1567 stream >> muted; 1583 stream >> muted;
1568 setVolume(); 1584 setVolume();
1569 emit volumeChanged( muted ); 1585 emit volumeChanged( muted );
1570 } 1586 }
1571 else if ( msg == "setMic(int,int)" ) { // Added: 2002-02-08 by Jeremy Cowgar <jc@cowgar.com> 1587 else if ( msg == "setMic(int,int)" ) { // Added: 2002-02-08 by Jeremy Cowgar <jc@cowgar.com>
1572 int t, v; 1588 int t, v;
1573 stream >> t >> v; 1589 stream >> t >> v;
1574 setMic( t, v ); 1590 setMic( t, v );
1575 emit micChanged( micMuted ); 1591 emit micChanged( micMuted );
1576 } 1592 }
1577 else if ( msg == "micChange(bool)" ) { // Added: 2002-02-08 by Jeremy Cowgar <jc@cowgar.com> 1593 else if ( msg == "micChange(bool)" ) { // Added: 2002-02-08 by Jeremy Cowgar <jc@cowgar.com>
1578 stream >> micMuted; 1594 stream >> micMuted;
1579 setMic(); 1595 setMic();
1580 emit micChanged( micMuted ); 1596 emit micChanged( micMuted );
1581 } 1597 }
1582 else if ( msg == "setBass(int,int)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org> 1598 else if ( msg == "setBass(int,int)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org>
1583 int t, v; 1599 int t, v;
1584 stream >> t >> v; 1600 stream >> t >> v;
1585 setBass( t, v ); 1601 setBass( t, v );
1586 } 1602 }
1587 else if ( msg == "bassChange(bool)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org> 1603 else if ( msg == "bassChange(bool)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org>
1588 setBass(); 1604 setBass();
1589 } 1605 }
1590 else if ( msg == "setTreble(int,int)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org> 1606 else if ( msg == "setTreble(int,int)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org>
1591 int t, v; 1607 int t, v;
1592 stream >> t >> v; 1608 stream >> t >> v;
1593 setTreble( t, v ); 1609 setTreble( t, v );
1594 } 1610 }
1595 else if ( msg == "trebleChange(bool)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org> 1611 else if ( msg == "trebleChange(bool)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org>
1596 setTreble(); 1612 setTreble();
1597 } else if ( msg == "getMarkedText()" ) { 1613 } else if ( msg == "getMarkedText()" ) {
1598 if ( type() == GuiServer ) { 1614 if ( type() == GuiServer ) {
1599 const ushort unicode = 'C'-'@'; 1615 const ushort unicode = 'C'-'@';
1600 const int scan = Key_C; 1616 const int scan = Key_C;
1601 qwsServer->processKeyEvent( unicode, scan, ControlButton, TRUE, FALSE ); 1617 qwsServer->processKeyEvent( unicode, scan, ControlButton, TRUE, FALSE );
1602 qwsServer->processKeyEvent( unicode, scan, ControlButton, FALSE, FALSE ); 1618 qwsServer->processKeyEvent( unicode, scan, ControlButton, FALSE, FALSE );
1603 } 1619 }
1604 } else if ( msg == "newChannel(QString)") { 1620 } else if ( msg == "newChannel(QString)") {
1605 QString myChannel = "QPE/Application/" + d->appName; 1621 QString myChannel = "QPE/Application/" + d->appName;
1606 QString channel; 1622 QString channel;
1607 stream >> channel; 1623 stream >> channel;
1608 if (channel == myChannel) { 1624 if (channel == myChannel) {
1609 processQCopFile(); 1625 processQCopFile();
1610 d->sendQCopQ(); 1626 d->sendQCopQ();
1611 } 1627 }
1612 } 1628 }
1613 1629
1614 1630
1615#endif 1631#endif
1616} 1632}
1617 1633
1618 1634
1619 1635
1620 1636
1621 1637
1622/*! 1638/*!
1623 \internal 1639 \internal
1624*/ 1640*/
1625bool QPEApplication::raiseAppropriateWindow() 1641bool QPEApplication::raiseAppropriateWindow()
1626{ 1642{
1627 bool r=FALSE; 1643 bool r=FALSE;
1628 1644
1629 // 1. Raise the main widget 1645 // 1. Raise the main widget
1630 QWidget *top = d->qpe_main_widget; 1646 QWidget *top = d->qpe_main_widget;
1631 if ( !top ) top = mainWidget(); 1647 if ( !top ) top = mainWidget();
1632 1648
1633 if ( top && d->keep_running ) { 1649 if ( top && d->keep_running ) {
1634 if ( top->isVisible() ) 1650 if ( top->isVisible() )
1635 r = TRUE; 1651 r = TRUE;
1636 else if (d->preloaded) { 1652 else if (d->preloaded) {
1637 // We are preloaded and not visible.. pretend we just started.. 1653 // We are preloaded and not visible.. pretend we just started..
1638#ifndef QT_NO_COP 1654#ifndef QT_NO_COP
1639 QCopEnvelope e("QPE/System", "fastAppShowing(QString)"); 1655 QCopEnvelope e("QPE/System", "fastAppShowing(QString)");
1640 e << d->appName; 1656 e << d->appName;
1641#endif 1657#endif
1642 } 1658 }
1643 1659
1644 d->show_mx(top,d->nomaximize, d->appName); 1660 d->show_mx(top,d->nomaximize, d->appName);
1645 top->raise(); 1661 top->raise();
1646 } 1662 }
1647 1663
1648 QWidget *topm = activeModalWidget(); 1664 QWidget *topm = activeModalWidget();
1649 1665
1650 // 2. Raise any parentless widgets (except top and topm, as they 1666 // 2. Raise any parentless widgets (except top and topm, as they
1651 // are raised before and after this loop). Order from most 1667 // are raised before and after this loop). Order from most
1652 // recently raised as deepest to least recently as top, so 1668 // recently raised as deepest to least recently as top, so
1653 // that repeated calls cycle through widgets. 1669 // that repeated calls cycle through widgets.
1654 QWidgetList *list = topLevelWidgets(); 1670 QWidgetList *list = topLevelWidgets();
1655 if ( list ) { 1671 if ( list ) {
1656 bool foundlast = FALSE; 1672 bool foundlast = FALSE;
1657 QWidget* topsub = 0; 1673 QWidget* topsub = 0;
1658 if ( d->lastraised ) { 1674 if ( d->lastraised ) {
1659 for (QWidget* w = list->first(); w; w = list->next()) { 1675 for (QWidget* w = list->first(); w; w = list->next()) {
1660 if ( !w->parentWidget() && w != topm && w->isVisible() && !w->isDesktop() ) { 1676 if ( !w->parentWidget() && w != topm && w->isVisible() && !w->isDesktop() ) {
1661 if ( w == d->lastraised ) 1677 if ( w == d->lastraised )
1662 foundlast = TRUE; 1678 foundlast = TRUE;
1663 if ( foundlast ) { 1679 if ( foundlast ) {
1664 w->raise(); 1680 w->raise();
1665 topsub = w; 1681 topsub = w;
1666 } 1682 }
1667 } 1683 }
1668 } 1684 }
1669 } 1685 }
1670 for (QWidget* w = list->first(); w; w = list->next()) { 1686 for (QWidget* w = list->first(); w; w = list->next()) {
1671 if ( !w->parentWidget() && w != topm && w->isVisible() && !w->isDesktop() ) { 1687 if ( !w->parentWidget() && w != topm && w->isVisible() && !w->isDesktop() ) {
1672 if ( w == d->lastraised ) 1688 if ( w == d->lastraised )
1673 break; 1689 break;
1674 w->raise(); 1690 w->raise();
1675 topsub = w; 1691 topsub = w;
1676 } 1692 }
1677 } 1693 }
1678 d->lastraised = topsub; 1694 d->lastraised = topsub;
1679 delete list; 1695 delete list;
1680 } 1696 }
1681 1697
1682 // 3. Raise the active modal widget. 1698 // 3. Raise the active modal widget.
1683 if ( topm ) { 1699 if ( topm ) {
1684 topm->show(); 1700 topm->show();
1685 topm->raise(); 1701 topm->raise();
1686 // If we haven't already handled the fastAppShowing message 1702 // If we haven't already handled the fastAppShowing message
1687 if (!top && d->preloaded) { 1703 if (!top && d->preloaded) {
1688#ifndef QT_NO_COP 1704#ifndef QT_NO_COP
1689 QCopEnvelope e("QPE/System", "fastAppShowing(QString)"); 1705 QCopEnvelope e("QPE/System", "fastAppShowing(QString)");
1690 e << d->appName; 1706 e << d->appName;
1691#endif 1707#endif
1692 } 1708 }
1693 r = FALSE; 1709 r = FALSE;
1694 } 1710 }
1695 1711
1696 return r; 1712 return r;
1697} 1713}
1698 1714
1699 1715
1700void QPEApplication::pidMessage( const QCString& msg, const QByteArray& data) 1716void QPEApplication::pidMessage( const QCString& msg, const QByteArray& data)
1701{ 1717{
1702#ifdef Q_WS_QWS 1718#ifdef Q_WS_QWS
1703 1719
1704 if ( msg == "quit()" ) { 1720 if ( msg == "quit()" ) {
1705 tryQuit(); 1721 tryQuit();
1706 } 1722 }
1707 else if ( msg == "quitIfInvisible()" ) { 1723 else if ( msg == "quitIfInvisible()" ) {
1708 if ( d->qpe_main_widget && !d->qpe_main_widget->isVisible() ) 1724 if ( d->qpe_main_widget && !d->qpe_main_widget->isVisible() )
1709 quit(); 1725 quit();
1710 } 1726 }
1711 else if ( msg == "close()" ) { 1727 else if ( msg == "close()" ) {
1712 hideOrQuit(); 1728 hideOrQuit();
1713 } 1729 }
1714 else if ( msg == "disablePreload()" ) { 1730 else if ( msg == "disablePreload()" ) {
1715 d->preloaded = FALSE; 1731 d->preloaded = FALSE;
1716 d->keep_running = TRUE; 1732 d->keep_running = TRUE;
1717 /* so that quit will quit */ 1733 /* so that quit will quit */
1718 } 1734 }
1719 else if ( msg == "enablePreload()" ) { 1735 else if ( msg == "enablePreload()" ) {
1720 if (d->qpe_main_widget) 1736 if (d->qpe_main_widget)
1721 d->preloaded = TRUE; 1737 d->preloaded = TRUE;
1722 d->keep_running = TRUE; 1738 d->keep_running = TRUE;
1723 /* so next quit won't quit */ 1739 /* so next quit won't quit */
1724 } 1740 }
1725 else if ( msg == "raise()" ) { 1741 else if ( msg == "raise()" ) {
1726 d->keep_running = TRUE; 1742 d->keep_running = TRUE;
1727 d->notbusysent = FALSE; 1743 d->notbusysent = FALSE;
1728 raiseAppropriateWindow(); 1744 raiseAppropriateWindow();
1729 // Tell the system we're still chugging along... 1745 // Tell the system we're still chugging along...
1730 QCopEnvelope e("QPE/System", "appRaised(QString)"); 1746 QCopEnvelope e("QPE/System", "appRaised(QString)");
1731 e << d->appName; 1747 e << d->appName;
1732 } 1748 }
1733 else if ( msg == "flush()" ) { 1749 else if ( msg == "flush()" ) {
1734 emit flush(); 1750 emit flush();
1735 // we need to tell the desktop 1751 // we need to tell the desktop
1736 QCopEnvelope e( "QPE/Desktop", "flushDone(QString)" ); 1752 QCopEnvelope e( "QPE/Desktop", "flushDone(QString)" );
1737 e << d->appName; 1753 e << d->appName;
1738 } 1754 }
1739 else if ( msg == "reload()" ) { 1755 else if ( msg == "reload()" ) {
1740 emit reload(); 1756 emit reload();
1741 } 1757 }
1742 else if ( msg == "setDocument(QString)" ) { 1758 else if ( msg == "setDocument(QString)" ) {
1743 d->keep_running = TRUE; 1759 d->keep_running = TRUE;
1744 QDataStream stream( data, IO_ReadOnly ); 1760 QDataStream stream( data, IO_ReadOnly );
1745 QString doc; 1761 QString doc;
1746 stream >> doc; 1762 stream >> doc;
1747 QWidget *mw = mainWidget(); 1763 QWidget *mw = mainWidget();
1748 if ( !mw ) 1764 if ( !mw )
1749 mw = d->qpe_main_widget; 1765 mw = d->qpe_main_widget;
1750 if ( mw ) 1766 if ( mw )
1751 Global::setDocument( mw, doc ); 1767 Global::setDocument( mw, doc );
1752 1768
1753 } else if ( msg == "QPEProcessQCop()" ) { 1769 } else if ( msg == "QPEProcessQCop()" ) {
1754 processQCopFile(); 1770 processQCopFile();
1755 d->sendQCopQ(); 1771 d->sendQCopQ();
1756 }else 1772 }else
1757 { 1773 {
1758 bool p = d->keep_running; 1774 bool p = d->keep_running;
1759 d->keep_running = FALSE; 1775 d->keep_running = FALSE;
1760 emit appMessage( msg, data); 1776 emit appMessage( msg, data);
1761 if ( d->keep_running ) { 1777 if ( d->keep_running ) {
1762 d->notbusysent = FALSE; 1778 d->notbusysent = FALSE;
1763 raiseAppropriateWindow(); 1779 raiseAppropriateWindow();
1764 if ( !p ) { 1780 if ( !p ) {
1765 // Tell the system we're still chugging along... 1781 // Tell the system we're still chugging along...
1766#ifndef QT_NO_COP 1782#ifndef QT_NO_COP
1767 QCopEnvelope e("QPE/System", "appRaised(QString)"); 1783 QCopEnvelope e("QPE/System", "appRaised(QString)");
1768 e << d->appName; 1784 e << d->appName;
1769#endif 1785#endif
1770 } 1786 }
1771 } 1787 }
1772 if ( p ) 1788 if ( p )
1773 d->keep_running = p; 1789 d->keep_running = p;
1774 } 1790 }
1775#endif 1791#endif
1776} 1792}
1777 1793
1778 1794
1779/*! 1795/*!
1780 Sets widget \a mw as the mainWidget() and shows it. For small windows, 1796 Sets widget \a mw as the mainWidget() and shows it. For small windows,
1781 consider passing TRUE for \a nomaximize rather than the default FALSE. 1797 consider passing TRUE for \a nomaximize rather than the default FALSE.
1782 1798
1783 \sa showMainDocumentWidget() 1799 \sa showMainDocumentWidget()
1784*/ 1800*/
1785void QPEApplication::showMainWidget( QWidget* mw, bool nomaximize ) 1801void QPEApplication::showMainWidget( QWidget* mw, bool nomaximize )
1786{ 1802{
1787// setMainWidget(mw); this breaks FastLoading because lastWindowClose() would quit 1803// setMainWidget(mw); this breaks FastLoading because lastWindowClose() would quit
1788 d->show(mw, nomaximize ); 1804 d->show(mw, nomaximize );
1789} 1805}
1790 1806
1791/*! 1807/*!
1792 Sets widget \a mw as the mainWidget() and shows it. For small windows, 1808 Sets widget \a mw as the mainWidget() and shows it. For small windows,
1793 consider passing TRUE for \a nomaximize rather than the default FALSE. 1809 consider passing TRUE for \a nomaximize rather than the default FALSE.
1794 1810
1795 This calls designates the application as 1811 This calls designates the application as
1796 a \link docwidget.html document-oriented\endlink application. 1812 a \link docwidget.html document-oriented\endlink application.
1797 1813
1798 The \a mw widget \e must have this slot: setDocument(const QString&). 1814 The \a mw widget \e must have this slot: setDocument(const QString&).
1799 1815
1800 \sa showMainWidget() 1816 \sa showMainWidget()
1801*/ 1817*/
1802void QPEApplication::showMainDocumentWidget( QWidget* mw, bool nomaximize ) 1818void QPEApplication::showMainDocumentWidget( QWidget* mw, bool nomaximize )
1803{ 1819{
1804 if ( mw && argc() == 2 ) 1820 if ( mw && argc() == 2 )
1805 Global::setDocument( mw, QString::fromUtf8(argv()[1]) ); 1821 Global::setDocument( mw, QString::fromUtf8(argv()[1]) );
1806 1822
1807 1823
1808// setMainWidget(mw); see above 1824// setMainWidget(mw); see above
1809 d->show(mw, nomaximize ); 1825 d->show(mw, nomaximize );
1810} 1826}
1811 1827
1812 1828
1813/*! 1829/*!
1814 If an application is started via a \link qcop.html QCop\endlink 1830 If an application is started via a \link qcop.html QCop\endlink
1815 message, the application will process the \link qcop.html 1831 message, the application will process the \link qcop.html
1816 QCop\endlink message and then quit. If the application calls this 1832 QCop\endlink message and then quit. If the application calls this
1817 function while processing a \link qcop.html QCop\endlink message, 1833 function while processing a \link qcop.html QCop\endlink message,
1818 after processing its outstanding \link qcop.html QCop\endlink 1834 after processing its outstanding \link qcop.html QCop\endlink
1819 messages the application will start 'properly' and show itself. 1835 messages the application will start 'properly' and show itself.
1820 1836
1821 \sa keepRunning() 1837 \sa keepRunning()
1822*/ 1838*/
1823void QPEApplication::setKeepRunning() 1839void QPEApplication::setKeepRunning()
1824{ 1840{
1825 if ( qApp && qApp->inherits( "QPEApplication" ) ) { 1841 if ( qApp && qApp->inherits( "QPEApplication" ) ) {
1826 QPEApplication * qpeApp = ( QPEApplication* ) qApp; 1842 QPEApplication * qpeApp = ( QPEApplication* ) qApp;
1827 qpeApp->d->keep_running = TRUE; 1843 qpeApp->d->keep_running = TRUE;
1828 } 1844 }
1829} 1845}
1830 1846
1831/*! 1847/*!
1832 Returns TRUE if the application will quit after processing the 1848 Returns TRUE if the application will quit after processing the
1833 current list of qcop messages; otherwise returns FALSE. 1849 current list of qcop messages; otherwise returns FALSE.
1834 1850
1835 \sa setKeepRunning() 1851 \sa setKeepRunning()
1836*/ 1852*/
1837bool QPEApplication::keepRunning() const 1853bool QPEApplication::keepRunning() const
1838{ 1854{
1839 return d->keep_running; 1855 return d->keep_running;
1840} 1856}
1841 1857
1842/*! 1858/*!
1843 \internal 1859 \internal
1844*/ 1860*/
1845void QPEApplication::internalSetStyle( const QString &style ) 1861void QPEApplication::internalSetStyle( const QString &style )
1846{ 1862{
1847#if QT_VERSION >= 300 1863#if QT_VERSION >= 300
1848 if ( style == "QPE" ) { 1864 if ( style == "QPE" ) {
1849 setStyle( new QPEStyle ); 1865 setStyle( new QPEStyle );
1850 } 1866 }
1851 else { 1867 else {
1852 QStyle *s = QStyleFactory::create( style ); 1868 QStyle *s = QStyleFactory::create( style );
1853 if ( s ) 1869 if ( s )
1854 setStyle( s ); 1870 setStyle( s );
1855 } 1871 }
1856#else 1872#else
1857 if ( style == "Windows" ) { 1873 if ( style == "Windows" ) {
1858 setStyle( new QWindowsStyle ); 1874 setStyle( new QWindowsStyle );
1859 } 1875 }
1860 else if ( style == "QPE" ) { 1876 else if ( style == "QPE" ) {
1861 setStyle( new QPEStyle ); 1877 setStyle( new QPEStyle );
1862 } 1878 }
1863 else if ( style == "Light" ) { 1879 else if ( style == "Light" ) {
1864 setStyle( new LightStyle ); 1880 setStyle( new LightStyle );
1865 } 1881 }
1866#ifndef QT_NO_STYLE_PLATINUM 1882#ifndef QT_NO_STYLE_PLATINUM
1867 else if ( style == "Platinum" ) { 1883 else if ( style == "Platinum" ) {
1868 setStyle( new QPlatinumStyle ); 1884 setStyle( new QPlatinumStyle );
1869 } 1885 }
1870#endif 1886#endif
1871#ifndef QT_NO_STYLE_MOTIF 1887#ifndef QT_NO_STYLE_MOTIF
1872 else if ( style == "Motif" ) { 1888 else if ( style == "Motif" ) {
1873 setStyle( new QMotifStyle ); 1889 setStyle( new QMotifStyle );
1874 } 1890 }
1875#endif 1891#endif
1876#ifndef QT_NO_STYLE_MOTIFPLUS 1892#ifndef QT_NO_STYLE_MOTIFPLUS
1877 else if ( style == "MotifPlus" ) { 1893 else if ( style == "MotifPlus" ) {
1878 setStyle( new QMotifPlusStyle ); 1894 setStyle( new QMotifPlusStyle );
1879 } 1895 }
1880#endif 1896#endif
1881 1897
1882 else { 1898 else {
1883 QStyle *sty = 0; 1899 QStyle *sty = 0;
1884 QString path = QPEApplication::qpeDir ( ) + "/plugins/styles/"; 1900 QString path = QPEApplication::qpeDir ( ) + "/plugins/styles/";
1885 1901
1886#ifdef Q_OS_MACX 1902#ifdef Q_OS_MACX
1887 if ( style. find ( ".dylib" ) > 0 ) 1903 if ( style. find ( ".dylib" ) > 0 )
1888 path += style; 1904 path += style;
1889 else 1905 else
1890 path = path + "lib" + style. lower ( ) + ".dylib"; // compatibility 1906 path = path + "lib" + style. lower ( ) + ".dylib"; // compatibility
1891#else 1907#else
1892 if ( style. find ( ".so" ) > 0 ) 1908 if ( style. find ( ".so" ) > 0 )
1893 path += style; 1909 path += style;
1894 else 1910 else
1895 path = path + "lib" + style. lower ( ) + ".so"; // compatibility 1911 path = path + "lib" + style. lower ( ) + ".so"; // compatibility
1896#endif 1912#endif
1897 static QLibrary *lastlib = 0; 1913 static QLibrary *lastlib = 0;
1898 static StyleInterface *lastiface = 0; 1914 static StyleInterface *lastiface = 0;
1899 1915
1900 QLibrary *lib = new QLibrary ( path ); 1916 QLibrary *lib = new QLibrary ( path );
1901 StyleInterface *iface = 0; 1917 StyleInterface *iface = 0;
1902 1918
1903 if (( lib-> queryInterface ( IID_Style, ( QUnknownInterface ** ) &iface ) == QS_OK ) && iface ) 1919 if (( lib-> queryInterface ( IID_Style, ( QUnknownInterface ** ) &iface ) == QS_OK ) && iface )
1904 sty = iface-> style ( ); 1920 sty = iface-> style ( );
1905 1921
1906 if ( sty ) { 1922 if ( sty ) {
1907 setStyle ( sty ); 1923 setStyle ( sty );
1908 1924
1909 if ( lastiface ) 1925 if ( lastiface )
1910 lastiface-> release ( ); 1926 lastiface-> release ( );
1911 lastiface = iface; 1927 lastiface = iface;
1912 1928
1913 if ( lastlib ) { 1929 if ( lastlib ) {
1914 lastlib-> unload ( ); 1930 lastlib-> unload ( );
1915 delete lastlib; 1931 delete lastlib;
1916 } 1932 }
1917 lastlib = lib; 1933 lastlib = lib;
1918 } 1934 }
1919 else { 1935 else {
1920 if ( iface ) 1936 if ( iface )
1921 iface-> release ( ); 1937 iface-> release ( );
1922 delete lib; 1938 delete lib;
1923 1939
1924 setStyle ( new LightStyle ( )); 1940 setStyle ( new LightStyle ( ));
1925 } 1941 }
1926 } 1942 }
1927#endif 1943#endif
1928} 1944}
1929 1945
1930/*! 1946/*!
1931 \internal 1947 \internal
1932*/ 1948*/
1933void QPEApplication::prepareForTermination( bool willrestart ) 1949void QPEApplication::prepareForTermination( bool willrestart )
1934{ 1950{
1935 if ( willrestart ) { 1951 if ( willrestart ) {
1936 // Draw a big wait icon, the image can be altered in later revisions 1952 // Draw a big wait icon, the image can be altered in later revisions
1937 // QWidget *d = QApplication::desktop(); 1953 // QWidget *d = QApplication::desktop();
1938 QImage img = Resource::loadImage( "launcher/new_wait" ); 1954 QImage img = Resource::loadImage( "launcher/new_wait" );
1939 QPixmap pix; 1955 QPixmap pix;
1940 pix.convertFromImage( img.smoothScale( 1 * img.width(), 1 * img.height() ) ); 1956 pix.convertFromImage( img.smoothScale( 1 * img.width(), 1 * img.height() ) );
1941 QLabel *lblWait = new QLabel( 0, "wait hack!", QWidget::WStyle_Customize | 1957 QLabel *lblWait = new QLabel( 0, "wait hack!", QWidget::WStyle_Customize |
1942 QWidget::WStyle_NoBorder | QWidget::WStyle_Tool ); 1958 QWidget::WStyle_NoBorder | QWidget::WStyle_Tool );
1943 lblWait->setPixmap( pix ); 1959 lblWait->setPixmap( pix );
1944 lblWait->setAlignment( QWidget::AlignCenter ); 1960 lblWait->setAlignment( QWidget::AlignCenter );
1945 lblWait->show(); 1961 lblWait->show();
1946 lblWait->showMaximized(); 1962 lblWait->showMaximized();
1947 } 1963 }
1948#ifndef SINGLE_APP 1964#ifndef SINGLE_APP
1949 { QCopEnvelope envelope( "QPE/System", "forceQuit()" ); 1965 { QCopEnvelope envelope( "QPE/System", "forceQuit()" );
1950 } 1966 }
1951 processEvents(); // ensure the message goes out. 1967 processEvents(); // ensure the message goes out.
1952 sleep( 1 ); // You have 1 second to comply. 1968 sleep( 1 ); // You have 1 second to comply.
1953#endif 1969#endif
1954} 1970}
1955 1971
1956/*! 1972/*!
1957 \internal 1973 \internal
1958*/ 1974*/
1959void QPEApplication::shutdown() 1975void QPEApplication::shutdown()
1960{ 1976{
1961 // Implement in server's QPEApplication subclass 1977 // Implement in server's QPEApplication subclass
1962} 1978}
1963 1979
1964/*! 1980/*!
1965 \internal 1981 \internal
1966*/ 1982*/
1967void QPEApplication::restart() 1983void QPEApplication::restart()
1968{ 1984{
1969 // Implement in server's QPEApplication subclass 1985 // Implement in server's QPEApplication subclass
1970} 1986}
1971 1987
1972static QPtrDict<void>* stylusDict = 0; 1988static QPtrDict<void>* stylusDict = 0;
1973static void createDict() 1989static void createDict()
1974{ 1990{
1975 if ( !stylusDict ) 1991 if ( !stylusDict )
1976 stylusDict = new QPtrDict<void>; 1992 stylusDict = new QPtrDict<void>;
1977} 1993}
1978 1994
1979/*! 1995/*!
1980 Returns the current StylusMode for widget \a w. 1996 Returns the current StylusMode for widget \a w.
1981 1997
1982 \sa setStylusOperation() StylusMode 1998 \sa setStylusOperation() StylusMode
1983*/ 1999*/
1984QPEApplication::StylusMode QPEApplication::stylusOperation( QWidget* w ) 2000QPEApplication::StylusMode QPEApplication::stylusOperation( QWidget* w )
1985{ 2001{
1986 if ( stylusDict ) 2002 if ( stylusDict )
1987 return ( StylusMode ) ( int ) stylusDict->find( w ); 2003 return ( StylusMode ) ( int ) stylusDict->find( w );
1988 return LeftOnly; 2004 return LeftOnly;
1989} 2005}
1990 2006
1991/*! 2007/*!
1992 \enum QPEApplication::StylusMode 2008 \enum QPEApplication::StylusMode
1993 2009
1994 \value LeftOnly the stylus only generates LeftButton 2010 \value LeftOnly the stylus only generates LeftButton
1995 events (the default). 2011 events (the default).
1996 \value RightOnHold the stylus generates RightButton events 2012 \value RightOnHold the stylus generates RightButton events
1997 if the user uses the press-and-hold gesture. 2013 if the user uses the press-and-hold gesture.
1998 2014
1999 \sa setStylusOperation() stylusOperation() 2015 \sa setStylusOperation() stylusOperation()
2000*/ 2016*/
2001 2017
2002/*! 2018/*!
2003 Causes widget \a w to receive mouse events according to the stylus 2019 Causes widget \a w to receive mouse events according to the stylus
2004 \a mode. 2020 \a mode.
2005 2021
2006 \sa stylusOperation() StylusMode 2022 \sa stylusOperation() StylusMode
2007*/ 2023*/
2008void QPEApplication::setStylusOperation( QWidget * w, StylusMode mode ) 2024void QPEApplication::setStylusOperation( QWidget * w, StylusMode mode )
2009{ 2025{
2010 createDict(); 2026 createDict();
2011 if ( mode == LeftOnly ) { 2027 if ( mode == LeftOnly ) {
2012 stylusDict->remove 2028 stylusDict->remove
2013 ( w ); 2029 ( w );
2014 w->removeEventFilter( qApp ); 2030 w->removeEventFilter( qApp );
2015 } 2031 }
2016 else { 2032 else {
2017 stylusDict->insert( w, ( void* ) mode ); 2033 stylusDict->insert( w, ( void* ) mode );
2018 connect( w, SIGNAL( destroyed() ), qApp, SLOT( removeSenderFromStylusDict() ) ); 2034 connect( w, SIGNAL( destroyed() ), qApp, SLOT( removeSenderFromStylusDict() ) );
2019 w->installEventFilter( qApp ); 2035 w->installEventFilter( qApp );
2020 } 2036 }
2021} 2037}
2022 2038
2023 2039
2024/*! 2040/*!
2025 \reimp 2041 \reimp
2026*/ 2042*/
2027bool QPEApplication::eventFilter( QObject *o, QEvent *e ) 2043bool QPEApplication::eventFilter( QObject *o, QEvent *e )
2028{ 2044{
2029 if ( !o->isWidgetType() ) 2045 if ( !o->isWidgetType() )
2030 return FALSE; 2046 return FALSE;
2031 2047
2032 if ( stylusDict && e->type() >= QEvent::MouseButtonPress && e->type() <= QEvent::MouseMove ) { 2048 if ( stylusDict && e->type() >= QEvent::MouseButtonPress && e->type() <= QEvent::MouseMove ) {
2033 QMouseEvent * me = ( QMouseEvent* ) e; 2049 QMouseEvent * me = ( QMouseEvent* ) e;
2034 StylusMode mode = (StylusMode)(int)stylusDict->find(o); 2050 StylusMode mode = (StylusMode)(int)stylusDict->find(o);
2035 switch (mode) { 2051 switch (mode) {
2036 case RightOnHold: 2052 case RightOnHold:
2037 switch ( me->type() ) { 2053 switch ( me->type() ) {
2038 case QEvent::MouseButtonPress: 2054 case QEvent::MouseButtonPress:
2039 if ( me->button() == LeftButton ) { 2055 if ( me->button() == LeftButton ) {
2040 static long Pref = 500; // #### pref. 2056 static long Pref = 500; // #### pref.
2041 d->presswidget = (QWidget*)o; 2057 d->presswidget = (QWidget*)o;
2042 d->presspos = me->pos(); 2058 d->presspos = me->pos();
2043 d->rightpressed = FALSE; 2059 d->rightpressed = FALSE;
2044#ifdef OPIE_WITHROHFEEDBACK 2060#ifdef OPIE_WITHROHFEEDBACK
2045 if( ! d->RoH ) 2061 if( ! d->RoH )
2046 d->RoH = new Opie::Internal::RoHFeedback; 2062 d->RoH = new Opie::Internal::RoHFeedback;
2047 2063
2048 d->RoH->init( me->globalPos(), d->presswidget ); 2064 d->RoH->init( me->globalPos(), d->presswidget );
2049 Pref = d->RoH->delay(); 2065 Pref = d->RoH->delay();
2050 2066
2051#endif 2067#endif
2052 if (!d->presstimer ) 2068 if (!d->presstimer )
2053 d->presstimer = startTimer( Pref ); // #### pref. 2069 d->presstimer = startTimer( Pref ); // #### pref.
2054 2070
2055 } 2071 }
2056 break; 2072 break;
2057 case QEvent::MouseMove: 2073 case QEvent::MouseMove:
2058 if (d->presstimer && (me->pos() - d->presspos).manhattanLength() > 8) { 2074 if (d->presstimer && (me->pos() - d->presspos).manhattanLength() > 8) {
2059 killTimer(d->presstimer); 2075 killTimer(d->presstimer);
2060#ifdef OPIE_WITHROHFEEDBACK 2076#ifdef OPIE_WITHROHFEEDBACK
2061 d->RoH->stop(); 2077 d->RoH->stop();
2062#endif 2078#endif
2063 d->presstimer = 0; 2079 d->presstimer = 0;
2064 } 2080 }
2065 break; 2081 break;
2066 case QEvent::MouseButtonRelease: 2082 case QEvent::MouseButtonRelease:
2067 if ( me->button() == LeftButton ) { 2083 if ( me->button() == LeftButton ) {
2068 if ( d->presstimer ) { 2084 if ( d->presstimer ) {
2069 killTimer(d->presstimer); 2085 killTimer(d->presstimer);
2070#ifdef OPIE_WITHROHFEEDBACK 2086#ifdef OPIE_WITHROHFEEDBACK
2071 d->RoH->stop( ); 2087 d->RoH->stop( );
2072#endif 2088#endif
2073 d->presstimer = 0; 2089 d->presstimer = 0;
2074 } 2090 }
2075 if ( d->rightpressed && d->presswidget ) { 2091 if ( d->rightpressed && d->presswidget ) {
2076 printf( "Send ButtonRelease\n" ); 2092 printf( "Send ButtonRelease\n" );
2077 // Right released 2093 // Right released
2078 postEvent( d->presswidget, 2094 postEvent( d->presswidget,
2079 new QMouseEvent( QEvent::MouseButtonRelease, me->pos(), 2095 new QMouseEvent( QEvent::MouseButtonRelease, me->pos(),
2080 RightButton, LeftButton + RightButton ) ); 2096 RightButton, LeftButton + RightButton ) );
2081 // Left released, off-widget 2097 // Left released, off-widget
2082 postEvent( d->presswidget, 2098 postEvent( d->presswidget,
2083 new QMouseEvent( QEvent::MouseMove, QPoint( -1, -1), 2099 new QMouseEvent( QEvent::MouseMove, QPoint( -1, -1),
2084 LeftButton, LeftButton ) ); 2100 LeftButton, LeftButton ) );
2085 postEvent( d->presswidget, 2101 postEvent( d->presswidget,
2086 new QMouseEvent( QEvent::MouseButtonRelease, QPoint( -1, -1), 2102 new QMouseEvent( QEvent::MouseButtonRelease, QPoint( -1, -1),
2087 LeftButton, LeftButton ) ); 2103 LeftButton, LeftButton ) );
2088 d->rightpressed = FALSE; 2104 d->rightpressed = FALSE;
2089 return TRUE; // don't send the real Left release 2105 return TRUE; // don't send the real Left release
2090 } 2106 }
2091 } 2107 }
2092 break; 2108 break;
2093 default: 2109 default:
2094 break; 2110 break;
2095 } 2111 }
2096 break; 2112 break;
2097 default: 2113 default:
2098 ; 2114 ;
2099 } 2115 }
2100 } 2116 }
2101 else if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) { 2117 else if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) {
2102 QKeyEvent *ke = (QKeyEvent *)e; 2118 QKeyEvent *ke = (QKeyEvent *)e;
2103 if ( ke->key() == Key_Enter ) { 2119 if ( ke->key() == Key_Enter ) {
2104 if ( o->isA( "QRadioButton" ) || o->isA( "QCheckBox" ) ) { 2120 if ( o->isA( "QRadioButton" ) || o->isA( "QCheckBox" ) ) {
2105 postEvent( o, new QKeyEvent( e->type(), Key_Space, ' ', 2121 postEvent( o, new QKeyEvent( e->type(), Key_Space, ' ',
2106 ke->state(), " ", ke->isAutoRepeat(), ke->count() ) ); 2122 ke->state(), " ", ke->isAutoRepeat(), ke->count() ) );
2107 return TRUE; 2123 return TRUE;
2108 } 2124 }
2109 } 2125 }
2110 } 2126 }
2111 return FALSE; 2127 return FALSE;
2112} 2128}
2113 2129
2114/*! 2130/*!
2115 \reimp 2131 \reimp
2116*/ 2132*/
2117void QPEApplication::timerEvent( QTimerEvent *e ) 2133void QPEApplication::timerEvent( QTimerEvent *e )
2118{ 2134{
2119 if ( e->timerId() == d->presstimer && d->presswidget ) { 2135 if ( e->timerId() == d->presstimer && d->presswidget ) {
2120 2136
2121 // Right pressed 2137 // Right pressed
2122 postEvent( d->presswidget, 2138 postEvent( d->presswidget,
2123 new QMouseEvent( QEvent::MouseButtonPress, d->presspos, 2139 new QMouseEvent( QEvent::MouseButtonPress, d->presspos,
2124 RightButton, LeftButton ) ); 2140 RightButton, LeftButton ) );
2125 killTimer( d->presstimer ); 2141 killTimer( d->presstimer );
2126 d->presstimer = 0; 2142 d->presstimer = 0;
2127 d->rightpressed = TRUE; 2143 d->rightpressed = TRUE;
2128#ifdef OPIE_WITHROHFEEDBACK 2144#ifdef OPIE_WITHROHFEEDBACK
2129 d->RoH->stop(); 2145 d->RoH->stop();
2130#endif 2146#endif
2131 } 2147 }
2132} 2148}
2133 2149
2134void QPEApplication::removeSenderFromStylusDict() 2150void QPEApplication::removeSenderFromStylusDict()
2135{ 2151{
2136 stylusDict->remove 2152 stylusDict->remove
2137 ( ( void* ) sender() ); 2153 ( ( void* ) sender() );
2138 if ( d->presswidget == sender() ) 2154 if ( d->presswidget == sender() )
2139 d->presswidget = 0; 2155 d->presswidget = 0;
2140} 2156}
2141 2157
2142/*! 2158/*!
2143 \internal 2159 \internal
2144*/ 2160*/
2145bool QPEApplication::keyboardGrabbed() const 2161bool QPEApplication::keyboardGrabbed() const
2146{ 2162{
2147 return d->kbgrabbed; 2163 return d->kbgrabbed;
2148} 2164}
2149 2165
2150 2166
2151/*! 2167/*!
2152 Reverses the effect of grabKeyboard(). This is called automatically 2168 Reverses the effect of grabKeyboard(). This is called automatically
2153 on program exit. 2169 on program exit.
2154*/ 2170*/
2155void QPEApplication::ungrabKeyboard() 2171void QPEApplication::ungrabKeyboard()
2156{ 2172{
2157 ((QPEApplication *) qApp )-> d-> kbgrabbed = false; 2173 ((QPEApplication *) qApp )-> d-> kbgrabbed = false;
2158} 2174}
2159 2175
2160/*! 2176/*!
2161 Grabs the physical keyboard keys, e.g. the application's launching 2177 Grabs the physical keyboard keys, e.g. the application's launching
2162 keys. Instead of launching applications when these keys are pressed 2178 keys. Instead of launching applications when these keys are pressed
2163 the signals emitted are sent to this application instead. Some games 2179 the signals emitted are sent to this application instead. Some games
2164 programs take over the launch keys in this way to make interaction 2180 programs take over the launch keys in this way to make interaction
2165 easier. 2181 easier.
2166 2182
2167 \sa ungrabKeyboard() 2183 \sa ungrabKeyboard()
2168*/ 2184*/
2169void QPEApplication::grabKeyboard() 2185void QPEApplication::grabKeyboard()
2170{ 2186{
2171 ((QPEApplication *) qApp )-> d-> kbgrabbed = true; 2187 ((QPEApplication *) qApp )-> d-> kbgrabbed = true;
2172} 2188}
2173 2189
2174/*! 2190/*!
2175 \reimp 2191 \reimp