author | sandman <sandman> | 2002-06-21 01:23:55 (UTC) |
---|---|---|
committer | sandman <sandman> | 2002-06-21 01:23:55 (UTC) |
commit | 3f1129f79e945135828191679559da70cf4ac6fa (patch) (unidiff) | |
tree | ac5a2e4698a93a201c6bdb5bcf377e1e429c32ed | |
parent | 2a7407325b1607c9ee40ed3558c8549672a36ad4 (diff) | |
download | opie-3f1129f79e945135828191679559da70cf4ac6fa.zip opie-3f1129f79e945135828191679559da70cf4ac6fa.tar.gz opie-3f1129f79e945135828191679559da70cf4ac6fa.tar.bz2 |
Added a hack to support on-demand loading of liquid style with Qt2
Will be removed, once we switch to Qt3
-rw-r--r-- | library/qpeapplication.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/library/qpeapplication.cpp b/library/qpeapplication.cpp index f84bc0e..1534b0b 100644 --- a/library/qpeapplication.cpp +++ b/library/qpeapplication.cpp | |||
@@ -1,476 +1,477 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | ** $Id$ | 19 | ** $Id$ |
20 | ** | 20 | ** |
21 | **********************************************************************/ | 21 | **********************************************************************/ |
22 | #define QTOPIA_INTERNAL_LANGLIST | 22 | #define QTOPIA_INTERNAL_LANGLIST |
23 | #include <stdlib.h> | 23 | #include <stdlib.h> |
24 | #include <unistd.h> | 24 | #include <unistd.h> |
25 | #include <qfile.h> | 25 | #include <qfile.h> |
26 | #ifdef Q_WS_QWS | 26 | #ifdef Q_WS_QWS |
27 | #ifndef QT_NO_COP | 27 | #ifndef QT_NO_COP |
28 | #if QT_VERSION <= 231 | 28 | #if QT_VERSION <= 231 |
29 | #define private public | 29 | #define private public |
30 | #define sendLocally processEvent | 30 | #define sendLocally processEvent |
31 | #include "qcopenvelope_qws.h" | 31 | #include "qcopenvelope_qws.h" |
32 | #undef private | 32 | #undef private |
33 | #else | 33 | #else |
34 | #include "qcopenvelope_qws.h" | 34 | #include "qcopenvelope_qws.h" |
35 | #endif | 35 | #endif |
36 | #endif | 36 | #endif |
37 | #include <qwindowsystem_qws.h> | 37 | #include <qwindowsystem_qws.h> |
38 | #endif | 38 | #endif |
39 | #include <qtextstream.h> | 39 | #include <qtextstream.h> |
40 | #include <qpalette.h> | 40 | #include <qpalette.h> |
41 | #include <qbuffer.h> | 41 | #include <qbuffer.h> |
42 | #include <qptrdict.h> | 42 | #include <qptrdict.h> |
43 | #include <qregexp.h> | 43 | #include <qregexp.h> |
44 | #include <qdir.h> | 44 | #include <qdir.h> |
45 | #include <qlabel.h> | 45 | #include <qlabel.h> |
46 | #include <qdialog.h> | 46 | #include <qdialog.h> |
47 | #include <qdragobject.h> | 47 | #include <qdragobject.h> |
48 | #include <qevent.h> | 48 | #include <qevent.h> |
49 | #include <qtooltip.h> | 49 | #include <qtooltip.h> |
50 | #include <qsignal.h> | 50 | #include <qsignal.h> |
51 | #include <linux/fb.h> | 51 | #include <linux/fb.h> |
52 | 52 | ||
53 | #include <qsignal.h> | 53 | #include <qsignal.h> |
54 | #include "qpeapplication.h" | 54 | #include "qpeapplication.h" |
55 | #include "qpestyle.h" | 55 | #include "qpestyle.h" |
56 | #if QT_VERSION >= 300 | 56 | #if QT_VERSION >= 300 |
57 | #include <qstylefactory.h> | 57 | #include <qstylefactory.h> |
58 | #else | 58 | #else |
59 | #include <qplatinumstyle.h> | 59 | #include <qplatinumstyle.h> |
60 | #include <qwindowsstyle.h> | 60 | #include <qwindowsstyle.h> |
61 | #include <qmotifstyle.h> | 61 | #include <qmotifstyle.h> |
62 | #include <qmotifplusstyle.h> | 62 | #include <qmotifplusstyle.h> |
63 | #include "lightstyle.h" | 63 | #include "lightstyle.h" |
64 | #endif | 64 | #endif |
65 | #include "global.h" | 65 | #include "global.h" |
66 | #include "resource.h" | 66 | #include "resource.h" |
67 | #if QT_VERSION <= 230 && defined(QT_NO_CODECS) | 67 | #if QT_VERSION <= 230 && defined(QT_NO_CODECS) |
68 | #include "qutfcodec.h" | 68 | #include "qutfcodec.h" |
69 | #endif | 69 | #endif |
70 | #include "config.h" | 70 | #include "config.h" |
71 | #include "network.h" | 71 | #include "network.h" |
72 | #include "fontmanager.h" | 72 | #include "fontmanager.h" |
73 | #include "fontdatabase.h" | 73 | #include "fontdatabase.h" |
74 | 74 | ||
75 | #include "power.h" | 75 | #include "power.h" |
76 | #include "alarmserver.h" | 76 | #include "alarmserver.h" |
77 | #include "applnk.h" | 77 | #include "applnk.h" |
78 | #include "qpemenubar.h" | 78 | #include "qpemenubar.h" |
79 | 79 | ||
80 | #include <unistd.h> | 80 | #include <unistd.h> |
81 | #include <sys/file.h> | 81 | #include <sys/file.h> |
82 | #include <sys/ioctl.h> | 82 | #include <sys/ioctl.h> |
83 | #include <sys/soundcard.h> | 83 | #include <sys/soundcard.h> |
84 | 84 | ||
85 | // for setBacklight() | 85 | // for setBacklight() |
86 | #if defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX) | 86 | #if defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX) |
87 | #include <linux/fb.h> | 87 | #include <linux/fb.h> |
88 | #include <sys/types.h> | 88 | #include <sys/types.h> |
89 | #include <sys/stat.h> | 89 | #include <sys/stat.h> |
90 | #endif | 90 | #endif |
91 | #include <stdlib.h> | 91 | #include <stdlib.h> |
92 | 92 | ||
93 | #include <dlfcn.h> // for Liquid HACK | ||
93 | 94 | ||
94 | class QPEApplicationData { | 95 | class QPEApplicationData { |
95 | public: | 96 | public: |
96 | QPEApplicationData() : presstimer(0), presswidget(0), rightpressed(FALSE), | 97 | QPEApplicationData() : presstimer(0), presswidget(0), rightpressed(FALSE), |
97 | kbgrabber(0), kbregrab(FALSE), notbusysent(FALSE), preloaded(FALSE), | 98 | kbgrabber(0), kbregrab(FALSE), notbusysent(FALSE), preloaded(FALSE), |
98 | forceshow(FALSE), nomaximize(FALSE), qpe_main_widget(0), | 99 | forceshow(FALSE), nomaximize(FALSE), qpe_main_widget(0), |
99 | keep_running(TRUE) | 100 | keep_running(TRUE) |
100 | { | 101 | { |
101 | qcopq.setAutoDelete(TRUE); | 102 | qcopq.setAutoDelete(TRUE); |
102 | } | 103 | } |
103 | 104 | ||
104 | int presstimer; | 105 | int presstimer; |
105 | QWidget* presswidget; | 106 | QWidget* presswidget; |
106 | QPoint presspos; | 107 | QPoint presspos; |
107 | bool rightpressed; | 108 | bool rightpressed; |
108 | int kbgrabber; | 109 | int kbgrabber; |
109 | bool kbregrab; | 110 | bool kbregrab; |
110 | bool notbusysent; | 111 | bool notbusysent; |
111 | QString appName; | 112 | QString appName; |
112 | struct QCopRec { | 113 | struct QCopRec { |
113 | QCopRec(const QCString &ch, const QCString &msg, | 114 | QCopRec(const QCString &ch, const QCString &msg, |
114 | const QByteArray &d) : | 115 | const QByteArray &d) : |
115 | channel(ch), message(msg), data(d) { } | 116 | channel(ch), message(msg), data(d) { } |
116 | 117 | ||
117 | QCString channel; | 118 | QCString channel; |
118 | QCString message; | 119 | QCString message; |
119 | QByteArray data; | 120 | QByteArray data; |
120 | }; | 121 | }; |
121 | bool preloaded; | 122 | bool preloaded; |
122 | bool forceshow; | 123 | bool forceshow; |
123 | bool nomaximize; | 124 | bool nomaximize; |
124 | QWidget* qpe_main_widget; | 125 | QWidget* qpe_main_widget; |
125 | bool keep_running; | 126 | bool keep_running; |
126 | QList<QCopRec> qcopq; | 127 | QList<QCopRec> qcopq; |
127 | 128 | ||
128 | void enqueueQCop(const QCString &ch, const QCString &msg, | 129 | void enqueueQCop(const QCString &ch, const QCString &msg, |
129 | const QByteArray &data) | 130 | const QByteArray &data) |
130 | { | 131 | { |
131 | qcopq.append(new QCopRec(ch,msg,data)); | 132 | qcopq.append(new QCopRec(ch,msg,data)); |
132 | } | 133 | } |
133 | void sendQCopQ() | 134 | void sendQCopQ() |
134 | { | 135 | { |
135 | QCopRec* r; | 136 | QCopRec* r; |
136 | for (QListIterator<QCopRec> it(qcopq); (r=it.current()); ++it) | 137 | for (QListIterator<QCopRec> it(qcopq); (r=it.current()); ++it) |
137 | QCopChannel::sendLocally(r->channel,r->message,r->data); | 138 | QCopChannel::sendLocally(r->channel,r->message,r->data); |
138 | qcopq.clear(); | 139 | qcopq.clear(); |
139 | } | 140 | } |
140 | }; | 141 | }; |
141 | 142 | ||
142 | class ResourceMimeFactory : public QMimeSourceFactory { | 143 | class ResourceMimeFactory : public QMimeSourceFactory { |
143 | public: | 144 | public: |
144 | ResourceMimeFactory() | 145 | ResourceMimeFactory() |
145 | { | 146 | { |
146 | setFilePath( Global::helpPath() ); | 147 | setFilePath( Global::helpPath() ); |
147 | setExtensionType("html","text/html;charset=UTF-8"); | 148 | setExtensionType("html","text/html;charset=UTF-8"); |
148 | } | 149 | } |
149 | 150 | ||
150 | const QMimeSource* data(const QString& abs_name) const | 151 | const QMimeSource* data(const QString& abs_name) const |
151 | { | 152 | { |
152 | const QMimeSource* r = QMimeSourceFactory::data(abs_name); | 153 | const QMimeSource* r = QMimeSourceFactory::data(abs_name); |
153 | if ( !r ) { | 154 | if ( !r ) { |
154 | int sl = abs_name.length(); | 155 | int sl = abs_name.length(); |
155 | do { | 156 | do { |
156 | sl = abs_name.findRev('/',sl-1); | 157 | sl = abs_name.findRev('/',sl-1); |
157 | QString name = sl>=0 ? abs_name.mid(sl+1) : abs_name; | 158 | QString name = sl>=0 ? abs_name.mid(sl+1) : abs_name; |
158 | int dot = name.findRev('.'); | 159 | int dot = name.findRev('.'); |
159 | if ( dot >= 0 ) | 160 | if ( dot >= 0 ) |
160 | name = name.left(dot); | 161 | name = name.left(dot); |
161 | QImage img = Resource::loadImage(name); | 162 | QImage img = Resource::loadImage(name); |
162 | if ( !img.isNull() ) | 163 | if ( !img.isNull() ) |
163 | r = new QImageDrag(img); | 164 | r = new QImageDrag(img); |
164 | } while (!r && sl>0); | 165 | } while (!r && sl>0); |
165 | } | 166 | } |
166 | return r; | 167 | return r; |
167 | } | 168 | } |
168 | }; | 169 | }; |
169 | 170 | ||
170 | static int muted=0; | 171 | static int muted=0; |
171 | static int micMuted=0; | 172 | static int micMuted=0; |
172 | 173 | ||
173 | static void setVolume(int t=0, int percent=-1) | 174 | static void setVolume(int t=0, int percent=-1) |
174 | { | 175 | { |
175 | switch (t) { | 176 | switch (t) { |
176 | case 0: { | 177 | case 0: { |
177 | Config cfg("qpe"); | 178 | Config cfg("qpe"); |
178 | cfg.setGroup("Volume"); | 179 | cfg.setGroup("Volume"); |
179 | if ( percent < 0 ) | 180 | if ( percent < 0 ) |
180 | percent = cfg.readNumEntry("VolumePercent",50); | 181 | percent = cfg.readNumEntry("VolumePercent",50); |
181 | int fd = 0; | 182 | int fd = 0; |
182 | if ((fd = open("/dev/mixer", O_RDWR))>=0) { | 183 | if ((fd = open("/dev/mixer", O_RDWR))>=0) { |
183 | int vol = muted ? 0 : percent; | 184 | int vol = muted ? 0 : percent; |
184 | // set both channels to same volume | 185 | // set both channels to same volume |
185 | vol |= vol << 8; | 186 | vol |= vol << 8; |
186 | ioctl(fd, MIXER_WRITE(0), &vol); | 187 | ioctl(fd, MIXER_WRITE(0), &vol); |
187 | ::close(fd); | 188 | ::close(fd); |
188 | } | 189 | } |
189 | } break; | 190 | } break; |
190 | } | 191 | } |
191 | } | 192 | } |
192 | 193 | ||
193 | static void setMic(int t=0, int percent=-1) | 194 | static void setMic(int t=0, int percent=-1) |
194 | { | 195 | { |
195 | switch (t) { | 196 | switch (t) { |
196 | case 0: { | 197 | case 0: { |
197 | Config cfg("qpe"); | 198 | Config cfg("qpe"); |
198 | cfg.setGroup("Volume"); | 199 | cfg.setGroup("Volume"); |
199 | if ( percent < 0 ) | 200 | if ( percent < 0 ) |
200 | percent = cfg.readNumEntry("Mic",50); | 201 | percent = cfg.readNumEntry("Mic",50); |
201 | 202 | ||
202 | int fd = 0; | 203 | int fd = 0; |
203 | int mic = micMuted ? 0 : percent; | 204 | int mic = micMuted ? 0 : percent; |
204 | if ((fd = open("/dev/mixer", O_RDWR))>=0) { | 205 | if ((fd = open("/dev/mixer", O_RDWR))>=0) { |
205 | ioctl(fd, MIXER_WRITE(SOUND_MIXER_MIC), &mic); | 206 | ioctl(fd, MIXER_WRITE(SOUND_MIXER_MIC), &mic); |
206 | ::close(fd); | 207 | ::close(fd); |
207 | } | 208 | } |
208 | } break; | 209 | } break; |
209 | } | 210 | } |
210 | } | 211 | } |
211 | 212 | ||
212 | int qpe_sysBrightnessSteps() | 213 | int qpe_sysBrightnessSteps() |
213 | { | 214 | { |
214 | #if defined(QT_QWS_IPAQ) | 215 | #if defined(QT_QWS_IPAQ) |
215 | return 255; | 216 | return 255; |
216 | #elif defined(QT_QWS_EBX) | 217 | #elif defined(QT_QWS_EBX) |
217 | return 4; | 218 | return 4; |
218 | #else | 219 | #else |
219 | return 255; // ? | 220 | return 255; // ? |
220 | #endif | 221 | #endif |
221 | } | 222 | } |
222 | 223 | ||
223 | 224 | ||
224 | static int& hack(int& i) | 225 | static int& hack(int& i) |
225 | { | 226 | { |
226 | #if QT_VERSION <= 230 && defined(QT_NO_CODECS) | 227 | #if QT_VERSION <= 230 && defined(QT_NO_CODECS) |
227 | // These should be created, but aren't in Qt 2.3.0 | 228 | // These should be created, but aren't in Qt 2.3.0 |
228 | (void)new QUtf8Codec; | 229 | (void)new QUtf8Codec; |
229 | (void)new QUtf16Codec; | 230 | (void)new QUtf16Codec; |
230 | #endif | 231 | #endif |
231 | return i; | 232 | return i; |
232 | } | 233 | } |
233 | 234 | ||
234 | static bool forced_off = FALSE; | 235 | static bool forced_off = FALSE; |
235 | static int curbl=-1; | 236 | static int curbl=-1; |
236 | 237 | ||
237 | static int backlight() | 238 | static int backlight() |
238 | { | 239 | { |
239 | if ( curbl == -1 ) { | 240 | if ( curbl == -1 ) { |
240 | // Read from config | 241 | // Read from config |
241 | Config config( "qpe" ); | 242 | Config config( "qpe" ); |
242 | config.setGroup( "Screensaver" ); | 243 | config.setGroup( "Screensaver" ); |
243 | curbl = config.readNumEntry("Brightness",255); | 244 | curbl = config.readNumEntry("Brightness",255); |
244 | } | 245 | } |
245 | return curbl; | 246 | return curbl; |
246 | } | 247 | } |
247 | 248 | ||
248 | static void setBacklight(int bright) | 249 | static void setBacklight(int bright) |
249 | { | 250 | { |
250 | if ( bright == -3 ) { | 251 | if ( bright == -3 ) { |
251 | // Forced on | 252 | // Forced on |
252 | forced_off = FALSE; | 253 | forced_off = FALSE; |
253 | bright = -1; | 254 | bright = -1; |
254 | } | 255 | } |
255 | if ( forced_off && bright != -2 ) | 256 | if ( forced_off && bright != -2 ) |
256 | return; | 257 | return; |
257 | if ( bright == -2 ) { | 258 | if ( bright == -2 ) { |
258 | // Toggle between off and on | 259 | // Toggle between off and on |
259 | bright = curbl ? 0 : -1; | 260 | bright = curbl ? 0 : -1; |
260 | forced_off = !bright; | 261 | forced_off = !bright; |
261 | } | 262 | } |
262 | if ( bright == -1 ) { | 263 | if ( bright == -1 ) { |
263 | // Read from config | 264 | // Read from config |
264 | Config config( "qpe" ); | 265 | Config config( "qpe" ); |
265 | config.setGroup( "Screensaver" ); | 266 | config.setGroup( "Screensaver" ); |
266 | bright = config.readNumEntry("Brightness",255); | 267 | bright = config.readNumEntry("Brightness",255); |
267 | } | 268 | } |
268 | #if defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX) | 269 | #if defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX) |
269 | if ( QFile::exists("/usr/bin/bl") ) { | 270 | if ( QFile::exists("/usr/bin/bl") ) { |
270 | QString cmd = "/usr/bin/bl 1 "; | 271 | QString cmd = "/usr/bin/bl 1 "; |
271 | cmd += bright<=0 ? "0 " : "1 "; | 272 | cmd += bright<=0 ? "0 " : "1 "; |
272 | cmd += QString::number(bright); | 273 | cmd += QString::number(bright); |
273 | system(cmd.latin1()); | 274 | system(cmd.latin1()); |
274 | #if defined(QT_QWS_EBX) | 275 | #if defined(QT_QWS_EBX) |
275 | } else if ( QFile::exists("/dev/fl") ) { | 276 | } else if ( QFile::exists("/dev/fl") ) { |
276 | #define FL_IOCTL_STEP_CONTRAST 100 | 277 | #define FL_IOCTL_STEP_CONTRAST 100 |
277 | int fd = open("/dev/fl", O_WRONLY); | 278 | int fd = open("/dev/fl", O_WRONLY); |
278 | if (fd >= 0 ) { | 279 | if (fd >= 0 ) { |
279 | int steps = qpe_sysBrightnessSteps(); | 280 | int steps = qpe_sysBrightnessSteps(); |
280 | int bl = ( bright * steps + 127 ) / 255; | 281 | int bl = ( bright * steps + 127 ) / 255; |
281 | if ( bright && !bl ) bl = 1; | 282 | if ( bright && !bl ) bl = 1; |
282 | bl = ioctl(fd, FL_IOCTL_STEP_CONTRAST, bl); | 283 | bl = ioctl(fd, FL_IOCTL_STEP_CONTRAST, bl); |
283 | close(fd); | 284 | close(fd); |
284 | } | 285 | } |
285 | } | 286 | } |
286 | #elif defined(QT_QWS_IPAQ) | 287 | #elif defined(QT_QWS_IPAQ) |
287 | } else if ( QFile::exists("/dev/ts") || QFile::exists("/dev/h3600_ts") ) { | 288 | } else if ( QFile::exists("/dev/ts") || QFile::exists("/dev/h3600_ts") ) { |
288 | typedef struct { | 289 | typedef struct { |
289 | unsigned char mode; | 290 | unsigned char mode; |
290 | unsigned char pwr; | 291 | unsigned char pwr; |
291 | unsigned char brightness; | 292 | unsigned char brightness; |
292 | } FLITE_IN; | 293 | } FLITE_IN; |
293 | # ifndef FLITE_ON | 294 | # ifndef FLITE_ON |
294 | # ifndef _LINUX_IOCTL_H | 295 | # ifndef _LINUX_IOCTL_H |
295 | # include <linux/ioctl.h> | 296 | # include <linux/ioctl.h> |
296 | # endif | 297 | # endif |
297 | # define FLITE_ON _IOW('f', 7, FLITE_IN) | 298 | # define FLITE_ON _IOW('f', 7, FLITE_IN) |
298 | # endif | 299 | # endif |
299 | int fd; | 300 | int fd; |
300 | if ( QFile::exists("/dev/ts") ) | 301 | if ( QFile::exists("/dev/ts") ) |
301 | fd = open("/dev/ts", O_WRONLY); | 302 | fd = open("/dev/ts", O_WRONLY); |
302 | else | 303 | else |
303 | fd = open("/dev/h3600_ts", O_WRONLY); | 304 | fd = open("/dev/h3600_ts", O_WRONLY); |
304 | if (fd >= 0 ) { | 305 | if (fd >= 0 ) { |
305 | FLITE_IN bl; | 306 | FLITE_IN bl; |
306 | bl.mode = 1; | 307 | bl.mode = 1; |
307 | bl.pwr = bright ? 1 : 0; | 308 | bl.pwr = bright ? 1 : 0; |
308 | bl.brightness = bright; | 309 | bl.brightness = bright; |
309 | ioctl(fd, FLITE_ON, &bl); | 310 | ioctl(fd, FLITE_ON, &bl); |
310 | close(fd); | 311 | close(fd); |
311 | } | 312 | } |
312 | } | 313 | } |
313 | #endif | 314 | #endif |
314 | #endif | 315 | #endif |
315 | curbl = bright; | 316 | curbl = bright; |
316 | } | 317 | } |
317 | 318 | ||
318 | void qpe_setBacklight(int bright) { setBacklight(bright); } | 319 | void qpe_setBacklight(int bright) { setBacklight(bright); } |
319 | 320 | ||
320 | static bool dim_on = FALSE; | 321 | static bool dim_on = FALSE; |
321 | static bool lightoff_on = FALSE; | 322 | static bool lightoff_on = FALSE; |
322 | static int disable_suspend = 100; | 323 | static int disable_suspend = 100; |
323 | 324 | ||
324 | static bool powerOnline() | 325 | static bool powerOnline() |
325 | { | 326 | { |
326 | return PowerStatusManager::readStatus().acStatus() == PowerStatus::Online; | 327 | return PowerStatusManager::readStatus().acStatus() == PowerStatus::Online; |
327 | } | 328 | } |
328 | 329 | ||
329 | static bool networkOnline() | 330 | static bool networkOnline() |
330 | { | 331 | { |
331 | return Network::networkOnline(); | 332 | return Network::networkOnline(); |
332 | } | 333 | } |
333 | 334 | ||
334 | class QPEScreenSaver : public QWSScreenSaver | 335 | class QPEScreenSaver : public QWSScreenSaver |
335 | { | 336 | { |
336 | private: | 337 | private: |
337 | int LcdOn; | 338 | int LcdOn; |
338 | 339 | ||
339 | public: | 340 | public: |
340 | QPEScreenSaver() | 341 | QPEScreenSaver() |
341 | { | 342 | { |
342 | int fd; | 343 | int fd; |
343 | 344 | ||
344 | LcdOn = TRUE; | 345 | LcdOn = TRUE; |
345 | // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off) | 346 | // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off) |
346 | fd=open("/dev/fb0",O_RDWR); | 347 | fd=open("/dev/fb0",O_RDWR); |
347 | if (fd != -1) { ioctl(fd,FBIOBLANK,VESA_NO_BLANKING); close(fd); } | 348 | if (fd != -1) { ioctl(fd,FBIOBLANK,VESA_NO_BLANKING); close(fd); } |
348 | } | 349 | } |
349 | void restore() | 350 | void restore() |
350 | { | 351 | { |
351 | if (!LcdOn) // We must have turned it off | 352 | if (!LcdOn) // We must have turned it off |
352 | { | 353 | { |
353 | int fd; | 354 | int fd; |
354 | fd=open("/dev/fb0",O_RDWR); | 355 | fd=open("/dev/fb0",O_RDWR); |
355 | if (fd != -1) { ioctl(fd,FBIOBLANK,VESA_NO_BLANKING); close(fd); } | 356 | if (fd != -1) { ioctl(fd,FBIOBLANK,VESA_NO_BLANKING); close(fd); } |
356 | } | 357 | } |
357 | setBacklight(-1); | 358 | setBacklight(-1); |
358 | } | 359 | } |
359 | bool save(int level) | 360 | bool save(int level) |
360 | { | 361 | { |
361 | int fd; | 362 | int fd; |
362 | 363 | ||
363 | switch ( level ) { | 364 | switch ( level ) { |
364 | case 0: | 365 | case 0: |
365 | if ( disable_suspend > 0 && dim_on ) { | 366 | if ( disable_suspend > 0 && dim_on ) { |
366 | if (backlight() > 1) | 367 | if (backlight() > 1) |
367 | setBacklight(1); // lowest non-off | 368 | setBacklight(1); // lowest non-off |
368 | } | 369 | } |
369 | return TRUE; | 370 | return TRUE; |
370 | break; | 371 | break; |
371 | case 1: | 372 | case 1: |
372 | if ( disable_suspend > 1 && lightoff_on ) { | 373 | if ( disable_suspend > 1 && lightoff_on ) { |
373 | setBacklight(0); // off | 374 | setBacklight(0); // off |
374 | } | 375 | } |
375 | return TRUE; | 376 | return TRUE; |
376 | break; | 377 | break; |
377 | case 2: | 378 | case 2: |
378 | Config config( "qpe" ); | 379 | Config config( "qpe" ); |
379 | config.setGroup( "Screensaver" ); | 380 | config.setGroup( "Screensaver" ); |
380 | if (config.readNumEntry("LcdOffOnly",0) != 0) // We're only turning off the LCD | 381 | if (config.readNumEntry("LcdOffOnly",0) != 0) // We're only turning off the LCD |
381 | { | 382 | { |
382 | fd=open("/dev/fb0",O_RDWR); | 383 | fd=open("/dev/fb0",O_RDWR); |
383 | if (fd != -1) { ioctl(fd,FBIOBLANK,VESA_POWERDOWN); close(fd); } | 384 | if (fd != -1) { ioctl(fd,FBIOBLANK,VESA_POWERDOWN); close(fd); } |
384 | LcdOn = FALSE; | 385 | LcdOn = FALSE; |
385 | } | 386 | } |
386 | else // We're going to suspend the whole machine | 387 | else // We're going to suspend the whole machine |
387 | { | 388 | { |
388 | if ( disable_suspend > 2 && !powerOnline() && !networkOnline() ) { | 389 | if ( disable_suspend > 2 && !powerOnline() && !networkOnline() ) { |
389 | QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); | 390 | QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); |
390 | return TRUE; | 391 | return TRUE; |
391 | } | 392 | } |
392 | } | 393 | } |
393 | break; | 394 | break; |
394 | } | 395 | } |
395 | return FALSE; | 396 | return FALSE; |
396 | } | 397 | } |
397 | }; | 398 | }; |
398 | 399 | ||
399 | static int ssi(int interval, Config &config, const QString &enable, const QString& value, int def) | 400 | static int ssi(int interval, Config &config, const QString &enable, const QString& value, int def) |
400 | { | 401 | { |
401 | if ( !enable.isEmpty() && config.readNumEntry(enable,0) == 0 ) | 402 | if ( !enable.isEmpty() && config.readNumEntry(enable,0) == 0 ) |
402 | return 0; | 403 | return 0; |
403 | 404 | ||
404 | if ( interval < 0 ) { | 405 | if ( interval < 0 ) { |
405 | // Restore screen blanking and power saving state | 406 | // Restore screen blanking and power saving state |
406 | interval = config.readNumEntry( value, def ); | 407 | interval = config.readNumEntry( value, def ); |
407 | } | 408 | } |
408 | return interval; | 409 | return interval; |
409 | } | 410 | } |
410 | 411 | ||
411 | static void setScreenSaverIntervals(int i1, int i2, int i3) | 412 | static void setScreenSaverIntervals(int i1, int i2, int i3) |
412 | { | 413 | { |
413 | Config config( "qpe" ); | 414 | Config config( "qpe" ); |
414 | config.setGroup( "Screensaver" ); | 415 | config.setGroup( "Screensaver" ); |
415 | 416 | ||
416 | int v[4]; | 417 | int v[4]; |
417 | i1 = ssi(i1, config, "Dim","Interval_Dim", 30); | 418 | i1 = ssi(i1, config, "Dim","Interval_Dim", 30); |
418 | i2 = ssi(i2, config, "LightOff","Interval_LightOff", 20); | 419 | i2 = ssi(i2, config, "LightOff","Interval_LightOff", 20); |
419 | i3 = ssi(i3, config, "","Interval", 60); | 420 | i3 = ssi(i3, config, "","Interval", 60); |
420 | 421 | ||
421 | //qDebug("screen saver intervals: %d %d %d", i1, i2, i3); | 422 | //qDebug("screen saver intervals: %d %d %d", i1, i2, i3); |
422 | 423 | ||
423 | v[0] = QMAX( 1000*i1, 100); | 424 | v[0] = QMAX( 1000*i1, 100); |
424 | v[1] = QMAX( 1000*i2, 100); | 425 | v[1] = QMAX( 1000*i2, 100); |
425 | v[2] = QMAX( 1000*i3, 100); | 426 | v[2] = QMAX( 1000*i3, 100); |
426 | v[3] = 0; | 427 | v[3] = 0; |
427 | dim_on = ( (i1 != 0) ? config.readNumEntry("Dim",1) : FALSE ); | 428 | dim_on = ( (i1 != 0) ? config.readNumEntry("Dim",1) : FALSE ); |
428 | lightoff_on = ( (i2 != 0 ) ? config.readNumEntry("LightOff",1) : FALSE ); | 429 | lightoff_on = ( (i2 != 0 ) ? config.readNumEntry("LightOff",1) : FALSE ); |
429 | if ( !i1 && !i2 && !i3 ) | 430 | if ( !i1 && !i2 && !i3 ) |
430 | QWSServer::setScreenSaverInterval(0); | 431 | QWSServer::setScreenSaverInterval(0); |
431 | else | 432 | else |
432 | QWSServer::setScreenSaverIntervals(v); | 433 | QWSServer::setScreenSaverIntervals(v); |
433 | } | 434 | } |
434 | 435 | ||
435 | static void setScreenSaverInterval(int interval) | 436 | static void setScreenSaverInterval(int interval) |
436 | { | 437 | { |
437 | setScreenSaverIntervals(-1,-1,interval); | 438 | setScreenSaverIntervals(-1,-1,interval); |
438 | } | 439 | } |
439 | 440 | ||
440 | 441 | ||
441 | /*! | 442 | /*! |
442 | \class QPEApplication qpeapplication.h | 443 | \class QPEApplication qpeapplication.h |
443 | \brief The QPEApplication class implements various system services | 444 | \brief The QPEApplication class implements various system services |
444 | that are available to all Qtopia applications. | 445 | that are available to all Qtopia applications. |
445 | 446 | ||
446 | Simply by using QPEApplication instead of QApplication, a plain Qt | 447 | Simply by using QPEApplication instead of QApplication, a plain Qt |
447 | application becomes a Qtopia application. It automatically follows | 448 | application becomes a Qtopia application. It automatically follows |
448 | style changes, quits and raises, and in the | 449 | style changes, quits and raises, and in the |
449 | case of \link docwidget.html document-oriented\endlink applications, | 450 | case of \link docwidget.html document-oriented\endlink applications, |
450 | changes the current displayed document in response to the environment. | 451 | changes the current displayed document in response to the environment. |
451 | */ | 452 | */ |
452 | 453 | ||
453 | /*! | 454 | /*! |
454 | \fn void QPEApplication::clientMoused() | 455 | \fn void QPEApplication::clientMoused() |
455 | 456 | ||
456 | \internal | 457 | \internal |
457 | */ | 458 | */ |
458 | 459 | ||
459 | /*! | 460 | /*! |
460 | \fn void QPEApplication::timeChanged(); | 461 | \fn void QPEApplication::timeChanged(); |
461 | 462 | ||
462 | This signal is emitted when the time jumps forward or backwards | 463 | This signal is emitted when the time jumps forward or backwards |
463 | by more than the normal passage of time. | 464 | by more than the normal passage of time. |
464 | */ | 465 | */ |
465 | 466 | ||
466 | /*! | 467 | /*! |
467 | \fn void QPEApplication::clockChanged( bool ampm ); | 468 | \fn void QPEApplication::clockChanged( bool ampm ); |
468 | 469 | ||
469 | This signal is emitted when the user changes the style | 470 | This signal is emitted when the user changes the style |
470 | of clock. If \a ampm is TRUE, the user wants a 12-hour | 471 | of clock. If \a ampm is TRUE, the user wants a 12-hour |
471 | AM/PM close, otherwise, they want a 24-hour clock. | 472 | AM/PM close, otherwise, they want a 24-hour clock. |
472 | */ | 473 | */ |
473 | 474 | ||
474 | /*! | 475 | /*! |
475 | \fn void QPEApplication::appMessage( const QCString& msg, const QByteArray& data ) | 476 | \fn void QPEApplication::appMessage( const QCString& msg, const QByteArray& data ) |
476 | 477 | ||
@@ -933,722 +934,743 @@ void QPEApplication::applyStyle() | |||
933 | void QPEApplication::systemMessage( const QCString &msg, const QByteArray &data) | 934 | void QPEApplication::systemMessage( const QCString &msg, const QByteArray &data) |
934 | { | 935 | { |
935 | #ifdef Q_WS_QWS | 936 | #ifdef Q_WS_QWS |
936 | QDataStream stream( data, IO_ReadOnly ); | 937 | QDataStream stream( data, IO_ReadOnly ); |
937 | if ( msg == "applyStyle()" ) { | 938 | if ( msg == "applyStyle()" ) { |
938 | applyStyle(); | 939 | applyStyle(); |
939 | } else if ( msg == "setScreenSaverInterval(int)" ) { | 940 | } else if ( msg == "setScreenSaverInterval(int)" ) { |
940 | if ( type() == GuiServer ) { | 941 | if ( type() == GuiServer ) { |
941 | int time; | 942 | int time; |
942 | stream >> time; | 943 | stream >> time; |
943 | setScreenSaverInterval(time); | 944 | setScreenSaverInterval(time); |
944 | } | 945 | } |
945 | } else if ( msg == "setScreenSaverIntervals(int,int,int)" ) { | 946 | } else if ( msg == "setScreenSaverIntervals(int,int,int)" ) { |
946 | if ( type() == GuiServer ) { | 947 | if ( type() == GuiServer ) { |
947 | int t1,t2,t3; | 948 | int t1,t2,t3; |
948 | stream >> t1 >> t2 >> t3; | 949 | stream >> t1 >> t2 >> t3; |
949 | setScreenSaverIntervals(t1,t2,t3); | 950 | setScreenSaverIntervals(t1,t2,t3); |
950 | } | 951 | } |
951 | } else if ( msg == "setBacklight(int)" ) { | 952 | } else if ( msg == "setBacklight(int)" ) { |
952 | if ( type() == GuiServer ) { | 953 | if ( type() == GuiServer ) { |
953 | int bright; | 954 | int bright; |
954 | stream >> bright; | 955 | stream >> bright; |
955 | setBacklight(bright); | 956 | setBacklight(bright); |
956 | } | 957 | } |
957 | } else if ( msg == "setDefaultRotation(int)" ) { | 958 | } else if ( msg == "setDefaultRotation(int)" ) { |
958 | if ( type() == GuiServer ) { | 959 | if ( type() == GuiServer ) { |
959 | int r; | 960 | int r; |
960 | stream >> r; | 961 | stream >> r; |
961 | setDefaultRotation(r); | 962 | setDefaultRotation(r); |
962 | } | 963 | } |
963 | } else if ( msg == "shutdown()" ) { | 964 | } else if ( msg == "shutdown()" ) { |
964 | if ( type() == GuiServer ) | 965 | if ( type() == GuiServer ) |
965 | shutdown(); | 966 | shutdown(); |
966 | } else if ( msg == "quit()" ) { | 967 | } else if ( msg == "quit()" ) { |
967 | if ( type() != GuiServer ) | 968 | if ( type() != GuiServer ) |
968 | tryQuit(); | 969 | tryQuit(); |
969 | } else if ( msg == "forceQuit()" ) { | 970 | } else if ( msg == "forceQuit()" ) { |
970 | if ( type() != GuiServer ) | 971 | if ( type() != GuiServer ) |
971 | quit(); | 972 | quit(); |
972 | } else if ( msg == "restart()" ) { | 973 | } else if ( msg == "restart()" ) { |
973 | if ( type() == GuiServer ) | 974 | if ( type() == GuiServer ) |
974 | restart(); | 975 | restart(); |
975 | } else if ( msg == "grabKeyboard(QString)" ) { | 976 | } else if ( msg == "grabKeyboard(QString)" ) { |
976 | QString who; | 977 | QString who; |
977 | stream >> who; | 978 | stream >> who; |
978 | if ( who.isEmpty() ) | 979 | if ( who.isEmpty() ) |
979 | d->kbgrabber = 0; | 980 | d->kbgrabber = 0; |
980 | else if ( who != d->appName ) | 981 | else if ( who != d->appName ) |
981 | d->kbgrabber = 1; | 982 | d->kbgrabber = 1; |
982 | else | 983 | else |
983 | d->kbgrabber = 2; | 984 | d->kbgrabber = 2; |
984 | } else if ( msg == "language(QString)" ) { | 985 | } else if ( msg == "language(QString)" ) { |
985 | if ( type() == GuiServer ) { | 986 | if ( type() == GuiServer ) { |
986 | QString l; | 987 | QString l; |
987 | stream >> l; | 988 | stream >> l; |
988 | QString cl = getenv("LANG"); | 989 | QString cl = getenv("LANG"); |
989 | if ( cl != l ) { | 990 | if ( cl != l ) { |
990 | if ( l.isNull() ) | 991 | if ( l.isNull() ) |
991 | unsetenv( "LANG" ); | 992 | unsetenv( "LANG" ); |
992 | else | 993 | else |
993 | setenv( "LANG", l.latin1(), 1 ); | 994 | setenv( "LANG", l.latin1(), 1 ); |
994 | restart(); | 995 | restart(); |
995 | } | 996 | } |
996 | } | 997 | } |
997 | } else if ( msg == "timeChange(QString)" ) { | 998 | } else if ( msg == "timeChange(QString)" ) { |
998 | QString t; | 999 | QString t; |
999 | stream >> t; | 1000 | stream >> t; |
1000 | if ( t.isNull() ) | 1001 | if ( t.isNull() ) |
1001 | unsetenv( "TZ" ); | 1002 | unsetenv( "TZ" ); |
1002 | else | 1003 | else |
1003 | setenv( "TZ", t.latin1(), 1 ); | 1004 | setenv( "TZ", t.latin1(), 1 ); |
1004 | // emit the signal so everyone else knows... | 1005 | // emit the signal so everyone else knows... |
1005 | emit timeChanged(); | 1006 | emit timeChanged(); |
1006 | } else if ( msg == "execute(QString)" ) { | 1007 | } else if ( msg == "execute(QString)" ) { |
1007 | if ( type() == GuiServer ) { | 1008 | if ( type() == GuiServer ) { |
1008 | QString t; | 1009 | QString t; |
1009 | stream >> t; | 1010 | stream >> t; |
1010 | Global::execute( t ); | 1011 | Global::execute( t ); |
1011 | } | 1012 | } |
1012 | } else if ( msg == "execute(QString,QString)" ) { | 1013 | } else if ( msg == "execute(QString,QString)" ) { |
1013 | if ( type() == GuiServer ) { | 1014 | if ( type() == GuiServer ) { |
1014 | QString t,d; | 1015 | QString t,d; |
1015 | stream >> t >> d; | 1016 | stream >> t >> d; |
1016 | Global::execute( t, d ); | 1017 | Global::execute( t, d ); |
1017 | } | 1018 | } |
1018 | } else if ( msg == "addAlarm(QDateTime,QCString,QCString,int)" ) { | 1019 | } else if ( msg == "addAlarm(QDateTime,QCString,QCString,int)" ) { |
1019 | if ( type() == GuiServer ) { | 1020 | if ( type() == GuiServer ) { |
1020 | QDateTime when; | 1021 | QDateTime when; |
1021 | QCString channel, message; | 1022 | QCString channel, message; |
1022 | int data; | 1023 | int data; |
1023 | stream >> when >> channel >> message >> data; | 1024 | stream >> when >> channel >> message >> data; |
1024 | AlarmServer::addAlarm( when, channel, message, data ); | 1025 | AlarmServer::addAlarm( when, channel, message, data ); |
1025 | } | 1026 | } |
1026 | } else if ( msg == "deleteAlarm(QDateTime,QCString,QCString,int)" ) { | 1027 | } else if ( msg == "deleteAlarm(QDateTime,QCString,QCString,int)" ) { |
1027 | if ( type() == GuiServer ) { | 1028 | if ( type() == GuiServer ) { |
1028 | QDateTime when; | 1029 | QDateTime when; |
1029 | QCString channel, message; | 1030 | QCString channel, message; |
1030 | int data; | 1031 | int data; |
1031 | stream >> when >> channel >> message >> data; | 1032 | stream >> when >> channel >> message >> data; |
1032 | AlarmServer::deleteAlarm( when, channel, message, data ); | 1033 | AlarmServer::deleteAlarm( when, channel, message, data ); |
1033 | } | 1034 | } |
1034 | } else if ( msg == "clockChange(bool)" ) { | 1035 | } else if ( msg == "clockChange(bool)" ) { |
1035 | int tmp; | 1036 | int tmp; |
1036 | stream >> tmp; | 1037 | stream >> tmp; |
1037 | emit clockChanged( tmp ); | 1038 | emit clockChanged( tmp ); |
1038 | } else if ( msg == "weekChange(bool)" ) { | 1039 | } else if ( msg == "weekChange(bool)" ) { |
1039 | int tmp; | 1040 | int tmp; |
1040 | stream >> tmp; | 1041 | stream >> tmp; |
1041 | emit weekChanged( tmp ); | 1042 | emit weekChanged( tmp ); |
1042 | } else if ( msg == "setDateFormat(DateFormat)" ) { | 1043 | } else if ( msg == "setDateFormat(DateFormat)" ) { |
1043 | DateFormat tmp; | 1044 | DateFormat tmp; |
1044 | stream >> tmp; | 1045 | stream >> tmp; |
1045 | emit dateFormatChanged( tmp ); | 1046 | emit dateFormatChanged( tmp ); |
1046 | } else if ( msg == "setVolume(int,int)" ) { | 1047 | } else if ( msg == "setVolume(int,int)" ) { |
1047 | int t,v; | 1048 | int t,v; |
1048 | stream >> t >> v; | 1049 | stream >> t >> v; |
1049 | setVolume(t,v); | 1050 | setVolume(t,v); |
1050 | emit volumeChanged( muted ); | 1051 | emit volumeChanged( muted ); |
1051 | } else if ( msg == "volumeChange(bool)" ) { | 1052 | } else if ( msg == "volumeChange(bool)" ) { |
1052 | stream >> muted; | 1053 | stream >> muted; |
1053 | setVolume(); | 1054 | setVolume(); |
1054 | emit volumeChanged( muted ); | 1055 | emit volumeChanged( muted ); |
1055 | } else if ( msg == "setMic(int,int)") { // Added: 2002-02-08 by Jeremy Cowgar <jc@cowgar.com> | 1056 | } else if ( msg == "setMic(int,int)") { // Added: 2002-02-08 by Jeremy Cowgar <jc@cowgar.com> |
1056 | int t,v; | 1057 | int t,v; |
1057 | stream >> t >> v; | 1058 | stream >> t >> v; |
1058 | setMic(t,v); | 1059 | setMic(t,v); |
1059 | emit micChanged( micMuted ); | 1060 | emit micChanged( micMuted ); |
1060 | } else if ( msg == "micChange(bool)" ) { // Added: 2002-02-08 by Jeremy Cowgar <jc@cowgar.com> | 1061 | } else if ( msg == "micChange(bool)" ) { // Added: 2002-02-08 by Jeremy Cowgar <jc@cowgar.com> |
1061 | stream >> micMuted; | 1062 | stream >> micMuted; |
1062 | setMic(); | 1063 | setMic(); |
1063 | emit micChanged( micMuted ); | 1064 | emit micChanged( micMuted ); |
1064 | } else if ( msg == "setScreenSaverMode(int)" ) { | 1065 | } else if ( msg == "setScreenSaverMode(int)" ) { |
1065 | if ( type() == GuiServer ) { | 1066 | if ( type() == GuiServer ) { |
1066 | int old = disable_suspend; | 1067 | int old = disable_suspend; |
1067 | stream >> disable_suspend; | 1068 | stream >> disable_suspend; |
1068 | //qDebug("setScreenSaverMode(%d)", disable_suspend ); | 1069 | //qDebug("setScreenSaverMode(%d)", disable_suspend ); |
1069 | if ( disable_suspend > old ) | 1070 | if ( disable_suspend > old ) |
1070 | setScreenSaverInterval( -1 ); | 1071 | setScreenSaverInterval( -1 ); |
1071 | } | 1072 | } |
1072 | } | 1073 | } |
1073 | #endif | 1074 | #endif |
1074 | } | 1075 | } |
1075 | 1076 | ||
1076 | /*! | 1077 | /*! |
1077 | \internal | 1078 | \internal |
1078 | */ | 1079 | */ |
1079 | bool QPEApplication::raiseAppropriateWindow() | 1080 | bool QPEApplication::raiseAppropriateWindow() |
1080 | { | 1081 | { |
1081 | bool r=FALSE; | 1082 | bool r=FALSE; |
1082 | // ########## raise()ing main window should raise and set active | 1083 | // ########## raise()ing main window should raise and set active |
1083 | // ########## it and then all childen. This belongs in Qt/Embedded | 1084 | // ########## it and then all childen. This belongs in Qt/Embedded |
1084 | QWidget *top = d->qpe_main_widget; | 1085 | QWidget *top = d->qpe_main_widget; |
1085 | if ( !top ) top =mainWidget(); | 1086 | if ( !top ) top =mainWidget(); |
1086 | if ( top && d->keep_running ) { | 1087 | if ( top && d->keep_running ) { |
1087 | if ( top->isVisible() ) | 1088 | if ( top->isVisible() ) |
1088 | r = TRUE; | 1089 | r = TRUE; |
1089 | #ifdef Q_WS_QWS | 1090 | #ifdef Q_WS_QWS |
1090 | if ( !d->nomaximize ) | 1091 | if ( !d->nomaximize ) |
1091 | top->showMaximized(); | 1092 | top->showMaximized(); |
1092 | else | 1093 | else |
1093 | #endif | 1094 | #endif |
1094 | top->show(); | 1095 | top->show(); |
1095 | top->raise(); | 1096 | top->raise(); |
1096 | top->setActiveWindow(); | 1097 | top->setActiveWindow(); |
1097 | } | 1098 | } |
1098 | QWidget *topm = activeModalWidget(); | 1099 | QWidget *topm = activeModalWidget(); |
1099 | if ( topm && topm != top ) { | 1100 | if ( topm && topm != top ) { |
1100 | topm->show(); | 1101 | topm->show(); |
1101 | topm->raise(); | 1102 | topm->raise(); |
1102 | topm->setActiveWindow(); | 1103 | topm->setActiveWindow(); |
1103 | r = FALSE; | 1104 | r = FALSE; |
1104 | } | 1105 | } |
1105 | return r; | 1106 | return r; |
1106 | } | 1107 | } |
1107 | 1108 | ||
1108 | void QPEApplication::pidMessage( const QCString &msg, const QByteArray & data) | 1109 | void QPEApplication::pidMessage( const QCString &msg, const QByteArray & data) |
1109 | { | 1110 | { |
1110 | #ifdef Q_WS_QWS | 1111 | #ifdef Q_WS_QWS |
1111 | 1112 | ||
1112 | if ( msg == "quit()" ) { | 1113 | if ( msg == "quit()" ) { |
1113 | tryQuit(); | 1114 | tryQuit(); |
1114 | } else if ( msg == "quitIfInvisible()" ) { | 1115 | } else if ( msg == "quitIfInvisible()" ) { |
1115 | if ( d->qpe_main_widget && !d->qpe_main_widget->isVisible() ) | 1116 | if ( d->qpe_main_widget && !d->qpe_main_widget->isVisible() ) |
1116 | quit(); | 1117 | quit(); |
1117 | } else if ( msg == "close()" ) { | 1118 | } else if ( msg == "close()" ) { |
1118 | hideOrQuit(); | 1119 | hideOrQuit(); |
1119 | } else if ( msg == "disablePreload()" ) { | 1120 | } else if ( msg == "disablePreload()" ) { |
1120 | d->preloaded = FALSE; | 1121 | d->preloaded = FALSE; |
1121 | d->keep_running = TRUE; | 1122 | d->keep_running = TRUE; |
1122 | /* so that quit will quit */ | 1123 | /* so that quit will quit */ |
1123 | } else if ( msg == "enablePreload()" ) { | 1124 | } else if ( msg == "enablePreload()" ) { |
1124 | d->preloaded = TRUE; | 1125 | d->preloaded = TRUE; |
1125 | d->keep_running = TRUE; | 1126 | d->keep_running = TRUE; |
1126 | /* so next quit won't quit */ | 1127 | /* so next quit won't quit */ |
1127 | } else if ( msg == "raise()" ) { | 1128 | } else if ( msg == "raise()" ) { |
1128 | d->keep_running = TRUE; | 1129 | d->keep_running = TRUE; |
1129 | d->notbusysent = FALSE; | 1130 | d->notbusysent = FALSE; |
1130 | raiseAppropriateWindow(); | 1131 | raiseAppropriateWindow(); |
1131 | } else if ( msg == "flush()" ) { | 1132 | } else if ( msg == "flush()" ) { |
1132 | emit flush(); | 1133 | emit flush(); |
1133 | // we need to tell the desktop | 1134 | // we need to tell the desktop |
1134 | QCopEnvelope e( "QPE/Desktop", "flushDone(QString)" ); | 1135 | QCopEnvelope e( "QPE/Desktop", "flushDone(QString)" ); |
1135 | e << d->appName; | 1136 | e << d->appName; |
1136 | } else if ( msg == "reload()" ) { | 1137 | } else if ( msg == "reload()" ) { |
1137 | emit reload(); | 1138 | emit reload(); |
1138 | } else if ( msg == "setDocument(QString)" ) { | 1139 | } else if ( msg == "setDocument(QString)" ) { |
1139 | d->keep_running = TRUE; | 1140 | d->keep_running = TRUE; |
1140 | QDataStream stream( data, IO_ReadOnly ); | 1141 | QDataStream stream( data, IO_ReadOnly ); |
1141 | QString doc; | 1142 | QString doc; |
1142 | stream >> doc; | 1143 | stream >> doc; |
1143 | QWidget *mw = mainWidget(); | 1144 | QWidget *mw = mainWidget(); |
1144 | if ( !mw ) | 1145 | if ( !mw ) |
1145 | mw = d->qpe_main_widget; | 1146 | mw = d->qpe_main_widget; |
1146 | if ( mw ) | 1147 | if ( mw ) |
1147 | Global::setDocument( mw, doc ); | 1148 | Global::setDocument( mw, doc ); |
1148 | } else if ( msg == "nextView()" ) { | 1149 | } else if ( msg == "nextView()" ) { |
1149 | if ( raiseAppropriateWindow() ) | 1150 | if ( raiseAppropriateWindow() ) |
1150 | emit appMessage( msg, data); | 1151 | emit appMessage( msg, data); |
1151 | } else { | 1152 | } else { |
1152 | emit appMessage( msg, data); | 1153 | emit appMessage( msg, data); |
1153 | } | 1154 | } |
1154 | #endif | 1155 | #endif |
1155 | } | 1156 | } |
1156 | 1157 | ||
1157 | 1158 | ||
1158 | static bool setWidgetCaptionFromAppName( QWidget* /*mw*/, const QString& /*appName*/, const QString& /*appsPath*/ ) | 1159 | static bool setWidgetCaptionFromAppName( QWidget* /*mw*/, const QString& /*appName*/, const QString& /*appsPath*/ ) |
1159 | { | 1160 | { |
1160 | /* | 1161 | /* |
1161 | // This works but disable it for now until it is safe to apply | 1162 | // This works but disable it for now until it is safe to apply |
1162 | // What is does is scan the .desktop files of all the apps for | 1163 | // What is does is scan the .desktop files of all the apps for |
1163 | // the applnk that has the corresponding argv[0] as this program | 1164 | // the applnk that has the corresponding argv[0] as this program |
1164 | // then it uses the name stored in the .desktop file as the caption | 1165 | // then it uses the name stored in the .desktop file as the caption |
1165 | // for the main widget. This saves duplicating translations for | 1166 | // for the main widget. This saves duplicating translations for |
1166 | // the app name in the program and in the .desktop files. | 1167 | // the app name in the program and in the .desktop files. |
1167 | 1168 | ||
1168 | AppLnkSet apps( appsPath ); | 1169 | AppLnkSet apps( appsPath ); |
1169 | 1170 | ||
1170 | QList<AppLnk> appsList = apps.children(); | 1171 | QList<AppLnk> appsList = apps.children(); |
1171 | for ( QListIterator<AppLnk> it(appsList); it.current(); ++it ) { | 1172 | for ( QListIterator<AppLnk> it(appsList); it.current(); ++it ) { |
1172 | if ( (*it)->exec() == appName ) { | 1173 | if ( (*it)->exec() == appName ) { |
1173 | mw->setCaption( (*it)->name() ); | 1174 | mw->setCaption( (*it)->name() ); |
1174 | return TRUE; | 1175 | return TRUE; |
1175 | } | 1176 | } |
1176 | } | 1177 | } |
1177 | */ | 1178 | */ |
1178 | return FALSE; | 1179 | return FALSE; |
1179 | } | 1180 | } |
1180 | 1181 | ||
1181 | 1182 | ||
1182 | /*! | 1183 | /*! |
1183 | Sets \a mw as the mainWidget() and shows it. For small windows, | 1184 | Sets \a mw as the mainWidget() and shows it. For small windows, |
1184 | consider passing TRUE for \a nomaximize rather than the default FALSE. | 1185 | consider passing TRUE for \a nomaximize rather than the default FALSE. |
1185 | 1186 | ||
1186 | \sa showMainDocumentWidget() | 1187 | \sa showMainDocumentWidget() |
1187 | */ | 1188 | */ |
1188 | void QPEApplication::showMainWidget( QWidget* mw, bool nomaximize ) | 1189 | void QPEApplication::showMainWidget( QWidget* mw, bool nomaximize ) |
1189 | { | 1190 | { |
1190 | setWidgetCaptionFromAppName( mw, d->appName, qpeDir() + "apps" ); | 1191 | setWidgetCaptionFromAppName( mw, d->appName, qpeDir() + "apps" ); |
1191 | 1192 | ||
1192 | d->nomaximize = nomaximize; | 1193 | d->nomaximize = nomaximize; |
1193 | d->qpe_main_widget = mw; | 1194 | d->qpe_main_widget = mw; |
1194 | d->sendQCopQ(); | 1195 | d->sendQCopQ(); |
1195 | if ( d->preloaded ) { | 1196 | if ( d->preloaded ) { |
1196 | if(d->forceshow) { | 1197 | if(d->forceshow) { |
1197 | #ifdef Q_WS_QWS | 1198 | #ifdef Q_WS_QWS |
1198 | if ( !nomaximize ) | 1199 | if ( !nomaximize ) |
1199 | mw->showMaximized(); | 1200 | mw->showMaximized(); |
1200 | else | 1201 | else |
1201 | #endif | 1202 | #endif |
1202 | mw->show(); | 1203 | mw->show(); |
1203 | } | 1204 | } |
1204 | } else if ( d->keep_running ) { | 1205 | } else if ( d->keep_running ) { |
1205 | #ifdef Q_WS_QWS | 1206 | #ifdef Q_WS_QWS |
1206 | if ( !nomaximize ) | 1207 | if ( !nomaximize ) |
1207 | mw->showMaximized(); | 1208 | mw->showMaximized(); |
1208 | else | 1209 | else |
1209 | #endif | 1210 | #endif |
1210 | mw->show(); | 1211 | mw->show(); |
1211 | } | 1212 | } |
1212 | } | 1213 | } |
1213 | 1214 | ||
1214 | /*! | 1215 | /*! |
1215 | Sets \a mw as the mainWidget() and shows it. For small windows, | 1216 | Sets \a mw as the mainWidget() and shows it. For small windows, |
1216 | consider passing TRUE for \a nomaximize rather than the default FALSE. | 1217 | consider passing TRUE for \a nomaximize rather than the default FALSE. |
1217 | 1218 | ||
1218 | This calls designates the application as | 1219 | This calls designates the application as |
1219 | a \link docwidget.html document-oriented\endlink application. | 1220 | a \link docwidget.html document-oriented\endlink application. |
1220 | 1221 | ||
1221 | The \a mw widget must have a slot: setDocument(const QString&). | 1222 | The \a mw widget must have a slot: setDocument(const QString&). |
1222 | 1223 | ||
1223 | \sa showMainWidget() | 1224 | \sa showMainWidget() |
1224 | */ | 1225 | */ |
1225 | void QPEApplication::showMainDocumentWidget( QWidget* mw, bool nomaximize ) | 1226 | void QPEApplication::showMainDocumentWidget( QWidget* mw, bool nomaximize ) |
1226 | { | 1227 | { |
1227 | setWidgetCaptionFromAppName( mw, d->appName, qpeDir() + "apps" ); | 1228 | setWidgetCaptionFromAppName( mw, d->appName, qpeDir() + "apps" ); |
1228 | 1229 | ||
1229 | if ( mw && argc() == 2 ) | 1230 | if ( mw && argc() == 2 ) |
1230 | Global::setDocument( mw, QString::fromUtf8(argv()[1]) ); | 1231 | Global::setDocument( mw, QString::fromUtf8(argv()[1]) ); |
1231 | d->nomaximize = nomaximize; | 1232 | d->nomaximize = nomaximize; |
1232 | d->qpe_main_widget = mw; | 1233 | d->qpe_main_widget = mw; |
1233 | d->sendQCopQ(); | 1234 | d->sendQCopQ(); |
1234 | if ( d->preloaded ) { | 1235 | if ( d->preloaded ) { |
1235 | if(d->forceshow) { | 1236 | if(d->forceshow) { |
1236 | #ifdef Q_WS_QWS | 1237 | #ifdef Q_WS_QWS |
1237 | if ( !nomaximize ) | 1238 | if ( !nomaximize ) |
1238 | mw->showMaximized(); | 1239 | mw->showMaximized(); |
1239 | else | 1240 | else |
1240 | #endif | 1241 | #endif |
1241 | mw->show(); | 1242 | mw->show(); |
1242 | } | 1243 | } |
1243 | } else if ( d->keep_running ) { | 1244 | } else if ( d->keep_running ) { |
1244 | #ifdef Q_WS_QWS | 1245 | #ifdef Q_WS_QWS |
1245 | if ( !nomaximize ) | 1246 | if ( !nomaximize ) |
1246 | mw->showMaximized(); | 1247 | mw->showMaximized(); |
1247 | else | 1248 | else |
1248 | #endif | 1249 | #endif |
1249 | mw->show(); | 1250 | mw->show(); |
1250 | } | 1251 | } |
1251 | } | 1252 | } |
1252 | 1253 | ||
1253 | 1254 | ||
1254 | /*! | 1255 | /*! |
1255 | Sets that the application should continue running after processing | 1256 | Sets that the application should continue running after processing |
1256 | qcop messages. Normally if an application is started via a qcop message, | 1257 | qcop messages. Normally if an application is started via a qcop message, |
1257 | the application will process the qcop message and then quit. If while | 1258 | the application will process the qcop message and then quit. If while |
1258 | processing the qcop message it calls this function, then the application | 1259 | processing the qcop message it calls this function, then the application |
1259 | will show and start proper once it has finished processing qcop messages. | 1260 | will show and start proper once it has finished processing qcop messages. |
1260 | 1261 | ||
1261 | \sa keepRunning() | 1262 | \sa keepRunning() |
1262 | */ | 1263 | */ |
1263 | void QPEApplication::setKeepRunning() | 1264 | void QPEApplication::setKeepRunning() |
1264 | { | 1265 | { |
1265 | if ( qApp && qApp->inherits( "QPEApplication" ) ) { | 1266 | if ( qApp && qApp->inherits( "QPEApplication" ) ) { |
1266 | QPEApplication *qpeApp = (QPEApplication*)qApp; | 1267 | QPEApplication *qpeApp = (QPEApplication*)qApp; |
1267 | qpeApp->d->keep_running = TRUE; | 1268 | qpeApp->d->keep_running = TRUE; |
1268 | } | 1269 | } |
1269 | } | 1270 | } |
1270 | 1271 | ||
1271 | /*! | 1272 | /*! |
1272 | Returns whether the application will quit after processing the current | 1273 | Returns whether the application will quit after processing the current |
1273 | list of qcop messages. | 1274 | list of qcop messages. |
1274 | 1275 | ||
1275 | \sa setKeepRunning() | 1276 | \sa setKeepRunning() |
1276 | */ | 1277 | */ |
1277 | bool QPEApplication::keepRunning() const | 1278 | bool QPEApplication::keepRunning() const |
1278 | { | 1279 | { |
1279 | return d->keep_running; | 1280 | return d->keep_running; |
1280 | } | 1281 | } |
1281 | 1282 | ||
1282 | /*! | 1283 | /*! |
1283 | \internal | 1284 | \internal |
1284 | */ | 1285 | */ |
1285 | void QPEApplication::internalSetStyle( const QString &style ) | 1286 | void QPEApplication::internalSetStyle( const QString &style ) |
1286 | { | 1287 | { |
1287 | #if QT_VERSION >= 300 | 1288 | #if QT_VERSION >= 300 |
1288 | if ( style == "QPE" ) { | 1289 | if ( style == "QPE" ) { |
1289 | setStyle( new QPEStyle ); | 1290 | setStyle( new QPEStyle ); |
1290 | } else { | 1291 | } else { |
1291 | QStyle *s = QStyleFactory::create(style); | 1292 | QStyle *s = QStyleFactory::create(style); |
1292 | if ( s ) setStyle(s); | 1293 | if ( s ) setStyle(s); |
1293 | } | 1294 | } |
1294 | #else | 1295 | #else |
1295 | if ( style == "Windows" ) { | 1296 | if ( style == "Windows" ) { |
1296 | setStyle( new QWindowsStyle ); | 1297 | setStyle( new QWindowsStyle ); |
1297 | } else if ( style == "QPE" ) { | 1298 | } else if ( style == "QPE" ) { |
1298 | setStyle( new QPEStyle ); | 1299 | setStyle( new QPEStyle ); |
1299 | } else if ( style == "Light" ) { | 1300 | } else if ( style == "Light" ) { |
1300 | setStyle( new LightStyle ); | 1301 | setStyle( new LightStyle ); |
1301 | } | 1302 | } |
1302 | #ifndef QT_NO_STYLE_PLATINUM | 1303 | #ifndef QT_NO_STYLE_PLATINUM |
1303 | else if ( style == "Platinum" ) { | 1304 | else if ( style == "Platinum" ) { |
1304 | setStyle( new QPlatinumStyle ); | 1305 | setStyle( new QPlatinumStyle ); |
1305 | } | 1306 | } |
1306 | #endif | 1307 | #endif |
1307 | #ifndef QT_NO_STYLE_MOTIF | 1308 | #ifndef QT_NO_STYLE_MOTIF |
1308 | else if ( style == "Motif" ) { | 1309 | else if ( style == "Motif" ) { |
1309 | setStyle( new QMotifStyle ); | 1310 | setStyle( new QMotifStyle ); |
1310 | } | 1311 | } |
1311 | #endif | 1312 | #endif |
1312 | #ifndef QT_NO_STYLE_MOTIFPLUS | 1313 | #ifndef QT_NO_STYLE_MOTIFPLUS |
1313 | else if ( style == "MotifPlus" ) { | 1314 | else if ( style == "MotifPlus" ) { |
1314 | setStyle( new QMotifPlusStyle ); | 1315 | setStyle( new QMotifPlusStyle ); |
1315 | } | 1316 | } |
1316 | #endif | 1317 | #endif |
1318 | |||
1319 | // HACK for Qt2 only | ||
1320 | else if ( style == "Liquid" ) { | ||
1321 | static void *lib = 0; | ||
1322 | QStyle *sty = 0; | ||
1323 | |||
1324 | |||
1325 | if ( !lib ) { | ||
1326 | QString path = QPEApplication::qpeDir() + "/plugins/styles/" + "libliquid.so"; | ||
1327 | lib = ::dlopen ( path. local8Bit ( ), RTLD_NOW | RTLD_GLOBAL ); | ||
1328 | } | ||
1329 | if ( lib ) { | ||
1330 | void *sym = ::dlsym ( lib, "allocate" ); | ||
1331 | |||
1332 | if ( sym ) | ||
1333 | sty = ((QStyle * (*) ( )) sym ) ( ); | ||
1334 | } | ||
1335 | if ( sty ) | ||
1336 | setStyle ( sty ); | ||
1337 | } | ||
1338 | // HACK for Qt2 only | ||
1317 | #endif | 1339 | #endif |
1318 | } | 1340 | } |
1319 | 1341 | ||
1320 | /*! | 1342 | /*! |
1321 | \internal | 1343 | \internal |
1322 | */ | 1344 | */ |
1323 | void QPEApplication::prepareForTermination(bool willrestart) | 1345 | void QPEApplication::prepareForTermination(bool willrestart) |
1324 | { | 1346 | { |
1325 | if ( willrestart ) { | 1347 | if ( willrestart ) { |
1326 | // Draw a big wait icon, the image can be altered in later revisions | 1348 | // Draw a big wait icon, the image can be altered in later revisions |
1327 | // QWidget *d = QApplication::desktop(); | 1349 | // QWidget *d = QApplication::desktop(); |
1328 | QImage img = Resource::loadImage( "launcher/new_wait" ); | 1350 | QImage img = Resource::loadImage( "launcher/new_wait" ); |
1329 | QPixmap pix; | 1351 | QPixmap pix; |
1330 | pix.convertFromImage(img.smoothScale(1*img.width(), 1*img.height())); | 1352 | pix.convertFromImage(img.smoothScale(1*img.width(), 1*img.height())); |
1331 | QLabel *lblWait = new QLabel(0, "wait hack!", QWidget::WStyle_Customize | | 1353 | QLabel *lblWait = new QLabel(0, "wait hack!", QWidget::WStyle_Customize | |
1332 | QWidget::WStyle_NoBorder | QWidget::WStyle_Tool ); | 1354 | QWidget::WStyle_NoBorder | QWidget::WStyle_Tool ); |
1333 | lblWait->setPixmap( pix ); | 1355 | lblWait->setPixmap( pix ); |
1334 | lblWait->setAlignment( QWidget::AlignCenter ); | 1356 | lblWait->setAlignment( QWidget::AlignCenter ); |
1335 | lblWait->show(); | 1357 | lblWait->show(); |
1336 | lblWait->showMaximized(); | 1358 | lblWait->showMaximized(); |
1337 | } | 1359 | } |
1338 | #ifndef SINGLE_APP | 1360 | #ifndef SINGLE_APP |
1339 | { QCopEnvelope envelope("QPE/System", "forceQuit()"); } | 1361 | { QCopEnvelope envelope("QPE/System", "forceQuit()"); } |
1340 | processEvents(); // ensure the message goes out. | 1362 | processEvents(); // ensure the message goes out. |
1341 | sleep(1); // You have 1 second to comply. | 1363 | sleep(1); // You have 1 second to comply. |
1342 | #endif | 1364 | #endif |
1343 | } | 1365 | } |
1344 | 1366 | ||
1345 | /*! | 1367 | /*! |
1346 | \internal | 1368 | \internal |
1347 | */ | 1369 | */ |
1348 | void QPEApplication::shutdown() | 1370 | void QPEApplication::shutdown() |
1349 | { | 1371 | { |
1350 | // Implement in server's QPEApplication subclass | 1372 | // Implement in server's QPEApplication subclass |
1351 | } | 1373 | } |
1352 | 1374 | ||
1353 | /*! | 1375 | /*! |
1354 | \internal | 1376 | \internal |
1355 | */ | 1377 | */ |
1356 | void QPEApplication::restart() | 1378 | void QPEApplication::restart() |
1357 | { | 1379 | { |
1358 | // Implement in server's QPEApplication subclass | 1380 | // Implement in server's QPEApplication subclass |
1359 | } | 1381 | } |
1360 | 1382 | ||
1361 | static QPtrDict<void>* stylusDict=0; | 1383 | static QPtrDict<void>* stylusDict=0; |
1362 | static void createDict() | 1384 | static void createDict() |
1363 | { | 1385 | { |
1364 | if ( !stylusDict ) | 1386 | if ( !stylusDict ) |
1365 | stylusDict = new QPtrDict<void>; | 1387 | stylusDict = new QPtrDict<void>; |
1366 | } | 1388 | } |
1367 | 1389 | ||
1368 | /*! | 1390 | /*! |
1369 | Returns the current StylusMode for \a w. | 1391 | Returns the current StylusMode for \a w. |
1370 | 1392 | ||
1371 | \sa setStylusOperation() | 1393 | \sa setStylusOperation() |
1372 | */ | 1394 | */ |
1373 | QPEApplication::StylusMode QPEApplication::stylusOperation( QWidget* w ) | 1395 | QPEApplication::StylusMode QPEApplication::stylusOperation( QWidget* w ) |
1374 | { | 1396 | { |
1375 | if ( stylusDict ) | 1397 | if ( stylusDict ) |
1376 | return (StylusMode)(int)stylusDict->find(w); | 1398 | return (StylusMode)(int)stylusDict->find(w); |
1377 | return LeftOnly; | 1399 | return LeftOnly; |
1378 | } | 1400 | } |
1379 | 1401 | ||
1380 | /*! | 1402 | /*! |
1381 | \enum QPEApplication::StylusMode | 1403 | \enum QPEApplication::StylusMode |
1382 | 1404 | ||
1383 | \value LeftOnly the stylus only generates LeftButton | 1405 | \value LeftOnly the stylus only generates LeftButton |
1384 | events (the default). | 1406 | events (the default). |
1385 | \value RightOnHold the stylus generates RightButton events | 1407 | \value RightOnHold the stylus generates RightButton events |
1386 | if the user uses the press-and-hold gesture. | 1408 | if the user uses the press-and-hold gesture. |
1387 | 1409 | ||
1388 | See setStylusOperation(). | 1410 | See setStylusOperation(). |
1389 | */ | 1411 | */ |
1390 | 1412 | ||
1391 | /*! | 1413 | /*! |
1392 | Causes \a w to receive mouse events according to \a mode. | 1414 | Causes \a w to receive mouse events according to \a mode. |
1393 | 1415 | ||
1394 | \sa stylusOperation() | 1416 | \sa stylusOperation() |
1395 | */ | 1417 | */ |
1396 | void QPEApplication::setStylusOperation( QWidget* w, StylusMode mode ) | 1418 | void QPEApplication::setStylusOperation( QWidget* w, StylusMode mode ) |
1397 | { | 1419 | { |
1398 | createDict(); | 1420 | createDict(); |
1399 | if ( mode == LeftOnly ) { | 1421 | if ( mode == LeftOnly ) { |
1400 | stylusDict->remove(w); | 1422 | stylusDict->remove(w); |
1401 | w->removeEventFilter(qApp); | 1423 | w->removeEventFilter(qApp); |
1402 | } else { | 1424 | } else { |
1403 | stylusDict->insert(w,(void*)mode); | 1425 | stylusDict->insert(w,(void*)mode); |
1404 | connect(w,SIGNAL(destroyed()),qApp,SLOT(removeSenderFromStylusDict())); | 1426 | connect(w,SIGNAL(destroyed()),qApp,SLOT(removeSenderFromStylusDict())); |
1405 | w->installEventFilter(qApp); | 1427 | w->installEventFilter(qApp); |
1406 | } | 1428 | } |
1407 | } | 1429 | } |
1408 | 1430 | ||
1409 | 1431 | ||
1410 | /*! | 1432 | /*! |
1411 | \reimp | 1433 | \reimp |
1412 | */ | 1434 | */ |
1413 | bool QPEApplication::eventFilter( QObject *o, QEvent *e ) | 1435 | bool QPEApplication::eventFilter( QObject *o, QEvent *e ) |
1414 | { | 1436 | { |
1415 | if ( stylusDict && e->type() >= QEvent::MouseButtonPress && e->type() <= QEvent::MouseMove ) { | 1437 | if ( stylusDict && e->type() >= QEvent::MouseButtonPress && e->type() <= QEvent::MouseMove ) { |
1416 | QMouseEvent* me = (QMouseEvent*)e; | 1438 | QMouseEvent* me = (QMouseEvent*)e; |
1417 | if ( me->button() == LeftButton ) { | 1439 | if ( me->button() == LeftButton ) { |
1418 | StylusMode mode = (StylusMode)(int)stylusDict->find(o); | 1440 | StylusMode mode = (StylusMode)(int)stylusDict->find(o); |
1419 | switch (mode) { | 1441 | switch (mode) { |
1420 | case RightOnHold: | 1442 | case RightOnHold: |
1421 | switch ( me->type() ) { | 1443 | switch ( me->type() ) { |
1422 | case QEvent::MouseButtonPress: | 1444 | case QEvent::MouseButtonPress: |
1423 | d->presstimer = startTimer(500); // #### pref. | 1445 | d->presstimer = startTimer(500); // #### pref. |
1424 | d->presswidget = (QWidget*)o; | 1446 | d->presswidget = (QWidget*)o; |
1425 | d->presspos = me->pos(); | 1447 | d->presspos = me->pos(); |
1426 | d->rightpressed = FALSE; | 1448 | d->rightpressed = FALSE; |
1427 | break; | 1449 | break; |
1428 | case QEvent::MouseButtonRelease: | 1450 | case QEvent::MouseButtonRelease: |
1429 | if ( d->presstimer ) { | 1451 | if ( d->presstimer ) { |
1430 | killTimer(d->presstimer); | 1452 | killTimer(d->presstimer); |
1431 | d->presstimer = 0; | 1453 | d->presstimer = 0; |
1432 | } | 1454 | } |
1433 | if ( d->rightpressed && d->presswidget ) { | 1455 | if ( d->rightpressed && d->presswidget ) { |
1434 | // Right released | 1456 | // Right released |
1435 | postEvent( d->presswidget, | 1457 | postEvent( d->presswidget, |
1436 | new QMouseEvent( QEvent::MouseButtonRelease, me->pos(), | 1458 | new QMouseEvent( QEvent::MouseButtonRelease, me->pos(), |
1437 | RightButton, LeftButton+RightButton ) ); | 1459 | RightButton, LeftButton+RightButton ) ); |
1438 | // Left released, off-widget | 1460 | // Left released, off-widget |
1439 | postEvent( d->presswidget, | 1461 | postEvent( d->presswidget, |
1440 | new QMouseEvent( QEvent::MouseMove, QPoint(-1,-1), | 1462 | new QMouseEvent( QEvent::MouseMove, QPoint(-1,-1), |
1441 | LeftButton, LeftButton ) ); | 1463 | LeftButton, LeftButton ) ); |
1442 | postEvent( d->presswidget, | 1464 | postEvent( d->presswidget, |
1443 | new QMouseEvent( QEvent::MouseButtonRelease, QPoint(-1,-1), | 1465 | new QMouseEvent( QEvent::MouseButtonRelease, QPoint(-1,-1), |
1444 | LeftButton, LeftButton ) ); | 1466 | LeftButton, LeftButton ) ); |
1445 | d->rightpressed = FALSE; | 1467 | d->rightpressed = FALSE; |
1446 | return TRUE; // don't send the real Left release | 1468 | return TRUE; // don't send the real Left release |
1447 | } | 1469 | } |
1448 | break; | 1470 | break; |
1449 | default: | 1471 | default: |
1450 | break; | 1472 | break; |
1451 | } | 1473 | } |
1452 | break; | 1474 | break; |
1453 | default: | 1475 | default: |
1454 | ; | 1476 | ; |
1455 | } | 1477 | } |
1456 | } | 1478 | } |
1457 | } else if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) { | 1479 | } else if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) { |
1458 | QKeyEvent *ke = (QKeyEvent *)e; | 1480 | QKeyEvent *ke = (QKeyEvent *)e; |
1459 | if ( ke->key() == Key_Enter ) { | 1481 | if ( ke->key() == Key_Enter ) { |
1460 | if ( o->isA( "QRadioButton" ) || o->isA( "QCheckBox" ) ) { | 1482 | if ( o->isA( "QRadioButton" ) || o->isA( "QCheckBox" ) ) { |
1461 | postEvent( o, new QKeyEvent( e->type(), Key_Space, ' ', | 1483 | postEvent( o, new QKeyEvent( e->type(), Key_Space, ' ', |
1462 | ke->state(), " ", ke->isAutoRepeat(), ke->count() ) ); | 1484 | ke->state(), " ", ke->isAutoRepeat(), ke->count() ) ); |
1463 | return TRUE; | 1485 | return TRUE; |
1464 | } | 1486 | } |
1465 | } | 1487 | } |
1466 | } | 1488 | } |
1467 | 1489 | ||
1468 | return FALSE; | 1490 | return FALSE; |
1469 | } | 1491 | } |
1470 | 1492 | ||
1471 | /*! | 1493 | /*! |
1472 | \reimp | 1494 | \reimp |
1473 | */ | 1495 | */ |
1474 | void QPEApplication::timerEvent( QTimerEvent *e ) | 1496 | void QPEApplication::timerEvent( QTimerEvent *e ) |
1475 | { | 1497 | { |
1476 | if ( e->timerId() == d->presstimer && d->presswidget ) { | 1498 | if ( e->timerId() == d->presstimer && d->presswidget ) { |
1477 | // Right pressed | 1499 | // Right pressed |
1478 | postEvent( d->presswidget, | 1500 | postEvent( d->presswidget, |
1479 | new QMouseEvent( QEvent::MouseButtonPress, d->presspos, | 1501 | new QMouseEvent( QEvent::MouseButtonPress, d->presspos, |
1480 | RightButton, LeftButton ) ); | 1502 | RightButton, LeftButton ) ); |
1481 | killTimer( d->presstimer ); | 1503 | killTimer( d->presstimer ); |
1482 | d->presstimer = 0; | 1504 | d->presstimer = 0; |
1483 | d->rightpressed = TRUE; | 1505 | d->rightpressed = TRUE; |
1484 | } | 1506 | } |
1485 | } | 1507 | } |
1486 | 1508 | ||
1487 | void QPEApplication::removeSenderFromStylusDict() | 1509 | void QPEApplication::removeSenderFromStylusDict() |
1488 | { | 1510 | { |
1489 | stylusDict->remove((void*)sender()); | 1511 | stylusDict->remove((void*)sender()); |
1490 | if ( d->presswidget == sender() ) | 1512 | if ( d->presswidget == sender() ) |
1491 | d->presswidget = 0; | 1513 | d->presswidget = 0; |
1492 | } | 1514 | } |
1493 | 1515 | ||
1494 | /*! | 1516 | /*! |
1495 | \internal | 1517 | \internal |
1496 | */ | 1518 | */ |
1497 | bool QPEApplication::keyboardGrabbed() const | 1519 | bool QPEApplication::keyboardGrabbed() const |
1498 | { | 1520 | { |
1499 | return d->kbgrabber; | 1521 | return d->kbgrabber; |
1500 | } | 1522 | } |
1501 | 1523 | ||
1502 | 1524 | ||
1503 | /*! | 1525 | /*! |
1504 | Reverses the effect of grabKeyboard(). This is called automatically | 1526 | Reverses the effect of grabKeyboard(). This is called automatically |
1505 | on program exit. | 1527 | on program exit. |
1506 | */ | 1528 | */ |
1507 | void QPEApplication::ungrabKeyboard() | 1529 | void QPEApplication::ungrabKeyboard() |
1508 | { | 1530 | { |
1509 | QPEApplicationData* d = ((QPEApplication*)qApp)->d; | 1531 | QPEApplicationData* d = ((QPEApplication*)qApp)->d; |
1510 | if ( d->kbgrabber == 2 ) { | 1532 | if ( d->kbgrabber == 2 ) { |
1511 | QCopEnvelope e("QPE/System", "grabKeyboard(QString)" ); | 1533 | QCopEnvelope e("QPE/System", "grabKeyboard(QString)" ); |
1512 | e << QString::null; | 1534 | e << QString::null; |
1513 | d->kbregrab = FALSE; | 1535 | d->kbregrab = FALSE; |
1514 | d->kbgrabber = 0; | 1536 | d->kbgrabber = 0; |
1515 | } | 1537 | } |
1516 | } | 1538 | } |
1517 | 1539 | ||
1518 | /*! | 1540 | /*! |
1519 | Grabs the keyboard such that the system's application launching | 1541 | Grabs the keyboard such that the system's application launching |
1520 | keys no longer work, and instead they are receivable by this | 1542 | keys no longer work, and instead they are receivable by this |
1521 | application. | 1543 | application. |
1522 | 1544 | ||
1523 | \sa ungrabKeyboard() | 1545 | \sa ungrabKeyboard() |
1524 | */ | 1546 | */ |
1525 | void QPEApplication::grabKeyboard() | 1547 | void QPEApplication::grabKeyboard() |
1526 | { | 1548 | { |
1527 | QPEApplicationData* d = ((QPEApplication*)qApp)->d; | 1549 | QPEApplicationData* d = ((QPEApplication*)qApp)->d; |
1528 | if ( qApp->type() == QApplication::GuiServer ) | 1550 | if ( qApp->type() == QApplication::GuiServer ) |
1529 | d->kbgrabber = 0; | 1551 | d->kbgrabber = 0; |
1530 | else { | 1552 | else { |
1531 | QCopEnvelope e("QPE/System", "grabKeyboard(QString)" ); | 1553 | QCopEnvelope e("QPE/System", "grabKeyboard(QString)" ); |
1532 | e << d->appName; | 1554 | e << d->appName; |
1533 | d->kbgrabber = 2; // me | 1555 | d->kbgrabber = 2; // me |
1534 | } | 1556 | } |
1535 | } | 1557 | } |
1536 | 1558 | ||
1537 | /*! | 1559 | /*! |
1538 | \reimp | 1560 | \reimp |
1539 | */ | 1561 | */ |
1540 | int QPEApplication::exec() | 1562 | int QPEApplication::exec() |
1541 | { | 1563 | { |
1542 | d->sendQCopQ(); | 1564 | d->sendQCopQ(); |
1543 | if ( d->keep_running) | 1565 | if ( d->keep_running) |
1544 | //|| d->qpe_main_widget && d->qpe_main_widget->isVisible() ) | 1566 | //|| d->qpe_main_widget && d->qpe_main_widget->isVisible() ) |
1545 | return QApplication::exec(); | 1567 | return QApplication::exec(); |
1546 | 1568 | ||
1547 | { | 1569 | { |
1548 | QCopEnvelope e("QPE/System", "closing(QString)" ); | 1570 | QCopEnvelope e("QPE/System", "closing(QString)" ); |
1549 | e << d->appName; | 1571 | e << d->appName; |
1550 | } | 1572 | } |
1551 | processEvents(); | 1573 | processEvents(); |
1552 | return 0; | 1574 | return 0; |
1553 | } | 1575 | } |
1554 | 1576 | ||
1555 | /*! | 1577 | /*! |
1556 | \internal | 1578 | \internal |
1557 | External request for application to quit. Quits if possible without | 1579 | External request for application to quit. Quits if possible without |
1558 | loosing state. | 1580 | loosing state. |
1559 | */ | 1581 | */ |
1560 | void QPEApplication::tryQuit() | 1582 | void QPEApplication::tryQuit() |
1561 | { | 1583 | { |
1562 | if ( activeModalWidget() || strcmp( argv()[0], "embeddedkonsole") == 0 ) | 1584 | if ( activeModalWidget() || strcmp( argv()[0], "embeddedkonsole") == 0 ) |
1563 | return; // Inside modal loop or konsole. Too hard to save state. | 1585 | return; // Inside modal loop or konsole. Too hard to save state. |
1564 | { | 1586 | { |
1565 | QCopEnvelope e("QPE/System", "closing(QString)" ); | 1587 | QCopEnvelope e("QPE/System", "closing(QString)" ); |
1566 | e << d->appName; | 1588 | e << d->appName; |
1567 | } | 1589 | } |
1568 | processEvents(); | 1590 | processEvents(); |
1569 | 1591 | ||
1570 | quit(); | 1592 | quit(); |
1571 | } | 1593 | } |
1572 | 1594 | ||
1573 | /*! | 1595 | /*! |
1574 | \internal | 1596 | \internal |
1575 | User initiated quit. Makes the window 'Go Away'. If preloaded this means | 1597 | User initiated quit. Makes the window 'Go Away'. If preloaded this means |
1576 | hiding the window. If not it means quitting the application. | 1598 | hiding the window. If not it means quitting the application. |
1577 | As this is user initiated we don't need to check state. | 1599 | As this is user initiated we don't need to check state. |
1578 | */ | 1600 | */ |
1579 | void QPEApplication::hideOrQuit() | 1601 | void QPEApplication::hideOrQuit() |
1580 | { | 1602 | { |
1581 | // notify of our demise :) | 1603 | // notify of our demise :) |
1582 | { | 1604 | { |
1583 | QCopEnvelope e("QPE/System", "closing(QString)" ); | 1605 | QCopEnvelope e("QPE/System", "closing(QString)" ); |
1584 | e << d->appName; | 1606 | e << d->appName; |
1585 | } | 1607 | } |
1586 | processEvents(); | 1608 | processEvents(); |
1587 | if ( d->preloaded && d->qpe_main_widget ) | 1609 | if ( d->preloaded && d->qpe_main_widget ) |
1588 | d->qpe_main_widget->hide(); | 1610 | d->qpe_main_widget->hide(); |
1589 | else | 1611 | else |
1590 | quit(); | 1612 | quit(); |
1591 | } | 1613 | } |
1592 | 1614 | ||
1593 | #if defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX) | 1615 | #if defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX) |
1594 | 1616 | ||
1595 | // The libraries with the skiff package (and possibly others) have | 1617 | // The libraries with the skiff package (and possibly others) have |
1596 | // completely useless implementations of builtin new and delete that | 1618 | // completely useless implementations of builtin new and delete that |
1597 | // use about 50% of your CPU. Here we revert to the simple libc | 1619 | // use about 50% of your CPU. Here we revert to the simple libc |
1598 | // functions. | 1620 | // functions. |
1599 | 1621 | ||
1600 | void* operator new[](size_t size) | 1622 | void* operator new[](size_t size) |
1601 | { | 1623 | { |
1602 | return malloc(size); | 1624 | return malloc(size); |
1603 | } | 1625 | } |
1604 | 1626 | ||
1605 | void* operator new(size_t size) | 1627 | void* operator new(size_t size) |
1606 | { | 1628 | { |
1607 | return malloc(size); | 1629 | return malloc(size); |
1608 | } | 1630 | } |
1609 | 1631 | ||
1610 | void operator delete[](void* p) | 1632 | void operator delete[](void* p) |
1611 | { | 1633 | { |
1612 | free(p); | 1634 | free(p); |
1613 | } | 1635 | } |
1614 | 1636 | ||
1615 | void operator delete[](void* p, size_t /*size*/) | 1637 | void operator delete[](void* p, size_t /*size*/) |
1616 | { | 1638 | { |
1617 | free(p); | 1639 | free(p); |
1618 | } | 1640 | } |
1619 | 1641 | ||
1620 | void operator delete(void* p) | 1642 | void operator delete(void* p) |
1621 | { | 1643 | { |
1622 | free(p); | 1644 | free(p); |
1623 | } | 1645 | } |
1624 | 1646 | ||
1625 | void operator delete(void* p, size_t /*size*/) | 1647 | void operator delete(void* p, size_t /*size*/) |
1626 | { | 1648 | { |
1627 | free(p); | 1649 | free(p); |
1628 | } | 1650 | } |
1629 | 1651 | ||
1630 | #endif | 1652 | #endif |
1631 | 1653 | ||
1632 | #if ( QT_VERSION <= 230 ) && !defined(SINGLE_APP) | 1654 | #if ( QT_VERSION <= 230 ) && !defined(SINGLE_APP) |
1633 | #include <qwidgetlist.h> | 1655 | #include <qwidgetlist.h> |
1634 | #include <qgfx_qws.h> | 1656 | #include <qgfx_qws.h> |
1635 | extern QRect qt_maxWindowRect; | 1657 | extern QRect qt_maxWindowRect; |
1636 | void qt_setMaxWindowRect(const QRect& r) | 1658 | void qt_setMaxWindowRect(const QRect& r) |
1637 | { | 1659 | { |
1638 | qt_maxWindowRect = qt_screen->mapFromDevice(r, | 1660 | qt_maxWindowRect = qt_screen->mapFromDevice(r, |
1639 | qt_screen->mapToDevice(QSize(qt_screen->width(),qt_screen->height()))); | 1661 | qt_screen->mapToDevice(QSize(qt_screen->width(),qt_screen->height()))); |
1640 | // Re-resize any maximized windows | 1662 | // Re-resize any maximized windows |
1641 | QWidgetList* l = QApplication::topLevelWidgets(); | 1663 | QWidgetList* l = QApplication::topLevelWidgets(); |
1642 | if ( l ) { | 1664 | if ( l ) { |
1643 | QWidget *w = l->first(); | 1665 | QWidget *w = l->first(); |
1644 | while ( w ) { | 1666 | while ( w ) { |
1645 | if ( w->isVisible() && w->isMaximized() ) | 1667 | if ( w->isVisible() && w->isMaximized() ) |
1646 | { | 1668 | { |
1647 | w->showMaximized(); | 1669 | w->showMaximized(); |
1648 | } | 1670 | } |
1649 | w = l->next(); | 1671 | w = l->next(); |
1650 | } | 1672 | } |
1651 | delete l; | 1673 | delete l; |
1652 | } | 1674 | } |
1653 | } | 1675 | } |
1654 | #endif | 1676 | #endif |