author | zecke <zecke> | 2005-03-06 23:30:41 (UTC) |
---|---|---|
committer | zecke <zecke> | 2005-03-06 23:30:41 (UTC) |
commit | f312f32d624c6198c63890e141e8658bc492cf37 (patch) (unidiff) | |
tree | c76e9caad09226113e42e0477d08e13d6388af2e | |
parent | 578cc81bc489015320351efd4fabcbed3355ac23 (diff) | |
download | opie-f312f32d624c6198c63890e141e8658bc492cf37.zip opie-f312f32d624c6198c63890e141e8658bc492cf37.tar.gz opie-f312f32d624c6198c63890e141e8658bc492cf37.tar.bz2 |
The mainwidget could be deleted before the qpeapplication will be destructed or
the event loop will be left.
Use a QGuardedPtr to not save widget coordinates on a not anymore existing
mainwidget
-rw-r--r-- | library/qpeapplication.cpp | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/library/qpeapplication.cpp b/library/qpeapplication.cpp index 2bd7cbe..953f9d0 100644 --- a/library/qpeapplication.cpp +++ b/library/qpeapplication.cpp | |||
@@ -122,97 +122,97 @@ public: | |||
122 | fontFamily( "Vera" ), fontSize( 10 ), smallIconSize( 14 ), | 122 | fontFamily( "Vera" ), fontSize( 10 ), smallIconSize( 14 ), |
123 | bigIconSize( 32 ), qpe_main_widget( 0 ) | 123 | bigIconSize( 32 ), qpe_main_widget( 0 ) |
124 | { | 124 | { |
125 | Config cfg( "qpe" ); | 125 | Config cfg( "qpe" ); |
126 | cfg.setGroup( "Appearance" ); | 126 | cfg.setGroup( "Appearance" ); |
127 | useBigPixmaps = cfg.readBoolEntry( "useBigPixmaps", false ); | 127 | useBigPixmaps = cfg.readBoolEntry( "useBigPixmaps", false ); |
128 | fontFamily = cfg.readEntry( "FontFamily", "Vera" ); | 128 | fontFamily = cfg.readEntry( "FontFamily", "Vera" ); |
129 | fontSize = cfg.readNumEntry( "FontSize", 10 ); | 129 | fontSize = cfg.readNumEntry( "FontSize", 10 ); |
130 | smallIconSize = cfg.readNumEntry( "SmallIconSize", 14 ); | 130 | smallIconSize = cfg.readNumEntry( "SmallIconSize", 14 ); |
131 | bigIconSize = cfg.readNumEntry( "BigIconSize", 32 ); | 131 | bigIconSize = cfg.readNumEntry( "BigIconSize", 32 ); |
132 | #ifdef OPIE_WITHROHFEEDBACK | 132 | #ifdef OPIE_WITHROHFEEDBACK |
133 | RoH = 0; | 133 | RoH = 0; |
134 | #endif | 134 | #endif |
135 | } | 135 | } |
136 | 136 | ||
137 | int presstimer; | 137 | int presstimer; |
138 | QWidget* presswidget; | 138 | QWidget* presswidget; |
139 | QPoint presspos; | 139 | QPoint presspos; |
140 | #ifdef OPIE_WITHROHFEEDBACK | 140 | #ifdef OPIE_WITHROHFEEDBACK |
141 | Opie::Internal::RoHFeedback *RoH; | 141 | Opie::Internal::RoHFeedback *RoH; |
142 | #endif | 142 | #endif |
143 | 143 | ||
144 | bool rightpressed : 1; | 144 | bool rightpressed : 1; |
145 | bool kbgrabbed : 1; | 145 | bool kbgrabbed : 1; |
146 | bool notbusysent : 1; | 146 | bool notbusysent : 1; |
147 | bool preloaded : 1; | 147 | bool preloaded : 1; |
148 | bool forceshow : 1; | 148 | bool forceshow : 1; |
149 | bool nomaximize : 1; | 149 | bool nomaximize : 1; |
150 | bool keep_running : 1; | 150 | bool keep_running : 1; |
151 | bool qcopQok : 1; | 151 | bool qcopQok : 1; |
152 | 152 | ||
153 | QCString fontFamily; | 153 | QCString fontFamily; |
154 | int fontSize; | 154 | int fontSize; |
155 | int smallIconSize; | 155 | int smallIconSize; |
156 | int bigIconSize; | 156 | int bigIconSize; |
157 | 157 | ||
158 | QString appName; | 158 | QString appName; |
159 | struct QCopRec | 159 | struct QCopRec |
160 | { | 160 | { |
161 | QCopRec( const QCString &ch, const QCString &msg, | 161 | QCopRec( const QCString &ch, const QCString &msg, |
162 | const QByteArray &d ) : | 162 | const QByteArray &d ) : |
163 | channel( ch ), message( msg ), data( d ) | 163 | channel( ch ), message( msg ), data( d ) |
164 | { } | 164 | { } |
165 | 165 | ||
166 | QCString channel; | 166 | QCString channel; |
167 | QCString message; | 167 | QCString message; |
168 | QByteArray data; | 168 | QByteArray data; |
169 | }; | 169 | }; |
170 | QWidget* qpe_main_widget; | 170 | QGuardedPtr<QWidget> qpe_main_widget; |
171 | QGuardedPtr<QWidget> lastraised; | 171 | QGuardedPtr<QWidget> lastraised; |
172 | QQueue<QCopRec> qcopq; | 172 | QQueue<QCopRec> qcopq; |
173 | QString styleName; | 173 | QString styleName; |
174 | QString decorationName; | 174 | QString decorationName; |
175 | 175 | ||
176 | void enqueueQCop( const QCString &ch, const QCString &msg, | 176 | void enqueueQCop( const QCString &ch, const QCString &msg, |
177 | const QByteArray &data ) | 177 | const QByteArray &data ) |
178 | { | 178 | { |
179 | qcopq.enqueue( new QCopRec( ch, msg, data ) ); | 179 | qcopq.enqueue( new QCopRec( ch, msg, data ) ); |
180 | } | 180 | } |
181 | void sendQCopQ() | 181 | void sendQCopQ() |
182 | { | 182 | { |
183 | if (!qcopQok ) | 183 | if (!qcopQok ) |
184 | return; | 184 | return; |
185 | 185 | ||
186 | QCopRec * r; | 186 | QCopRec * r; |
187 | 187 | ||
188 | while((r=qcopq.dequeue())) { | 188 | while((r=qcopq.dequeue())) { |
189 | // remove from queue before sending... | 189 | // remove from queue before sending... |
190 | // event loop can come around again before getting | 190 | // event loop can come around again before getting |
191 | // back from sendLocally | 191 | // back from sendLocally |
192 | #ifndef QT_NO_COP | 192 | #ifndef QT_NO_COP |
193 | QCopChannel::sendLocally( r->channel, r->message, r->data ); | 193 | QCopChannel::sendLocally( r->channel, r->message, r->data ); |
194 | #endif | 194 | #endif |
195 | 195 | ||
196 | delete r; | 196 | delete r; |
197 | } | 197 | } |
198 | } | 198 | } |
199 | 199 | ||
200 | static void show_mx(QWidget* mw, bool nomaximize, QString &strName) { | 200 | static void show_mx(QWidget* mw, bool nomaximize, QString &strName) { |
201 | if ( mw->inherits("QMainWindow") || mw->isA("QMainWindow") ) | 201 | if ( mw->inherits("QMainWindow") || mw->isA("QMainWindow") ) |
202 | { | 202 | { |
203 | ( ( QMainWindow* ) mw )->setUsesBigPixmaps( useBigPixmaps ); | 203 | ( ( QMainWindow* ) mw )->setUsesBigPixmaps( useBigPixmaps ); |
204 | } | 204 | } |
205 | QPoint p; | 205 | QPoint p; |
206 | QSize s; | 206 | QSize s; |
207 | bool max; | 207 | bool max; |
208 | 208 | ||
209 | if ( mw->isVisible() ) { | 209 | if ( mw->isVisible() ) { |
210 | if ( read_widget_rect(strName, max, p, s) && validate_widget_size(mw, p, s) ) { | 210 | if ( read_widget_rect(strName, max, p, s) && validate_widget_size(mw, p, s) ) { |
211 | mw->resize(s); | 211 | mw->resize(s); |
212 | mw->move(p); | 212 | mw->move(p); |
213 | } | 213 | } |
214 | mw->raise(); | 214 | mw->raise(); |
215 | } else { | 215 | } else { |
216 | 216 | ||
217 | if ( mw->layout() && mw->inherits("QDialog") ) { | 217 | if ( mw->layout() && mw->inherits("QDialog") ) { |
218 | if ( read_widget_rect(strName, max, p, s) && validate_widget_size(mw, p, s) ) { | 218 | if ( read_widget_rect(strName, max, p, s) && validate_widget_size(mw, p, s) ) { |
@@ -274,96 +274,99 @@ public: | |||
274 | 274 | ||
275 | return FALSE; | 275 | return FALSE; |
276 | } | 276 | } |
277 | 277 | ||
278 | 278 | ||
279 | static bool validate_widget_size(const QWidget *w, QPoint &p, QSize &s) | 279 | static bool validate_widget_size(const QWidget *w, QPoint &p, QSize &s) |
280 | { | 280 | { |
281 | #ifndef Q_WS_QWS | 281 | #ifndef Q_WS_QWS |
282 | QRect qt_maxWindowRect = qApp->desktop()->geometry(); | 282 | QRect qt_maxWindowRect = qApp->desktop()->geometry(); |
283 | #endif | 283 | #endif |
284 | int maxX = qt_maxWindowRect.width(); | 284 | int maxX = qt_maxWindowRect.width(); |
285 | int maxY = qt_maxWindowRect.height(); | 285 | int maxY = qt_maxWindowRect.height(); |
286 | int wWidth = s.width() + ( w->frameGeometry().width() - w->geometry().width() ); | 286 | int wWidth = s.width() + ( w->frameGeometry().width() - w->geometry().width() ); |
287 | int wHeight = s.height() + ( w->frameGeometry().height() - w->geometry().height() ); | 287 | int wHeight = s.height() + ( w->frameGeometry().height() - w->geometry().height() ); |
288 | 288 | ||
289 | // total window size is not allowed to be larger than desktop window size | 289 | // total window size is not allowed to be larger than desktop window size |
290 | if ( ( wWidth >= maxX ) && ( wHeight >= maxY ) ) | 290 | if ( ( wWidth >= maxX ) && ( wHeight >= maxY ) ) |
291 | return FALSE; | 291 | return FALSE; |
292 | 292 | ||
293 | if ( wWidth > maxX ) { | 293 | if ( wWidth > maxX ) { |
294 | s.setWidth( maxX - (w->frameGeometry().width() - w->geometry().width() ) ); | 294 | s.setWidth( maxX - (w->frameGeometry().width() - w->geometry().width() ) ); |
295 | wWidth = maxX; | 295 | wWidth = maxX; |
296 | } | 296 | } |
297 | 297 | ||
298 | if ( wHeight > maxY ) { | 298 | if ( wHeight > maxY ) { |
299 | s.setHeight( maxY - (w->frameGeometry().height() - w->geometry().height() ) ); | 299 | s.setHeight( maxY - (w->frameGeometry().height() - w->geometry().height() ) ); |
300 | wHeight = maxY; | 300 | wHeight = maxY; |
301 | } | 301 | } |
302 | 302 | ||
303 | // any smaller than this and the maximize/close/help buttons will be overlapping | 303 | // any smaller than this and the maximize/close/help buttons will be overlapping |
304 | if ( wWidth < 80 || wHeight < 60 ) | 304 | if ( wWidth < 80 || wHeight < 60 ) |
305 | return FALSE; | 305 | return FALSE; |
306 | 306 | ||
307 | if ( p.x() < 0 ) | 307 | if ( p.x() < 0 ) |
308 | p.setX(0); | 308 | p.setX(0); |
309 | if ( p.y() < 0 ) | 309 | if ( p.y() < 0 ) |
310 | p.setY(0); | 310 | p.setY(0); |
311 | 311 | ||
312 | if ( p.x() + wWidth > maxX ) | 312 | if ( p.x() + wWidth > maxX ) |
313 | p.setX( maxX - wWidth ); | 313 | p.setX( maxX - wWidth ); |
314 | if ( p.y() + wHeight > maxY ) | 314 | if ( p.y() + wHeight > maxY ) |
315 | p.setY( maxY - wHeight ); | 315 | p.setY( maxY - wHeight ); |
316 | 316 | ||
317 | return TRUE; | 317 | return TRUE; |
318 | } | 318 | } |
319 | 319 | ||
320 | static void store_widget_rect(QWidget *w, QString &app) | 320 | static void store_widget_rect(QWidget *w, QString &app) |
321 | { | 321 | { |
322 | if( !w ) | ||
323 | return; | ||
324 | |||
322 | // 350 is the trigger in qwsdefaultdecoration for providing a resize button | 325 | // 350 is the trigger in qwsdefaultdecoration for providing a resize button |
323 | if ( qApp->desktop()->width() <= 350 ) | 326 | if ( qApp->desktop()->width() <= 350 ) |
324 | return; | 327 | return; |
325 | // we use these to map the offset of geometry and pos. ( we can only use normalGeometry to | 328 | // we use these to map the offset of geometry and pos. ( we can only use normalGeometry to |
326 | // get the non-maximized version, so we have to do it the hard way ) | 329 | // get the non-maximized version, so we have to do it the hard way ) |
327 | int offsetX = w->x() - w->geometry().left(); | 330 | int offsetX = w->x() - w->geometry().left(); |
328 | int offsetY = w->y() - w->geometry().top(); | 331 | int offsetY = w->y() - w->geometry().top(); |
329 | 332 | ||
330 | QRect r; | 333 | QRect r; |
331 | if ( w->isMaximized() ) | 334 | if ( w->isMaximized() ) |
332 | r = ( (HackWidget *) w)->normalGeometry(); | 335 | r = ( (HackWidget *) w)->normalGeometry(); |
333 | else | 336 | else |
334 | r = w->geometry(); | 337 | r = w->geometry(); |
335 | 338 | ||
336 | // Stores the window placement as pos(), size() (due to the offset mapping) | 339 | // Stores the window placement as pos(), size() (due to the offset mapping) |
337 | Config cfg( "qpe" ); | 340 | Config cfg( "qpe" ); |
338 | cfg.setGroup("ApplicationPositions"); | 341 | cfg.setGroup("ApplicationPositions"); |
339 | QString s; | 342 | QString s; |
340 | s.sprintf("%d,%d,%d,%d,%d", r.left() + offsetX, r.top() + offsetY, r.width(), r.height(), w->isMaximized() ); | 343 | s.sprintf("%d,%d,%d,%d,%d", r.left() + offsetX, r.top() + offsetY, r.width(), r.height(), w->isMaximized() ); |
341 | cfg.writeEntry( app, s ); | 344 | cfg.writeEntry( app, s ); |
342 | } | 345 | } |
343 | 346 | ||
344 | static bool setWidgetCaptionFromAppName( QWidget* /*mw*/, const QString& /*appName*/, const QString& /*appsPath*/ ) | 347 | static bool setWidgetCaptionFromAppName( QWidget* /*mw*/, const QString& /*appName*/, const QString& /*appsPath*/ ) |
345 | { | 348 | { |
346 | /* | 349 | /* |
347 | // This works but disable it for now until it is safe to apply | 350 | // This works but disable it for now until it is safe to apply |
348 | // What is does is scan the .desktop files of all the apps for | 351 | // What is does is scan the .desktop files of all the apps for |
349 | // the applnk that has the corresponding argv[0] as this program | 352 | // the applnk that has the corresponding argv[0] as this program |
350 | // then it uses the name stored in the .desktop file as the caption | 353 | // then it uses the name stored in the .desktop file as the caption |
351 | // for the main widget. This saves duplicating translations for | 354 | // for the main widget. This saves duplicating translations for |
352 | // the app name in the program and in the .desktop files. | 355 | // the app name in the program and in the .desktop files. |
353 | 356 | ||
354 | AppLnkSet apps( appsPath ); | 357 | AppLnkSet apps( appsPath ); |
355 | 358 | ||
356 | QList<AppLnk> appsList = apps.children(); | 359 | QList<AppLnk> appsList = apps.children(); |
357 | for ( QListIterator<AppLnk> it(appsList); it.current(); ++it ) { | 360 | for ( QListIterator<AppLnk> it(appsList); it.current(); ++it ) { |
358 | if ( (*it)->exec() == appName ) { | 361 | if ( (*it)->exec() == appName ) { |
359 | mw->setCaption( (*it)->name() ); | 362 | mw->setCaption( (*it)->name() ); |
360 | return TRUE; | 363 | return TRUE; |
361 | } | 364 | } |
362 | } | 365 | } |
363 | */ | 366 | */ |
364 | return FALSE; | 367 | return FALSE; |
365 | } | 368 | } |
366 | 369 | ||
367 | 370 | ||
368 | void show(QWidget* mw, bool nomax) | 371 | void show(QWidget* mw, bool nomax) |
369 | { | 372 | { |