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