summaryrefslogtreecommitdiff
path: root/library/qpeapplication.cpp
Unidiff
Diffstat (limited to 'library/qpeapplication.cpp') (more/less context) (show whitespace changes)
-rw-r--r--library/qpeapplication.cpp16
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
@@ -80,76 +80,78 @@
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
103static bool useBigPixmaps = 0; 103static bool useBigPixmaps = 0;
104static bool saveWindowsPos = 0;
104 105
105class HackWidget : public QWidget 106class HackWidget : public QWidget
106{ 107{
107public: 108public:
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
115class QPEApplicationData 116class QPEApplicationData
116{ 117{
117public: 118public:
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;
@@ -229,142 +231,141 @@ public:
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 }
@@ -2186,48 +2187,53 @@ void QPEApplication::tryQuit()
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*/
2189void QPEApplication::hideOrQuit() 2190void 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
2211bool QPEApplication::isSaveWindowsPos()
2212{
2213 return saveWindowsPos;
2214}
2215
2210#if (__GNUC__ > 2 ) && !defined(_OS_MACX_) 2216#if (__GNUC__ > 2 ) && !defined(_OS_MACX_)
2211extern "C" void __cxa_pure_virtual(); 2217extern "C" void __cxa_pure_virtual();
2212 2218
2213void __cxa_pure_virtual() 2219void __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
2230void* operator new[]( size_t size ) 2236void* operator new[]( size_t size )
2231{ 2237{
2232 return malloc( size ); 2238 return malloc( size );
2233} 2239}