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