-rw-r--r-- | library/qpeapplication.cpp | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/library/qpeapplication.cpp b/library/qpeapplication.cpp index dcc1001..34f5e6a 100644 --- a/library/qpeapplication.cpp +++ b/library/qpeapplication.cpp | |||
@@ -1,858 +1,859 @@ | |||
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 >= 0x030000 | 63 | #if QT_VERSION >= 0x030000 |
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 | #include "fontdatabase.h" | 83 | #include "fontdatabase.h" |
84 | #endif | 84 | #endif |
85 | 85 | ||
86 | #include "alarmserver.h" | 86 | #include "alarmserver.h" |
87 | #include "applnk.h" | 87 | #include "applnk.h" |
88 | #include "qpemenubar.h" | 88 | #include "qpemenubar.h" |
89 | #include "textcodecinterface.h" | 89 | #include "textcodecinterface.h" |
90 | #include "imagecodecinterface.h" | 90 | #include "imagecodecinterface.h" |
91 | #include <qtopia/qpeglobal.h> | 91 | #include <qtopia/qpeglobal.h> |
92 | 92 | ||
93 | #include <unistd.h> | 93 | #include <unistd.h> |
94 | #include <sys/file.h> | 94 | #include <sys/file.h> |
95 | #include <sys/ioctl.h> | 95 | #include <sys/ioctl.h> |
96 | #ifndef QT_NO_SOUND | 96 | #ifndef QT_NO_SOUND |
97 | #include <sys/soundcard.h> | 97 | #include <sys/soundcard.h> |
98 | #endif | 98 | #endif |
99 | 99 | ||
100 | #include <backend/rohfeedback.h> | 100 | #include <backend/rohfeedback.h> |
101 | 101 | ||
102 | 102 | ||
103 | static bool useBigPixmaps = 0; | 103 | static bool useBigPixmaps = 0; |
104 | static bool saveWindowsPos = 0; | ||
104 | 105 | ||
105 | class HackWidget : public QWidget | 106 | class HackWidget : public QWidget |
106 | { | 107 | { |
107 | public: | 108 | public: |
108 | bool needsOk() | 109 | bool needsOk() |
109 | { return (getWState() & WState_Reserved1 ); } | 110 | { return (getWState() & WState_Reserved1 ); } |
110 | 111 | ||
111 | QRect normalGeometry() | 112 | QRect normalGeometry() |
112 | { return topData()->normalGeometry; }; | 113 | { return topData()->normalGeometry; }; |
113 | }; | 114 | }; |
114 | 115 | ||
115 | class QPEApplicationData | 116 | class QPEApplicationData |
116 | { | 117 | { |
117 | public: | 118 | public: |
118 | QPEApplicationData ( ) : | 119 | QPEApplicationData ( ) : |
119 | presstimer( 0 ), presswidget( 0 ), rightpressed( false ), kbgrabbed( false ), | 120 | presstimer( 0 ), presswidget( 0 ), rightpressed( false ), kbgrabbed( false ), |
120 | notbusysent( false ), preloaded( false ), forceshow( false ), nomaximize( false ), | 121 | notbusysent( false ), preloaded( false ), forceshow( false ), nomaximize( false ), |
121 | keep_running( true ), qcopQok( false ), | 122 | keep_running( true ), qcopQok( false ), |
122 | fontFamily( "Vera" ), fontSize( 10 ), smallIconSize( 14 ), | 123 | fontFamily( "Vera" ), fontSize( 10 ), smallIconSize( 14 ), |
123 | bigIconSize( 32 ), qpe_main_widget( 0 ) | 124 | bigIconSize( 32 ), qpe_main_widget( 0 ) |
124 | { | 125 | { |
125 | Config cfg( "qpe" ); | 126 | Config cfg( "qpe" ); |
126 | cfg.setGroup( "Appearance" ); | 127 | cfg.setGroup( "Appearance" ); |
127 | useBigPixmaps = cfg.readBoolEntry( "useBigPixmaps", false ); | 128 | useBigPixmaps = cfg.readBoolEntry( "useBigPixmaps", false ); |
128 | fontFamily = cfg.readEntry( "FontFamily", "Vera" ); | 129 | fontFamily = cfg.readEntry( "FontFamily", "Vera" ); |
129 | fontSize = cfg.readNumEntry( "FontSize", 10 ); | 130 | fontSize = cfg.readNumEntry( "FontSize", 10 ); |
130 | smallIconSize = cfg.readNumEntry( "SmallIconSize", 14 ); | 131 | smallIconSize = cfg.readNumEntry( "SmallIconSize", 14 ); |
131 | bigIconSize = cfg.readNumEntry( "BigIconSize", 32 ); | 132 | bigIconSize = cfg.readNumEntry( "BigIconSize", 32 ); |
133 | saveWindowsPos = cfg.readBoolEntry( "AllowWindowed", false ); | ||
132 | #ifdef OPIE_WITHROHFEEDBACK | 134 | #ifdef OPIE_WITHROHFEEDBACK |
133 | RoH = 0; | 135 | RoH = 0; |
134 | #endif | 136 | #endif |
135 | } | 137 | } |
136 | 138 | ||
137 | int presstimer; | 139 | int presstimer; |
138 | QWidget* presswidget; | 140 | QWidget* presswidget; |
139 | QPoint presspos; | 141 | QPoint presspos; |
140 | #ifdef OPIE_WITHROHFEEDBACK | 142 | #ifdef OPIE_WITHROHFEEDBACK |
141 | Opie::Internal::RoHFeedback *RoH; | 143 | Opie::Internal::RoHFeedback *RoH; |
142 | #endif | 144 | #endif |
143 | 145 | ||
144 | bool rightpressed : 1; | 146 | bool rightpressed : 1; |
145 | bool kbgrabbed : 1; | 147 | bool kbgrabbed : 1; |
146 | bool notbusysent : 1; | 148 | bool notbusysent : 1; |
147 | bool preloaded : 1; | 149 | bool preloaded : 1; |
148 | bool forceshow : 1; | 150 | bool forceshow : 1; |
149 | bool nomaximize : 1; | 151 | bool nomaximize : 1; |
150 | bool keep_running : 1; | 152 | bool keep_running : 1; |
151 | bool qcopQok : 1; | 153 | bool qcopQok : 1; |
152 | 154 | ||
153 | QCString fontFamily; | 155 | QCString fontFamily; |
154 | int fontSize; | 156 | int fontSize; |
155 | int smallIconSize; | 157 | int smallIconSize; |
156 | int bigIconSize; | 158 | int bigIconSize; |
157 | 159 | ||
158 | QString appName; | 160 | QString appName; |
159 | struct QCopRec | 161 | struct QCopRec |
160 | { | 162 | { |
161 | QCopRec( const QCString &ch, const QCString &msg, | 163 | QCopRec( const QCString &ch, const QCString &msg, |
162 | const QByteArray &d ) : | 164 | const QByteArray &d ) : |
163 | channel( ch ), message( msg ), data( d ) | 165 | channel( ch ), message( msg ), data( d ) |
164 | { } | 166 | { } |
165 | 167 | ||
166 | QCString channel; | 168 | QCString channel; |
167 | QCString message; | 169 | QCString message; |
168 | QByteArray data; | 170 | QByteArray data; |
169 | }; | 171 | }; |
170 | QGuardedPtr<QWidget> qpe_main_widget; | 172 | QGuardedPtr<QWidget> qpe_main_widget; |
171 | QGuardedPtr<QWidget> lastraised; | 173 | QGuardedPtr<QWidget> lastraised; |
172 | QQueue<QCopRec> qcopq; | 174 | QQueue<QCopRec> qcopq; |
173 | QString styleName; | 175 | QString styleName; |
174 | QString decorationName; | 176 | QString decorationName; |
175 | 177 | ||
176 | void enqueueQCop( const QCString &ch, const QCString &msg, | 178 | void enqueueQCop( const QCString &ch, const QCString &msg, |
177 | const QByteArray &data ) | 179 | const QByteArray &data ) |
178 | { | 180 | { |
179 | qcopq.enqueue( new QCopRec( ch, msg, data ) ); | 181 | qcopq.enqueue( new QCopRec( ch, msg, data ) ); |
180 | } | 182 | } |
181 | void sendQCopQ() | 183 | void sendQCopQ() |
182 | { | 184 | { |
183 | if (!qcopQok ) | 185 | if (!qcopQok ) |
184 | return; | 186 | return; |
185 | 187 | ||
186 | QCopRec * r; | 188 | QCopRec * r; |
187 | 189 | ||
188 | while((r=qcopq.dequeue())) { | 190 | while((r=qcopq.dequeue())) { |
189 | // remove from queue before sending... | 191 | // remove from queue before sending... |
190 | // event loop can come around again before getting | 192 | // event loop can come around again before getting |
191 | // back from sendLocally | 193 | // back from sendLocally |
192 | #ifndef QT_NO_COP | 194 | #ifndef QT_NO_COP |
193 | QCopChannel::sendLocally( r->channel, r->message, r->data ); | 195 | QCopChannel::sendLocally( r->channel, r->message, r->data ); |
194 | #endif | 196 | #endif |
195 | 197 | ||
196 | delete r; | 198 | delete r; |
197 | } | 199 | } |
198 | } | 200 | } |
199 | 201 | ||
200 | static void show_mx(QWidget* mw, bool nomaximize, QString &strName) { | 202 | static void show_mx(QWidget* mw, bool nomaximize, QString &strName) { |
201 | if ( mw->inherits("QMainWindow") || mw->isA("QMainWindow") ) | 203 | if ( mw->inherits("QMainWindow") || mw->isA("QMainWindow") ) |
202 | { | 204 | { |
203 | ( ( QMainWindow* ) mw )->setUsesBigPixmaps( useBigPixmaps ); | 205 | ( ( QMainWindow* ) mw )->setUsesBigPixmaps( useBigPixmaps ); |
204 | } | 206 | } |
205 | QPoint p; | 207 | QPoint p; |
206 | QSize s; | 208 | QSize s; |
207 | bool max; | 209 | bool max; |
208 | 210 | ||
209 | if ( mw->isVisible() ) { | 211 | if ( mw->isVisible() ) { |
210 | if ( read_widget_rect(strName, max, p, s) && validate_widget_size(mw, p, s) ) { | 212 | if ( read_widget_rect(strName, max, p, s) && validate_widget_size(mw, p, s) ) { |
211 | mw->resize(s); | 213 | mw->resize(s); |
212 | mw->move(p); | 214 | mw->move(p); |
213 | } | 215 | } |
214 | mw->raise(); | 216 | mw->raise(); |
215 | } else { | 217 | } else { |
216 | 218 | ||
217 | if ( mw->layout() && mw->inherits("QDialog") ) { | 219 | if ( mw->layout() && mw->inherits("QDialog") ) { |
218 | if ( read_widget_rect(strName, max, p, s) && validate_widget_size(mw, p, s) ) { | 220 | if ( read_widget_rect(strName, max, p, s) && validate_widget_size(mw, p, s) ) { |
219 | mw->resize(s); | 221 | mw->resize(s); |
220 | mw->move(p); | 222 | mw->move(p); |
221 | 223 | ||
222 | if ( max && !nomaximize ) { | 224 | if ( max && !nomaximize ) { |
223 | mw->showMaximized(); | 225 | mw->showMaximized(); |
224 | } else { | 226 | } else { |
225 | mw->show(); | 227 | mw->show(); |
226 | } | 228 | } |
227 | } else { | 229 | } else { |
228 | QPEApplication::showDialog((QDialog*)mw,nomaximize); | 230 | QPEApplication::showDialog((QDialog*)mw,nomaximize); |
229 | } | 231 | } |
230 | } else { | 232 | } else { |
231 | if ( read_widget_rect(strName, max, p, s) && validate_widget_size(mw, p, s) ) { | 233 | if ( read_widget_rect(strName, max, p, s) && validate_widget_size(mw, p, s) ) { |
232 | mw->resize(s); | 234 | mw->resize(s); |
233 | mw->move(p); | 235 | mw->move(p); |
234 | } else { //no stored rectangle, make an estimation | 236 | } else { //no stored rectangle, make an estimation |
235 | int x = (qApp->desktop()->width()-mw->frameGeometry().width())/2; | 237 | int x = (qApp->desktop()->width()-mw->frameGeometry().width())/2; |
236 | int y = (qApp->desktop()->height()-mw->frameGeometry().height())/2; | 238 | int y = (qApp->desktop()->height()-mw->frameGeometry().height())/2; |
237 | mw->move( QMAX(x,0), QMAX(y,0) ); | 239 | mw->move( QMAX(x,0), QMAX(y,0) ); |
238 | #ifdef Q_WS_QWS | 240 | #ifdef Q_WS_QWS |
239 | if ( !nomaximize ) | 241 | if ( !nomaximize ) |
240 | mw->showMaximized(); | 242 | mw->showMaximized(); |
241 | #endif | 243 | #endif |
242 | } | 244 | } |
243 | if ( max && !nomaximize ) | 245 | if ( max && !nomaximize ) |
244 | mw->showMaximized(); | 246 | mw->showMaximized(); |
245 | else | 247 | else |
246 | mw->show(); | 248 | mw->show(); |
247 | } | 249 | } |
248 | } | 250 | } |
249 | } | 251 | } |
250 | 252 | ||
251 | static bool read_widget_rect(const QString &app, bool &maximized, QPoint &p, QSize &s) | 253 | static bool read_widget_rect(const QString &app, bool &maximized, QPoint &p, QSize &s) |
252 | { | 254 | { |
253 | #ifndef OPIE_NO_WINDOWED | 255 | if (!saveWindowsPos) |
256 | return FALSE; | ||
254 | maximized = TRUE; | 257 | maximized = TRUE; |
255 | // 350 is the trigger in qwsdefaultdecoration for providing a resize button | 258 | // 350 is the trigger in qwsdefaultdecoration for providing a resize button |
256 | if ( qApp->desktop()->width() <= 350 ) | 259 | if ( qApp->desktop()->width() <= 350 ) |
257 | return FALSE; | 260 | return FALSE; |
258 | 261 | ||
259 | Config cfg( "qpe" ); | 262 | Config cfg( "qpe" ); |
260 | cfg.setGroup("ApplicationPositions"); | 263 | cfg.setGroup("ApplicationPositions"); |
261 | QString str = cfg.readEntry( app, QString::null ); | 264 | QString str = cfg.readEntry( app, QString::null ); |
262 | QStringList l = QStringList::split(",", str); | 265 | QStringList l = QStringList::split(",", str); |
263 | 266 | ||
264 | if ( l.count() == 5) { | 267 | if ( l.count() == 5) { |
265 | p.setX( l[0].toInt() ); | 268 | p.setX( l[0].toInt() ); |
266 | p.setY( l[1].toInt() ); | 269 | p.setY( l[1].toInt() ); |
267 | 270 | ||
268 | s.setWidth( l[2].toInt() ); | 271 | s.setWidth( l[2].toInt() ); |
269 | s.setHeight( l[3].toInt() ); | 272 | s.setHeight( l[3].toInt() ); |
270 | 273 | ||
271 | maximized = l[4].toInt(); | 274 | maximized = l[4].toInt(); |
272 | 275 | ||
273 | return TRUE; | 276 | return TRUE; |
274 | } | 277 | } |
275 | #endif | ||
276 | return FALSE; | ||
277 | } | 278 | } |
278 | 279 | ||
279 | 280 | ||
280 | static bool validate_widget_size(const QWidget *w, QPoint &p, QSize &s) | 281 | static bool validate_widget_size(const QWidget *w, QPoint &p, QSize &s) |
281 | { | 282 | { |
282 | #ifndef Q_WS_QWS | 283 | #ifndef Q_WS_QWS |
283 | QRect qt_maxWindowRect = qApp->desktop()->geometry(); | 284 | QRect qt_maxWindowRect = qApp->desktop()->geometry(); |
284 | #endif | 285 | #endif |
285 | int maxX = qt_maxWindowRect.width(); | 286 | int maxX = qt_maxWindowRect.width(); |
286 | int maxY = qt_maxWindowRect.height(); | 287 | int maxY = qt_maxWindowRect.height(); |
287 | int wWidth = s.width() + ( w->frameGeometry().width() - w->geometry().width() ); | 288 | int wWidth = s.width() + ( w->frameGeometry().width() - w->geometry().width() ); |
288 | int wHeight = s.height() + ( w->frameGeometry().height() - w->geometry().height() ); | 289 | int wHeight = s.height() + ( w->frameGeometry().height() - w->geometry().height() ); |
289 | 290 | ||
290 | // total window size is not allowed to be larger than desktop window size | 291 | // total window size is not allowed to be larger than desktop window size |
291 | if ( ( wWidth >= maxX ) && ( wHeight >= maxY ) ) | 292 | if ( ( wWidth >= maxX ) && ( wHeight >= maxY ) ) |
292 | return FALSE; | 293 | return FALSE; |
293 | 294 | ||
294 | if ( wWidth > maxX ) { | 295 | if ( wWidth > maxX ) { |
295 | s.setWidth( maxX - (w->frameGeometry().width() - w->geometry().width() ) ); | 296 | s.setWidth( maxX - (w->frameGeometry().width() - w->geometry().width() ) ); |
296 | wWidth = maxX; | 297 | wWidth = maxX; |
297 | } | 298 | } |
298 | 299 | ||
299 | if ( wHeight > maxY ) { | 300 | if ( wHeight > maxY ) { |
300 | s.setHeight( maxY - (w->frameGeometry().height() - w->geometry().height() ) ); | 301 | s.setHeight( maxY - (w->frameGeometry().height() - w->geometry().height() ) ); |
301 | wHeight = maxY; | 302 | wHeight = maxY; |
302 | } | 303 | } |
303 | 304 | ||
304 | // any smaller than this and the maximize/close/help buttons will be overlapping | 305 | // any smaller than this and the maximize/close/help buttons will be overlapping |
305 | if ( wWidth < 80 || wHeight < 60 ) | 306 | if ( wWidth < 80 || wHeight < 60 ) |
306 | return FALSE; | 307 | return FALSE; |
307 | 308 | ||
308 | if ( p.x() < 0 ) | 309 | if ( p.x() < 0 ) |
309 | p.setX(0); | 310 | p.setX(0); |
310 | if ( p.y() < 0 ) | 311 | if ( p.y() < 0 ) |
311 | p.setY(0); | 312 | p.setY(0); |
312 | 313 | ||
313 | if ( p.x() + wWidth > maxX ) | 314 | if ( p.x() + wWidth > maxX ) |
314 | p.setX( maxX - wWidth ); | 315 | p.setX( maxX - wWidth ); |
315 | if ( p.y() + wHeight > maxY ) | 316 | if ( p.y() + wHeight > maxY ) |
316 | p.setY( maxY - wHeight ); | 317 | p.setY( maxY - wHeight ); |
317 | 318 | ||
318 | return TRUE; | 319 | return TRUE; |
319 | } | 320 | } |
320 | 321 | ||
321 | static void store_widget_rect(QWidget *w, QString &app) | 322 | static void store_widget_rect(QWidget *w, QString &app) |
322 | { | 323 | { |
323 | if( !w ) | 324 | if( !w ) |
324 | return; | 325 | return; |
325 | #ifndef OPIE_NO_WINDOWED | 326 | if (!saveWindowsPos) |
327 | return; | ||
326 | // 350 is the trigger in qwsdefaultdecoration for providing a resize button | 328 | // 350 is the trigger in qwsdefaultdecoration for providing a resize button |
327 | if ( qApp->desktop()->width() <= 350 ) | 329 | if ( qApp->desktop()->width() <= 350 ) |
328 | return; | 330 | return; |
329 | // we use these to map the offset of geometry and pos. ( we can only use normalGeometry to | 331 | // we use these to map the offset of geometry and pos. ( we can only use normalGeometry to |
330 | // get the non-maximized version, so we have to do it the hard way ) | 332 | // get the non-maximized version, so we have to do it the hard way ) |
331 | int offsetX = w->x() - w->geometry().left(); | 333 | int offsetX = w->x() - w->geometry().left(); |
332 | int offsetY = w->y() - w->geometry().top(); | 334 | int offsetY = w->y() - w->geometry().top(); |
333 | 335 | ||
334 | QRect r; | 336 | QRect r; |
335 | if ( w->isMaximized() ) | 337 | if ( w->isMaximized() ) |
336 | r = ( (HackWidget *) w)->normalGeometry(); | 338 | r = ( (HackWidget *) w)->normalGeometry(); |
337 | else | 339 | else |
338 | r = w->geometry(); | 340 | r = w->geometry(); |
339 | 341 | ||
340 | // Stores the window placement as pos(), size() (due to the offset mapping) | 342 | // Stores the window placement as pos(), size() (due to the offset mapping) |
341 | Config cfg( "qpe" ); | 343 | Config cfg( "qpe" ); |
342 | cfg.setGroup("ApplicationPositions"); | 344 | cfg.setGroup("ApplicationPositions"); |
343 | QString s; | 345 | QString s; |
344 | s.sprintf("%d,%d,%d,%d,%d", r.left() + offsetX, r.top() + offsetY, r.width(), r.height(), w->isMaximized() ); | 346 | s.sprintf("%d,%d,%d,%d,%d", r.left() + offsetX, r.top() + offsetY, r.width(), r.height(), w->isMaximized() ); |
345 | cfg.writeEntry( app, s ); | 347 | cfg.writeEntry( app, s ); |
346 | #endif | ||
347 | } | 348 | } |
348 | 349 | ||
349 | static bool setWidgetCaptionFromAppName( QWidget* /*mw*/, const QString& /*appName*/, const QString& /*appsPath*/ ) | 350 | static bool setWidgetCaptionFromAppName( QWidget* /*mw*/, const QString& /*appName*/, const QString& /*appsPath*/ ) |
350 | { | 351 | { |
351 | /* | 352 | /* |
352 | // This works but disable it for now until it is safe to apply | 353 | // This works but disable it for now until it is safe to apply |
353 | // What is does is scan the .desktop files of all the apps for | 354 | // What is does is scan the .desktop files of all the apps for |
354 | // the applnk that has the corresponding argv[0] as this program | 355 | // the applnk that has the corresponding argv[0] as this program |
355 | // then it uses the name stored in the .desktop file as the caption | 356 | // then it uses the name stored in the .desktop file as the caption |
356 | // for the main widget. This saves duplicating translations for | 357 | // for the main widget. This saves duplicating translations for |
357 | // the app name in the program and in the .desktop files. | 358 | // the app name in the program and in the .desktop files. |
358 | 359 | ||
359 | AppLnkSet apps( appsPath ); | 360 | AppLnkSet apps( appsPath ); |
360 | 361 | ||
361 | QList<AppLnk> appsList = apps.children(); | 362 | QList<AppLnk> appsList = apps.children(); |
362 | for ( QListIterator<AppLnk> it(appsList); it.current(); ++it ) { | 363 | for ( QListIterator<AppLnk> it(appsList); it.current(); ++it ) { |
363 | if ( (*it)->exec() == appName ) { | 364 | if ( (*it)->exec() == appName ) { |
364 | mw->setCaption( (*it)->name() ); | 365 | mw->setCaption( (*it)->name() ); |
365 | return TRUE; | 366 | return TRUE; |
366 | } | 367 | } |
367 | } | 368 | } |
368 | */ | 369 | */ |
369 | return FALSE; | 370 | return FALSE; |
370 | } | 371 | } |
371 | 372 | ||
372 | 373 | ||
373 | void show(QWidget* mw, bool nomax) | 374 | void show(QWidget* mw, bool nomax) |
374 | { | 375 | { |
375 | setWidgetCaptionFromAppName( mw, appName, QPEApplication::qpeDir() + "apps" ); | 376 | setWidgetCaptionFromAppName( mw, appName, QPEApplication::qpeDir() + "apps" ); |
376 | nomaximize = nomax; | 377 | nomaximize = nomax; |
377 | qpe_main_widget = mw; | 378 | qpe_main_widget = mw; |
378 | qcopQok = TRUE; | 379 | qcopQok = TRUE; |
379 | #ifndef QT_NO_COP | 380 | #ifndef QT_NO_COP |
380 | 381 | ||
381 | sendQCopQ(); | 382 | sendQCopQ(); |
382 | #endif | 383 | #endif |
383 | 384 | ||
384 | if ( preloaded ) { | 385 | if ( preloaded ) { |
385 | if (forceshow) | 386 | if (forceshow) |
386 | show_mx(mw, nomax, appName); | 387 | show_mx(mw, nomax, appName); |
387 | } | 388 | } |
388 | else if ( keep_running ) { | 389 | else if ( keep_running ) { |
389 | show_mx(mw, nomax, appName); | 390 | show_mx(mw, nomax, appName); |
390 | } | 391 | } |
391 | } | 392 | } |
392 | 393 | ||
393 | void loadTextCodecs() | 394 | void loadTextCodecs() |
394 | { | 395 | { |
395 | QString path = QPEApplication::qpeDir() + "plugins/textcodecs"; | 396 | QString path = QPEApplication::qpeDir() + "plugins/textcodecs"; |
396 | #ifdef Q_OS_MACX | 397 | #ifdef Q_OS_MACX |
397 | QDir dir( path, "lib*.dylib" ); | 398 | QDir dir( path, "lib*.dylib" ); |
398 | #else | 399 | #else |
399 | QDir dir( path, "lib*.so" ); | 400 | QDir dir( path, "lib*.so" ); |
400 | #endif | 401 | #endif |
401 | QStringList list; | 402 | QStringList list; |
402 | if ( dir. exists ( )) | 403 | if ( dir. exists ( )) |
403 | list = dir.entryList(); | 404 | list = dir.entryList(); |
404 | QStringList::Iterator it; | 405 | QStringList::Iterator it; |
405 | for ( it = list.begin(); it != list.end(); ++it ) { | 406 | for ( it = list.begin(); it != list.end(); ++it ) { |
406 | TextCodecInterface *iface = 0; | 407 | TextCodecInterface *iface = 0; |
407 | QLibrary *lib = new QLibrary( path + "/" + *it ); | 408 | QLibrary *lib = new QLibrary( path + "/" + *it ); |
408 | if ( lib->queryInterface( IID_QtopiaTextCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) { | 409 | if ( lib->queryInterface( IID_QtopiaTextCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) { |
409 | QValueList<int> mibs = iface->mibEnums(); | 410 | QValueList<int> mibs = iface->mibEnums(); |
410 | for (QValueList<int>::ConstIterator i = mibs.begin(); i != mibs.end(); ++i) { | 411 | for (QValueList<int>::ConstIterator i = mibs.begin(); i != mibs.end(); ++i) { |
411 | (void)iface->createForMib(*i); | 412 | (void)iface->createForMib(*i); |
412 | // ### it exists now; need to remember if we can delete it | 413 | // ### it exists now; need to remember if we can delete it |
413 | } | 414 | } |
414 | } | 415 | } |
415 | else { | 416 | else { |
416 | lib->unload(); | 417 | lib->unload(); |
417 | delete lib; | 418 | delete lib; |
418 | } | 419 | } |
419 | } | 420 | } |
420 | } | 421 | } |
421 | 422 | ||
422 | void loadImageCodecs() | 423 | void loadImageCodecs() |
423 | { | 424 | { |
424 | QString path = QPEApplication::qpeDir() + "plugins/imagecodecs"; | 425 | QString path = QPEApplication::qpeDir() + "plugins/imagecodecs"; |
425 | #ifdef Q_OS_MACX | 426 | #ifdef Q_OS_MACX |
426 | QDir dir( path, "lib*.dylib" ); | 427 | QDir dir( path, "lib*.dylib" ); |
427 | #else | 428 | #else |
428 | QDir dir( path, "lib*.so" ); | 429 | QDir dir( path, "lib*.so" ); |
429 | #endif | 430 | #endif |
430 | QStringList list; | 431 | QStringList list; |
431 | if ( dir. exists ( )) | 432 | if ( dir. exists ( )) |
432 | list = dir.entryList(); | 433 | list = dir.entryList(); |
433 | QStringList::Iterator it; | 434 | QStringList::Iterator it; |
434 | for ( it = list.begin(); it != list.end(); ++it ) { | 435 | for ( it = list.begin(); it != list.end(); ++it ) { |
435 | ImageCodecInterface *iface = 0; | 436 | ImageCodecInterface *iface = 0; |
436 | QLibrary *lib = new QLibrary( path + "/" + *it ); | 437 | QLibrary *lib = new QLibrary( path + "/" + *it ); |
437 | if ( lib->queryInterface( IID_QtopiaImageCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) { | 438 | if ( lib->queryInterface( IID_QtopiaImageCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) { |
438 | QStringList formats = iface->keys(); | 439 | QStringList formats = iface->keys(); |
439 | for (QStringList::ConstIterator i = formats.begin(); i != formats.end(); ++i) { | 440 | for (QStringList::ConstIterator i = formats.begin(); i != formats.end(); ++i) { |
440 | (void)iface->installIOHandler(*i); | 441 | (void)iface->installIOHandler(*i); |
441 | // ### it exists now; need to remember if we can delete it | 442 | // ### it exists now; need to remember if we can delete it |
442 | } | 443 | } |
443 | } | 444 | } |
444 | else { | 445 | else { |
445 | lib->unload(); | 446 | lib->unload(); |
446 | delete lib; | 447 | delete lib; |
447 | } | 448 | } |
448 | } | 449 | } |
449 | } | 450 | } |
450 | 451 | ||
451 | }; | 452 | }; |
452 | 453 | ||
453 | class ResourceMimeFactory : public QMimeSourceFactory | 454 | class ResourceMimeFactory : public QMimeSourceFactory |
454 | { | 455 | { |
455 | public: | 456 | public: |
456 | ResourceMimeFactory() : resImage( 0 ) | 457 | ResourceMimeFactory() : resImage( 0 ) |
457 | { | 458 | { |
458 | setFilePath( Global::helpPath() ); | 459 | setFilePath( Global::helpPath() ); |
459 | setExtensionType( "html", "text/html;charset=UTF-8" ); | 460 | setExtensionType( "html", "text/html;charset=UTF-8" ); |
460 | } | 461 | } |
461 | ~ResourceMimeFactory() { | 462 | ~ResourceMimeFactory() { |
462 | delete resImage; | 463 | delete resImage; |
463 | } | 464 | } |
464 | 465 | ||
465 | const QMimeSource* data( const QString& abs_name ) const | 466 | const QMimeSource* data( const QString& abs_name ) const |
466 | { | 467 | { |
467 | const QMimeSource * r = QMimeSourceFactory::data( abs_name ); | 468 | const QMimeSource * r = QMimeSourceFactory::data( abs_name ); |
468 | if ( !r ) { | 469 | if ( !r ) { |
469 | int sl = abs_name.length(); | 470 | int sl = abs_name.length(); |
470 | do { | 471 | do { |
471 | sl = abs_name.findRev( '/', sl - 1 ); | 472 | sl = abs_name.findRev( '/', sl - 1 ); |
472 | QString name = sl >= 0 ? abs_name.mid( sl + 1 ) : abs_name; | 473 | QString name = sl >= 0 ? abs_name.mid( sl + 1 ) : abs_name; |
473 | int dot = name.findRev( '.' ); | 474 | int dot = name.findRev( '.' ); |
474 | if ( dot >= 0 ) | 475 | if ( dot >= 0 ) |
475 | name = name.left( dot ); | 476 | name = name.left( dot ); |
476 | QImage img = Resource::loadImage( name ); | 477 | QImage img = Resource::loadImage( name ); |
477 | if ( !img.isNull() ) { | 478 | if ( !img.isNull() ) { |
478 | delete resImage; | 479 | delete resImage; |
479 | resImage = new QImageDrag( img ); | 480 | resImage = new QImageDrag( img ); |
480 | r = resImage; | 481 | r = resImage; |
481 | } | 482 | } |
482 | } | 483 | } |
483 | while ( !r && sl > 0 ); | 484 | while ( !r && sl > 0 ); |
484 | } | 485 | } |
485 | return r; | 486 | return r; |
486 | } | 487 | } |
487 | private: | 488 | private: |
488 | mutable QImageDrag *resImage; | 489 | mutable QImageDrag *resImage; |
489 | }; | 490 | }; |
490 | 491 | ||
491 | static int& hack(int& i) | 492 | static int& hack(int& i) |
492 | { | 493 | { |
493 | #if QT_VERSION <= 230 && defined(QT_NO_CODECS) | 494 | #if QT_VERSION <= 230 && defined(QT_NO_CODECS) |
494 | // These should be created, but aren't in Qt 2.3.0 | 495 | // These should be created, but aren't in Qt 2.3.0 |
495 | (void)new QUtf8Codec; | 496 | (void)new QUtf8Codec; |
496 | (void)new QUtf16Codec; | 497 | (void)new QUtf16Codec; |
497 | #endif | 498 | #endif |
498 | return i; | 499 | return i; |
499 | } | 500 | } |
500 | 501 | ||
501 | static int muted = 0; | 502 | static int muted = 0; |
502 | static int micMuted = 0; | 503 | static int micMuted = 0; |
503 | 504 | ||
504 | static void setVolume( int t = 0, int percent = -1 ) | 505 | static void setVolume( int t = 0, int percent = -1 ) |
505 | { | 506 | { |
506 | switch ( t ) { | 507 | switch ( t ) { |
507 | case 0: { | 508 | case 0: { |
508 | Config cfg( "qpe" ); | 509 | Config cfg( "qpe" ); |
509 | cfg.setGroup( "Volume" ); | 510 | cfg.setGroup( "Volume" ); |
510 | if ( percent < 0 ) | 511 | if ( percent < 0 ) |
511 | percent = cfg.readNumEntry( "VolumePercent", 50 ); | 512 | percent = cfg.readNumEntry( "VolumePercent", 50 ); |
512 | #ifndef QT_NO_SOUND | 513 | #ifndef QT_NO_SOUND |
513 | int fd = 0; | 514 | int fd = 0; |
514 | #ifdef QT_QWS_DEVFS | 515 | #ifdef QT_QWS_DEVFS |
515 | if ( ( fd = open( "/dev/sound/mixer", O_RDWR ) ) >= 0 ) { | 516 | if ( ( fd = open( "/dev/sound/mixer", O_RDWR ) ) >= 0 ) { |
516 | #else | 517 | #else |
517 | if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { | 518 | if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { |
518 | #endif | 519 | #endif |
519 | int vol = muted ? 0 : percent; | 520 | int vol = muted ? 0 : percent; |
520 | // set both channels to same volume | 521 | // set both channels to same volume |
521 | vol |= vol << 8; | 522 | vol |= vol << 8; |
522 | ioctl( fd, MIXER_WRITE( SOUND_MIXER_VOLUME ), &vol ); | 523 | ioctl( fd, MIXER_WRITE( SOUND_MIXER_VOLUME ), &vol ); |
523 | ::close( fd ); | 524 | ::close( fd ); |
524 | } | 525 | } |
525 | #endif | 526 | #endif |
526 | } | 527 | } |
527 | break; | 528 | break; |
528 | } | 529 | } |
529 | } | 530 | } |
530 | 531 | ||
531 | static void setMic( int t = 0, int percent = -1 ) | 532 | static void setMic( int t = 0, int percent = -1 ) |
532 | { | 533 | { |
533 | switch ( t ) { | 534 | switch ( t ) { |
534 | case 0: { | 535 | case 0: { |
535 | Config cfg( "qpe" ); | 536 | Config cfg( "qpe" ); |
536 | cfg.setGroup( "Volume" ); | 537 | cfg.setGroup( "Volume" ); |
537 | if ( percent < 0 ) | 538 | if ( percent < 0 ) |
538 | percent = cfg.readNumEntry( "Mic", 50 ); | 539 | percent = cfg.readNumEntry( "Mic", 50 ); |
539 | 540 | ||
540 | #ifndef QT_NO_SOUND | 541 | #ifndef QT_NO_SOUND |
541 | int fd = 0; | 542 | int fd = 0; |
542 | int mic = micMuted ? 0 : percent; | 543 | int mic = micMuted ? 0 : percent; |
543 | #ifdef QT_QWS_DEVFS | 544 | #ifdef QT_QWS_DEVFS |
544 | if ( ( fd = open( "/dev/sound/mixer", O_RDWR ) ) >= 0 ) { | 545 | if ( ( fd = open( "/dev/sound/mixer", O_RDWR ) ) >= 0 ) { |
545 | #else | 546 | #else |
546 | if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { | 547 | if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { |
547 | #endif | 548 | #endif |
548 | ioctl( fd, MIXER_WRITE( SOUND_MIXER_MIC ), &mic ); | 549 | ioctl( fd, MIXER_WRITE( SOUND_MIXER_MIC ), &mic ); |
549 | ::close( fd ); | 550 | ::close( fd ); |
550 | } | 551 | } |
551 | #endif | 552 | #endif |
552 | } | 553 | } |
553 | break; | 554 | break; |
554 | } | 555 | } |
555 | } | 556 | } |
556 | 557 | ||
557 | 558 | ||
558 | static void setBass( int t = 0, int percent = -1 ) | 559 | static void setBass( int t = 0, int percent = -1 ) |
559 | { | 560 | { |
560 | switch ( t ) { | 561 | switch ( t ) { |
561 | case 0: { | 562 | case 0: { |
562 | Config cfg( "qpe" ); | 563 | Config cfg( "qpe" ); |
563 | cfg.setGroup( "Volume" ); | 564 | cfg.setGroup( "Volume" ); |
564 | if ( percent < 0 ) | 565 | if ( percent < 0 ) |
565 | percent = cfg.readNumEntry( "BassPercent", 50 ); | 566 | percent = cfg.readNumEntry( "BassPercent", 50 ); |
566 | 567 | ||
567 | #ifndef QT_NO_SOUND | 568 | #ifndef QT_NO_SOUND |
568 | int fd = 0; | 569 | int fd = 0; |
569 | int bass = percent; | 570 | int bass = percent; |
570 | #ifdef QT_QWS_DEVFS | 571 | #ifdef QT_QWS_DEVFS |
571 | if ( ( fd = open( "/dev/sound/mixer", O_RDWR ) ) >= 0 ) { | 572 | if ( ( fd = open( "/dev/sound/mixer", O_RDWR ) ) >= 0 ) { |
572 | #else | 573 | #else |
573 | if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { | 574 | if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { |
574 | #endif | 575 | #endif |
575 | ioctl( fd, MIXER_WRITE( SOUND_MIXER_BASS ), &bass ); | 576 | ioctl( fd, MIXER_WRITE( SOUND_MIXER_BASS ), &bass ); |
576 | ::close( fd ); | 577 | ::close( fd ); |
577 | } | 578 | } |
578 | #endif | 579 | #endif |
579 | } | 580 | } |
580 | break; | 581 | break; |
581 | } | 582 | } |
582 | } | 583 | } |
583 | 584 | ||
584 | 585 | ||
585 | static void setTreble( int t = 0, int percent = -1 ) | 586 | static void setTreble( int t = 0, int percent = -1 ) |
586 | { | 587 | { |
587 | switch ( t ) { | 588 | switch ( t ) { |
588 | case 0: { | 589 | case 0: { |
589 | Config cfg( "qpe" ); | 590 | Config cfg( "qpe" ); |
590 | cfg.setGroup( "Volume" ); | 591 | cfg.setGroup( "Volume" ); |
591 | if ( percent < 0 ) | 592 | if ( percent < 0 ) |
592 | percent = cfg.readNumEntry( "TreblePercent", 50 ); | 593 | percent = cfg.readNumEntry( "TreblePercent", 50 ); |
593 | 594 | ||
594 | #ifndef QT_NO_SOUND | 595 | #ifndef QT_NO_SOUND |
595 | int fd = 0; | 596 | int fd = 0; |
596 | int treble = percent; | 597 | int treble = percent; |
597 | #ifdef QT_QWS_DEVFS | 598 | #ifdef QT_QWS_DEVFS |
598 | if ( ( fd = open( "/dev/sound/mixer", O_RDWR ) ) >= 0 ) { | 599 | if ( ( fd = open( "/dev/sound/mixer", O_RDWR ) ) >= 0 ) { |
599 | #else | 600 | #else |
600 | if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { | 601 | if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { |
601 | #endif | 602 | #endif |
602 | ioctl( fd, MIXER_WRITE( SOUND_MIXER_TREBLE ), &treble ); | 603 | ioctl( fd, MIXER_WRITE( SOUND_MIXER_TREBLE ), &treble ); |
603 | ::close( fd ); | 604 | ::close( fd ); |
604 | } | 605 | } |
605 | #endif | 606 | #endif |
606 | } | 607 | } |
607 | break; | 608 | break; |
608 | } | 609 | } |
609 | } | 610 | } |
610 | 611 | ||
611 | 612 | ||
612 | /** | 613 | /** |
613 | \class QPEApplication | 614 | \class QPEApplication |
614 | \brief The QPEApplication class implements various system services | 615 | \brief The QPEApplication class implements various system services |
615 | that are available to all Qtopia applications. | 616 | that are available to all Qtopia applications. |
616 | 617 | ||
617 | Simply by using QPEApplication instead of QApplication, a standard Qt | 618 | Simply by using QPEApplication instead of QApplication, a standard Qt |
618 | application becomes a Qtopia application. It automatically follows | 619 | application becomes a Qtopia application. It automatically follows |
619 | style changes, quits and raises, and in the | 620 | style changes, quits and raises, and in the |
620 | case of \link docwidget.html document-oriented\endlink applications, | 621 | case of \link docwidget.html document-oriented\endlink applications, |
621 | changes the currently displayed document in response to the environment. | 622 | changes the currently displayed document in response to the environment. |
622 | 623 | ||
623 | To create a \link docwidget.html document-oriented\endlink | 624 | To create a \link docwidget.html document-oriented\endlink |
624 | application use showMainDocumentWidget(); to create a | 625 | application use showMainDocumentWidget(); to create a |
625 | non-document-oriented application use showMainWidget(). The | 626 | non-document-oriented application use showMainWidget(). The |
626 | keepRunning() function indicates whether the application will | 627 | keepRunning() function indicates whether the application will |
627 | continue running after it's processed the last \link qcop.html | 628 | continue running after it's processed the last \link qcop.html |
628 | QCop\endlink message. This can be changed using setKeepRunning(). | 629 | QCop\endlink message. This can be changed using setKeepRunning(). |
629 | 630 | ||
630 | A variety of signals are emitted when certain events occur, for | 631 | A variety of signals are emitted when certain events occur, for |
631 | example, timeChanged(), clockChanged(), weekChanged(), | 632 | example, timeChanged(), clockChanged(), weekChanged(), |
632 | dateFormatChanged() and volumeChanged(). If the application receives | 633 | dateFormatChanged() and volumeChanged(). If the application receives |
633 | a \link qcop.html QCop\endlink message on the application's | 634 | a \link qcop.html QCop\endlink message on the application's |
634 | QPE/Application/\e{appname} channel, the appMessage() signal is | 635 | QPE/Application/\e{appname} channel, the appMessage() signal is |
635 | emitted. There are also flush() and reload() signals, which | 636 | emitted. There are also flush() and reload() signals, which |
636 | are emitted when synching begins and ends respectively - upon these | 637 | are emitted when synching begins and ends respectively - upon these |
637 | signals, the application should save and reload any data | 638 | signals, the application should save and reload any data |
638 | files that are involved in synching. Most of these signals will initially | 639 | files that are involved in synching. Most of these signals will initially |
639 | be received and unfiltered through the appMessage() signal. | 640 | be received and unfiltered through the appMessage() signal. |
640 | 641 | ||
641 | This class also provides a set of useful static functions. The | 642 | This class also provides a set of useful static functions. The |
642 | qpeDir() and documentDir() functions return the respective paths. | 643 | qpeDir() and documentDir() functions return the respective paths. |
643 | The grabKeyboard() and ungrabKeyboard() functions are used to | 644 | The grabKeyboard() and ungrabKeyboard() functions are used to |
644 | control whether the application takes control of the device's | 645 | control whether the application takes control of the device's |
645 | physical buttons (e.g. application launch keys). The stylus' mode of | 646 | physical buttons (e.g. application launch keys). The stylus' mode of |
646 | operation is set with setStylusOperation() and retrieved with | 647 | operation is set with setStylusOperation() and retrieved with |
647 | stylusOperation(). There are also setInputMethodHint() and | 648 | stylusOperation(). There are also setInputMethodHint() and |
648 | inputMethodHint() functions. | 649 | inputMethodHint() functions. |
649 | 650 | ||
650 | \ingroup qtopiaemb | 651 | \ingroup qtopiaemb |
651 | */ | 652 | */ |
652 | 653 | ||
653 | /*! | 654 | /*! |
654 | \fn void QPEApplication::clientMoused() | 655 | \fn void QPEApplication::clientMoused() |
655 | 656 | ||
656 | \internal | 657 | \internal |
657 | */ | 658 | */ |
658 | 659 | ||
659 | /*! | 660 | /*! |
660 | \fn void QPEApplication::timeChanged(); | 661 | \fn void QPEApplication::timeChanged(); |
661 | This signal is emitted when the time changes outside the normal | 662 | This signal is emitted when the time changes outside the normal |
662 | passage of time, i.e. if the time is set backwards or forwards. | 663 | passage of time, i.e. if the time is set backwards or forwards. |
663 | */ | 664 | */ |
664 | 665 | ||
665 | /*! | 666 | /*! |
666 | \fn void QPEApplication::clockChanged( bool ampm ); | 667 | \fn void QPEApplication::clockChanged( bool ampm ); |
667 | 668 | ||
668 | This signal is emitted when the user changes the clock's style. If | 669 | This signal is emitted when the user changes the clock's style. If |
669 | \a ampm is TRUE, the user wants a 12-hour AM/PM clock, otherwise, | 670 | \a ampm is TRUE, the user wants a 12-hour AM/PM clock, otherwise, |
670 | they want a 24-hour clock. | 671 | they want a 24-hour clock. |
671 | */ | 672 | */ |
672 | 673 | ||
673 | /*! | 674 | /*! |
674 | \fn void QPEApplication::volumeChanged( bool muted ) | 675 | \fn void QPEApplication::volumeChanged( bool muted ) |
675 | 676 | ||
676 | This signal is emitted whenever the mute state is changed. If \a | 677 | This signal is emitted whenever the mute state is changed. If \a |
677 | muted is TRUE, then sound output has been muted. | 678 | muted is TRUE, then sound output has been muted. |
678 | */ | 679 | */ |
679 | 680 | ||
680 | /*! | 681 | /*! |
681 | \fn void QPEApplication::weekChanged( bool startOnMonday ) | 682 | \fn void QPEApplication::weekChanged( bool startOnMonday ) |
682 | 683 | ||
683 | This signal is emitted if the week start day is changed. If \a | 684 | This signal is emitted if the week start day is changed. If \a |
684 | startOnMonday is TRUE then the first day of the week is Monday; if | 685 | startOnMonday is TRUE then the first day of the week is Monday; if |
685 | \a startOnMonday is FALSE then the first day of the week is | 686 | \a startOnMonday is FALSE then the first day of the week is |
686 | Sunday. | 687 | Sunday. |
687 | */ | 688 | */ |
688 | 689 | ||
689 | /*! | 690 | /*! |
690 | \fn void QPEApplication::dateFormatChanged(DateFormat) | 691 | \fn void QPEApplication::dateFormatChanged(DateFormat) |
691 | 692 | ||
692 | This signal is emitted whenever the date format is changed. | 693 | This signal is emitted whenever the date format is changed. |
693 | */ | 694 | */ |
694 | 695 | ||
695 | /*! | 696 | /*! |
696 | \fn void QPEApplication::flush() | 697 | \fn void QPEApplication::flush() |
697 | 698 | ||
698 | ### | 699 | ### |
699 | */ | 700 | */ |
700 | 701 | ||
701 | /*! | 702 | /*! |
702 | \fn void QPEApplication::reload() | 703 | \fn void QPEApplication::reload() |
703 | 704 | ||
704 | */ | 705 | */ |
705 | 706 | ||
706 | 707 | ||
707 | 708 | ||
708 | void QPEApplication::processQCopFile() | 709 | void QPEApplication::processQCopFile() |
709 | { | 710 | { |
710 | QString qcopfn("/tmp/qcop-msg-"); | 711 | QString qcopfn("/tmp/qcop-msg-"); |
711 | qcopfn += d->appName; // append command name | 712 | qcopfn += d->appName; // append command name |
712 | 713 | ||
713 | QFile f(qcopfn); | 714 | QFile f(qcopfn); |
714 | if ( f.open(IO_ReadWrite) ) { | 715 | if ( f.open(IO_ReadWrite) ) { |
715 | #ifndef Q_OS_WIN32 | 716 | #ifndef Q_OS_WIN32 |
716 | flock(f.handle(), LOCK_EX); | 717 | flock(f.handle(), LOCK_EX); |
717 | #endif | 718 | #endif |
718 | QDataStream ds(&f); | 719 | QDataStream ds(&f); |
719 | QCString channel, message; | 720 | QCString channel, message; |
720 | QByteArray data; | 721 | QByteArray data; |
721 | while(!ds.atEnd()) { | 722 | while(!ds.atEnd()) { |
722 | ds >> channel >> message >> data; | 723 | ds >> channel >> message >> data; |
723 | d->enqueueQCop(channel,message,data); | 724 | d->enqueueQCop(channel,message,data); |
724 | } | 725 | } |
725 | ::ftruncate(f.handle(), 0); | 726 | ::ftruncate(f.handle(), 0); |
726 | #ifndef Q_OS_WIN32 | 727 | #ifndef Q_OS_WIN32 |
727 | f.flush(); | 728 | f.flush(); |
728 | flock(f.handle(), LOCK_UN); | 729 | flock(f.handle(), LOCK_UN); |
729 | #endif | 730 | #endif |
730 | } | 731 | } |
731 | #endif | 732 | #endif |
732 | } | 733 | } |
733 | 734 | ||
734 | 735 | ||
735 | /*! | 736 | /*! |
736 | \fn void QPEApplication::appMessage( const QCString& msg, const QByteArray& data ) | 737 | \fn void QPEApplication::appMessage( const QCString& msg, const QByteArray& data ) |
737 | 738 | ||
738 | This signal is emitted when a message is received on this | 739 | This signal is emitted when a message is received on this |
739 | application's QPE/Application/<i>appname</i> \link qcop.html | 740 | application's QPE/Application/<i>appname</i> \link qcop.html |
740 | QCop\endlink channel. | 741 | QCop\endlink channel. |
741 | 742 | ||
742 | The slot to which you connect this signal uses \a msg and \a data | 743 | The slot to which you connect this signal uses \a msg and \a data |
743 | in the following way: | 744 | in the following way: |
744 | 745 | ||
745 | \code | 746 | \code |
746 | void MyWidget::receive( const QCString& msg, const QByteArray& data ) | 747 | void MyWidget::receive( const QCString& msg, const QByteArray& data ) |
747 | { | 748 | { |
748 | QDataStream stream( data, IO_ReadOnly ); | 749 | QDataStream stream( data, IO_ReadOnly ); |
749 | if ( msg == "someMessage(int,int,int)" ) { | 750 | if ( msg == "someMessage(int,int,int)" ) { |
750 | int a,b,c; | 751 | int a,b,c; |
751 | stream >> a >> b >> c; | 752 | stream >> a >> b >> c; |
752 | ... | 753 | ... |
753 | } else if ( msg == "otherMessage(QString)" ) { | 754 | } else if ( msg == "otherMessage(QString)" ) { |
754 | ... | 755 | ... |
755 | } | 756 | } |
756 | } | 757 | } |
757 | \endcode | 758 | \endcode |
758 | 759 | ||
759 | \sa qcop.html | 760 | \sa qcop.html |
760 | Note that messages received here may be processed by qpe application | 761 | Note that messages received here may be processed by qpe application |
761 | and emitted as signals, such as flush() and reload(). | 762 | and emitted as signals, such as flush() and reload(). |
762 | */ | 763 | */ |
763 | 764 | ||
764 | #ifndef QT_NO_TRANSLATION | 765 | #ifndef QT_NO_TRANSLATION |
765 | static void qtopia_loadTranslations( const QStringList& qms ) | 766 | static void qtopia_loadTranslations( const QStringList& qms ) |
766 | { | 767 | { |
767 | QStringList langs = Global::languageList(); | 768 | QStringList langs = Global::languageList(); |
768 | 769 | ||
769 | for (QStringList::ConstIterator it = langs.begin(); it!=langs.end(); ++it) { | 770 | for (QStringList::ConstIterator it = langs.begin(); it!=langs.end(); ++it) { |
770 | QString lang = *it; | 771 | QString lang = *it; |
771 | 772 | ||
772 | QTranslator * trans; | 773 | QTranslator * trans; |
773 | QString tfn; | 774 | QString tfn; |
774 | 775 | ||
775 | for (QStringList::ConstIterator qmit = qms.begin(); qmit!=qms.end(); ++qmit) { | 776 | for (QStringList::ConstIterator qmit = qms.begin(); qmit!=qms.end(); ++qmit) { |
776 | trans = new QTranslator(qApp); | 777 | trans = new QTranslator(qApp); |
777 | tfn = QPEApplication::qpeDir() + "i18n/" + lang + "/" + *qmit + ".qm"; | 778 | tfn = QPEApplication::qpeDir() + "i18n/" + lang + "/" + *qmit + ".qm"; |
778 | if ( trans->load( tfn )) | 779 | if ( trans->load( tfn )) |
779 | qApp->installTranslator( trans ); | 780 | qApp->installTranslator( trans ); |
780 | else | 781 | else |
781 | delete trans; | 782 | delete trans; |
782 | } | 783 | } |
783 | } | 784 | } |
784 | } | 785 | } |
785 | #endif | 786 | #endif |
786 | 787 | ||
787 | /* | 788 | /* |
788 | Turn off qDebug in release mode | 789 | Turn off qDebug in release mode |
789 | */ | 790 | */ |
790 | static void qtopiaMsgHandler(QtMsgType type, const char* msg) | 791 | static void qtopiaMsgHandler(QtMsgType type, const char* msg) |
791 | { | 792 | { |
792 | switch ( type ) { | 793 | switch ( type ) { |
793 | case QtDebugMsg: | 794 | case QtDebugMsg: |
794 | #ifdef QT_DEBUG | 795 | #ifdef QT_DEBUG |
795 | fprintf( stderr, "Debug: %s\n", msg ); | 796 | fprintf( stderr, "Debug: %s\n", msg ); |
796 | #endif | 797 | #endif |
797 | break; | 798 | break; |
798 | case QtWarningMsg: | 799 | case QtWarningMsg: |
799 | #ifdef QT_DEBUG | 800 | #ifdef QT_DEBUG |
800 | fprintf( stderr, "Warning: %s\n", msg ); | 801 | fprintf( stderr, "Warning: %s\n", msg ); |
801 | #endif | 802 | #endif |
802 | break; | 803 | break; |
803 | case QtFatalMsg: | 804 | case QtFatalMsg: |
804 | fprintf( stderr, "Fatal: %s\n", msg ); | 805 | fprintf( stderr, "Fatal: %s\n", msg ); |
805 | abort(); | 806 | abort(); |
806 | } | 807 | } |
807 | } | 808 | } |
808 | 809 | ||
809 | /*! | 810 | /*! |
810 | Constructs a QPEApplication just as you would construct | 811 | Constructs a QPEApplication just as you would construct |
811 | a QApplication, passing \a argc, \a argv, and \a t. | 812 | a QApplication, passing \a argc, \a argv, and \a t. |
812 | 813 | ||
813 | For applications, \a t should be the default, GuiClient. Only | 814 | For applications, \a t should be the default, GuiClient. Only |
814 | the Qtopia server passes GuiServer. | 815 | the Qtopia server passes GuiServer. |
815 | */ | 816 | */ |
816 | QPEApplication::QPEApplication( int & argc, char **argv, Type t ) | 817 | QPEApplication::QPEApplication( int & argc, char **argv, Type t ) |
817 | : QApplication( hack(argc), argv, t ), pidChannel( 0 ) | 818 | : QApplication( hack(argc), argv, t ), pidChannel( 0 ) |
818 | { | 819 | { |
819 | QPixmapCache::setCacheLimit(256); // sensible default for smaller devices. | 820 | QPixmapCache::setCacheLimit(256); // sensible default for smaller devices. |
820 | qInstallMsgHandler(qtopiaMsgHandler); | 821 | qInstallMsgHandler(qtopiaMsgHandler); |
821 | 822 | ||
822 | d = new QPEApplicationData; | 823 | d = new QPEApplicationData; |
823 | d->loadTextCodecs(); | 824 | d->loadTextCodecs(); |
824 | d->loadImageCodecs(); | 825 | d->loadImageCodecs(); |
825 | 826 | ||
826 | setFont( QFont( d->fontFamily, d->fontSize ) ); | 827 | setFont( QFont( d->fontFamily, d->fontSize ) ); |
827 | AppLnk::setSmallIconSize( d->smallIconSize ); | 828 | AppLnk::setSmallIconSize( d->smallIconSize ); |
828 | AppLnk::setBigIconSize( d->bigIconSize ); | 829 | AppLnk::setBigIconSize( d->bigIconSize ); |
829 | 830 | ||
830 | QMimeSourceFactory::setDefaultFactory( new ResourceMimeFactory ); | 831 | QMimeSourceFactory::setDefaultFactory( new ResourceMimeFactory ); |
831 | 832 | ||
832 | connect( this, SIGNAL( lastWindowClosed() ), this, SLOT( hideOrQuit() ) ); | 833 | connect( this, SIGNAL( lastWindowClosed() ), this, SLOT( hideOrQuit() ) ); |
833 | 834 | ||
834 | 835 | ||
835 | sysChannel = new QCopChannel( "QPE/System", this ); | 836 | sysChannel = new QCopChannel( "QPE/System", this ); |
836 | connect( sysChannel, SIGNAL( received(const QCString&,const QByteArray&) ), | 837 | connect( sysChannel, SIGNAL( received(const QCString&,const QByteArray&) ), |
837 | this, SLOT( systemMessage(const QCString&,const QByteArray&) ) ); | 838 | this, SLOT( systemMessage(const QCString&,const QByteArray&) ) ); |
838 | 839 | ||
839 | /* COde now in initapp */ | 840 | /* COde now in initapp */ |
840 | #if 0 | 841 | #if 0 |
841 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 842 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
842 | 843 | ||
843 | QString qcopfn( "/tmp/qcop-msg-" ); | 844 | QString qcopfn( "/tmp/qcop-msg-" ); |
844 | qcopfn += QString( argv[ 0 ] ); // append command name | 845 | qcopfn += QString( argv[ 0 ] ); // append command name |
845 | 846 | ||
846 | QFile f( qcopfn ); | 847 | QFile f( qcopfn ); |
847 | if ( f.open( IO_ReadOnly ) ) { | 848 | if ( f.open( IO_ReadOnly ) ) { |
848 | flock( f.handle(), LOCK_EX ); | 849 | flock( f.handle(), LOCK_EX ); |
849 | } | 850 | } |
850 | 851 | ||
851 | 852 | ||
852 | 853 | ||
853 | QCString channel = QCString( argv[ 0 ] ); | 854 | QCString channel = QCString( argv[ 0 ] ); |
854 | channel.replace( QRegExp( ".*/" ), "" ); | 855 | channel.replace( QRegExp( ".*/" ), "" ); |
855 | d->appName = channel; | 856 | d->appName = channel; |
856 | channel = "QPE/Application/" + channel; | 857 | channel = "QPE/Application/" + channel; |
857 | pidChannel = new QCopChannel( channel, this ); | 858 | pidChannel = new QCopChannel( channel, this ); |
858 | connect( pidChannel, SIGNAL( received(const QCString&,const QByteArray&) ), | 859 | connect( pidChannel, SIGNAL( received(const QCString&,const QByteArray&) ), |
@@ -1698,593 +1699,598 @@ void QPEApplication::pidMessage( const QCString& msg, const QByteArray& data) | |||
1698 | e << d->appName; | 1699 | e << d->appName; |
1699 | } | 1700 | } |
1700 | else if ( msg == "flush()" ) { | 1701 | else if ( msg == "flush()" ) { |
1701 | emit flush(); | 1702 | emit flush(); |
1702 | // we need to tell the desktop | 1703 | // we need to tell the desktop |
1703 | QCopEnvelope e( "QPE/Desktop", "flushDone(QString)" ); | 1704 | QCopEnvelope e( "QPE/Desktop", "flushDone(QString)" ); |
1704 | e << d->appName; | 1705 | e << d->appName; |
1705 | } | 1706 | } |
1706 | else if ( msg == "reload()" ) { | 1707 | else if ( msg == "reload()" ) { |
1707 | emit reload(); | 1708 | emit reload(); |
1708 | } | 1709 | } |
1709 | else if ( msg == "setDocument(QString)" ) { | 1710 | else if ( msg == "setDocument(QString)" ) { |
1710 | d->keep_running = TRUE; | 1711 | d->keep_running = TRUE; |
1711 | QDataStream stream( data, IO_ReadOnly ); | 1712 | QDataStream stream( data, IO_ReadOnly ); |
1712 | QString doc; | 1713 | QString doc; |
1713 | stream >> doc; | 1714 | stream >> doc; |
1714 | QWidget *mw = mainWidget(); | 1715 | QWidget *mw = mainWidget(); |
1715 | if ( !mw ) | 1716 | if ( !mw ) |
1716 | mw = d->qpe_main_widget; | 1717 | mw = d->qpe_main_widget; |
1717 | if ( mw ) | 1718 | if ( mw ) |
1718 | Global::setDocument( mw, doc ); | 1719 | Global::setDocument( mw, doc ); |
1719 | 1720 | ||
1720 | } else if ( msg == "QPEProcessQCop()" ) { | 1721 | } else if ( msg == "QPEProcessQCop()" ) { |
1721 | processQCopFile(); | 1722 | processQCopFile(); |
1722 | d->sendQCopQ(); | 1723 | d->sendQCopQ(); |
1723 | }else | 1724 | }else |
1724 | { | 1725 | { |
1725 | bool p = d->keep_running; | 1726 | bool p = d->keep_running; |
1726 | d->keep_running = FALSE; | 1727 | d->keep_running = FALSE; |
1727 | emit appMessage( msg, data); | 1728 | emit appMessage( msg, data); |
1728 | if ( d->keep_running ) { | 1729 | if ( d->keep_running ) { |
1729 | d->notbusysent = FALSE; | 1730 | d->notbusysent = FALSE; |
1730 | raiseAppropriateWindow(); | 1731 | raiseAppropriateWindow(); |
1731 | if ( !p ) { | 1732 | if ( !p ) { |
1732 | // Tell the system we're still chugging along... | 1733 | // Tell the system we're still chugging along... |
1733 | #ifndef QT_NO_COP | 1734 | #ifndef QT_NO_COP |
1734 | QCopEnvelope e("QPE/System", "appRaised(QString)"); | 1735 | QCopEnvelope e("QPE/System", "appRaised(QString)"); |
1735 | e << d->appName; | 1736 | e << d->appName; |
1736 | #endif | 1737 | #endif |
1737 | } | 1738 | } |
1738 | } | 1739 | } |
1739 | if ( p ) | 1740 | if ( p ) |
1740 | d->keep_running = p; | 1741 | d->keep_running = p; |
1741 | } | 1742 | } |
1742 | #endif | 1743 | #endif |
1743 | } | 1744 | } |
1744 | 1745 | ||
1745 | 1746 | ||
1746 | /*! | 1747 | /*! |
1747 | Sets widget \a mw as the mainWidget() and shows it. For small windows, | 1748 | Sets widget \a mw as the mainWidget() and shows it. For small windows, |
1748 | consider passing TRUE for \a nomaximize rather than the default FALSE. | 1749 | consider passing TRUE for \a nomaximize rather than the default FALSE. |
1749 | 1750 | ||
1750 | \sa showMainDocumentWidget() | 1751 | \sa showMainDocumentWidget() |
1751 | */ | 1752 | */ |
1752 | void QPEApplication::showMainWidget( QWidget* mw, bool nomaximize ) | 1753 | void QPEApplication::showMainWidget( QWidget* mw, bool nomaximize ) |
1753 | { | 1754 | { |
1754 | // setMainWidget(mw); this breaks FastLoading because lastWindowClose() would quit | 1755 | // setMainWidget(mw); this breaks FastLoading because lastWindowClose() would quit |
1755 | d->show(mw, nomaximize ); | 1756 | d->show(mw, nomaximize ); |
1756 | } | 1757 | } |
1757 | 1758 | ||
1758 | /*! | 1759 | /*! |
1759 | Sets widget \a mw as the mainWidget() and shows it. For small windows, | 1760 | Sets widget \a mw as the mainWidget() and shows it. For small windows, |
1760 | consider passing TRUE for \a nomaximize rather than the default FALSE. | 1761 | consider passing TRUE for \a nomaximize rather than the default FALSE. |
1761 | 1762 | ||
1762 | This calls designates the application as | 1763 | This calls designates the application as |
1763 | a \link docwidget.html document-oriented\endlink application. | 1764 | a \link docwidget.html document-oriented\endlink application. |
1764 | 1765 | ||
1765 | The \a mw widget \e must have this slot: setDocument(const QString&). | 1766 | The \a mw widget \e must have this slot: setDocument(const QString&). |
1766 | 1767 | ||
1767 | \sa showMainWidget() | 1768 | \sa showMainWidget() |
1768 | */ | 1769 | */ |
1769 | void QPEApplication::showMainDocumentWidget( QWidget* mw, bool nomaximize ) | 1770 | void QPEApplication::showMainDocumentWidget( QWidget* mw, bool nomaximize ) |
1770 | { | 1771 | { |
1771 | if ( mw && argc() == 2 ) | 1772 | if ( mw && argc() == 2 ) |
1772 | Global::setDocument( mw, QString::fromUtf8(argv()[1]) ); | 1773 | Global::setDocument( mw, QString::fromUtf8(argv()[1]) ); |
1773 | 1774 | ||
1774 | 1775 | ||
1775 | // setMainWidget(mw); see above | 1776 | // setMainWidget(mw); see above |
1776 | d->show(mw, nomaximize ); | 1777 | d->show(mw, nomaximize ); |
1777 | } | 1778 | } |
1778 | 1779 | ||
1779 | 1780 | ||
1780 | /*! | 1781 | /*! |
1781 | If an application is started via a \link qcop.html QCop\endlink | 1782 | If an application is started via a \link qcop.html QCop\endlink |
1782 | message, the application will process the \link qcop.html | 1783 | message, the application will process the \link qcop.html |
1783 | QCop\endlink message and then quit. If the application calls this | 1784 | QCop\endlink message and then quit. If the application calls this |
1784 | function while processing a \link qcop.html QCop\endlink message, | 1785 | function while processing a \link qcop.html QCop\endlink message, |
1785 | after processing its outstanding \link qcop.html QCop\endlink | 1786 | after processing its outstanding \link qcop.html QCop\endlink |
1786 | messages the application will start 'properly' and show itself. | 1787 | messages the application will start 'properly' and show itself. |
1787 | 1788 | ||
1788 | \sa keepRunning() | 1789 | \sa keepRunning() |
1789 | */ | 1790 | */ |
1790 | void QPEApplication::setKeepRunning() | 1791 | void QPEApplication::setKeepRunning() |
1791 | { | 1792 | { |
1792 | if ( qApp && qApp->inherits( "QPEApplication" ) ) { | 1793 | if ( qApp && qApp->inherits( "QPEApplication" ) ) { |
1793 | QPEApplication * qpeApp = ( QPEApplication* ) qApp; | 1794 | QPEApplication * qpeApp = ( QPEApplication* ) qApp; |
1794 | qpeApp->d->keep_running = TRUE; | 1795 | qpeApp->d->keep_running = TRUE; |
1795 | } | 1796 | } |
1796 | } | 1797 | } |
1797 | 1798 | ||
1798 | /*! | 1799 | /*! |
1799 | Returns TRUE if the application will quit after processing the | 1800 | Returns TRUE if the application will quit after processing the |
1800 | current list of qcop messages; otherwise returns FALSE. | 1801 | current list of qcop messages; otherwise returns FALSE. |
1801 | 1802 | ||
1802 | \sa setKeepRunning() | 1803 | \sa setKeepRunning() |
1803 | */ | 1804 | */ |
1804 | bool QPEApplication::keepRunning() const | 1805 | bool QPEApplication::keepRunning() const |
1805 | { | 1806 | { |
1806 | return d->keep_running; | 1807 | return d->keep_running; |
1807 | } | 1808 | } |
1808 | 1809 | ||
1809 | /*! | 1810 | /*! |
1810 | \internal | 1811 | \internal |
1811 | */ | 1812 | */ |
1812 | void QPEApplication::internalSetStyle( const QString &style ) | 1813 | void QPEApplication::internalSetStyle( const QString &style ) |
1813 | { | 1814 | { |
1814 | #if QT_VERSION >= 0x030000 | 1815 | #if QT_VERSION >= 0x030000 |
1815 | if ( style == "QPE" ) { | 1816 | if ( style == "QPE" ) { |
1816 | setStyle( new QPEStyle ); | 1817 | setStyle( new QPEStyle ); |
1817 | } | 1818 | } |
1818 | else { | 1819 | else { |
1819 | QStyle *s = QStyleFactory::create( style ); | 1820 | QStyle *s = QStyleFactory::create( style ); |
1820 | if ( s ) | 1821 | if ( s ) |
1821 | setStyle( s ); | 1822 | setStyle( s ); |
1822 | } | 1823 | } |
1823 | #else | 1824 | #else |
1824 | if ( style == "Windows" ) { | 1825 | if ( style == "Windows" ) { |
1825 | setStyle( new QWindowsStyle ); | 1826 | setStyle( new QWindowsStyle ); |
1826 | } | 1827 | } |
1827 | else if ( style == "QPE" ) { | 1828 | else if ( style == "QPE" ) { |
1828 | setStyle( new QPEStyle ); | 1829 | setStyle( new QPEStyle ); |
1829 | } | 1830 | } |
1830 | else if ( style == "Light" ) { | 1831 | else if ( style == "Light" ) { |
1831 | setStyle( new LightStyle ); | 1832 | setStyle( new LightStyle ); |
1832 | } | 1833 | } |
1833 | #ifndef QT_NO_STYLE_PLATINUM | 1834 | #ifndef QT_NO_STYLE_PLATINUM |
1834 | else if ( style == "Platinum" ) { | 1835 | else if ( style == "Platinum" ) { |
1835 | setStyle( new QPlatinumStyle ); | 1836 | setStyle( new QPlatinumStyle ); |
1836 | } | 1837 | } |
1837 | #endif | 1838 | #endif |
1838 | #ifndef QT_NO_STYLE_MOTIF | 1839 | #ifndef QT_NO_STYLE_MOTIF |
1839 | else if ( style == "Motif" ) { | 1840 | else if ( style == "Motif" ) { |
1840 | setStyle( new QMotifStyle ); | 1841 | setStyle( new QMotifStyle ); |
1841 | } | 1842 | } |
1842 | #endif | 1843 | #endif |
1843 | #ifndef QT_NO_STYLE_MOTIFPLUS | 1844 | #ifndef QT_NO_STYLE_MOTIFPLUS |
1844 | else if ( style == "MotifPlus" ) { | 1845 | else if ( style == "MotifPlus" ) { |
1845 | setStyle( new QMotifPlusStyle ); | 1846 | setStyle( new QMotifPlusStyle ); |
1846 | } | 1847 | } |
1847 | #endif | 1848 | #endif |
1848 | 1849 | ||
1849 | else { | 1850 | else { |
1850 | QStyle *sty = 0; | 1851 | QStyle *sty = 0; |
1851 | QString path = QPEApplication::qpeDir ( ) + "plugins/styles/"; | 1852 | QString path = QPEApplication::qpeDir ( ) + "plugins/styles/"; |
1852 | 1853 | ||
1853 | #ifdef Q_OS_MACX | 1854 | #ifdef Q_OS_MACX |
1854 | if ( style. find ( ".dylib" ) > 0 ) | 1855 | if ( style. find ( ".dylib" ) > 0 ) |
1855 | path += style; | 1856 | path += style; |
1856 | else | 1857 | else |
1857 | path = path + "lib" + style. lower ( ) + ".dylib"; // compatibility | 1858 | path = path + "lib" + style. lower ( ) + ".dylib"; // compatibility |
1858 | #else | 1859 | #else |
1859 | if ( style. find ( ".so" ) > 0 ) | 1860 | if ( style. find ( ".so" ) > 0 ) |
1860 | path += style; | 1861 | path += style; |
1861 | else | 1862 | else |
1862 | path = path + "lib" + style. lower ( ) + ".so"; // compatibility | 1863 | path = path + "lib" + style. lower ( ) + ".so"; // compatibility |
1863 | #endif | 1864 | #endif |
1864 | static QLibrary *lastlib = 0; | 1865 | static QLibrary *lastlib = 0; |
1865 | static StyleInterface *lastiface = 0; | 1866 | static StyleInterface *lastiface = 0; |
1866 | 1867 | ||
1867 | QLibrary *lib = new QLibrary ( path ); | 1868 | QLibrary *lib = new QLibrary ( path ); |
1868 | StyleInterface *iface = 0; | 1869 | StyleInterface *iface = 0; |
1869 | 1870 | ||
1870 | if (( lib-> queryInterface ( IID_Style, ( QUnknownInterface ** ) &iface ) == QS_OK ) && iface ) | 1871 | if (( lib-> queryInterface ( IID_Style, ( QUnknownInterface ** ) &iface ) == QS_OK ) && iface ) |
1871 | sty = iface-> style ( ); | 1872 | sty = iface-> style ( ); |
1872 | 1873 | ||
1873 | if ( sty ) { | 1874 | if ( sty ) { |
1874 | setStyle ( sty ); | 1875 | setStyle ( sty ); |
1875 | 1876 | ||
1876 | if ( lastiface ) | 1877 | if ( lastiface ) |
1877 | lastiface-> release ( ); | 1878 | lastiface-> release ( ); |
1878 | lastiface = iface; | 1879 | lastiface = iface; |
1879 | 1880 | ||
1880 | if ( lastlib ) { | 1881 | if ( lastlib ) { |
1881 | lastlib-> unload ( ); | 1882 | lastlib-> unload ( ); |
1882 | delete lastlib; | 1883 | delete lastlib; |
1883 | } | 1884 | } |
1884 | lastlib = lib; | 1885 | lastlib = lib; |
1885 | } | 1886 | } |
1886 | else { | 1887 | else { |
1887 | if ( iface ) | 1888 | if ( iface ) |
1888 | iface-> release ( ); | 1889 | iface-> release ( ); |
1889 | delete lib; | 1890 | delete lib; |
1890 | 1891 | ||
1891 | setStyle ( new LightStyle ( )); | 1892 | setStyle ( new LightStyle ( )); |
1892 | } | 1893 | } |
1893 | } | 1894 | } |
1894 | #endif | 1895 | #endif |
1895 | } | 1896 | } |
1896 | 1897 | ||
1897 | /*! | 1898 | /*! |
1898 | \internal | 1899 | \internal |
1899 | */ | 1900 | */ |
1900 | void QPEApplication::prepareForTermination( bool willrestart ) | 1901 | void QPEApplication::prepareForTermination( bool willrestart ) |
1901 | { | 1902 | { |
1902 | if ( willrestart ) { | 1903 | if ( willrestart ) { |
1903 | QLabel *lblWait = new QLabel( tr( "Please wait..." ), 0, "wait hack", QWidget::WStyle_Customize | | 1904 | QLabel *lblWait = new QLabel( tr( "Please wait..." ), 0, "wait hack", QWidget::WStyle_Customize | |
1904 | QWidget::WStyle_NoBorder | QWidget::WStyle_Tool ); | 1905 | QWidget::WStyle_NoBorder | QWidget::WStyle_Tool ); |
1905 | lblWait->setAlignment( QWidget::AlignCenter ); | 1906 | lblWait->setAlignment( QWidget::AlignCenter ); |
1906 | lblWait->show(); | 1907 | lblWait->show(); |
1907 | lblWait->showMaximized(); | 1908 | lblWait->showMaximized(); |
1908 | } | 1909 | } |
1909 | { QCopEnvelope envelope( "QPE/System", "forceQuit()" ); | 1910 | { QCopEnvelope envelope( "QPE/System", "forceQuit()" ); |
1910 | } | 1911 | } |
1911 | processEvents(); // ensure the message goes out. | 1912 | processEvents(); // ensure the message goes out. |
1912 | } | 1913 | } |
1913 | 1914 | ||
1914 | /*! | 1915 | /*! |
1915 | \internal | 1916 | \internal |
1916 | */ | 1917 | */ |
1917 | void QPEApplication::shutdown() | 1918 | void QPEApplication::shutdown() |
1918 | { | 1919 | { |
1919 | // Implement in server's QPEApplication subclass | 1920 | // Implement in server's QPEApplication subclass |
1920 | } | 1921 | } |
1921 | 1922 | ||
1922 | /*! | 1923 | /*! |
1923 | \internal | 1924 | \internal |
1924 | */ | 1925 | */ |
1925 | void QPEApplication::restart() | 1926 | void QPEApplication::restart() |
1926 | { | 1927 | { |
1927 | // Implement in server's QPEApplication subclass | 1928 | // Implement in server's QPEApplication subclass |
1928 | } | 1929 | } |
1929 | 1930 | ||
1930 | static QPtrDict<void>* stylusDict = 0; | 1931 | static QPtrDict<void>* stylusDict = 0; |
1931 | static void createDict() | 1932 | static void createDict() |
1932 | { | 1933 | { |
1933 | if ( !stylusDict ) | 1934 | if ( !stylusDict ) |
1934 | stylusDict = new QPtrDict<void>; | 1935 | stylusDict = new QPtrDict<void>; |
1935 | } | 1936 | } |
1936 | 1937 | ||
1937 | /*! | 1938 | /*! |
1938 | Returns the current StylusMode for widget \a w. | 1939 | Returns the current StylusMode for widget \a w. |
1939 | 1940 | ||
1940 | \sa setStylusOperation() StylusMode | 1941 | \sa setStylusOperation() StylusMode |
1941 | */ | 1942 | */ |
1942 | QPEApplication::StylusMode QPEApplication::stylusOperation( QWidget* w ) | 1943 | QPEApplication::StylusMode QPEApplication::stylusOperation( QWidget* w ) |
1943 | { | 1944 | { |
1944 | if ( stylusDict ) | 1945 | if ( stylusDict ) |
1945 | return ( StylusMode ) ( int ) stylusDict->find( w ); | 1946 | return ( StylusMode ) ( int ) stylusDict->find( w ); |
1946 | return LeftOnly; | 1947 | return LeftOnly; |
1947 | } | 1948 | } |
1948 | 1949 | ||
1949 | /*! | 1950 | /*! |
1950 | \enum QPEApplication::StylusMode | 1951 | \enum QPEApplication::StylusMode |
1951 | 1952 | ||
1952 | \value LeftOnly the stylus only generates LeftButton | 1953 | \value LeftOnly the stylus only generates LeftButton |
1953 | events (the default). | 1954 | events (the default). |
1954 | \value RightOnHold the stylus generates RightButton events | 1955 | \value RightOnHold the stylus generates RightButton events |
1955 | if the user uses the press-and-hold gesture. | 1956 | if the user uses the press-and-hold gesture. |
1956 | 1957 | ||
1957 | \sa setStylusOperation() stylusOperation() | 1958 | \sa setStylusOperation() stylusOperation() |
1958 | */ | 1959 | */ |
1959 | 1960 | ||
1960 | /*! | 1961 | /*! |
1961 | Causes widget \a w to receive mouse events according to the stylus | 1962 | Causes widget \a w to receive mouse events according to the stylus |
1962 | \a mode. | 1963 | \a mode. |
1963 | 1964 | ||
1964 | \sa stylusOperation() StylusMode | 1965 | \sa stylusOperation() StylusMode |
1965 | */ | 1966 | */ |
1966 | void QPEApplication::setStylusOperation( QWidget * w, StylusMode mode ) | 1967 | void QPEApplication::setStylusOperation( QWidget * w, StylusMode mode ) |
1967 | { | 1968 | { |
1968 | createDict(); | 1969 | createDict(); |
1969 | if ( mode == LeftOnly ) { | 1970 | if ( mode == LeftOnly ) { |
1970 | stylusDict->remove | 1971 | stylusDict->remove |
1971 | ( w ); | 1972 | ( w ); |
1972 | w->removeEventFilter( qApp ); | 1973 | w->removeEventFilter( qApp ); |
1973 | } | 1974 | } |
1974 | else { | 1975 | else { |
1975 | stylusDict->insert( w, ( void* ) mode ); | 1976 | stylusDict->insert( w, ( void* ) mode ); |
1976 | connect( w, SIGNAL( destroyed() ), qApp, SLOT( removeSenderFromStylusDict() ) ); | 1977 | connect( w, SIGNAL( destroyed() ), qApp, SLOT( removeSenderFromStylusDict() ) ); |
1977 | w->installEventFilter( qApp ); | 1978 | w->installEventFilter( qApp ); |
1978 | } | 1979 | } |
1979 | } | 1980 | } |
1980 | 1981 | ||
1981 | 1982 | ||
1982 | /*! | 1983 | /*! |
1983 | \reimp | 1984 | \reimp |
1984 | */ | 1985 | */ |
1985 | bool QPEApplication::eventFilter( QObject *o, QEvent *e ) | 1986 | bool QPEApplication::eventFilter( QObject *o, QEvent *e ) |
1986 | { | 1987 | { |
1987 | if ( !o->isWidgetType() ) | 1988 | if ( !o->isWidgetType() ) |
1988 | return FALSE; | 1989 | return FALSE; |
1989 | 1990 | ||
1990 | if ( stylusDict && e->type() >= QEvent::MouseButtonPress && e->type() <= QEvent::MouseMove ) { | 1991 | if ( stylusDict && e->type() >= QEvent::MouseButtonPress && e->type() <= QEvent::MouseMove ) { |
1991 | QMouseEvent * me = ( QMouseEvent* ) e; | 1992 | QMouseEvent * me = ( QMouseEvent* ) e; |
1992 | StylusMode mode = (StylusMode)(int)stylusDict->find(o); | 1993 | StylusMode mode = (StylusMode)(int)stylusDict->find(o); |
1993 | switch (mode) { | 1994 | switch (mode) { |
1994 | case RightOnHold: | 1995 | case RightOnHold: |
1995 | switch ( me->type() ) { | 1996 | switch ( me->type() ) { |
1996 | case QEvent::MouseButtonPress: | 1997 | case QEvent::MouseButtonPress: |
1997 | if ( me->button() == LeftButton ) { | 1998 | if ( me->button() == LeftButton ) { |
1998 | static long Pref = 500; // #### pref. | 1999 | static long Pref = 500; // #### pref. |
1999 | d->presswidget = (QWidget*)o; | 2000 | d->presswidget = (QWidget*)o; |
2000 | d->presspos = me->pos(); | 2001 | d->presspos = me->pos(); |
2001 | d->rightpressed = FALSE; | 2002 | d->rightpressed = FALSE; |
2002 | #ifdef OPIE_WITHROHFEEDBACK | 2003 | #ifdef OPIE_WITHROHFEEDBACK |
2003 | if( ! d->RoH ) | 2004 | if( ! d->RoH ) |
2004 | d->RoH = new Opie::Internal::RoHFeedback; | 2005 | d->RoH = new Opie::Internal::RoHFeedback; |
2005 | 2006 | ||
2006 | d->RoH->init( me->globalPos(), d->presswidget ); | 2007 | d->RoH->init( me->globalPos(), d->presswidget ); |
2007 | Pref = d->RoH->delay(); | 2008 | Pref = d->RoH->delay(); |
2008 | 2009 | ||
2009 | #endif | 2010 | #endif |
2010 | if (!d->presstimer ) | 2011 | if (!d->presstimer ) |
2011 | d->presstimer = startTimer( Pref ); // #### pref. | 2012 | d->presstimer = startTimer( Pref ); // #### pref. |
2012 | 2013 | ||
2013 | } | 2014 | } |
2014 | break; | 2015 | break; |
2015 | case QEvent::MouseMove: | 2016 | case QEvent::MouseMove: |
2016 | if (d->presstimer && (me->pos() - d->presspos).manhattanLength() > 8) { | 2017 | if (d->presstimer && (me->pos() - d->presspos).manhattanLength() > 8) { |
2017 | killTimer(d->presstimer); | 2018 | killTimer(d->presstimer); |
2018 | #ifdef OPIE_WITHROHFEEDBACK | 2019 | #ifdef OPIE_WITHROHFEEDBACK |
2019 | d->RoH->stop(); | 2020 | d->RoH->stop(); |
2020 | #endif | 2021 | #endif |
2021 | d->presstimer = 0; | 2022 | d->presstimer = 0; |
2022 | } | 2023 | } |
2023 | break; | 2024 | break; |
2024 | case QEvent::MouseButtonRelease: | 2025 | case QEvent::MouseButtonRelease: |
2025 | if ( me->button() == LeftButton ) { | 2026 | if ( me->button() == LeftButton ) { |
2026 | if ( d->presstimer ) { | 2027 | if ( d->presstimer ) { |
2027 | killTimer(d->presstimer); | 2028 | killTimer(d->presstimer); |
2028 | #ifdef OPIE_WITHROHFEEDBACK | 2029 | #ifdef OPIE_WITHROHFEEDBACK |
2029 | d->RoH->stop( ); | 2030 | d->RoH->stop( ); |
2030 | #endif | 2031 | #endif |
2031 | d->presstimer = 0; | 2032 | d->presstimer = 0; |
2032 | } | 2033 | } |
2033 | if ( d->rightpressed && d->presswidget ) { | 2034 | if ( d->rightpressed && d->presswidget ) { |
2034 | printf( "Send ButtonRelease\n" ); | 2035 | printf( "Send ButtonRelease\n" ); |
2035 | // Right released | 2036 | // Right released |
2036 | postEvent( d->presswidget, | 2037 | postEvent( d->presswidget, |
2037 | new QMouseEvent( QEvent::MouseButtonRelease, me->pos(), | 2038 | new QMouseEvent( QEvent::MouseButtonRelease, me->pos(), |
2038 | RightButton, LeftButton + RightButton ) ); | 2039 | RightButton, LeftButton + RightButton ) ); |
2039 | // Left released, off-widget | 2040 | // Left released, off-widget |
2040 | postEvent( d->presswidget, | 2041 | postEvent( d->presswidget, |
2041 | new QMouseEvent( QEvent::MouseMove, QPoint( -1, -1), | 2042 | new QMouseEvent( QEvent::MouseMove, QPoint( -1, -1), |
2042 | LeftButton, LeftButton ) ); | 2043 | LeftButton, LeftButton ) ); |
2043 | postEvent( d->presswidget, | 2044 | postEvent( d->presswidget, |
2044 | new QMouseEvent( QEvent::MouseButtonRelease, QPoint( -1, -1), | 2045 | new QMouseEvent( QEvent::MouseButtonRelease, QPoint( -1, -1), |
2045 | LeftButton, LeftButton ) ); | 2046 | LeftButton, LeftButton ) ); |
2046 | d->rightpressed = FALSE; | 2047 | d->rightpressed = FALSE; |
2047 | return TRUE; // don't send the real Left release | 2048 | return TRUE; // don't send the real Left release |
2048 | } | 2049 | } |
2049 | } | 2050 | } |
2050 | break; | 2051 | break; |
2051 | default: | 2052 | default: |
2052 | break; | 2053 | break; |
2053 | } | 2054 | } |
2054 | break; | 2055 | break; |
2055 | default: | 2056 | default: |
2056 | ; | 2057 | ; |
2057 | } | 2058 | } |
2058 | } | 2059 | } |
2059 | else if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) { | 2060 | else if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) { |
2060 | QKeyEvent *ke = (QKeyEvent *)e; | 2061 | QKeyEvent *ke = (QKeyEvent *)e; |
2061 | if ( ke->key() == Key_Enter ) { | 2062 | if ( ke->key() == Key_Enter ) { |
2062 | if ( o->isA( "QRadioButton" ) || o->isA( "QCheckBox" ) ) { | 2063 | if ( o->isA( "QRadioButton" ) || o->isA( "QCheckBox" ) ) { |
2063 | postEvent( o, new QKeyEvent( e->type(), Key_Space, ' ', | 2064 | postEvent( o, new QKeyEvent( e->type(), Key_Space, ' ', |
2064 | ke->state(), " ", ke->isAutoRepeat(), ke->count() ) ); | 2065 | ke->state(), " ", ke->isAutoRepeat(), ke->count() ) ); |
2065 | return TRUE; | 2066 | return TRUE; |
2066 | } | 2067 | } |
2067 | } | 2068 | } |
2068 | } | 2069 | } |
2069 | return FALSE; | 2070 | return FALSE; |
2070 | } | 2071 | } |
2071 | 2072 | ||
2072 | /*! | 2073 | /*! |
2073 | \reimp | 2074 | \reimp |
2074 | */ | 2075 | */ |
2075 | void QPEApplication::timerEvent( QTimerEvent *e ) | 2076 | void QPEApplication::timerEvent( QTimerEvent *e ) |
2076 | { | 2077 | { |
2077 | if ( e->timerId() == d->presstimer && d->presswidget ) { | 2078 | if ( e->timerId() == d->presstimer && d->presswidget ) { |
2078 | 2079 | ||
2079 | // Right pressed | 2080 | // Right pressed |
2080 | postEvent( d->presswidget, | 2081 | postEvent( d->presswidget, |
2081 | new QMouseEvent( QEvent::MouseButtonPress, d->presspos, | 2082 | new QMouseEvent( QEvent::MouseButtonPress, d->presspos, |
2082 | RightButton, LeftButton ) ); | 2083 | RightButton, LeftButton ) ); |
2083 | killTimer( d->presstimer ); | 2084 | killTimer( d->presstimer ); |
2084 | d->presstimer = 0; | 2085 | d->presstimer = 0; |
2085 | d->rightpressed = TRUE; | 2086 | d->rightpressed = TRUE; |
2086 | #ifdef OPIE_WITHROHFEEDBACK | 2087 | #ifdef OPIE_WITHROHFEEDBACK |
2087 | d->RoH->stop(); | 2088 | d->RoH->stop(); |
2088 | #endif | 2089 | #endif |
2089 | } | 2090 | } |
2090 | } | 2091 | } |
2091 | 2092 | ||
2092 | void QPEApplication::removeSenderFromStylusDict() | 2093 | void QPEApplication::removeSenderFromStylusDict() |
2093 | { | 2094 | { |
2094 | stylusDict->remove | 2095 | stylusDict->remove |
2095 | ( ( void* ) sender() ); | 2096 | ( ( void* ) sender() ); |
2096 | if ( d->presswidget == sender() ) | 2097 | if ( d->presswidget == sender() ) |
2097 | d->presswidget = 0; | 2098 | d->presswidget = 0; |
2098 | } | 2099 | } |
2099 | 2100 | ||
2100 | /*! | 2101 | /*! |
2101 | \internal | 2102 | \internal |
2102 | */ | 2103 | */ |
2103 | bool QPEApplication::keyboardGrabbed() const | 2104 | bool QPEApplication::keyboardGrabbed() const |
2104 | { | 2105 | { |
2105 | return d->kbgrabbed; | 2106 | return d->kbgrabbed; |
2106 | } | 2107 | } |
2107 | 2108 | ||
2108 | 2109 | ||
2109 | /*! | 2110 | /*! |
2110 | Reverses the effect of grabKeyboard(). This is called automatically | 2111 | Reverses the effect of grabKeyboard(). This is called automatically |
2111 | on program exit. | 2112 | on program exit. |
2112 | */ | 2113 | */ |
2113 | void QPEApplication::ungrabKeyboard() | 2114 | void QPEApplication::ungrabKeyboard() |
2114 | { | 2115 | { |
2115 | ((QPEApplication *) qApp )-> d-> kbgrabbed = false; | 2116 | ((QPEApplication *) qApp )-> d-> kbgrabbed = false; |
2116 | } | 2117 | } |
2117 | 2118 | ||
2118 | /*! | 2119 | /*! |
2119 | Grabs the physical keyboard keys, e.g. the application's launching | 2120 | Grabs the physical keyboard keys, e.g. the application's launching |
2120 | keys. Instead of launching applications when these keys are pressed | 2121 | keys. Instead of launching applications when these keys are pressed |
2121 | the signals emitted are sent to this application instead. Some games | 2122 | the signals emitted are sent to this application instead. Some games |
2122 | programs take over the launch keys in this way to make interaction | 2123 | programs take over the launch keys in this way to make interaction |
2123 | easier. | 2124 | easier. |
2124 | 2125 | ||
2125 | \sa ungrabKeyboard() | 2126 | \sa ungrabKeyboard() |
2126 | */ | 2127 | */ |
2127 | void QPEApplication::grabKeyboard() | 2128 | void QPEApplication::grabKeyboard() |
2128 | { | 2129 | { |
2129 | ((QPEApplication *) qApp )-> d-> kbgrabbed = true; | 2130 | ((QPEApplication *) qApp )-> d-> kbgrabbed = true; |
2130 | } | 2131 | } |
2131 | 2132 | ||
2132 | /*! | 2133 | /*! |
2133 | \reimp | 2134 | \reimp |
2134 | */ | 2135 | */ |
2135 | int QPEApplication::exec() | 2136 | int QPEApplication::exec() |
2136 | { | 2137 | { |
2137 | d->qcopQok = true; | 2138 | d->qcopQok = true; |
2138 | #ifndef QT_NO_COP | 2139 | #ifndef QT_NO_COP |
2139 | d->sendQCopQ(); | 2140 | d->sendQCopQ(); |
2140 | if ( !d->keep_running ) | 2141 | if ( !d->keep_running ) |
2141 | processEvents(); // we may have received QCop messages in the meantime. | 2142 | processEvents(); // we may have received QCop messages in the meantime. |
2142 | #endif | 2143 | #endif |
2143 | 2144 | ||
2144 | if ( d->keep_running ) | 2145 | if ( d->keep_running ) |
2145 | //|| d->qpe_main_widget && d->qpe_main_widget->isVisible() ) | 2146 | //|| d->qpe_main_widget && d->qpe_main_widget->isVisible() ) |
2146 | return QApplication::exec(); | 2147 | return QApplication::exec(); |
2147 | 2148 | ||
2148 | #ifndef QT_NO_COP | 2149 | #ifndef QT_NO_COP |
2149 | 2150 | ||
2150 | { | 2151 | { |
2151 | QCopEnvelope e( "QPE/System", "closing(QString)" ); | 2152 | QCopEnvelope e( "QPE/System", "closing(QString)" ); |
2152 | e << d->appName; | 2153 | e << d->appName; |
2153 | } | 2154 | } |
2154 | #endif | 2155 | #endif |
2155 | processEvents(); | 2156 | processEvents(); |
2156 | return 0; | 2157 | return 0; |
2157 | } | 2158 | } |
2158 | 2159 | ||
2159 | /*! | 2160 | /*! |
2160 | \internal | 2161 | \internal |
2161 | External request for application to quit. Quits if possible without | 2162 | External request for application to quit. Quits if possible without |
2162 | loosing state. | 2163 | loosing state. |
2163 | */ | 2164 | */ |
2164 | void QPEApplication::tryQuit() | 2165 | void QPEApplication::tryQuit() |
2165 | { | 2166 | { |
2166 | if ( activeModalWidget() ) | 2167 | if ( activeModalWidget() ) |
2167 | return ; // Inside modal loop or konsole. Too hard to save state. | 2168 | return ; // Inside modal loop or konsole. Too hard to save state. |
2168 | #ifndef QT_NO_COP | 2169 | #ifndef QT_NO_COP |
2169 | 2170 | ||
2170 | { | 2171 | { |
2171 | QCopEnvelope e( "QPE/System", "closing(QString)" ); | 2172 | QCopEnvelope e( "QPE/System", "closing(QString)" ); |
2172 | e << d->appName; | 2173 | e << d->appName; |
2173 | } | 2174 | } |
2174 | #endif | 2175 | #endif |
2175 | if ( d->keep_running ) | 2176 | if ( d->keep_running ) |
2176 | d->store_widget_rect(d->qpe_main_widget, d->appName); | 2177 | d->store_widget_rect(d->qpe_main_widget, d->appName); |
2177 | processEvents(); | 2178 | processEvents(); |
2178 | 2179 | ||
2179 | quit(); | 2180 | quit(); |
2180 | } | 2181 | } |
2181 | 2182 | ||
2182 | 2183 | ||
2183 | /*! | 2184 | /*! |
2184 | \internal | 2185 | \internal |
2185 | User initiated quit. Makes the window 'Go Away'. If preloaded this means | 2186 | User initiated quit. Makes the window 'Go Away'. If preloaded this means |
2186 | hiding the window. If not it means quitting the application. | 2187 | hiding the window. If not it means quitting the application. |
2187 | As this is user initiated we don't need to check state. | 2188 | As this is user initiated we don't need to check state. |
2188 | */ | 2189 | */ |
2189 | void QPEApplication::hideOrQuit() | 2190 | void QPEApplication::hideOrQuit() |
2190 | { | 2191 | { |
2191 | if ( d->keep_running ) | 2192 | if ( d->keep_running ) |
2192 | d->store_widget_rect(d->qpe_main_widget, d->appName); | 2193 | d->store_widget_rect(d->qpe_main_widget, d->appName); |
2193 | processEvents(); | 2194 | processEvents(); |
2194 | 2195 | ||
2195 | // If we are a preloaded application we don't actually quit, so emit | 2196 | // If we are a preloaded application we don't actually quit, so emit |
2196 | // a System message indicating we're quasi-closing. | 2197 | // a System message indicating we're quasi-closing. |
2197 | if ( d->preloaded && d->qpe_main_widget ) | 2198 | if ( d->preloaded && d->qpe_main_widget ) |
2198 | #ifndef QT_NO_COP | 2199 | #ifndef QT_NO_COP |
2199 | 2200 | ||
2200 | { | 2201 | { |
2201 | QCopEnvelope e("QPE/System", "fastAppHiding(QString)" ); | 2202 | QCopEnvelope e("QPE/System", "fastAppHiding(QString)" ); |
2202 | e << d->appName; | 2203 | e << d->appName; |
2203 | d->qpe_main_widget->hide(); | 2204 | d->qpe_main_widget->hide(); |
2204 | } | 2205 | } |
2205 | #endif | 2206 | #endif |
2206 | else | 2207 | else |
2207 | quit(); | 2208 | quit(); |
2208 | } | 2209 | } |
2209 | 2210 | ||
2211 | bool QPEApplication::isSaveWindowsPos() | ||
2212 | { | ||
2213 | return saveWindowsPos; | ||
2214 | } | ||
2215 | |||
2210 | #if (__GNUC__ > 2 ) && !defined(_OS_MACX_) | 2216 | #if (__GNUC__ > 2 ) && !defined(_OS_MACX_) |
2211 | extern "C" void __cxa_pure_virtual(); | 2217 | extern "C" void __cxa_pure_virtual(); |
2212 | 2218 | ||
2213 | void __cxa_pure_virtual() | 2219 | void __cxa_pure_virtual() |
2214 | { | 2220 | { |
2215 | fprintf( stderr, "Pure virtual called\n"); | 2221 | fprintf( stderr, "Pure virtual called\n"); |
2216 | abort(); | 2222 | abort(); |
2217 | 2223 | ||
2218 | } | 2224 | } |
2219 | 2225 | ||
2220 | #endif | 2226 | #endif |
2221 | 2227 | ||
2222 | 2228 | ||
2223 | #if defined(OPIE_NEW_MALLOC) | 2229 | #if defined(OPIE_NEW_MALLOC) |
2224 | 2230 | ||
2225 | // The libraries with the skiff package (and possibly others) have | 2231 | // The libraries with the skiff package (and possibly others) have |
2226 | // completely useless implementations of builtin new and delete that | 2232 | // completely useless implementations of builtin new and delete that |
2227 | // use about 50% of your CPU. Here we revert to the simple libc | 2233 | // use about 50% of your CPU. Here we revert to the simple libc |
2228 | // functions. | 2234 | // functions. |
2229 | 2235 | ||
2230 | void* operator new[]( size_t size ) | 2236 | void* operator new[]( size_t size ) |
2231 | { | 2237 | { |
2232 | return malloc( size ); | 2238 | return malloc( size ); |
2233 | } | 2239 | } |
2234 | 2240 | ||
2235 | void* operator new( size_t size ) | 2241 | void* operator new( size_t size ) |
2236 | { | 2242 | { |
2237 | return malloc( size ); | 2243 | return malloc( size ); |
2238 | } | 2244 | } |
2239 | 2245 | ||
2240 | void operator delete[]( void* p ) | 2246 | void operator delete[]( void* p ) |
2241 | { | 2247 | { |
2242 | if ( p ) | 2248 | if ( p ) |
2243 | free( p ); | 2249 | free( p ); |
2244 | } | 2250 | } |
2245 | 2251 | ||
2246 | void operator delete[]( void* p, size_t /*size*/ ) | 2252 | void operator delete[]( void* p, size_t /*size*/ ) |
2247 | { | 2253 | { |
2248 | if ( p ) | 2254 | if ( p ) |
2249 | free( p ); | 2255 | free( p ); |
2250 | } | 2256 | } |
2251 | 2257 | ||
2252 | 2258 | ||
2253 | void operator delete( void* p ) | 2259 | void operator delete( void* p ) |
2254 | { | 2260 | { |
2255 | if ( p ) | 2261 | if ( p ) |
2256 | free( p ); | 2262 | free( p ); |
2257 | } | 2263 | } |
2258 | 2264 | ||
2259 | void operator delete( void* p, size_t /*size*/ ) | 2265 | void operator delete( void* p, size_t /*size*/ ) |
2260 | { | 2266 | { |
2261 | if ( p ) | 2267 | if ( p ) |
2262 | free( p ); | 2268 | free( p ); |
2263 | } | 2269 | } |
2264 | 2270 | ||
2265 | #endif | 2271 | #endif |
2266 | 2272 | ||
2267 | #if ( QT_VERSION <= 230 ) && !defined(SINGLE_APP) | 2273 | #if ( QT_VERSION <= 230 ) && !defined(SINGLE_APP) |
2268 | #include <qwidgetlist.h> | 2274 | #include <qwidgetlist.h> |
2269 | #ifdef QWS | 2275 | #ifdef QWS |
2270 | #include <qgfx_qws.h> | 2276 | #include <qgfx_qws.h> |
2271 | extern QRect qt_maxWindowRect; | 2277 | extern QRect qt_maxWindowRect; |
2272 | void qt_setMaxWindowRect(const QRect& r ) | 2278 | void qt_setMaxWindowRect(const QRect& r ) |
2273 | { | 2279 | { |
2274 | qt_maxWindowRect = qt_screen->mapFromDevice( r, | 2280 | qt_maxWindowRect = qt_screen->mapFromDevice( r, |
2275 | qt_screen->mapToDevice( QSize( qt_screen->width(), qt_screen->height() ) ) ); | 2281 | qt_screen->mapToDevice( QSize( qt_screen->width(), qt_screen->height() ) ) ); |
2276 | // Re-resize any maximized windows | 2282 | // Re-resize any maximized windows |
2277 | QWidgetList* l = QApplication::topLevelWidgets(); | 2283 | QWidgetList* l = QApplication::topLevelWidgets(); |
2278 | if ( l ) { | 2284 | if ( l ) { |
2279 | QWidget * w = l->first(); | 2285 | QWidget * w = l->first(); |
2280 | while ( w ) { | 2286 | while ( w ) { |
2281 | if ( w->isVisible() && w->isMaximized() ) { | 2287 | if ( w->isVisible() && w->isMaximized() ) { |
2282 | w->showMaximized(); | 2288 | w->showMaximized(); |
2283 | } | 2289 | } |
2284 | w = l->next(); | 2290 | w = l->next(); |
2285 | } | 2291 | } |
2286 | delete l; | 2292 | delete l; |
2287 | } | 2293 | } |
2288 | } | 2294 | } |
2289 | #endif | 2295 | #endif |
2290 | #endif | 2296 | #endif |