-rw-r--r-- | library/qpeapplication.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/library/qpeapplication.cpp b/library/qpeapplication.cpp index 87a9739..76d62ef 100644 --- a/library/qpeapplication.cpp +++ b/library/qpeapplication.cpp | |||
@@ -1,819 +1,830 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | ** $Id$ | 19 | ** $Id$ |
20 | ** | 20 | ** |
21 | **********************************************************************/ | 21 | **********************************************************************/ |
22 | #define QTOPIA_INTERNAL_LANGLIST | 22 | #define QTOPIA_INTERNAL_LANGLIST |
23 | #include <stdlib.h> | 23 | #include <stdlib.h> |
24 | #include <unistd.h> | 24 | #include <unistd.h> |
25 | #include <qfile.h> | 25 | #include <qfile.h> |
26 | #ifdef Q_WS_QWS | 26 | #ifdef Q_WS_QWS |
27 | #ifndef QT_NO_COP | 27 | #ifndef QT_NO_COP |
28 | #if QT_VERSION <= 231 | 28 | #if QT_VERSION <= 231 |
29 | #define private public | 29 | #define private public |
30 | #define sendLocally processEvent | 30 | #define sendLocally processEvent |
31 | #include "qcopenvelope_qws.h" | 31 | #include "qcopenvelope_qws.h" |
32 | #undef private | 32 | #undef private |
33 | #else | 33 | #else |
34 | #include "qcopenvelope_qws.h" | 34 | #include "qcopenvelope_qws.h" |
35 | #endif | 35 | #endif |
36 | #endif | 36 | #endif |
37 | #include <qwindowsystem_qws.h> | 37 | #include <qwindowsystem_qws.h> |
38 | #endif | 38 | #endif |
39 | #include <qtextstream.h> | 39 | #include <qtextstream.h> |
40 | #include <qpalette.h> | 40 | #include <qpalette.h> |
41 | #include <qbuffer.h> | 41 | #include <qbuffer.h> |
42 | #include <qptrdict.h> | 42 | #include <qptrdict.h> |
43 | #include <qregexp.h> | 43 | #include <qregexp.h> |
44 | #include <qdir.h> | 44 | #include <qdir.h> |
45 | #include <qlabel.h> | 45 | #include <qlabel.h> |
46 | #include <qdialog.h> | 46 | #include <qdialog.h> |
47 | #include <qdragobject.h> | 47 | #include <qdragobject.h> |
48 | #include <qevent.h> | 48 | #include <qevent.h> |
49 | #include <qtooltip.h> | 49 | #include <qtooltip.h> |
50 | #include <qsignal.h> | 50 | #include <qsignal.h> |
51 | #include <linux/fb.h> | 51 | |
52 | |||
53 | //#include <linux/fb.h> better not rely on kernel headers in userspace ... | ||
54 | |||
55 | /* VESA Blanking Levels */ | ||
56 | #define VESA_NO_BLANKING 0 | ||
57 | #define VESA_VSYNC_SUSPEND 1 | ||
58 | #define VESA_HSYNC_SUSPEND 2 | ||
59 | #define VESA_POWERDOWN 3 | ||
60 | |||
61 | #define FBIOBLANK 0x4611 | ||
62 | |||
52 | 63 | ||
53 | #include <qsignal.h> | 64 | #include <qsignal.h> |
54 | #include "qpeapplication.h" | 65 | #include "qpeapplication.h" |
55 | #include "qpestyle.h" | 66 | #include "qpestyle.h" |
56 | #if QT_VERSION >= 300 | 67 | #if QT_VERSION >= 300 |
57 | #include <qstylefactory.h> | 68 | #include <qstylefactory.h> |
58 | #else | 69 | #else |
59 | #include <qplatinumstyle.h> | 70 | #include <qplatinumstyle.h> |
60 | #include <qwindowsstyle.h> | 71 | #include <qwindowsstyle.h> |
61 | #include <qmotifstyle.h> | 72 | #include <qmotifstyle.h> |
62 | #include <qmotifplusstyle.h> | 73 | #include <qmotifplusstyle.h> |
63 | #include "lightstyle.h" | 74 | #include "lightstyle.h" |
64 | #endif | 75 | #endif |
65 | #include "global.h" | 76 | #include "global.h" |
66 | #include "resource.h" | 77 | #include "resource.h" |
67 | #if QT_VERSION <= 230 && defined(QT_NO_CODECS) | 78 | #if QT_VERSION <= 230 && defined(QT_NO_CODECS) |
68 | #include "qutfcodec.h" | 79 | #include "qutfcodec.h" |
69 | #endif | 80 | #endif |
70 | #include "config.h" | 81 | #include "config.h" |
71 | #include "network.h" | 82 | #include "network.h" |
72 | #include "fontmanager.h" | 83 | #include "fontmanager.h" |
73 | #include "fontdatabase.h" | 84 | #include "fontdatabase.h" |
74 | 85 | ||
75 | #include "power.h" | 86 | #include "power.h" |
76 | #include "alarmserver.h" | 87 | #include "alarmserver.h" |
77 | #include "applnk.h" | 88 | #include "applnk.h" |
78 | #include "qpemenubar.h" | 89 | #include "qpemenubar.h" |
79 | 90 | ||
80 | #include <unistd.h> | 91 | #include <unistd.h> |
81 | #include <sys/file.h> | 92 | #include <sys/file.h> |
82 | #include <sys/ioctl.h> | 93 | #include <sys/ioctl.h> |
83 | #include <sys/soundcard.h> | 94 | #include <sys/soundcard.h> |
84 | 95 | ||
85 | // for setBacklight() | 96 | // for setBacklight() |
86 | #if defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX) | 97 | #if defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX) |
87 | #include <linux/fb.h> | 98 | #include <linux/fb.h> |
88 | #include <sys/types.h> | 99 | #include <sys/types.h> |
89 | #include <sys/stat.h> | 100 | #include <sys/stat.h> |
90 | #endif | 101 | #endif |
91 | #include <stdlib.h> | 102 | #include <stdlib.h> |
92 | 103 | ||
93 | #include <dlfcn.h> // for Liquid HACK | 104 | #include <dlfcn.h> // for Liquid HACK |
94 | 105 | ||
95 | class QPEApplicationData { | 106 | class QPEApplicationData { |
96 | public: | 107 | public: |
97 | QPEApplicationData() : presstimer(0), presswidget(0), rightpressed(FALSE), | 108 | QPEApplicationData() : presstimer(0), presswidget(0), rightpressed(FALSE), |
98 | kbgrabber(0), kbregrab(FALSE), notbusysent(FALSE), preloaded(FALSE), | 109 | kbgrabber(0), kbregrab(FALSE), notbusysent(FALSE), preloaded(FALSE), |
99 | forceshow(FALSE), nomaximize(FALSE), qpe_main_widget(0), | 110 | forceshow(FALSE), nomaximize(FALSE), qpe_main_widget(0), |
100 | keep_running(TRUE) | 111 | keep_running(TRUE) |
101 | { | 112 | { |
102 | qcopq.setAutoDelete(TRUE); | 113 | qcopq.setAutoDelete(TRUE); |
103 | } | 114 | } |
104 | 115 | ||
105 | int presstimer; | 116 | int presstimer; |
106 | QWidget* presswidget; | 117 | QWidget* presswidget; |
107 | QPoint presspos; | 118 | QPoint presspos; |
108 | bool rightpressed; | 119 | bool rightpressed; |
109 | int kbgrabber; | 120 | int kbgrabber; |
110 | bool kbregrab; | 121 | bool kbregrab; |
111 | bool notbusysent; | 122 | bool notbusysent; |
112 | QString appName; | 123 | QString appName; |
113 | struct QCopRec { | 124 | struct QCopRec { |
114 | QCopRec(const QCString &ch, const QCString &msg, | 125 | QCopRec(const QCString &ch, const QCString &msg, |
115 | const QByteArray &d) : | 126 | const QByteArray &d) : |
116 | channel(ch), message(msg), data(d) { } | 127 | channel(ch), message(msg), data(d) { } |
117 | 128 | ||
118 | QCString channel; | 129 | QCString channel; |
119 | QCString message; | 130 | QCString message; |
120 | QByteArray data; | 131 | QByteArray data; |
121 | }; | 132 | }; |
122 | bool preloaded; | 133 | bool preloaded; |
123 | bool forceshow; | 134 | bool forceshow; |
124 | bool nomaximize; | 135 | bool nomaximize; |
125 | QWidget* qpe_main_widget; | 136 | QWidget* qpe_main_widget; |
126 | bool keep_running; | 137 | bool keep_running; |
127 | QList<QCopRec> qcopq; | 138 | QList<QCopRec> qcopq; |
128 | 139 | ||
129 | void enqueueQCop(const QCString &ch, const QCString &msg, | 140 | void enqueueQCop(const QCString &ch, const QCString &msg, |
130 | const QByteArray &data) | 141 | const QByteArray &data) |
131 | { | 142 | { |
132 | qcopq.append(new QCopRec(ch,msg,data)); | 143 | qcopq.append(new QCopRec(ch,msg,data)); |
133 | } | 144 | } |
134 | void sendQCopQ() | 145 | void sendQCopQ() |
135 | { | 146 | { |
136 | QCopRec* r; | 147 | QCopRec* r; |
137 | for (QListIterator<QCopRec> it(qcopq); (r=it.current()); ++it) | 148 | for (QListIterator<QCopRec> it(qcopq); (r=it.current()); ++it) |
138 | QCopChannel::sendLocally(r->channel,r->message,r->data); | 149 | QCopChannel::sendLocally(r->channel,r->message,r->data); |
139 | qcopq.clear(); | 150 | qcopq.clear(); |
140 | } | 151 | } |
141 | }; | 152 | }; |
142 | 153 | ||
143 | class ResourceMimeFactory : public QMimeSourceFactory { | 154 | class ResourceMimeFactory : public QMimeSourceFactory { |
144 | public: | 155 | public: |
145 | ResourceMimeFactory() | 156 | ResourceMimeFactory() |
146 | { | 157 | { |
147 | setFilePath( Global::helpPath() ); | 158 | setFilePath( Global::helpPath() ); |
148 | setExtensionType("html","text/html;charset=UTF-8"); | 159 | setExtensionType("html","text/html;charset=UTF-8"); |
149 | } | 160 | } |
150 | 161 | ||
151 | const QMimeSource* data(const QString& abs_name) const | 162 | const QMimeSource* data(const QString& abs_name) const |
152 | { | 163 | { |
153 | const QMimeSource* r = QMimeSourceFactory::data(abs_name); | 164 | const QMimeSource* r = QMimeSourceFactory::data(abs_name); |
154 | if ( !r ) { | 165 | if ( !r ) { |
155 | int sl = abs_name.length(); | 166 | int sl = abs_name.length(); |
156 | do { | 167 | do { |
157 | sl = abs_name.findRev('/',sl-1); | 168 | sl = abs_name.findRev('/',sl-1); |
158 | QString name = sl>=0 ? abs_name.mid(sl+1) : abs_name; | 169 | QString name = sl>=0 ? abs_name.mid(sl+1) : abs_name; |
159 | int dot = name.findRev('.'); | 170 | int dot = name.findRev('.'); |
160 | if ( dot >= 0 ) | 171 | if ( dot >= 0 ) |
161 | name = name.left(dot); | 172 | name = name.left(dot); |
162 | QImage img = Resource::loadImage(name); | 173 | QImage img = Resource::loadImage(name); |
163 | if ( !img.isNull() ) | 174 | if ( !img.isNull() ) |
164 | r = new QImageDrag(img); | 175 | r = new QImageDrag(img); |
165 | } while (!r && sl>0); | 176 | } while (!r && sl>0); |
166 | } | 177 | } |
167 | return r; | 178 | return r; |
168 | } | 179 | } |
169 | }; | 180 | }; |
170 | 181 | ||
171 | static int muted=0; | 182 | static int muted=0; |
172 | static int micMuted=0; | 183 | static int micMuted=0; |
173 | 184 | ||
174 | static void setVolume(int t=0, int percent=-1) | 185 | static void setVolume(int t=0, int percent=-1) |
175 | { | 186 | { |
176 | switch (t) { | 187 | switch (t) { |
177 | case 0: { | 188 | case 0: { |
178 | Config cfg("qpe"); | 189 | Config cfg("qpe"); |
179 | cfg.setGroup("Volume"); | 190 | cfg.setGroup("Volume"); |
180 | if ( percent < 0 ) | 191 | if ( percent < 0 ) |
181 | percent = cfg.readNumEntry("VolumePercent",50); | 192 | percent = cfg.readNumEntry("VolumePercent",50); |
182 | int fd = 0; | 193 | int fd = 0; |
183 | if ((fd = open("/dev/mixer", O_RDWR))>=0) { | 194 | if ((fd = open("/dev/mixer", O_RDWR))>=0) { |
184 | int vol = muted ? 0 : percent; | 195 | int vol = muted ? 0 : percent; |
185 | // set both channels to same volume | 196 | // set both channels to same volume |
186 | vol |= vol << 8; | 197 | vol |= vol << 8; |
187 | ioctl(fd, MIXER_WRITE(0), &vol); | 198 | ioctl(fd, MIXER_WRITE(0), &vol); |
188 | ::close(fd); | 199 | ::close(fd); |
189 | } | 200 | } |
190 | } break; | 201 | } break; |
191 | } | 202 | } |
192 | } | 203 | } |
193 | 204 | ||
194 | static void setMic(int t=0, int percent=-1) | 205 | static void setMic(int t=0, int percent=-1) |
195 | { | 206 | { |
196 | switch (t) { | 207 | switch (t) { |
197 | case 0: { | 208 | case 0: { |
198 | Config cfg("qpe"); | 209 | Config cfg("qpe"); |
199 | cfg.setGroup("Volume"); | 210 | cfg.setGroup("Volume"); |
200 | if ( percent < 0 ) | 211 | if ( percent < 0 ) |
201 | percent = cfg.readNumEntry("Mic",50); | 212 | percent = cfg.readNumEntry("Mic",50); |
202 | 213 | ||
203 | int fd = 0; | 214 | int fd = 0; |
204 | int mic = micMuted ? 0 : percent; | 215 | int mic = micMuted ? 0 : percent; |
205 | if ((fd = open("/dev/mixer", O_RDWR))>=0) { | 216 | if ((fd = open("/dev/mixer", O_RDWR))>=0) { |
206 | ioctl(fd, MIXER_WRITE(SOUND_MIXER_MIC), &mic); | 217 | ioctl(fd, MIXER_WRITE(SOUND_MIXER_MIC), &mic); |
207 | ::close(fd); | 218 | ::close(fd); |
208 | } | 219 | } |
209 | } break; | 220 | } break; |
210 | } | 221 | } |
211 | } | 222 | } |
212 | 223 | ||
213 | int qpe_sysBrightnessSteps() | 224 | int qpe_sysBrightnessSteps() |
214 | { | 225 | { |
215 | #if defined(QT_QWS_IPAQ) | 226 | #if defined(QT_QWS_IPAQ) |
216 | return 255; | 227 | return 255; |
217 | #elif defined(QT_QWS_EBX) | 228 | #elif defined(QT_QWS_EBX) |
218 | return 4; | 229 | return 4; |
219 | #else | 230 | #else |
220 | return 255; // ? | 231 | return 255; // ? |
221 | #endif | 232 | #endif |
222 | } | 233 | } |
223 | 234 | ||
224 | 235 | ||
225 | static int& hack(int& i) | 236 | static int& hack(int& i) |
226 | { | 237 | { |
227 | #if QT_VERSION <= 230 && defined(QT_NO_CODECS) | 238 | #if QT_VERSION <= 230 && defined(QT_NO_CODECS) |
228 | // These should be created, but aren't in Qt 2.3.0 | 239 | // These should be created, but aren't in Qt 2.3.0 |
229 | (void)new QUtf8Codec; | 240 | (void)new QUtf8Codec; |
230 | (void)new QUtf16Codec; | 241 | (void)new QUtf16Codec; |
231 | #endif | 242 | #endif |
232 | return i; | 243 | return i; |
233 | } | 244 | } |
234 | 245 | ||
235 | static bool forced_off = FALSE; | 246 | static bool forced_off = FALSE; |
236 | static int curbl=-1; | 247 | static int curbl=-1; |
237 | 248 | ||
238 | static int backlight() | 249 | static int backlight() |
239 | { | 250 | { |
240 | if ( curbl == -1 ) { | 251 | if ( curbl == -1 ) { |
241 | // Read from config | 252 | // Read from config |
242 | Config config( "qpe" ); | 253 | Config config( "qpe" ); |
243 | config.setGroup( "Screensaver" ); | 254 | config.setGroup( "Screensaver" ); |
244 | curbl = config.readNumEntry("Brightness",255); | 255 | curbl = config.readNumEntry("Brightness",255); |
245 | } | 256 | } |
246 | return curbl; | 257 | return curbl; |
247 | } | 258 | } |
248 | 259 | ||
249 | static void setBacklight(int bright) | 260 | static void setBacklight(int bright) |
250 | { | 261 | { |
251 | if ( bright == -3 ) { | 262 | if ( bright == -3 ) { |
252 | // Forced on | 263 | // Forced on |
253 | forced_off = FALSE; | 264 | forced_off = FALSE; |
254 | bright = -1; | 265 | bright = -1; |
255 | } | 266 | } |
256 | if ( forced_off && bright != -2 ) | 267 | if ( forced_off && bright != -2 ) |
257 | return; | 268 | return; |
258 | if ( bright == -2 ) { | 269 | if ( bright == -2 ) { |
259 | // Toggle between off and on | 270 | // Toggle between off and on |
260 | bright = curbl ? 0 : -1; | 271 | bright = curbl ? 0 : -1; |
261 | forced_off = !bright; | 272 | forced_off = !bright; |
262 | } | 273 | } |
263 | if ( bright == -1 ) { | 274 | if ( bright == -1 ) { |
264 | // Read from config | 275 | // Read from config |
265 | Config config( "qpe" ); | 276 | Config config( "qpe" ); |
266 | config.setGroup( "Screensaver" ); | 277 | config.setGroup( "Screensaver" ); |
267 | bright = config.readNumEntry("Brightness",255); | 278 | bright = config.readNumEntry("Brightness",255); |
268 | } | 279 | } |
269 | #if defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX) | 280 | #if defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX) |
270 | if ( QFile::exists("/usr/bin/bl") ) { | 281 | if ( QFile::exists("/usr/bin/bl") ) { |
271 | QString cmd = "/usr/bin/bl 1 "; | 282 | QString cmd = "/usr/bin/bl 1 "; |
272 | cmd += bright<=0 ? "0 " : "1 "; | 283 | cmd += bright<=0 ? "0 " : "1 "; |
273 | cmd += QString::number(bright); | 284 | cmd += QString::number(bright); |
274 | system(cmd.latin1()); | 285 | system(cmd.latin1()); |
275 | #if defined(QT_QWS_EBX) | 286 | #if defined(QT_QWS_EBX) |
276 | } else if ( QFile::exists("/dev/fl") ) { | 287 | } else if ( QFile::exists("/dev/fl") ) { |
277 | #define FL_IOCTL_STEP_CONTRAST 100 | 288 | #define FL_IOCTL_STEP_CONTRAST 100 |
278 | int fd = open("/dev/fl", O_WRONLY); | 289 | int fd = open("/dev/fl", O_WRONLY); |
279 | if (fd >= 0 ) { | 290 | if (fd >= 0 ) { |
280 | int steps = qpe_sysBrightnessSteps(); | 291 | int steps = qpe_sysBrightnessSteps(); |
281 | int bl = ( bright * steps + 127 ) / 255; | 292 | int bl = ( bright * steps + 127 ) / 255; |
282 | if ( bright && !bl ) bl = 1; | 293 | if ( bright && !bl ) bl = 1; |
283 | bl = ioctl(fd, FL_IOCTL_STEP_CONTRAST, bl); | 294 | bl = ioctl(fd, FL_IOCTL_STEP_CONTRAST, bl); |
284 | close(fd); | 295 | close(fd); |
285 | } | 296 | } |
286 | } | 297 | } |
287 | #elif defined(QT_QWS_IPAQ) | 298 | #elif defined(QT_QWS_IPAQ) |
288 | } else if ( QFile::exists("/dev/ts") || QFile::exists("/dev/h3600_ts") ) { | 299 | } else if ( QFile::exists("/dev/ts") || QFile::exists("/dev/h3600_ts") ) { |
289 | typedef struct { | 300 | typedef struct { |
290 | unsigned char mode; | 301 | unsigned char mode; |
291 | unsigned char pwr; | 302 | unsigned char pwr; |
292 | unsigned char brightness; | 303 | unsigned char brightness; |
293 | } FLITE_IN; | 304 | } FLITE_IN; |
294 | # ifndef FLITE_ON | 305 | # ifndef FLITE_ON |
295 | # ifndef _LINUX_IOCTL_H | 306 | # ifndef _LINUX_IOCTL_H |
296 | # include <linux/ioctl.h> | 307 | # include <linux/ioctl.h> |
297 | # endif | 308 | # endif |
298 | # define FLITE_ON _IOW('f', 7, FLITE_IN) | 309 | # define FLITE_ON _IOW('f', 7, FLITE_IN) |
299 | # endif | 310 | # endif |
300 | int fd; | 311 | int fd; |
301 | if ( QFile::exists("/dev/ts") ) | 312 | if ( QFile::exists("/dev/ts") ) |
302 | fd = open("/dev/ts", O_WRONLY); | 313 | fd = open("/dev/ts", O_WRONLY); |
303 | else | 314 | else |
304 | fd = open("/dev/h3600_ts", O_WRONLY); | 315 | fd = open("/dev/h3600_ts", O_WRONLY); |
305 | if (fd >= 0 ) { | 316 | if (fd >= 0 ) { |
306 | FLITE_IN bl; | 317 | FLITE_IN bl; |
307 | bl.mode = 1; | 318 | bl.mode = 1; |
308 | bl.pwr = bright ? 1 : 0; | 319 | bl.pwr = bright ? 1 : 0; |
309 | bl.brightness = bright; | 320 | bl.brightness = bright; |
310 | ioctl(fd, FLITE_ON, &bl); | 321 | ioctl(fd, FLITE_ON, &bl); |
311 | close(fd); | 322 | close(fd); |
312 | } | 323 | } |
313 | } | 324 | } |
314 | #endif | 325 | #endif |
315 | #endif | 326 | #endif |
316 | curbl = bright; | 327 | curbl = bright; |
317 | } | 328 | } |
318 | 329 | ||
319 | void qpe_setBacklight(int bright) { setBacklight(bright); } | 330 | void qpe_setBacklight(int bright) { setBacklight(bright); } |
320 | 331 | ||
321 | static bool dim_on = FALSE; | 332 | static bool dim_on = FALSE; |
322 | static bool lightoff_on = FALSE; | 333 | static bool lightoff_on = FALSE; |
323 | static int disable_suspend = 100; | 334 | static int disable_suspend = 100; |
324 | 335 | ||
325 | static bool powerOnline() | 336 | static bool powerOnline() |
326 | { | 337 | { |
327 | return PowerStatusManager::readStatus().acStatus() == PowerStatus::Online; | 338 | return PowerStatusManager::readStatus().acStatus() == PowerStatus::Online; |
328 | } | 339 | } |
329 | 340 | ||
330 | static bool networkOnline() | 341 | static bool networkOnline() |
331 | { | 342 | { |
332 | return Network::networkOnline(); | 343 | return Network::networkOnline(); |
333 | } | 344 | } |
334 | 345 | ||
335 | class QPEScreenSaver : public QWSScreenSaver | 346 | class QPEScreenSaver : public QWSScreenSaver |
336 | { | 347 | { |
337 | private: | 348 | private: |
338 | int LcdOn; | 349 | int LcdOn; |
339 | 350 | ||
340 | public: | 351 | public: |
341 | QPEScreenSaver() | 352 | QPEScreenSaver() |
342 | { | 353 | { |
343 | int fd; | 354 | int fd; |
344 | 355 | ||
345 | LcdOn = TRUE; | 356 | LcdOn = TRUE; |
346 | // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off) | 357 | // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off) |
347 | fd=open("/dev/fb0",O_RDWR); | 358 | fd=open("/dev/fb0",O_RDWR); |
348 | if (fd != -1) { ioctl(fd,FBIOBLANK,VESA_NO_BLANKING); close(fd); } | 359 | if (fd != -1) { ioctl(fd,FBIOBLANK,VESA_NO_BLANKING); close(fd); } |
349 | } | 360 | } |
350 | void restore() | 361 | void restore() |
351 | { | 362 | { |
352 | if (!LcdOn) // We must have turned it off | 363 | if (!LcdOn) // We must have turned it off |
353 | { | 364 | { |
354 | int fd; | 365 | int fd; |
355 | fd=open("/dev/fb0",O_RDWR); | 366 | fd=open("/dev/fb0",O_RDWR); |
356 | if (fd != -1) { ioctl(fd,FBIOBLANK,VESA_NO_BLANKING); close(fd); } | 367 | if (fd != -1) { ioctl(fd,FBIOBLANK,VESA_NO_BLANKING); close(fd); } |
357 | } | 368 | } |
358 | setBacklight(-1); | 369 | setBacklight(-1); |
359 | } | 370 | } |
360 | bool save(int level) | 371 | bool save(int level) |
361 | { | 372 | { |
362 | int fd; | 373 | int fd; |
363 | 374 | ||
364 | switch ( level ) { | 375 | switch ( level ) { |
365 | case 0: | 376 | case 0: |
366 | if ( disable_suspend > 0 && dim_on ) { | 377 | if ( disable_suspend > 0 && dim_on ) { |
367 | if (backlight() > 1) | 378 | if (backlight() > 1) |
368 | setBacklight(1); // lowest non-off | 379 | setBacklight(1); // lowest non-off |
369 | } | 380 | } |
370 | return TRUE; | 381 | return TRUE; |
371 | break; | 382 | break; |
372 | case 1: | 383 | case 1: |
373 | if ( disable_suspend > 1 && lightoff_on ) { | 384 | if ( disable_suspend > 1 && lightoff_on ) { |
374 | setBacklight(0); // off | 385 | setBacklight(0); // off |
375 | } | 386 | } |
376 | return TRUE; | 387 | return TRUE; |
377 | break; | 388 | break; |
378 | case 2: | 389 | case 2: |
379 | Config config( "qpe" ); | 390 | Config config( "qpe" ); |
380 | config.setGroup( "Screensaver" ); | 391 | config.setGroup( "Screensaver" ); |
381 | if (config.readNumEntry("LcdOffOnly",0) != 0) // We're only turning off the LCD | 392 | if (config.readNumEntry("LcdOffOnly",0) != 0) // We're only turning off the LCD |
382 | { | 393 | { |
383 | fd=open("/dev/fb0",O_RDWR); | 394 | fd=open("/dev/fb0",O_RDWR); |
384 | if (fd != -1) { ioctl(fd,FBIOBLANK,VESA_POWERDOWN); close(fd); } | 395 | if (fd != -1) { ioctl(fd,FBIOBLANK,VESA_POWERDOWN); close(fd); } |
385 | LcdOn = FALSE; | 396 | LcdOn = FALSE; |
386 | } | 397 | } |
387 | else // We're going to suspend the whole machine | 398 | else // We're going to suspend the whole machine |
388 | { | 399 | { |
389 | if ( disable_suspend > 2 && !powerOnline() && !networkOnline() ) { | 400 | if ( disable_suspend > 2 && !powerOnline() && !networkOnline() ) { |
390 | QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); | 401 | QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); |
391 | return TRUE; | 402 | return TRUE; |
392 | } | 403 | } |
393 | } | 404 | } |
394 | break; | 405 | break; |
395 | } | 406 | } |
396 | return FALSE; | 407 | return FALSE; |
397 | } | 408 | } |
398 | }; | 409 | }; |
399 | 410 | ||
400 | static int ssi(int interval, Config &config, const QString &enable, const QString& value, int def) | 411 | static int ssi(int interval, Config &config, const QString &enable, const QString& value, int def) |
401 | { | 412 | { |
402 | if ( !enable.isEmpty() && config.readNumEntry(enable,0) == 0 ) | 413 | if ( !enable.isEmpty() && config.readNumEntry(enable,0) == 0 ) |
403 | return 0; | 414 | return 0; |
404 | 415 | ||
405 | if ( interval < 0 ) { | 416 | if ( interval < 0 ) { |
406 | // Restore screen blanking and power saving state | 417 | // Restore screen blanking and power saving state |
407 | interval = config.readNumEntry( value, def ); | 418 | interval = config.readNumEntry( value, def ); |
408 | } | 419 | } |
409 | return interval; | 420 | return interval; |
410 | } | 421 | } |
411 | 422 | ||
412 | static void setScreenSaverIntervals(int i1, int i2, int i3) | 423 | static void setScreenSaverIntervals(int i1, int i2, int i3) |
413 | { | 424 | { |
414 | Config config( "qpe" ); | 425 | Config config( "qpe" ); |
415 | config.setGroup( "Screensaver" ); | 426 | config.setGroup( "Screensaver" ); |
416 | 427 | ||
417 | int v[4]; | 428 | int v[4]; |
418 | i1 = ssi(i1, config, "Dim","Interval_Dim", 30); | 429 | i1 = ssi(i1, config, "Dim","Interval_Dim", 30); |
419 | i2 = ssi(i2, config, "LightOff","Interval_LightOff", 20); | 430 | i2 = ssi(i2, config, "LightOff","Interval_LightOff", 20); |
420 | i3 = ssi(i3, config, "","Interval", 60); | 431 | i3 = ssi(i3, config, "","Interval", 60); |
421 | 432 | ||
422 | //qDebug("screen saver intervals: %d %d %d", i1, i2, i3); | 433 | //qDebug("screen saver intervals: %d %d %d", i1, i2, i3); |
423 | 434 | ||
424 | v[0] = QMAX( 1000*i1, 100); | 435 | v[0] = QMAX( 1000*i1, 100); |
425 | v[1] = QMAX( 1000*i2, 100); | 436 | v[1] = QMAX( 1000*i2, 100); |
426 | v[2] = QMAX( 1000*i3, 100); | 437 | v[2] = QMAX( 1000*i3, 100); |
427 | v[3] = 0; | 438 | v[3] = 0; |
428 | dim_on = ( (i1 != 0) ? config.readNumEntry("Dim",1) : FALSE ); | 439 | dim_on = ( (i1 != 0) ? config.readNumEntry("Dim",1) : FALSE ); |
429 | lightoff_on = ( (i2 != 0 ) ? config.readNumEntry("LightOff",1) : FALSE ); | 440 | lightoff_on = ( (i2 != 0 ) ? config.readNumEntry("LightOff",1) : FALSE ); |
430 | if ( !i1 && !i2 && !i3 ) | 441 | if ( !i1 && !i2 && !i3 ) |
431 | QWSServer::setScreenSaverInterval(0); | 442 | QWSServer::setScreenSaverInterval(0); |
432 | else | 443 | else |
433 | QWSServer::setScreenSaverIntervals(v); | 444 | QWSServer::setScreenSaverIntervals(v); |
434 | } | 445 | } |
435 | 446 | ||
436 | static void setScreenSaverInterval(int interval) | 447 | static void setScreenSaverInterval(int interval) |
437 | { | 448 | { |
438 | setScreenSaverIntervals(-1,-1,interval); | 449 | setScreenSaverIntervals(-1,-1,interval); |
439 | } | 450 | } |
440 | 451 | ||
441 | 452 | ||
442 | /*! | 453 | /*! |
443 | \class QPEApplication qpeapplication.h | 454 | \class QPEApplication qpeapplication.h |
444 | \brief The QPEApplication class implements various system services | 455 | \brief The QPEApplication class implements various system services |
445 | that are available to all Qtopia applications. | 456 | that are available to all Qtopia applications. |
446 | 457 | ||
447 | Simply by using QPEApplication instead of QApplication, a plain Qt | 458 | Simply by using QPEApplication instead of QApplication, a plain Qt |
448 | application becomes a Qtopia application. It automatically follows | 459 | application becomes a Qtopia application. It automatically follows |
449 | style changes, quits and raises, and in the | 460 | style changes, quits and raises, and in the |
450 | case of \link docwidget.html document-oriented\endlink applications, | 461 | case of \link docwidget.html document-oriented\endlink applications, |
451 | changes the current displayed document in response to the environment. | 462 | changes the current displayed document in response to the environment. |
452 | */ | 463 | */ |
453 | 464 | ||
454 | /*! | 465 | /*! |
455 | \fn void QPEApplication::clientMoused() | 466 | \fn void QPEApplication::clientMoused() |
456 | 467 | ||
457 | \internal | 468 | \internal |
458 | */ | 469 | */ |
459 | 470 | ||
460 | /*! | 471 | /*! |
461 | \fn void QPEApplication::timeChanged(); | 472 | \fn void QPEApplication::timeChanged(); |
462 | 473 | ||
463 | This signal is emitted when the time jumps forward or backwards | 474 | This signal is emitted when the time jumps forward or backwards |
464 | by more than the normal passage of time. | 475 | by more than the normal passage of time. |
465 | */ | 476 | */ |
466 | 477 | ||
467 | /*! | 478 | /*! |
468 | \fn void QPEApplication::clockChanged( bool ampm ); | 479 | \fn void QPEApplication::clockChanged( bool ampm ); |
469 | 480 | ||
470 | This signal is emitted when the user changes the style | 481 | This signal is emitted when the user changes the style |
471 | of clock. If \a ampm is TRUE, the user wants a 12-hour | 482 | of clock. If \a ampm is TRUE, the user wants a 12-hour |
472 | AM/PM close, otherwise, they want a 24-hour clock. | 483 | AM/PM close, otherwise, they want a 24-hour clock. |
473 | */ | 484 | */ |
474 | 485 | ||
475 | /*! | 486 | /*! |
476 | \fn void QPEApplication::appMessage( const QCString& msg, const QByteArray& data ) | 487 | \fn void QPEApplication::appMessage( const QCString& msg, const QByteArray& data ) |
477 | 488 | ||
478 | This signal is emitted when a message is received on the | 489 | This signal is emitted when a message is received on the |
479 | QPE/Application/<i>appname</i> QCop channel for this application. | 490 | QPE/Application/<i>appname</i> QCop channel for this application. |
480 | 491 | ||
481 | The slot to which you connect this signal uses \a msg and \a data | 492 | The slot to which you connect this signal uses \a msg and \a data |
482 | in the following way: | 493 | in the following way: |
483 | 494 | ||
484 | \code | 495 | \code |
485 | void MyWidget::receive( const QCString& msg, const QByteArray& data ) | 496 | void MyWidget::receive( const QCString& msg, const QByteArray& data ) |
486 | { | 497 | { |
487 | QDataStream stream( data, IO_ReadOnly ); | 498 | QDataStream stream( data, IO_ReadOnly ); |
488 | if ( msg == "someMessage(int,int,int)" ) { | 499 | if ( msg == "someMessage(int,int,int)" ) { |
489 | int a,b,c; | 500 | int a,b,c; |
490 | stream >> a >> b >> c; | 501 | stream >> a >> b >> c; |
491 | ... | 502 | ... |
492 | } else if ( msg == "otherMessage(QString)" ) { | 503 | } else if ( msg == "otherMessage(QString)" ) { |
493 | ... | 504 | ... |
494 | } | 505 | } |
495 | } | 506 | } |
496 | \endcode | 507 | \endcode |
497 | 508 | ||
498 | \sa qcop.html | 509 | \sa qcop.html |
499 | */ | 510 | */ |
500 | 511 | ||
501 | /*! | 512 | /*! |
502 | Constructs a QPEApplication just as you would construct | 513 | Constructs a QPEApplication just as you would construct |
503 | a QApplication, passing \a argc, \a argv, and \a t. | 514 | a QApplication, passing \a argc, \a argv, and \a t. |
504 | */ | 515 | */ |
505 | QPEApplication::QPEApplication( int& argc, char **argv, Type t ) | 516 | QPEApplication::QPEApplication( int& argc, char **argv, Type t ) |
506 | : QApplication( hack(argc), argv, t ) | 517 | : QApplication( hack(argc), argv, t ) |
507 | { | 518 | { |
508 | int dw = desktop()->width(); | 519 | int dw = desktop()->width(); |
509 | if ( dw < 200 ) { | 520 | if ( dw < 200 ) { |
510 | // setFont( QFont( "helvetica", 8 ) ); | 521 | // setFont( QFont( "helvetica", 8 ) ); |
511 | AppLnk::setSmallIconSize(10); | 522 | AppLnk::setSmallIconSize(10); |
512 | AppLnk::setBigIconSize(28); | 523 | AppLnk::setBigIconSize(28); |
513 | } | 524 | } |
514 | 525 | ||
515 | d = new QPEApplicationData; | 526 | d = new QPEApplicationData; |
516 | QMimeSourceFactory::setDefaultFactory(new ResourceMimeFactory); | 527 | QMimeSourceFactory::setDefaultFactory(new ResourceMimeFactory); |
517 | 528 | ||
518 | connect(this, SIGNAL(lastWindowClosed()), this, SLOT(hideOrQuit())); | 529 | connect(this, SIGNAL(lastWindowClosed()), this, SLOT(hideOrQuit())); |
519 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 530 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
520 | 531 | ||
521 | QString qcopfn("/tmp/qcop-msg-"); | 532 | QString qcopfn("/tmp/qcop-msg-"); |
522 | qcopfn += QString(argv[0]); // append command name | 533 | qcopfn += QString(argv[0]); // append command name |
523 | 534 | ||
524 | QFile f(qcopfn); | 535 | QFile f(qcopfn); |
525 | if ( f.open(IO_ReadOnly) ) { | 536 | if ( f.open(IO_ReadOnly) ) { |
526 | flock(f.handle(), LOCK_EX); | 537 | flock(f.handle(), LOCK_EX); |
527 | } | 538 | } |
528 | 539 | ||
529 | sysChannel = new QCopChannel( "QPE/System", this ); | 540 | sysChannel = new QCopChannel( "QPE/System", this ); |
530 | connect( sysChannel, SIGNAL(received(const QCString &, const QByteArray &)), | 541 | connect( sysChannel, SIGNAL(received(const QCString &, const QByteArray &)), |
531 | this, SLOT(systemMessage( const QCString &, const QByteArray &)) ); | 542 | this, SLOT(systemMessage( const QCString &, const QByteArray &)) ); |
532 | 543 | ||
533 | QCString channel = QCString(argv[0]); | 544 | QCString channel = QCString(argv[0]); |
534 | channel.replace(QRegExp(".*/"),""); | 545 | channel.replace(QRegExp(".*/"),""); |
535 | d->appName = channel; | 546 | d->appName = channel; |
536 | channel = "QPE/Application/" + channel; | 547 | channel = "QPE/Application/" + channel; |
537 | pidChannel = new QCopChannel( channel, this); | 548 | pidChannel = new QCopChannel( channel, this); |
538 | connect( pidChannel, SIGNAL(received(const QCString &, const QByteArray &)), | 549 | connect( pidChannel, SIGNAL(received(const QCString &, const QByteArray &)), |
539 | this, SLOT(pidMessage(const QCString &, const QByteArray &))); | 550 | this, SLOT(pidMessage(const QCString &, const QByteArray &))); |
540 | 551 | ||
541 | if ( f.isOpen() ) { | 552 | if ( f.isOpen() ) { |
542 | d->keep_running = FALSE; | 553 | d->keep_running = FALSE; |
543 | QDataStream ds(&f); | 554 | QDataStream ds(&f); |
544 | QCString channel, message; | 555 | QCString channel, message; |
545 | QByteArray data; | 556 | QByteArray data; |
546 | while(!ds.atEnd()) { | 557 | while(!ds.atEnd()) { |
547 | ds >> channel >> message >> data; | 558 | ds >> channel >> message >> data; |
548 | d->enqueueQCop(channel,message,data); | 559 | d->enqueueQCop(channel,message,data); |
549 | } | 560 | } |
550 | 561 | ||
551 | flock(f.handle(), LOCK_UN); | 562 | flock(f.handle(), LOCK_UN); |
552 | f.close(); | 563 | f.close(); |
553 | f.remove(); | 564 | f.remove(); |
554 | } | 565 | } |
555 | 566 | ||
556 | for (int a=0; a<argc; a++) { | 567 | for (int a=0; a<argc; a++) { |
557 | if ( qstrcmp(argv[a],"-preload")==0 ) { | 568 | if ( qstrcmp(argv[a],"-preload")==0 ) { |
558 | argv[a] = argv[a+1]; | 569 | argv[a] = argv[a+1]; |
559 | a++; | 570 | a++; |
560 | d->preloaded = TRUE; | 571 | d->preloaded = TRUE; |
561 | argc-=1; | 572 | argc-=1; |
562 | } else if ( qstrcmp(argv[a],"-preload-show")==0 ) { | 573 | } else if ( qstrcmp(argv[a],"-preload-show")==0 ) { |
563 | argv[a] = argv[a+1]; | 574 | argv[a] = argv[a+1]; |
564 | a++; | 575 | a++; |
565 | d->preloaded = TRUE; | 576 | d->preloaded = TRUE; |
566 | d->forceshow = TRUE; | 577 | d->forceshow = TRUE; |
567 | argc-=1; | 578 | argc-=1; |
568 | } | 579 | } |
569 | } | 580 | } |
570 | 581 | ||
571 | /* overide stored arguments */ | 582 | /* overide stored arguments */ |
572 | setArgs(argc, argv); | 583 | setArgs(argc, argv); |
573 | 584 | ||
574 | #endif | 585 | #endif |
575 | 586 | ||
576 | qwsSetDecoration( new QPEDecoration() ); | 587 | qwsSetDecoration( new QPEDecoration() ); |
577 | 588 | ||
578 | #ifndef QT_NO_TRANSLATION | 589 | #ifndef QT_NO_TRANSLATION |
579 | QStringList langs = Global::languageList(); | 590 | QStringList langs = Global::languageList(); |
580 | for (QStringList::ConstIterator it = langs.begin(); it!=langs.end(); ++it) { | 591 | for (QStringList::ConstIterator it = langs.begin(); it!=langs.end(); ++it) { |
581 | QString lang = *it; | 592 | QString lang = *it; |
582 | 593 | ||
583 | QTranslator * trans; | 594 | QTranslator * trans; |
584 | QString tfn; | 595 | QString tfn; |
585 | 596 | ||
586 | trans = new QTranslator(this); | 597 | trans = new QTranslator(this); |
587 | tfn = qpeDir()+"/i18n/"+lang+"/libqpe.qm"; | 598 | tfn = qpeDir()+"/i18n/"+lang+"/libqpe.qm"; |
588 | if ( trans->load( tfn )) | 599 | if ( trans->load( tfn )) |
589 | installTranslator( trans ); | 600 | installTranslator( trans ); |
590 | else | 601 | else |
591 | delete trans; | 602 | delete trans; |
592 | 603 | ||
593 | trans = new QTranslator(this); | 604 | trans = new QTranslator(this); |
594 | tfn = qpeDir()+"/i18n/"+lang+"/"+d->appName+".qm"; | 605 | tfn = qpeDir()+"/i18n/"+lang+"/"+d->appName+".qm"; |
595 | if ( trans->load( tfn )) | 606 | if ( trans->load( tfn )) |
596 | installTranslator( trans ); | 607 | installTranslator( trans ); |
597 | else | 608 | else |
598 | delete trans; | 609 | delete trans; |
599 | 610 | ||
600 | //###language/font hack; should look it up somewhere | 611 | //###language/font hack; should look it up somewhere |
601 | if ( lang == "ja" || lang == "zh_CN" || lang == "zh_TW" || lang == "ko" ) { | 612 | if ( lang == "ja" || lang == "zh_CN" || lang == "zh_TW" || lang == "ko" ) { |
602 | QFont fn = FontManager::unicodeFont( FontManager::Proportional ); | 613 | QFont fn = FontManager::unicodeFont( FontManager::Proportional ); |
603 | setFont( fn ); | 614 | setFont( fn ); |
604 | } | 615 | } |
605 | else { | 616 | else { |
606 | Config config( "qpe" ); | 617 | Config config( "qpe" ); |
607 | config.setGroup( "Appearance" ); | 618 | config.setGroup( "Appearance" ); |
608 | QString familyStr = config.readEntry( "FontFamily", "helvetica" ); | 619 | QString familyStr = config.readEntry( "FontFamily", "helvetica" ); |
609 | QString styleStr = config.readEntry( "FontStyle", "Regular" ); | 620 | QString styleStr = config.readEntry( "FontStyle", "Regular" ); |
610 | QString sizeStr = config.readEntry( "FontSize", "10" ); | 621 | QString sizeStr = config.readEntry( "FontSize", "10" ); |
611 | QString charSetStr = config.readEntry( "FontCharSet", QString::null ); | 622 | QString charSetStr = config.readEntry( "FontCharSet", QString::null ); |
612 | bool ok; | 623 | bool ok; |
613 | int i_size = sizeStr.toInt( &ok, 10 ); | 624 | int i_size = sizeStr.toInt( &ok, 10 ); |
614 | FontDatabase fdb; | 625 | FontDatabase fdb; |
615 | QFont selectedFont = fdb.font( familyStr, styleStr, i_size, charSetStr ); | 626 | QFont selectedFont = fdb.font( familyStr, styleStr, i_size, charSetStr ); |
616 | setFont( selectedFont ); | 627 | setFont( selectedFont ); |
617 | } | 628 | } |
618 | } | 629 | } |
619 | 630 | ||
620 | #endif | 631 | #endif |
621 | 632 | ||
622 | applyStyle(); | 633 | applyStyle(); |
623 | 634 | ||
624 | if ( type() == GuiServer ) { | 635 | if ( type() == GuiServer ) { |
625 | setScreenSaverInterval(-1); | 636 | setScreenSaverInterval(-1); |
626 | setVolume(); | 637 | setVolume(); |
627 | QWSServer::setScreenSaver(new QPEScreenSaver); | 638 | QWSServer::setScreenSaver(new QPEScreenSaver); |
628 | } | 639 | } |
629 | 640 | ||
630 | installEventFilter( this ); | 641 | installEventFilter( this ); |
631 | 642 | ||
632 | QPEMenuToolFocusManager::initialize(); | 643 | QPEMenuToolFocusManager::initialize(); |
633 | 644 | ||
634 | #ifdef QT_NO_QWS_CURSOR | 645 | #ifdef QT_NO_QWS_CURSOR |
635 | // if we have no cursor, probably don't want tooltips | 646 | // if we have no cursor, probably don't want tooltips |
636 | QToolTip::setEnabled( FALSE ); | 647 | QToolTip::setEnabled( FALSE ); |
637 | #endif | 648 | #endif |
638 | } | 649 | } |
639 | 650 | ||
640 | static QPtrDict<void>* inputMethodDict=0; | 651 | static QPtrDict<void>* inputMethodDict=0; |
641 | static void createInputMethodDict() | 652 | static void createInputMethodDict() |
642 | { | 653 | { |
643 | if ( !inputMethodDict ) | 654 | if ( !inputMethodDict ) |
644 | inputMethodDict = new QPtrDict<void>; | 655 | inputMethodDict = new QPtrDict<void>; |
645 | } | 656 | } |
646 | 657 | ||
647 | /*! | 658 | /*! |
648 | Returns the currently set hint to the system as to whether | 659 | Returns the currently set hint to the system as to whether |
649 | \a w has any use for text input methods. | 660 | \a w has any use for text input methods. |
650 | 661 | ||
651 | \sa setInputMethodHint() | 662 | \sa setInputMethodHint() |
652 | */ | 663 | */ |
653 | QPEApplication::InputMethodHint QPEApplication::inputMethodHint( QWidget* w ) | 664 | QPEApplication::InputMethodHint QPEApplication::inputMethodHint( QWidget* w ) |
654 | { | 665 | { |
655 | if ( inputMethodDict && w ) | 666 | if ( inputMethodDict && w ) |
656 | return (InputMethodHint)(int)inputMethodDict->find(w); | 667 | return (InputMethodHint)(int)inputMethodDict->find(w); |
657 | return Normal; | 668 | return Normal; |
658 | } | 669 | } |
659 | 670 | ||
660 | /*! | 671 | /*! |
661 | \enum QPEApplication::InputMethodHint | 672 | \enum QPEApplication::InputMethodHint |
662 | 673 | ||
663 | \value Normal the application sometimes needs text input (the default). | 674 | \value Normal the application sometimes needs text input (the default). |
664 | \value AlwaysOff the application never needs text input. | 675 | \value AlwaysOff the application never needs text input. |
665 | \value AlwaysOn the application always needs text input. | 676 | \value AlwaysOn the application always needs text input. |
666 | */ | 677 | */ |
667 | 678 | ||
668 | /*! | 679 | /*! |
669 | Hints to the system that \a w has use for text input methods | 680 | Hints to the system that \a w has use for text input methods |
670 | as specified by \a mode. | 681 | as specified by \a mode. |
671 | 682 | ||
672 | \sa inputMethodHint() | 683 | \sa inputMethodHint() |
673 | */ | 684 | */ |
674 | void QPEApplication::setInputMethodHint( QWidget* w, InputMethodHint mode ) | 685 | void QPEApplication::setInputMethodHint( QWidget* w, InputMethodHint mode ) |
675 | { | 686 | { |
676 | createInputMethodDict(); | 687 | createInputMethodDict(); |
677 | if ( mode == Normal ) { | 688 | if ( mode == Normal ) { |
678 | inputMethodDict->remove(w); | 689 | inputMethodDict->remove(w); |
679 | } else { | 690 | } else { |
680 | inputMethodDict->insert(w,(void*)mode); | 691 | inputMethodDict->insert(w,(void*)mode); |
681 | } | 692 | } |
682 | } | 693 | } |
683 | 694 | ||
684 | class HackDialog : public QDialog | 695 | class HackDialog : public QDialog |
685 | { | 696 | { |
686 | public: | 697 | public: |
687 | void acceptIt() { accept(); } | 698 | void acceptIt() { accept(); } |
688 | void rejectIt() { reject(); } | 699 | void rejectIt() { reject(); } |
689 | }; | 700 | }; |
690 | 701 | ||
691 | 702 | ||
692 | void QPEApplication::mapToDefaultAction( QWSKeyEvent *ke, int key ) | 703 | void QPEApplication::mapToDefaultAction( QWSKeyEvent *ke, int key ) |
693 | { | 704 | { |
694 | // specialised actions for certain widgets. May want to | 705 | // specialised actions for certain widgets. May want to |
695 | // add more stuff here. | 706 | // add more stuff here. |
696 | if ( activePopupWidget() && activePopupWidget()->inherits( "QListBox" ) | 707 | if ( activePopupWidget() && activePopupWidget()->inherits( "QListBox" ) |
697 | && activePopupWidget()->parentWidget() | 708 | && activePopupWidget()->parentWidget() |
698 | && activePopupWidget()->parentWidget()->inherits( "QComboBox" ) ) | 709 | && activePopupWidget()->parentWidget()->inherits( "QComboBox" ) ) |
699 | key = Qt::Key_Return; | 710 | key = Qt::Key_Return; |
700 | 711 | ||
701 | if ( activePopupWidget() && activePopupWidget()->inherits( "QPopupMenu" ) ) | 712 | if ( activePopupWidget() && activePopupWidget()->inherits( "QPopupMenu" ) ) |
702 | key = Qt::Key_Return; | 713 | key = Qt::Key_Return; |
703 | 714 | ||
704 | ke->simpleData.keycode = key; | 715 | ke->simpleData.keycode = key; |
705 | } | 716 | } |
706 | 717 | ||
707 | class HackWidget : public QWidget | 718 | class HackWidget : public QWidget |
708 | { | 719 | { |
709 | public: | 720 | public: |
710 | bool needsOk() | 721 | bool needsOk() |
711 | { return (getWState() & WState_Reserved1 ); } | 722 | { return (getWState() & WState_Reserved1 ); } |
712 | }; | 723 | }; |
713 | 724 | ||
714 | /*! | 725 | /*! |
715 | \internal | 726 | \internal |
716 | */ | 727 | */ |
717 | bool QPEApplication::qwsEventFilter( QWSEvent *e ) | 728 | bool QPEApplication::qwsEventFilter( QWSEvent *e ) |
718 | { | 729 | { |
719 | if ( !d->notbusysent && e->type == QWSEvent::Focus ) { | 730 | if ( !d->notbusysent && e->type == QWSEvent::Focus ) { |
720 | if ( qApp->type() != QApplication::GuiServer ) { | 731 | if ( qApp->type() != QApplication::GuiServer ) { |
721 | QCopEnvelope e("QPE/System", "notBusy(QString)" ); | 732 | QCopEnvelope e("QPE/System", "notBusy(QString)" ); |
722 | e << d->appName; | 733 | e << d->appName; |
723 | } | 734 | } |
724 | d->notbusysent=TRUE; | 735 | d->notbusysent=TRUE; |
725 | } | 736 | } |
726 | if ( type() == GuiServer ) { | 737 | if ( type() == GuiServer ) { |
727 | switch ( e->type ) { | 738 | switch ( e->type ) { |
728 | case QWSEvent::Mouse: | 739 | case QWSEvent::Mouse: |
729 | if ( e->asMouse()->simpleData.state && !QWidget::find(e->window()) ) | 740 | if ( e->asMouse()->simpleData.state && !QWidget::find(e->window()) ) |
730 | emit clientMoused(); | 741 | emit clientMoused(); |
731 | } | 742 | } |
732 | } | 743 | } |
733 | if ( e->type == QWSEvent::Key ) { | 744 | if ( e->type == QWSEvent::Key ) { |
734 | if ( d->kbgrabber == 1 ) | 745 | if ( d->kbgrabber == 1 ) |
735 | return TRUE; | 746 | return TRUE; |
736 | QWSKeyEvent *ke = (QWSKeyEvent *)e; | 747 | QWSKeyEvent *ke = (QWSKeyEvent *)e; |
737 | if ( ke->simpleData.keycode == Qt::Key_F33 ) { | 748 | if ( ke->simpleData.keycode == Qt::Key_F33 ) { |
738 | // Use special "OK" key to press "OK" on top level widgets | 749 | // Use special "OK" key to press "OK" on top level widgets |
739 | QWidget *active = activeWindow(); | 750 | QWidget *active = activeWindow(); |
740 | QWidget *popup = 0; | 751 | QWidget *popup = 0; |
741 | if ( active && active->isPopup() ) { | 752 | if ( active && active->isPopup() ) { |
742 | popup = active; | 753 | popup = active; |
743 | active = active->parentWidget(); | 754 | active = active->parentWidget(); |
744 | } | 755 | } |
745 | if ( active && (int)active->winId() == ke->simpleData.window && | 756 | if ( active && (int)active->winId() == ke->simpleData.window && |
746 | !active->testWFlags( WStyle_Customize|WType_Popup|WType_Desktop )) { | 757 | !active->testWFlags( WStyle_Customize|WType_Popup|WType_Desktop )) { |
747 | if ( ke->simpleData.is_press ) { | 758 | if ( ke->simpleData.is_press ) { |
748 | if ( popup ) | 759 | if ( popup ) |
749 | popup->close(); | 760 | popup->close(); |
750 | if ( active->inherits( "QDialog" ) ) { | 761 | if ( active->inherits( "QDialog" ) ) { |
751 | HackDialog *d = (HackDialog *)active; | 762 | HackDialog *d = (HackDialog *)active; |
752 | d->acceptIt(); | 763 | d->acceptIt(); |
753 | return TRUE; | 764 | return TRUE; |
754 | } else if ( ((HackWidget *)active)->needsOk() ) { | 765 | } else if ( ((HackWidget *)active)->needsOk() ) { |
755 | QSignal s; | 766 | QSignal s; |
756 | s.connect( active, SLOT( accept() ) ); | 767 | s.connect( active, SLOT( accept() ) ); |
757 | s.activate(); | 768 | s.activate(); |
758 | } else { | 769 | } else { |
759 | // do the same as with the select key: Map to the default action of the widget: | 770 | // do the same as with the select key: Map to the default action of the widget: |
760 | mapToDefaultAction( ke, Qt::Key_Return ); | 771 | mapToDefaultAction( ke, Qt::Key_Return ); |
761 | } | 772 | } |
762 | } | 773 | } |
763 | } | 774 | } |
764 | } else if ( ke->simpleData.keycode == Qt::Key_F30 ) { | 775 | } else if ( ke->simpleData.keycode == Qt::Key_F30 ) { |
765 | // Use special "select" key to do whatever default action a widget has | 776 | // Use special "select" key to do whatever default action a widget has |
766 | mapToDefaultAction( ke, Qt::Key_Space ); | 777 | mapToDefaultAction( ke, Qt::Key_Space ); |
767 | } else if ( ke->simpleData.keycode == Qt::Key_Escape && | 778 | } else if ( ke->simpleData.keycode == Qt::Key_Escape && |
768 | ke->simpleData.is_press ) { | 779 | ke->simpleData.is_press ) { |
769 | // Escape key closes app if focus on toplevel | 780 | // Escape key closes app if focus on toplevel |
770 | QWidget *active = activeWindow(); | 781 | QWidget *active = activeWindow(); |
771 | if ( active && active->testWFlags( WType_TopLevel ) && | 782 | if ( active && active->testWFlags( WType_TopLevel ) && |
772 | (int)active->winId() == ke->simpleData.window && | 783 | (int)active->winId() == ke->simpleData.window && |
773 | !active->testWFlags( WStyle_Dialog|WStyle_Customize|WType_Popup|WType_Desktop )) { | 784 | !active->testWFlags( WStyle_Dialog|WStyle_Customize|WType_Popup|WType_Desktop )) { |
774 | if ( active->inherits( "QDialog" ) ) { | 785 | if ( active->inherits( "QDialog" ) ) { |
775 | HackDialog *d = (HackDialog *)active; | 786 | HackDialog *d = (HackDialog *)active; |
776 | d->rejectIt(); | 787 | d->rejectIt(); |
777 | return TRUE; | 788 | return TRUE; |
778 | } else if ( strcmp( argv()[0], "embeddedkonsole") != 0 ) { | 789 | } else if ( strcmp( argv()[0], "embeddedkonsole") != 0 ) { |
779 | active->close(); | 790 | active->close(); |
780 | } | 791 | } |
781 | } | 792 | } |
782 | } | 793 | } |
783 | 794 | ||
784 | #if QT_VERSION < 231 | 795 | #if QT_VERSION < 231 |
785 | // Filter out the F4/Launcher key from apps | 796 | // Filter out the F4/Launcher key from apps |
786 | // ### The launcher key may not always be F4 on all devices | 797 | // ### The launcher key may not always be F4 on all devices |
787 | if ( ((QWSKeyEvent *)e)->simpleData.keycode == Qt::Key_F4 ) | 798 | if ( ((QWSKeyEvent *)e)->simpleData.keycode == Qt::Key_F4 ) |
788 | return TRUE; | 799 | return TRUE; |
789 | #endif | 800 | #endif |
790 | } | 801 | } |
791 | if ( e->type == QWSEvent::Focus ) { | 802 | if ( e->type == QWSEvent::Focus ) { |
792 | QWSFocusEvent *fe = (QWSFocusEvent*)e; | 803 | QWSFocusEvent *fe = (QWSFocusEvent*)e; |
793 | QWidget* nfw = QWidget::find(e->window()); | 804 | QWidget* nfw = QWidget::find(e->window()); |
794 | if ( !fe->simpleData.get_focus ) { | 805 | if ( !fe->simpleData.get_focus ) { |
795 | QWidget *active = activeWindow(); | 806 | QWidget *active = activeWindow(); |
796 | while ( active && active->isPopup() ) { | 807 | while ( active && active->isPopup() ) { |
797 | active->close(); | 808 | active->close(); |
798 | active = activeWindow(); | 809 | active = activeWindow(); |
799 | } | 810 | } |
800 | if ( !nfw && d->kbgrabber == 2 ) { | 811 | if ( !nfw && d->kbgrabber == 2 ) { |
801 | ungrabKeyboard(); | 812 | ungrabKeyboard(); |
802 | d->kbregrab = TRUE; // want kb back when we're active | 813 | d->kbregrab = TRUE; // want kb back when we're active |
803 | } | 814 | } |
804 | } else { | 815 | } else { |
805 | // make sure our modal widget is ALWAYS on top | 816 | // make sure our modal widget is ALWAYS on top |
806 | QWidget *topm = activeModalWidget(); | 817 | QWidget *topm = activeModalWidget(); |
807 | if ( topm ) { | 818 | if ( topm ) { |
808 | topm->raise(); | 819 | topm->raise(); |
809 | } | 820 | } |
810 | if ( d->kbregrab ) { | 821 | if ( d->kbregrab ) { |
811 | grabKeyboard(); | 822 | grabKeyboard(); |
812 | d->kbregrab = FALSE; | 823 | d->kbregrab = FALSE; |
813 | } | 824 | } |
814 | } | 825 | } |
815 | if ( fe->simpleData.get_focus && inputMethodDict ) { | 826 | if ( fe->simpleData.get_focus && inputMethodDict ) { |
816 | InputMethodHint m = inputMethodHint( QWidget::find(e->window()) ); | 827 | InputMethodHint m = inputMethodHint( QWidget::find(e->window()) ); |
817 | if ( m == AlwaysOff ) | 828 | if ( m == AlwaysOff ) |
818 | Global::hideInputMethod(); | 829 | Global::hideInputMethod(); |
819 | if ( m == AlwaysOn ) | 830 | if ( m == AlwaysOn ) |