summaryrefslogtreecommitdiff
path: root/library/qpeapplication.h
Unidiff
Diffstat (limited to 'library/qpeapplication.h') (more/less context) (ignore whitespace changes)
-rw-r--r--library/qpeapplication.h40
1 files changed, 39 insertions, 1 deletions
diff --git a/library/qpeapplication.h b/library/qpeapplication.h
index 729cf2b..3ef8b46 100644
--- a/library/qpeapplication.h
+++ b/library/qpeapplication.h
@@ -1,206 +1,244 @@
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#ifndef __QPE_APPLICATION_H__ 20#ifndef __QPE_APPLICATION_H__
21#define __QPE_APPLICATION_H__ 21#define __QPE_APPLICATION_H__
22 22
23#include <stdlib.h> // for setenv() 23#include <stdlib.h> // for setenv()
24 24
25#include <qglobal.h> 25#include <qglobal.h>
26#include <qapplication.h> 26#include <qapplication.h>
27#include <qdialog.h> 27#include <qdialog.h>
28#include <qwsdisplay_qws.h> 28#include <qwsdisplay_qws.h>
29#if defined(_WS_QWS_) && !defined(Q_WS_QWS) 29#if defined(_WS_QWS_) && !defined(Q_WS_QWS)
30#define Q_WS_QWS 30#define Q_WS_QWS
31#endif 31#endif
32#include "qpedecoration_qws.h" 32#include "qpedecoration_qws.h"
33#include "timestring.h" 33#include "timestring.h"
34 34
35class QCopChannel; 35class QCopChannel;
36class QPEApplicationData; 36class QPEApplicationData;
37class QWSEvent; 37class QWSEvent;
38class QWSKeyEvent; 38class QWSKeyEvent;
39 39
40 40/**
41 \brief The QPEApplication class implements various system services
42 that are available to all Qtopia applications.
43
44 Simply by using QPEApplication instead of QApplication, a standard Qt
45 application becomes a Qtopia application. It automatically follows
46 style changes, quits and raises, and in the
47 case of \link docwidget.html document-oriented\endlink applications,
48 changes the currently displayed document in response to the environment.
49
50 To create a \link docwidget.html document-oriented\endlink
51 application use showMainDocumentWidget(); to create a
52 non-document-oriented application use showMainWidget(). The
53 keepRunning() function indicates whether the application will
54 continue running after it's processed the last \link qcop.html
55 QCop\endlink message. This can be changed using setKeepRunning().
56
57 A variety of signals are emitted when certain events occur, for
58 example, timeChanged(), clockChanged(), weekChanged(),
59 dateFormatChanged() and volumeChanged(). If the application receives
60 a \link qcop.html QCop\endlink message on the application's
61 QPE/Application/\e{appname} channel, the appMessage() signal is
62 emitted. There are also flush() and reload() signals, which
63 are emitted when synching begins and ends respectively - upon these
64 signals, the application should save and reload any data
65 files that are involved in synching. Most of these signals will initially
66 be received and unfiltered through the appMessage() signal.
67
68 This class also provides a set of useful static functions. The
69 qpeDir() and documentDir() functions return the respective paths.
70 The grabKeyboard() and ungrabKeyboard() functions are used to
71 control whether the application takes control of the device's
72 physical buttons (e.g. application launch keys). The stylus' mode of
73 operation is set with setStylusOperation() and retrieved with
74 stylusOperation(). There are also setInputMethodHint() and
75 inputMethodHint() functions.
76
77 \ingroup qtopiaemb
78*/
41class QPEApplication : public QApplication 79class QPEApplication : public QApplication
42{ 80{
43 Q_OBJECT 81 Q_OBJECT
44public: 82public:
45 QPEApplication( int& argc, char **argv, Type=GuiClient ); 83 QPEApplication( int& argc, char **argv, Type=GuiClient );
46 ~QPEApplication(); 84 ~QPEApplication();
47 85
48 static QString qpeDir(); 86 static QString qpeDir();
49 static QString documentDir(); 87 static QString documentDir();
50 void applyStyle(); 88 void applyStyle();
51 void reset(); 89 void reset();
52 static int defaultRotation(); 90 static int defaultRotation();
53 static void setDefaultRotation(int r); 91 static void setDefaultRotation(int r);
54 static void setCurrentRotation(int r); 92 static void setCurrentRotation(int r);
55 static void setCurrentMode(int x, int y, int depth ); 93 static void setCurrentMode(int x, int y, int depth );
56 static void grabKeyboard(); 94 static void grabKeyboard();
57 static void ungrabKeyboard(); 95 static void ungrabKeyboard();
58 96
59 enum StylusMode { 97 enum StylusMode {
60 LeftOnly, 98 LeftOnly,
61 RightOnHold 99 RightOnHold
62 // RightOnHoldLeftDelayed, etc. 100 // RightOnHoldLeftDelayed, etc.
63 }; 101 };
64 static void setStylusOperation( QWidget*, StylusMode ); 102 static void setStylusOperation( QWidget*, StylusMode );
65 static StylusMode stylusOperation( QWidget* ); 103 static StylusMode stylusOperation( QWidget* );
66 104
67 enum InputMethodHint { 105 enum InputMethodHint {
68 Normal, 106 Normal,
69 AlwaysOff, 107 AlwaysOff,
70 AlwaysOn 108 AlwaysOn
71 }; 109 };
72 110
73 enum screenSaverHint { 111 enum screenSaverHint {
74 Disable = 0, 112 Disable = 0,
75 DisableLightOff = 1, 113 DisableLightOff = 1,
76 DisableSuspend = 2, 114 DisableSuspend = 2,
77 Enable = 100 115 Enable = 100
78 }; 116 };
79 117
80 static void setInputMethodHint( QWidget *, InputMethodHint ); 118 static void setInputMethodHint( QWidget *, InputMethodHint );
81 static InputMethodHint inputMethodHint( QWidget * ); 119 static InputMethodHint inputMethodHint( QWidget * );
82 120
83 void showMainWidget( QWidget*, bool nomax=FALSE ); 121 void showMainWidget( QWidget*, bool nomax=FALSE );
84 void showMainDocumentWidget( QWidget*, bool nomax=FALSE ); 122 void showMainDocumentWidget( QWidget*, bool nomax=FALSE );
85 static void showDialog( QDialog*, bool nomax=FALSE ); 123 static void showDialog( QDialog*, bool nomax=FALSE );
86 static int execDialog( QDialog*, bool nomax=FALSE ); 124 static int execDialog( QDialog*, bool nomax=FALSE );
87 /* Merge setTempScreenSaverMode */ 125 /* Merge setTempScreenSaverMode */
88#ifdef QTOPIA_INTERNAL_INITAPP 126#ifdef QTOPIA_INTERNAL_INITAPP
89 void initApp( int argv, char **argv ); 127 void initApp( int argv, char **argv );
90#endif 128#endif
91 129
92 static void setKeepRunning(); 130 static void setKeepRunning();
93 bool keepRunning() const; 131 bool keepRunning() const;
94 132
95 bool keyboardGrabbed() const; 133 bool keyboardGrabbed() const;
96 134
97 int exec(); 135 int exec();
98 136
99signals: 137signals:
100 void clientMoused(); 138 void clientMoused();
101 void timeChanged(); 139 void timeChanged();
102 void clockChanged( bool pm ); 140 void clockChanged( bool pm );
103 void micChanged( bool muted ); 141 void micChanged( bool muted );
104 void volumeChanged( bool muted ); 142 void volumeChanged( bool muted );
105 void appMessage( const QCString& msg, const QByteArray& data); 143 void appMessage( const QCString& msg, const QByteArray& data);
106 void weekChanged( bool startOnMonday ); 144 void weekChanged( bool startOnMonday );
107 void dateFormatChanged( DateFormat ); 145 void dateFormatChanged( DateFormat );
108 void flush(); 146 void flush();
109 void reload(); 147 void reload();
110 /* linkChanged signal */ 148 /* linkChanged signal */
111 149
112private slots: 150private slots:
113 void systemMessage( const QCString &msg, const QByteArray &data ); 151 void systemMessage( const QCString &msg, const QByteArray &data );
114 void pidMessage( const QCString &msg, const QByteArray &data ); 152 void pidMessage( const QCString &msg, const QByteArray &data );
115 void removeSenderFromStylusDict(); 153 void removeSenderFromStylusDict();
116 void hideOrQuit(); 154 void hideOrQuit();
117 155
118protected: 156protected:
119 bool qwsEventFilter( QWSEvent * ); 157 bool qwsEventFilter( QWSEvent * );
120 void internalSetStyle( const QString &style ); 158 void internalSetStyle( const QString &style );
121 void prepareForTermination(bool willrestart); 159 void prepareForTermination(bool willrestart);
122 virtual void restart(); 160 virtual void restart();
123 virtual void shutdown(); 161 virtual void shutdown();
124 bool eventFilter( QObject *, QEvent * ); 162 bool eventFilter( QObject *, QEvent * );
125 void timerEvent( QTimerEvent * ); 163 void timerEvent( QTimerEvent * );
126 bool raiseAppropriateWindow(); 164 bool raiseAppropriateWindow();
127 virtual void tryQuit(); 165 virtual void tryQuit();
128#if QT_VERSION > 233 166#if QT_VERSION > 233
129 virtual void polish ( QWidget * ); // this is actually implemented in qt_override.cpp (!) 167 virtual void polish ( QWidget * ); // this is actually implemented in qt_override.cpp (!)
130#endif 168#endif
131private: 169private:
132#ifndef QT_NO_TRANSLATION 170#ifndef QT_NO_TRANSLATION
133 void installTranslation( const QString& baseName ); 171 void installTranslation( const QString& baseName );
134#endif 172#endif
135 void mapToDefaultAction( QWSKeyEvent *ke, int defKey ); 173 void mapToDefaultAction( QWSKeyEvent *ke, int defKey );
136 void processQCopFile(); 174 void processQCopFile();
137 175
138#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 176#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
139 QCopChannel *sysChannel; 177 QCopChannel *sysChannel;
140 QCopChannel *pidChannel; 178 QCopChannel *pidChannel;
141#endif 179#endif
142 QPEApplicationData *d; 180 QPEApplicationData *d;
143 181
144 bool reserved_sh; 182 bool reserved_sh;
145 183
146 184
147 185
148}; 186};
149 187
150inline void QPEApplication::showDialog( QDialog* d, bool nomax ) 188inline void QPEApplication::showDialog( QDialog* d, bool nomax )
151{ 189{
152 QSize sh = d->sizeHint(); 190 QSize sh = d->sizeHint();
153 int w = QMAX(sh.width(),d->width()); 191 int w = QMAX(sh.width(),d->width());
154 int h = QMAX(sh.height(),d->height()); 192 int h = QMAX(sh.height(),d->height());
155 if ( !nomax 193 if ( !nomax
156 && ( w > qApp->desktop()->width()*3/4 194 && ( w > qApp->desktop()->width()*3/4
157 || h > qApp->desktop()->height()*3/4 ) ) 195 || h > qApp->desktop()->height()*3/4 ) )
158 { 196 {
159 d->showMaximized(); 197 d->showMaximized();
160 } else { 198 } else {
161 d->resize(w,h); 199 d->resize(w,h);
162 d->show(); 200 d->show();
163 } 201 }
164} 202}
165 203
166inline int QPEApplication::execDialog( QDialog* d, bool nomax ) 204inline int QPEApplication::execDialog( QDialog* d, bool nomax )
167{ 205{
168 showDialog(d,nomax); 206 showDialog(d,nomax);
169 return d->exec(); 207 return d->exec();
170} 208}
171 209
172enum Transformation { Rot0, Rot90, Rot180, Rot270 }; /* from qgfxtransformed_qws.cpp */ 210enum Transformation { Rot0, Rot90, Rot180, Rot270 }; /* from qgfxtransformed_qws.cpp */
173 211
174inline int TransToDeg ( Transformation t ) 212inline int TransToDeg ( Transformation t )
175{ 213{
176 int d = static_cast<int>( t ); 214 int d = static_cast<int>( t );
177 return d * 90; 215 return d * 90;
178} 216}
179 217
180inline Transformation DegToTrans ( int d ) 218inline Transformation DegToTrans ( int d )
181{ 219{
182 Transformation t = static_cast<Transformation>( d / 90 ); 220 Transformation t = static_cast<Transformation>( d / 90 );
183 return t; 221 return t;
184} 222}
185 223
186/* 224/*
187 * Set current rotation of Opie, and rotation for newly started apps. 225 * Set current rotation of Opie, and rotation for newly started apps.
188 * Differs from setDefaultRotation in that 1) it rotates currently running apps, 226 * Differs from setDefaultRotation in that 1) it rotates currently running apps,
189 * and 2) does not set deforient or save orientation to qpe.conf. 227 * and 2) does not set deforient or save orientation to qpe.conf.
190 */ 228 */
191 229
192inline void QPEApplication::setCurrentRotation( int r ) 230inline void QPEApplication::setCurrentRotation( int r )
193{ 231{
194 // setTransformation has been introduced in Qt/Embedded 2.3.4 snapshots 232 // setTransformation has been introduced in Qt/Embedded 2.3.4 snapshots
195 // for compatibility with the SharpROM use fallback to setDefaultTransformation() 233 // for compatibility with the SharpROM use fallback to setDefaultTransformation()
196#if QT_VERSION > 233 234#if QT_VERSION > 233
197 Transformation e = DegToTrans( r ); 235 Transformation e = DegToTrans( r );
198 ::setenv( "QWS_DISPLAY", QString( "Transformed:Rot%1:0" ).arg( r ).latin1(), 1 ); 236 ::setenv( "QWS_DISPLAY", QString( "Transformed:Rot%1:0" ).arg( r ).latin1(), 1 );
199 qApp->desktop()->qwsDisplay()->setTransformation( e ); 237 qApp->desktop()->qwsDisplay()->setTransformation( e );
200#else 238#else
201 setDefaultRotation( r ); 239 setDefaultRotation( r );
202#endif 240#endif
203} 241}
204 242
205 243
206#endif 244#endif