summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--library/qpeapplication.cpp35
1 files changed, 31 insertions, 4 deletions
diff --git a/library/qpeapplication.cpp b/library/qpeapplication.cpp
index c154689..ba9db71 100644
--- a/library/qpeapplication.cpp
+++ b/library/qpeapplication.cpp
@@ -1,744 +1,771 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of 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** $Id$ 19** $Id$
20** 20**
21**********************************************************************/ 21**********************************************************************/
22#define QTOPIA_INTERNAL_LANGLIST 22#define QTOPIA_INTERNAL_LANGLIST
23#include <stdlib.h> 23#include <stdlib.h>
24#include <unistd.h> 24#include <unistd.h>
25#include <qfile.h> 25#include <qfile.h>
26#ifdef Q_WS_QWS 26#ifdef Q_WS_QWS
27#ifndef QT_NO_COP 27#ifndef QT_NO_COP
28#if QT_VERSION <= 231 28#if QT_VERSION <= 231
29#define private public 29#define private public
30#define sendLocally processEvent 30#define sendLocally processEvent
31#include "qcopenvelope_qws.h" 31#include "qcopenvelope_qws.h"
32#undef private 32#undef private
33#else 33#else
34#include "qcopenvelope_qws.h" 34#include "qcopenvelope_qws.h"
35#endif 35#endif
36#endif 36#endif
37#include <qwindowsystem_qws.h> 37#include <qwindowsystem_qws.h>
38#endif 38#endif
39#include <qtextstream.h> 39#include <qtextstream.h>
40#include <qpalette.h> 40#include <qpalette.h>
41#include <qbuffer.h> 41#include <qbuffer.h>
42#include <qptrdict.h> 42#include <qptrdict.h>
43#include <qregexp.h> 43#include <qregexp.h>
44#include <qdir.h> 44#include <qdir.h>
45#include <qlabel.h> 45#include <qlabel.h>
46#include <qdialog.h> 46#include <qdialog.h>
47#include <qdragobject.h> 47#include <qdragobject.h>
48#include <qevent.h> 48#include <qevent.h>
49#include <qtooltip.h> 49#include <qtooltip.h>
50#include <qsignal.h> 50#include <qsignal.h>
51#include "qpeapplication.h" 51#include "qpeapplication.h"
52#include "qpestyle.h" 52#include "qpestyle.h"
53#if QT_VERSION >= 300 53#if QT_VERSION >= 300
54#include <qstylefactory.h> 54#include <qstylefactory.h>
55#else 55#else
56#include <qplatinumstyle.h> 56#include <qplatinumstyle.h>
57#include <qwindowsstyle.h> 57#include <qwindowsstyle.h>
58#include <qmotifstyle.h> 58#include <qmotifstyle.h>
59#include <qmotifplusstyle.h> 59#include <qmotifplusstyle.h>
60#include "lightstyle.h" 60#include "lightstyle.h"
61#endif 61#endif
62#include "global.h" 62#include "global.h"
63#include "resource.h" 63#include "resource.h"
64#if QT_VERSION <= 230 && defined(QT_NO_CODECS) 64#if QT_VERSION <= 230 && defined(QT_NO_CODECS)
65#include "qutfcodec.h" 65#include "qutfcodec.h"
66#endif 66#endif
67#include "config.h" 67#include "config.h"
68#include "network.h" 68#include "network.h"
69#include "fontmanager.h" 69#include "fontmanager.h"
70#include "power.h" 70#include "power.h"
71#include "alarmserver.h" 71#include "alarmserver.h"
72#include "applnk.h" 72#include "applnk.h"
73#include "qpemenubar.h" 73#include "qpemenubar.h"
74 74
75#include <unistd.h> 75#include <unistd.h>
76#include <sys/file.h> 76#include <sys/file.h>
77#include <sys/ioctl.h> 77#include <sys/ioctl.h>
78#include <sys/soundcard.h> 78#include <sys/soundcard.h>
79 79
80// for setBacklight() 80// for setBacklight()
81#if defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX) 81#if defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX)
82#include <linux/fb.h> 82#include <linux/fb.h>
83#include <sys/types.h> 83#include <sys/types.h>
84#include <sys/stat.h> 84#include <sys/stat.h>
85#endif 85#endif
86#include <stdlib.h> 86#include <stdlib.h>
87 87
88 88
89class QPEApplicationData { 89class QPEApplicationData {
90public: 90public:
91 QPEApplicationData() : presstimer(0), presswidget(0), rightpressed(FALSE), 91 QPEApplicationData() : presstimer(0), presswidget(0), rightpressed(FALSE),
92 kbgrabber(0), kbregrab(FALSE), notbusysent(FALSE), preloaded(FALSE), 92 kbgrabber(0), kbregrab(FALSE), notbusysent(FALSE), preloaded(FALSE),
93 forceshow(FALSE), nomaximize(FALSE), qpe_main_widget(0), 93 forceshow(FALSE), nomaximize(FALSE), qpe_main_widget(0),
94 keep_running(TRUE) 94 keep_running(TRUE)
95 { 95 {
96 qcopq.setAutoDelete(TRUE); 96 qcopq.setAutoDelete(TRUE);
97 } 97 }
98 98
99 int presstimer; 99 int presstimer;
100 QWidget* presswidget; 100 QWidget* presswidget;
101 QPoint presspos; 101 QPoint presspos;
102 bool rightpressed; 102 bool rightpressed;
103 int kbgrabber; 103 int kbgrabber;
104 bool kbregrab; 104 bool kbregrab;
105 bool notbusysent; 105 bool notbusysent;
106 QString appName; 106 QString appName;
107 struct QCopRec { 107 struct QCopRec {
108 QCopRec(const QCString &ch, const QCString &msg, 108 QCopRec(const QCString &ch, const QCString &msg,
109 const QByteArray &d) : 109 const QByteArray &d) :
110 channel(ch), message(msg), data(d) { } 110 channel(ch), message(msg), data(d) { }
111 111
112 QCString channel; 112 QCString channel;
113 QCString message; 113 QCString message;
114 QByteArray data; 114 QByteArray data;
115 }; 115 };
116 bool preloaded; 116 bool preloaded;
117 bool forceshow; 117 bool forceshow;
118 bool nomaximize; 118 bool nomaximize;
119 QWidget* qpe_main_widget; 119 QWidget* qpe_main_widget;
120 bool keep_running; 120 bool keep_running;
121 QList<QCopRec> qcopq; 121 QList<QCopRec> qcopq;
122 122
123 void enqueueQCop(const QCString &ch, const QCString &msg, 123 void enqueueQCop(const QCString &ch, const QCString &msg,
124 const QByteArray &data) 124 const QByteArray &data)
125 { 125 {
126 qcopq.append(new QCopRec(ch,msg,data)); 126 qcopq.append(new QCopRec(ch,msg,data));
127 } 127 }
128 void sendQCopQ() 128 void sendQCopQ()
129 { 129 {
130 QCopRec* r; 130 QCopRec* r;
131 for (QListIterator<QCopRec> it(qcopq); (r=it.current()); ++it) 131 for (QListIterator<QCopRec> it(qcopq); (r=it.current()); ++it)
132 QCopChannel::sendLocally(r->channel,r->message,r->data); 132 QCopChannel::sendLocally(r->channel,r->message,r->data);
133 qcopq.clear(); 133 qcopq.clear();
134 } 134 }
135}; 135};
136 136
137class ResourceMimeFactory : public QMimeSourceFactory { 137class ResourceMimeFactory : public QMimeSourceFactory {
138public: 138public:
139 ResourceMimeFactory() 139 ResourceMimeFactory()
140 { 140 {
141 setFilePath( Global::helpPath() ); 141 setFilePath( Global::helpPath() );
142 setExtensionType("html","text/html;charset=UTF-8"); 142 setExtensionType("html","text/html;charset=UTF-8");
143 } 143 }
144 144
145 const QMimeSource* data(const QString& abs_name) const 145 const QMimeSource* data(const QString& abs_name) const
146 { 146 {
147 const QMimeSource* r = QMimeSourceFactory::data(abs_name); 147 const QMimeSource* r = QMimeSourceFactory::data(abs_name);
148 if ( !r ) { 148 if ( !r ) {
149 int sl = abs_name.length(); 149 int sl = abs_name.length();
150 do { 150 do {
151 sl = abs_name.findRev('/',sl-1); 151 sl = abs_name.findRev('/',sl-1);
152 QString name = sl>=0 ? abs_name.mid(sl+1) : abs_name; 152 QString name = sl>=0 ? abs_name.mid(sl+1) : abs_name;
153 int dot = name.findRev('.'); 153 int dot = name.findRev('.');
154 if ( dot >= 0 ) 154 if ( dot >= 0 )
155 name = name.left(dot); 155 name = name.left(dot);
156 QImage img = Resource::loadImage(name); 156 QImage img = Resource::loadImage(name);
157 if ( !img.isNull() ) 157 if ( !img.isNull() )
158 r = new QImageDrag(img); 158 r = new QImageDrag(img);
159 } while (!r && sl>0); 159 } while (!r && sl>0);
160 } 160 }
161 return r; 161 return r;
162 } 162 }
163}; 163};
164 164
165static int muted=0; 165static int muted=0;
166static int micMuted=0; 166static int micMuted=0;
167 167
168static void setVolume(int t=0, int percent=-1) 168static void setVolume(int t=0, int percent=-1)
169{ 169{
170 switch (t) { 170 switch (t) {
171 case 0: { 171 case 0: {
172 Config cfg("Sound"); 172 Config cfg("Sound");
173 cfg.setGroup("System"); 173 cfg.setGroup("System");
174 if ( percent < 0 ) 174 if ( percent < 0 )
175 percent = cfg.readNumEntry("Volume",50); 175 percent = cfg.readNumEntry("Volume",50);
176 int fd = 0; 176 int fd = 0;
177 if ((fd = open("/dev/mixer", O_RDWR))>=0) { 177 if ((fd = open("/dev/mixer", O_RDWR))>=0) {
178 int vol = muted ? 0 : percent; 178 int vol = muted ? 0 : percent;
179 // set both channels to same volume 179 // set both channels to same volume
180 vol |= vol << 8; 180 vol |= vol << 8;
181 ioctl(fd, MIXER_WRITE(0), &vol); 181 ioctl(fd, MIXER_WRITE(0), &vol);
182 ::close(fd); 182 ::close(fd);
183 } 183 }
184 } break; 184 } break;
185 } 185 }
186} 186}
187 187
188static void setMic(int t=0, int percent=-1) 188static void setMic(int t=0, int percent=-1)
189{ 189{
190 switch (t) { 190 switch (t) {
191 case 0: { 191 case 0: {
192 Config cfg("Sound"); 192 Config cfg("Sound");
193 cfg.setGroup("System"); 193 cfg.setGroup("System");
194 if ( percent < 0 ) 194 if ( percent < 0 )
195 percent = cfg.readNumEntry("Mic",50); 195 percent = cfg.readNumEntry("Mic",50);
196 196
197 int fd = 0; 197 int fd = 0;
198 int mic = micMuted ? 0 : percent; 198 int mic = micMuted ? 0 : percent;
199 if ((fd = open("/dev/mixer", O_RDWR))>=0) { 199 if ((fd = open("/dev/mixer", O_RDWR))>=0) {
200 ioctl(fd, MIXER_WRITE(SOUND_MIXER_MIC), &mic); 200 ioctl(fd, MIXER_WRITE(SOUND_MIXER_MIC), &mic);
201 ::close(fd); 201 ::close(fd);
202 } 202 }
203 } break; 203 } break;
204 } 204 }
205} 205}
206 206
207int qpe_sysBrightnessSteps() 207int qpe_sysBrightnessSteps()
208{ 208{
209#if defined(QT_QWS_IPAQ) 209#if defined(QT_QWS_IPAQ)
210 return 255; 210 return 255;
211#elif defined(QT_QWS_EBX) 211#elif defined(QT_QWS_EBX)
212 return 4; 212 return 4;
213#else 213#else
214 return 255; // ? 214 return 255; // ?
215#endif 215#endif
216} 216}
217 217
218 218
219static int& hack(int& i) 219static int& hack(int& i)
220{ 220{
221#if QT_VERSION <= 230 && defined(QT_NO_CODECS) 221#if QT_VERSION <= 230 && defined(QT_NO_CODECS)
222 // These should be created, but aren't in Qt 2.3.0 222 // These should be created, but aren't in Qt 2.3.0
223 (void)new QUtf8Codec; 223 (void)new QUtf8Codec;
224 (void)new QUtf16Codec; 224 (void)new QUtf16Codec;
225#endif 225#endif
226 return i; 226 return i;
227} 227}
228 228
229static bool forced_off = FALSE; 229static bool forced_off = FALSE;
230static int curbl=-1; 230static int curbl=-1;
231 231
232static int backlight() 232static int backlight()
233{ 233{
234 if ( curbl == -1 ) { 234 if ( curbl == -1 ) {
235 // Read from config 235 // Read from config
236 Config config( "qpe" ); 236 Config config( "qpe" );
237 config.setGroup( "Screensaver" ); 237 config.setGroup( "Screensaver" );
238 curbl = config.readNumEntry("Brightness",255); 238 curbl = config.readNumEntry("Brightness",255);
239 } 239 }
240 return curbl; 240 return curbl;
241} 241}
242 242
243static void setBacklight(int bright) 243static void setBacklight(int bright)
244{ 244{
245 if ( bright == -3 ) { 245 if ( bright == -3 ) {
246 // Forced on 246 // Forced on
247 forced_off = FALSE; 247 forced_off = FALSE;
248 bright = -1; 248 bright = -1;
249 } 249 }
250 if ( forced_off && bright != -2 ) 250 if ( forced_off && bright != -2 )
251 return; 251 return;
252 if ( bright == -2 ) { 252 if ( bright == -2 ) {
253 // Toggle between off and on 253 // Toggle between off and on
254 bright = curbl ? 0 : -1; 254 bright = curbl ? 0 : -1;
255 forced_off = !bright; 255 forced_off = !bright;
256 } 256 }
257 if ( bright == -1 ) { 257 if ( bright == -1 ) {
258 // Read from config 258 // Read from config
259 Config config( "qpe" ); 259 Config config( "qpe" );
260 config.setGroup( "Screensaver" ); 260 config.setGroup( "Screensaver" );
261 bright = config.readNumEntry("Brightness",255); 261 bright = config.readNumEntry("Brightness",255);
262 } 262 }
263#if defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX) 263#if defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX)
264 if ( QFile::exists("/usr/bin/bl") ) { 264 if ( QFile::exists("/usr/bin/bl") ) {
265 QString cmd = "/usr/bin/bl 1 "; 265 QString cmd = "/usr/bin/bl 1 ";
266 cmd += bright<=0 ? "0 " : "1 "; 266 cmd += bright<=0 ? "0 " : "1 ";
267 cmd += QString::number(bright); 267 cmd += QString::number(bright);
268 system(cmd.latin1()); 268 system(cmd.latin1());
269#if defined(QT_QWS_EBX) 269#if defined(QT_QWS_EBX)
270 } else if ( QFile::exists("/dev/fl") ) { 270 } else if ( QFile::exists("/dev/fl") ) {
271#define FL_IOCTL_STEP_CONTRAST 100 271#define FL_IOCTL_STEP_CONTRAST 100
272 int fd = open("/dev/fl", O_WRONLY); 272 int fd = open("/dev/fl", O_WRONLY);
273 if (fd >= 0 ) { 273 if (fd >= 0 ) {
274 int steps = qpe_sysBrightnessSteps(); 274 int steps = qpe_sysBrightnessSteps();
275 int bl = ( bright * steps + 127 ) / 255; 275 int bl = ( bright * steps + 127 ) / 255;
276 if ( bright && !bl ) bl = 1; 276 if ( bright && !bl ) bl = 1;
277 bl = ioctl(fd, FL_IOCTL_STEP_CONTRAST, bl); 277 bl = ioctl(fd, FL_IOCTL_STEP_CONTRAST, bl);
278 close(fd); 278 close(fd);
279 } 279 }
280 } 280 }
281#elif defined(QT_QWS_IPAQ) 281#elif defined(QT_QWS_IPAQ)
282 } else if ( QFile::exists("/dev/ts") || QFile::exists("/dev/h3600_ts") ) { 282 } else if ( QFile::exists("/dev/ts") || QFile::exists("/dev/h3600_ts") ) {
283 typedef struct { 283 typedef struct {
284 unsigned char mode; 284 unsigned char mode;
285 unsigned char pwr; 285 unsigned char pwr;
286 unsigned char brightness; 286 unsigned char brightness;
287 } FLITE_IN; 287 } FLITE_IN;
288# ifndef FLITE_ON 288# ifndef FLITE_ON
289# ifndef _LINUX_IOCTL_H 289# ifndef _LINUX_IOCTL_H
290# include <linux/ioctl.h> 290# include <linux/ioctl.h>
291# endif 291# endif
292# define FLITE_ON _IOW('f', 7, FLITE_IN) 292# define FLITE_ON _IOW('f', 7, FLITE_IN)
293# endif 293# endif
294 int fd; 294 int fd;
295 if ( QFile::exists("/dev/ts") ) 295 if ( QFile::exists("/dev/ts") )
296 fd = open("/dev/ts", O_WRONLY); 296 fd = open("/dev/ts", O_WRONLY);
297 else 297 else
298 fd = open("/dev/h3600_ts", O_WRONLY); 298 fd = open("/dev/h3600_ts", O_WRONLY);
299 if (fd >= 0 ) { 299 if (fd >= 0 ) {
300 FLITE_IN bl; 300 FLITE_IN bl;
301 bl.mode = 1; 301 bl.mode = 1;
302 bl.pwr = bright ? 1 : 0; 302 bl.pwr = bright ? 1 : 0;
303 bl.brightness = bright; 303 bl.brightness = bright;
304 ioctl(fd, FLITE_ON, &bl); 304 ioctl(fd, FLITE_ON, &bl);
305 close(fd); 305 close(fd);
306 } 306 }
307 } 307 }
308#endif 308#endif
309#endif 309#endif
310 curbl = bright; 310 curbl = bright;
311} 311}
312 312
313void qpe_setBacklight(int bright) { setBacklight(bright); } 313void qpe_setBacklight(int bright) { setBacklight(bright); }
314 314
315static bool dim_on = FALSE; 315static bool dim_on = FALSE;
316static bool lightoff_on = FALSE; 316static bool lightoff_on = FALSE;
317static int disable_suspend = 100; 317static int disable_suspend = 100;
318 318
319static bool powerOnline() 319static bool powerOnline()
320{ 320{
321 return PowerStatusManager::readStatus().acStatus() == PowerStatus::Online; 321 return PowerStatusManager::readStatus().acStatus() == PowerStatus::Online;
322} 322}
323 323
324static bool networkOnline() 324static bool networkOnline()
325{ 325{
326 return Network::networkOnline(); 326 return Network::networkOnline();
327} 327}
328 328
329class QPEScreenSaver : public QWSScreenSaver 329class QPEScreenSaver : public QWSScreenSaver
330{ 330{
331private:
332 int LcdOn;
331 333
332public: 334public:
333 QPEScreenSaver() 335 QPEScreenSaver()
334 { 336 {
337 int fd;
338
339 LcdOn = TRUE;
340 // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off)
341 fd=open("/dev/fb0",O_RDWR);
342 if (fd != -1) { ioctl(fd,FBIOBLANK,VESA_NO_BLANKING); close(fd); }
335 } 343 }
336 void restore() 344 void restore()
337 { 345 {
346 if (!LcdOn) // We must have turned it off
347 {
348 int fd;
349 fd=open("/dev/fb0",O_RDWR);
350 if (fd != -1) { ioctl(fd,FBIOBLANK,VESA_NO_BLANKING); close(fd); }
351 }
338 setBacklight(-1); 352 setBacklight(-1);
339 } 353 }
340 bool save(int level) 354 bool save(int level)
341 { 355 {
356 int fd;
357
342 switch ( level ) { 358 switch ( level ) {
343 case 0: 359 case 0:
344 if ( disable_suspend > 0 && dim_on ) { 360 if ( disable_suspend > 0 && dim_on ) {
345 if (backlight() > 1) 361 if (backlight() > 1)
346 setBacklight(1); // lowest non-off 362 setBacklight(1); // lowest non-off
347 } 363 }
348 return TRUE; 364 return TRUE;
349 break; 365 break;
350 case 1: 366 case 1:
351 if ( disable_suspend > 1 && lightoff_on ) { 367 if ( disable_suspend > 1 && lightoff_on ) {
352 setBacklight(0); // off 368 setBacklight(0); // off
353 } 369 }
354 return TRUE; 370 return TRUE;
355 break; 371 break;
356 case 2: 372 case 2:
357 if ( disable_suspend > 2 && !powerOnline() && !networkOnline() ) { 373 Config config( "qpe" );
358 QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); 374 config.setGroup( "Screensaver" );
359 return TRUE; 375 if (config.readNumEntry("LcdOffOnly",0) != 0) // We're only turning off the LCD
360 } 376 {
377 fd=open("/dev/fb0",O_RDWR);
378 if (fd != -1) { ioctl(fd,FBIOBLANK,VESA_POWERDOWN); close(fd); }
379 LcdOn = FALSE;
380 }
381 else // We're going to suspend the whole machine
382 {
383 if ( disable_suspend > 2 && !powerOnline() && !networkOnline() ) {
384 QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE );
385 return TRUE;
386 }
387 }
361 break; 388 break;
362 } 389 }
363 return FALSE; 390 return FALSE;
364 } 391 }
365}; 392};
366 393
367static int ssi(int interval, Config &config, const QString &enable, const QString& value, int def) 394static int ssi(int interval, Config &config, const QString &enable, const QString& value, int def)
368{ 395{
369 if ( !enable.isEmpty() && config.readNumEntry(enable,0) == 0 ) 396 if ( !enable.isEmpty() && config.readNumEntry(enable,0) == 0 )
370 return 0; 397 return 0;
371 398
372 if ( interval < 0 ) { 399 if ( interval < 0 ) {
373 // Restore screen blanking and power saving state 400 // Restore screen blanking and power saving state
374 interval = config.readNumEntry( value, def ); 401 interval = config.readNumEntry( value, def );
375 } 402 }
376 return interval; 403 return interval;
377} 404}
378 405
379static void setScreenSaverIntervals(int i1, int i2, int i3) 406static void setScreenSaverIntervals(int i1, int i2, int i3)
380{ 407{
381 Config config( "qpe" ); 408 Config config( "qpe" );
382 config.setGroup( "Screensaver" ); 409 config.setGroup( "Screensaver" );
383 410
384 int v[4]; 411 int v[4];
385 i1 = ssi(i1, config, "Dim","Interval_Dim", 30); 412 i1 = ssi(i1, config, "Dim","Interval_Dim", 30);
386 i2 = ssi(i2, config, "LightOff","Interval_LightOff", 20); 413 i2 = ssi(i2, config, "LightOff","Interval_LightOff", 20);
387 i3 = ssi(i3, config, "","Interval", 60); 414 i3 = ssi(i3, config, "","Interval", 60);
388 415
389 //qDebug("screen saver intervals: %d %d %d", i1, i2, i3); 416 //qDebug("screen saver intervals: %d %d %d", i1, i2, i3);
390 417
391 v[0] = QMAX( 1000*i1, 100); 418 v[0] = QMAX( 1000*i1, 100);
392 v[1] = QMAX( 1000*i2, 100); 419 v[1] = QMAX( 1000*i2, 100);
393 v[2] = QMAX( 1000*i3, 100); 420 v[2] = QMAX( 1000*i3, 100);
394 v[3] = 0; 421 v[3] = 0;
395 dim_on = ( (i1 != 0) ? config.readNumEntry("Dim",1) : FALSE ); 422 dim_on = ( (i1 != 0) ? config.readNumEntry("Dim",1) : FALSE );
396 lightoff_on = ( (i2 != 0 ) ? config.readNumEntry("LightOff",1) : FALSE ); 423 lightoff_on = ( (i2 != 0 ) ? config.readNumEntry("LightOff",1) : FALSE );
397 if ( !i1 && !i2 && !i3 ) 424 if ( !i1 && !i2 && !i3 )
398 QWSServer::setScreenSaverInterval(0); 425 QWSServer::setScreenSaverInterval(0);
399 else 426 else
400 QWSServer::setScreenSaverIntervals(v); 427 QWSServer::setScreenSaverIntervals(v);
401} 428}
402 429
403static void setScreenSaverInterval(int interval) 430static void setScreenSaverInterval(int interval)
404{ 431{
405 setScreenSaverIntervals(-1,-1,interval); 432 setScreenSaverIntervals(-1,-1,interval);
406} 433}
407 434
408 435
409/*! 436/*!
410 \class QPEApplication qpeapplication.h 437 \class QPEApplication qpeapplication.h
411 \brief The QPEApplication class implements various system services 438 \brief The QPEApplication class implements various system services
412 that are available to all Qtopia applications. 439 that are available to all Qtopia applications.
413 440
414 Simply by using QPEApplication instead of QApplication, a plain Qt 441 Simply by using QPEApplication instead of QApplication, a plain Qt
415 application becomes a Qtopia application. It automatically follows 442 application becomes a Qtopia application. It automatically follows
416 style changes, quits and raises, and in the 443 style changes, quits and raises, and in the
417 case of \link docwidget.html document-oriented\endlink applications, 444 case of \link docwidget.html document-oriented\endlink applications,
418 changes the current displayed document in response to the environment. 445 changes the current displayed document in response to the environment.
419*/ 446*/
420 447
421/*! 448/*!
422 \fn void QPEApplication::clientMoused() 449 \fn void QPEApplication::clientMoused()
423 450
424 \internal 451 \internal
425*/ 452*/
426 453
427/*! 454/*!
428 \fn void QPEApplication::timeChanged(); 455 \fn void QPEApplication::timeChanged();
429 456
430 This signal is emitted when the time jumps forward or backwards 457 This signal is emitted when the time jumps forward or backwards
431 by more than the normal passage of time. 458 by more than the normal passage of time.
432*/ 459*/
433 460
434/*! 461/*!
435 \fn void QPEApplication::clockChanged( bool ampm ); 462 \fn void QPEApplication::clockChanged( bool ampm );
436 463
437 This signal is emitted when the user changes the style 464 This signal is emitted when the user changes the style
438 of clock. If \a ampm is TRUE, the user wants a 12-hour 465 of clock. If \a ampm is TRUE, the user wants a 12-hour
439 AM/PM close, otherwise, they want a 24-hour clock. 466 AM/PM close, otherwise, they want a 24-hour clock.
440*/ 467*/
441 468
442/*! 469/*!
443 \fn void QPEApplication::appMessage( const QCString& msg, const QByteArray& data ) 470 \fn void QPEApplication::appMessage( const QCString& msg, const QByteArray& data )
444 471
445 This signal is emitted when a message is received on the 472 This signal is emitted when a message is received on the
446 QPE/Application/<i>appname</i> QCop channel for this application. 473 QPE/Application/<i>appname</i> QCop channel for this application.
447 474
448 The slot to which you connect this signal uses \a msg and \a data 475 The slot to which you connect this signal uses \a msg and \a data
449 in the following way: 476 in the following way:
450 477
451\code 478\code
452 void MyWidget::receive( const QCString& msg, const QByteArray& data ) 479 void MyWidget::receive( const QCString& msg, const QByteArray& data )
453 { 480 {
454 QDataStream stream( data, IO_ReadOnly ); 481 QDataStream stream( data, IO_ReadOnly );
455 if ( msg == "someMessage(int,int,int)" ) { 482 if ( msg == "someMessage(int,int,int)" ) {
456 int a,b,c; 483 int a,b,c;
457 stream >> a >> b >> c; 484 stream >> a >> b >> c;
458 ... 485 ...
459 } else if ( msg == "otherMessage(QString)" ) { 486 } else if ( msg == "otherMessage(QString)" ) {
460 ... 487 ...
461 } 488 }
462 } 489 }
463\endcode 490\endcode
464 491
465 \sa qcop.html 492 \sa qcop.html
466*/ 493*/
467 494
468/*! 495/*!
469 Constructs a QPEApplication just as you would construct 496 Constructs a QPEApplication just as you would construct
470 a QApplication, passing \a argc, \a argv, and \a t. 497 a QApplication, passing \a argc, \a argv, and \a t.
471*/ 498*/
472QPEApplication::QPEApplication( int& argc, char **argv, Type t ) 499QPEApplication::QPEApplication( int& argc, char **argv, Type t )
473 : QApplication( hack(argc), argv, t ) 500 : QApplication( hack(argc), argv, t )
474{ 501{
475 int dw = desktop()->width(); 502 int dw = desktop()->width();
476 if ( dw < 200 ) { 503 if ( dw < 200 ) {
477 setFont( QFont( "helvetica", 8 ) ); 504 setFont( QFont( "helvetica", 8 ) );
478 AppLnk::setSmallIconSize(10); 505 AppLnk::setSmallIconSize(10);
479 AppLnk::setBigIconSize(28); 506 AppLnk::setBigIconSize(28);
480 } 507 }
481 508
482 d = new QPEApplicationData; 509 d = new QPEApplicationData;
483 QMimeSourceFactory::setDefaultFactory(new ResourceMimeFactory); 510 QMimeSourceFactory::setDefaultFactory(new ResourceMimeFactory);
484 511
485 connect(this, SIGNAL(lastWindowClosed()), this, SLOT(hideOrQuit())); 512 connect(this, SIGNAL(lastWindowClosed()), this, SLOT(hideOrQuit()));
486#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 513#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
487 514
488 QString qcopfn("/tmp/qcop-msg-"); 515 QString qcopfn("/tmp/qcop-msg-");
489 qcopfn += QString(argv[0]); // append command name 516 qcopfn += QString(argv[0]); // append command name
490 517
491 QFile f(qcopfn); 518 QFile f(qcopfn);
492 if ( f.open(IO_ReadOnly) ) { 519 if ( f.open(IO_ReadOnly) ) {
493 flock(f.handle(), LOCK_EX); 520 flock(f.handle(), LOCK_EX);
494 } 521 }
495 522
496 sysChannel = new QCopChannel( "QPE/System", this ); 523 sysChannel = new QCopChannel( "QPE/System", this );
497 connect( sysChannel, SIGNAL(received(const QCString &, const QByteArray &)), 524 connect( sysChannel, SIGNAL(received(const QCString &, const QByteArray &)),
498 this, SLOT(systemMessage( const QCString &, const QByteArray &)) ); 525 this, SLOT(systemMessage( const QCString &, const QByteArray &)) );
499 526
500 QCString channel = QCString(argv[0]); 527 QCString channel = QCString(argv[0]);
501 channel.replace(QRegExp(".*/"),""); 528 channel.replace(QRegExp(".*/"),"");
502 d->appName = channel; 529 d->appName = channel;
503 channel = "QPE/Application/" + channel; 530 channel = "QPE/Application/" + channel;
504 pidChannel = new QCopChannel( channel, this); 531 pidChannel = new QCopChannel( channel, this);
505 connect( pidChannel, SIGNAL(received(const QCString &, const QByteArray &)), 532 connect( pidChannel, SIGNAL(received(const QCString &, const QByteArray &)),
506 this, SLOT(pidMessage(const QCString &, const QByteArray &))); 533 this, SLOT(pidMessage(const QCString &, const QByteArray &)));
507 534
508 if ( f.isOpen() ) { 535 if ( f.isOpen() ) {
509 d->keep_running = FALSE; 536 d->keep_running = FALSE;
510 QDataStream ds(&f); 537 QDataStream ds(&f);
511 QCString channel, message; 538 QCString channel, message;
512 QByteArray data; 539 QByteArray data;
513 while(!ds.atEnd()) { 540 while(!ds.atEnd()) {
514 ds >> channel >> message >> data; 541 ds >> channel >> message >> data;
515 d->enqueueQCop(channel,message,data); 542 d->enqueueQCop(channel,message,data);
516 } 543 }
517 544
518 flock(f.handle(), LOCK_UN); 545 flock(f.handle(), LOCK_UN);
519 f.close(); 546 f.close();
520 f.remove(); 547 f.remove();
521 } 548 }
522 549
523 for (int a=0; a<argc; a++) { 550 for (int a=0; a<argc; a++) {
524 if ( qstrcmp(argv[a],"-preload")==0 ) { 551 if ( qstrcmp(argv[a],"-preload")==0 ) {
525 argv[a] = argv[a+1]; 552 argv[a] = argv[a+1];
526 a++; 553 a++;
527 d->preloaded = TRUE; 554 d->preloaded = TRUE;
528 argc-=1; 555 argc-=1;
529 } else if ( qstrcmp(argv[a],"-preload-show")==0 ) { 556 } else if ( qstrcmp(argv[a],"-preload-show")==0 ) {
530 argv[a] = argv[a+1]; 557 argv[a] = argv[a+1];
531 a++; 558 a++;
532 d->preloaded = TRUE; 559 d->preloaded = TRUE;
533 d->forceshow = TRUE; 560 d->forceshow = TRUE;
534 argc-=1; 561 argc-=1;
535 } 562 }
536 } 563 }
537 564
538 /* overide stored arguments */ 565 /* overide stored arguments */
539 setArgs(argc, argv); 566 setArgs(argc, argv);
540 567
541#endif 568#endif
542 569
543 qwsSetDecoration( new QPEDecoration() ); 570 qwsSetDecoration( new QPEDecoration() );
544 571
545#ifndef QT_NO_TRANSLATION 572#ifndef QT_NO_TRANSLATION
546 QStringList langs = Global::languageList(); 573 QStringList langs = Global::languageList();
547 for (QStringList::ConstIterator it = langs.begin(); it!=langs.end(); ++it) { 574 for (QStringList::ConstIterator it = langs.begin(); it!=langs.end(); ++it) {
548 QString lang = *it; 575 QString lang = *it;
549 576
550 QTranslator * trans; 577 QTranslator * trans;
551 QString tfn; 578 QString tfn;
552 579
553 trans = new QTranslator(this); 580 trans = new QTranslator(this);
554 tfn = qpeDir()+"/i18n/"+lang+"/libqpe.qm"; 581 tfn = qpeDir()+"/i18n/"+lang+"/libqpe.qm";
555 if ( trans->load( tfn )) 582 if ( trans->load( tfn ))
556 installTranslator( trans ); 583 installTranslator( trans );
557 else 584 else
558 delete trans; 585 delete trans;
559 586
560 trans = new QTranslator(this); 587 trans = new QTranslator(this);
561 tfn = qpeDir()+"/i18n/"+lang+"/"+d->appName+".qm"; 588 tfn = qpeDir()+"/i18n/"+lang+"/"+d->appName+".qm";
562 if ( trans->load( tfn )) 589 if ( trans->load( tfn ))
563 installTranslator( trans ); 590 installTranslator( trans );
564 else 591 else
565 delete trans; 592 delete trans;
566 593
567 //###language/font hack; should look it up somewhere 594 //###language/font hack; should look it up somewhere
568 if ( lang == "ja" || lang == "zh_CN" || lang == "zh_TW" || lang == "ko" ) { 595 if ( lang == "ja" || lang == "zh_CN" || lang == "zh_TW" || lang == "ko" ) {
569 QFont fn = FontManager::unicodeFont( FontManager::Proportional ); 596 QFont fn = FontManager::unicodeFont( FontManager::Proportional );
570 setFont( fn ); 597 setFont( fn );
571 } 598 }
572 } 599 }
573#endif 600#endif
574 601
575 applyStyle(); 602 applyStyle();
576 603
577 if ( type() == GuiServer ) { 604 if ( type() == GuiServer ) {
578 setScreenSaverInterval(-1); 605 setScreenSaverInterval(-1);
579 setVolume(); 606 setVolume();
580 QWSServer::setScreenSaver(new QPEScreenSaver); 607 QWSServer::setScreenSaver(new QPEScreenSaver);
581 } 608 }
582 609
583 installEventFilter( this ); 610 installEventFilter( this );
584 611
585 QPEMenuToolFocusManager::initialize(); 612 QPEMenuToolFocusManager::initialize();
586 613
587#ifdef QT_NO_QWS_CURSOR 614#ifdef QT_NO_QWS_CURSOR
588 // if we have no cursor, probably don't want tooltips 615 // if we have no cursor, probably don't want tooltips
589 QToolTip::setEnabled( FALSE ); 616 QToolTip::setEnabled( FALSE );
590#endif 617#endif
591} 618}
592 619
593static QPtrDict<void>* inputMethodDict=0; 620static QPtrDict<void>* inputMethodDict=0;
594static void createInputMethodDict() 621static void createInputMethodDict()
595{ 622{
596 if ( !inputMethodDict ) 623 if ( !inputMethodDict )
597 inputMethodDict = new QPtrDict<void>; 624 inputMethodDict = new QPtrDict<void>;
598} 625}
599 626
600/*! 627/*!
601 Returns the currently set hint to the system as to whether 628 Returns the currently set hint to the system as to whether
602 \a w has any use for text input methods. 629 \a w has any use for text input methods.
603 630
604 \sa setInputMethodHint() 631 \sa setInputMethodHint()
605*/ 632*/
606QPEApplication::InputMethodHint QPEApplication::inputMethodHint( QWidget* w ) 633QPEApplication::InputMethodHint QPEApplication::inputMethodHint( QWidget* w )
607{ 634{
608 if ( inputMethodDict && w ) 635 if ( inputMethodDict && w )
609 return (InputMethodHint)(int)inputMethodDict->find(w); 636 return (InputMethodHint)(int)inputMethodDict->find(w);
610 return Normal; 637 return Normal;
611} 638}
612 639
613/*! 640/*!
614 \enum QPEApplication::InputMethodHint 641 \enum QPEApplication::InputMethodHint
615 642
616 \value Normal the application sometimes needs text input (the default). 643 \value Normal the application sometimes needs text input (the default).
617 \value AlwaysOff the application never needs text input. 644 \value AlwaysOff the application never needs text input.
618 \value AlwaysOn the application always needs text input. 645 \value AlwaysOn the application always needs text input.
619*/ 646*/
620 647
621/*! 648/*!
622 Hints to the system that \a w has use for text input methods 649 Hints to the system that \a w has use for text input methods
623 as specified by \a mode. 650 as specified by \a mode.
624 651
625 \sa inputMethodHint() 652 \sa inputMethodHint()
626*/ 653*/
627void QPEApplication::setInputMethodHint( QWidget* w, InputMethodHint mode ) 654void QPEApplication::setInputMethodHint( QWidget* w, InputMethodHint mode )
628{ 655{
629 createInputMethodDict(); 656 createInputMethodDict();
630 if ( mode == Normal ) { 657 if ( mode == Normal ) {
631 inputMethodDict->remove(w); 658 inputMethodDict->remove(w);
632 } else { 659 } else {
633 inputMethodDict->insert(w,(void*)mode); 660 inputMethodDict->insert(w,(void*)mode);
634 } 661 }
635} 662}
636 663
637class HackDialog : public QDialog 664class HackDialog : public QDialog
638{ 665{
639public: 666public:
640 void acceptIt() { accept(); } 667 void acceptIt() { accept(); }
641 void rejectIt() { reject(); } 668 void rejectIt() { reject(); }
642}; 669};
643 670
644 671
645void QPEApplication::mapToDefaultAction( QWSKeyEvent *ke, int key ) 672void QPEApplication::mapToDefaultAction( QWSKeyEvent *ke, int key )
646{ 673{
647 // specialised actions for certain widgets. May want to 674 // specialised actions for certain widgets. May want to
648 // add more stuff here. 675 // add more stuff here.
649 if ( activePopupWidget() && activePopupWidget()->inherits( "QListBox" ) 676 if ( activePopupWidget() && activePopupWidget()->inherits( "QListBox" )
650 && activePopupWidget()->parentWidget() 677 && activePopupWidget()->parentWidget()
651 && activePopupWidget()->parentWidget()->inherits( "QComboBox" ) ) 678 && activePopupWidget()->parentWidget()->inherits( "QComboBox" ) )
652 key = Qt::Key_Return; 679 key = Qt::Key_Return;
653 680
654 if ( activePopupWidget() && activePopupWidget()->inherits( "QPopupMenu" ) ) 681 if ( activePopupWidget() && activePopupWidget()->inherits( "QPopupMenu" ) )
655 key = Qt::Key_Return; 682 key = Qt::Key_Return;
656 683
657 ke->simpleData.keycode = key; 684 ke->simpleData.keycode = key;
658} 685}
659 686
660class HackWidget : public QWidget 687class HackWidget : public QWidget
661{ 688{
662public: 689public:
663 bool needsOk() 690 bool needsOk()
664 { return (getWState() & WState_Reserved1 ); } 691 { return (getWState() & WState_Reserved1 ); }
665}; 692};
666 693
667/*! 694/*!
668 \internal 695 \internal
669*/ 696*/
670bool QPEApplication::qwsEventFilter( QWSEvent *e ) 697bool QPEApplication::qwsEventFilter( QWSEvent *e )
671{ 698{
672 if ( !d->notbusysent && e->type == QWSEvent::Focus ) { 699 if ( !d->notbusysent && e->type == QWSEvent::Focus ) {
673 if ( qApp->type() != QApplication::GuiServer ) { 700 if ( qApp->type() != QApplication::GuiServer ) {
674 QCopEnvelope e("QPE/System", "notBusy(QString)" ); 701 QCopEnvelope e("QPE/System", "notBusy(QString)" );
675 e << d->appName; 702 e << d->appName;
676 } 703 }
677 d->notbusysent=TRUE; 704 d->notbusysent=TRUE;
678 } 705 }
679 if ( type() == GuiServer ) { 706 if ( type() == GuiServer ) {
680 switch ( e->type ) { 707 switch ( e->type ) {
681 case QWSEvent::Mouse: 708 case QWSEvent::Mouse:
682 if ( e->asMouse()->simpleData.state && !QWidget::find(e->window()) ) 709 if ( e->asMouse()->simpleData.state && !QWidget::find(e->window()) )
683 emit clientMoused(); 710 emit clientMoused();
684 } 711 }
685 } 712 }
686 if ( e->type == QWSEvent::Key ) { 713 if ( e->type == QWSEvent::Key ) {
687 if ( d->kbgrabber == 1 ) 714 if ( d->kbgrabber == 1 )
688 return TRUE; 715 return TRUE;
689 QWSKeyEvent *ke = (QWSKeyEvent *)e; 716 QWSKeyEvent *ke = (QWSKeyEvent *)e;
690 if ( ke->simpleData.keycode == Qt::Key_F33 ) { 717 if ( ke->simpleData.keycode == Qt::Key_F33 ) {
691 // Use special "OK" key to press "OK" on top level widgets 718 // Use special "OK" key to press "OK" on top level widgets
692 QWidget *active = activeWindow(); 719 QWidget *active = activeWindow();
693 QWidget *popup = 0; 720 QWidget *popup = 0;
694 if ( active && active->isPopup() ) { 721 if ( active && active->isPopup() ) {
695 popup = active; 722 popup = active;
696 active = active->parentWidget(); 723 active = active->parentWidget();
697 } 724 }
698 if ( active && (int)active->winId() == ke->simpleData.window && 725 if ( active && (int)active->winId() == ke->simpleData.window &&
699 !active->testWFlags( WStyle_Customize|WType_Popup|WType_Desktop )) { 726 !active->testWFlags( WStyle_Customize|WType_Popup|WType_Desktop )) {
700 if ( ke->simpleData.is_press ) { 727 if ( ke->simpleData.is_press ) {
701 if ( popup ) 728 if ( popup )
702 popup->close(); 729 popup->close();
703 if ( active->inherits( "QDialog" ) ) { 730 if ( active->inherits( "QDialog" ) ) {
704 HackDialog *d = (HackDialog *)active; 731 HackDialog *d = (HackDialog *)active;
705 d->acceptIt(); 732 d->acceptIt();
706 return TRUE; 733 return TRUE;
707 } else if ( ((HackWidget *)active)->needsOk() ) { 734 } else if ( ((HackWidget *)active)->needsOk() ) {
708 QSignal s; 735 QSignal s;
709 s.connect( active, SLOT( accept() ) ); 736 s.connect( active, SLOT( accept() ) );
710 s.activate(); 737 s.activate();
711 } else { 738 } else {
712 // do the same as with the select key: Map to the default action of the widget: 739 // do the same as with the select key: Map to the default action of the widget:
713 mapToDefaultAction( ke, Qt::Key_Return ); 740 mapToDefaultAction( ke, Qt::Key_Return );
714 } 741 }
715 } 742 }
716 } 743 }
717 } else if ( ke->simpleData.keycode == Qt::Key_F30 ) { 744 } else if ( ke->simpleData.keycode == Qt::Key_F30 ) {
718 // Use special "select" key to do whatever default action a widget has 745 // Use special "select" key to do whatever default action a widget has
719 mapToDefaultAction( ke, Qt::Key_Space ); 746 mapToDefaultAction( ke, Qt::Key_Space );
720 } else if ( ke->simpleData.keycode == Qt::Key_Escape && 747 } else if ( ke->simpleData.keycode == Qt::Key_Escape &&
721 ke->simpleData.is_press ) { 748 ke->simpleData.is_press ) {
722 // Escape key closes app if focus on toplevel 749 // Escape key closes app if focus on toplevel
723 QWidget *active = activeWindow(); 750 QWidget *active = activeWindow();
724 if ( active && active->testWFlags( WType_TopLevel ) && 751 if ( active && active->testWFlags( WType_TopLevel ) &&
725 (int)active->winId() == ke->simpleData.window && 752 (int)active->winId() == ke->simpleData.window &&
726 !active->testWFlags( WStyle_Dialog|WStyle_Customize|WType_Popup|WType_Desktop )) { 753 !active->testWFlags( WStyle_Dialog|WStyle_Customize|WType_Popup|WType_Desktop )) {
727 if ( active->inherits( "QDialog" ) ) { 754 if ( active->inherits( "QDialog" ) ) {
728 HackDialog *d = (HackDialog *)active; 755 HackDialog *d = (HackDialog *)active;
729 d->rejectIt(); 756 d->rejectIt();
730 return TRUE; 757 return TRUE;
731 } else if ( strcmp( argv()[0], "embeddedkonsole") != 0 ) { 758 } else if ( strcmp( argv()[0], "embeddedkonsole") != 0 ) {
732 active->close(); 759 active->close();
733 } 760 }
734 } 761 }
735 } 762 }
736 763
737#if QT_VERSION < 231 764#if QT_VERSION < 231
738 // Filter out the F4/Launcher key from apps 765 // Filter out the F4/Launcher key from apps
739 // ### The launcher key may not always be F4 on all devices 766 // ### The launcher key may not always be F4 on all devices
740 if ( ((QWSKeyEvent *)e)->simpleData.keycode == Qt::Key_F4 ) 767 if ( ((QWSKeyEvent *)e)->simpleData.keycode == Qt::Key_F4 )
741 return TRUE; 768 return TRUE;
742#endif 769#endif
743 } 770 }
744 if ( e->type == QWSEvent::Focus ) { 771 if ( e->type == QWSEvent::Focus ) {