-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 cf76000..755fb19 100644 --- a/library/qpeapplication.cpp +++ b/library/qpeapplication.cpp | |||
@@ -1,947 +1,958 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of the Qtopia Environment. | 4 | ** This file is part of the 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 | */ | 19 | */ |
20 | #define QTOPIA_INTERNAL_LANGLIST | 20 | #define QTOPIA_INTERNAL_LANGLIST |
21 | #include <stdlib.h> | 21 | #include <stdlib.h> |
22 | #include <unistd.h> | 22 | #include <unistd.h> |
23 | #ifndef Q_OS_MACX | 23 | #ifndef Q_OS_MACX |
24 | #include <linux/limits.h> // needed for some toolchains (PATH_MAX) | 24 | #include <linux/limits.h> // needed for some toolchains (PATH_MAX) |
25 | #endif | 25 | #endif |
26 | #include <qfile.h> | 26 | #include <qfile.h> |
27 | #include <qqueue.h> | 27 | #include <qqueue.h> |
28 | #ifdef Q_WS_QWS | 28 | #ifdef Q_WS_QWS |
29 | #ifndef QT_NO_COP | 29 | #ifndef QT_NO_COP |
30 | #if QT_VERSION <= 231 | 30 | #if QT_VERSION <= 231 |
31 | #define private public | 31 | #define private public |
32 | #define sendLocally processEvent | 32 | #define sendLocally processEvent |
33 | #include "qcopenvelope_qws.h" | 33 | #include "qcopenvelope_qws.h" |
34 | #undef private | 34 | #undef private |
35 | #else | 35 | #else |
36 | #include "qcopenvelope_qws.h" | 36 | #include "qcopenvelope_qws.h" |
37 | #endif | 37 | #endif |
38 | #endif | 38 | #endif |
39 | #include <qwindowsystem_qws.h> | 39 | #include <qwindowsystem_qws.h> |
40 | #endif | 40 | #endif |
41 | #include <qtextstream.h> | 41 | #include <qtextstream.h> |
42 | #include <qpalette.h> | 42 | #include <qpalette.h> |
43 | #include <qbuffer.h> | 43 | #include <qbuffer.h> |
44 | #include <qptrdict.h> | 44 | #include <qptrdict.h> |
45 | #include <qregexp.h> | 45 | #include <qregexp.h> |
46 | #include <qdir.h> | 46 | #include <qdir.h> |
47 | #include <qlabel.h> | 47 | #include <qlabel.h> |
48 | #include <qdialog.h> | 48 | #include <qdialog.h> |
49 | #include <qdragobject.h> | 49 | #include <qdragobject.h> |
50 | #include <qtextcodec.h> | 50 | #include <qtextcodec.h> |
51 | #include <qevent.h> | 51 | #include <qevent.h> |
52 | #include <qtooltip.h> | 52 | #include <qtooltip.h> |
53 | #include <qsignal.h> | 53 | #include <qsignal.h> |
54 | #include <qmainwindow.h> | 54 | #include <qmainwindow.h> |
55 | #include <qwidgetlist.h> | 55 | #include <qwidgetlist.h> |
56 | #include <qpixmapcache.h> | 56 | #include <qpixmapcache.h> |
57 | 57 | ||
58 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 58 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
59 | #define QTOPIA_INTERNAL_INITAPP | 59 | #define QTOPIA_INTERNAL_INITAPP |
60 | #include "qpeapplication.h" | 60 | #include "qpeapplication.h" |
61 | #include "qpestyle.h" | 61 | #include "qpestyle.h" |
62 | #include "styleinterface.h" | 62 | #include "styleinterface.h" |
63 | #if QT_VERSION >= 300 | 63 | #if QT_VERSION >= 300 |
64 | #include <qstylefactory.h> | 64 | #include <qstylefactory.h> |
65 | #else | 65 | #else |
66 | #include <qplatinumstyle.h> | 66 | #include <qplatinumstyle.h> |
67 | #include <qwindowsstyle.h> | 67 | #include <qwindowsstyle.h> |
68 | #include <qmotifstyle.h> | 68 | #include <qmotifstyle.h> |
69 | #include <qmotifplusstyle.h> | 69 | #include <qmotifplusstyle.h> |
70 | #include "lightstyle.h" | 70 | #include "lightstyle.h" |
71 | 71 | ||
72 | #include <qpe/qlibrary.h> | 72 | #include <qpe/qlibrary.h> |
73 | #endif | 73 | #endif |
74 | #include "global.h" | 74 | #include "global.h" |
75 | #include "resource.h" | 75 | #include "resource.h" |
76 | #if QT_VERSION <= 230 && defined(QT_NO_CODECS) | 76 | #if QT_VERSION <= 230 && defined(QT_NO_CODECS) |
77 | #include "qutfcodec.h" | 77 | #include "qutfcodec.h" |
78 | #endif | 78 | #endif |
79 | #include "config.h" | 79 | #include "config.h" |
80 | #include "network.h" | 80 | #include "network.h" |
81 | #ifdef QWS | 81 | #ifdef QWS |
82 | #include "fontmanager.h" | 82 | #include "fontmanager.h" |
83 | #endif | 83 | #endif |
84 | 84 | ||
85 | #include "alarmserver.h" | 85 | #include "alarmserver.h" |
86 | #include "applnk.h" | 86 | #include "applnk.h" |
87 | #include "qpemenubar.h" | 87 | #include "qpemenubar.h" |
88 | #include "textcodecinterface.h" | 88 | #include "textcodecinterface.h" |
89 | #include "imagecodecinterface.h" | 89 | #include "imagecodecinterface.h" |
90 | 90 | ||
91 | #include <unistd.h> | 91 | #include <unistd.h> |
92 | #include <sys/file.h> | 92 | #include <sys/file.h> |
93 | #include <sys/ioctl.h> | 93 | #include <sys/ioctl.h> |
94 | #ifndef QT_NO_SOUND | 94 | #ifndef QT_NO_SOUND |
95 | #include <sys/soundcard.h> | 95 | #include <sys/soundcard.h> |
96 | #endif | 96 | #endif |
97 | #include "qt_override_p.h" | 97 | #include "qt_override_p.h" |
98 | 98 | ||
99 | 99 | ||
100 | class QPEApplicationData | 100 | class QPEApplicationData |
101 | { | 101 | { |
102 | public: | 102 | public: |
103 | QPEApplicationData ( ) | 103 | QPEApplicationData ( ) |
104 | : presstimer( 0 ), presswidget( 0 ), rightpressed( false ), kbgrabbed( false ), | 104 | : presstimer( 0 ), presswidget( 0 ), rightpressed( false ), kbgrabbed( false ), |
105 | notbusysent( false ), preloaded( false ), forceshow( false ), nomaximize( false ), | 105 | notbusysent( false ), preloaded( false ), forceshow( false ), nomaximize( false ), |
106 | keep_running( true ), qcopQok( false ), qpe_main_widget( 0 ) | 106 | keep_running( true ), qcopQok( false ), qpe_main_widget( 0 ) |
107 | 107 | ||
108 | {} | 108 | {} |
109 | 109 | ||
110 | int presstimer; | 110 | int presstimer; |
111 | QWidget* presswidget; | 111 | QWidget* presswidget; |
112 | QPoint presspos; | 112 | QPoint presspos; |
113 | 113 | ||
114 | bool rightpressed : 1; | 114 | bool rightpressed : 1; |
115 | bool kbgrabbed : 1; | 115 | bool kbgrabbed : 1; |
116 | bool notbusysent : 1; | 116 | bool notbusysent : 1; |
117 | bool preloaded : 1; | 117 | bool preloaded : 1; |
118 | bool forceshow : 1; | 118 | bool forceshow : 1; |
119 | bool nomaximize : 1; | 119 | bool nomaximize : 1; |
120 | bool keep_running : 1; | 120 | bool keep_running : 1; |
121 | bool qcopQok : 1; | 121 | bool qcopQok : 1; |
122 | 122 | ||
123 | 123 | ||
124 | QStringList langs; | 124 | QStringList langs; |
125 | QString appName; | 125 | QString appName; |
126 | struct QCopRec | 126 | struct QCopRec |
127 | { | 127 | { |
128 | QCopRec( const QCString &ch, const QCString &msg, | 128 | QCopRec( const QCString &ch, const QCString &msg, |
129 | const QByteArray &d ) : | 129 | const QByteArray &d ) : |
130 | channel( ch ), message( msg ), data( d ) | 130 | channel( ch ), message( msg ), data( d ) |
131 | { } | 131 | { } |
132 | 132 | ||
133 | QCString channel; | 133 | QCString channel; |
134 | QCString message; | 134 | QCString message; |
135 | QByteArray data; | 135 | QByteArray data; |
136 | }; | 136 | }; |
137 | QWidget* qpe_main_widget; | 137 | QWidget* qpe_main_widget; |
138 | QGuardedPtr<QWidget> lastraised; | 138 | QGuardedPtr<QWidget> lastraised; |
139 | QQueue<QCopRec> qcopq; | 139 | QQueue<QCopRec> qcopq; |
140 | QString styleName; | 140 | QString styleName; |
141 | QString decorationName; | 141 | QString decorationName; |
142 | 142 | ||
143 | void enqueueQCop( const QCString &ch, const QCString &msg, | 143 | void enqueueQCop( const QCString &ch, const QCString &msg, |
144 | const QByteArray &data ) | 144 | const QByteArray &data ) |
145 | { | 145 | { |
146 | qcopq.enqueue( new QCopRec( ch, msg, data ) ); | 146 | qcopq.enqueue( new QCopRec( ch, msg, data ) ); |
147 | } | 147 | } |
148 | void sendQCopQ() | 148 | void sendQCopQ() |
149 | { | 149 | { |
150 | if (!qcopQok ) | 150 | if (!qcopQok ) |
151 | return; | 151 | return; |
152 | 152 | ||
153 | QCopRec * r; | 153 | QCopRec * r; |
154 | 154 | ||
155 | while((r=qcopq.dequeue())) { | 155 | while((r=qcopq.dequeue())) { |
156 | // remove from queue before sending... | 156 | // remove from queue before sending... |
157 | // event loop can come around again before getting | 157 | // event loop can come around again before getting |
158 | // back from sendLocally | 158 | // back from sendLocally |
159 | #ifndef QT_NO_COP | 159 | #ifndef QT_NO_COP |
160 | QCopChannel::sendLocally( r->channel, r->message, r->data ); | 160 | QCopChannel::sendLocally( r->channel, r->message, r->data ); |
161 | #endif | 161 | #endif |
162 | 162 | ||
163 | delete r; | 163 | delete r; |
164 | } | 164 | } |
165 | } | 165 | } |
166 | static void show_mx(QWidget* mw, bool nomaximize, const QString & = QString::null ) | 166 | static void show_mx(QWidget* mw, bool nomaximize, const QString & = QString::null ) |
167 | { | 167 | { |
168 | 168 | ||
169 | // ugly hack, remove that later after finding a sane solution | 169 | // ugly hack, remove that later after finding a sane solution |
170 | // Addendum: Only Sharp currently has models with high resolution but (physically) small displays, | 170 | // Addendum: Only Sharp currently has models with high resolution but (physically) small displays, |
171 | // so this is only useful if QT_QWS_SIMPAD is NOT defined. E.g. SIMpad has 800x600 but has | 171 | // so this is only useful if QT_QWS_SIMPAD is NOT defined. E.g. SIMpad has 800x600 but has |
172 | // a (physically) large enough display to use the small icons | 172 | // a (physically) large enough display to use the small icons |
173 | #if defined(OPIE_HIGH_RES_SMALL_PHY) | 173 | #if defined(OPIE_HIGH_RES_SMALL_PHY) |
174 | if ( QPEApplication::desktop() ->width() >= 600 && ( mw->inherits("QMainWindow") || mw->isA("QMainWindow") ) ) { | 174 | if ( QPEApplication::desktop() ->width() >= 600 && ( mw->inherits("QMainWindow") || mw->isA("QMainWindow") ) ) { |
175 | ( ( QMainWindow* ) mw )->setUsesBigPixmaps( true ); | 175 | ( ( QMainWindow* ) mw )->setUsesBigPixmaps( true ); |
176 | } | 176 | } |
177 | #endif | 177 | #endif |
178 | 178 | ||
179 | QPEApplication::showWidget( mw, nomaximize ); | 179 | if ( mw->layout() && mw->inherits("QDialog") ) { |
180 | QPEApplication::showDialog((QDialog*)mw, nomaximize); | ||
181 | } | ||
182 | else { | ||
183 | #ifdef Q_WS_QWS | ||
184 | if ( !nomaximize ) | ||
185 | mw->showMaximized(); | ||
186 | else | ||
187 | #endif | ||
188 | |||
189 | mw->show(); | ||
190 | } | ||
180 | } | 191 | } |
181 | static bool setWidgetCaptionFromAppName( QWidget* /*mw*/, const QString& /*appName*/, const QString& /*appsPath*/ ) | 192 | static bool setWidgetCaptionFromAppName( QWidget* /*mw*/, const QString& /*appName*/, const QString& /*appsPath*/ ) |
182 | { | 193 | { |
183 | /* | 194 | /* |
184 | // This works but disable it for now until it is safe to apply | 195 | // This works but disable it for now until it is safe to apply |
185 | // What is does is scan the .desktop files of all the apps for | 196 | // What is does is scan the .desktop files of all the apps for |
186 | // the applnk that has the corresponding argv[0] as this program | 197 | // the applnk that has the corresponding argv[0] as this program |
187 | // then it uses the name stored in the .desktop file as the caption | 198 | // then it uses the name stored in the .desktop file as the caption |
188 | // for the main widget. This saves duplicating translations for | 199 | // for the main widget. This saves duplicating translations for |
189 | // the app name in the program and in the .desktop files. | 200 | // the app name in the program and in the .desktop files. |
190 | 201 | ||
191 | AppLnkSet apps( appsPath ); | 202 | AppLnkSet apps( appsPath ); |
192 | 203 | ||
193 | QList<AppLnk> appsList = apps.children(); | 204 | QList<AppLnk> appsList = apps.children(); |
194 | for ( QListIterator<AppLnk> it(appsList); it.current(); ++it ) { | 205 | for ( QListIterator<AppLnk> it(appsList); it.current(); ++it ) { |
195 | if ( (*it)->exec() == appName ) { | 206 | if ( (*it)->exec() == appName ) { |
196 | mw->setCaption( (*it)->name() ); | 207 | mw->setCaption( (*it)->name() ); |
197 | return TRUE; | 208 | return TRUE; |
198 | } | 209 | } |
199 | } | 210 | } |
200 | */ | 211 | */ |
201 | return FALSE; | 212 | return FALSE; |
202 | } | 213 | } |
203 | 214 | ||
204 | 215 | ||
205 | void show(QWidget* mw, bool nomax) | 216 | void show(QWidget* mw, bool nomax) |
206 | { | 217 | { |
207 | setWidgetCaptionFromAppName( mw, appName, QPEApplication::qpeDir() + "apps" ); | 218 | setWidgetCaptionFromAppName( mw, appName, QPEApplication::qpeDir() + "apps" ); |
208 | nomaximize = nomax; | 219 | nomaximize = nomax; |
209 | qpe_main_widget = mw; | 220 | qpe_main_widget = mw; |
210 | qcopQok = TRUE; | 221 | qcopQok = TRUE; |
211 | #ifndef QT_NO_COP | 222 | #ifndef QT_NO_COP |
212 | 223 | ||
213 | sendQCopQ(); | 224 | sendQCopQ(); |
214 | #endif | 225 | #endif |
215 | 226 | ||
216 | if ( preloaded ) { | 227 | if ( preloaded ) { |
217 | if (forceshow) | 228 | if (forceshow) |
218 | show_mx(mw, nomax); | 229 | show_mx(mw, nomax); |
219 | } | 230 | } |
220 | else if ( keep_running ) { | 231 | else if ( keep_running ) { |
221 | show_mx(mw, nomax); | 232 | show_mx(mw, nomax); |
222 | } | 233 | } |
223 | } | 234 | } |
224 | 235 | ||
225 | void loadTextCodecs() | 236 | void loadTextCodecs() |
226 | { | 237 | { |
227 | QString path = QPEApplication::qpeDir() + "/plugins/textcodecs"; | 238 | QString path = QPEApplication::qpeDir() + "/plugins/textcodecs"; |
228 | #ifdef Q_OS_MACX | 239 | #ifdef Q_OS_MACX |
229 | QDir dir( path, "lib*.dylib" ); | 240 | QDir dir( path, "lib*.dylib" ); |
230 | #else | 241 | #else |
231 | QDir dir( path, "lib*.so" ); | 242 | QDir dir( path, "lib*.so" ); |
232 | #endif | 243 | #endif |
233 | QStringList list; | 244 | QStringList list; |
234 | if ( dir. exists ( )) | 245 | if ( dir. exists ( )) |
235 | list = dir.entryList(); | 246 | list = dir.entryList(); |
236 | QStringList::Iterator it; | 247 | QStringList::Iterator it; |
237 | for ( it = list.begin(); it != list.end(); ++it ) { | 248 | for ( it = list.begin(); it != list.end(); ++it ) { |
238 | TextCodecInterface *iface = 0; | 249 | TextCodecInterface *iface = 0; |
239 | QLibrary *lib = new QLibrary( path + "/" + *it ); | 250 | QLibrary *lib = new QLibrary( path + "/" + *it ); |
240 | if ( lib->queryInterface( IID_QtopiaTextCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) { | 251 | if ( lib->queryInterface( IID_QtopiaTextCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) { |
241 | QValueList<int> mibs = iface->mibEnums(); | 252 | QValueList<int> mibs = iface->mibEnums(); |
242 | for (QValueList<int>::ConstIterator i = mibs.begin(); i != mibs.end(); ++i) { | 253 | for (QValueList<int>::ConstIterator i = mibs.begin(); i != mibs.end(); ++i) { |
243 | (void)iface->createForMib(*i); | 254 | (void)iface->createForMib(*i); |
244 | // ### it exists now; need to remember if we can delete it | 255 | // ### it exists now; need to remember if we can delete it |
245 | } | 256 | } |
246 | } | 257 | } |
247 | else { | 258 | else { |
248 | lib->unload(); | 259 | lib->unload(); |
249 | delete lib; | 260 | delete lib; |
250 | } | 261 | } |
251 | } | 262 | } |
252 | } | 263 | } |
253 | 264 | ||
254 | void loadImageCodecs() | 265 | void loadImageCodecs() |
255 | { | 266 | { |
256 | QString path = QPEApplication::qpeDir() + "/plugins/imagecodecs"; | 267 | QString path = QPEApplication::qpeDir() + "/plugins/imagecodecs"; |
257 | #ifdef Q_OS_MACX | 268 | #ifdef Q_OS_MACX |
258 | QDir dir( path, "lib*.dylib" ); | 269 | QDir dir( path, "lib*.dylib" ); |
259 | #else | 270 | #else |
260 | QDir dir( path, "lib*.so" ); | 271 | QDir dir( path, "lib*.so" ); |
261 | #endif | 272 | #endif |
262 | QStringList list; | 273 | QStringList list; |
263 | if ( dir. exists ( )) | 274 | if ( dir. exists ( )) |
264 | list = dir.entryList(); | 275 | list = dir.entryList(); |
265 | QStringList::Iterator it; | 276 | QStringList::Iterator it; |
266 | for ( it = list.begin(); it != list.end(); ++it ) { | 277 | for ( it = list.begin(); it != list.end(); ++it ) { |
267 | ImageCodecInterface *iface = 0; | 278 | ImageCodecInterface *iface = 0; |
268 | QLibrary *lib = new QLibrary( path + "/" + *it ); | 279 | QLibrary *lib = new QLibrary( path + "/" + *it ); |
269 | if ( lib->queryInterface( IID_QtopiaImageCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) { | 280 | if ( lib->queryInterface( IID_QtopiaImageCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) { |
270 | QStringList formats = iface->keys(); | 281 | QStringList formats = iface->keys(); |
271 | for (QStringList::ConstIterator i = formats.begin(); i != formats.end(); ++i) { | 282 | for (QStringList::ConstIterator i = formats.begin(); i != formats.end(); ++i) { |
272 | (void)iface->installIOHandler(*i); | 283 | (void)iface->installIOHandler(*i); |
273 | // ### it exists now; need to remember if we can delete it | 284 | // ### it exists now; need to remember if we can delete it |
274 | } | 285 | } |
275 | } | 286 | } |
276 | else { | 287 | else { |
277 | lib->unload(); | 288 | lib->unload(); |
278 | delete lib; | 289 | delete lib; |
279 | } | 290 | } |
280 | } | 291 | } |
281 | } | 292 | } |
282 | }; | 293 | }; |
283 | 294 | ||
284 | class ResourceMimeFactory : public QMimeSourceFactory | 295 | class ResourceMimeFactory : public QMimeSourceFactory |
285 | { | 296 | { |
286 | public: | 297 | public: |
287 | ResourceMimeFactory() : resImage( 0 ) | 298 | ResourceMimeFactory() : resImage( 0 ) |
288 | { | 299 | { |
289 | setFilePath( Global::helpPath() ); | 300 | setFilePath( Global::helpPath() ); |
290 | setExtensionType( "html", "text/html;charset=UTF-8" ); | 301 | setExtensionType( "html", "text/html;charset=UTF-8" ); |
291 | } | 302 | } |
292 | ~ResourceMimeFactory() { | 303 | ~ResourceMimeFactory() { |
293 | delete resImage; | 304 | delete resImage; |
294 | } | 305 | } |
295 | 306 | ||
296 | const QMimeSource* data( const QString& abs_name ) const | 307 | const QMimeSource* data( const QString& abs_name ) const |
297 | { | 308 | { |
298 | const QMimeSource * r = QMimeSourceFactory::data( abs_name ); | 309 | const QMimeSource * r = QMimeSourceFactory::data( abs_name ); |
299 | if ( !r ) { | 310 | if ( !r ) { |
300 | int sl = abs_name.length(); | 311 | int sl = abs_name.length(); |
301 | do { | 312 | do { |
302 | sl = abs_name.findRev( '/', sl - 1 ); | 313 | sl = abs_name.findRev( '/', sl - 1 ); |
303 | QString name = sl >= 0 ? abs_name.mid( sl + 1 ) : abs_name; | 314 | QString name = sl >= 0 ? abs_name.mid( sl + 1 ) : abs_name; |
304 | int dot = name.findRev( '.' ); | 315 | int dot = name.findRev( '.' ); |
305 | if ( dot >= 0 ) | 316 | if ( dot >= 0 ) |
306 | name = name.left( dot ); | 317 | name = name.left( dot ); |
307 | QImage img = Resource::loadImage( name ); | 318 | QImage img = Resource::loadImage( name ); |
308 | if ( !img.isNull() ) { | 319 | if ( !img.isNull() ) { |
309 | delete resImage; | 320 | delete resImage; |
310 | resImage = new QImageDrag( img ); | 321 | resImage = new QImageDrag( img ); |
311 | r = resImage; | 322 | r = resImage; |
312 | } | 323 | } |
313 | } | 324 | } |
314 | while ( !r && sl > 0 ); | 325 | while ( !r && sl > 0 ); |
315 | } | 326 | } |
316 | return r; | 327 | return r; |
317 | } | 328 | } |
318 | private: | 329 | private: |
319 | mutable QImageDrag *resImage; | 330 | mutable QImageDrag *resImage; |
320 | }; | 331 | }; |
321 | 332 | ||
322 | static int& hack(int& i) | 333 | static int& hack(int& i) |
323 | { | 334 | { |
324 | #if QT_VERSION <= 230 && defined(QT_NO_CODECS) | 335 | #if QT_VERSION <= 230 && defined(QT_NO_CODECS) |
325 | // These should be created, but aren't in Qt 2.3.0 | 336 | // These should be created, but aren't in Qt 2.3.0 |
326 | (void)new QUtf8Codec; | 337 | (void)new QUtf8Codec; |
327 | (void)new QUtf16Codec; | 338 | (void)new QUtf16Codec; |
328 | #endif | 339 | #endif |
329 | return i; | 340 | return i; |
330 | } | 341 | } |
331 | 342 | ||
332 | static int muted = 0; | 343 | static int muted = 0; |
333 | static int micMuted = 0; | 344 | static int micMuted = 0; |
334 | 345 | ||
335 | static void setVolume( int t = 0, int percent = -1 ) | 346 | static void setVolume( int t = 0, int percent = -1 ) |
336 | { | 347 | { |
337 | switch ( t ) { | 348 | switch ( t ) { |
338 | case 0: { | 349 | case 0: { |
339 | Config cfg( "qpe" ); | 350 | Config cfg( "qpe" ); |
340 | cfg.setGroup( "Volume" ); | 351 | cfg.setGroup( "Volume" ); |
341 | if ( percent < 0 ) | 352 | if ( percent < 0 ) |
342 | percent = cfg.readNumEntry( "VolumePercent", 50 ); | 353 | percent = cfg.readNumEntry( "VolumePercent", 50 ); |
343 | #ifndef QT_NO_SOUND | 354 | #ifndef QT_NO_SOUND |
344 | int fd = 0; | 355 | int fd = 0; |
345 | if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { | 356 | if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { |
346 | int vol = muted ? 0 : percent; | 357 | int vol = muted ? 0 : percent; |
347 | // set both channels to same volume | 358 | // set both channels to same volume |
348 | vol |= vol << 8; | 359 | vol |= vol << 8; |
349 | ioctl( fd, MIXER_WRITE( SOUND_MIXER_VOLUME ), &vol ); | 360 | ioctl( fd, MIXER_WRITE( SOUND_MIXER_VOLUME ), &vol ); |
350 | ::close( fd ); | 361 | ::close( fd ); |
351 | } | 362 | } |
352 | #endif | 363 | #endif |
353 | } | 364 | } |
354 | break; | 365 | break; |
355 | } | 366 | } |
356 | } | 367 | } |
357 | 368 | ||
358 | static void setMic( int t = 0, int percent = -1 ) | 369 | static void setMic( int t = 0, int percent = -1 ) |
359 | { | 370 | { |
360 | switch ( t ) { | 371 | switch ( t ) { |
361 | case 0: { | 372 | case 0: { |
362 | Config cfg( "qpe" ); | 373 | Config cfg( "qpe" ); |
363 | cfg.setGroup( "Volume" ); | 374 | cfg.setGroup( "Volume" ); |
364 | if ( percent < 0 ) | 375 | if ( percent < 0 ) |
365 | percent = cfg.readNumEntry( "Mic", 50 ); | 376 | percent = cfg.readNumEntry( "Mic", 50 ); |
366 | 377 | ||
367 | #ifndef QT_NO_SOUND | 378 | #ifndef QT_NO_SOUND |
368 | int fd = 0; | 379 | int fd = 0; |
369 | int mic = micMuted ? 0 : percent; | 380 | int mic = micMuted ? 0 : percent; |
370 | if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { | 381 | if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { |
371 | ioctl( fd, MIXER_WRITE( SOUND_MIXER_MIC ), &mic ); | 382 | ioctl( fd, MIXER_WRITE( SOUND_MIXER_MIC ), &mic ); |
372 | ::close( fd ); | 383 | ::close( fd ); |
373 | } | 384 | } |
374 | #endif | 385 | #endif |
375 | } | 386 | } |
376 | break; | 387 | break; |
377 | } | 388 | } |
378 | } | 389 | } |
379 | 390 | ||
380 | 391 | ||
381 | static void setBass( int t = 0, int percent = -1 ) | 392 | static void setBass( int t = 0, int percent = -1 ) |
382 | { | 393 | { |
383 | switch ( t ) { | 394 | switch ( t ) { |
384 | case 0: { | 395 | case 0: { |
385 | Config cfg( "qpe" ); | 396 | Config cfg( "qpe" ); |
386 | cfg.setGroup( "Volume" ); | 397 | cfg.setGroup( "Volume" ); |
387 | if ( percent < 0 ) | 398 | if ( percent < 0 ) |
388 | percent = cfg.readNumEntry( "BassPercent", 50 ); | 399 | percent = cfg.readNumEntry( "BassPercent", 50 ); |
389 | 400 | ||
390 | #ifndef QT_NO_SOUND | 401 | #ifndef QT_NO_SOUND |
391 | int fd = 0; | 402 | int fd = 0; |
392 | int bass = percent; | 403 | int bass = percent; |
393 | if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { | 404 | if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { |
394 | ioctl( fd, MIXER_WRITE( SOUND_MIXER_BASS ), &bass ); | 405 | ioctl( fd, MIXER_WRITE( SOUND_MIXER_BASS ), &bass ); |
395 | ::close( fd ); | 406 | ::close( fd ); |
396 | } | 407 | } |
397 | #endif | 408 | #endif |
398 | } | 409 | } |
399 | break; | 410 | break; |
400 | } | 411 | } |
401 | } | 412 | } |
402 | 413 | ||
403 | 414 | ||
404 | static void setTreble( int t = 0, int percent = -1 ) | 415 | static void setTreble( int t = 0, int percent = -1 ) |
405 | { | 416 | { |
406 | switch ( t ) { | 417 | switch ( t ) { |
407 | case 0: { | 418 | case 0: { |
408 | Config cfg( "qpe" ); | 419 | Config cfg( "qpe" ); |
409 | cfg.setGroup( "Volume" ); | 420 | cfg.setGroup( "Volume" ); |
410 | if ( percent < 0 ) | 421 | if ( percent < 0 ) |
411 | percent = cfg.readNumEntry( "TreblePercent", 50 ); | 422 | percent = cfg.readNumEntry( "TreblePercent", 50 ); |
412 | 423 | ||
413 | #ifndef QT_NO_SOUND | 424 | #ifndef QT_NO_SOUND |
414 | int fd = 0; | 425 | int fd = 0; |
415 | int treble = percent; | 426 | int treble = percent; |
416 | if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { | 427 | if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { |
417 | ioctl( fd, MIXER_WRITE( SOUND_MIXER_TREBLE ), &treble ); | 428 | ioctl( fd, MIXER_WRITE( SOUND_MIXER_TREBLE ), &treble ); |
418 | ::close( fd ); | 429 | ::close( fd ); |
419 | } | 430 | } |
420 | #endif | 431 | #endif |
421 | } | 432 | } |
422 | break; | 433 | break; |
423 | } | 434 | } |
424 | } | 435 | } |
425 | 436 | ||
426 | 437 | ||
427 | /** | 438 | /** |
428 | \class QPEApplication | 439 | \class QPEApplication |
429 | \brief The QPEApplication class implements various system services | 440 | \brief The QPEApplication class implements various system services |
430 | that are available to all Qtopia applications. | 441 | that are available to all Qtopia applications. |
431 | 442 | ||
432 | Simply by using QPEApplication instead of QApplication, a standard Qt | 443 | Simply by using QPEApplication instead of QApplication, a standard Qt |
433 | application becomes a Qtopia application. It automatically follows | 444 | application becomes a Qtopia application. It automatically follows |
434 | style changes, quits and raises, and in the | 445 | style changes, quits and raises, and in the |
435 | case of \link docwidget.html document-oriented\endlink applications, | 446 | case of \link docwidget.html document-oriented\endlink applications, |
436 | changes the currently displayed document in response to the environment. | 447 | changes the currently displayed document in response to the environment. |
437 | 448 | ||
438 | To create a \link docwidget.html document-oriented\endlink | 449 | To create a \link docwidget.html document-oriented\endlink |
439 | application use showMainDocumentWidget(); to create a | 450 | application use showMainDocumentWidget(); to create a |
440 | non-document-oriented application use showMainWidget(). The | 451 | non-document-oriented application use showMainWidget(). The |
441 | keepRunning() function indicates whether the application will | 452 | keepRunning() function indicates whether the application will |
442 | continue running after it's processed the last \link qcop.html | 453 | continue running after it's processed the last \link qcop.html |
443 | QCop\endlink message. This can be changed using setKeepRunning(). | 454 | QCop\endlink message. This can be changed using setKeepRunning(). |
444 | 455 | ||
445 | A variety of signals are emitted when certain events occur, for | 456 | A variety of signals are emitted when certain events occur, for |
446 | example, timeChanged(), clockChanged(), weekChanged(), | 457 | example, timeChanged(), clockChanged(), weekChanged(), |
447 | dateFormatChanged() and volumeChanged(). If the application receives | 458 | dateFormatChanged() and volumeChanged(). If the application receives |
448 | a \link qcop.html QCop\endlink message on the application's | 459 | a \link qcop.html QCop\endlink message on the application's |
449 | QPE/Application/\e{appname} channel, the appMessage() signal is | 460 | QPE/Application/\e{appname} channel, the appMessage() signal is |
450 | emitted. There are also flush() and reload() signals, which | 461 | emitted. There are also flush() and reload() signals, which |
451 | are emitted when synching begins and ends respectively - upon these | 462 | are emitted when synching begins and ends respectively - upon these |
452 | signals, the application should save and reload any data | 463 | signals, the application should save and reload any data |
453 | files that are involved in synching. Most of these signals will initially | 464 | files that are involved in synching. Most of these signals will initially |
454 | be received and unfiltered through the appMessage() signal. | 465 | be received and unfiltered through the appMessage() signal. |
455 | 466 | ||
456 | This class also provides a set of useful static functions. The | 467 | This class also provides a set of useful static functions. The |
457 | qpeDir() and documentDir() functions return the respective paths. | 468 | qpeDir() and documentDir() functions return the respective paths. |
458 | The grabKeyboard() and ungrabKeyboard() functions are used to | 469 | The grabKeyboard() and ungrabKeyboard() functions are used to |
459 | control whether the application takes control of the device's | 470 | control whether the application takes control of the device's |
460 | physical buttons (e.g. application launch keys). The stylus' mode of | 471 | physical buttons (e.g. application launch keys). The stylus' mode of |
461 | operation is set with setStylusOperation() and retrieved with | 472 | operation is set with setStylusOperation() and retrieved with |
462 | stylusOperation(). There are also setInputMethodHint() and | 473 | stylusOperation(). There are also setInputMethodHint() and |
463 | inputMethodHint() functions. | 474 | inputMethodHint() functions. |
464 | 475 | ||
465 | \ingroup qtopiaemb | 476 | \ingroup qtopiaemb |
466 | */ | 477 | */ |
467 | 478 | ||
468 | /*! | 479 | /*! |
469 | \fn void QPEApplication::clientMoused() | 480 | \fn void QPEApplication::clientMoused() |
470 | 481 | ||
471 | \internal | 482 | \internal |
472 | */ | 483 | */ |
473 | 484 | ||
474 | /*! | 485 | /*! |
475 | \fn void QPEApplication::timeChanged(); | 486 | \fn void QPEApplication::timeChanged(); |
476 | This signal is emitted when the time changes outside the normal | 487 | This signal is emitted when the time changes outside the normal |
477 | passage of time, i.e. if the time is set backwards or forwards. | 488 | passage of time, i.e. if the time is set backwards or forwards. |
478 | */ | 489 | */ |
479 | 490 | ||
480 | /*! | 491 | /*! |
481 | \fn void QPEApplication::clockChanged( bool ampm ); | 492 | \fn void QPEApplication::clockChanged( bool ampm ); |
482 | 493 | ||
483 | This signal is emitted when the user changes the clock's style. If | 494 | This signal is emitted when the user changes the clock's style. If |
484 | \a ampm is TRUE, the user wants a 12-hour AM/PM clock, otherwise, | 495 | \a ampm is TRUE, the user wants a 12-hour AM/PM clock, otherwise, |
485 | they want a 24-hour clock. | 496 | they want a 24-hour clock. |
486 | */ | 497 | */ |
487 | 498 | ||
488 | /*! | 499 | /*! |
489 | \fn void QPEApplication::volumeChanged( bool muted ) | 500 | \fn void QPEApplication::volumeChanged( bool muted ) |
490 | 501 | ||
491 | This signal is emitted whenever the mute state is changed. If \a | 502 | This signal is emitted whenever the mute state is changed. If \a |
492 | muted is TRUE, then sound output has been muted. | 503 | muted is TRUE, then sound output has been muted. |
493 | */ | 504 | */ |
494 | 505 | ||
495 | /*! | 506 | /*! |
496 | \fn void QPEApplication::weekChanged( bool startOnMonday ) | 507 | \fn void QPEApplication::weekChanged( bool startOnMonday ) |
497 | 508 | ||
498 | This signal is emitted if the week start day is changed. If \a | 509 | This signal is emitted if the week start day is changed. If \a |
499 | startOnMonday is TRUE then the first day of the week is Monday; if | 510 | startOnMonday is TRUE then the first day of the week is Monday; if |
500 | \a startOnMonday is FALSE then the first day of the week is | 511 | \a startOnMonday is FALSE then the first day of the week is |
501 | Sunday. | 512 | Sunday. |
502 | */ | 513 | */ |
503 | 514 | ||
504 | /*! | 515 | /*! |
505 | \fn void QPEApplication::dateFormatChanged(DateFormat) | 516 | \fn void QPEApplication::dateFormatChanged(DateFormat) |
506 | 517 | ||
507 | This signal is emitted whenever the date format is changed. | 518 | This signal is emitted whenever the date format is changed. |
508 | */ | 519 | */ |
509 | 520 | ||
510 | /*! | 521 | /*! |
511 | \fn void QPEApplication::flush() | 522 | \fn void QPEApplication::flush() |
512 | 523 | ||
513 | ### | 524 | ### |
514 | */ | 525 | */ |
515 | 526 | ||
516 | /*! | 527 | /*! |
517 | \fn void QPEApplication::reload() | 528 | \fn void QPEApplication::reload() |
518 | 529 | ||
519 | */ | 530 | */ |
520 | 531 | ||
521 | 532 | ||
522 | 533 | ||
523 | void QPEApplication::processQCopFile() | 534 | void QPEApplication::processQCopFile() |
524 | { | 535 | { |
525 | QString qcopfn("/tmp/qcop-msg-"); | 536 | QString qcopfn("/tmp/qcop-msg-"); |
526 | qcopfn += d->appName; // append command name | 537 | qcopfn += d->appName; // append command name |
527 | 538 | ||
528 | QFile f(qcopfn); | 539 | QFile f(qcopfn); |
529 | if ( f.open(IO_ReadWrite) ) { | 540 | if ( f.open(IO_ReadWrite) ) { |
530 | #ifndef Q_OS_WIN32 | 541 | #ifndef Q_OS_WIN32 |
531 | flock(f.handle(), LOCK_EX); | 542 | flock(f.handle(), LOCK_EX); |
532 | #endif | 543 | #endif |
533 | QDataStream ds(&f); | 544 | QDataStream ds(&f); |
534 | QCString channel, message; | 545 | QCString channel, message; |
535 | QByteArray data; | 546 | QByteArray data; |
536 | while(!ds.atEnd()) { | 547 | while(!ds.atEnd()) { |
537 | ds >> channel >> message >> data; | 548 | ds >> channel >> message >> data; |
538 | d->enqueueQCop(channel,message,data); | 549 | d->enqueueQCop(channel,message,data); |
539 | } | 550 | } |
540 | ::ftruncate(f.handle(), 0); | 551 | ::ftruncate(f.handle(), 0); |
541 | #ifndef Q_OS_WIN32 | 552 | #ifndef Q_OS_WIN32 |
542 | f.flush(); | 553 | f.flush(); |
543 | flock(f.handle(), LOCK_UN); | 554 | flock(f.handle(), LOCK_UN); |
544 | #endif | 555 | #endif |
545 | } | 556 | } |
546 | #endif | 557 | #endif |
547 | } | 558 | } |
548 | 559 | ||
549 | 560 | ||
550 | /*! | 561 | /*! |
551 | \fn void QPEApplication::appMessage( const QCString& msg, const QByteArray& data ) | 562 | \fn void QPEApplication::appMessage( const QCString& msg, const QByteArray& data ) |
552 | 563 | ||
553 | This signal is emitted when a message is received on this | 564 | This signal is emitted when a message is received on this |
554 | application's QPE/Application/<i>appname</i> \link qcop.html | 565 | application's QPE/Application/<i>appname</i> \link qcop.html |
555 | QCop\endlink channel. | 566 | QCop\endlink channel. |
556 | 567 | ||
557 | The slot to which you connect this signal uses \a msg and \a data | 568 | The slot to which you connect this signal uses \a msg and \a data |
558 | in the following way: | 569 | in the following way: |
559 | 570 | ||
560 | \code | 571 | \code |
561 | void MyWidget::receive( const QCString& msg, const QByteArray& data ) | 572 | void MyWidget::receive( const QCString& msg, const QByteArray& data ) |
562 | { | 573 | { |
563 | QDataStream stream( data, IO_ReadOnly ); | 574 | QDataStream stream( data, IO_ReadOnly ); |
564 | if ( msg == "someMessage(int,int,int)" ) { | 575 | if ( msg == "someMessage(int,int,int)" ) { |
565 | int a,b,c; | 576 | int a,b,c; |
566 | stream >> a >> b >> c; | 577 | stream >> a >> b >> c; |
567 | ... | 578 | ... |
568 | } else if ( msg == "otherMessage(QString)" ) { | 579 | } else if ( msg == "otherMessage(QString)" ) { |
569 | ... | 580 | ... |
570 | } | 581 | } |
571 | } | 582 | } |
572 | \endcode | 583 | \endcode |
573 | 584 | ||
574 | \sa qcop.html | 585 | \sa qcop.html |
575 | Note that messages received here may be processed by qpe application | 586 | Note that messages received here may be processed by qpe application |
576 | and emitted as signals, such as flush() and reload(). | 587 | and emitted as signals, such as flush() and reload(). |
577 | */ | 588 | */ |
578 | 589 | ||
579 | /*! | 590 | /*! |
580 | Constructs a QPEApplication just as you would construct | 591 | Constructs a QPEApplication just as you would construct |
581 | a QApplication, passing \a argc, \a argv, and \a t. | 592 | a QApplication, passing \a argc, \a argv, and \a t. |
582 | 593 | ||
583 | For applications, \a t should be the default, GuiClient. Only | 594 | For applications, \a t should be the default, GuiClient. Only |
584 | the Qtopia server passes GuiServer. | 595 | the Qtopia server passes GuiServer. |
585 | */ | 596 | */ |
586 | QPEApplication::QPEApplication( int & argc, char **argv, Type t ) | 597 | QPEApplication::QPEApplication( int & argc, char **argv, Type t ) |
587 | : QApplication( hack(argc), argv, t ), pidChannel( 0 ) | 598 | : QApplication( hack(argc), argv, t ), pidChannel( 0 ) |
588 | { | 599 | { |
589 | QPixmapCache::setCacheLimit(256); // sensible default for smaller devices. | 600 | QPixmapCache::setCacheLimit(256); // sensible default for smaller devices. |
590 | 601 | ||
591 | d = new QPEApplicationData; | 602 | d = new QPEApplicationData; |
592 | d->loadTextCodecs(); | 603 | d->loadTextCodecs(); |
593 | d->loadImageCodecs(); | 604 | d->loadImageCodecs(); |
594 | int dw = desktop() ->width(); | 605 | int dw = desktop() ->width(); |
595 | 606 | ||
596 | if ( dw < 200 ) { | 607 | if ( dw < 200 ) { |
597 | setFont( QFont( "vera", 8 ) ); | 608 | setFont( QFont( "vera", 8 ) ); |
598 | AppLnk::setSmallIconSize( 10 ); | 609 | AppLnk::setSmallIconSize( 10 ); |
599 | AppLnk::setBigIconSize( 28 ); | 610 | AppLnk::setBigIconSize( 28 ); |
600 | } | 611 | } |
601 | #if defined(OPIE_HIGH_RES_SMALL_PHY) | 612 | #if defined(OPIE_HIGH_RES_SMALL_PHY) |
602 | else if ( dw > 600 ) { | 613 | else if ( dw > 600 ) { |
603 | setFont( QFont( "vera", 16 ) ); | 614 | setFont( QFont( "vera", 16 ) ); |
604 | AppLnk::setSmallIconSize( 24 ); | 615 | AppLnk::setSmallIconSize( 24 ); |
605 | AppLnk::setBigIconSize( 48 ); | 616 | AppLnk::setBigIconSize( 48 ); |
606 | } | 617 | } |
607 | #endif | 618 | #endif |
608 | else if ( dw > 200 ) { | 619 | else if ( dw > 200 ) { |
609 | setFont( QFont( "vera", 10 ) ); | 620 | setFont( QFont( "vera", 10 ) ); |
610 | AppLnk::setSmallIconSize( 14 ); | 621 | AppLnk::setSmallIconSize( 14 ); |
611 | AppLnk::setBigIconSize( 32 ); | 622 | AppLnk::setBigIconSize( 32 ); |
612 | } | 623 | } |
613 | 624 | ||
614 | QMimeSourceFactory::setDefaultFactory( new ResourceMimeFactory ); | 625 | QMimeSourceFactory::setDefaultFactory( new ResourceMimeFactory ); |
615 | 626 | ||
616 | connect( this, SIGNAL( lastWindowClosed() ), this, SLOT( hideOrQuit() ) ); | 627 | connect( this, SIGNAL( lastWindowClosed() ), this, SLOT( hideOrQuit() ) ); |
617 | 628 | ||
618 | 629 | ||
619 | sysChannel = new QCopChannel( "QPE/System", this ); | 630 | sysChannel = new QCopChannel( "QPE/System", this ); |
620 | connect( sysChannel, SIGNAL( received(const QCString&,const QByteArray&) ), | 631 | connect( sysChannel, SIGNAL( received(const QCString&,const QByteArray&) ), |
621 | this, SLOT( systemMessage(const QCString&,const QByteArray&) ) ); | 632 | this, SLOT( systemMessage(const QCString&,const QByteArray&) ) ); |
622 | 633 | ||
623 | /* COde now in initapp */ | 634 | /* COde now in initapp */ |
624 | #if 0 | 635 | #if 0 |
625 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 636 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
626 | 637 | ||
627 | QString qcopfn( "/tmp/qcop-msg-" ); | 638 | QString qcopfn( "/tmp/qcop-msg-" ); |
628 | qcopfn += QString( argv[ 0 ] ); // append command name | 639 | qcopfn += QString( argv[ 0 ] ); // append command name |
629 | 640 | ||
630 | QFile f( qcopfn ); | 641 | QFile f( qcopfn ); |
631 | if ( f.open( IO_ReadOnly ) ) { | 642 | if ( f.open( IO_ReadOnly ) ) { |
632 | flock( f.handle(), LOCK_EX ); | 643 | flock( f.handle(), LOCK_EX ); |
633 | } | 644 | } |
634 | 645 | ||
635 | 646 | ||
636 | 647 | ||
637 | QCString channel = QCString( argv[ 0 ] ); | 648 | QCString channel = QCString( argv[ 0 ] ); |
638 | channel.replace( QRegExp( ".*/" ), "" ); | 649 | channel.replace( QRegExp( ".*/" ), "" ); |
639 | d->appName = channel; | 650 | d->appName = channel; |
640 | channel = "QPE/Application/" + channel; | 651 | channel = "QPE/Application/" + channel; |
641 | pidChannel = new QCopChannel( channel, this ); | 652 | pidChannel = new QCopChannel( channel, this ); |
642 | connect( pidChannel, SIGNAL( received(const QCString&,const QByteArray&) ), | 653 | connect( pidChannel, SIGNAL( received(const QCString&,const QByteArray&) ), |
643 | this, SLOT( pidMessage(const QCString&,const QByteArray&) ) ); | 654 | this, SLOT( pidMessage(const QCString&,const QByteArray&) ) ); |
644 | 655 | ||
645 | if ( f.isOpen() ) { | 656 | if ( f.isOpen() ) { |
646 | d->keep_running = FALSE; | 657 | d->keep_running = FALSE; |
647 | QDataStream ds( &f ); | 658 | QDataStream ds( &f ); |
648 | QCString channel, message; | 659 | QCString channel, message; |
649 | QByteArray data; | 660 | QByteArray data; |
650 | while ( !ds.atEnd() ) { | 661 | while ( !ds.atEnd() ) { |
651 | ds >> channel >> message >> data; | 662 | ds >> channel >> message >> data; |
652 | d->enqueueQCop( channel, message, data ); | 663 | d->enqueueQCop( channel, message, data ); |
653 | } | 664 | } |
654 | 665 | ||
655 | flock( f.handle(), LOCK_UN ); | 666 | flock( f.handle(), LOCK_UN ); |
656 | f.close(); | 667 | f.close(); |
657 | f.remove(); | 668 | f.remove(); |
658 | } | 669 | } |
659 | 670 | ||
660 | for ( int a = 0; a < argc; a++ ) { | 671 | for ( int a = 0; a < argc; a++ ) { |
661 | if ( qstrcmp( argv[ a ], "-preload" ) == 0 ) { | 672 | if ( qstrcmp( argv[ a ], "-preload" ) == 0 ) { |
662 | argv[ a ] = argv[ a + 1 ]; | 673 | argv[ a ] = argv[ a + 1 ]; |
663 | a++; | 674 | a++; |
664 | d->preloaded = TRUE; | 675 | d->preloaded = TRUE; |
665 | argc -= 1; | 676 | argc -= 1; |
666 | } | 677 | } |
667 | else if ( qstrcmp( argv[ a ], "-preload-show" ) == 0 ) { | 678 | else if ( qstrcmp( argv[ a ], "-preload-show" ) == 0 ) { |
668 | argv[ a ] = argv[ a + 1 ]; | 679 | argv[ a ] = argv[ a + 1 ]; |
669 | a++; | 680 | a++; |
670 | d->preloaded = TRUE; | 681 | d->preloaded = TRUE; |
671 | d->forceshow = TRUE; | 682 | d->forceshow = TRUE; |
672 | argc -= 1; | 683 | argc -= 1; |
673 | } | 684 | } |
674 | } | 685 | } |
675 | 686 | ||
676 | /* overide stored arguments */ | 687 | /* overide stored arguments */ |
677 | setArgs( argc, argv ); | 688 | setArgs( argc, argv ); |
678 | 689 | ||
679 | #endif | 690 | #endif |
680 | #else | 691 | #else |
681 | initApp( argc, argv ); | 692 | initApp( argc, argv ); |
682 | #endif | 693 | #endif |
683 | // qwsSetDecoration( new QPEDecoration() ); | 694 | // qwsSetDecoration( new QPEDecoration() ); |
684 | 695 | ||
685 | #ifndef QT_NO_TRANSLATION | 696 | #ifndef QT_NO_TRANSLATION |
686 | 697 | ||
687 | d->langs = Global::languageList(); | 698 | d->langs = Global::languageList(); |
688 | for ( QStringList::ConstIterator it = d->langs.begin(); it != d->langs.end(); ++it ) { | 699 | for ( QStringList::ConstIterator it = d->langs.begin(); it != d->langs.end(); ++it ) { |
689 | QString lang = *it; | 700 | QString lang = *it; |
690 | 701 | ||
691 | installTranslation( lang + "/libopie.qm"); | 702 | installTranslation( lang + "/libopie.qm"); |
692 | installTranslation( lang + "/libqpe.qm" ); | 703 | installTranslation( lang + "/libqpe.qm" ); |
693 | installTranslation( lang + "/" + d->appName + ".qm" ); | 704 | installTranslation( lang + "/" + d->appName + ".qm" ); |
694 | 705 | ||
695 | 706 | ||
696 | //###language/font hack; should look it up somewhere | 707 | //###language/font hack; should look it up somewhere |
697 | #ifdef QWS | 708 | #ifdef QWS |
698 | 709 | ||
699 | if ( lang == "ja" || lang == "zh_CN" || lang == "zh_TW" || lang == "ko" ) { | 710 | if ( lang == "ja" || lang == "zh_CN" || lang == "zh_TW" || lang == "ko" ) { |
700 | QFont fn = FontManager::unicodeFont( FontManager::Proportional ); | 711 | QFont fn = FontManager::unicodeFont( FontManager::Proportional ); |
701 | setFont( fn ); | 712 | setFont( fn ); |
702 | } | 713 | } |
703 | #endif | 714 | #endif |
704 | } | 715 | } |
705 | #endif | 716 | #endif |
706 | 717 | ||
707 | applyStyle(); | 718 | applyStyle(); |
708 | 719 | ||
709 | if ( type() == GuiServer ) { | 720 | if ( type() == GuiServer ) { |
710 | setVolume(); | 721 | setVolume(); |
711 | } | 722 | } |
712 | 723 | ||
713 | installEventFilter( this ); | 724 | installEventFilter( this ); |
714 | 725 | ||
715 | QPEMenuToolFocusManager::initialize(); | 726 | QPEMenuToolFocusManager::initialize(); |
716 | 727 | ||
717 | #ifdef QT_NO_QWS_CURSOR | 728 | #ifdef QT_NO_QWS_CURSOR |
718 | // if we have no cursor, probably don't want tooltips | 729 | // if we have no cursor, probably don't want tooltips |
719 | QToolTip::setEnabled( FALSE ); | 730 | QToolTip::setEnabled( FALSE ); |
720 | #endif | 731 | #endif |
721 | } | 732 | } |
722 | 733 | ||
723 | 734 | ||
724 | #ifdef QTOPIA_INTERNAL_INITAPP | 735 | #ifdef QTOPIA_INTERNAL_INITAPP |
725 | void QPEApplication::initApp( int argc, char **argv ) | 736 | void QPEApplication::initApp( int argc, char **argv ) |
726 | { | 737 | { |
727 | delete pidChannel; | 738 | delete pidChannel; |
728 | d->keep_running = TRUE; | 739 | d->keep_running = TRUE; |
729 | d->preloaded = FALSE; | 740 | d->preloaded = FALSE; |
730 | d->forceshow = FALSE; | 741 | d->forceshow = FALSE; |
731 | 742 | ||
732 | QCString channel = QCString(argv[0]); | 743 | QCString channel = QCString(argv[0]); |
733 | 744 | ||
734 | channel.replace(QRegExp(".*/"),""); | 745 | channel.replace(QRegExp(".*/"),""); |
735 | d->appName = channel; | 746 | d->appName = channel; |
736 | 747 | ||
737 | #if QT_VERSION > 235 | 748 | #if QT_VERSION > 235 |
738 | qt_fbdpy->setIdentity( channel ); // In Qt/E 2.3.6 | 749 | qt_fbdpy->setIdentity( channel ); // In Qt/E 2.3.6 |
739 | #endif | 750 | #endif |
740 | 751 | ||
741 | channel = "QPE/Application/" + channel; | 752 | channel = "QPE/Application/" + channel; |
742 | pidChannel = new QCopChannel( channel, this); | 753 | pidChannel = new QCopChannel( channel, this); |
743 | connect( pidChannel, SIGNAL(received(const QCString&,const QByteArray&)), | 754 | connect( pidChannel, SIGNAL(received(const QCString&,const QByteArray&)), |
744 | this, SLOT(pidMessage(const QCString&,const QByteArray&))); | 755 | this, SLOT(pidMessage(const QCString&,const QByteArray&))); |
745 | 756 | ||
746 | 757 | ||
747 | 758 | ||
748 | processQCopFile(); | 759 | processQCopFile(); |
749 | d->keep_running = d->qcopq.isEmpty(); | 760 | d->keep_running = d->qcopq.isEmpty(); |
750 | 761 | ||
751 | for (int a=0; a<argc; a++) { | 762 | for (int a=0; a<argc; a++) { |
752 | if ( qstrcmp(argv[a],"-preload")==0 ) { | 763 | if ( qstrcmp(argv[a],"-preload")==0 ) { |
753 | argv[a] = argv[a+1]; | 764 | argv[a] = argv[a+1]; |
754 | a++; | 765 | a++; |
755 | d->preloaded = TRUE; | 766 | d->preloaded = TRUE; |
756 | argc-=1; | 767 | argc-=1; |
757 | } else if ( qstrcmp(argv[a],"-preload-show")==0 ) { | 768 | } else if ( qstrcmp(argv[a],"-preload-show")==0 ) { |
758 | argv[a] = argv[a+1]; | 769 | argv[a] = argv[a+1]; |
759 | a++; | 770 | a++; |
760 | d->preloaded = TRUE; | 771 | d->preloaded = TRUE; |
761 | d->forceshow = TRUE; | 772 | d->forceshow = TRUE; |
762 | argc-=1; | 773 | argc-=1; |
763 | } | 774 | } |
764 | } | 775 | } |
765 | 776 | ||
766 | /* overide stored arguments */ | 777 | /* overide stored arguments */ |
767 | setArgs(argc, argv); | 778 | setArgs(argc, argv); |
768 | 779 | ||
769 | /* install translation here */ | 780 | /* install translation here */ |
770 | for ( QStringList::ConstIterator it = d->langs.begin(); it != d->langs.end(); ++it ) | 781 | for ( QStringList::ConstIterator it = d->langs.begin(); it != d->langs.end(); ++it ) |
771 | installTranslation( (*it) + "/" + d->appName + ".qm" ); | 782 | installTranslation( (*it) + "/" + d->appName + ".qm" ); |
772 | } | 783 | } |
773 | #endif | 784 | #endif |
774 | 785 | ||
775 | 786 | ||
776 | static QPtrDict<void>* inputMethodDict = 0; | 787 | static QPtrDict<void>* inputMethodDict = 0; |
777 | static void createInputMethodDict() | 788 | static void createInputMethodDict() |
778 | { | 789 | { |
779 | if ( !inputMethodDict ) | 790 | if ( !inputMethodDict ) |
780 | inputMethodDict = new QPtrDict<void>; | 791 | inputMethodDict = new QPtrDict<void>; |
781 | } | 792 | } |
782 | 793 | ||
783 | /*! | 794 | /*! |
784 | Returns the currently set hint to the system as to whether | 795 | Returns the currently set hint to the system as to whether |
785 | widget \a w has any use for text input methods. | 796 | widget \a w has any use for text input methods. |
786 | 797 | ||
787 | 798 | ||
788 | \sa setInputMethodHint() InputMethodHint | 799 | \sa setInputMethodHint() InputMethodHint |
789 | */ | 800 | */ |
790 | QPEApplication::InputMethodHint QPEApplication::inputMethodHint( QWidget * w ) | 801 | QPEApplication::InputMethodHint QPEApplication::inputMethodHint( QWidget * w ) |
791 | { | 802 | { |
792 | if ( inputMethodDict && w ) | 803 | if ( inputMethodDict && w ) |
793 | return ( InputMethodHint ) ( int ) inputMethodDict->find( w ); | 804 | return ( InputMethodHint ) ( int ) inputMethodDict->find( w ); |
794 | return Normal; | 805 | return Normal; |
795 | } | 806 | } |
796 | 807 | ||
797 | /*! | 808 | /*! |
798 | \enum QPEApplication::InputMethodHint | 809 | \enum QPEApplication::InputMethodHint |
799 | 810 | ||
800 | \value Normal the application sometimes needs text input (the default). | 811 | \value Normal the application sometimes needs text input (the default). |
801 | \value AlwaysOff the application never needs text input. | 812 | \value AlwaysOff the application never needs text input. |
802 | \value AlwaysOn the application always needs text input. | 813 | \value AlwaysOn the application always needs text input. |
803 | */ | 814 | */ |
804 | 815 | ||
805 | /*! | 816 | /*! |
806 | Hints to the system that widget \a w has use for text input methods | 817 | Hints to the system that widget \a w has use for text input methods |
807 | as specified by \a mode. | 818 | as specified by \a mode. |
808 | 819 | ||
809 | \sa inputMethodHint() InputMethodHint | 820 | \sa inputMethodHint() InputMethodHint |
810 | */ | 821 | */ |
811 | void QPEApplication::setInputMethodHint( QWidget * w, InputMethodHint mode ) | 822 | void QPEApplication::setInputMethodHint( QWidget * w, InputMethodHint mode ) |
812 | { | 823 | { |
813 | createInputMethodDict(); | 824 | createInputMethodDict(); |
814 | if ( mode == Normal ) { | 825 | if ( mode == Normal ) { |
815 | inputMethodDict->remove | 826 | inputMethodDict->remove |
816 | ( w ); | 827 | ( w ); |
817 | } | 828 | } |
818 | else { | 829 | else { |
819 | inputMethodDict->insert( w, ( void* ) mode ); | 830 | inputMethodDict->insert( w, ( void* ) mode ); |
820 | } | 831 | } |
821 | } | 832 | } |
822 | 833 | ||
823 | class HackDialog : public QDialog | 834 | class HackDialog : public QDialog |
824 | { | 835 | { |
825 | public: | 836 | public: |
826 | void acceptIt() | 837 | void acceptIt() |
827 | { | 838 | { |
828 | accept(); | 839 | accept(); |
829 | } | 840 | } |
830 | void rejectIt() | 841 | void rejectIt() |
831 | { | 842 | { |
832 | reject(); | 843 | reject(); |
833 | } | 844 | } |
834 | }; | 845 | }; |
835 | 846 | ||
836 | 847 | ||
837 | void QPEApplication::mapToDefaultAction( QWSKeyEvent * ke, int key ) | 848 | void QPEApplication::mapToDefaultAction( QWSKeyEvent * ke, int key ) |
838 | { | 849 | { |
839 | // specialised actions for certain widgets. May want to | 850 | // specialised actions for certain widgets. May want to |
840 | // add more stuff here. | 851 | // add more stuff here. |
841 | if ( activePopupWidget() && activePopupWidget() ->inherits( "QListBox" ) | 852 | if ( activePopupWidget() && activePopupWidget() ->inherits( "QListBox" ) |
842 | && activePopupWidget() ->parentWidget() | 853 | && activePopupWidget() ->parentWidget() |
843 | && activePopupWidget() ->parentWidget() ->inherits( "QComboBox" ) ) | 854 | && activePopupWidget() ->parentWidget() ->inherits( "QComboBox" ) ) |
844 | key = Qt::Key_Return; | 855 | key = Qt::Key_Return; |
845 | 856 | ||
846 | if ( activePopupWidget() && activePopupWidget() ->inherits( "QPopupMenu" ) ) | 857 | if ( activePopupWidget() && activePopupWidget() ->inherits( "QPopupMenu" ) ) |
847 | key = Qt::Key_Return; | 858 | key = Qt::Key_Return; |
848 | 859 | ||
849 | #ifdef QWS | 860 | #ifdef QWS |
850 | 861 | ||
851 | ke->simpleData.keycode = key; | 862 | ke->simpleData.keycode = key; |
852 | #endif | 863 | #endif |
853 | } | 864 | } |
854 | 865 | ||
855 | class HackWidget : public QWidget | 866 | class HackWidget : public QWidget |
856 | { | 867 | { |
857 | public: | 868 | public: |
858 | bool needsOk() | 869 | bool needsOk() |
859 | { | 870 | { |
860 | return ( getWState() & WState_Reserved1 ); | 871 | return ( getWState() & WState_Reserved1 ); |
861 | } | 872 | } |
862 | }; | 873 | }; |
863 | 874 | ||
864 | /*! | 875 | /*! |
865 | \internal | 876 | \internal |
866 | */ | 877 | */ |
867 | 878 | ||
868 | #ifdef QWS | 879 | #ifdef QWS |
869 | bool QPEApplication::qwsEventFilter( QWSEvent * e ) | 880 | bool QPEApplication::qwsEventFilter( QWSEvent * e ) |
870 | { | 881 | { |
871 | if ( !d->notbusysent && e->type == QWSEvent::Focus ) { | 882 | if ( !d->notbusysent && e->type == QWSEvent::Focus ) { |
872 | if ( qApp->type() != QApplication::GuiServer ) { | 883 | if ( qApp->type() != QApplication::GuiServer ) { |
873 | QCopEnvelope e( "QPE/System", "notBusy(QString)" ); | 884 | QCopEnvelope e( "QPE/System", "notBusy(QString)" ); |
874 | e << d->appName; | 885 | e << d->appName; |
875 | } | 886 | } |
876 | d->notbusysent = TRUE; | 887 | d->notbusysent = TRUE; |
877 | } | 888 | } |
878 | if ( type() == GuiServer ) { | 889 | if ( type() == GuiServer ) { |
879 | switch ( e->type ) { | 890 | switch ( e->type ) { |
880 | case QWSEvent::Mouse: | 891 | case QWSEvent::Mouse: |
881 | if ( e->asMouse() ->simpleData.state && !QWidget::find( e->window() ) ) | 892 | if ( e->asMouse() ->simpleData.state && !QWidget::find( e->window() ) ) |
882 | emit clientMoused(); | 893 | emit clientMoused(); |
883 | break; | 894 | break; |
884 | default: | 895 | default: |
885 | break; | 896 | break; |
886 | } | 897 | } |
887 | } | 898 | } |
888 | if ( e->type == QWSEvent::Key ) { | 899 | if ( e->type == QWSEvent::Key ) { |
889 | QWSKeyEvent *ke = ( QWSKeyEvent * ) e; | 900 | QWSKeyEvent *ke = ( QWSKeyEvent * ) e; |
890 | if ( ke->simpleData.keycode == Qt::Key_F33 ) { | 901 | if ( ke->simpleData.keycode == Qt::Key_F33 ) { |
891 | // Use special "OK" key to press "OK" on top level widgets | 902 | // Use special "OK" key to press "OK" on top level widgets |
892 | QWidget * active = activeWindow(); | 903 | QWidget * active = activeWindow(); |
893 | QWidget *popup = 0; | 904 | QWidget *popup = 0; |
894 | if ( active && active->isPopup() ) { | 905 | if ( active && active->isPopup() ) { |
895 | popup = active; | 906 | popup = active; |
896 | active = active->parentWidget(); | 907 | active = active->parentWidget(); |
897 | } | 908 | } |
898 | if ( active && ( int ) active->winId() == ke->simpleData.window && | 909 | if ( active && ( int ) active->winId() == ke->simpleData.window && |
899 | !active->testWFlags( WStyle_Customize | WType_Popup | WType_Desktop ) ) { | 910 | !active->testWFlags( WStyle_Customize | WType_Popup | WType_Desktop ) ) { |
900 | if ( ke->simpleData.is_press ) { | 911 | if ( ke->simpleData.is_press ) { |
901 | if ( popup ) | 912 | if ( popup ) |
902 | popup->close(); | 913 | popup->close(); |
903 | if ( active->inherits( "QDialog" ) ) { | 914 | if ( active->inherits( "QDialog" ) ) { |
904 | HackDialog * d = ( HackDialog * ) active; | 915 | HackDialog * d = ( HackDialog * ) active; |
905 | d->acceptIt(); | 916 | d->acceptIt(); |
906 | return TRUE; | 917 | return TRUE; |
907 | } | 918 | } |
908 | else if ( ( ( HackWidget * ) active ) ->needsOk() ) { | 919 | else if ( ( ( HackWidget * ) active ) ->needsOk() ) { |
909 | QSignal s; | 920 | QSignal s; |
910 | s.connect( active, SLOT( accept() ) ); | 921 | s.connect( active, SLOT( accept() ) ); |
911 | s.activate(); | 922 | s.activate(); |
912 | } | 923 | } |
913 | else { | 924 | else { |
914 | // do the same as with the select key: Map to the default action of the widget: | 925 | // do the same as with the select key: Map to the default action of the widget: |
915 | mapToDefaultAction( ke, Qt::Key_Return ); | 926 | mapToDefaultAction( ke, Qt::Key_Return ); |
916 | } | 927 | } |
917 | } | 928 | } |
918 | } | 929 | } |
919 | } | 930 | } |
920 | else if ( ke->simpleData.keycode == Qt::Key_F30 ) { | 931 | else if ( ke->simpleData.keycode == Qt::Key_F30 ) { |
921 | // Use special "select" key to do whatever default action a widget has | 932 | // Use special "select" key to do whatever default action a widget has |
922 | mapToDefaultAction( ke, Qt::Key_Space ); | 933 | mapToDefaultAction( ke, Qt::Key_Space ); |
923 | } | 934 | } |
924 | else if ( ke->simpleData.keycode == Qt::Key_Escape && | 935 | else if ( ke->simpleData.keycode == Qt::Key_Escape && |
925 | ke->simpleData.is_press ) { | 936 | ke->simpleData.is_press ) { |
926 | // Escape key closes app if focus on toplevel | 937 | // Escape key closes app if focus on toplevel |
927 | QWidget * active = activeWindow(); | 938 | QWidget * active = activeWindow(); |
928 | if ( active && active->testWFlags( WType_TopLevel ) && | 939 | if ( active && active->testWFlags( WType_TopLevel ) && |
929 | ( int ) active->winId() == ke->simpleData.window && | 940 | ( int ) active->winId() == ke->simpleData.window && |
930 | !active->testWFlags( WStyle_Dialog | WStyle_Customize | WType_Popup | WType_Desktop ) ) { | 941 | !active->testWFlags( WStyle_Dialog | WStyle_Customize | WType_Popup | WType_Desktop ) ) { |
931 | if ( active->inherits( "QDialog" ) ) { | 942 | if ( active->inherits( "QDialog" ) ) { |
932 | HackDialog * d = ( HackDialog * ) active; | 943 | HackDialog * d = ( HackDialog * ) active; |
933 | d->rejectIt(); | 944 | d->rejectIt(); |
934 | return TRUE; | 945 | return TRUE; |
935 | } | 946 | } |
936 | else if ( strcmp( argv() [ 0 ], "embeddedkonsole" ) != 0 ) { | 947 | else if ( strcmp( argv() [ 0 ], "embeddedkonsole" ) != 0 ) { |
937 | active->close(); | 948 | active->close(); |
938 | } | 949 | } |
939 | } | 950 | } |
940 | } | 951 | } |
941 | else if ( ke->simpleData.keycode >= Qt::Key_F1 && ke->simpleData.keycode <= Qt::Key_F29 ) { | 952 | else if ( ke->simpleData.keycode >= Qt::Key_F1 && ke->simpleData.keycode <= Qt::Key_F29 ) { |
942 | // this should be if ( ODevice::inst ( )-> buttonForKeycode ( ... )) | 953 | // this should be if ( ODevice::inst ( )-> buttonForKeycode ( ... )) |
943 | // but we cannot access libopie function within libqpe :( | 954 | // but we cannot access libopie function within libqpe :( |
944 | 955 | ||
945 | QWidget * active = activeWindow ( ); | 956 | QWidget * active = activeWindow ( ); |
946 | if ( active && ((int) active-> winId ( ) == ke-> simpleData.window )) { | 957 | if ( active && ((int) active-> winId ( ) == ke-> simpleData.window )) { |
947 | if ( d-> kbgrabbed ) { // we grabbed the keyboard | 958 | if ( d-> kbgrabbed ) { // we grabbed the keyboard |