author | ar <ar> | 2005-03-10 16:21:07 (UTC) |
---|---|---|
committer | ar <ar> | 2005-03-10 16:21:07 (UTC) |
commit | 3bf4809c4f2263f0130472c41aa6c85e46e61db9 (patch) (unidiff) | |
tree | 82c34fddb63bb6ca8cbd53709ab2642795241d38 /library/qpeapplication.cpp | |
parent | 95a99e7b75eddc5629e839698b762f594be42b9f (diff) | |
download | opie-3bf4809c4f2263f0130472c41aa6c85e46e61db9.zip opie-3bf4809c4f2263f0130472c41aa6c85e46e61db9.tar.gz opie-3bf4809c4f2263f0130472c41aa6c85e46e61db9.tar.bz2 |
- implement nomax.patch from openembedded
-rw-r--r-- | library/qpeapplication.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/library/qpeapplication.cpp b/library/qpeapplication.cpp index 953f9d0..0f3e4a4 100644 --- a/library/qpeapplication.cpp +++ b/library/qpeapplication.cpp | |||
@@ -1,856 +1,858 @@ | |||
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 | #define QTOPIA_INTERNAL_LANGLIST | 20 | #define QTOPIA_INTERNAL_LANGLIST |
21 | #include <stdlib.h> | 21 | #include <stdlib.h> |
22 | #include <unistd.h> | 22 | #include <unistd.h> |
23 | #ifndef Q_OS_MACX | 23 | #ifndef Q_OS_MACX |
24 | #include <linux/limits.h> // needed for some toolchains (PATH_MAX) | 24 | #include <linux/limits.h> // needed for some toolchains (PATH_MAX) |
25 | #endif | 25 | #endif |
26 | #include <qfile.h> | 26 | #include <qfile.h> |
27 | #include <qqueue.h> | 27 | #include <qqueue.h> |
28 | #ifdef Q_WS_QWS | 28 | #ifdef Q_WS_QWS |
29 | #ifndef QT_NO_COP | 29 | #ifndef QT_NO_COP |
30 | #if QT_VERSION <= 231 | 30 | #if QT_VERSION <= 231 |
31 | #define private public | 31 | #define private public |
32 | #define sendLocally processEvent | 32 | #define sendLocally processEvent |
33 | #include "qcopenvelope_qws.h" | 33 | #include "qcopenvelope_qws.h" |
34 | #undef private | 34 | #undef private |
35 | #else | 35 | #else |
36 | #include "qcopenvelope_qws.h" | 36 | #include "qcopenvelope_qws.h" |
37 | #endif | 37 | #endif |
38 | #endif | 38 | #endif |
39 | #include <qwindowsystem_qws.h> | 39 | #include <qwindowsystem_qws.h> |
40 | #endif | 40 | #endif |
41 | #include <qtextstream.h> | 41 | #include <qtextstream.h> |
42 | #include <qpalette.h> | 42 | #include <qpalette.h> |
43 | #include <qbuffer.h> | 43 | #include <qbuffer.h> |
44 | #include <qptrdict.h> | 44 | #include <qptrdict.h> |
45 | #include <qregexp.h> | 45 | #include <qregexp.h> |
46 | #include <qdir.h> | 46 | #include <qdir.h> |
47 | #include <qlabel.h> | 47 | #include <qlabel.h> |
48 | #include <qdialog.h> | 48 | #include <qdialog.h> |
49 | #include <qdragobject.h> | 49 | #include <qdragobject.h> |
50 | #include <qtextcodec.h> | 50 | #include <qtextcodec.h> |
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 >= 0x030000 | 63 | #if QT_VERSION >= 0x030000 |
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 | #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 | ||
103 | static bool useBigPixmaps = 0; | 103 | static bool useBigPixmaps = 0; |
104 | 104 | ||
105 | class HackWidget : public QWidget | 105 | class HackWidget : public QWidget |
106 | { | 106 | { |
107 | public: | 107 | public: |
108 | bool needsOk() | 108 | bool needsOk() |
109 | { return (getWState() & WState_Reserved1 ); } | 109 | { return (getWState() & WState_Reserved1 ); } |
110 | 110 | ||
111 | QRect normalGeometry() | 111 | QRect normalGeometry() |
112 | { return topData()->normalGeometry; }; | 112 | { return topData()->normalGeometry; }; |
113 | }; | 113 | }; |
114 | 114 | ||
115 | class QPEApplicationData | 115 | class QPEApplicationData |
116 | { | 116 | { |
117 | public: | 117 | public: |
118 | QPEApplicationData ( ) : | 118 | QPEApplicationData ( ) : |
119 | presstimer( 0 ), presswidget( 0 ), rightpressed( false ), kbgrabbed( false ), | 119 | presstimer( 0 ), presswidget( 0 ), rightpressed( false ), kbgrabbed( false ), |
120 | notbusysent( false ), preloaded( false ), forceshow( false ), nomaximize( false ), | 120 | notbusysent( false ), preloaded( false ), forceshow( false ), nomaximize( false ), |
121 | keep_running( true ), qcopQok( false ), | 121 | keep_running( true ), qcopQok( false ), |
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 | QGuardedPtr<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) ) { |
219 | mw->resize(s); | 219 | mw->resize(s); |
220 | mw->move(p); | 220 | mw->move(p); |
221 | 221 | ||
222 | if ( max && !nomaximize ) { | 222 | if ( max && !nomaximize ) { |
223 | mw->showMaximized(); | 223 | mw->showMaximized(); |
224 | } else { | 224 | } else { |
225 | mw->show(); | 225 | mw->show(); |
226 | } | 226 | } |
227 | } else { | 227 | } else { |
228 | QPEApplication::showDialog((QDialog*)mw,nomaximize); | 228 | QPEApplication::showDialog((QDialog*)mw,nomaximize); |
229 | } | 229 | } |
230 | } else { | 230 | } else { |
231 | if ( read_widget_rect(strName, max, p, s) && validate_widget_size(mw, p, s) ) { | 231 | if ( read_widget_rect(strName, max, p, s) && validate_widget_size(mw, p, s) ) { |
232 | mw->resize(s); | 232 | mw->resize(s); |
233 | mw->move(p); | 233 | mw->move(p); |
234 | } else { //no stored rectangle, make an estimation | 234 | } else { //no stored rectangle, make an estimation |
235 | int x = (qApp->desktop()->width()-mw->frameGeometry().width())/2; | 235 | int x = (qApp->desktop()->width()-mw->frameGeometry().width())/2; |
236 | int y = (qApp->desktop()->height()-mw->frameGeometry().height())/2; | 236 | int y = (qApp->desktop()->height()-mw->frameGeometry().height())/2; |
237 | mw->move( QMAX(x,0), QMAX(y,0) ); | 237 | mw->move( QMAX(x,0), QMAX(y,0) ); |
238 | #ifdef Q_WS_QWS | 238 | #ifdef Q_WS_QWS |
239 | if ( !nomaximize ) | 239 | if ( !nomaximize ) |
240 | mw->showMaximized(); | 240 | mw->showMaximized(); |
241 | #endif | 241 | #endif |
242 | } | 242 | } |
243 | if ( max && !nomaximize ) | 243 | if ( max && !nomaximize ) |
244 | mw->showMaximized(); | 244 | mw->showMaximized(); |
245 | else | 245 | else |
246 | mw->show(); | 246 | mw->show(); |
247 | } | 247 | } |
248 | } | 248 | } |
249 | } | 249 | } |
250 | 250 | ||
251 | static bool read_widget_rect(const QString &app, bool &maximized, QPoint &p, QSize &s) | 251 | static bool read_widget_rect(const QString &app, bool &maximized, QPoint &p, QSize &s) |
252 | { | 252 | { |
253 | #ifndef OPIE_NO_WINDOWED | ||
253 | maximized = TRUE; | 254 | maximized = TRUE; |
254 | // 350 is the trigger in qwsdefaultdecoration for providing a resize button | 255 | // 350 is the trigger in qwsdefaultdecoration for providing a resize button |
255 | if ( qApp->desktop()->width() <= 350 ) | 256 | if ( qApp->desktop()->width() <= 350 ) |
256 | return FALSE; | 257 | return FALSE; |
257 | 258 | ||
258 | Config cfg( "qpe" ); | 259 | Config cfg( "qpe" ); |
259 | cfg.setGroup("ApplicationPositions"); | 260 | cfg.setGroup("ApplicationPositions"); |
260 | QString str = cfg.readEntry( app, QString::null ); | 261 | QString str = cfg.readEntry( app, QString::null ); |
261 | QStringList l = QStringList::split(",", str); | 262 | QStringList l = QStringList::split(",", str); |
262 | 263 | ||
263 | if ( l.count() == 5) { | 264 | if ( l.count() == 5) { |
264 | p.setX( l[0].toInt() ); | 265 | p.setX( l[0].toInt() ); |
265 | p.setY( l[1].toInt() ); | 266 | p.setY( l[1].toInt() ); |
266 | 267 | ||
267 | s.setWidth( l[2].toInt() ); | 268 | s.setWidth( l[2].toInt() ); |
268 | s.setHeight( l[3].toInt() ); | 269 | s.setHeight( l[3].toInt() ); |
269 | 270 | ||
270 | maximized = l[4].toInt(); | 271 | maximized = l[4].toInt(); |
271 | 272 | ||
272 | return TRUE; | 273 | return TRUE; |
273 | } | 274 | } |
274 | 275 | #endif | |
275 | return FALSE; | 276 | return FALSE; |
276 | } | 277 | } |
277 | 278 | ||
278 | 279 | ||
279 | static bool validate_widget_size(const QWidget *w, QPoint &p, QSize &s) | 280 | static bool validate_widget_size(const QWidget *w, QPoint &p, QSize &s) |
280 | { | 281 | { |
281 | #ifndef Q_WS_QWS | 282 | #ifndef Q_WS_QWS |
282 | QRect qt_maxWindowRect = qApp->desktop()->geometry(); | 283 | QRect qt_maxWindowRect = qApp->desktop()->geometry(); |
283 | #endif | 284 | #endif |
284 | int maxX = qt_maxWindowRect.width(); | 285 | int maxX = qt_maxWindowRect.width(); |
285 | int maxY = qt_maxWindowRect.height(); | 286 | int maxY = qt_maxWindowRect.height(); |
286 | int wWidth = s.width() + ( w->frameGeometry().width() - w->geometry().width() ); | 287 | int wWidth = s.width() + ( w->frameGeometry().width() - w->geometry().width() ); |
287 | int wHeight = s.height() + ( w->frameGeometry().height() - w->geometry().height() ); | 288 | int wHeight = s.height() + ( w->frameGeometry().height() - w->geometry().height() ); |
288 | 289 | ||
289 | // total window size is not allowed to be larger than desktop window size | 290 | // total window size is not allowed to be larger than desktop window size |
290 | if ( ( wWidth >= maxX ) && ( wHeight >= maxY ) ) | 291 | if ( ( wWidth >= maxX ) && ( wHeight >= maxY ) ) |
291 | return FALSE; | 292 | return FALSE; |
292 | 293 | ||
293 | if ( wWidth > maxX ) { | 294 | if ( wWidth > maxX ) { |
294 | s.setWidth( maxX - (w->frameGeometry().width() - w->geometry().width() ) ); | 295 | s.setWidth( maxX - (w->frameGeometry().width() - w->geometry().width() ) ); |
295 | wWidth = maxX; | 296 | wWidth = maxX; |
296 | } | 297 | } |
297 | 298 | ||
298 | if ( wHeight > maxY ) { | 299 | if ( wHeight > maxY ) { |
299 | s.setHeight( maxY - (w->frameGeometry().height() - w->geometry().height() ) ); | 300 | s.setHeight( maxY - (w->frameGeometry().height() - w->geometry().height() ) ); |
300 | wHeight = maxY; | 301 | wHeight = maxY; |
301 | } | 302 | } |
302 | 303 | ||
303 | // any smaller than this and the maximize/close/help buttons will be overlapping | 304 | // any smaller than this and the maximize/close/help buttons will be overlapping |
304 | if ( wWidth < 80 || wHeight < 60 ) | 305 | if ( wWidth < 80 || wHeight < 60 ) |
305 | return FALSE; | 306 | return FALSE; |
306 | 307 | ||
307 | if ( p.x() < 0 ) | 308 | if ( p.x() < 0 ) |
308 | p.setX(0); | 309 | p.setX(0); |
309 | if ( p.y() < 0 ) | 310 | if ( p.y() < 0 ) |
310 | p.setY(0); | 311 | p.setY(0); |
311 | 312 | ||
312 | if ( p.x() + wWidth > maxX ) | 313 | if ( p.x() + wWidth > maxX ) |
313 | p.setX( maxX - wWidth ); | 314 | p.setX( maxX - wWidth ); |
314 | if ( p.y() + wHeight > maxY ) | 315 | if ( p.y() + wHeight > maxY ) |
315 | p.setY( maxY - wHeight ); | 316 | p.setY( maxY - wHeight ); |
316 | 317 | ||
317 | return TRUE; | 318 | return TRUE; |
318 | } | 319 | } |
319 | 320 | ||
320 | static void store_widget_rect(QWidget *w, QString &app) | 321 | static void store_widget_rect(QWidget *w, QString &app) |
321 | { | 322 | { |
322 | if( !w ) | 323 | if( !w ) |
323 | return; | 324 | return; |
324 | 325 | #ifndef OPIE_NO_WINDOWED | |
325 | // 350 is the trigger in qwsdefaultdecoration for providing a resize button | 326 | // 350 is the trigger in qwsdefaultdecoration for providing a resize button |
326 | if ( qApp->desktop()->width() <= 350 ) | 327 | if ( qApp->desktop()->width() <= 350 ) |
327 | return; | 328 | return; |
328 | // we use these to map the offset of geometry and pos. ( we can only use normalGeometry to | 329 | // we use these to map the offset of geometry and pos. ( we can only use normalGeometry to |
329 | // get the non-maximized version, so we have to do it the hard way ) | 330 | // get the non-maximized version, so we have to do it the hard way ) |
330 | int offsetX = w->x() - w->geometry().left(); | 331 | int offsetX = w->x() - w->geometry().left(); |
331 | int offsetY = w->y() - w->geometry().top(); | 332 | int offsetY = w->y() - w->geometry().top(); |
332 | 333 | ||
333 | QRect r; | 334 | QRect r; |
334 | if ( w->isMaximized() ) | 335 | if ( w->isMaximized() ) |
335 | r = ( (HackWidget *) w)->normalGeometry(); | 336 | r = ( (HackWidget *) w)->normalGeometry(); |
336 | else | 337 | else |
337 | r = w->geometry(); | 338 | r = w->geometry(); |
338 | 339 | ||
339 | // Stores the window placement as pos(), size() (due to the offset mapping) | 340 | // Stores the window placement as pos(), size() (due to the offset mapping) |
340 | Config cfg( "qpe" ); | 341 | Config cfg( "qpe" ); |
341 | cfg.setGroup("ApplicationPositions"); | 342 | cfg.setGroup("ApplicationPositions"); |
342 | QString s; | 343 | QString s; |
343 | s.sprintf("%d,%d,%d,%d,%d", r.left() + offsetX, r.top() + offsetY, r.width(), r.height(), w->isMaximized() ); | 344 | s.sprintf("%d,%d,%d,%d,%d", r.left() + offsetX, r.top() + offsetY, r.width(), r.height(), w->isMaximized() ); |
344 | cfg.writeEntry( app, s ); | 345 | cfg.writeEntry( app, s ); |
346 | #endif | ||
345 | } | 347 | } |
346 | 348 | ||
347 | static bool setWidgetCaptionFromAppName( QWidget* /*mw*/, const QString& /*appName*/, const QString& /*appsPath*/ ) | 349 | static bool setWidgetCaptionFromAppName( QWidget* /*mw*/, const QString& /*appName*/, const QString& /*appsPath*/ ) |
348 | { | 350 | { |
349 | /* | 351 | /* |
350 | // This works but disable it for now until it is safe to apply | 352 | // This works but disable it for now until it is safe to apply |
351 | // What is does is scan the .desktop files of all the apps for | 353 | // What is does is scan the .desktop files of all the apps for |
352 | // the applnk that has the corresponding argv[0] as this program | 354 | // the applnk that has the corresponding argv[0] as this program |
353 | // then it uses the name stored in the .desktop file as the caption | 355 | // then it uses the name stored in the .desktop file as the caption |
354 | // for the main widget. This saves duplicating translations for | 356 | // for the main widget. This saves duplicating translations for |
355 | // the app name in the program and in the .desktop files. | 357 | // the app name in the program and in the .desktop files. |
356 | 358 | ||
357 | AppLnkSet apps( appsPath ); | 359 | AppLnkSet apps( appsPath ); |
358 | 360 | ||
359 | QList<AppLnk> appsList = apps.children(); | 361 | QList<AppLnk> appsList = apps.children(); |
360 | for ( QListIterator<AppLnk> it(appsList); it.current(); ++it ) { | 362 | for ( QListIterator<AppLnk> it(appsList); it.current(); ++it ) { |
361 | if ( (*it)->exec() == appName ) { | 363 | if ( (*it)->exec() == appName ) { |
362 | mw->setCaption( (*it)->name() ); | 364 | mw->setCaption( (*it)->name() ); |
363 | return TRUE; | 365 | return TRUE; |
364 | } | 366 | } |
365 | } | 367 | } |
366 | */ | 368 | */ |
367 | return FALSE; | 369 | return FALSE; |
368 | } | 370 | } |
369 | 371 | ||
370 | 372 | ||
371 | void show(QWidget* mw, bool nomax) | 373 | void show(QWidget* mw, bool nomax) |
372 | { | 374 | { |
373 | setWidgetCaptionFromAppName( mw, appName, QPEApplication::qpeDir() + "apps" ); | 375 | setWidgetCaptionFromAppName( mw, appName, QPEApplication::qpeDir() + "apps" ); |
374 | nomaximize = nomax; | 376 | nomaximize = nomax; |
375 | qpe_main_widget = mw; | 377 | qpe_main_widget = mw; |
376 | qcopQok = TRUE; | 378 | qcopQok = TRUE; |
377 | #ifndef QT_NO_COP | 379 | #ifndef QT_NO_COP |
378 | 380 | ||
379 | sendQCopQ(); | 381 | sendQCopQ(); |
380 | #endif | 382 | #endif |
381 | 383 | ||
382 | if ( preloaded ) { | 384 | if ( preloaded ) { |
383 | if (forceshow) | 385 | if (forceshow) |
384 | show_mx(mw, nomax, appName); | 386 | show_mx(mw, nomax, appName); |
385 | } | 387 | } |
386 | else if ( keep_running ) { | 388 | else if ( keep_running ) { |
387 | show_mx(mw, nomax, appName); | 389 | show_mx(mw, nomax, appName); |
388 | } | 390 | } |
389 | } | 391 | } |
390 | 392 | ||
391 | void loadTextCodecs() | 393 | void loadTextCodecs() |
392 | { | 394 | { |
393 | QString path = QPEApplication::qpeDir() + "plugins/textcodecs"; | 395 | QString path = QPEApplication::qpeDir() + "plugins/textcodecs"; |
394 | #ifdef Q_OS_MACX | 396 | #ifdef Q_OS_MACX |
395 | QDir dir( path, "lib*.dylib" ); | 397 | QDir dir( path, "lib*.dylib" ); |
396 | #else | 398 | #else |
397 | QDir dir( path, "lib*.so" ); | 399 | QDir dir( path, "lib*.so" ); |
398 | #endif | 400 | #endif |
399 | QStringList list; | 401 | QStringList list; |
400 | if ( dir. exists ( )) | 402 | if ( dir. exists ( )) |
401 | list = dir.entryList(); | 403 | list = dir.entryList(); |
402 | QStringList::Iterator it; | 404 | QStringList::Iterator it; |
403 | for ( it = list.begin(); it != list.end(); ++it ) { | 405 | for ( it = list.begin(); it != list.end(); ++it ) { |
404 | TextCodecInterface *iface = 0; | 406 | TextCodecInterface *iface = 0; |
405 | QLibrary *lib = new QLibrary( path + "/" + *it ); | 407 | QLibrary *lib = new QLibrary( path + "/" + *it ); |
406 | if ( lib->queryInterface( IID_QtopiaTextCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) { | 408 | if ( lib->queryInterface( IID_QtopiaTextCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) { |
407 | QValueList<int> mibs = iface->mibEnums(); | 409 | QValueList<int> mibs = iface->mibEnums(); |
408 | for (QValueList<int>::ConstIterator i = mibs.begin(); i != mibs.end(); ++i) { | 410 | for (QValueList<int>::ConstIterator i = mibs.begin(); i != mibs.end(); ++i) { |
409 | (void)iface->createForMib(*i); | 411 | (void)iface->createForMib(*i); |
410 | // ### it exists now; need to remember if we can delete it | 412 | // ### it exists now; need to remember if we can delete it |
411 | } | 413 | } |
412 | } | 414 | } |
413 | else { | 415 | else { |
414 | lib->unload(); | 416 | lib->unload(); |
415 | delete lib; | 417 | delete lib; |
416 | } | 418 | } |
417 | } | 419 | } |
418 | } | 420 | } |
419 | 421 | ||
420 | void loadImageCodecs() | 422 | void loadImageCodecs() |
421 | { | 423 | { |
422 | QString path = QPEApplication::qpeDir() + "plugins/imagecodecs"; | 424 | QString path = QPEApplication::qpeDir() + "plugins/imagecodecs"; |
423 | #ifdef Q_OS_MACX | 425 | #ifdef Q_OS_MACX |
424 | QDir dir( path, "lib*.dylib" ); | 426 | QDir dir( path, "lib*.dylib" ); |
425 | #else | 427 | #else |
426 | QDir dir( path, "lib*.so" ); | 428 | QDir dir( path, "lib*.so" ); |
427 | #endif | 429 | #endif |
428 | QStringList list; | 430 | QStringList list; |
429 | if ( dir. exists ( )) | 431 | if ( dir. exists ( )) |
430 | list = dir.entryList(); | 432 | list = dir.entryList(); |
431 | QStringList::Iterator it; | 433 | QStringList::Iterator it; |
432 | for ( it = list.begin(); it != list.end(); ++it ) { | 434 | for ( it = list.begin(); it != list.end(); ++it ) { |
433 | ImageCodecInterface *iface = 0; | 435 | ImageCodecInterface *iface = 0; |
434 | QLibrary *lib = new QLibrary( path + "/" + *it ); | 436 | QLibrary *lib = new QLibrary( path + "/" + *it ); |
435 | if ( lib->queryInterface( IID_QtopiaImageCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) { | 437 | if ( lib->queryInterface( IID_QtopiaImageCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) { |
436 | QStringList formats = iface->keys(); | 438 | QStringList formats = iface->keys(); |
437 | for (QStringList::ConstIterator i = formats.begin(); i != formats.end(); ++i) { | 439 | for (QStringList::ConstIterator i = formats.begin(); i != formats.end(); ++i) { |
438 | (void)iface->installIOHandler(*i); | 440 | (void)iface->installIOHandler(*i); |
439 | // ### it exists now; need to remember if we can delete it | 441 | // ### it exists now; need to remember if we can delete it |
440 | } | 442 | } |
441 | } | 443 | } |
442 | else { | 444 | else { |
443 | lib->unload(); | 445 | lib->unload(); |
444 | delete lib; | 446 | delete lib; |
445 | } | 447 | } |
446 | } | 448 | } |
447 | } | 449 | } |
448 | 450 | ||
449 | }; | 451 | }; |
450 | 452 | ||
451 | class ResourceMimeFactory : public QMimeSourceFactory | 453 | class ResourceMimeFactory : public QMimeSourceFactory |
452 | { | 454 | { |
453 | public: | 455 | public: |
454 | ResourceMimeFactory() : resImage( 0 ) | 456 | ResourceMimeFactory() : resImage( 0 ) |
455 | { | 457 | { |
456 | setFilePath( Global::helpPath() ); | 458 | setFilePath( Global::helpPath() ); |
457 | setExtensionType( "html", "text/html;charset=UTF-8" ); | 459 | setExtensionType( "html", "text/html;charset=UTF-8" ); |
458 | } | 460 | } |
459 | ~ResourceMimeFactory() { | 461 | ~ResourceMimeFactory() { |
460 | delete resImage; | 462 | delete resImage; |
461 | } | 463 | } |
462 | 464 | ||
463 | const QMimeSource* data( const QString& abs_name ) const | 465 | const QMimeSource* data( const QString& abs_name ) const |
464 | { | 466 | { |
465 | const QMimeSource * r = QMimeSourceFactory::data( abs_name ); | 467 | const QMimeSource * r = QMimeSourceFactory::data( abs_name ); |
466 | if ( !r ) { | 468 | if ( !r ) { |
467 | int sl = abs_name.length(); | 469 | int sl = abs_name.length(); |
468 | do { | 470 | do { |
469 | sl = abs_name.findRev( '/', sl - 1 ); | 471 | sl = abs_name.findRev( '/', sl - 1 ); |
470 | QString name = sl >= 0 ? abs_name.mid( sl + 1 ) : abs_name; | 472 | QString name = sl >= 0 ? abs_name.mid( sl + 1 ) : abs_name; |
471 | int dot = name.findRev( '.' ); | 473 | int dot = name.findRev( '.' ); |
472 | if ( dot >= 0 ) | 474 | if ( dot >= 0 ) |
473 | name = name.left( dot ); | 475 | name = name.left( dot ); |
474 | QImage img = Resource::loadImage( name ); | 476 | QImage img = Resource::loadImage( name ); |
475 | if ( !img.isNull() ) { | 477 | if ( !img.isNull() ) { |
476 | delete resImage; | 478 | delete resImage; |
477 | resImage = new QImageDrag( img ); | 479 | resImage = new QImageDrag( img ); |
478 | r = resImage; | 480 | r = resImage; |
479 | } | 481 | } |
480 | } | 482 | } |
481 | while ( !r && sl > 0 ); | 483 | while ( !r && sl > 0 ); |
482 | } | 484 | } |
483 | return r; | 485 | return r; |
484 | } | 486 | } |
485 | private: | 487 | private: |
486 | mutable QImageDrag *resImage; | 488 | mutable QImageDrag *resImage; |
487 | }; | 489 | }; |
488 | 490 | ||
489 | static int& hack(int& i) | 491 | static int& hack(int& i) |
490 | { | 492 | { |
491 | #if QT_VERSION <= 230 && defined(QT_NO_CODECS) | 493 | #if QT_VERSION <= 230 && defined(QT_NO_CODECS) |
492 | // These should be created, but aren't in Qt 2.3.0 | 494 | // These should be created, but aren't in Qt 2.3.0 |
493 | (void)new QUtf8Codec; | 495 | (void)new QUtf8Codec; |
494 | (void)new QUtf16Codec; | 496 | (void)new QUtf16Codec; |
495 | #endif | 497 | #endif |
496 | return i; | 498 | return i; |
497 | } | 499 | } |
498 | 500 | ||
499 | static int muted = 0; | 501 | static int muted = 0; |
500 | static int micMuted = 0; | 502 | static int micMuted = 0; |
501 | 503 | ||
502 | static void setVolume( int t = 0, int percent = -1 ) | 504 | static void setVolume( int t = 0, int percent = -1 ) |
503 | { | 505 | { |
504 | switch ( t ) { | 506 | switch ( t ) { |
505 | case 0: { | 507 | case 0: { |
506 | Config cfg( "qpe" ); | 508 | Config cfg( "qpe" ); |
507 | cfg.setGroup( "Volume" ); | 509 | cfg.setGroup( "Volume" ); |
508 | if ( percent < 0 ) | 510 | if ( percent < 0 ) |
509 | percent = cfg.readNumEntry( "VolumePercent", 50 ); | 511 | percent = cfg.readNumEntry( "VolumePercent", 50 ); |
510 | #ifndef QT_NO_SOUND | 512 | #ifndef QT_NO_SOUND |
511 | int fd = 0; | 513 | int fd = 0; |
512 | #ifdef QT_QWS_DEVFS | 514 | #ifdef QT_QWS_DEVFS |
513 | if ( ( fd = open( "/dev/sound/mixer", O_RDWR ) ) >= 0 ) { | 515 | if ( ( fd = open( "/dev/sound/mixer", O_RDWR ) ) >= 0 ) { |
514 | #else | 516 | #else |
515 | if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { | 517 | if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { |
516 | #endif | 518 | #endif |
517 | int vol = muted ? 0 : percent; | 519 | int vol = muted ? 0 : percent; |
518 | // set both channels to same volume | 520 | // set both channels to same volume |
519 | vol |= vol << 8; | 521 | vol |= vol << 8; |
520 | ioctl( fd, MIXER_WRITE( SOUND_MIXER_VOLUME ), &vol ); | 522 | ioctl( fd, MIXER_WRITE( SOUND_MIXER_VOLUME ), &vol ); |
521 | ::close( fd ); | 523 | ::close( fd ); |
522 | } | 524 | } |
523 | #endif | 525 | #endif |
524 | } | 526 | } |
525 | break; | 527 | break; |
526 | } | 528 | } |
527 | } | 529 | } |
528 | 530 | ||
529 | static void setMic( int t = 0, int percent = -1 ) | 531 | static void setMic( int t = 0, int percent = -1 ) |
530 | { | 532 | { |
531 | switch ( t ) { | 533 | switch ( t ) { |
532 | case 0: { | 534 | case 0: { |
533 | Config cfg( "qpe" ); | 535 | Config cfg( "qpe" ); |
534 | cfg.setGroup( "Volume" ); | 536 | cfg.setGroup( "Volume" ); |
535 | if ( percent < 0 ) | 537 | if ( percent < 0 ) |
536 | percent = cfg.readNumEntry( "Mic", 50 ); | 538 | percent = cfg.readNumEntry( "Mic", 50 ); |
537 | 539 | ||
538 | #ifndef QT_NO_SOUND | 540 | #ifndef QT_NO_SOUND |
539 | int fd = 0; | 541 | int fd = 0; |
540 | int mic = micMuted ? 0 : percent; | 542 | int mic = micMuted ? 0 : percent; |
541 | #ifdef QT_QWS_DEVFS | 543 | #ifdef QT_QWS_DEVFS |
542 | if ( ( fd = open( "/dev/sound/mixer", O_RDWR ) ) >= 0 ) { | 544 | if ( ( fd = open( "/dev/sound/mixer", O_RDWR ) ) >= 0 ) { |
543 | #else | 545 | #else |
544 | if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { | 546 | if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { |
545 | #endif | 547 | #endif |
546 | ioctl( fd, MIXER_WRITE( SOUND_MIXER_MIC ), &mic ); | 548 | ioctl( fd, MIXER_WRITE( SOUND_MIXER_MIC ), &mic ); |
547 | ::close( fd ); | 549 | ::close( fd ); |
548 | } | 550 | } |
549 | #endif | 551 | #endif |
550 | } | 552 | } |
551 | break; | 553 | break; |
552 | } | 554 | } |
553 | } | 555 | } |
554 | 556 | ||
555 | 557 | ||
556 | static void setBass( int t = 0, int percent = -1 ) | 558 | static void setBass( int t = 0, int percent = -1 ) |
557 | { | 559 | { |
558 | switch ( t ) { | 560 | switch ( t ) { |
559 | case 0: { | 561 | case 0: { |
560 | Config cfg( "qpe" ); | 562 | Config cfg( "qpe" ); |
561 | cfg.setGroup( "Volume" ); | 563 | cfg.setGroup( "Volume" ); |
562 | if ( percent < 0 ) | 564 | if ( percent < 0 ) |
563 | percent = cfg.readNumEntry( "BassPercent", 50 ); | 565 | percent = cfg.readNumEntry( "BassPercent", 50 ); |
564 | 566 | ||
565 | #ifndef QT_NO_SOUND | 567 | #ifndef QT_NO_SOUND |
566 | int fd = 0; | 568 | int fd = 0; |
567 | int bass = percent; | 569 | int bass = percent; |
568 | #ifdef QT_QWS_DEVFS | 570 | #ifdef QT_QWS_DEVFS |
569 | if ( ( fd = open( "/dev/sound/mixer", O_RDWR ) ) >= 0 ) { | 571 | if ( ( fd = open( "/dev/sound/mixer", O_RDWR ) ) >= 0 ) { |
570 | #else | 572 | #else |
571 | if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { | 573 | if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { |
572 | #endif | 574 | #endif |
573 | ioctl( fd, MIXER_WRITE( SOUND_MIXER_BASS ), &bass ); | 575 | ioctl( fd, MIXER_WRITE( SOUND_MIXER_BASS ), &bass ); |
574 | ::close( fd ); | 576 | ::close( fd ); |
575 | } | 577 | } |
576 | #endif | 578 | #endif |
577 | } | 579 | } |
578 | break; | 580 | break; |
579 | } | 581 | } |
580 | } | 582 | } |
581 | 583 | ||
582 | 584 | ||
583 | static void setTreble( int t = 0, int percent = -1 ) | 585 | static void setTreble( int t = 0, int percent = -1 ) |
584 | { | 586 | { |
585 | switch ( t ) { | 587 | switch ( t ) { |
586 | case 0: { | 588 | case 0: { |
587 | Config cfg( "qpe" ); | 589 | Config cfg( "qpe" ); |
588 | cfg.setGroup( "Volume" ); | 590 | cfg.setGroup( "Volume" ); |
589 | if ( percent < 0 ) | 591 | if ( percent < 0 ) |
590 | percent = cfg.readNumEntry( "TreblePercent", 50 ); | 592 | percent = cfg.readNumEntry( "TreblePercent", 50 ); |
591 | 593 | ||
592 | #ifndef QT_NO_SOUND | 594 | #ifndef QT_NO_SOUND |
593 | int fd = 0; | 595 | int fd = 0; |
594 | int treble = percent; | 596 | int treble = percent; |
595 | #ifdef QT_QWS_DEVFS | 597 | #ifdef QT_QWS_DEVFS |
596 | if ( ( fd = open( "/dev/sound/mixer", O_RDWR ) ) >= 0 ) { | 598 | if ( ( fd = open( "/dev/sound/mixer", O_RDWR ) ) >= 0 ) { |
597 | #else | 599 | #else |
598 | if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { | 600 | if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { |
599 | #endif | 601 | #endif |
600 | ioctl( fd, MIXER_WRITE( SOUND_MIXER_TREBLE ), &treble ); | 602 | ioctl( fd, MIXER_WRITE( SOUND_MIXER_TREBLE ), &treble ); |
601 | ::close( fd ); | 603 | ::close( fd ); |
602 | } | 604 | } |
603 | #endif | 605 | #endif |
604 | } | 606 | } |
605 | break; | 607 | break; |
606 | } | 608 | } |
607 | } | 609 | } |
608 | 610 | ||
609 | 611 | ||
610 | /** | 612 | /** |
611 | \class QPEApplication | 613 | \class QPEApplication |
612 | \brief The QPEApplication class implements various system services | 614 | \brief The QPEApplication class implements various system services |
613 | that are available to all Qtopia applications. | 615 | that are available to all Qtopia applications. |
614 | 616 | ||
615 | Simply by using QPEApplication instead of QApplication, a standard Qt | 617 | Simply by using QPEApplication instead of QApplication, a standard Qt |
616 | application becomes a Qtopia application. It automatically follows | 618 | application becomes a Qtopia application. It automatically follows |
617 | style changes, quits and raises, and in the | 619 | style changes, quits and raises, and in the |
618 | case of \link docwidget.html document-oriented\endlink applications, | 620 | case of \link docwidget.html document-oriented\endlink applications, |
619 | changes the currently displayed document in response to the environment. | 621 | changes the currently displayed document in response to the environment. |
620 | 622 | ||
621 | To create a \link docwidget.html document-oriented\endlink | 623 | To create a \link docwidget.html document-oriented\endlink |
622 | application use showMainDocumentWidget(); to create a | 624 | application use showMainDocumentWidget(); to create a |
623 | non-document-oriented application use showMainWidget(). The | 625 | non-document-oriented application use showMainWidget(). The |
624 | keepRunning() function indicates whether the application will | 626 | keepRunning() function indicates whether the application will |
625 | continue running after it's processed the last \link qcop.html | 627 | continue running after it's processed the last \link qcop.html |
626 | QCop\endlink message. This can be changed using setKeepRunning(). | 628 | QCop\endlink message. This can be changed using setKeepRunning(). |
627 | 629 | ||
628 | A variety of signals are emitted when certain events occur, for | 630 | A variety of signals are emitted when certain events occur, for |
629 | example, timeChanged(), clockChanged(), weekChanged(), | 631 | example, timeChanged(), clockChanged(), weekChanged(), |
630 | dateFormatChanged() and volumeChanged(). If the application receives | 632 | dateFormatChanged() and volumeChanged(). If the application receives |
631 | a \link qcop.html QCop\endlink message on the application's | 633 | a \link qcop.html QCop\endlink message on the application's |
632 | QPE/Application/\e{appname} channel, the appMessage() signal is | 634 | QPE/Application/\e{appname} channel, the appMessage() signal is |
633 | emitted. There are also flush() and reload() signals, which | 635 | emitted. There are also flush() and reload() signals, which |
634 | are emitted when synching begins and ends respectively - upon these | 636 | are emitted when synching begins and ends respectively - upon these |
635 | signals, the application should save and reload any data | 637 | signals, the application should save and reload any data |
636 | files that are involved in synching. Most of these signals will initially | 638 | files that are involved in synching. Most of these signals will initially |
637 | be received and unfiltered through the appMessage() signal. | 639 | be received and unfiltered through the appMessage() signal. |
638 | 640 | ||
639 | This class also provides a set of useful static functions. The | 641 | This class also provides a set of useful static functions. The |
640 | qpeDir() and documentDir() functions return the respective paths. | 642 | qpeDir() and documentDir() functions return the respective paths. |
641 | The grabKeyboard() and ungrabKeyboard() functions are used to | 643 | The grabKeyboard() and ungrabKeyboard() functions are used to |
642 | control whether the application takes control of the device's | 644 | control whether the application takes control of the device's |
643 | physical buttons (e.g. application launch keys). The stylus' mode of | 645 | physical buttons (e.g. application launch keys). The stylus' mode of |
644 | operation is set with setStylusOperation() and retrieved with | 646 | operation is set with setStylusOperation() and retrieved with |
645 | stylusOperation(). There are also setInputMethodHint() and | 647 | stylusOperation(). There are also setInputMethodHint() and |
646 | inputMethodHint() functions. | 648 | inputMethodHint() functions. |
647 | 649 | ||
648 | \ingroup qtopiaemb | 650 | \ingroup qtopiaemb |
649 | */ | 651 | */ |
650 | 652 | ||
651 | /*! | 653 | /*! |
652 | \fn void QPEApplication::clientMoused() | 654 | \fn void QPEApplication::clientMoused() |
653 | 655 | ||
654 | \internal | 656 | \internal |
655 | */ | 657 | */ |
656 | 658 | ||
657 | /*! | 659 | /*! |
658 | \fn void QPEApplication::timeChanged(); | 660 | \fn void QPEApplication::timeChanged(); |
659 | This signal is emitted when the time changes outside the normal | 661 | This signal is emitted when the time changes outside the normal |
660 | passage of time, i.e. if the time is set backwards or forwards. | 662 | passage of time, i.e. if the time is set backwards or forwards. |
661 | */ | 663 | */ |
662 | 664 | ||
663 | /*! | 665 | /*! |
664 | \fn void QPEApplication::clockChanged( bool ampm ); | 666 | \fn void QPEApplication::clockChanged( bool ampm ); |
665 | 667 | ||
666 | This signal is emitted when the user changes the clock's style. If | 668 | This signal is emitted when the user changes the clock's style. If |
667 | \a ampm is TRUE, the user wants a 12-hour AM/PM clock, otherwise, | 669 | \a ampm is TRUE, the user wants a 12-hour AM/PM clock, otherwise, |
668 | they want a 24-hour clock. | 670 | they want a 24-hour clock. |
669 | */ | 671 | */ |
670 | 672 | ||
671 | /*! | 673 | /*! |
672 | \fn void QPEApplication::volumeChanged( bool muted ) | 674 | \fn void QPEApplication::volumeChanged( bool muted ) |
673 | 675 | ||
674 | This signal is emitted whenever the mute state is changed. If \a | 676 | This signal is emitted whenever the mute state is changed. If \a |
675 | muted is TRUE, then sound output has been muted. | 677 | muted is TRUE, then sound output has been muted. |
676 | */ | 678 | */ |
677 | 679 | ||
678 | /*! | 680 | /*! |
679 | \fn void QPEApplication::weekChanged( bool startOnMonday ) | 681 | \fn void QPEApplication::weekChanged( bool startOnMonday ) |
680 | 682 | ||
681 | This signal is emitted if the week start day is changed. If \a | 683 | This signal is emitted if the week start day is changed. If \a |
682 | startOnMonday is TRUE then the first day of the week is Monday; if | 684 | startOnMonday is TRUE then the first day of the week is Monday; if |
683 | \a startOnMonday is FALSE then the first day of the week is | 685 | \a startOnMonday is FALSE then the first day of the week is |
684 | Sunday. | 686 | Sunday. |
685 | */ | 687 | */ |
686 | 688 | ||
687 | /*! | 689 | /*! |
688 | \fn void QPEApplication::dateFormatChanged(DateFormat) | 690 | \fn void QPEApplication::dateFormatChanged(DateFormat) |
689 | 691 | ||
690 | This signal is emitted whenever the date format is changed. | 692 | This signal is emitted whenever the date format is changed. |
691 | */ | 693 | */ |
692 | 694 | ||
693 | /*! | 695 | /*! |
694 | \fn void QPEApplication::flush() | 696 | \fn void QPEApplication::flush() |
695 | 697 | ||
696 | ### | 698 | ### |
697 | */ | 699 | */ |
698 | 700 | ||
699 | /*! | 701 | /*! |
700 | \fn void QPEApplication::reload() | 702 | \fn void QPEApplication::reload() |
701 | 703 | ||
702 | */ | 704 | */ |
703 | 705 | ||
704 | 706 | ||
705 | 707 | ||
706 | void QPEApplication::processQCopFile() | 708 | void QPEApplication::processQCopFile() |
707 | { | 709 | { |
708 | QString qcopfn("/tmp/qcop-msg-"); | 710 | QString qcopfn("/tmp/qcop-msg-"); |
709 | qcopfn += d->appName; // append command name | 711 | qcopfn += d->appName; // append command name |
710 | 712 | ||
711 | QFile f(qcopfn); | 713 | QFile f(qcopfn); |
712 | if ( f.open(IO_ReadWrite) ) { | 714 | if ( f.open(IO_ReadWrite) ) { |
713 | #ifndef Q_OS_WIN32 | 715 | #ifndef Q_OS_WIN32 |
714 | flock(f.handle(), LOCK_EX); | 716 | flock(f.handle(), LOCK_EX); |
715 | #endif | 717 | #endif |
716 | QDataStream ds(&f); | 718 | QDataStream ds(&f); |
717 | QCString channel, message; | 719 | QCString channel, message; |
718 | QByteArray data; | 720 | QByteArray data; |
719 | while(!ds.atEnd()) { | 721 | while(!ds.atEnd()) { |
720 | ds >> channel >> message >> data; | 722 | ds >> channel >> message >> data; |
721 | d->enqueueQCop(channel,message,data); | 723 | d->enqueueQCop(channel,message,data); |
722 | } | 724 | } |
723 | ::ftruncate(f.handle(), 0); | 725 | ::ftruncate(f.handle(), 0); |
724 | #ifndef Q_OS_WIN32 | 726 | #ifndef Q_OS_WIN32 |
725 | f.flush(); | 727 | f.flush(); |
726 | flock(f.handle(), LOCK_UN); | 728 | flock(f.handle(), LOCK_UN); |
727 | #endif | 729 | #endif |
728 | } | 730 | } |
729 | #endif | 731 | #endif |
730 | } | 732 | } |
731 | 733 | ||
732 | 734 | ||
733 | /*! | 735 | /*! |
734 | \fn void QPEApplication::appMessage( const QCString& msg, const QByteArray& data ) | 736 | \fn void QPEApplication::appMessage( const QCString& msg, const QByteArray& data ) |
735 | 737 | ||
736 | This signal is emitted when a message is received on this | 738 | This signal is emitted when a message is received on this |
737 | application's QPE/Application/<i>appname</i> \link qcop.html | 739 | application's QPE/Application/<i>appname</i> \link qcop.html |
738 | QCop\endlink channel. | 740 | QCop\endlink channel. |
739 | 741 | ||
740 | The slot to which you connect this signal uses \a msg and \a data | 742 | The slot to which you connect this signal uses \a msg and \a data |
741 | in the following way: | 743 | in the following way: |
742 | 744 | ||
743 | \code | 745 | \code |
744 | void MyWidget::receive( const QCString& msg, const QByteArray& data ) | 746 | void MyWidget::receive( const QCString& msg, const QByteArray& data ) |
745 | { | 747 | { |
746 | QDataStream stream( data, IO_ReadOnly ); | 748 | QDataStream stream( data, IO_ReadOnly ); |
747 | if ( msg == "someMessage(int,int,int)" ) { | 749 | if ( msg == "someMessage(int,int,int)" ) { |
748 | int a,b,c; | 750 | int a,b,c; |
749 | stream >> a >> b >> c; | 751 | stream >> a >> b >> c; |
750 | ... | 752 | ... |
751 | } else if ( msg == "otherMessage(QString)" ) { | 753 | } else if ( msg == "otherMessage(QString)" ) { |
752 | ... | 754 | ... |
753 | } | 755 | } |
754 | } | 756 | } |
755 | \endcode | 757 | \endcode |
756 | 758 | ||
757 | \sa qcop.html | 759 | \sa qcop.html |
758 | Note that messages received here may be processed by qpe application | 760 | Note that messages received here may be processed by qpe application |
759 | and emitted as signals, such as flush() and reload(). | 761 | and emitted as signals, such as flush() and reload(). |
760 | */ | 762 | */ |
761 | 763 | ||
762 | #ifndef QT_NO_TRANSLATION | 764 | #ifndef QT_NO_TRANSLATION |
763 | static void qtopia_loadTranslations( const QStringList& qms ) | 765 | static void qtopia_loadTranslations( const QStringList& qms ) |
764 | { | 766 | { |
765 | QStringList langs = Global::languageList(); | 767 | QStringList langs = Global::languageList(); |
766 | 768 | ||
767 | for (QStringList::ConstIterator it = langs.begin(); it!=langs.end(); ++it) { | 769 | for (QStringList::ConstIterator it = langs.begin(); it!=langs.end(); ++it) { |
768 | QString lang = *it; | 770 | QString lang = *it; |
769 | 771 | ||
770 | QTranslator * trans; | 772 | QTranslator * trans; |
771 | QString tfn; | 773 | QString tfn; |
772 | 774 | ||
773 | for (QStringList::ConstIterator qmit = qms.begin(); qmit!=qms.end(); ++qmit) { | 775 | for (QStringList::ConstIterator qmit = qms.begin(); qmit!=qms.end(); ++qmit) { |
774 | trans = new QTranslator(qApp); | 776 | trans = new QTranslator(qApp); |
775 | tfn = QPEApplication::qpeDir() + "i18n/" + lang + "/" + *qmit + ".qm"; | 777 | tfn = QPEApplication::qpeDir() + "i18n/" + lang + "/" + *qmit + ".qm"; |
776 | if ( trans->load( tfn )) | 778 | if ( trans->load( tfn )) |
777 | qApp->installTranslator( trans ); | 779 | qApp->installTranslator( trans ); |
778 | else | 780 | else |
779 | delete trans; | 781 | delete trans; |
780 | } | 782 | } |
781 | } | 783 | } |
782 | } | 784 | } |
783 | #endif | 785 | #endif |
784 | 786 | ||
785 | /* | 787 | /* |
786 | Turn off qDebug in release mode | 788 | Turn off qDebug in release mode |
787 | */ | 789 | */ |
788 | static void qtopiaMsgHandler(QtMsgType type, const char* msg) | 790 | static void qtopiaMsgHandler(QtMsgType type, const char* msg) |
789 | { | 791 | { |
790 | switch ( type ) { | 792 | switch ( type ) { |
791 | case QtDebugMsg: | 793 | case QtDebugMsg: |
792 | #ifdef QT_DEBUG | 794 | #ifdef QT_DEBUG |
793 | fprintf( stderr, "Debug: %s\n", msg ); | 795 | fprintf( stderr, "Debug: %s\n", msg ); |
794 | #endif | 796 | #endif |
795 | break; | 797 | break; |
796 | case QtWarningMsg: | 798 | case QtWarningMsg: |
797 | #ifdef QT_DEBUG | 799 | #ifdef QT_DEBUG |
798 | fprintf( stderr, "Warning: %s\n", msg ); | 800 | fprintf( stderr, "Warning: %s\n", msg ); |
799 | #endif | 801 | #endif |
800 | break; | 802 | break; |
801 | case QtFatalMsg: | 803 | case QtFatalMsg: |
802 | fprintf( stderr, "Fatal: %s\n", msg ); | 804 | fprintf( stderr, "Fatal: %s\n", msg ); |
803 | abort(); | 805 | abort(); |
804 | } | 806 | } |
805 | } | 807 | } |
806 | 808 | ||
807 | /*! | 809 | /*! |
808 | Constructs a QPEApplication just as you would construct | 810 | Constructs a QPEApplication just as you would construct |
809 | a QApplication, passing \a argc, \a argv, and \a t. | 811 | a QApplication, passing \a argc, \a argv, and \a t. |
810 | 812 | ||
811 | For applications, \a t should be the default, GuiClient. Only | 813 | For applications, \a t should be the default, GuiClient. Only |
812 | the Qtopia server passes GuiServer. | 814 | the Qtopia server passes GuiServer. |
813 | */ | 815 | */ |
814 | QPEApplication::QPEApplication( int & argc, char **argv, Type t ) | 816 | QPEApplication::QPEApplication( int & argc, char **argv, Type t ) |
815 | : QApplication( hack(argc), argv, t ), pidChannel( 0 ) | 817 | : QApplication( hack(argc), argv, t ), pidChannel( 0 ) |
816 | { | 818 | { |
817 | QPixmapCache::setCacheLimit(256); // sensible default for smaller devices. | 819 | QPixmapCache::setCacheLimit(256); // sensible default for smaller devices. |
818 | qInstallMsgHandler(qtopiaMsgHandler); | 820 | qInstallMsgHandler(qtopiaMsgHandler); |
819 | 821 | ||
820 | d = new QPEApplicationData; | 822 | d = new QPEApplicationData; |
821 | d->loadTextCodecs(); | 823 | d->loadTextCodecs(); |
822 | d->loadImageCodecs(); | 824 | d->loadImageCodecs(); |
823 | 825 | ||
824 | setFont( QFont( d->fontFamily, d->fontSize ) ); | 826 | setFont( QFont( d->fontFamily, d->fontSize ) ); |
825 | AppLnk::setSmallIconSize( d->smallIconSize ); | 827 | AppLnk::setSmallIconSize( d->smallIconSize ); |
826 | AppLnk::setBigIconSize( d->bigIconSize ); | 828 | AppLnk::setBigIconSize( d->bigIconSize ); |
827 | 829 | ||
828 | QMimeSourceFactory::setDefaultFactory( new ResourceMimeFactory ); | 830 | QMimeSourceFactory::setDefaultFactory( new ResourceMimeFactory ); |
829 | 831 | ||
830 | connect( this, SIGNAL( lastWindowClosed() ), this, SLOT( hideOrQuit() ) ); | 832 | connect( this, SIGNAL( lastWindowClosed() ), this, SLOT( hideOrQuit() ) ); |
831 | 833 | ||
832 | 834 | ||
833 | sysChannel = new QCopChannel( "QPE/System", this ); | 835 | sysChannel = new QCopChannel( "QPE/System", this ); |
834 | connect( sysChannel, SIGNAL( received(const QCString&,const QByteArray&) ), | 836 | connect( sysChannel, SIGNAL( received(const QCString&,const QByteArray&) ), |
835 | this, SLOT( systemMessage(const QCString&,const QByteArray&) ) ); | 837 | this, SLOT( systemMessage(const QCString&,const QByteArray&) ) ); |
836 | 838 | ||
837 | /* COde now in initapp */ | 839 | /* COde now in initapp */ |
838 | #if 0 | 840 | #if 0 |
839 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 841 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
840 | 842 | ||
841 | QString qcopfn( "/tmp/qcop-msg-" ); | 843 | QString qcopfn( "/tmp/qcop-msg-" ); |
842 | qcopfn += QString( argv[ 0 ] ); // append command name | 844 | qcopfn += QString( argv[ 0 ] ); // append command name |
843 | 845 | ||
844 | QFile f( qcopfn ); | 846 | QFile f( qcopfn ); |
845 | if ( f.open( IO_ReadOnly ) ) { | 847 | if ( f.open( IO_ReadOnly ) ) { |
846 | flock( f.handle(), LOCK_EX ); | 848 | flock( f.handle(), LOCK_EX ); |
847 | } | 849 | } |
848 | 850 | ||
849 | 851 | ||
850 | 852 | ||
851 | QCString channel = QCString( argv[ 0 ] ); | 853 | QCString channel = QCString( argv[ 0 ] ); |
852 | channel.replace( QRegExp( ".*/" ), "" ); | 854 | channel.replace( QRegExp( ".*/" ), "" ); |
853 | d->appName = channel; | 855 | d->appName = channel; |
854 | channel = "QPE/Application/" + channel; | 856 | channel = "QPE/Application/" + channel; |
855 | pidChannel = new QCopChannel( channel, this ); | 857 | pidChannel = new QCopChannel( channel, this ); |
856 | connect( pidChannel, SIGNAL( received(const QCString&,const QByteArray&) ), | 858 | connect( pidChannel, SIGNAL( received(const QCString&,const QByteArray&) ), |