summaryrefslogtreecommitdiff
path: root/library/qpeapplication.cpp
Side-by-side diff
Diffstat (limited to 'library/qpeapplication.cpp') (more/less context) (ignore 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
@@ -56,124 +56,126 @@
#include <qpixmapcache.h>
#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
#define QTOPIA_INTERNAL_INITAPP
#include "qpeapplication.h"
#include "qpestyle.h"
#include "styleinterface.h"
#if QT_VERSION >= 0x030000
#include <qstylefactory.h>
#else
#include <qplatinumstyle.h>
#include <qwindowsstyle.h>
#include <qmotifstyle.h>
#include <qmotifplusstyle.h>
#include "lightstyle.h"
#include <qpe/qlibrary.h>
#endif
#include "global.h"
#include "resource.h"
#if QT_VERSION <= 230 && defined(QT_NO_CODECS)
#include "qutfcodec.h"
#endif
#include "config.h"
#include "network.h"
#ifdef QWS
#include "fontmanager.h"
#include "fontdatabase.h"
#endif
#include "alarmserver.h"
#include "applnk.h"
#include "qpemenubar.h"
#include "textcodecinterface.h"
#include "imagecodecinterface.h"
#include <qtopia/qpeglobal.h>
#include <unistd.h>
#include <sys/file.h>
#include <sys/ioctl.h>
#ifndef QT_NO_SOUND
#include <sys/soundcard.h>
#endif
#include <backend/rohfeedback.h>
static bool useBigPixmaps = 0;
+static bool saveWindowsPos = 0;
class HackWidget : public QWidget
{
public:
bool needsOk()
{ return (getWState() & WState_Reserved1 ); }
QRect normalGeometry()
{ return topData()->normalGeometry; };
};
class QPEApplicationData
{
public:
QPEApplicationData ( ) :
presstimer( 0 ), presswidget( 0 ), rightpressed( false ), kbgrabbed( false ),
notbusysent( false ), preloaded( false ), forceshow( false ), nomaximize( false ),
keep_running( true ), qcopQok( false ),
fontFamily( "Vera" ), fontSize( 10 ), smallIconSize( 14 ),
bigIconSize( 32 ), qpe_main_widget( 0 )
{
Config cfg( "qpe" );
cfg.setGroup( "Appearance" );
useBigPixmaps = cfg.readBoolEntry( "useBigPixmaps", false );
fontFamily = cfg.readEntry( "FontFamily", "Vera" );
fontSize = cfg.readNumEntry( "FontSize", 10 );
smallIconSize = cfg.readNumEntry( "SmallIconSize", 14 );
bigIconSize = cfg.readNumEntry( "BigIconSize", 32 );
+ saveWindowsPos = cfg.readBoolEntry( "AllowWindowed", false );
#ifdef OPIE_WITHROHFEEDBACK
RoH = 0;
#endif
}
int presstimer;
QWidget* presswidget;
QPoint presspos;
#ifdef OPIE_WITHROHFEEDBACK
Opie::Internal::RoHFeedback *RoH;
#endif
bool rightpressed : 1;
bool kbgrabbed : 1;
bool notbusysent : 1;
bool preloaded : 1;
bool forceshow : 1;
bool nomaximize : 1;
bool keep_running : 1;
bool qcopQok : 1;
QCString fontFamily;
int fontSize;
int smallIconSize;
int bigIconSize;
QString appName;
struct QCopRec
{
QCopRec( const QCString &ch, const QCString &msg,
const QByteArray &d ) :
channel( ch ), message( msg ), data( d )
{ }
QCString channel;
QCString message;
QByteArray data;
};
QGuardedPtr<QWidget> qpe_main_widget;
QGuardedPtr<QWidget> lastraised;
QQueue<QCopRec> qcopq;
QString styleName;
QString decorationName;
void enqueueQCop( const QCString &ch, const QCString &msg,
const QByteArray &data )
{
qcopq.enqueue( new QCopRec( ch, msg, data ) );
@@ -205,190 +207,189 @@ public:
QPoint p;
QSize s;
bool max;
if ( mw->isVisible() ) {
if ( read_widget_rect(strName, max, p, s) && validate_widget_size(mw, p, s) ) {
mw->resize(s);
mw->move(p);
}
mw->raise();
} else {
if ( mw->layout() && mw->inherits("QDialog") ) {
if ( read_widget_rect(strName, max, p, s) && validate_widget_size(mw, p, s) ) {
mw->resize(s);
mw->move(p);
if ( max && !nomaximize ) {
mw->showMaximized();
} else {
mw->show();
}
} else {
QPEApplication::showDialog((QDialog*)mw,nomaximize);
}
} else {
if ( read_widget_rect(strName, max, p, s) && validate_widget_size(mw, p, s) ) {
mw->resize(s);
mw->move(p);
} else { //no stored rectangle, make an estimation
int x = (qApp->desktop()->width()-mw->frameGeometry().width())/2;
int y = (qApp->desktop()->height()-mw->frameGeometry().height())/2;
mw->move( QMAX(x,0), QMAX(y,0) );
#ifdef Q_WS_QWS
if ( !nomaximize )
mw->showMaximized();
#endif
}
if ( max && !nomaximize )
mw->showMaximized();
else
mw->show();
}
}
}
static bool read_widget_rect(const QString &app, bool &maximized, QPoint &p, QSize &s)
{
-#ifndef OPIE_NO_WINDOWED
+ if (!saveWindowsPos)
+ return FALSE;
maximized = TRUE;
// 350 is the trigger in qwsdefaultdecoration for providing a resize button
if ( qApp->desktop()->width() <= 350 )
return FALSE;
Config cfg( "qpe" );
cfg.setGroup("ApplicationPositions");
QString str = cfg.readEntry( app, QString::null );
QStringList l = QStringList::split(",", str);
if ( l.count() == 5) {
p.setX( l[0].toInt() );
p.setY( l[1].toInt() );
s.setWidth( l[2].toInt() );
s.setHeight( l[3].toInt() );
maximized = l[4].toInt();
return TRUE;
}
-#endif
- return FALSE;
}
static bool validate_widget_size(const QWidget *w, QPoint &p, QSize &s)
{
#ifndef Q_WS_QWS
QRect qt_maxWindowRect = qApp->desktop()->geometry();
#endif
int maxX = qt_maxWindowRect.width();
int maxY = qt_maxWindowRect.height();
int wWidth = s.width() + ( w->frameGeometry().width() - w->geometry().width() );
int wHeight = s.height() + ( w->frameGeometry().height() - w->geometry().height() );
// total window size is not allowed to be larger than desktop window size
if ( ( wWidth >= maxX ) && ( wHeight >= maxY ) )
return FALSE;
if ( wWidth > maxX ) {
s.setWidth( maxX - (w->frameGeometry().width() - w->geometry().width() ) );
wWidth = maxX;
}
if ( wHeight > maxY ) {
s.setHeight( maxY - (w->frameGeometry().height() - w->geometry().height() ) );
wHeight = maxY;
}
// any smaller than this and the maximize/close/help buttons will be overlapping
if ( wWidth < 80 || wHeight < 60 )
return FALSE;
if ( p.x() < 0 )
p.setX(0);
if ( p.y() < 0 )
p.setY(0);
if ( p.x() + wWidth > maxX )
p.setX( maxX - wWidth );
if ( p.y() + wHeight > maxY )
p.setY( maxY - wHeight );
return TRUE;
}
static void store_widget_rect(QWidget *w, QString &app)
{
if( !w )
return;
-#ifndef OPIE_NO_WINDOWED
+ if (!saveWindowsPos)
+ return;
// 350 is the trigger in qwsdefaultdecoration for providing a resize button
if ( qApp->desktop()->width() <= 350 )
return;
// we use these to map the offset of geometry and pos. ( we can only use normalGeometry to
// get the non-maximized version, so we have to do it the hard way )
int offsetX = w->x() - w->geometry().left();
int offsetY = w->y() - w->geometry().top();
QRect r;
if ( w->isMaximized() )
r = ( (HackWidget *) w)->normalGeometry();
else
r = w->geometry();
// Stores the window placement as pos(), size() (due to the offset mapping)
Config cfg( "qpe" );
cfg.setGroup("ApplicationPositions");
QString s;
s.sprintf("%d,%d,%d,%d,%d", r.left() + offsetX, r.top() + offsetY, r.width(), r.height(), w->isMaximized() );
cfg.writeEntry( app, s );
-#endif
}
static bool setWidgetCaptionFromAppName( QWidget* /*mw*/, const QString& /*appName*/, const QString& /*appsPath*/ )
{
/*
// This works but disable it for now until it is safe to apply
// What is does is scan the .desktop files of all the apps for
// the applnk that has the corresponding argv[0] as this program
// then it uses the name stored in the .desktop file as the caption
// for the main widget. This saves duplicating translations for
// the app name in the program and in the .desktop files.
AppLnkSet apps( appsPath );
QList<AppLnk> appsList = apps.children();
for ( QListIterator<AppLnk> it(appsList); it.current(); ++it ) {
if ( (*it)->exec() == appName ) {
mw->setCaption( (*it)->name() );
return TRUE;
}
}
*/
return FALSE;
}
void show(QWidget* mw, bool nomax)
{
setWidgetCaptionFromAppName( mw, appName, QPEApplication::qpeDir() + "apps" );
nomaximize = nomax;
qpe_main_widget = mw;
qcopQok = TRUE;
#ifndef QT_NO_COP
sendQCopQ();
#endif
if ( preloaded ) {
if (forceshow)
show_mx(mw, nomax, appName);
}
else if ( keep_running ) {
show_mx(mw, nomax, appName);
}
}
void loadTextCodecs()
{
@@ -2162,96 +2163,101 @@ int QPEApplication::exec()
loosing state.
*/
void QPEApplication::tryQuit()
{
if ( activeModalWidget() )
return ; // Inside modal loop or konsole. Too hard to save state.
#ifndef QT_NO_COP
{
QCopEnvelope e( "QPE/System", "closing(QString)" );
e << d->appName;
}
#endif
if ( d->keep_running )
d->store_widget_rect(d->qpe_main_widget, d->appName);
processEvents();
quit();
}
/*!
\internal
User initiated quit. Makes the window 'Go Away'. If preloaded this means
hiding the window. If not it means quitting the application.
As this is user initiated we don't need to check state.
*/
void QPEApplication::hideOrQuit()
{
if ( d->keep_running )
d->store_widget_rect(d->qpe_main_widget, d->appName);
processEvents();
// If we are a preloaded application we don't actually quit, so emit
// a System message indicating we're quasi-closing.
if ( d->preloaded && d->qpe_main_widget )
#ifndef QT_NO_COP
{
QCopEnvelope e("QPE/System", "fastAppHiding(QString)" );
e << d->appName;
d->qpe_main_widget->hide();
}
#endif
else
quit();
}
+bool QPEApplication::isSaveWindowsPos()
+{
+ return saveWindowsPos;
+}
+
#if (__GNUC__ > 2 ) && !defined(_OS_MACX_)
extern "C" void __cxa_pure_virtual();
void __cxa_pure_virtual()
{
fprintf( stderr, "Pure virtual called\n");
abort();
}
#endif
#if defined(OPIE_NEW_MALLOC)
// The libraries with the skiff package (and possibly others) have
// completely useless implementations of builtin new and delete that
// use about 50% of your CPU. Here we revert to the simple libc
// functions.
void* operator new[]( size_t size )
{
return malloc( size );
}
void* operator new( size_t size )
{
return malloc( size );
}
void operator delete[]( void* p )
{
if ( p )
free( p );
}
void operator delete[]( void* p, size_t /*size*/ )
{
if ( p )
free( p );
}
void operator delete( void* p )
{
if ( p )
free( p );
}