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