summaryrefslogtreecommitdiff
path: root/library/qpeapplication.cpp
Unidiff
Diffstat (limited to 'library/qpeapplication.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--library/qpeapplication.cpp20
1 files changed, 18 insertions, 2 deletions
diff --git a/library/qpeapplication.cpp b/library/qpeapplication.cpp
index cf437da..f84bc0e 100644
--- a/library/qpeapplication.cpp
+++ b/library/qpeapplication.cpp
@@ -1,1638 +1,1654 @@
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 <linux/fb.h> 51#include <linux/fb.h>
52 52
53#include <qsignal.h> 53#include <qsignal.h>
54#include "qpeapplication.h" 54#include "qpeapplication.h"
55#include "qpestyle.h" 55#include "qpestyle.h"
56#if QT_VERSION >= 300 56#if QT_VERSION >= 300
57#include <qstylefactory.h> 57#include <qstylefactory.h>
58#else 58#else
59#include <qplatinumstyle.h> 59#include <qplatinumstyle.h>
60#include <qwindowsstyle.h> 60#include <qwindowsstyle.h>
61#include <qmotifstyle.h> 61#include <qmotifstyle.h>
62#include <qmotifplusstyle.h> 62#include <qmotifplusstyle.h>
63#include "lightstyle.h" 63#include "lightstyle.h"
64#endif 64#endif
65#include "global.h" 65#include "global.h"
66#include "resource.h" 66#include "resource.h"
67#if QT_VERSION <= 230 && defined(QT_NO_CODECS) 67#if QT_VERSION <= 230 && defined(QT_NO_CODECS)
68#include "qutfcodec.h" 68#include "qutfcodec.h"
69#endif 69#endif
70#include "config.h" 70#include "config.h"
71#include "network.h" 71#include "network.h"
72#include "fontmanager.h" 72#include "fontmanager.h"
73#include "fontdatabase.h"
74
73#include "power.h" 75#include "power.h"
74#include "alarmserver.h" 76#include "alarmserver.h"
75#include "applnk.h" 77#include "applnk.h"
76#include "qpemenubar.h" 78#include "qpemenubar.h"
77 79
78#include <unistd.h> 80#include <unistd.h>
79#include <sys/file.h> 81#include <sys/file.h>
80#include <sys/ioctl.h> 82#include <sys/ioctl.h>
81#include <sys/soundcard.h> 83#include <sys/soundcard.h>
82 84
83// for setBacklight() 85// for setBacklight()
84#if defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX) 86#if defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX)
85#include <linux/fb.h> 87#include <linux/fb.h>
86#include <sys/types.h> 88#include <sys/types.h>
87#include <sys/stat.h> 89#include <sys/stat.h>
88#endif 90#endif
89#include <stdlib.h> 91#include <stdlib.h>
90 92
91 93
92class QPEApplicationData { 94class QPEApplicationData {
93public: 95public:
94 QPEApplicationData() : presstimer(0), presswidget(0), rightpressed(FALSE), 96 QPEApplicationData() : presstimer(0), presswidget(0), rightpressed(FALSE),
95 kbgrabber(0), kbregrab(FALSE), notbusysent(FALSE), preloaded(FALSE), 97 kbgrabber(0), kbregrab(FALSE), notbusysent(FALSE), preloaded(FALSE),
96 forceshow(FALSE), nomaximize(FALSE), qpe_main_widget(0), 98 forceshow(FALSE), nomaximize(FALSE), qpe_main_widget(0),
97 keep_running(TRUE) 99 keep_running(TRUE)
98 { 100 {
99 qcopq.setAutoDelete(TRUE); 101 qcopq.setAutoDelete(TRUE);
100 } 102 }
101 103
102 int presstimer; 104 int presstimer;
103 QWidget* presswidget; 105 QWidget* presswidget;
104 QPoint presspos; 106 QPoint presspos;
105 bool rightpressed; 107 bool rightpressed;
106 int kbgrabber; 108 int kbgrabber;
107 bool kbregrab; 109 bool kbregrab;
108 bool notbusysent; 110 bool notbusysent;
109 QString appName; 111 QString appName;
110 struct QCopRec { 112 struct QCopRec {
111 QCopRec(const QCString &ch, const QCString &msg, 113 QCopRec(const QCString &ch, const QCString &msg,
112 const QByteArray &d) : 114 const QByteArray &d) :
113 channel(ch), message(msg), data(d) { } 115 channel(ch), message(msg), data(d) { }
114 116
115 QCString channel; 117 QCString channel;
116 QCString message; 118 QCString message;
117 QByteArray data; 119 QByteArray data;
118 }; 120 };
119 bool preloaded; 121 bool preloaded;
120 bool forceshow; 122 bool forceshow;
121 bool nomaximize; 123 bool nomaximize;
122 QWidget* qpe_main_widget; 124 QWidget* qpe_main_widget;
123 bool keep_running; 125 bool keep_running;
124 QList<QCopRec> qcopq; 126 QList<QCopRec> qcopq;
125 127
126 void enqueueQCop(const QCString &ch, const QCString &msg, 128 void enqueueQCop(const QCString &ch, const QCString &msg,
127 const QByteArray &data) 129 const QByteArray &data)
128 { 130 {
129 qcopq.append(new QCopRec(ch,msg,data)); 131 qcopq.append(new QCopRec(ch,msg,data));
130 } 132 }
131 void sendQCopQ() 133 void sendQCopQ()
132 { 134 {
133 QCopRec* r; 135 QCopRec* r;
134 for (QListIterator<QCopRec> it(qcopq); (r=it.current()); ++it) 136 for (QListIterator<QCopRec> it(qcopq); (r=it.current()); ++it)
135 QCopChannel::sendLocally(r->channel,r->message,r->data); 137 QCopChannel::sendLocally(r->channel,r->message,r->data);
136 qcopq.clear(); 138 qcopq.clear();
137 } 139 }
138}; 140};
139 141
140class ResourceMimeFactory : public QMimeSourceFactory { 142class ResourceMimeFactory : public QMimeSourceFactory {
141public: 143public:
142 ResourceMimeFactory() 144 ResourceMimeFactory()
143 { 145 {
144 setFilePath( Global::helpPath() ); 146 setFilePath( Global::helpPath() );
145 setExtensionType("html","text/html;charset=UTF-8"); 147 setExtensionType("html","text/html;charset=UTF-8");
146 } 148 }
147 149
148 const QMimeSource* data(const QString& abs_name) const 150 const QMimeSource* data(const QString& abs_name) const
149 { 151 {
150 const QMimeSource* r = QMimeSourceFactory::data(abs_name); 152 const QMimeSource* r = QMimeSourceFactory::data(abs_name);
151 if ( !r ) { 153 if ( !r ) {
152 int sl = abs_name.length(); 154 int sl = abs_name.length();
153 do { 155 do {
154 sl = abs_name.findRev('/',sl-1); 156 sl = abs_name.findRev('/',sl-1);
155 QString name = sl>=0 ? abs_name.mid(sl+1) : abs_name; 157 QString name = sl>=0 ? abs_name.mid(sl+1) : abs_name;
156 int dot = name.findRev('.'); 158 int dot = name.findRev('.');
157 if ( dot >= 0 ) 159 if ( dot >= 0 )
158 name = name.left(dot); 160 name = name.left(dot);
159 QImage img = Resource::loadImage(name); 161 QImage img = Resource::loadImage(name);
160 if ( !img.isNull() ) 162 if ( !img.isNull() )
161 r = new QImageDrag(img); 163 r = new QImageDrag(img);
162 } while (!r && sl>0); 164 } while (!r && sl>0);
163 } 165 }
164 return r; 166 return r;
165 } 167 }
166}; 168};
167 169
168static int muted=0; 170static int muted=0;
169static int micMuted=0; 171static int micMuted=0;
170 172
171static void setVolume(int t=0, int percent=-1) 173static void setVolume(int t=0, int percent=-1)
172{ 174{
173 switch (t) { 175 switch (t) {
174 case 0: { 176 case 0: {
175 Config cfg("qpe"); 177 Config cfg("qpe");
176 cfg.setGroup("Volume"); 178 cfg.setGroup("Volume");
177 if ( percent < 0 ) 179 if ( percent < 0 )
178 percent = cfg.readNumEntry("VolumePercent",50); 180 percent = cfg.readNumEntry("VolumePercent",50);
179 int fd = 0; 181 int fd = 0;
180 if ((fd = open("/dev/mixer", O_RDWR))>=0) { 182 if ((fd = open("/dev/mixer", O_RDWR))>=0) {
181 int vol = muted ? 0 : percent; 183 int vol = muted ? 0 : percent;
182 // set both channels to same volume 184 // set both channels to same volume
183 vol |= vol << 8; 185 vol |= vol << 8;
184 ioctl(fd, MIXER_WRITE(0), &vol); 186 ioctl(fd, MIXER_WRITE(0), &vol);
185 ::close(fd); 187 ::close(fd);
186 } 188 }
187 } break; 189 } break;
188 } 190 }
189} 191}
190 192
191static void setMic(int t=0, int percent=-1) 193static void setMic(int t=0, int percent=-1)
192{ 194{
193 switch (t) { 195 switch (t) {
194 case 0: { 196 case 0: {
195 Config cfg("qpe"); 197 Config cfg("qpe");
196 cfg.setGroup("Volume"); 198 cfg.setGroup("Volume");
197 if ( percent < 0 ) 199 if ( percent < 0 )
198 percent = cfg.readNumEntry("Mic",50); 200 percent = cfg.readNumEntry("Mic",50);
199 201
200 int fd = 0; 202 int fd = 0;
201 int mic = micMuted ? 0 : percent; 203 int mic = micMuted ? 0 : percent;
202 if ((fd = open("/dev/mixer", O_RDWR))>=0) { 204 if ((fd = open("/dev/mixer", O_RDWR))>=0) {
203 ioctl(fd, MIXER_WRITE(SOUND_MIXER_MIC), &mic); 205 ioctl(fd, MIXER_WRITE(SOUND_MIXER_MIC), &mic);
204 ::close(fd); 206 ::close(fd);
205 } 207 }
206 } break; 208 } break;
207 } 209 }
208} 210}
209 211
210int qpe_sysBrightnessSteps() 212int qpe_sysBrightnessSteps()
211{ 213{
212#if defined(QT_QWS_IPAQ) 214#if defined(QT_QWS_IPAQ)
213 return 255; 215 return 255;
214#elif defined(QT_QWS_EBX) 216#elif defined(QT_QWS_EBX)
215 return 4; 217 return 4;
216#else 218#else
217 return 255; // ? 219 return 255; // ?
218#endif 220#endif
219} 221}
220 222
221 223
222static int& hack(int& i) 224static int& hack(int& i)
223{ 225{
224#if QT_VERSION <= 230 && defined(QT_NO_CODECS) 226#if QT_VERSION <= 230 && defined(QT_NO_CODECS)
225 // These should be created, but aren't in Qt 2.3.0 227 // These should be created, but aren't in Qt 2.3.0
226 (void)new QUtf8Codec; 228 (void)new QUtf8Codec;
227 (void)new QUtf16Codec; 229 (void)new QUtf16Codec;
228#endif 230#endif
229 return i; 231 return i;
230} 232}
231 233
232static bool forced_off = FALSE; 234static bool forced_off = FALSE;
233static int curbl=-1; 235static int curbl=-1;
234 236
235static int backlight() 237static int backlight()
236{ 238{
237 if ( curbl == -1 ) { 239 if ( curbl == -1 ) {
238 // Read from config 240 // Read from config
239 Config config( "qpe" ); 241 Config config( "qpe" );
240 config.setGroup( "Screensaver" ); 242 config.setGroup( "Screensaver" );
241 curbl = config.readNumEntry("Brightness",255); 243 curbl = config.readNumEntry("Brightness",255);
242 } 244 }
243 return curbl; 245 return curbl;
244} 246}
245 247
246static void setBacklight(int bright) 248static void setBacklight(int bright)
247{ 249{
248 if ( bright == -3 ) { 250 if ( bright == -3 ) {
249 // Forced on 251 // Forced on
250 forced_off = FALSE; 252 forced_off = FALSE;
251 bright = -1; 253 bright = -1;
252 } 254 }
253 if ( forced_off && bright != -2 ) 255 if ( forced_off && bright != -2 )
254 return; 256 return;
255 if ( bright == -2 ) { 257 if ( bright == -2 ) {
256 // Toggle between off and on 258 // Toggle between off and on
257 bright = curbl ? 0 : -1; 259 bright = curbl ? 0 : -1;
258 forced_off = !bright; 260 forced_off = !bright;
259 } 261 }
260 if ( bright == -1 ) { 262 if ( bright == -1 ) {
261 // Read from config 263 // Read from config
262 Config config( "qpe" ); 264 Config config( "qpe" );
263 config.setGroup( "Screensaver" ); 265 config.setGroup( "Screensaver" );
264 bright = config.readNumEntry("Brightness",255); 266 bright = config.readNumEntry("Brightness",255);
265 } 267 }
266#if defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX) 268#if defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX)
267 if ( QFile::exists("/usr/bin/bl") ) { 269 if ( QFile::exists("/usr/bin/bl") ) {
268 QString cmd = "/usr/bin/bl 1 "; 270 QString cmd = "/usr/bin/bl 1 ";
269 cmd += bright<=0 ? "0 " : "1 "; 271 cmd += bright<=0 ? "0 " : "1 ";
270 cmd += QString::number(bright); 272 cmd += QString::number(bright);
271 system(cmd.latin1()); 273 system(cmd.latin1());
272#if defined(QT_QWS_EBX) 274#if defined(QT_QWS_EBX)
273 } else if ( QFile::exists("/dev/fl") ) { 275 } else if ( QFile::exists("/dev/fl") ) {
274#define FL_IOCTL_STEP_CONTRAST 100 276#define FL_IOCTL_STEP_CONTRAST 100
275 int fd = open("/dev/fl", O_WRONLY); 277 int fd = open("/dev/fl", O_WRONLY);
276 if (fd >= 0 ) { 278 if (fd >= 0 ) {
277 int steps = qpe_sysBrightnessSteps(); 279 int steps = qpe_sysBrightnessSteps();
278 int bl = ( bright * steps + 127 ) / 255; 280 int bl = ( bright * steps + 127 ) / 255;
279 if ( bright && !bl ) bl = 1; 281 if ( bright && !bl ) bl = 1;
280 bl = ioctl(fd, FL_IOCTL_STEP_CONTRAST, bl); 282 bl = ioctl(fd, FL_IOCTL_STEP_CONTRAST, bl);
281 close(fd); 283 close(fd);
282 } 284 }
283 } 285 }
284#elif defined(QT_QWS_IPAQ) 286#elif defined(QT_QWS_IPAQ)
285 } else if ( QFile::exists("/dev/ts") || QFile::exists("/dev/h3600_ts") ) { 287 } else if ( QFile::exists("/dev/ts") || QFile::exists("/dev/h3600_ts") ) {
286 typedef struct { 288 typedef struct {
287 unsigned char mode; 289 unsigned char mode;
288 unsigned char pwr; 290 unsigned char pwr;
289 unsigned char brightness; 291 unsigned char brightness;
290 } FLITE_IN; 292 } FLITE_IN;
291# ifndef FLITE_ON 293# ifndef FLITE_ON
292# ifndef _LINUX_IOCTL_H 294# ifndef _LINUX_IOCTL_H
293# include <linux/ioctl.h> 295# include <linux/ioctl.h>
294# endif 296# endif
295# define FLITE_ON _IOW('f', 7, FLITE_IN) 297# define FLITE_ON _IOW('f', 7, FLITE_IN)
296# endif 298# endif
297 int fd; 299 int fd;
298 if ( QFile::exists("/dev/ts") ) 300 if ( QFile::exists("/dev/ts") )
299 fd = open("/dev/ts", O_WRONLY); 301 fd = open("/dev/ts", O_WRONLY);
300 else 302 else
301 fd = open("/dev/h3600_ts", O_WRONLY); 303 fd = open("/dev/h3600_ts", O_WRONLY);
302 if (fd >= 0 ) { 304 if (fd >= 0 ) {
303 FLITE_IN bl; 305 FLITE_IN bl;
304 bl.mode = 1; 306 bl.mode = 1;
305 bl.pwr = bright ? 1 : 0; 307 bl.pwr = bright ? 1 : 0;
306 bl.brightness = bright; 308 bl.brightness = bright;
307 ioctl(fd, FLITE_ON, &bl); 309 ioctl(fd, FLITE_ON, &bl);
308 close(fd); 310 close(fd);
309 } 311 }
310 } 312 }
311#endif 313#endif
312#endif 314#endif
313 curbl = bright; 315 curbl = bright;
314} 316}
315 317
316void qpe_setBacklight(int bright) { setBacklight(bright); } 318void qpe_setBacklight(int bright) { setBacklight(bright); }
317 319
318static bool dim_on = FALSE; 320static bool dim_on = FALSE;
319static bool lightoff_on = FALSE; 321static bool lightoff_on = FALSE;
320static int disable_suspend = 100; 322static int disable_suspend = 100;
321 323
322static bool powerOnline() 324static bool powerOnline()
323{ 325{
324 return PowerStatusManager::readStatus().acStatus() == PowerStatus::Online; 326 return PowerStatusManager::readStatus().acStatus() == PowerStatus::Online;
325} 327}
326 328
327static bool networkOnline() 329static bool networkOnline()
328{ 330{
329 return Network::networkOnline(); 331 return Network::networkOnline();
330} 332}
331 333
332class QPEScreenSaver : public QWSScreenSaver 334class QPEScreenSaver : public QWSScreenSaver
333{ 335{
334private: 336private:
335 int LcdOn; 337 int LcdOn;
336 338
337public: 339public:
338 QPEScreenSaver() 340 QPEScreenSaver()
339 { 341 {
340 int fd; 342 int fd;
341 343
342 LcdOn = TRUE; 344 LcdOn = TRUE;
343 // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off) 345 // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off)
344 fd=open("/dev/fb0",O_RDWR); 346 fd=open("/dev/fb0",O_RDWR);
345 if (fd != -1) { ioctl(fd,FBIOBLANK,VESA_NO_BLANKING); close(fd); } 347 if (fd != -1) { ioctl(fd,FBIOBLANK,VESA_NO_BLANKING); close(fd); }
346 } 348 }
347 void restore() 349 void restore()
348 { 350 {
349 if (!LcdOn) // We must have turned it off 351 if (!LcdOn) // We must have turned it off
350 { 352 {
351 int fd; 353 int fd;
352 fd=open("/dev/fb0",O_RDWR); 354 fd=open("/dev/fb0",O_RDWR);
353 if (fd != -1) { ioctl(fd,FBIOBLANK,VESA_NO_BLANKING); close(fd); } 355 if (fd != -1) { ioctl(fd,FBIOBLANK,VESA_NO_BLANKING); close(fd); }
354 } 356 }
355 setBacklight(-1); 357 setBacklight(-1);
356 } 358 }
357 bool save(int level) 359 bool save(int level)
358 { 360 {
359 int fd; 361 int fd;
360 362
361 switch ( level ) { 363 switch ( level ) {
362 case 0: 364 case 0:
363 if ( disable_suspend > 0 && dim_on ) { 365 if ( disable_suspend > 0 && dim_on ) {
364 if (backlight() > 1) 366 if (backlight() > 1)
365 setBacklight(1); // lowest non-off 367 setBacklight(1); // lowest non-off
366 } 368 }
367 return TRUE; 369 return TRUE;
368 break; 370 break;
369 case 1: 371 case 1:
370 if ( disable_suspend > 1 && lightoff_on ) { 372 if ( disable_suspend > 1 && lightoff_on ) {
371 setBacklight(0); // off 373 setBacklight(0); // off
372 } 374 }
373 return TRUE; 375 return TRUE;
374 break; 376 break;
375 case 2: 377 case 2:
376 Config config( "qpe" ); 378 Config config( "qpe" );
377 config.setGroup( "Screensaver" ); 379 config.setGroup( "Screensaver" );
378 if (config.readNumEntry("LcdOffOnly",0) != 0) // We're only turning off the LCD 380 if (config.readNumEntry("LcdOffOnly",0) != 0) // We're only turning off the LCD
379 { 381 {
380 fd=open("/dev/fb0",O_RDWR); 382 fd=open("/dev/fb0",O_RDWR);
381 if (fd != -1) { ioctl(fd,FBIOBLANK,VESA_POWERDOWN); close(fd); } 383 if (fd != -1) { ioctl(fd,FBIOBLANK,VESA_POWERDOWN); close(fd); }
382 LcdOn = FALSE; 384 LcdOn = FALSE;
383 } 385 }
384 else // We're going to suspend the whole machine 386 else // We're going to suspend the whole machine
385 { 387 {
386 if ( disable_suspend > 2 && !powerOnline() && !networkOnline() ) { 388 if ( disable_suspend > 2 && !powerOnline() && !networkOnline() ) {
387 QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); 389 QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE );
388 return TRUE; 390 return TRUE;
389 } 391 }
390 } 392 }
391 break; 393 break;
392 } 394 }
393 return FALSE; 395 return FALSE;
394 } 396 }
395}; 397};
396 398
397static int ssi(int interval, Config &config, const QString &enable, const QString& value, int def) 399static int ssi(int interval, Config &config, const QString &enable, const QString& value, int def)
398{ 400{
399 if ( !enable.isEmpty() && config.readNumEntry(enable,0) == 0 ) 401 if ( !enable.isEmpty() && config.readNumEntry(enable,0) == 0 )
400 return 0; 402 return 0;
401 403
402 if ( interval < 0 ) { 404 if ( interval < 0 ) {
403 // Restore screen blanking and power saving state 405 // Restore screen blanking and power saving state
404 interval = config.readNumEntry( value, def ); 406 interval = config.readNumEntry( value, def );
405 } 407 }
406 return interval; 408 return interval;
407} 409}
408 410
409static void setScreenSaverIntervals(int i1, int i2, int i3) 411static void setScreenSaverIntervals(int i1, int i2, int i3)
410{ 412{
411 Config config( "qpe" ); 413 Config config( "qpe" );
412 config.setGroup( "Screensaver" ); 414 config.setGroup( "Screensaver" );
413 415
414 int v[4]; 416 int v[4];
415 i1 = ssi(i1, config, "Dim","Interval_Dim", 30); 417 i1 = ssi(i1, config, "Dim","Interval_Dim", 30);
416 i2 = ssi(i2, config, "LightOff","Interval_LightOff", 20); 418 i2 = ssi(i2, config, "LightOff","Interval_LightOff", 20);
417 i3 = ssi(i3, config, "","Interval", 60); 419 i3 = ssi(i3, config, "","Interval", 60);
418 420
419 //qDebug("screen saver intervals: %d %d %d", i1, i2, i3); 421 //qDebug("screen saver intervals: %d %d %d", i1, i2, i3);
420 422
421 v[0] = QMAX( 1000*i1, 100); 423 v[0] = QMAX( 1000*i1, 100);
422 v[1] = QMAX( 1000*i2, 100); 424 v[1] = QMAX( 1000*i2, 100);
423 v[2] = QMAX( 1000*i3, 100); 425 v[2] = QMAX( 1000*i3, 100);
424 v[3] = 0; 426 v[3] = 0;
425 dim_on = ( (i1 != 0) ? config.readNumEntry("Dim",1) : FALSE ); 427 dim_on = ( (i1 != 0) ? config.readNumEntry("Dim",1) : FALSE );
426 lightoff_on = ( (i2 != 0 ) ? config.readNumEntry("LightOff",1) : FALSE ); 428 lightoff_on = ( (i2 != 0 ) ? config.readNumEntry("LightOff",1) : FALSE );
427 if ( !i1 && !i2 && !i3 ) 429 if ( !i1 && !i2 && !i3 )
428 QWSServer::setScreenSaverInterval(0); 430 QWSServer::setScreenSaverInterval(0);
429 else 431 else
430 QWSServer::setScreenSaverIntervals(v); 432 QWSServer::setScreenSaverIntervals(v);
431} 433}
432 434
433static void setScreenSaverInterval(int interval) 435static void setScreenSaverInterval(int interval)
434{ 436{
435 setScreenSaverIntervals(-1,-1,interval); 437 setScreenSaverIntervals(-1,-1,interval);
436} 438}
437 439
438 440
439/*! 441/*!
440 \class QPEApplication qpeapplication.h 442 \class QPEApplication qpeapplication.h
441 \brief The QPEApplication class implements various system services 443 \brief The QPEApplication class implements various system services
442 that are available to all Qtopia applications. 444 that are available to all Qtopia applications.
443 445
444 Simply by using QPEApplication instead of QApplication, a plain Qt 446 Simply by using QPEApplication instead of QApplication, a plain Qt
445 application becomes a Qtopia application. It automatically follows 447 application becomes a Qtopia application. It automatically follows
446 style changes, quits and raises, and in the 448 style changes, quits and raises, and in the
447 case of \link docwidget.html document-oriented\endlink applications, 449 case of \link docwidget.html document-oriented\endlink applications,
448 changes the current displayed document in response to the environment. 450 changes the current displayed document in response to the environment.
449*/ 451*/
450 452
451/*! 453/*!
452 \fn void QPEApplication::clientMoused() 454 \fn void QPEApplication::clientMoused()
453 455
454 \internal 456 \internal
455*/ 457*/
456 458
457/*! 459/*!
458 \fn void QPEApplication::timeChanged(); 460 \fn void QPEApplication::timeChanged();
459 461
460 This signal is emitted when the time jumps forward or backwards 462 This signal is emitted when the time jumps forward or backwards
461 by more than the normal passage of time. 463 by more than the normal passage of time.
462*/ 464*/
463 465
464/*! 466/*!
465 \fn void QPEApplication::clockChanged( bool ampm ); 467 \fn void QPEApplication::clockChanged( bool ampm );
466 468
467 This signal is emitted when the user changes the style 469 This signal is emitted when the user changes the style
468 of clock. If \a ampm is TRUE, the user wants a 12-hour 470 of clock. If \a ampm is TRUE, the user wants a 12-hour
469 AM/PM close, otherwise, they want a 24-hour clock. 471 AM/PM close, otherwise, they want a 24-hour clock.
470*/ 472*/
471 473
472/*! 474/*!
473 \fn void QPEApplication::appMessage( const QCString& msg, const QByteArray& data ) 475 \fn void QPEApplication::appMessage( const QCString& msg, const QByteArray& data )
474 476
475 This signal is emitted when a message is received on the 477 This signal is emitted when a message is received on the
476 QPE/Application/<i>appname</i> QCop channel for this application. 478 QPE/Application/<i>appname</i> QCop channel for this application.
477 479
478 The slot to which you connect this signal uses \a msg and \a data 480 The slot to which you connect this signal uses \a msg and \a data
479 in the following way: 481 in the following way:
480 482
481\code 483\code
482 void MyWidget::receive( const QCString& msg, const QByteArray& data ) 484 void MyWidget::receive( const QCString& msg, const QByteArray& data )
483 { 485 {
484 QDataStream stream( data, IO_ReadOnly ); 486 QDataStream stream( data, IO_ReadOnly );
485 if ( msg == "someMessage(int,int,int)" ) { 487 if ( msg == "someMessage(int,int,int)" ) {
486 int a,b,c; 488 int a,b,c;
487 stream >> a >> b >> c; 489 stream >> a >> b >> c;
488 ... 490 ...
489 } else if ( msg == "otherMessage(QString)" ) { 491 } else if ( msg == "otherMessage(QString)" ) {
490 ... 492 ...
491 } 493 }
492 } 494 }
493\endcode 495\endcode
494 496
495 \sa qcop.html 497 \sa qcop.html
496*/ 498*/
497 499
498/*! 500/*!
499 Constructs a QPEApplication just as you would construct 501 Constructs a QPEApplication just as you would construct
500 a QApplication, passing \a argc, \a argv, and \a t. 502 a QApplication, passing \a argc, \a argv, and \a t.
501*/ 503*/
502QPEApplication::QPEApplication( int& argc, char **argv, Type t ) 504QPEApplication::QPEApplication( int& argc, char **argv, Type t )
503 : QApplication( hack(argc), argv, t ) 505 : QApplication( hack(argc), argv, t )
504{ 506{
505 int dw = desktop()->width(); 507 int dw = desktop()->width();
506 if ( dw < 200 ) { 508 if ( dw < 200 ) {
507 setFont( QFont( "helvetica", 8 ) ); 509// setFont( QFont( "helvetica", 8 ) );
508 AppLnk::setSmallIconSize(10); 510 AppLnk::setSmallIconSize(10);
509 AppLnk::setBigIconSize(28); 511 AppLnk::setBigIconSize(28);
510 } 512 }
511 513
512 d = new QPEApplicationData; 514 d = new QPEApplicationData;
513 QMimeSourceFactory::setDefaultFactory(new ResourceMimeFactory); 515 QMimeSourceFactory::setDefaultFactory(new ResourceMimeFactory);
514 516
515 connect(this, SIGNAL(lastWindowClosed()), this, SLOT(hideOrQuit())); 517 connect(this, SIGNAL(lastWindowClosed()), this, SLOT(hideOrQuit()));
516#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 518#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
517 519
518 QString qcopfn("/tmp/qcop-msg-"); 520 QString qcopfn("/tmp/qcop-msg-");
519 qcopfn += QString(argv[0]); // append command name 521 qcopfn += QString(argv[0]); // append command name
520 522
521 QFile f(qcopfn); 523 QFile f(qcopfn);
522 if ( f.open(IO_ReadOnly) ) { 524 if ( f.open(IO_ReadOnly) ) {
523 flock(f.handle(), LOCK_EX); 525 flock(f.handle(), LOCK_EX);
524 } 526 }
525 527
526 sysChannel = new QCopChannel( "QPE/System", this ); 528 sysChannel = new QCopChannel( "QPE/System", this );
527 connect( sysChannel, SIGNAL(received(const QCString &, const QByteArray &)), 529 connect( sysChannel, SIGNAL(received(const QCString &, const QByteArray &)),
528 this, SLOT(systemMessage( const QCString &, const QByteArray &)) ); 530 this, SLOT(systemMessage( const QCString &, const QByteArray &)) );
529 531
530 QCString channel = QCString(argv[0]); 532 QCString channel = QCString(argv[0]);
531 channel.replace(QRegExp(".*/"),""); 533 channel.replace(QRegExp(".*/"),"");
532 d->appName = channel; 534 d->appName = channel;
533 channel = "QPE/Application/" + channel; 535 channel = "QPE/Application/" + channel;
534 pidChannel = new QCopChannel( channel, this); 536 pidChannel = new QCopChannel( channel, this);
535 connect( pidChannel, SIGNAL(received(const QCString &, const QByteArray &)), 537 connect( pidChannel, SIGNAL(received(const QCString &, const QByteArray &)),
536 this, SLOT(pidMessage(const QCString &, const QByteArray &))); 538 this, SLOT(pidMessage(const QCString &, const QByteArray &)));
537 539
538 if ( f.isOpen() ) { 540 if ( f.isOpen() ) {
539 d->keep_running = FALSE; 541 d->keep_running = FALSE;
540 QDataStream ds(&f); 542 QDataStream ds(&f);
541 QCString channel, message; 543 QCString channel, message;
542 QByteArray data; 544 QByteArray data;
543 while(!ds.atEnd()) { 545 while(!ds.atEnd()) {
544 ds >> channel >> message >> data; 546 ds >> channel >> message >> data;
545 d->enqueueQCop(channel,message,data); 547 d->enqueueQCop(channel,message,data);
546 } 548 }
547 549
548 flock(f.handle(), LOCK_UN); 550 flock(f.handle(), LOCK_UN);
549 f.close(); 551 f.close();
550 f.remove(); 552 f.remove();
551 } 553 }
552 554
553 for (int a=0; a<argc; a++) { 555 for (int a=0; a<argc; a++) {
554 if ( qstrcmp(argv[a],"-preload")==0 ) { 556 if ( qstrcmp(argv[a],"-preload")==0 ) {
555 argv[a] = argv[a+1]; 557 argv[a] = argv[a+1];
556 a++; 558 a++;
557 d->preloaded = TRUE; 559 d->preloaded = TRUE;
558 argc-=1; 560 argc-=1;
559 } else if ( qstrcmp(argv[a],"-preload-show")==0 ) { 561 } else if ( qstrcmp(argv[a],"-preload-show")==0 ) {
560 argv[a] = argv[a+1]; 562 argv[a] = argv[a+1];
561 a++; 563 a++;
562 d->preloaded = TRUE; 564 d->preloaded = TRUE;
563 d->forceshow = TRUE; 565 d->forceshow = TRUE;
564 argc-=1; 566 argc-=1;
565 } 567 }
566 } 568 }
567 569
568 /* overide stored arguments */ 570 /* overide stored arguments */
569 setArgs(argc, argv); 571 setArgs(argc, argv);
570 572
571#endif 573#endif
572 574
573 qwsSetDecoration( new QPEDecoration() ); 575 qwsSetDecoration( new QPEDecoration() );
574 576
575#ifndef QT_NO_TRANSLATION 577#ifndef QT_NO_TRANSLATION
576 QStringList langs = Global::languageList(); 578 QStringList langs = Global::languageList();
577 for (QStringList::ConstIterator it = langs.begin(); it!=langs.end(); ++it) { 579 for (QStringList::ConstIterator it = langs.begin(); it!=langs.end(); ++it) {
578 QString lang = *it; 580 QString lang = *it;
579 581
580 QTranslator * trans; 582 QTranslator * trans;
581 QString tfn; 583 QString tfn;
582 584
583 trans = new QTranslator(this); 585 trans = new QTranslator(this);
584 tfn = qpeDir()+"/i18n/"+lang+"/libqpe.qm"; 586 tfn = qpeDir()+"/i18n/"+lang+"/libqpe.qm";
585 if ( trans->load( tfn )) 587 if ( trans->load( tfn ))
586 installTranslator( trans ); 588 installTranslator( trans );
587 else 589 else
588 delete trans; 590 delete trans;
589 591
590 trans = new QTranslator(this); 592 trans = new QTranslator(this);
591 tfn = qpeDir()+"/i18n/"+lang+"/"+d->appName+".qm"; 593 tfn = qpeDir()+"/i18n/"+lang+"/"+d->appName+".qm";
592 if ( trans->load( tfn )) 594 if ( trans->load( tfn ))
593 installTranslator( trans ); 595 installTranslator( trans );
594 else 596 else
595 delete trans; 597 delete trans;
596 598
597 //###language/font hack; should look it up somewhere 599 //###language/font hack; should look it up somewhere
598 if ( lang == "ja" || lang == "zh_CN" || lang == "zh_TW" || lang == "ko" ) { 600 if ( lang == "ja" || lang == "zh_CN" || lang == "zh_TW" || lang == "ko" ) {
599 QFont fn = FontManager::unicodeFont( FontManager::Proportional ); 601 QFont fn = FontManager::unicodeFont( FontManager::Proportional );
600 setFont( fn ); 602 setFont( fn );
601 } 603 }
604 else {
605 Config config( "qpe" );
606 config.setGroup( "Appearance" );
607 QString familyStr = config.readEntry( "FontFamily", "fixed" );
608 QString styleStr = config.readEntry( "FontStyle", "Regular" );
609 QString sizeStr = config.readEntry( "FontSize", "10" );
610 QString charSetStr = config.readEntry( "FontCharSet", "iso10646-1" );
611 bool ok;
612 int i_size = sizeStr.toInt( &ok, 10 );
613 FontDatabase fdb;
614 QFont selectedFont = fdb.font( familyStr, styleStr, i_size, charSetStr );
615 setFont( selectedFont );
616 }
602 } 617 }
618
603#endif 619#endif
604 620
605 applyStyle(); 621 applyStyle();
606 622
607 if ( type() == GuiServer ) { 623 if ( type() == GuiServer ) {
608 setScreenSaverInterval(-1); 624 setScreenSaverInterval(-1);
609 setVolume(); 625 setVolume();
610 QWSServer::setScreenSaver(new QPEScreenSaver); 626 QWSServer::setScreenSaver(new QPEScreenSaver);
611 } 627 }
612 628
613 installEventFilter( this ); 629 installEventFilter( this );
614 630
615 QPEMenuToolFocusManager::initialize(); 631 QPEMenuToolFocusManager::initialize();
616 632
617#ifdef QT_NO_QWS_CURSOR 633#ifdef QT_NO_QWS_CURSOR
618 // if we have no cursor, probably don't want tooltips 634 // if we have no cursor, probably don't want tooltips
619 QToolTip::setEnabled( FALSE ); 635 QToolTip::setEnabled( FALSE );
620#endif 636#endif
621} 637}
622 638
623static QPtrDict<void>* inputMethodDict=0; 639static QPtrDict<void>* inputMethodDict=0;
624static void createInputMethodDict() 640static void createInputMethodDict()
625{ 641{
626 if ( !inputMethodDict ) 642 if ( !inputMethodDict )
627 inputMethodDict = new QPtrDict<void>; 643 inputMethodDict = new QPtrDict<void>;
628} 644}
629 645
630/*! 646/*!
631 Returns the currently set hint to the system as to whether 647 Returns the currently set hint to the system as to whether
632 \a w has any use for text input methods. 648 \a w has any use for text input methods.
633 649
634 \sa setInputMethodHint() 650 \sa setInputMethodHint()
635*/ 651*/
636QPEApplication::InputMethodHint QPEApplication::inputMethodHint( QWidget* w ) 652QPEApplication::InputMethodHint QPEApplication::inputMethodHint( QWidget* w )
637{ 653{
638 if ( inputMethodDict && w ) 654 if ( inputMethodDict && w )
639 return (InputMethodHint)(int)inputMethodDict->find(w); 655 return (InputMethodHint)(int)inputMethodDict->find(w);
640 return Normal; 656 return Normal;
641} 657}
642 658
643/*! 659/*!
644 \enum QPEApplication::InputMethodHint 660 \enum QPEApplication::InputMethodHint
645 661
646 \value Normal the application sometimes needs text input (the default). 662 \value Normal the application sometimes needs text input (the default).
647 \value AlwaysOff the application never needs text input. 663 \value AlwaysOff the application never needs text input.
648 \value AlwaysOn the application always needs text input. 664 \value AlwaysOn the application always needs text input.
649*/ 665*/
650 666
651/*! 667/*!
652 Hints to the system that \a w has use for text input methods 668 Hints to the system that \a w has use for text input methods
653 as specified by \a mode. 669 as specified by \a mode.
654 670
655 \sa inputMethodHint() 671 \sa inputMethodHint()
656*/ 672*/
657void QPEApplication::setInputMethodHint( QWidget* w, InputMethodHint mode ) 673void QPEApplication::setInputMethodHint( QWidget* w, InputMethodHint mode )
658{ 674{
659 createInputMethodDict(); 675 createInputMethodDict();
660 if ( mode == Normal ) { 676 if ( mode == Normal ) {
661 inputMethodDict->remove(w); 677 inputMethodDict->remove(w);
662 } else { 678 } else {
663 inputMethodDict->insert(w,(void*)mode); 679 inputMethodDict->insert(w,(void*)mode);
664 } 680 }
665} 681}
666 682
667class HackDialog : public QDialog 683class HackDialog : public QDialog
668{ 684{
669public: 685public:
670 void acceptIt() { accept(); } 686 void acceptIt() { accept(); }
671 void rejectIt() { reject(); } 687 void rejectIt() { reject(); }
672}; 688};
673 689
674 690
675void QPEApplication::mapToDefaultAction( QWSKeyEvent *ke, int key ) 691void QPEApplication::mapToDefaultAction( QWSKeyEvent *ke, int key )
676{ 692{
677 // specialised actions for certain widgets. May want to 693 // specialised actions for certain widgets. May want to
678 // add more stuff here. 694 // add more stuff here.
679 if ( activePopupWidget() && activePopupWidget()->inherits( "QListBox" ) 695 if ( activePopupWidget() && activePopupWidget()->inherits( "QListBox" )
680 && activePopupWidget()->parentWidget() 696 && activePopupWidget()->parentWidget()
681 && activePopupWidget()->parentWidget()->inherits( "QComboBox" ) ) 697 && activePopupWidget()->parentWidget()->inherits( "QComboBox" ) )
682 key = Qt::Key_Return; 698 key = Qt::Key_Return;
683 699
684 if ( activePopupWidget() && activePopupWidget()->inherits( "QPopupMenu" ) ) 700 if ( activePopupWidget() && activePopupWidget()->inherits( "QPopupMenu" ) )
685 key = Qt::Key_Return; 701 key = Qt::Key_Return;
686 702
687 ke->simpleData.keycode = key; 703 ke->simpleData.keycode = key;
688} 704}
689 705
690class HackWidget : public QWidget 706class HackWidget : public QWidget
691{ 707{
692public: 708public:
693 bool needsOk() 709 bool needsOk()
694 { return (getWState() & WState_Reserved1 ); } 710 { return (getWState() & WState_Reserved1 ); }
695}; 711};
696 712
697/*! 713/*!
698 \internal 714 \internal
699*/ 715*/
700bool QPEApplication::qwsEventFilter( QWSEvent *e ) 716bool QPEApplication::qwsEventFilter( QWSEvent *e )
701{ 717{
702 if ( !d->notbusysent && e->type == QWSEvent::Focus ) { 718 if ( !d->notbusysent && e->type == QWSEvent::Focus ) {
703 if ( qApp->type() != QApplication::GuiServer ) { 719 if ( qApp->type() != QApplication::GuiServer ) {
704 QCopEnvelope e("QPE/System", "notBusy(QString)" ); 720 QCopEnvelope e("QPE/System", "notBusy(QString)" );
705 e << d->appName; 721 e << d->appName;
706 } 722 }
707 d->notbusysent=TRUE; 723 d->notbusysent=TRUE;
708 } 724 }
709 if ( type() == GuiServer ) { 725 if ( type() == GuiServer ) {
710 switch ( e->type ) { 726 switch ( e->type ) {
711 case QWSEvent::Mouse: 727 case QWSEvent::Mouse:
712 if ( e->asMouse()->simpleData.state && !QWidget::find(e->window()) ) 728 if ( e->asMouse()->simpleData.state && !QWidget::find(e->window()) )
713 emit clientMoused(); 729 emit clientMoused();
714 } 730 }
715 } 731 }
716 if ( e->type == QWSEvent::Key ) { 732 if ( e->type == QWSEvent::Key ) {
717 if ( d->kbgrabber == 1 ) 733 if ( d->kbgrabber == 1 )
718 return TRUE; 734 return TRUE;
719 QWSKeyEvent *ke = (QWSKeyEvent *)e; 735 QWSKeyEvent *ke = (QWSKeyEvent *)e;
720 if ( ke->simpleData.keycode == Qt::Key_F33 ) { 736 if ( ke->simpleData.keycode == Qt::Key_F33 ) {
721 // Use special "OK" key to press "OK" on top level widgets 737 // Use special "OK" key to press "OK" on top level widgets
722 QWidget *active = activeWindow(); 738 QWidget *active = activeWindow();
723 QWidget *popup = 0; 739 QWidget *popup = 0;
724 if ( active && active->isPopup() ) { 740 if ( active && active->isPopup() ) {
725 popup = active; 741 popup = active;
726 active = active->parentWidget(); 742 active = active->parentWidget();
727 } 743 }
728 if ( active && (int)active->winId() == ke->simpleData.window && 744 if ( active && (int)active->winId() == ke->simpleData.window &&
729 !active->testWFlags( WStyle_Customize|WType_Popup|WType_Desktop )) { 745 !active->testWFlags( WStyle_Customize|WType_Popup|WType_Desktop )) {
730 if ( ke->simpleData.is_press ) { 746 if ( ke->simpleData.is_press ) {
731 if ( popup ) 747 if ( popup )
732 popup->close(); 748 popup->close();
733 if ( active->inherits( "QDialog" ) ) { 749 if ( active->inherits( "QDialog" ) ) {
734 HackDialog *d = (HackDialog *)active; 750 HackDialog *d = (HackDialog *)active;
735 d->acceptIt(); 751 d->acceptIt();
736 return TRUE; 752 return TRUE;
737 } else if ( ((HackWidget *)active)->needsOk() ) { 753 } else if ( ((HackWidget *)active)->needsOk() ) {
738 QSignal s; 754 QSignal s;
739 s.connect( active, SLOT( accept() ) ); 755 s.connect( active, SLOT( accept() ) );
740 s.activate(); 756 s.activate();
741 } else { 757 } else {
742 // do the same as with the select key: Map to the default action of the widget: 758 // do the same as with the select key: Map to the default action of the widget:
743 mapToDefaultAction( ke, Qt::Key_Return ); 759 mapToDefaultAction( ke, Qt::Key_Return );
744 } 760 }
745 } 761 }
746 } 762 }
747 } else if ( ke->simpleData.keycode == Qt::Key_F30 ) { 763 } else if ( ke->simpleData.keycode == Qt::Key_F30 ) {
748 // Use special "select" key to do whatever default action a widget has 764 // Use special "select" key to do whatever default action a widget has
749 mapToDefaultAction( ke, Qt::Key_Space ); 765 mapToDefaultAction( ke, Qt::Key_Space );
750 } else if ( ke->simpleData.keycode == Qt::Key_Escape && 766 } else if ( ke->simpleData.keycode == Qt::Key_Escape &&
751 ke->simpleData.is_press ) { 767 ke->simpleData.is_press ) {
752 // Escape key closes app if focus on toplevel 768 // Escape key closes app if focus on toplevel
753 QWidget *active = activeWindow(); 769 QWidget *active = activeWindow();
754 if ( active && active->testWFlags( WType_TopLevel ) && 770 if ( active && active->testWFlags( WType_TopLevel ) &&
755 (int)active->winId() == ke->simpleData.window && 771 (int)active->winId() == ke->simpleData.window &&
756 !active->testWFlags( WStyle_Dialog|WStyle_Customize|WType_Popup|WType_Desktop )) { 772 !active->testWFlags( WStyle_Dialog|WStyle_Customize|WType_Popup|WType_Desktop )) {
757 if ( active->inherits( "QDialog" ) ) { 773 if ( active->inherits( "QDialog" ) ) {
758 HackDialog *d = (HackDialog *)active; 774 HackDialog *d = (HackDialog *)active;
759 d->rejectIt(); 775 d->rejectIt();
760 return TRUE; 776 return TRUE;
761 } else if ( strcmp( argv()[0], "embeddedkonsole") != 0 ) { 777 } else if ( strcmp( argv()[0], "embeddedkonsole") != 0 ) {
762 active->close(); 778 active->close();
763 } 779 }
764 } 780 }
765 } 781 }
766 782
767#if QT_VERSION < 231 783#if QT_VERSION < 231
768 // Filter out the F4/Launcher key from apps 784 // Filter out the F4/Launcher key from apps
769 // ### The launcher key may not always be F4 on all devices 785 // ### The launcher key may not always be F4 on all devices
770 if ( ((QWSKeyEvent *)e)->simpleData.keycode == Qt::Key_F4 ) 786 if ( ((QWSKeyEvent *)e)->simpleData.keycode == Qt::Key_F4 )
771 return TRUE; 787 return TRUE;
772#endif 788#endif
773 } 789 }
774 if ( e->type == QWSEvent::Focus ) { 790 if ( e->type == QWSEvent::Focus ) {
775 QWSFocusEvent *fe = (QWSFocusEvent*)e; 791 QWSFocusEvent *fe = (QWSFocusEvent*)e;
776 QWidget* nfw = QWidget::find(e->window()); 792 QWidget* nfw = QWidget::find(e->window());
777 if ( !fe->simpleData.get_focus ) { 793 if ( !fe->simpleData.get_focus ) {
778 QWidget *active = activeWindow(); 794 QWidget *active = activeWindow();
779 while ( active && active->isPopup() ) { 795 while ( active && active->isPopup() ) {
780 active->close(); 796 active->close();
781 active = activeWindow(); 797 active = activeWindow();
782 } 798 }
783 if ( !nfw && d->kbgrabber == 2 ) { 799 if ( !nfw && d->kbgrabber == 2 ) {
784 ungrabKeyboard(); 800 ungrabKeyboard();
785 d->kbregrab = TRUE; // want kb back when we're active 801 d->kbregrab = TRUE; // want kb back when we're active
786 } 802 }
787 } else { 803 } else {
788 // make sure our modal widget is ALWAYS on top 804 // make sure our modal widget is ALWAYS on top
789 QWidget *topm = activeModalWidget(); 805 QWidget *topm = activeModalWidget();
790 if ( topm ) { 806 if ( topm ) {
791 topm->raise(); 807 topm->raise();
792 } 808 }
793 if ( d->kbregrab ) { 809 if ( d->kbregrab ) {
794 grabKeyboard(); 810 grabKeyboard();
795 d->kbregrab = FALSE; 811 d->kbregrab = FALSE;
796 } 812 }
797 } 813 }
798 if ( fe->simpleData.get_focus && inputMethodDict ) { 814 if ( fe->simpleData.get_focus && inputMethodDict ) {
799 InputMethodHint m = inputMethodHint( QWidget::find(e->window()) ); 815 InputMethodHint m = inputMethodHint( QWidget::find(e->window()) );
800 if ( m == AlwaysOff ) 816 if ( m == AlwaysOff )
801 Global::hideInputMethod(); 817 Global::hideInputMethod();
802 if ( m == AlwaysOn ) 818 if ( m == AlwaysOn )
803 Global::showInputMethod(); 819 Global::showInputMethod();
804 } 820 }
805 } 821 }
806 return QApplication::qwsEventFilter( e ); 822 return QApplication::qwsEventFilter( e );
807} 823}
808 824
809/*! 825/*!
810 Destroys the QPEApplication. 826 Destroys the QPEApplication.
811*/ 827*/
812QPEApplication::~QPEApplication() 828QPEApplication::~QPEApplication()
813{ 829{
814 ungrabKeyboard(); 830 ungrabKeyboard();
815#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 831#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
816 // Need to delete QCopChannels early, since the display will 832 // Need to delete QCopChannels early, since the display will
817 // be gone by the time we get to ~QObject(). 833 // be gone by the time we get to ~QObject().
818 delete sysChannel; 834 delete sysChannel;
819 delete pidChannel; 835 delete pidChannel;
820#endif 836#endif
821 delete d; 837 delete d;
822} 838}
823 839
824/*! 840/*!
825 Returns <tt>$OPIEDIR/</tt>. 841 Returns <tt>$OPIEDIR/</tt>.
826*/ 842*/
827QString QPEApplication::qpeDir() 843QString QPEApplication::qpeDir()
828{ 844{
829 const char *base = getenv( "OPIEDIR" ); 845 const char *base = getenv( "OPIEDIR" );
830 if ( base ) 846 if ( base )
831 return QString( base ) + "/"; 847 return QString( base ) + "/";
832 848
833 return QString( "../" ); 849 return QString( "../" );
834} 850}
835 851
836/*! 852/*!
837 Returns the user's current Document directory. There is a trailing "/". 853 Returns the user's current Document directory. There is a trailing "/".
838*/ 854*/
839QString QPEApplication::documentDir() 855QString QPEApplication::documentDir()
840{ 856{
841 const char *base = getenv( "HOME" ); 857 const char *base = getenv( "HOME" );
842 if ( base ) 858 if ( base )
843 return QString( base ) + "/Documents/"; 859 return QString( base ) + "/Documents/";
844 860
845 return QString( "../Documents/" ); 861 return QString( "../Documents/" );
846} 862}
847 863
848static int deforient=-1; 864static int deforient=-1;
849 865
850/*! 866/*!
851 \internal 867 \internal
852*/ 868*/
853int QPEApplication::defaultRotation() 869int QPEApplication::defaultRotation()
854{ 870{
855 if ( deforient < 0 ) { 871 if ( deforient < 0 ) {
856 QString d = getenv("QWS_DISPLAY"); 872 QString d = getenv("QWS_DISPLAY");
857 if ( d.contains("Rot90") ) { 873 if ( d.contains("Rot90") ) {
858 deforient = 90; 874 deforient = 90;
859 } else if ( d.contains("Rot180") ) { 875 } else if ( d.contains("Rot180") ) {
860 deforient = 180; 876 deforient = 180;
861 } else if ( d.contains("Rot270") ) { 877 } else if ( d.contains("Rot270") ) {
862 deforient = 270; 878 deforient = 270;
863 } else { 879 } else {
864 deforient=0; 880 deforient=0;
865 } 881 }
866 } 882 }
867 return deforient; 883 return deforient;
868} 884}
869 885
870/*! 886/*!
871 \internal 887 \internal
872*/ 888*/
873void QPEApplication::setDefaultRotation(int r) 889void QPEApplication::setDefaultRotation(int r)
874{ 890{
875 if ( qApp->type() == GuiServer ) { 891 if ( qApp->type() == GuiServer ) {
876 deforient = r; 892 deforient = r;
877 setenv("QWS_DISPLAY", QString("Transformed:Rot%1:0").arg(r).latin1(), 1); 893 setenv("QWS_DISPLAY", QString("Transformed:Rot%1:0").arg(r).latin1(), 1);
878 } else { 894 } else {
879 QCopEnvelope("QPE/System", "setDefaultRotation(int)") << r; 895 QCopEnvelope("QPE/System", "setDefaultRotation(int)") << r;
880 } 896 }
881} 897}
882 898
883/*! 899/*!
884 \internal 900 \internal
885*/ 901*/
886void QPEApplication::applyStyle() 902void QPEApplication::applyStyle()
887{ 903{
888 Config config( "qpe" ); 904 Config config( "qpe" );
889 905
890 config.setGroup( "Appearance" ); 906 config.setGroup( "Appearance" );
891 907
892 // Widget style 908 // Widget style
893 QString style = config.readEntry( "Style", "Light" ); 909 QString style = config.readEntry( "Style", "Light" );
894 internalSetStyle( style ); 910 internalSetStyle( style );
895 911
896 // Colors 912 // Colors
897 QColor bgcolor( config.readEntry( "Background", "#E5E1D5" ) ); 913 QColor bgcolor( config.readEntry( "Background", "#E5E1D5" ) );
898 QColor btncolor( config.readEntry( "Button", "#D6CDBB" ) ); 914 QColor btncolor( config.readEntry( "Button", "#D6CDBB" ) );
899 QPalette pal( btncolor, bgcolor ); 915 QPalette pal( btncolor, bgcolor );
900 QString color = config.readEntry( "Highlight", "#800000" ); 916 QString color = config.readEntry( "Highlight", "#800000" );
901 pal.setColor( QColorGroup::Highlight, QColor(color) ); 917 pal.setColor( QColorGroup::Highlight, QColor(color) );
902 color = config.readEntry( "HighlightedText", "#FFFFFF" ); 918 color = config.readEntry( "HighlightedText", "#FFFFFF" );
903 pal.setColor( QColorGroup::HighlightedText, QColor(color) ); 919 pal.setColor( QColorGroup::HighlightedText, QColor(color) );
904 color = config.readEntry( "Text", "#000000" ); 920 color = config.readEntry( "Text", "#000000" );
905 pal.setColor( QColorGroup::Text, QColor(color) ); 921 pal.setColor( QColorGroup::Text, QColor(color) );
906 color = config.readEntry( "ButtonText", "#000000" ); 922 color = config.readEntry( "ButtonText", "#000000" );
907 pal.setColor( QPalette::Active, QColorGroup::ButtonText, QColor(color) ); 923 pal.setColor( QPalette::Active, QColorGroup::ButtonText, QColor(color) );
908 color = config.readEntry( "Base", "#FFFFFF" ); 924 color = config.readEntry( "Base", "#FFFFFF" );
909 pal.setColor( QColorGroup::Base, QColor(color) ); 925 pal.setColor( QColorGroup::Base, QColor(color) );
910 926
911 pal.setColor( QPalette::Disabled, QColorGroup::Text, 927 pal.setColor( QPalette::Disabled, QColorGroup::Text,
912 pal.color(QPalette::Active, QColorGroup::Background).dark() ); 928 pal.color(QPalette::Active, QColorGroup::Background).dark() );
913 929
914 setPalette( pal, TRUE ); 930 setPalette( pal, TRUE );
915} 931}
916 932
917void QPEApplication::systemMessage( const QCString &msg, const QByteArray &data) 933void QPEApplication::systemMessage( const QCString &msg, const QByteArray &data)
918{ 934{
919#ifdef Q_WS_QWS 935#ifdef Q_WS_QWS
920 QDataStream stream( data, IO_ReadOnly ); 936 QDataStream stream( data, IO_ReadOnly );
921 if ( msg == "applyStyle()" ) { 937 if ( msg == "applyStyle()" ) {
922 applyStyle(); 938 applyStyle();
923 } else if ( msg == "setScreenSaverInterval(int)" ) { 939 } else if ( msg == "setScreenSaverInterval(int)" ) {
924 if ( type() == GuiServer ) { 940 if ( type() == GuiServer ) {
925 int time; 941 int time;
926 stream >> time; 942 stream >> time;
927 setScreenSaverInterval(time); 943 setScreenSaverInterval(time);
928 } 944 }
929 } else if ( msg == "setScreenSaverIntervals(int,int,int)" ) { 945 } else if ( msg == "setScreenSaverIntervals(int,int,int)" ) {
930 if ( type() == GuiServer ) { 946 if ( type() == GuiServer ) {
931 int t1,t2,t3; 947 int t1,t2,t3;
932 stream >> t1 >> t2 >> t3; 948 stream >> t1 >> t2 >> t3;
933 setScreenSaverIntervals(t1,t2,t3); 949 setScreenSaverIntervals(t1,t2,t3);
934 } 950 }
935 } else if ( msg == "setBacklight(int)" ) { 951 } else if ( msg == "setBacklight(int)" ) {
936 if ( type() == GuiServer ) { 952 if ( type() == GuiServer ) {
937 int bright; 953 int bright;
938 stream >> bright; 954 stream >> bright;
939 setBacklight(bright); 955 setBacklight(bright);
940 } 956 }
941 } else if ( msg == "setDefaultRotation(int)" ) { 957 } else if ( msg == "setDefaultRotation(int)" ) {
942 if ( type() == GuiServer ) { 958 if ( type() == GuiServer ) {
943 int r; 959 int r;
944 stream >> r; 960 stream >> r;
945 setDefaultRotation(r); 961 setDefaultRotation(r);
946 } 962 }
947 } else if ( msg == "shutdown()" ) { 963 } else if ( msg == "shutdown()" ) {
948 if ( type() == GuiServer ) 964 if ( type() == GuiServer )
949 shutdown(); 965 shutdown();
950 } else if ( msg == "quit()" ) { 966 } else if ( msg == "quit()" ) {
951 if ( type() != GuiServer ) 967 if ( type() != GuiServer )
952 tryQuit(); 968 tryQuit();
953 } else if ( msg == "forceQuit()" ) { 969 } else if ( msg == "forceQuit()" ) {
954 if ( type() != GuiServer ) 970 if ( type() != GuiServer )
955 quit(); 971 quit();
956 } else if ( msg == "restart()" ) { 972 } else if ( msg == "restart()" ) {
957 if ( type() == GuiServer ) 973 if ( type() == GuiServer )
958 restart(); 974 restart();
959 } else if ( msg == "grabKeyboard(QString)" ) { 975 } else if ( msg == "grabKeyboard(QString)" ) {
960 QString who; 976 QString who;
961 stream >> who; 977 stream >> who;
962 if ( who.isEmpty() ) 978 if ( who.isEmpty() )
963 d->kbgrabber = 0; 979 d->kbgrabber = 0;
964 else if ( who != d->appName ) 980 else if ( who != d->appName )
965 d->kbgrabber = 1; 981 d->kbgrabber = 1;
966 else 982 else
967 d->kbgrabber = 2; 983 d->kbgrabber = 2;
968 } else if ( msg == "language(QString)" ) { 984 } else if ( msg == "language(QString)" ) {
969 if ( type() == GuiServer ) { 985 if ( type() == GuiServer ) {
970 QString l; 986 QString l;
971 stream >> l; 987 stream >> l;
972 QString cl = getenv("LANG"); 988 QString cl = getenv("LANG");
973 if ( cl != l ) { 989 if ( cl != l ) {
974 if ( l.isNull() ) 990 if ( l.isNull() )
975 unsetenv( "LANG" ); 991 unsetenv( "LANG" );
976 else 992 else
977 setenv( "LANG", l.latin1(), 1 ); 993 setenv( "LANG", l.latin1(), 1 );
978 restart(); 994 restart();
979 } 995 }
980 } 996 }
981 } else if ( msg == "timeChange(QString)" ) { 997 } else if ( msg == "timeChange(QString)" ) {
982 QString t; 998 QString t;
983 stream >> t; 999 stream >> t;
984 if ( t.isNull() ) 1000 if ( t.isNull() )
985 unsetenv( "TZ" ); 1001 unsetenv( "TZ" );
986 else 1002 else
987 setenv( "TZ", t.latin1(), 1 ); 1003 setenv( "TZ", t.latin1(), 1 );
988 // emit the signal so everyone else knows... 1004 // emit the signal so everyone else knows...
989 emit timeChanged(); 1005 emit timeChanged();
990 } else if ( msg == "execute(QString)" ) { 1006 } else if ( msg == "execute(QString)" ) {
991 if ( type() == GuiServer ) { 1007 if ( type() == GuiServer ) {
992 QString t; 1008 QString t;
993 stream >> t; 1009 stream >> t;
994 Global::execute( t ); 1010 Global::execute( t );
995 } 1011 }
996 } else if ( msg == "execute(QString,QString)" ) { 1012 } else if ( msg == "execute(QString,QString)" ) {
997 if ( type() == GuiServer ) { 1013 if ( type() == GuiServer ) {
998 QString t,d; 1014 QString t,d;
999 stream >> t >> d; 1015 stream >> t >> d;
1000 Global::execute( t, d ); 1016 Global::execute( t, d );
1001 } 1017 }
1002 } else if ( msg == "addAlarm(QDateTime,QCString,QCString,int)" ) { 1018 } else if ( msg == "addAlarm(QDateTime,QCString,QCString,int)" ) {
1003 if ( type() == GuiServer ) { 1019 if ( type() == GuiServer ) {
1004 QDateTime when; 1020 QDateTime when;
1005 QCString channel, message; 1021 QCString channel, message;
1006 int data; 1022 int data;
1007 stream >> when >> channel >> message >> data; 1023 stream >> when >> channel >> message >> data;
1008 AlarmServer::addAlarm( when, channel, message, data ); 1024 AlarmServer::addAlarm( when, channel, message, data );
1009 } 1025 }
1010 } else if ( msg == "deleteAlarm(QDateTime,QCString,QCString,int)" ) { 1026 } else if ( msg == "deleteAlarm(QDateTime,QCString,QCString,int)" ) {
1011 if ( type() == GuiServer ) { 1027 if ( type() == GuiServer ) {
1012 QDateTime when; 1028 QDateTime when;
1013 QCString channel, message; 1029 QCString channel, message;
1014 int data; 1030 int data;
1015 stream >> when >> channel >> message >> data; 1031 stream >> when >> channel >> message >> data;
1016 AlarmServer::deleteAlarm( when, channel, message, data ); 1032 AlarmServer::deleteAlarm( when, channel, message, data );
1017 } 1033 }
1018 } else if ( msg == "clockChange(bool)" ) { 1034 } else if ( msg == "clockChange(bool)" ) {
1019 int tmp; 1035 int tmp;
1020 stream >> tmp; 1036 stream >> tmp;
1021 emit clockChanged( tmp ); 1037 emit clockChanged( tmp );
1022 } else if ( msg == "weekChange(bool)" ) { 1038 } else if ( msg == "weekChange(bool)" ) {
1023 int tmp; 1039 int tmp;
1024 stream >> tmp; 1040 stream >> tmp;
1025 emit weekChanged( tmp ); 1041 emit weekChanged( tmp );
1026 } else if ( msg == "setDateFormat(DateFormat)" ) { 1042 } else if ( msg == "setDateFormat(DateFormat)" ) {
1027 DateFormat tmp; 1043 DateFormat tmp;
1028 stream >> tmp; 1044 stream >> tmp;
1029 emit dateFormatChanged( tmp ); 1045 emit dateFormatChanged( tmp );
1030 } else if ( msg == "setVolume(int,int)" ) { 1046 } else if ( msg == "setVolume(int,int)" ) {
1031 int t,v; 1047 int t,v;
1032 stream >> t >> v; 1048 stream >> t >> v;
1033 setVolume(t,v); 1049 setVolume(t,v);
1034 emit volumeChanged( muted ); 1050 emit volumeChanged( muted );
1035 } else if ( msg == "volumeChange(bool)" ) { 1051 } else if ( msg == "volumeChange(bool)" ) {
1036 stream >> muted; 1052 stream >> muted;
1037 setVolume(); 1053 setVolume();
1038 emit volumeChanged( muted ); 1054 emit volumeChanged( muted );
1039 } else if ( msg == "setMic(int,int)") { // Added: 2002-02-08 by Jeremy Cowgar <jc@cowgar.com> 1055 } else if ( msg == "setMic(int,int)") { // Added: 2002-02-08 by Jeremy Cowgar <jc@cowgar.com>
1040 int t,v; 1056 int t,v;
1041 stream >> t >> v; 1057 stream >> t >> v;
1042 setMic(t,v); 1058 setMic(t,v);
1043 emit micChanged( micMuted ); 1059 emit micChanged( micMuted );
1044 } else if ( msg == "micChange(bool)" ) { // Added: 2002-02-08 by Jeremy Cowgar <jc@cowgar.com> 1060 } else if ( msg == "micChange(bool)" ) { // Added: 2002-02-08 by Jeremy Cowgar <jc@cowgar.com>
1045 stream >> micMuted; 1061 stream >> micMuted;
1046 setMic(); 1062 setMic();
1047 emit micChanged( micMuted ); 1063 emit micChanged( micMuted );
1048 } else if ( msg == "setScreenSaverMode(int)" ) { 1064 } else if ( msg == "setScreenSaverMode(int)" ) {
1049 if ( type() == GuiServer ) { 1065 if ( type() == GuiServer ) {
1050 int old = disable_suspend; 1066 int old = disable_suspend;
1051 stream >> disable_suspend; 1067 stream >> disable_suspend;
1052 //qDebug("setScreenSaverMode(%d)", disable_suspend ); 1068 //qDebug("setScreenSaverMode(%d)", disable_suspend );
1053 if ( disable_suspend > old ) 1069 if ( disable_suspend > old )
1054 setScreenSaverInterval( -1 ); 1070 setScreenSaverInterval( -1 );
1055 } 1071 }
1056 } 1072 }
1057#endif 1073#endif
1058} 1074}
1059 1075
1060/*! 1076/*!
1061 \internal 1077 \internal
1062*/ 1078*/
1063bool QPEApplication::raiseAppropriateWindow() 1079bool QPEApplication::raiseAppropriateWindow()
1064{ 1080{
1065 bool r=FALSE; 1081 bool r=FALSE;
1066 // ########## raise()ing main window should raise and set active 1082 // ########## raise()ing main window should raise and set active
1067 // ########## it and then all childen. This belongs in Qt/Embedded 1083 // ########## it and then all childen. This belongs in Qt/Embedded
1068 QWidget *top = d->qpe_main_widget; 1084 QWidget *top = d->qpe_main_widget;
1069 if ( !top ) top =mainWidget(); 1085 if ( !top ) top =mainWidget();
1070 if ( top && d->keep_running ) { 1086 if ( top && d->keep_running ) {
1071 if ( top->isVisible() ) 1087 if ( top->isVisible() )
1072 r = TRUE; 1088 r = TRUE;
1073#ifdef Q_WS_QWS 1089#ifdef Q_WS_QWS
1074 if ( !d->nomaximize ) 1090 if ( !d->nomaximize )
1075 top->showMaximized(); 1091 top->showMaximized();
1076 else 1092 else
1077#endif 1093#endif
1078 top->show(); 1094 top->show();
1079 top->raise(); 1095 top->raise();
1080 top->setActiveWindow(); 1096 top->setActiveWindow();
1081 } 1097 }
1082 QWidget *topm = activeModalWidget(); 1098 QWidget *topm = activeModalWidget();
1083 if ( topm && topm != top ) { 1099 if ( topm && topm != top ) {
1084 topm->show(); 1100 topm->show();
1085 topm->raise(); 1101 topm->raise();
1086 topm->setActiveWindow(); 1102 topm->setActiveWindow();
1087 r = FALSE; 1103 r = FALSE;
1088 } 1104 }
1089 return r; 1105 return r;
1090} 1106}
1091 1107
1092void QPEApplication::pidMessage( const QCString &msg, const QByteArray & data) 1108void QPEApplication::pidMessage( const QCString &msg, const QByteArray & data)
1093{ 1109{
1094#ifdef Q_WS_QWS 1110#ifdef Q_WS_QWS
1095 1111
1096 if ( msg == "quit()" ) { 1112 if ( msg == "quit()" ) {
1097 tryQuit(); 1113 tryQuit();
1098 } else if ( msg == "quitIfInvisible()" ) { 1114 } else if ( msg == "quitIfInvisible()" ) {
1099 if ( d->qpe_main_widget && !d->qpe_main_widget->isVisible() ) 1115 if ( d->qpe_main_widget && !d->qpe_main_widget->isVisible() )
1100 quit(); 1116 quit();
1101 } else if ( msg == "close()" ) { 1117 } else if ( msg == "close()" ) {
1102 hideOrQuit(); 1118 hideOrQuit();
1103 } else if ( msg == "disablePreload()" ) { 1119 } else if ( msg == "disablePreload()" ) {
1104 d->preloaded = FALSE; 1120 d->preloaded = FALSE;
1105 d->keep_running = TRUE; 1121 d->keep_running = TRUE;
1106 /* so that quit will quit */ 1122 /* so that quit will quit */
1107 } else if ( msg == "enablePreload()" ) { 1123 } else if ( msg == "enablePreload()" ) {
1108 d->preloaded = TRUE; 1124 d->preloaded = TRUE;
1109 d->keep_running = TRUE; 1125 d->keep_running = TRUE;
1110 /* so next quit won't quit */ 1126 /* so next quit won't quit */
1111 } else if ( msg == "raise()" ) { 1127 } else if ( msg == "raise()" ) {
1112 d->keep_running = TRUE; 1128 d->keep_running = TRUE;
1113 d->notbusysent = FALSE; 1129 d->notbusysent = FALSE;
1114 raiseAppropriateWindow(); 1130 raiseAppropriateWindow();
1115 } else if ( msg == "flush()" ) { 1131 } else if ( msg == "flush()" ) {
1116 emit flush(); 1132 emit flush();
1117 // we need to tell the desktop 1133 // we need to tell the desktop
1118 QCopEnvelope e( "QPE/Desktop", "flushDone(QString)" ); 1134 QCopEnvelope e( "QPE/Desktop", "flushDone(QString)" );
1119 e << d->appName; 1135 e << d->appName;
1120 } else if ( msg == "reload()" ) { 1136 } else if ( msg == "reload()" ) {
1121 emit reload(); 1137 emit reload();
1122 } else if ( msg == "setDocument(QString)" ) { 1138 } else if ( msg == "setDocument(QString)" ) {
1123 d->keep_running = TRUE; 1139 d->keep_running = TRUE;
1124 QDataStream stream( data, IO_ReadOnly ); 1140 QDataStream stream( data, IO_ReadOnly );
1125 QString doc; 1141 QString doc;
1126 stream >> doc; 1142 stream >> doc;
1127 QWidget *mw = mainWidget(); 1143 QWidget *mw = mainWidget();
1128 if ( !mw ) 1144 if ( !mw )
1129 mw = d->qpe_main_widget; 1145 mw = d->qpe_main_widget;
1130 if ( mw ) 1146 if ( mw )
1131 Global::setDocument( mw, doc ); 1147 Global::setDocument( mw, doc );
1132 } else if ( msg == "nextView()" ) { 1148 } else if ( msg == "nextView()" ) {
1133 if ( raiseAppropriateWindow() ) 1149 if ( raiseAppropriateWindow() )
1134 emit appMessage( msg, data); 1150 emit appMessage( msg, data);
1135 } else { 1151 } else {
1136 emit appMessage( msg, data); 1152 emit appMessage( msg, data);
1137 } 1153 }
1138#endif 1154#endif
1139} 1155}
1140 1156
1141 1157
1142static bool setWidgetCaptionFromAppName( QWidget* /*mw*/, const QString& /*appName*/, const QString& /*appsPath*/ ) 1158static bool setWidgetCaptionFromAppName( QWidget* /*mw*/, const QString& /*appName*/, const QString& /*appsPath*/ )
1143{ 1159{
1144/* 1160/*
1145 // This works but disable it for now until it is safe to apply 1161 // This works but disable it for now until it is safe to apply
1146 // What is does is scan the .desktop files of all the apps for 1162 // What is does is scan the .desktop files of all the apps for
1147 // the applnk that has the corresponding argv[0] as this program 1163 // the applnk that has the corresponding argv[0] as this program
1148 // then it uses the name stored in the .desktop file as the caption 1164 // then it uses the name stored in the .desktop file as the caption
1149 // for the main widget. This saves duplicating translations for 1165 // for the main widget. This saves duplicating translations for
1150 // the app name in the program and in the .desktop files. 1166 // the app name in the program and in the .desktop files.
1151 1167
1152 AppLnkSet apps( appsPath ); 1168 AppLnkSet apps( appsPath );
1153 1169
1154 QList<AppLnk> appsList = apps.children(); 1170 QList<AppLnk> appsList = apps.children();
1155 for ( QListIterator<AppLnk> it(appsList); it.current(); ++it ) { 1171 for ( QListIterator<AppLnk> it(appsList); it.current(); ++it ) {
1156 if ( (*it)->exec() == appName ) { 1172 if ( (*it)->exec() == appName ) {
1157 mw->setCaption( (*it)->name() ); 1173 mw->setCaption( (*it)->name() );
1158 return TRUE; 1174 return TRUE;
1159 } 1175 }
1160 } 1176 }
1161*/ 1177*/
1162 return FALSE; 1178 return FALSE;
1163} 1179}
1164 1180
1165 1181
1166/*! 1182/*!
1167 Sets \a mw as the mainWidget() and shows it. For small windows, 1183 Sets \a mw as the mainWidget() and shows it. For small windows,
1168 consider passing TRUE for \a nomaximize rather than the default FALSE. 1184 consider passing TRUE for \a nomaximize rather than the default FALSE.
1169 1185
1170 \sa showMainDocumentWidget() 1186 \sa showMainDocumentWidget()
1171*/ 1187*/
1172void QPEApplication::showMainWidget( QWidget* mw, bool nomaximize ) 1188void QPEApplication::showMainWidget( QWidget* mw, bool nomaximize )
1173{ 1189{
1174 setWidgetCaptionFromAppName( mw, d->appName, qpeDir() + "apps" ); 1190 setWidgetCaptionFromAppName( mw, d->appName, qpeDir() + "apps" );
1175 1191
1176 d->nomaximize = nomaximize; 1192 d->nomaximize = nomaximize;
1177 d->qpe_main_widget = mw; 1193 d->qpe_main_widget = mw;
1178 d->sendQCopQ(); 1194 d->sendQCopQ();
1179 if ( d->preloaded ) { 1195 if ( d->preloaded ) {
1180 if(d->forceshow) { 1196 if(d->forceshow) {
1181#ifdef Q_WS_QWS 1197#ifdef Q_WS_QWS
1182 if ( !nomaximize ) 1198 if ( !nomaximize )
1183 mw->showMaximized(); 1199 mw->showMaximized();
1184 else 1200 else
1185#endif 1201#endif
1186 mw->show(); 1202 mw->show();
1187 } 1203 }
1188 } else if ( d->keep_running ) { 1204 } else if ( d->keep_running ) {
1189#ifdef Q_WS_QWS 1205#ifdef Q_WS_QWS
1190 if ( !nomaximize ) 1206 if ( !nomaximize )
1191 mw->showMaximized(); 1207 mw->showMaximized();
1192 else 1208 else
1193#endif 1209#endif
1194 mw->show(); 1210 mw->show();
1195 } 1211 }
1196} 1212}
1197 1213
1198/*! 1214/*!
1199 Sets \a mw as the mainWidget() and shows it. For small windows, 1215 Sets \a mw as the mainWidget() and shows it. For small windows,
1200 consider passing TRUE for \a nomaximize rather than the default FALSE. 1216 consider passing TRUE for \a nomaximize rather than the default FALSE.
1201 1217
1202 This calls designates the application as 1218 This calls designates the application as
1203 a \link docwidget.html document-oriented\endlink application. 1219 a \link docwidget.html document-oriented\endlink application.
1204 1220
1205 The \a mw widget must have a slot: setDocument(const QString&). 1221 The \a mw widget must have a slot: setDocument(const QString&).
1206 1222
1207 \sa showMainWidget() 1223 \sa showMainWidget()
1208*/ 1224*/
1209void QPEApplication::showMainDocumentWidget( QWidget* mw, bool nomaximize ) 1225void QPEApplication::showMainDocumentWidget( QWidget* mw, bool nomaximize )
1210{ 1226{
1211 setWidgetCaptionFromAppName( mw, d->appName, qpeDir() + "apps" ); 1227 setWidgetCaptionFromAppName( mw, d->appName, qpeDir() + "apps" );
1212 1228
1213 if ( mw && argc() == 2 ) 1229 if ( mw && argc() == 2 )
1214 Global::setDocument( mw, QString::fromUtf8(argv()[1]) ); 1230 Global::setDocument( mw, QString::fromUtf8(argv()[1]) );
1215 d->nomaximize = nomaximize; 1231 d->nomaximize = nomaximize;
1216 d->qpe_main_widget = mw; 1232 d->qpe_main_widget = mw;
1217 d->sendQCopQ(); 1233 d->sendQCopQ();
1218 if ( d->preloaded ) { 1234 if ( d->preloaded ) {
1219 if(d->forceshow) { 1235 if(d->forceshow) {
1220#ifdef Q_WS_QWS 1236#ifdef Q_WS_QWS
1221 if ( !nomaximize ) 1237 if ( !nomaximize )
1222 mw->showMaximized(); 1238 mw->showMaximized();
1223 else 1239 else
1224#endif 1240#endif
1225 mw->show(); 1241 mw->show();
1226 } 1242 }
1227 } else if ( d->keep_running ) { 1243 } else if ( d->keep_running ) {
1228#ifdef Q_WS_QWS 1244#ifdef Q_WS_QWS
1229 if ( !nomaximize ) 1245 if ( !nomaximize )
1230 mw->showMaximized(); 1246 mw->showMaximized();
1231 else 1247 else
1232#endif 1248#endif
1233 mw->show(); 1249 mw->show();
1234 } 1250 }
1235} 1251}
1236 1252
1237 1253
1238/*! 1254/*!
1239 Sets that the application should continue running after processing 1255 Sets that the application should continue running after processing
1240 qcop messages. Normally if an application is started via a qcop message, 1256 qcop messages. Normally if an application is started via a qcop message,
1241 the application will process the qcop message and then quit. If while 1257 the application will process the qcop message and then quit. If while
1242 processing the qcop message it calls this function, then the application 1258 processing the qcop message it calls this function, then the application
1243 will show and start proper once it has finished processing qcop messages. 1259 will show and start proper once it has finished processing qcop messages.
1244 1260
1245 \sa keepRunning() 1261 \sa keepRunning()
1246*/ 1262*/
1247void QPEApplication::setKeepRunning() 1263void QPEApplication::setKeepRunning()
1248{ 1264{
1249 if ( qApp && qApp->inherits( "QPEApplication" ) ) { 1265 if ( qApp && qApp->inherits( "QPEApplication" ) ) {
1250 QPEApplication *qpeApp = (QPEApplication*)qApp; 1266 QPEApplication *qpeApp = (QPEApplication*)qApp;
1251 qpeApp->d->keep_running = TRUE; 1267 qpeApp->d->keep_running = TRUE;
1252 } 1268 }
1253} 1269}
1254 1270
1255/*! 1271/*!
1256 Returns whether the application will quit after processing the current 1272 Returns whether the application will quit after processing the current
1257 list of qcop messages. 1273 list of qcop messages.
1258 1274
1259 \sa setKeepRunning() 1275 \sa setKeepRunning()
1260*/ 1276*/
1261bool QPEApplication::keepRunning() const 1277bool QPEApplication::keepRunning() const
1262{ 1278{
1263 return d->keep_running; 1279 return d->keep_running;
1264} 1280}
1265 1281
1266/*! 1282/*!
1267 \internal 1283 \internal
1268*/ 1284*/
1269void QPEApplication::internalSetStyle( const QString &style ) 1285void QPEApplication::internalSetStyle( const QString &style )
1270{ 1286{
1271#if QT_VERSION >= 300 1287#if QT_VERSION >= 300
1272 if ( style == "QPE" ) { 1288 if ( style == "QPE" ) {
1273 setStyle( new QPEStyle ); 1289 setStyle( new QPEStyle );
1274 } else { 1290 } else {
1275 QStyle *s = QStyleFactory::create(style); 1291 QStyle *s = QStyleFactory::create(style);
1276 if ( s ) setStyle(s); 1292 if ( s ) setStyle(s);
1277 } 1293 }
1278#else 1294#else
1279 if ( style == "Windows" ) { 1295 if ( style == "Windows" ) {
1280 setStyle( new QWindowsStyle ); 1296 setStyle( new QWindowsStyle );
1281 } else if ( style == "QPE" ) { 1297 } else if ( style == "QPE" ) {
1282 setStyle( new QPEStyle ); 1298 setStyle( new QPEStyle );
1283 } else if ( style == "Light" ) { 1299 } else if ( style == "Light" ) {
1284 setStyle( new LightStyle ); 1300 setStyle( new LightStyle );
1285 } 1301 }
1286#ifndef QT_NO_STYLE_PLATINUM 1302#ifndef QT_NO_STYLE_PLATINUM
1287 else if ( style == "Platinum" ) { 1303 else if ( style == "Platinum" ) {
1288 setStyle( new QPlatinumStyle ); 1304 setStyle( new QPlatinumStyle );
1289 } 1305 }
1290#endif 1306#endif
1291#ifndef QT_NO_STYLE_MOTIF 1307#ifndef QT_NO_STYLE_MOTIF
1292 else if ( style == "Motif" ) { 1308 else if ( style == "Motif" ) {
1293 setStyle( new QMotifStyle ); 1309 setStyle( new QMotifStyle );
1294 } 1310 }
1295#endif 1311#endif
1296#ifndef QT_NO_STYLE_MOTIFPLUS 1312#ifndef QT_NO_STYLE_MOTIFPLUS
1297 else if ( style == "MotifPlus" ) { 1313 else if ( style == "MotifPlus" ) {
1298 setStyle( new QMotifPlusStyle ); 1314 setStyle( new QMotifPlusStyle );
1299 } 1315 }
1300#endif 1316#endif
1301#endif 1317#endif
1302} 1318}
1303 1319
1304/*! 1320/*!
1305 \internal 1321 \internal
1306*/ 1322*/
1307void QPEApplication::prepareForTermination(bool willrestart) 1323void QPEApplication::prepareForTermination(bool willrestart)
1308{ 1324{
1309 if ( willrestart ) { 1325 if ( willrestart ) {
1310 // Draw a big wait icon, the image can be altered in later revisions 1326 // Draw a big wait icon, the image can be altered in later revisions
1311// QWidget *d = QApplication::desktop(); 1327// QWidget *d = QApplication::desktop();
1312 QImage img = Resource::loadImage( "launcher/new_wait" ); 1328 QImage img = Resource::loadImage( "launcher/new_wait" );
1313 QPixmap pix; 1329 QPixmap pix;
1314 pix.convertFromImage(img.smoothScale(1*img.width(), 1*img.height())); 1330 pix.convertFromImage(img.smoothScale(1*img.width(), 1*img.height()));
1315 QLabel *lblWait = new QLabel(0, "wait hack!", QWidget::WStyle_Customize | 1331 QLabel *lblWait = new QLabel(0, "wait hack!", QWidget::WStyle_Customize |
1316 QWidget::WStyle_NoBorder | QWidget::WStyle_Tool ); 1332 QWidget::WStyle_NoBorder | QWidget::WStyle_Tool );
1317 lblWait->setPixmap( pix ); 1333 lblWait->setPixmap( pix );
1318 lblWait->setAlignment( QWidget::AlignCenter ); 1334 lblWait->setAlignment( QWidget::AlignCenter );
1319 lblWait->show(); 1335 lblWait->show();
1320 lblWait->showMaximized(); 1336 lblWait->showMaximized();
1321 } 1337 }
1322#ifndef SINGLE_APP 1338#ifndef SINGLE_APP
1323 { QCopEnvelope envelope("QPE/System", "forceQuit()"); } 1339 { QCopEnvelope envelope("QPE/System", "forceQuit()"); }
1324 processEvents(); // ensure the message goes out. 1340 processEvents(); // ensure the message goes out.
1325 sleep(1); // You have 1 second to comply. 1341 sleep(1); // You have 1 second to comply.
1326#endif 1342#endif
1327} 1343}
1328 1344
1329/*! 1345/*!
1330 \internal 1346 \internal
1331*/ 1347*/
1332void QPEApplication::shutdown() 1348void QPEApplication::shutdown()
1333{ 1349{
1334 // Implement in server's QPEApplication subclass 1350 // Implement in server's QPEApplication subclass
1335} 1351}
1336 1352
1337/*! 1353/*!
1338 \internal 1354 \internal
1339*/ 1355*/
1340void QPEApplication::restart() 1356void QPEApplication::restart()
1341{ 1357{
1342 // Implement in server's QPEApplication subclass 1358 // Implement in server's QPEApplication subclass
1343} 1359}
1344 1360
1345static QPtrDict<void>* stylusDict=0; 1361static QPtrDict<void>* stylusDict=0;
1346static void createDict() 1362static void createDict()
1347{ 1363{
1348 if ( !stylusDict ) 1364 if ( !stylusDict )
1349 stylusDict = new QPtrDict<void>; 1365 stylusDict = new QPtrDict<void>;
1350} 1366}
1351 1367
1352/*! 1368/*!
1353 Returns the current StylusMode for \a w. 1369 Returns the current StylusMode for \a w.
1354 1370
1355 \sa setStylusOperation() 1371 \sa setStylusOperation()
1356*/ 1372*/
1357QPEApplication::StylusMode QPEApplication::stylusOperation( QWidget* w ) 1373QPEApplication::StylusMode QPEApplication::stylusOperation( QWidget* w )
1358{ 1374{
1359 if ( stylusDict ) 1375 if ( stylusDict )
1360 return (StylusMode)(int)stylusDict->find(w); 1376 return (StylusMode)(int)stylusDict->find(w);
1361 return LeftOnly; 1377 return LeftOnly;
1362} 1378}
1363 1379
1364/*! 1380/*!
1365 \enum QPEApplication::StylusMode 1381 \enum QPEApplication::StylusMode
1366 1382
1367 \value LeftOnly the stylus only generates LeftButton 1383 \value LeftOnly the stylus only generates LeftButton
1368 events (the default). 1384 events (the default).
1369 \value RightOnHold the stylus generates RightButton events 1385 \value RightOnHold the stylus generates RightButton events
1370 if the user uses the press-and-hold gesture. 1386 if the user uses the press-and-hold gesture.
1371 1387
1372 See setStylusOperation(). 1388 See setStylusOperation().
1373*/ 1389*/
1374 1390
1375/*! 1391/*!
1376 Causes \a w to receive mouse events according to \a mode. 1392 Causes \a w to receive mouse events according to \a mode.
1377 1393
1378 \sa stylusOperation() 1394 \sa stylusOperation()
1379*/ 1395*/
1380void QPEApplication::setStylusOperation( QWidget* w, StylusMode mode ) 1396void QPEApplication::setStylusOperation( QWidget* w, StylusMode mode )
1381{ 1397{
1382 createDict(); 1398 createDict();
1383 if ( mode == LeftOnly ) { 1399 if ( mode == LeftOnly ) {
1384 stylusDict->remove(w); 1400 stylusDict->remove(w);
1385 w->removeEventFilter(qApp); 1401 w->removeEventFilter(qApp);
1386 } else { 1402 } else {
1387 stylusDict->insert(w,(void*)mode); 1403 stylusDict->insert(w,(void*)mode);
1388 connect(w,SIGNAL(destroyed()),qApp,SLOT(removeSenderFromStylusDict())); 1404 connect(w,SIGNAL(destroyed()),qApp,SLOT(removeSenderFromStylusDict()));
1389 w->installEventFilter(qApp); 1405 w->installEventFilter(qApp);
1390 } 1406 }
1391} 1407}
1392 1408
1393 1409
1394/*! 1410/*!
1395 \reimp 1411 \reimp
1396*/ 1412*/
1397bool QPEApplication::eventFilter( QObject *o, QEvent *e ) 1413bool QPEApplication::eventFilter( QObject *o, QEvent *e )
1398{ 1414{
1399 if ( stylusDict && e->type() >= QEvent::MouseButtonPress && e->type() <= QEvent::MouseMove ) { 1415 if ( stylusDict && e->type() >= QEvent::MouseButtonPress && e->type() <= QEvent::MouseMove ) {
1400 QMouseEvent* me = (QMouseEvent*)e; 1416 QMouseEvent* me = (QMouseEvent*)e;
1401 if ( me->button() == LeftButton ) { 1417 if ( me->button() == LeftButton ) {
1402 StylusMode mode = (StylusMode)(int)stylusDict->find(o); 1418 StylusMode mode = (StylusMode)(int)stylusDict->find(o);
1403 switch (mode) { 1419 switch (mode) {
1404 case RightOnHold: 1420 case RightOnHold:
1405 switch ( me->type() ) { 1421 switch ( me->type() ) {
1406 case QEvent::MouseButtonPress: 1422 case QEvent::MouseButtonPress:
1407 d->presstimer = startTimer(500); // #### pref. 1423 d->presstimer = startTimer(500); // #### pref.
1408 d->presswidget = (QWidget*)o; 1424 d->presswidget = (QWidget*)o;
1409 d->presspos = me->pos(); 1425 d->presspos = me->pos();
1410 d->rightpressed = FALSE; 1426 d->rightpressed = FALSE;
1411 break; 1427 break;
1412 case QEvent::MouseButtonRelease: 1428 case QEvent::MouseButtonRelease:
1413 if ( d->presstimer ) { 1429 if ( d->presstimer ) {
1414 killTimer(d->presstimer); 1430 killTimer(d->presstimer);
1415 d->presstimer = 0; 1431 d->presstimer = 0;
1416 } 1432 }
1417 if ( d->rightpressed && d->presswidget ) { 1433 if ( d->rightpressed && d->presswidget ) {
1418 // Right released 1434 // Right released
1419 postEvent( d->presswidget, 1435 postEvent( d->presswidget,
1420 new QMouseEvent( QEvent::MouseButtonRelease, me->pos(), 1436 new QMouseEvent( QEvent::MouseButtonRelease, me->pos(),
1421 RightButton, LeftButton+RightButton ) ); 1437 RightButton, LeftButton+RightButton ) );
1422 // Left released, off-widget 1438 // Left released, off-widget
1423 postEvent( d->presswidget, 1439 postEvent( d->presswidget,
1424 new QMouseEvent( QEvent::MouseMove, QPoint(-1,-1), 1440 new QMouseEvent( QEvent::MouseMove, QPoint(-1,-1),
1425 LeftButton, LeftButton ) ); 1441 LeftButton, LeftButton ) );
1426 postEvent( d->presswidget, 1442 postEvent( d->presswidget,
1427 new QMouseEvent( QEvent::MouseButtonRelease, QPoint(-1,-1), 1443 new QMouseEvent( QEvent::MouseButtonRelease, QPoint(-1,-1),
1428 LeftButton, LeftButton ) ); 1444 LeftButton, LeftButton ) );
1429 d->rightpressed = FALSE; 1445 d->rightpressed = FALSE;
1430 return TRUE; // don't send the real Left release 1446 return TRUE; // don't send the real Left release
1431 } 1447 }
1432 break; 1448 break;
1433 default: 1449 default:
1434 break; 1450 break;
1435 } 1451 }
1436 break; 1452 break;
1437 default: 1453 default:
1438 ; 1454 ;
1439 } 1455 }
1440 } 1456 }
1441 } else if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) { 1457 } else if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) {
1442 QKeyEvent *ke = (QKeyEvent *)e; 1458 QKeyEvent *ke = (QKeyEvent *)e;
1443 if ( ke->key() == Key_Enter ) { 1459 if ( ke->key() == Key_Enter ) {
1444 if ( o->isA( "QRadioButton" ) || o->isA( "QCheckBox" ) ) { 1460 if ( o->isA( "QRadioButton" ) || o->isA( "QCheckBox" ) ) {
1445 postEvent( o, new QKeyEvent( e->type(), Key_Space, ' ', 1461 postEvent( o, new QKeyEvent( e->type(), Key_Space, ' ',
1446 ke->state(), " ", ke->isAutoRepeat(), ke->count() ) ); 1462 ke->state(), " ", ke->isAutoRepeat(), ke->count() ) );
1447 return TRUE; 1463 return TRUE;
1448 } 1464 }
1449 } 1465 }
1450 } 1466 }
1451 1467
1452 return FALSE; 1468 return FALSE;
1453} 1469}
1454 1470
1455/*! 1471/*!
1456 \reimp 1472 \reimp
1457*/ 1473*/
1458void QPEApplication::timerEvent( QTimerEvent *e ) 1474void QPEApplication::timerEvent( QTimerEvent *e )
1459{ 1475{
1460 if ( e->timerId() == d->presstimer && d->presswidget ) { 1476 if ( e->timerId() == d->presstimer && d->presswidget ) {
1461 // Right pressed 1477 // Right pressed
1462 postEvent( d->presswidget, 1478 postEvent( d->presswidget,
1463 new QMouseEvent( QEvent::MouseButtonPress, d->presspos, 1479 new QMouseEvent( QEvent::MouseButtonPress, d->presspos,
1464 RightButton, LeftButton ) ); 1480 RightButton, LeftButton ) );
1465 killTimer( d->presstimer ); 1481 killTimer( d->presstimer );
1466 d->presstimer = 0; 1482 d->presstimer = 0;
1467 d->rightpressed = TRUE; 1483 d->rightpressed = TRUE;
1468 } 1484 }
1469} 1485}
1470 1486
1471void QPEApplication::removeSenderFromStylusDict() 1487void QPEApplication::removeSenderFromStylusDict()
1472{ 1488{
1473 stylusDict->remove((void*)sender()); 1489 stylusDict->remove((void*)sender());
1474 if ( d->presswidget == sender() ) 1490 if ( d->presswidget == sender() )
1475 d->presswidget = 0; 1491 d->presswidget = 0;
1476} 1492}
1477 1493
1478/*! 1494/*!
1479 \internal 1495 \internal
1480*/ 1496*/
1481bool QPEApplication::keyboardGrabbed() const 1497bool QPEApplication::keyboardGrabbed() const
1482{ 1498{
1483 return d->kbgrabber; 1499 return d->kbgrabber;
1484} 1500}
1485 1501
1486 1502
1487/*! 1503/*!
1488 Reverses the effect of grabKeyboard(). This is called automatically 1504 Reverses the effect of grabKeyboard(). This is called automatically
1489 on program exit. 1505 on program exit.
1490*/ 1506*/
1491void QPEApplication::ungrabKeyboard() 1507void QPEApplication::ungrabKeyboard()
1492{ 1508{
1493 QPEApplicationData* d = ((QPEApplication*)qApp)->d; 1509 QPEApplicationData* d = ((QPEApplication*)qApp)->d;
1494 if ( d->kbgrabber == 2 ) { 1510 if ( d->kbgrabber == 2 ) {
1495 QCopEnvelope e("QPE/System", "grabKeyboard(QString)" ); 1511 QCopEnvelope e("QPE/System", "grabKeyboard(QString)" );
1496 e << QString::null; 1512 e << QString::null;
1497 d->kbregrab = FALSE; 1513 d->kbregrab = FALSE;
1498 d->kbgrabber = 0; 1514 d->kbgrabber = 0;
1499 } 1515 }
1500} 1516}
1501 1517
1502/*! 1518/*!
1503 Grabs the keyboard such that the system's application launching 1519 Grabs the keyboard such that the system's application launching
1504 keys no longer work, and instead they are receivable by this 1520 keys no longer work, and instead they are receivable by this
1505 application. 1521 application.
1506 1522
1507 \sa ungrabKeyboard() 1523 \sa ungrabKeyboard()
1508*/ 1524*/
1509void QPEApplication::grabKeyboard() 1525void QPEApplication::grabKeyboard()
1510{ 1526{
1511 QPEApplicationData* d = ((QPEApplication*)qApp)->d; 1527 QPEApplicationData* d = ((QPEApplication*)qApp)->d;
1512 if ( qApp->type() == QApplication::GuiServer ) 1528 if ( qApp->type() == QApplication::GuiServer )
1513 d->kbgrabber = 0; 1529 d->kbgrabber = 0;
1514 else { 1530 else {
1515 QCopEnvelope e("QPE/System", "grabKeyboard(QString)" ); 1531 QCopEnvelope e("QPE/System", "grabKeyboard(QString)" );
1516 e << d->appName; 1532 e << d->appName;
1517 d->kbgrabber = 2; // me 1533 d->kbgrabber = 2; // me
1518 } 1534 }
1519} 1535}
1520 1536
1521/*! 1537/*!
1522 \reimp 1538 \reimp
1523*/ 1539*/
1524int QPEApplication::exec() 1540int QPEApplication::exec()
1525{ 1541{
1526 d->sendQCopQ(); 1542 d->sendQCopQ();
1527 if ( d->keep_running) 1543 if ( d->keep_running)
1528 //|| d->qpe_main_widget && d->qpe_main_widget->isVisible() ) 1544 //|| d->qpe_main_widget && d->qpe_main_widget->isVisible() )
1529 return QApplication::exec(); 1545 return QApplication::exec();
1530 1546
1531 { 1547 {
1532 QCopEnvelope e("QPE/System", "closing(QString)" ); 1548 QCopEnvelope e("QPE/System", "closing(QString)" );
1533 e << d->appName; 1549 e << d->appName;
1534 } 1550 }
1535 processEvents(); 1551 processEvents();
1536 return 0; 1552 return 0;
1537} 1553}
1538 1554
1539/*! 1555/*!
1540 \internal 1556 \internal
1541 External request for application to quit. Quits if possible without 1557 External request for application to quit. Quits if possible without
1542 loosing state. 1558 loosing state.
1543*/ 1559*/
1544void QPEApplication::tryQuit() 1560void QPEApplication::tryQuit()
1545{ 1561{
1546 if ( activeModalWidget() || strcmp( argv()[0], "embeddedkonsole") == 0 ) 1562 if ( activeModalWidget() || strcmp( argv()[0], "embeddedkonsole") == 0 )
1547 return; // Inside modal loop or konsole. Too hard to save state. 1563 return; // Inside modal loop or konsole. Too hard to save state.
1548 { 1564 {
1549 QCopEnvelope e("QPE/System", "closing(QString)" ); 1565 QCopEnvelope e("QPE/System", "closing(QString)" );
1550 e << d->appName; 1566 e << d->appName;
1551 } 1567 }
1552 processEvents(); 1568 processEvents();
1553 1569
1554 quit(); 1570 quit();
1555} 1571}
1556 1572
1557/*! 1573/*!
1558 \internal 1574 \internal
1559 User initiated quit. Makes the window 'Go Away'. If preloaded this means 1575 User initiated quit. Makes the window 'Go Away'. If preloaded this means
1560 hiding the window. If not it means quitting the application. 1576 hiding the window. If not it means quitting the application.
1561 As this is user initiated we don't need to check state. 1577 As this is user initiated we don't need to check state.
1562*/ 1578*/
1563void QPEApplication::hideOrQuit() 1579void QPEApplication::hideOrQuit()
1564{ 1580{
1565 // notify of our demise :) 1581 // notify of our demise :)
1566 { 1582 {
1567 QCopEnvelope e("QPE/System", "closing(QString)" ); 1583 QCopEnvelope e("QPE/System", "closing(QString)" );
1568 e << d->appName; 1584 e << d->appName;
1569 } 1585 }
1570 processEvents(); 1586 processEvents();
1571 if ( d->preloaded && d->qpe_main_widget ) 1587 if ( d->preloaded && d->qpe_main_widget )
1572 d->qpe_main_widget->hide(); 1588 d->qpe_main_widget->hide();
1573 else 1589 else
1574 quit(); 1590 quit();
1575} 1591}
1576 1592
1577#if defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX) 1593#if defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX)
1578 1594
1579// The libraries with the skiff package (and possibly others) have 1595// The libraries with the skiff package (and possibly others) have
1580// completely useless implementations of builtin new and delete that 1596// completely useless implementations of builtin new and delete that
1581// use about 50% of your CPU. Here we revert to the simple libc 1597// use about 50% of your CPU. Here we revert to the simple libc
1582// functions. 1598// functions.
1583 1599
1584void* operator new[](size_t size) 1600void* operator new[](size_t size)
1585{ 1601{
1586 return malloc(size); 1602 return malloc(size);
1587} 1603}
1588 1604
1589void* operator new(size_t size) 1605void* operator new(size_t size)
1590{ 1606{
1591 return malloc(size); 1607 return malloc(size);
1592} 1608}
1593 1609
1594void operator delete[](void* p) 1610void operator delete[](void* p)
1595{ 1611{
1596 free(p); 1612 free(p);
1597} 1613}
1598 1614
1599void operator delete[](void* p, size_t /*size*/) 1615void operator delete[](void* p, size_t /*size*/)
1600{ 1616{
1601 free(p); 1617 free(p);
1602} 1618}
1603 1619
1604void operator delete(void* p) 1620void operator delete(void* p)
1605{ 1621{
1606 free(p); 1622 free(p);
1607} 1623}
1608 1624
1609void operator delete(void* p, size_t /*size*/) 1625void operator delete(void* p, size_t /*size*/)
1610{ 1626{
1611 free(p); 1627 free(p);
1612} 1628}
1613 1629
1614#endif 1630#endif
1615 1631
1616#if ( QT_VERSION <= 230 ) && !defined(SINGLE_APP) 1632#if ( QT_VERSION <= 230 ) && !defined(SINGLE_APP)
1617#include <qwidgetlist.h> 1633#include <qwidgetlist.h>
1618#include <qgfx_qws.h> 1634#include <qgfx_qws.h>
1619extern QRect qt_maxWindowRect; 1635extern QRect qt_maxWindowRect;
1620void qt_setMaxWindowRect(const QRect& r) 1636void qt_setMaxWindowRect(const QRect& r)
1621{ 1637{
1622 qt_maxWindowRect = qt_screen->mapFromDevice(r, 1638 qt_maxWindowRect = qt_screen->mapFromDevice(r,
1623 qt_screen->mapToDevice(QSize(qt_screen->width(),qt_screen->height()))); 1639 qt_screen->mapToDevice(QSize(qt_screen->width(),qt_screen->height())));
1624 // Re-resize any maximized windows 1640 // Re-resize any maximized windows
1625 QWidgetList* l = QApplication::topLevelWidgets(); 1641 QWidgetList* l = QApplication::topLevelWidgets();
1626 if ( l ) { 1642 if ( l ) {
1627 QWidget *w = l->first(); 1643 QWidget *w = l->first();
1628 while ( w ) { 1644 while ( w ) {
1629 if ( w->isVisible() && w->isMaximized() ) 1645 if ( w->isVisible() && w->isMaximized() )
1630 { 1646 {
1631 w->showMaximized(); 1647 w->showMaximized();
1632 } 1648 }
1633 w = l->next(); 1649 w = l->next();
1634 } 1650 }
1635 delete l; 1651 delete l;
1636 } 1652 }
1637} 1653}
1638#endif 1654#endif