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