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