author | llornkcor <llornkcor> | 2004-04-25 07:56:02 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2004-04-25 07:56:02 (UTC) |
commit | 73f0c227fc94bc4dea12e4eb2384bdff2e9561eb (patch) (unidiff) | |
tree | c33525271239fbf69e5daf9223beaa5dd28e0bb6 /library | |
parent | cf9cab31dc8a46d3a2d74931b2a428ca87eed0a9 (diff) | |
download | opie-73f0c227fc94bc4dea12e4eb2384bdff2e9561eb.zip opie-73f0c227fc94bc4dea12e4eb2384bdff2e9561eb.tar.gz opie-73f0c227fc94bc4dea12e4eb2384bdff2e9561eb.tar.bz2 |
fix nonmaximized apps, and make the state and position persistent. ported from Qtopia 1.7 :)
-rw-r--r-- | library/qpeapplication.cpp | 271 |
1 files changed, 240 insertions, 31 deletions
diff --git a/library/qpeapplication.cpp b/library/qpeapplication.cpp index 755fb19..90cd5f1 100644 --- a/library/qpeapplication.cpp +++ b/library/qpeapplication.cpp | |||
@@ -51,230 +51,435 @@ | |||
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 | class HackWidget : public QWidget | ||
100 | { | ||
101 | public: | ||
102 | bool needsOk() | ||
103 | { return (getWState() & WState_Reserved1 ); } | ||
104 | |||
105 | QRect normalGeometry() | ||
106 | { return topData()->normalGeometry; }; | ||
107 | }; | ||
99 | 108 | ||
100 | class QPEApplicationData | 109 | class QPEApplicationData |
101 | { | 110 | { |
102 | public: | 111 | public: |
103 | QPEApplicationData ( ) | 112 | QPEApplicationData ( ) |
104 | : presstimer( 0 ), presswidget( 0 ), rightpressed( false ), kbgrabbed( false ), | 113 | : presstimer( 0 ), presswidget( 0 ), rightpressed( false ), kbgrabbed( false ), |
105 | notbusysent( false ), preloaded( false ), forceshow( false ), nomaximize( false ), | 114 | notbusysent( false ), preloaded( false ), forceshow( false ), nomaximize( false ), |
106 | keep_running( true ), qcopQok( false ), qpe_main_widget( 0 ) | 115 | keep_running( true ), qcopQok( false ), qpe_main_widget( 0 ) |
107 | 116 | ||
108 | {} | 117 | {} |
109 | 118 | ||
110 | int presstimer; | 119 | int presstimer; |
111 | QWidget* presswidget; | 120 | QWidget* presswidget; |
112 | QPoint presspos; | 121 | QPoint presspos; |
113 | 122 | ||
114 | bool rightpressed : 1; | 123 | bool rightpressed : 1; |
115 | bool kbgrabbed : 1; | 124 | bool kbgrabbed : 1; |
116 | bool notbusysent : 1; | 125 | bool notbusysent : 1; |
117 | bool preloaded : 1; | 126 | bool preloaded : 1; |
118 | bool forceshow : 1; | 127 | bool forceshow : 1; |
119 | bool nomaximize : 1; | 128 | bool nomaximize : 1; |
120 | bool keep_running : 1; | 129 | bool keep_running : 1; |
121 | bool qcopQok : 1; | 130 | bool qcopQok : 1; |
122 | 131 | ||
123 | 132 | ||
124 | QStringList langs; | 133 | QStringList langs; |
125 | QString appName; | 134 | QString appName; |
126 | struct QCopRec | 135 | struct QCopRec |
127 | { | 136 | { |
128 | QCopRec( const QCString &ch, const QCString &msg, | 137 | QCopRec( const QCString &ch, const QCString &msg, |
129 | const QByteArray &d ) : | 138 | const QByteArray &d ) : |
130 | channel( ch ), message( msg ), data( d ) | 139 | channel( ch ), message( msg ), data( d ) |
131 | { } | 140 | { } |
132 | 141 | ||
133 | QCString channel; | 142 | QCString channel; |
134 | QCString message; | 143 | QCString message; |
135 | QByteArray data; | 144 | QByteArray data; |
136 | }; | 145 | }; |
137 | QWidget* qpe_main_widget; | 146 | QWidget* qpe_main_widget; |
138 | QGuardedPtr<QWidget> lastraised; | 147 | QGuardedPtr<QWidget> lastraised; |
139 | QQueue<QCopRec> qcopq; | 148 | QQueue<QCopRec> qcopq; |
140 | QString styleName; | 149 | QString styleName; |
141 | QString decorationName; | 150 | QString decorationName; |
142 | 151 | ||
143 | void enqueueQCop( const QCString &ch, const QCString &msg, | 152 | void enqueueQCop( const QCString &ch, const QCString &msg, |
144 | const QByteArray &data ) | 153 | const QByteArray &data ) |
145 | { | 154 | { |
146 | qcopq.enqueue( new QCopRec( ch, msg, data ) ); | 155 | qcopq.enqueue( new QCopRec( ch, msg, data ) ); |
147 | } | 156 | } |
148 | void sendQCopQ() | 157 | void sendQCopQ() |
149 | { | 158 | { |
150 | if (!qcopQok ) | 159 | if (!qcopQok ) |
151 | return; | 160 | return; |
152 | 161 | ||
153 | QCopRec * r; | 162 | QCopRec * r; |
154 | 163 | ||
155 | while((r=qcopq.dequeue())) { | 164 | while((r=qcopq.dequeue())) { |
156 | // remove from queue before sending... | 165 | // remove from queue before sending... |
157 | // event loop can come around again before getting | 166 | // event loop can come around again before getting |
158 | // back from sendLocally | 167 | // back from sendLocally |
159 | #ifndef QT_NO_COP | 168 | #ifndef QT_NO_COP |
160 | QCopChannel::sendLocally( r->channel, r->message, r->data ); | 169 | QCopChannel::sendLocally( r->channel, r->message, r->data ); |
161 | #endif | 170 | #endif |
162 | 171 | ||
163 | delete r; | 172 | delete r; |
164 | } | 173 | } |
165 | } | 174 | } |
166 | static void show_mx(QWidget* mw, bool nomaximize, const QString & = QString::null ) | 175 | |
176 | static void show_mx(QWidget* mw, bool nomaximize, QString &strName/* = QString::null */) | ||
167 | { | 177 | { |
178 | if ( mw->isVisible() ) { | ||
179 | mw->raise(); | ||
180 | } else { | ||
181 | QPoint p; | ||
182 | QSize s; | ||
183 | |||
184 | if ( mw->layout() && mw->inherits("QDialog") ) { | ||
185 | bool max; | ||
186 | if ( read_widget_rect(strName, max, p, s) && validate_widget_size(mw, p, s) ) { | ||
187 | mw->resize(s); | ||
188 | mw->move(p); | ||
189 | |||
190 | if ( max && !nomaximize ) | ||
191 | mw->showMaximized(); | ||
192 | else | ||
193 | mw->show(); | ||
194 | } else { | ||
195 | qpe_show_dialog((QDialog*)mw,nomaximize); | ||
196 | } | ||
197 | } else { | ||
198 | bool max; | ||
199 | if ( read_widget_rect(strName, max, p, s) && validate_widget_size(mw, p, s) ) { | ||
200 | mw->resize(s); | ||
201 | mw->move(p); | ||
202 | } else { //no stored rectangle, make an estimation | ||
203 | int x = (qApp->desktop()->width()-mw->frameGeometry().width())/2; | ||
204 | int y = (qApp->desktop()->height()-mw->frameGeometry().height())/2; | ||
205 | mw->move( QMAX(x,0), QMAX(y,0) ); | ||
206 | #ifdef Q_WS_QWS | ||
207 | if ( !nomaximize ) | ||
208 | mw->showMaximized(); | ||
209 | #endif | ||
210 | } | ||
211 | if ( max && !nomaximize ) | ||
212 | mw->showMaximized(); | ||
213 | else | ||
214 | mw->show(); | ||
215 | } | ||
216 | } | ||
217 | } | ||
218 | // // ugly hack, remove that later after finding a sane solution | ||
219 | // // Addendum: Only Sharp currently has models with high resolution but (physically) small displays, | ||
220 | // // so this is only useful if QT_QWS_SIMPAD is NOT defined. E.g. SIMpad has 800x600 but has | ||
221 | // // a (physically) large enough display to use the small icons | ||
222 | // #if defined(OPIE_HIGH_RES_SMALL_PHY) | ||
223 | // if ( QPEApplication::desktop() ->width() >= 600 && ( mw->inherits("QMainWindow") || mw->isA("QMainWindow") ) ) { | ||
224 | // ( ( QMainWindow* ) mw )->setUsesBigPixmaps( true ); | ||
225 | // } | ||
226 | // #endif | ||
227 | |||
228 | // if ( mw->layout() && mw->inherits("QDialog") ) { | ||
229 | // QPEApplication::showDialog((QDialog*)mw, nomaximize); | ||
230 | // } | ||
231 | // else { | ||
232 | // #ifdef Q_WS_QWS | ||
233 | // if ( !nomaximize ) { | ||
234 | // qDebug("QDialog special case XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); | ||
235 | // mw->showMaximized(); | ||
236 | // //QPEApplication::showWidget( mw, !nomaximize ); | ||
237 | // }else | ||
238 | // #endif | ||
239 | // mw->show(); | ||
240 | // } | ||
241 | //} | ||
242 | |||
243 | |||
244 | static void qpe_show_dialog( QDialog* d, bool nomax ) | ||
245 | { | ||
246 | QSize sh = d->sizeHint(); | ||
247 | int w = QMAX(sh.width(),d->width()); | ||
248 | int h = QMAX(sh.height(),d->height()); | ||
168 | 249 | ||
169 | // ugly hack, remove that later after finding a sane solution | 250 | if ( d->parentWidget() && !d->parentWidget()->topLevelWidget()->isMaximized() ) |
170 | // Addendum: Only Sharp currently has models with high resolution but (physically) small displays, | 251 | nomax = TRUE; |
171 | // so this is only useful if QT_QWS_SIMPAD is NOT defined. E.g. SIMpad has 800x600 but has | 252 | |
172 | // a (physically) large enough display to use the small icons | 253 | #ifndef Q_WS_QWS |
173 | #if defined(OPIE_HIGH_RES_SMALL_PHY) | 254 | QSize s(qApp->desktop()->width(), qApp->desktop()->height() ); |
174 | if ( QPEApplication::desktop() ->width() >= 600 && ( mw->inherits("QMainWindow") || mw->isA("QMainWindow") ) ) { | 255 | #else |
175 | ( ( QMainWindow* ) mw )->setUsesBigPixmaps( true ); | 256 | QSize s(qt_maxWindowRect.width(), qt_maxWindowRect.height() ); |
176 | } | ||
177 | #endif | 257 | #endif |
178 | 258 | ||
179 | if ( mw->layout() && mw->inherits("QDialog") ) { | 259 | int maxX = s.width() - (d->frameGeometry().width() - d->geometry().width()); |
180 | QPEApplication::showDialog((QDialog*)mw, nomaximize); | 260 | int maxY = s.height() - (d->frameGeometry().height() - d->geometry().height()); |
181 | } | 261 | |
182 | else { | 262 | if ( (w >= maxX && h >= maxY) || ( (!nomax) && ( w > s.width()*3/4 || h > s.height()*3/4 ) ) ) { |
183 | #ifdef Q_WS_QWS | 263 | d->showMaximized(); |
184 | if ( !nomaximize ) | 264 | } else { |
185 | mw->showMaximized(); | 265 | // try centering the dialog around its parent |
186 | else | 266 | QPoint p(0,0); |
267 | if ( d->parentWidget() ) { | ||
268 | QPoint pp = d->parentWidget()->mapToGlobal( QPoint(0,0) ); | ||
269 | p = QPoint( pp.x() + d->parentWidget()->width()/2, | ||
270 | pp.y() + d->parentWidget()->height()/ 2 ); | ||
271 | } else { | ||
272 | p = QPoint( maxX/2, maxY/2 ); | ||
273 | } | ||
274 | |||
275 | p = QPoint( p.x() - w/2, p.y() - h/2 ); | ||
276 | //qDebug("p(x,y) is %d %d", p.x(), p.y() ); | ||
277 | |||
278 | if ( w >= maxX ) { | ||
279 | if ( p.y() < 0 ) | ||
280 | p.setY(0); | ||
281 | if ( p.y() + h > maxY ) | ||
282 | p.setY( maxY - h); | ||
283 | |||
284 | d->resize(maxX, h); | ||
285 | d->move(0, p.y() ); | ||
286 | } else if ( h >= maxY ) { | ||
287 | if ( p.x() < 0 ) | ||
288 | p.setX(0); | ||
289 | if ( p.x() + w > maxX ) | ||
290 | p.setX( maxX - w); | ||
291 | |||
292 | d->resize(w, maxY); | ||
293 | d->move(p.x(),0); | ||
294 | } else { | ||
295 | d->resize(w, h); | ||
296 | } | ||
297 | |||
298 | d->show(); | ||
299 | } | ||
300 | } | ||
301 | |||
302 | static bool read_widget_rect(const QString &app, bool &maximized, QPoint &p, QSize &s) | ||
303 | { | ||
304 | maximized = TRUE; | ||
305 | |||
306 | // 350 is the trigger in qwsdefaultdecoration for providing a resize button | ||
307 | if ( qApp->desktop()->width() <= 350 ) | ||
308 | return FALSE; | ||
309 | |||
310 | Config cfg( "qpe" ); | ||
311 | cfg.setGroup("ApplicationPositions"); | ||
312 | QString str = cfg.readEntry( app, QString::null ); | ||
313 | QStringList l = QStringList::split(",", str); | ||
314 | |||
315 | if ( l.count() == 5) { | ||
316 | p.setX( l[0].toInt() ); | ||
317 | p.setY( l[1].toInt() ); | ||
318 | |||
319 | s.setWidth( l[2].toInt() ); | ||
320 | s.setHeight( l[3].toInt() ); | ||
321 | |||
322 | maximized = l[4].toInt(); | ||
323 | |||
324 | return TRUE; | ||
325 | } | ||
326 | |||
327 | return FALSE; | ||
328 | } | ||
329 | |||
330 | |||
331 | static bool validate_widget_size(const QWidget *w, QPoint &p, QSize &s) | ||
332 | { | ||
333 | #ifndef Q_WS_QWS | ||
334 | QRect qt_maxWindowRect = qApp->desktop()->geometry(); | ||
187 | #endif | 335 | #endif |
336 | int maxX = qt_maxWindowRect.width(); | ||
337 | int maxY = qt_maxWindowRect.height(); | ||
338 | int wWidth = s.width() + ( w->frameGeometry().width() - w->geometry().width() ); | ||
339 | int wHeight = s.height() + ( w->frameGeometry().height() - w->geometry().height() ); | ||
188 | 340 | ||
189 | mw->show(); | 341 | // total window size is not allowed to be larger than desktop window size |
190 | } | 342 | if ( ( wWidth >= maxX ) && ( wHeight >= maxY ) ) |
343 | return FALSE; | ||
344 | |||
345 | if ( wWidth > maxX ) { | ||
346 | s.setWidth( maxX - (w->frameGeometry().width() - w->geometry().width() ) ); | ||
347 | wWidth = maxX; | ||
348 | } | ||
349 | |||
350 | if ( wHeight > maxY ) { | ||
351 | s.setHeight( maxY - (w->frameGeometry().height() - w->geometry().height() ) ); | ||
352 | wHeight = maxY; | ||
191 | } | 353 | } |
354 | |||
355 | // any smaller than this and the maximize/close/help buttons will be overlapping | ||
356 | if ( wWidth < 80 || wHeight < 60 ) | ||
357 | return FALSE; | ||
358 | |||
359 | if ( p.x() < 0 ) | ||
360 | p.setX(0); | ||
361 | if ( p.y() < 0 ) | ||
362 | p.setY(0); | ||
363 | |||
364 | if ( p.x() + wWidth > maxX ) | ||
365 | p.setX( maxX - wWidth ); | ||
366 | if ( p.y() + wHeight > maxY ) | ||
367 | p.setY( maxY - wHeight ); | ||
368 | |||
369 | return TRUE; | ||
370 | } | ||
371 | |||
372 | static void store_widget_rect(QWidget *w, QString &app) | ||
373 | { | ||
374 | // 350 is the trigger in qwsdefaultdecoration for providing a resize button | ||
375 | if ( qApp->desktop()->width() <= 350 ) | ||
376 | return; | ||
377 | |||
378 | // we use these to map the offset of geometry and pos. ( we can only use normalGeometry to | ||
379 | // get the non-maximized version, so we have to do it the hard way ) | ||
380 | int offsetX = w->x() - w->geometry().left(); | ||
381 | int offsetY = w->y() - w->geometry().top(); | ||
382 | |||
383 | QRect r; | ||
384 | if ( w->isMaximized() ) | ||
385 | r = ( (HackWidget *) w)->normalGeometry(); | ||
386 | else | ||
387 | r = w->geometry(); | ||
388 | |||
389 | // Stores the window placement as pos(), size() (due to the offset mapping) | ||
390 | Config cfg( "qpe" ); | ||
391 | cfg.setGroup("ApplicationPositions"); | ||
392 | QString s; | ||
393 | s.sprintf("%d,%d,%d,%d,%d", r.left() + offsetX, r.top() + offsetY, r.width(), r.height(), w->isMaximized() ); | ||
394 | cfg.writeEntry( app, s ); | ||
395 | } | ||
396 | |||
192 | static bool setWidgetCaptionFromAppName( QWidget* /*mw*/, const QString& /*appName*/, const QString& /*appsPath*/ ) | 397 | static bool setWidgetCaptionFromAppName( QWidget* /*mw*/, const QString& /*appName*/, const QString& /*appsPath*/ ) |
193 | { | 398 | { |
194 | /* | 399 | /* |
195 | // This works but disable it for now until it is safe to apply | 400 | // This works but disable it for now until it is safe to apply |
196 | // What is does is scan the .desktop files of all the apps for | 401 | // What is does is scan the .desktop files of all the apps for |
197 | // the applnk that has the corresponding argv[0] as this program | 402 | // the applnk that has the corresponding argv[0] as this program |
198 | // then it uses the name stored in the .desktop file as the caption | 403 | // then it uses the name stored in the .desktop file as the caption |
199 | // for the main widget. This saves duplicating translations for | 404 | // for the main widget. This saves duplicating translations for |
200 | // the app name in the program and in the .desktop files. | 405 | // the app name in the program and in the .desktop files. |
201 | 406 | ||
202 | AppLnkSet apps( appsPath ); | 407 | AppLnkSet apps( appsPath ); |
203 | 408 | ||
204 | QList<AppLnk> appsList = apps.children(); | 409 | QList<AppLnk> appsList = apps.children(); |
205 | for ( QListIterator<AppLnk> it(appsList); it.current(); ++it ) { | 410 | for ( QListIterator<AppLnk> it(appsList); it.current(); ++it ) { |
206 | if ( (*it)->exec() == appName ) { | 411 | if ( (*it)->exec() == appName ) { |
207 | mw->setCaption( (*it)->name() ); | 412 | mw->setCaption( (*it)->name() ); |
208 | return TRUE; | 413 | return TRUE; |
209 | } | 414 | } |
210 | } | 415 | } |
211 | */ | 416 | */ |
212 | return FALSE; | 417 | return FALSE; |
213 | } | 418 | } |
214 | 419 | ||
215 | 420 | ||
216 | void show(QWidget* mw, bool nomax) | 421 | void show(QWidget* mw, bool nomax) |
217 | { | 422 | { |
218 | setWidgetCaptionFromAppName( mw, appName, QPEApplication::qpeDir() + "apps" ); | 423 | setWidgetCaptionFromAppName( mw, appName, QPEApplication::qpeDir() + "apps" ); |
219 | nomaximize = nomax; | 424 | nomaximize = nomax; |
220 | qpe_main_widget = mw; | 425 | qpe_main_widget = mw; |
221 | qcopQok = TRUE; | 426 | qcopQok = TRUE; |
222 | #ifndef QT_NO_COP | 427 | #ifndef QT_NO_COP |
223 | 428 | ||
224 | sendQCopQ(); | 429 | sendQCopQ(); |
225 | #endif | 430 | #endif |
226 | 431 | ||
227 | if ( preloaded ) { | 432 | if ( preloaded ) { |
228 | if (forceshow) | 433 | if (forceshow) |
229 | show_mx(mw, nomax); | 434 | show_mx(mw, nomax, appName); |
230 | } | 435 | } |
231 | else if ( keep_running ) { | 436 | else if ( keep_running ) { |
232 | show_mx(mw, nomax); | 437 | show_mx(mw, nomax, appName); |
233 | } | 438 | } |
234 | } | 439 | } |
235 | 440 | ||
236 | void loadTextCodecs() | 441 | void loadTextCodecs() |
237 | { | 442 | { |
238 | QString path = QPEApplication::qpeDir() + "/plugins/textcodecs"; | 443 | QString path = QPEApplication::qpeDir() + "/plugins/textcodecs"; |
239 | #ifdef Q_OS_MACX | 444 | #ifdef Q_OS_MACX |
240 | QDir dir( path, "lib*.dylib" ); | 445 | QDir dir( path, "lib*.dylib" ); |
241 | #else | 446 | #else |
242 | QDir dir( path, "lib*.so" ); | 447 | QDir dir( path, "lib*.so" ); |
243 | #endif | 448 | #endif |
244 | QStringList list; | 449 | QStringList list; |
245 | if ( dir. exists ( )) | 450 | if ( dir. exists ( )) |
246 | list = dir.entryList(); | 451 | list = dir.entryList(); |
247 | QStringList::Iterator it; | 452 | QStringList::Iterator it; |
248 | for ( it = list.begin(); it != list.end(); ++it ) { | 453 | for ( it = list.begin(); it != list.end(); ++it ) { |
249 | TextCodecInterface *iface = 0; | 454 | TextCodecInterface *iface = 0; |
250 | QLibrary *lib = new QLibrary( path + "/" + *it ); | 455 | QLibrary *lib = new QLibrary( path + "/" + *it ); |
251 | if ( lib->queryInterface( IID_QtopiaTextCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) { | 456 | if ( lib->queryInterface( IID_QtopiaTextCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) { |
252 | QValueList<int> mibs = iface->mibEnums(); | 457 | QValueList<int> mibs = iface->mibEnums(); |
253 | for (QValueList<int>::ConstIterator i = mibs.begin(); i != mibs.end(); ++i) { | 458 | for (QValueList<int>::ConstIterator i = mibs.begin(); i != mibs.end(); ++i) { |
254 | (void)iface->createForMib(*i); | 459 | (void)iface->createForMib(*i); |
255 | // ### it exists now; need to remember if we can delete it | 460 | // ### it exists now; need to remember if we can delete it |
256 | } | 461 | } |
257 | } | 462 | } |
258 | else { | 463 | else { |
259 | lib->unload(); | 464 | lib->unload(); |
260 | delete lib; | 465 | delete lib; |
261 | } | 466 | } |
262 | } | 467 | } |
263 | } | 468 | } |
264 | 469 | ||
265 | void loadImageCodecs() | 470 | void loadImageCodecs() |
266 | { | 471 | { |
267 | QString path = QPEApplication::qpeDir() + "/plugins/imagecodecs"; | 472 | QString path = QPEApplication::qpeDir() + "/plugins/imagecodecs"; |
268 | #ifdef Q_OS_MACX | 473 | #ifdef Q_OS_MACX |
269 | QDir dir( path, "lib*.dylib" ); | 474 | QDir dir( path, "lib*.dylib" ); |
270 | #else | 475 | #else |
271 | QDir dir( path, "lib*.so" ); | 476 | QDir dir( path, "lib*.so" ); |
272 | #endif | 477 | #endif |
273 | QStringList list; | 478 | QStringList list; |
274 | if ( dir. exists ( )) | 479 | if ( dir. exists ( )) |
275 | list = dir.entryList(); | 480 | list = dir.entryList(); |
276 | QStringList::Iterator it; | 481 | QStringList::Iterator it; |
277 | for ( it = list.begin(); it != list.end(); ++it ) { | 482 | for ( it = list.begin(); it != list.end(); ++it ) { |
278 | ImageCodecInterface *iface = 0; | 483 | ImageCodecInterface *iface = 0; |
279 | QLibrary *lib = new QLibrary( path + "/" + *it ); | 484 | QLibrary *lib = new QLibrary( path + "/" + *it ); |
280 | if ( lib->queryInterface( IID_QtopiaImageCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) { | 485 | if ( lib->queryInterface( IID_QtopiaImageCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) { |
@@ -818,104 +1023,104 @@ QPEApplication::InputMethodHint QPEApplication::inputMethodHint( QWidget * w ) | |||
818 | as specified by \a mode. | 1023 | as specified by \a mode. |
819 | 1024 | ||
820 | \sa inputMethodHint() InputMethodHint | 1025 | \sa inputMethodHint() InputMethodHint |
821 | */ | 1026 | */ |
822 | void QPEApplication::setInputMethodHint( QWidget * w, InputMethodHint mode ) | 1027 | void QPEApplication::setInputMethodHint( QWidget * w, InputMethodHint mode ) |
823 | { | 1028 | { |
824 | createInputMethodDict(); | 1029 | createInputMethodDict(); |
825 | if ( mode == Normal ) { | 1030 | if ( mode == Normal ) { |
826 | inputMethodDict->remove | 1031 | inputMethodDict->remove |
827 | ( w ); | 1032 | ( w ); |
828 | } | 1033 | } |
829 | else { | 1034 | else { |
830 | inputMethodDict->insert( w, ( void* ) mode ); | 1035 | inputMethodDict->insert( w, ( void* ) mode ); |
831 | } | 1036 | } |
832 | } | 1037 | } |
833 | 1038 | ||
834 | class HackDialog : public QDialog | 1039 | class HackDialog : public QDialog |
835 | { | 1040 | { |
836 | public: | 1041 | public: |
837 | void acceptIt() | 1042 | void acceptIt() |
838 | { | 1043 | { |
839 | accept(); | 1044 | accept(); |
840 | } | 1045 | } |
841 | void rejectIt() | 1046 | void rejectIt() |
842 | { | 1047 | { |
843 | reject(); | 1048 | reject(); |
844 | } | 1049 | } |
845 | }; | 1050 | }; |
846 | 1051 | ||
847 | 1052 | ||
848 | void QPEApplication::mapToDefaultAction( QWSKeyEvent * ke, int key ) | 1053 | void QPEApplication::mapToDefaultAction( QWSKeyEvent * ke, int key ) |
849 | { | 1054 | { |
850 | // specialised actions for certain widgets. May want to | 1055 | // specialised actions for certain widgets. May want to |
851 | // add more stuff here. | 1056 | // add more stuff here. |
852 | if ( activePopupWidget() && activePopupWidget() ->inherits( "QListBox" ) | 1057 | if ( activePopupWidget() && activePopupWidget() ->inherits( "QListBox" ) |
853 | && activePopupWidget() ->parentWidget() | 1058 | && activePopupWidget() ->parentWidget() |
854 | && activePopupWidget() ->parentWidget() ->inherits( "QComboBox" ) ) | 1059 | && activePopupWidget() ->parentWidget() ->inherits( "QComboBox" ) ) |
855 | key = Qt::Key_Return; | 1060 | key = Qt::Key_Return; |
856 | 1061 | ||
857 | if ( activePopupWidget() && activePopupWidget() ->inherits( "QPopupMenu" ) ) | 1062 | if ( activePopupWidget() && activePopupWidget() ->inherits( "QPopupMenu" ) ) |
858 | key = Qt::Key_Return; | 1063 | key = Qt::Key_Return; |
859 | 1064 | ||
860 | #ifdef QWS | 1065 | #ifdef QWS |
861 | 1066 | ||
862 | ke->simpleData.keycode = key; | 1067 | ke->simpleData.keycode = key; |
863 | #endif | 1068 | #endif |
864 | } | 1069 | } |
865 | 1070 | ||
866 | class HackWidget : public QWidget | 1071 | // class HackWidget : public QWidget |
867 | { | 1072 | // { |
868 | public: | 1073 | // public: |
869 | bool needsOk() | 1074 | // bool needsOk() |
870 | { | 1075 | // { |
871 | return ( getWState() & WState_Reserved1 ); | 1076 | // return ( getWState() & WState_Reserved1 ); |
872 | } | 1077 | // } |
873 | }; | 1078 | // }; |
874 | 1079 | ||
875 | /*! | 1080 | /*! |
876 | \internal | 1081 | \internal |
877 | */ | 1082 | */ |
878 | 1083 | ||
879 | #ifdef QWS | 1084 | #ifdef QWS |
880 | bool QPEApplication::qwsEventFilter( QWSEvent * e ) | 1085 | bool QPEApplication::qwsEventFilter( QWSEvent * e ) |
881 | { | 1086 | { |
882 | if ( !d->notbusysent && e->type == QWSEvent::Focus ) { | 1087 | if ( !d->notbusysent && e->type == QWSEvent::Focus ) { |
883 | if ( qApp->type() != QApplication::GuiServer ) { | 1088 | if ( qApp->type() != QApplication::GuiServer ) { |
884 | QCopEnvelope e( "QPE/System", "notBusy(QString)" ); | 1089 | QCopEnvelope e( "QPE/System", "notBusy(QString)" ); |
885 | e << d->appName; | 1090 | e << d->appName; |
886 | } | 1091 | } |
887 | d->notbusysent = TRUE; | 1092 | d->notbusysent = TRUE; |
888 | } | 1093 | } |
889 | if ( type() == GuiServer ) { | 1094 | if ( type() == GuiServer ) { |
890 | switch ( e->type ) { | 1095 | switch ( e->type ) { |
891 | case QWSEvent::Mouse: | 1096 | case QWSEvent::Mouse: |
892 | if ( e->asMouse() ->simpleData.state && !QWidget::find( e->window() ) ) | 1097 | if ( e->asMouse() ->simpleData.state && !QWidget::find( e->window() ) ) |
893 | emit clientMoused(); | 1098 | emit clientMoused(); |
894 | break; | 1099 | break; |
895 | default: | 1100 | default: |
896 | break; | 1101 | break; |
897 | } | 1102 | } |
898 | } | 1103 | } |
899 | if ( e->type == QWSEvent::Key ) { | 1104 | if ( e->type == QWSEvent::Key ) { |
900 | QWSKeyEvent *ke = ( QWSKeyEvent * ) e; | 1105 | QWSKeyEvent *ke = ( QWSKeyEvent * ) e; |
901 | if ( ke->simpleData.keycode == Qt::Key_F33 ) { | 1106 | if ( ke->simpleData.keycode == Qt::Key_F33 ) { |
902 | // Use special "OK" key to press "OK" on top level widgets | 1107 | // Use special "OK" key to press "OK" on top level widgets |
903 | QWidget * active = activeWindow(); | 1108 | QWidget * active = activeWindow(); |
904 | QWidget *popup = 0; | 1109 | QWidget *popup = 0; |
905 | if ( active && active->isPopup() ) { | 1110 | if ( active && active->isPopup() ) { |
906 | popup = active; | 1111 | popup = active; |
907 | active = active->parentWidget(); | 1112 | active = active->parentWidget(); |
908 | } | 1113 | } |
909 | if ( active && ( int ) active->winId() == ke->simpleData.window && | 1114 | if ( active && ( int ) active->winId() == ke->simpleData.window && |
910 | !active->testWFlags( WStyle_Customize | WType_Popup | WType_Desktop ) ) { | 1115 | !active->testWFlags( WStyle_Customize | WType_Popup | WType_Desktop ) ) { |
911 | if ( ke->simpleData.is_press ) { | 1116 | if ( ke->simpleData.is_press ) { |
912 | if ( popup ) | 1117 | if ( popup ) |
913 | popup->close(); | 1118 | popup->close(); |
914 | if ( active->inherits( "QDialog" ) ) { | 1119 | if ( active->inherits( "QDialog" ) ) { |
915 | HackDialog * d = ( HackDialog * ) active; | 1120 | HackDialog * d = ( HackDialog * ) active; |
916 | d->acceptIt(); | 1121 | d->acceptIt(); |
917 | return TRUE; | 1122 | return TRUE; |
918 | } | 1123 | } |
919 | else if ( ( ( HackWidget * ) active ) ->needsOk() ) { | 1124 | else if ( ( ( HackWidget * ) active ) ->needsOk() ) { |
920 | QSignal s; | 1125 | QSignal s; |
921 | s.connect( active, SLOT( accept() ) ); | 1126 | s.connect( active, SLOT( accept() ) ); |
@@ -1933,121 +2138,125 @@ void QPEApplication::ungrabKeyboard() | |||
1933 | void QPEApplication::grabKeyboard() | 2138 | void QPEApplication::grabKeyboard() |
1934 | { | 2139 | { |
1935 | ((QPEApplication *) qApp )-> d-> kbgrabbed = true; | 2140 | ((QPEApplication *) qApp )-> d-> kbgrabbed = true; |
1936 | } | 2141 | } |
1937 | 2142 | ||
1938 | /*! | 2143 | /*! |
1939 | \reimp | 2144 | \reimp |
1940 | */ | 2145 | */ |
1941 | int QPEApplication::exec() | 2146 | int QPEApplication::exec() |
1942 | { | 2147 | { |
1943 | d->qcopQok = true; | 2148 | d->qcopQok = true; |
1944 | #ifndef QT_NO_COP | 2149 | #ifndef QT_NO_COP |
1945 | d->sendQCopQ(); | 2150 | d->sendQCopQ(); |
1946 | if ( !d->keep_running ) | 2151 | if ( !d->keep_running ) |
1947 | processEvents(); // we may have received QCop messages in the meantime. | 2152 | processEvents(); // we may have received QCop messages in the meantime. |
1948 | #endif | 2153 | #endif |
1949 | 2154 | ||
1950 | if ( d->keep_running ) | 2155 | if ( d->keep_running ) |
1951 | //|| d->qpe_main_widget && d->qpe_main_widget->isVisible() ) | 2156 | //|| d->qpe_main_widget && d->qpe_main_widget->isVisible() ) |
1952 | return QApplication::exec(); | 2157 | return QApplication::exec(); |
1953 | 2158 | ||
1954 | #ifndef QT_NO_COP | 2159 | #ifndef QT_NO_COP |
1955 | 2160 | ||
1956 | { | 2161 | { |
1957 | QCopEnvelope e( "QPE/System", "closing(QString)" ); | 2162 | QCopEnvelope e( "QPE/System", "closing(QString)" ); |
1958 | e << d->appName; | 2163 | e << d->appName; |
1959 | } | 2164 | } |
1960 | #endif | 2165 | #endif |
1961 | processEvents(); | 2166 | processEvents(); |
1962 | return 0; | 2167 | return 0; |
1963 | } | 2168 | } |
1964 | 2169 | ||
1965 | /*! | 2170 | /*! |
1966 | \internal | 2171 | \internal |
1967 | External request for application to quit. Quits if possible without | 2172 | External request for application to quit. Quits if possible without |
1968 | loosing state. | 2173 | loosing state. |
1969 | */ | 2174 | */ |
1970 | void QPEApplication::tryQuit() | 2175 | void QPEApplication::tryQuit() |
1971 | { | 2176 | { |
1972 | if ( activeModalWidget() || strcmp( argv() [ 0 ], "embeddedkonsole" ) == 0 ) | 2177 | if ( activeModalWidget() || strcmp( argv() [ 0 ], "embeddedkonsole" ) == 0 ) |
1973 | return ; // Inside modal loop or konsole. Too hard to save state. | 2178 | return ; // Inside modal loop or konsole. Too hard to save state. |
1974 | #ifndef QT_NO_COP | 2179 | #ifndef QT_NO_COP |
1975 | 2180 | ||
1976 | { | 2181 | { |
1977 | QCopEnvelope e( "QPE/System", "closing(QString)" ); | 2182 | QCopEnvelope e( "QPE/System", "closing(QString)" ); |
1978 | e << d->appName; | 2183 | e << d->appName; |
1979 | } | 2184 | } |
1980 | #endif | 2185 | #endif |
2186 | if ( d->keep_running ) | ||
2187 | d->store_widget_rect(d->qpe_main_widget, d->appName); | ||
1981 | processEvents(); | 2188 | processEvents(); |
1982 | 2189 | ||
1983 | quit(); | 2190 | quit(); |
1984 | } | 2191 | } |
1985 | 2192 | ||
1986 | /*! | 2193 | /*! |
1987 | \internal | 2194 | \internal |
1988 | */ | 2195 | */ |
1989 | void QPEApplication::installTranslation( const QString& baseName ) { | 2196 | void QPEApplication::installTranslation( const QString& baseName ) { |
1990 | QTranslator* trans = new QTranslator(this); | 2197 | QTranslator* trans = new QTranslator(this); |
1991 | QString tfn = qpeDir() + "/i18n/"+baseName; | 2198 | QString tfn = qpeDir() + "/i18n/"+baseName; |
1992 | if ( trans->load( tfn ) ) | 2199 | if ( trans->load( tfn ) ) |
1993 | installTranslator( trans ); | 2200 | installTranslator( trans ); |
1994 | else | 2201 | else |
1995 | delete trans; | 2202 | delete trans; |
1996 | } | 2203 | } |
1997 | 2204 | ||
1998 | /*! | 2205 | /*! |
1999 | \internal | 2206 | \internal |
2000 | User initiated quit. Makes the window 'Go Away'. If preloaded this means | 2207 | User initiated quit. Makes the window 'Go Away'. If preloaded this means |
2001 | hiding the window. If not it means quitting the application. | 2208 | hiding the window. If not it means quitting the application. |
2002 | As this is user initiated we don't need to check state. | 2209 | As this is user initiated we don't need to check state. |
2003 | */ | 2210 | */ |
2004 | void QPEApplication::hideOrQuit() | 2211 | void QPEApplication::hideOrQuit() |
2005 | { | 2212 | { |
2213 | if ( d->keep_running ) | ||
2214 | d->store_widget_rect(d->qpe_main_widget, d->appName); | ||
2006 | processEvents(); | 2215 | processEvents(); |
2007 | 2216 | ||
2008 | // If we are a preloaded application we don't actually quit, so emit | 2217 | // If we are a preloaded application we don't actually quit, so emit |
2009 | // a System message indicating we're quasi-closing. | 2218 | // a System message indicating we're quasi-closing. |
2010 | if ( d->preloaded && d->qpe_main_widget ) | 2219 | if ( d->preloaded && d->qpe_main_widget ) |
2011 | #ifndef QT_NO_COP | 2220 | #ifndef QT_NO_COP |
2012 | 2221 | ||
2013 | { | 2222 | { |
2014 | QCopEnvelope e("QPE/System", "fastAppHiding(QString)" ); | 2223 | QCopEnvelope e("QPE/System", "fastAppHiding(QString)" ); |
2015 | e << d->appName; | 2224 | e << d->appName; |
2016 | d->qpe_main_widget->hide(); | 2225 | d->qpe_main_widget->hide(); |
2017 | } | 2226 | } |
2018 | #endif | 2227 | #endif |
2019 | else | 2228 | else |
2020 | quit(); | 2229 | quit(); |
2021 | } | 2230 | } |
2022 | 2231 | ||
2023 | #if (__GNUC__ > 2 ) | 2232 | #if (__GNUC__ > 2 ) |
2024 | extern "C" void __cxa_pure_virtual(); | 2233 | extern "C" void __cxa_pure_virtual(); |
2025 | 2234 | ||
2026 | void __cxa_pure_virtual() | 2235 | void __cxa_pure_virtual() |
2027 | { | 2236 | { |
2028 | fprintf( stderr, "Pure virtual called\n"); | 2237 | fprintf( stderr, "Pure virtual called\n"); |
2029 | abort(); | 2238 | abort(); |
2030 | 2239 | ||
2031 | } | 2240 | } |
2032 | 2241 | ||
2033 | #endif | 2242 | #endif |
2034 | 2243 | ||
2035 | 2244 | ||
2036 | #if defined(OPIE_NEW_MALLOC) | 2245 | #if defined(OPIE_NEW_MALLOC) |
2037 | 2246 | ||
2038 | // The libraries with the skiff package (and possibly others) have | 2247 | // The libraries with the skiff package (and possibly others) have |
2039 | // completely useless implementations of builtin new and delete that | 2248 | // completely useless implementations of builtin new and delete that |
2040 | // use about 50% of your CPU. Here we revert to the simple libc | 2249 | // use about 50% of your CPU. Here we revert to the simple libc |
2041 | // functions. | 2250 | // functions. |
2042 | 2251 | ||
2043 | void* operator new[]( size_t size ) | 2252 | void* operator new[]( size_t size ) |
2044 | { | 2253 | { |
2045 | return malloc( size ); | 2254 | return malloc( size ); |
2046 | } | 2255 | } |
2047 | 2256 | ||
2048 | void* operator new( size_t size ) | 2257 | void* operator new( size_t size ) |
2049 | { | 2258 | { |
2050 | return malloc( size ); | 2259 | return malloc( size ); |
2051 | } | 2260 | } |
2052 | 2261 | ||
2053 | void operator delete[]( void* p ) | 2262 | void operator delete[]( void* p ) |