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