summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2005-06-26 12:18:37 (UTC)
committer mickeyl <mickeyl>2005-06-26 12:18:37 (UTC)
commit53f924947144ddbb3e15d3bd1ddc877073c7ec7f (patch) (unidiff)
tree501e5658099d63309fbf56fc7bd046c0a174a024
parentd5a2b0d5ca4daa11894c52f3599dab56205bef4c (diff)
downloadopie-53f924947144ddbb3e15d3bd1ddc877073c7ec7f.zip
opie-53f924947144ddbb3e15d3bd1ddc877073c7ec7f.tar.gz
opie-53f924947144ddbb3e15d3bd1ddc877073c7ec7f.tar.bz2
get the default gfx driver from QWS_DISPLAY instead of hardcoding
it to 'Transformed' when launching rotated apps. Patch courtesy Manuel Teira
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--library/applnk.cpp6
-rw-r--r--library/qpeapplication.cpp5
-rw-r--r--library/qpeapplication.h5
3 files changed, 12 insertions, 4 deletions
diff --git a/library/applnk.cpp b/library/applnk.cpp
index c82d3b9..874a1b6 100644
--- a/library/applnk.cpp
+++ b/library/applnk.cpp
@@ -1,1531 +1,1533 @@
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 20
21#define QTOPIA_INTERNAL_MIMEEXT 21#define QTOPIA_INTERNAL_MIMEEXT
22#define QTOPIA_INTERNAL_PRELOADACCESS 22#define QTOPIA_INTERNAL_PRELOADACCESS
23#define QTOPIA_INTERNAL_APPLNKASSIGN 23#define QTOPIA_INTERNAL_APPLNKASSIGN
24 24
25#include "applnk.h" 25#include "applnk.h"
26 26
27#include <qpe/qpeapplication.h> 27#include <qpe/qpeapplication.h>
28#include <qpe/categories.h> 28#include <qpe/categories.h>
29#include <qpe/categoryselect.h> 29#include <qpe/categoryselect.h>
30#include <qpe/global.h> 30#include <qpe/global.h>
31#include <qpe/qcopenvelope_qws.h> 31#include <qpe/qcopenvelope_qws.h>
32#include <qpe/mimetype.h> 32#include <qpe/mimetype.h>
33#include <qpe/config.h> 33#include <qpe/config.h>
34#include <qpe/storage.h> 34#include <qpe/storage.h>
35#include <qpe/resource.h> 35#include <qpe/resource.h>
36 36
37#include <qdir.h> 37#include <qdir.h>
38 38
39 39
40#include <stdlib.h> 40#include <stdlib.h>
41 41
42int AppLnk::lastId = 5000; 42int AppLnk::lastId = 5000;
43 43
44static int smallSize = 14; 44static int smallSize = 14;
45static int bigSize = 32; 45static int bigSize = 32;
46 46
47static QString safeFileName(const QString& n) 47static QString safeFileName(const QString& n)
48{ 48{
49 QString safename=n; 49 QString safename=n;
50 safename.replace(QRegExp("[^0-9A-Za-z.]"),"_"); 50 safename.replace(QRegExp("[^0-9A-Za-z.]"),"_");
51 safename.replace(QRegExp("^[^A-Za-z]*"),""); 51 safename.replace(QRegExp("^[^A-Za-z]*"),"");
52 if ( safename.isEmpty() ) 52 if ( safename.isEmpty() )
53 safename = "_"; 53 safename = "_";
54 return safename; 54 return safename;
55} 55}
56 56
57static bool prepareDirectories(const QString& lf) 57static bool prepareDirectories(const QString& lf)
58{ 58{
59 if ( !QFile::exists(lf) ) { 59 if ( !QFile::exists(lf) ) {
60 // May need to create directories 60 // May need to create directories
61 QFileInfo fi(lf); 61 QFileInfo fi(lf);
62 if ( system(("mkdir -p "+fi.dirPath(TRUE))) ) 62 if ( system(("mkdir -p "+fi.dirPath(TRUE))) )
63 return FALSE; 63 return FALSE;
64 } 64 }
65 return TRUE; 65 return TRUE;
66} 66}
67 67
68class AppLnkPrivate 68class AppLnkPrivate
69{ 69{
70public: 70public:
71 /* the size of the Pixmap */ 71 /* the size of the Pixmap */
72 enum Size {Normal = 0, Big }; 72 enum Size {Normal = 0, Big };
73 AppLnkPrivate() { 73 AppLnkPrivate() {
74 /* we want one normal and one big item */ 74 /* we want one normal and one big item */
75 75
76 QPixmap pix; 76 QPixmap pix;
77 mPixmaps.insert(0, pix ); 77 mPixmaps.insert(0, pix );
78 mPixmaps.insert(1, pix); 78 mPixmaps.insert(1, pix);
79 } 79 }
80 80
81 QStringList mCatList; // always correct 81 QStringList mCatList; // always correct
82 QArray<int> mCat; // cached value; correct if not empty 82 QArray<int> mCat; // cached value; correct if not empty
83 QMap<int, QPixmap> mPixmaps; 83 QMap<int, QPixmap> mPixmaps;
84 84
85 void updateCatListFromArray() 85 void updateCatListFromArray()
86 { 86 {
87 Categories cat( 0 ); 87 Categories cat( 0 );
88 cat.load( categoryFileName() ); 88 cat.load( categoryFileName() );
89 // we need to update the names for the mCat... to mCatList 89 // we need to update the names for the mCat... to mCatList
90 mCatList.clear(); 90 mCatList.clear();
91 for (uint i = 0; i < mCat.count(); i++ ) 91 for (uint i = 0; i < mCat.count(); i++ )
92 mCatList << cat.label("Document View", mCat[i] ); 92 mCatList << cat.label("Document View", mCat[i] );
93 93
94 } 94 }
95 95
96 void setCatArrayDirty() 96 void setCatArrayDirty()
97 { 97 {
98 mCat.resize(0); 98 mCat.resize(0);
99 } 99 }
100 100
101 void ensureCatArray() 101 void ensureCatArray()
102 { 102 {
103 if ( mCat.count() > 0 || mCatList.count()==0 ) 103 if ( mCat.count() > 0 || mCatList.count()==0 )
104 return; 104 return;
105 105
106 Categories cat( 0 ); 106 Categories cat( 0 );
107 cat.load( categoryFileName() ); 107 cat.load( categoryFileName() );
108 mCat.resize( mCatList.count() ); 108 mCat.resize( mCatList.count() );
109 int i; 109 int i;
110 QStringList::ConstIterator it; 110 QStringList::ConstIterator it;
111 for ( i = 0, it = mCatList.begin(); it != mCatList.end(); 111 for ( i = 0, it = mCatList.begin(); it != mCatList.end();
112 ++it, i++ ) { 112 ++it, i++ ) {
113 113
114 bool number; 114 bool number;
115 int id = (*it).toInt( &number ); 115 int id = (*it).toInt( &number );
116 if ( !number ) { 116 if ( !number ) {
117 id = cat.id( "Document View", *it ); 117 id = cat.id( "Document View", *it );
118 if ( id == 0 ) 118 if ( id == 0 )
119 id = cat.addCategory( "Document View", *it ); 119 id = cat.addCategory( "Document View", *it );
120 } 120 }
121 mCat[i] = id; 121 mCat[i] = id;
122 } 122 }
123 } 123 }
124}; 124};
125 125
126/*! 126/*!
127 \class AppLnk applnk.h 127 \class AppLnk applnk.h
128 \brief The AppLnk class represents an application available on the system. 128 \brief The AppLnk class represents an application available on the system.
129 129
130 Every Qtopia application \e app has a corresponding \e app.desktop 130 Every Qtopia application \e app has a corresponding \e app.desktop
131 file. When one of these files is read its data is stored as an 131 file. When one of these files is read its data is stored as an
132 AppLnk object. 132 AppLnk object.
133 133
134 The AppLnk class introduces some Qtopia-specific concepts, and 134 The AppLnk class introduces some Qtopia-specific concepts, and
135 provides a variety of functions, as described in the following 135 provides a variety of functions, as described in the following
136 sections. 136 sections.
137 \tableofcontents 137 \tableofcontents
138 138
139 \target Types 139 \target Types
140 \section1 Types 140 \section1 Types
141 141
142 Every AppLnk object has a \e type. For applications, games and 142 Every AppLnk object has a \e type. For applications, games and
143 settings the type is \c Application; for documents the 143 settings the type is \c Application; for documents the
144 type is the document's MIME type. 144 type is the document's MIME type.
145 145
146 \target files-and-links 146 \target files-and-links
147 \section1 Files and Links 147 \section1 Files and Links
148 148
149 When you create an AppLnk (or more likely, a \link doclnk.html 149 When you create an AppLnk (or more likely, a \link doclnk.html
150 DocLnk\endlink), you don't deal directly with filenames in the 150 DocLnk\endlink), you don't deal directly with filenames in the
151 filesystem. Instead you do this: 151 filesystem. Instead you do this:
152 \code 152 \code
153 DocLnk d; 153 DocLnk d;
154 d.setType("text/plain"); 154 d.setType("text/plain");
155 d.setName("My Nicely Named Document / Whatever"); // Yes, "/" is legal. 155 d.setName("My Nicely Named Document / Whatever"); // Yes, "/" is legal.
156 \endcode 156 \endcode
157 At this point, the file() and linkFile() are unknown. Normally 157 At this point, the file() and linkFile() are unknown. Normally
158 this is uninteresting, and the names become automatically known, 158 this is uninteresting, and the names become automatically known,
159 and more importantly, becomes reserved, when you ask what they are: 159 and more importantly, becomes reserved, when you ask what they are:
160 160
161 \code 161 \code
162 QString fn = d.file(); 162 QString fn = d.file();
163 \endcode 163 \endcode
164 This invents a filename, and creates the file on disk (an empty 164 This invents a filename, and creates the file on disk (an empty
165 reservation file) to prevent the name being used by another 165 reservation file) to prevent the name being used by another
166 application. 166 application.
167 167
168 In some circumstances, you don't want to create the file if it 168 In some circumstances, you don't want to create the file if it
169 doesn't already exist (e.g. in the Document tab, some of the \link 169 doesn't already exist (e.g. in the Document tab, some of the \link
170 doclnk.html DocLnk\endlink objects represented by icons are 170 doclnk.html DocLnk\endlink objects represented by icons are
171 DocLnk's created just for that view - they don't have 171 DocLnk's created just for that view - they don't have
172 corresponding \c .desktop files. To avoid littering empty 172 corresponding \c .desktop files. To avoid littering empty
173 reservation files around, we check in a few places to see whether 173 reservation files around, we check in a few places to see whether
174 the file really needs to exist). 174 the file really needs to exist).
175 175
176 \section1 Functionality 176 \section1 Functionality
177 177
178 AppLnk objects are created by calling the constructor with the 178 AppLnk objects are created by calling the constructor with the
179 name of a \e .desktop file. The object can be checked for validity 179 name of a \e .desktop file. The object can be checked for validity
180 using isValid(). 180 using isValid().
181 181
182 The following functions are used to set or retrieve information 182 The following functions are used to set or retrieve information
183 about the application: 183 about the application:
184 \table 184 \table
185 \header \i Get Function \i Set Function \i Short Description 185 \header \i Get Function \i Set Function \i Short Description
186 \row \i \l name() \i \l setName() \i application's name 186 \row \i \l name() \i \l setName() \i application's name
187 \row \i \l pixmap() \i \e none \i application's icon 187 \row \i \l pixmap() \i \e none \i application's icon
188 \row \i \l bigPixmap() \i \e none \i application's large icon 188 \row \i \l bigPixmap() \i \e none \i application's large icon
189 \row \i \e none \i setIcon() \i sets the icon's filename 189 \row \i \e none \i setIcon() \i sets the icon's filename
190 \row \i \l type() \i \l setType() \i see \link #Types Types\endlink above 190 \row \i \l type() \i \l setType() \i see \link #Types Types\endlink above
191 \row \i \l rotation() \i \e none \i 0, 90, 180 or 270 degrees 191 \row \i \l rotation() \i \e none \i 0, 90, 180 or 270 degrees
192 \row \i \l comment() \i \l setComment() \i text for the Details dialog 192 \row \i \l comment() \i \l setComment() \i text for the Details dialog
193 \row \i \l exec() \i \l setExec() \i executable's filename 193 \row \i \l exec() \i \l setExec() \i executable's filename
194 \row \i \l file() \i \e none \i document's filename 194 \row \i \l file() \i \e none \i document's filename
195 \row \i \l linkFile() \i \l setLinkFile() \i \e .desktop filename 195 \row \i \l linkFile() \i \l setLinkFile() \i \e .desktop filename
196 \row \i \l mimeTypes() \i \e none \i the mime types the application can view or edit 196 \row \i \l mimeTypes() \i \e none \i the mime types the application can view or edit
197 \row \i \l categories() \i \l setCategories() \i \e{see the function descriptions} 197 \row \i \l categories() \i \l setCategories() \i \e{see the function descriptions}
198 \row \i \l fileKnown() \i \e none \i see \link 198 \row \i \l fileKnown() \i \e none \i see \link
199#files-and-links Files and Links\endlink above 199#files-and-links Files and Links\endlink above
200 \row \i \l linkFileKnown() \i \e none \i see \link 200 \row \i \l linkFileKnown() \i \e none \i see \link
201#files-and-links Files and Links\endlink above 201#files-and-links Files and Links\endlink above
202 \row \i \l property() \i \l setProperty() \i any AppLnk property 202 \row \i \l property() \i \l setProperty() \i any AppLnk property
203 can be retrieved or set (if writeable) using these 203 can be retrieved or set (if writeable) using these
204 \endtable 204 \endtable
205 205
206 To save an AppLnk to disk use writeLink(). To execute the 206 To save an AppLnk to disk use writeLink(). To execute the
207 application that the AppLnk object refers to, use execute(). 207 application that the AppLnk object refers to, use execute().
208 208
209 AppLnk's can be deleted from disk using removeLinkFile(). To 209 AppLnk's can be deleted from disk using removeLinkFile(). To
210 remove both the link and the application's executable use 210 remove both the link and the application's executable use
211 removeFiles(). 211 removeFiles().
212 212
213 Icon sizes can be globally changed (but only for AppLnk objects 213 Icon sizes can be globally changed (but only for AppLnk objects
214 created after the calls) with setSmallIconSize() and 214 created after the calls) with setSmallIconSize() and
215 setBigIconSize(). 215 setBigIconSize().
216 216
217 \ingroup qtopiaemb 217 \ingroup qtopiaemb
218*/ 218*/
219 219
220/*! 220/*!
221 Sets the size used for small icons to \a small pixels. 221 Sets the size used for small icons to \a small pixels.
222 Only affects AppLnk objects created after the call. 222 Only affects AppLnk objects created after the call.
223 223
224 \sa smallIconSize() setIcon() 224 \sa smallIconSize() setIcon()
225*/ 225*/
226void AppLnk::setSmallIconSize(int small) 226void AppLnk::setSmallIconSize(int small)
227{ 227{
228 smallSize = small; 228 smallSize = small;
229} 229}
230 230
231/*! 231/*!
232 Returns the size used for small icons. 232 Returns the size used for small icons.
233 233
234 \sa setSmallIconSize() setIcon() 234 \sa setSmallIconSize() setIcon()
235*/ 235*/
236int AppLnk::smallIconSize() 236int AppLnk::smallIconSize()
237{ 237{
238 return smallSize; 238 return smallSize;
239} 239}
240 240
241 241
242/*! 242/*!
243 Sets the size used for large icons to \a big pixels. 243 Sets the size used for large icons to \a big pixels.
244 Only affects AppLnk objects created after the call. 244 Only affects AppLnk objects created after the call.
245 245
246 \sa bigIconSize() setIcon() 246 \sa bigIconSize() setIcon()
247*/ 247*/
248void AppLnk::setBigIconSize(int big) 248void AppLnk::setBigIconSize(int big)
249{ 249{
250 bigSize = big; 250 bigSize = big;
251} 251}
252 252
253/*! 253/*!
254 Returns the size used for large icons. 254 Returns the size used for large icons.
255 255
256 \sa setBigIconSize() setIcon() 256 \sa setBigIconSize() setIcon()
257*/ 257*/
258int AppLnk::bigIconSize() 258int AppLnk::bigIconSize()
259{ 259{
260 return bigSize; 260 return bigSize;
261} 261}
262 262
263 263
264/*! 264/*!
265 \fn QString AppLnk::name() const 265 \fn QString AppLnk::name() const
266 266
267 Returns the Name property. This is the user-visible name for the 267 Returns the Name property. This is the user-visible name for the
268 document or application, not the filename. 268 document or application, not the filename.
269 269
270 See \link #files-and-links Files and Links\endlink. 270 See \link #files-and-links Files and Links\endlink.
271 271
272 \sa setName() 272 \sa setName()
273*/ 273*/
274/*! 274/*!
275 \fn QString AppLnk::exec() const 275 \fn QString AppLnk::exec() const
276 276
277 Returns the Exec property. This is the name of the executable 277 Returns the Exec property. This is the name of the executable
278 program associated with the AppLnk. 278 program associated with the AppLnk.
279 279
280 \sa setExec() 280 \sa setExec()
281*/ 281*/
282/*! 282/*!
283 \fn QString AppLnk::rotation() const 283 \fn QString AppLnk::rotation() const
284 284
285 Returns the Rotation property. The value is 0, 90, 180 or 270 285 Returns the Rotation property. The value is 0, 90, 180 or 270
286 degrees. 286 degrees.
287*/ 287*/
288/*! 288/*!
289 \fn QString AppLnk::comment() const 289 \fn QString AppLnk::comment() const
290 290
291 Returns the Comment property. 291 Returns the Comment property.
292 292
293 \sa setComment() 293 \sa setComment()
294*/ 294*/
295/*! 295/*!
296 \fn QStringList AppLnk::mimeTypes() const 296 \fn QStringList AppLnk::mimeTypes() const
297 297
298 Returns the MimeTypes property. This is the list of MIME types 298 Returns the MimeTypes property. This is the list of MIME types
299 that the application can view or edit. 299 that the application can view or edit.
300*/ 300*/
301/*! 301/*!
302 \fn const QArray<int>& AppLnk::categories() const 302 \fn const QArray<int>& AppLnk::categories() const
303 303
304 Returns the Categories property. 304 Returns the Categories property.
305 305
306 See the CategoryWidget for more details. 306 See the CategoryWidget for more details.
307 307
308 \sa setCategories() 308 \sa setCategories()
309*/ 309*/
310 310
311const QArray<int>& AppLnk::categories() const 311const QArray<int>& AppLnk::categories() const
312{ 312{
313 d->ensureCatArray(); 313 d->ensureCatArray();
314 return d->mCat; 314 return d->mCat;
315} 315}
316 316
317/*! 317/*!
318 \fn int AppLnk::id() const 318 \fn int AppLnk::id() const
319 319
320 Returns the id of the AppLnk. If the AppLnk is not in an AppLnkSet, 320 Returns the id of the AppLnk. If the AppLnk is not in an AppLnkSet,
321 this value is 0, otherwise it is a value that is unique for the 321 this value is 0, otherwise it is a value that is unique for the
322 duration of the current process. 322 duration of the current process.
323 323
324 \sa AppLnkSet::find() 324 \sa AppLnkSet::find()
325*/ 325*/
326 326
327/*! 327/*!
328 \fn bool AppLnk::isValid() const 328 \fn bool AppLnk::isValid() const
329 329
330 Returns TRUE if this AppLnk is valid; otherwise returns FALSE. 330 Returns TRUE if this AppLnk is valid; otherwise returns FALSE.
331*/ 331*/
332/*! 332/*!
333 \fn bool AppLnk::fileKnown() const 333 \fn bool AppLnk::fileKnown() const
334 334
335 If the with the AppLnk associated file is not equal to QString::null 335 If the with the AppLnk associated file is not equal to QString::null
336*/ 336*/
337/*! 337/*!
338 \fn bool AppLnk::linkFileKnown()const 338 \fn bool AppLnk::linkFileKnown()const
339 339
340 The filename of the AppLnk 340 The filename of the AppLnk
341 341
342*/ 342*/
343/*! 343/*!
344 \fn void AppLnk::setRotation( const QString& ) 344 \fn void AppLnk::setRotation( const QString& )
345 345
346 The default rotation of the associated application. This 346 The default rotation of the associated application. This
347 function is included inline for binary compatible issues 347 function is included inline for binary compatible issues
348*/ 348*/
349/*! 349/*!
350 Creates an invalid AppLnk. 350 Creates an invalid AppLnk.
351 351
352 \sa isValid() 352 \sa isValid()
353*/ 353*/
354AppLnk::AppLnk() 354AppLnk::AppLnk()
355{ 355{
356 mId = 0; 356 mId = 0;
357 d = new AppLnkPrivate(); 357 d = new AppLnkPrivate();
358} 358}
359 359
360/*! 360/*!
361 Loads \a file (e.g. \e app.desktop) as an AppLnk. 361 Loads \a file (e.g. \e app.desktop) as an AppLnk.
362 362
363 \sa writeLink() 363 \sa writeLink()
364*/ 364*/
365AppLnk::AppLnk( const QString &file ) 365AppLnk::AppLnk( const QString &file )
366{ 366{
367 QStringList sl; 367 QStringList sl;
368 d = new AppLnkPrivate(); 368 d = new AppLnkPrivate();
369 if ( !file.isNull() ) { 369 if ( !file.isNull() ) {
370 Config config( file, Config::File ); 370 Config config( file, Config::File );
371 371
372 if ( config.isValid() ) { 372 if ( config.isValid() ) {
373 config.setGroup( "Desktop Entry" ); 373 config.setGroup( "Desktop Entry" );
374 374
375 mName = config.readEntry( "Name", file ); 375 mName = config.readEntry( "Name", file );
376 mExec = config.readEntry( "Exec" ); 376 mExec = config.readEntry( "Exec" );
377 mType = config.readEntry( "Type", QString::null ); 377 mType = config.readEntry( "Type", QString::null );
378 mIconFile = config.readEntry( "Icon", QString::null ); 378 mIconFile = config.readEntry( "Icon", QString::null );
379 mRotation = config.readEntry( "Rotation", "" ); 379 mRotation = config.readEntry( "Rotation", "" );
380 mComment = config.readEntry( "Comment", QString::null ); 380 mComment = config.readEntry( "Comment", QString::null );
381 // MIME types are case-insensitive. 381 // MIME types are case-insensitive.
382 mMimeTypes = config.readListEntry( "MimeType", ';' ); 382 mMimeTypes = config.readListEntry( "MimeType", ';' );
383 for (QStringList::Iterator it=mMimeTypes.begin(); it!=mMimeTypes.end(); ++it) 383 for (QStringList::Iterator it=mMimeTypes.begin(); it!=mMimeTypes.end(); ++it)
384 *it = (*it).lower(); 384 *it = (*it).lower();
385 mMimeTypeIcons = config.readListEntry( "MimeTypeIcons", ';' ); 385 mMimeTypeIcons = config.readListEntry( "MimeTypeIcons", ';' );
386 mLinkFile = file; 386 mLinkFile = file;
387 mFile = config.readEntry("File", QString::null); 387 mFile = config.readEntry("File", QString::null);
388 if ( !mExec. isEmpty ( )) { 388 if ( !mExec. isEmpty ( )) {
389 mFile = QString::null; 389 mFile = QString::null;
390 } 390 }
391 else if ( mFile[0] != '/' ) { 391 else if ( mFile[0] != '/' ) {
392 int slash = file.findRev('/'); 392 int slash = file.findRev('/');
393 if ( slash >= 0 ) { 393 if ( slash >= 0 ) {
394 mFile = file.left(slash) + '/' + mFile; 394 mFile = file.left(slash) + '/' + mFile;
395 } 395 }
396 } 396 }
397 d->mCatList = config.readListEntry("Categories", ';'); 397 d->mCatList = config.readListEntry("Categories", ';');
398 if ( d->mCatList[0].toInt() < -1 ) { 398 if ( d->mCatList[0].toInt() < -1 ) {
399 // numeric cats in file! convert to text 399 // numeric cats in file! convert to text
400 Categories cat( 0 ); 400 Categories cat( 0 );
401 cat.load( categoryFileName() ); 401 cat.load( categoryFileName() );
402 d->mCat.resize( d->mCatList.count() ); 402 d->mCat.resize( d->mCatList.count() );
403 int i; 403 int i;
404 QStringList::ConstIterator it; 404 QStringList::ConstIterator it;
405 for ( i = 0, it = d->mCatList.begin(); it != d->mCatList.end(); 405 for ( i = 0, it = d->mCatList.begin(); it != d->mCatList.end();
406 ++it, i++ ) { 406 ++it, i++ ) {
407 bool number; 407 bool number;
408 int id = (*it).toInt( &number ); 408 int id = (*it).toInt( &number );
409 if ( !number ) { 409 if ( !number ) {
410 // convert from text 410 // convert from text
411 id = cat.id( "Document View", *it ); 411 id = cat.id( "Document View", *it );
412 if ( id == 0 ) 412 if ( id == 0 )
413 id = cat.addCategory( "Document View", *it ); 413 id = cat.addCategory( "Document View", *it );
414 } 414 }
415 d->mCat[i] = id; 415 d->mCat[i] = id;
416 } 416 }
417 d->updateCatListFromArray(); 417 d->updateCatListFromArray();
418 } 418 }
419 } 419 }
420 } 420 }
421 mId = 0; 421 mId = 0;
422} 422}
423 423
424AppLnk& AppLnk::operator=(const AppLnk &copy) 424AppLnk& AppLnk::operator=(const AppLnk &copy)
425{ 425{
426 if ( this == &copy ) return *this; 426 if ( this == &copy ) return *this;
427 if ( mId ) 427 if ( mId )
428 qWarning("Deleting AppLnk that is in an AppLnkSet"); 428 qWarning("Deleting AppLnk that is in an AppLnkSet");
429 if ( d ) 429 if ( d )
430 delete d; 430 delete d;
431 431
432 432
433 mName = copy.mName; 433 mName = copy.mName;
434 434
435 /* remove for Qtopia 3.0 -zecke */ 435 /* remove for Qtopia 3.0 -zecke */
436 mPixmap = copy.mPixmap; 436 mPixmap = copy.mPixmap;
437 mBigPixmap = copy.mBigPixmap; 437 mBigPixmap = copy.mBigPixmap;
438 438
439 mExec = copy.mExec; 439 mExec = copy.mExec;
440 mType = copy.mType; 440 mType = copy.mType;
441 mRotation = copy.mRotation; 441 mRotation = copy.mRotation;
442 mComment = copy.mComment; 442 mComment = copy.mComment;
443 mFile = copy.mFile; 443 mFile = copy.mFile;
444 mLinkFile = copy.mLinkFile; 444 mLinkFile = copy.mLinkFile;
445 mIconFile = copy.mIconFile; 445 mIconFile = copy.mIconFile;
446 mMimeTypes = copy.mMimeTypes; 446 mMimeTypes = copy.mMimeTypes;
447 mMimeTypeIcons = copy.mMimeTypeIcons; 447 mMimeTypeIcons = copy.mMimeTypeIcons;
448 mId = 0; 448 mId = 0;
449 d = new AppLnkPrivate(); 449 d = new AppLnkPrivate();
450 d->mCat = copy.d->mCat; 450 d->mCat = copy.d->mCat;
451 d->mCatList = copy.d->mCatList; 451 d->mCatList = copy.d->mCatList;
452 d->mPixmaps = copy.d->mPixmaps; 452 d->mPixmaps = copy.d->mPixmaps;
453 453
454 return *this; 454 return *this;
455} 455}
456/*! 456/*!
457 protected internally to share code 457 protected internally to share code
458 should I document that at all? 458 should I document that at all?
459 I don't know the TT style for that 459 I don't know the TT style for that
460*/ 460*/
461const QPixmap& AppLnk::pixmap( int pos, int size ) const { 461const QPixmap& AppLnk::pixmap( int pos, int size ) const {
462 if ( d->mPixmaps[pos].isNull() ) { 462 if ( d->mPixmaps[pos].isNull() ) {
463 AppLnk* that = (AppLnk*)this; 463 AppLnk* that = (AppLnk*)this;
464 if ( mIconFile.isEmpty() ) { 464 if ( mIconFile.isEmpty() ) {
465 MimeType mt(type()); 465 MimeType mt(type());
466 that->d->mPixmaps[pos] = pos ? mt.bigPixmap() : mt.pixmap(); 466 that->d->mPixmaps[pos] = pos ? mt.bigPixmap() : mt.pixmap();
467 if ( that->d->mPixmaps[pos].isNull() ) 467 if ( that->d->mPixmaps[pos].isNull() )
468 that->d->mPixmaps[pos].convertFromImage( 468 that->d->mPixmaps[pos].convertFromImage(
469 Resource::loadImage("UnknownDocument") 469 Resource::loadImage("UnknownDocument")
470 .smoothScale( size, size ) ); 470 .smoothScale( size, size ) );
471 return that->d->mPixmaps[pos]; 471 return that->d->mPixmaps[pos];
472 } 472 }
473 473
474 QImage unscaledIcon = Resource::loadImage( that->mIconFile ); 474 QImage unscaledIcon = Resource::loadImage( that->mIconFile );
475 if ( unscaledIcon.isNull() ) { 475 if ( unscaledIcon.isNull() ) {
476 // qDebug( "Cannot find icon: %s", that->mIconFile.latin1() ); 476 // qDebug( "Cannot find icon: %s", that->mIconFile.latin1() );
477 that->d->mPixmaps[pos].convertFromImage( 477 that->d->mPixmaps[pos].convertFromImage(
478 Resource::loadImage("UnknownDocument") 478 Resource::loadImage("UnknownDocument")
479 .smoothScale( size, size ) ); 479 .smoothScale( size, size ) );
480 } else { 480 } else {
481 that->d->mPixmaps[0].convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) ); 481 that->d->mPixmaps[0].convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) );
482 that->d->mPixmaps[1].convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) ); 482 that->d->mPixmaps[1].convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) );
483 } 483 }
484 return that->d->mPixmaps[pos]; 484 return that->d->mPixmaps[pos];
485 } 485 }
486 486
487 return d->mPixmaps[pos]; 487 return d->mPixmaps[pos];
488} 488}
489 489
490/*! 490/*!
491 Returns a small pixmap associated with the application. 491 Returns a small pixmap associated with the application.
492 492
493 \sa bigPixmap() setIcon() 493 \sa bigPixmap() setIcon()
494*/ 494*/
495const QPixmap& AppLnk::pixmap() const 495const QPixmap& AppLnk::pixmap() const
496{ 496{
497 if ( d->mPixmaps[0].isNull() ) { 497 if ( d->mPixmaps[0].isNull() ) {
498 return pixmap(AppLnkPrivate::Normal, smallSize ); 498 return pixmap(AppLnkPrivate::Normal, smallSize );
499 } 499 }
500 return d->mPixmaps[0]; 500 return d->mPixmaps[0];
501} 501}
502 502
503/*! 503/*!
504 Returns a large pixmap associated with the application. 504 Returns a large pixmap associated with the application.
505 505
506 \sa pixmap() setIcon() 506 \sa pixmap() setIcon()
507*/ 507*/
508const QPixmap& AppLnk::bigPixmap() const 508const QPixmap& AppLnk::bigPixmap() const
509{ 509{
510 if ( d->mPixmaps[1].isNull() ) { 510 if ( d->mPixmaps[1].isNull() ) {
511 return pixmap( AppLnkPrivate::Big, bigSize ); 511 return pixmap( AppLnkPrivate::Big, bigSize );
512 } 512 }
513 return d->mPixmaps[1]; 513 return d->mPixmaps[1];
514} 514}
515 515
516/*! 516/*!
517 Returns the type of the AppLnk. For applications, games and 517 Returns the type of the AppLnk. For applications, games and
518 settings the type is \c Application; for documents the type is the 518 settings the type is \c Application; for documents the type is the
519 document's MIME type. 519 document's MIME type.
520*/ 520*/
521QString AppLnk::type() const 521QString AppLnk::type() const
522{ 522{
523 if ( mType.isNull() ) { 523 if ( mType.isNull() ) {
524 AppLnk* that = (AppLnk*)this; 524 AppLnk* that = (AppLnk*)this;
525 QString f = file(); 525 QString f = file();
526 if ( !f.isNull() ) { 526 if ( !f.isNull() ) {
527 MimeType mt(f); 527 MimeType mt(f);
528 that->mType = mt.id(); 528 that->mType = mt.id();
529 return that->mType; 529 return that->mType;
530 } 530 }
531 } 531 }
532 return mType; 532 return mType;
533} 533}
534 534
535/*! 535/*!
536 Returns the file associated with the AppLnk. 536 Returns the file associated with the AppLnk.
537 537
538 \sa exec() name() 538 \sa exec() name()
539*/ 539*/
540QString AppLnk::file() const 540QString AppLnk::file() const
541{ 541{
542 if ( mExec.isEmpty ( ) && mFile.isNull() ) { 542 if ( mExec.isEmpty ( ) && mFile.isNull() ) {
543 AppLnk* that = (AppLnk*)this; 543 AppLnk* that = (AppLnk*)this;
544 QString ext = MimeType(mType).extension(); 544 QString ext = MimeType(mType).extension();
545 if ( !ext.isEmpty() ) 545 if ( !ext.isEmpty() )
546 ext = "." + ext; 546 ext = "." + ext;
547 if ( !mLinkFile.isEmpty() ) { 547 if ( !mLinkFile.isEmpty() ) {
548 that->mFile = 548 that->mFile =
549 mLinkFile.right(8)==".desktop" // 8 = strlen(".desktop") 549 mLinkFile.right(8)==".desktop" // 8 = strlen(".desktop")
550 ? mLinkFile.left(mLinkFile.length()-8) : mLinkFile; 550 ? mLinkFile.left(mLinkFile.length()-8) : mLinkFile;
551 qDebug("mFile now == %s", mFile.latin1()); 551 qDebug("mFile now == %s", mFile.latin1());
552 } else if ( mType.contains('/') ) { 552 } else if ( mType.contains('/') ) {
553 that->mFile = 553 that->mFile =
554 QString(getenv("HOME"))+"/Documents/"+mType+"/"+safeFileName(that->mName); 554 QString(getenv("HOME"))+"/Documents/"+mType+"/"+safeFileName(that->mName);
555 /* 555 /*
556 * A file with the same name or a .desktop file already exists 556 * A file with the same name or a .desktop file already exists
557 */ 557 */
558 if ( QFile::exists(that->mFile+ext) || QFile::exists(that->mFile+".desktop") ) { 558 if ( QFile::exists(that->mFile+ext) || QFile::exists(that->mFile+".desktop") ) {
559 int n=1; 559 int n=1;
560 QString nn; 560 QString nn;
561 while (QFile::exists((nn=(that->mFile+"_"+QString::number(n)))+ext) 561 while (QFile::exists((nn=(that->mFile+"_"+QString::number(n)))+ext)
562 || QFile::exists(nn+".desktop")) 562 || QFile::exists(nn+".desktop"))
563 n++; 563 n++;
564 that->mFile = nn; 564 that->mFile = nn;
565 } 565 }
566 that->mLinkFile = that->mFile+".desktop"; 566 that->mLinkFile = that->mFile+".desktop";
567 that->mFile += ext; 567 that->mFile += ext;
568 } 568 }
569 prepareDirectories(that->mFile); 569 prepareDirectories(that->mFile);
570 if ( !that->mFile.isEmpty() ) { 570 if ( !that->mFile.isEmpty() ) {
571 QFile f(that->mFile); 571 QFile f(that->mFile);
572 if ( !f.open(IO_WriteOnly) ) 572 if ( !f.open(IO_WriteOnly) )
573 that->mFile = QString::null; 573 that->mFile = QString::null;
574 return that->mFile; 574 return that->mFile;
575 } 575 }
576 } 576 }
577 return mFile; 577 return mFile;
578} 578}
579 579
580/*! 580/*!
581 Returns the desktop file corresponding to this AppLnk. 581 Returns the desktop file corresponding to this AppLnk.
582 582
583 \sa file() exec() name() 583 \sa file() exec() name()
584*/ 584*/
585QString AppLnk::linkFile() const 585QString AppLnk::linkFile() const
586{ 586{
587 if ( mLinkFile.isNull() ) { 587 if ( mLinkFile.isNull() ) {
588 AppLnk* that = (AppLnk*)this; 588 AppLnk* that = (AppLnk*)this;
589 if ( type().contains('/') ) { 589 if ( type().contains('/') ) {
590 StorageInfo storage; 590 StorageInfo storage;
591 const FileSystem *fs = storage.fileSystemOf( that->mFile ); 591 const FileSystem *fs = storage.fileSystemOf( that->mFile );
592 /* tmpfs + and ramfs are available too but not removable 592 /* tmpfs + and ramfs are available too but not removable
593 * either we fix storage or add this 593 * either we fix storage or add this
594 */ 594 */
595 if ( fs && ( fs->isRemovable() || fs->disk() == "/dev/mtdblock6" || fs->disk() == "tmpfs") ) { 595 if ( fs && ( fs->isRemovable() || fs->disk() == "/dev/mtdblock6" || fs->disk() == "tmpfs") ) {
596 that->mLinkFile = fs->path(); 596 that->mLinkFile = fs->path();
597 } else 597 } else
598 that->mLinkFile = getenv( "HOME" ); 598 that->mLinkFile = getenv( "HOME" );
599 that->mLinkFile += "/Documents/"+type()+"/"+safeFileName(that->mName); 599 that->mLinkFile += "/Documents/"+type()+"/"+safeFileName(that->mName);
600 600
601 /* the desktop file exists make sure we don't point to the same file */ 601 /* the desktop file exists make sure we don't point to the same file */
602 if ( QFile::exists(that->mLinkFile+".desktop") ) { 602 if ( QFile::exists(that->mLinkFile+".desktop") ) {
603 AppLnk lnk( that->mLinkFile + ".desktop" ); 603 AppLnk lnk( that->mLinkFile + ".desktop" );
604 604
605 /* the linked is different */ 605 /* the linked is different */
606 if(that->file() != lnk.file() ) { 606 if(that->file() != lnk.file() ) {
607 int n = 1; 607 int n = 1;
608 QString nn; 608 QString nn;
609 while (QFile::exists((nn=that->mLinkFile+"_"+QString::number(n))+".desktop")) { 609 while (QFile::exists((nn=that->mLinkFile+"_"+QString::number(n))+".desktop")) {
610 n++; 610 n++;
611 /* just to be sure */ 611 /* just to be sure */
612 AppLnk lnk(nn ); 612 AppLnk lnk(nn );
613 if (lnk.file() == that->file() ) 613 if (lnk.file() == that->file() )
614 break; 614 break;
615 } 615 }
616 that->mLinkFile = nn; 616 that->mLinkFile = nn;
617 } 617 }
618 } 618 }
619 that->mLinkFile += ".desktop"; 619 that->mLinkFile += ".desktop";
620 storeLink(); 620 storeLink();
621 } 621 }
622 return that->mLinkFile; 622 return that->mLinkFile;
623 } 623 }
624 return mLinkFile; 624 return mLinkFile;
625} 625}
626 626
627/*! 627/*!
628 Copies \a copy. 628 Copies \a copy.
629*/ 629*/
630AppLnk::AppLnk( const AppLnk &copy ) 630AppLnk::AppLnk( const AppLnk &copy )
631{ 631{
632 mName = copy.mName; 632 mName = copy.mName;
633 mPixmap = copy.mPixmap; 633 mPixmap = copy.mPixmap;
634 mBigPixmap = copy.mBigPixmap; 634 mBigPixmap = copy.mBigPixmap;
635 mExec = copy.mExec; 635 mExec = copy.mExec;
636 mType = copy.mType; 636 mType = copy.mType;
637 mRotation = copy.mRotation; 637 mRotation = copy.mRotation;
638 mComment = copy.mComment; 638 mComment = copy.mComment;
639 mFile = copy.mFile; 639 mFile = copy.mFile;
640 mLinkFile = copy.mLinkFile; 640 mLinkFile = copy.mLinkFile;
641 mIconFile = copy.mIconFile; 641 mIconFile = copy.mIconFile;
642 mMimeTypes = copy.mMimeTypes; 642 mMimeTypes = copy.mMimeTypes;
643 mMimeTypeIcons = copy.mMimeTypeIcons; 643 mMimeTypeIcons = copy.mMimeTypeIcons;
644 mId = 0; 644 mId = 0;
645 d = new AppLnkPrivate(); 645 d = new AppLnkPrivate();
646 d->mCat = copy.d->mCat; 646 d->mCat = copy.d->mCat;
647 d->mCatList = copy.d->mCatList; 647 d->mCatList = copy.d->mCatList;
648 d->mPixmaps = copy.d->mPixmaps; 648 d->mPixmaps = copy.d->mPixmaps;
649} 649}
650 650
651/*! 651/*!
652 Destroys the AppLnk. Note that if the AppLnk is currently a member 652 Destroys the AppLnk. Note that if the AppLnk is currently a member
653 of an AppLnkSet, this will produce a run-time warning. 653 of an AppLnkSet, this will produce a run-time warning.
654 654
655 \sa AppLnkSet::add() AppLnkSet::remove() 655 \sa AppLnkSet::add() AppLnkSet::remove()
656*/ 656*/
657AppLnk::~AppLnk() 657AppLnk::~AppLnk()
658{ 658{
659 if ( mId ) 659 if ( mId )
660 qWarning("Deleting AppLnk that is in an AppLnkSet"); 660 qWarning("Deleting AppLnk that is in an AppLnkSet");
661 if ( d ) 661 if ( d )
662 delete d; 662 delete d;
663} 663}
664 664
665/*! 665/*!
666 \overload 666 \overload
667 Executes the application associated with this AppLnk. 667 Executes the application associated with this AppLnk.
668 668
669 \sa exec() 669 \sa exec()
670*/ 670*/
671void AppLnk::execute() const 671void AppLnk::execute() const
672{ 672{
673 execute( QStringList::split( ' ', property( "Arguments" ) ) ); 673 execute( QStringList::split( ' ', property( "Arguments" ) ) );
674} 674}
675 675
676/*! 676/*!
677 Executes the application associated with this AppLnk, with 677 Executes the application associated with this AppLnk, with
678 \a args as arguments. 678 \a args as arguments.
679 679
680 \sa exec() 680 \sa exec()
681*/ 681*/
682void AppLnk::execute(const QStringList& args) const 682void AppLnk::execute(const QStringList& args) const
683{ 683{
684#ifdef Q_WS_QWS 684#ifdef Q_WS_QWS
685 if ( !mRotation.isEmpty() ) { 685 if ( !mRotation.isEmpty() ) {
686 // ######## this will only work in the server 686 // ######## this will only work in the server
687 int rot = QPEApplication::defaultRotation(); 687 int rot = QPEApplication::defaultRotation();
688 int j = 0;
688 rot = (rot+mRotation.toInt())%360; 689 rot = (rot+mRotation.toInt())%360;
689 QCString old = getenv("QWS_DISPLAY"); 690 QCString old = getenv( "QWS_DISPLAY" ) ? getenv( "QWS_DISPLAY" ) : "Transformed";
690 setenv("QWS_DISPLAY", QString("Transformed:Rot%1:0").arg(rot), 1); 691 QString driver( old.left( ( ( j = old.find( ':' ) ) >= 0 ) ? j : old.size() ).data() );
692 setenv( "QWS_DISPLAY", QString( "%1:Rot%2:0" ).arg( driver ).arg( rot ), 1 );
691 invoke(args); 693 invoke(args);
692 setenv("QWS_DISPLAY", old.data(), 1); 694 setenv("QWS_DISPLAY", old.data(), 1);
693 } else 695 } else
694#endif 696#endif
695 invoke(args); 697 invoke(args);
696} 698}
697 699
698/*! 700/*!
699 Invokes the application associated with this AppLnk, with 701 Invokes the application associated with this AppLnk, with
700 \a args as arguments. Rotation is not taken into account by 702 \a args as arguments. Rotation is not taken into account by
701 this function, so you should not call it directly. 703 this function, so you should not call it directly.
702 704
703 \sa execute() 705 \sa execute()
704*/ 706*/
705void AppLnk::invoke(const QStringList& args) const 707void AppLnk::invoke(const QStringList& args) const
706{ 708{
707 if ( property( "Arguments" ).isEmpty() ) 709 if ( property( "Arguments" ).isEmpty() )
708 Global::execute( exec(), args[0] ); 710 Global::execute( exec(), args[0] );
709 else 711 else
710 Global::execute( exec(), args.join( " " ) ); 712 Global::execute( exec(), args.join( " " ) );
711} 713}
712 714
713/*! 715/*!
714 Sets the Exec property to \a exec. 716 Sets the Exec property to \a exec.
715 717
716 \sa exec() name() 718 \sa exec() name()
717*/ 719*/
718void AppLnk::setExec( const QString& exec ) 720void AppLnk::setExec( const QString& exec )
719{ 721{
720 mExec = exec; 722 mExec = exec;
721} 723}
722 724
723#if 0 // this was inlined for better BC 725#if 0 // this was inlined for better BC
724/*! 726/*!
725 Sets the Rotation property to \a rot. 727 Sets the Rotation property to \a rot.
726 728
727 \sa rotation() 729 \sa rotation()
728*/ 730*/
729void AppLnk::setRotation ( const QString &rot ) 731void AppLnk::setRotation ( const QString &rot )
730{ 732{
731 mRotation = rot; 733 mRotation = rot;
732} 734}
733#endif 735#endif
734 736
735/*! 737/*!
736 Sets the Name property to \a docname. 738 Sets the Name property to \a docname.
737 739
738 \sa name() 740 \sa name()
739*/ 741*/
740void AppLnk::setName( const QString& docname ) 742void AppLnk::setName( const QString& docname )
741{ 743{
742 mName = docname; 744 mName = docname;
743} 745}
744 746
745/*! 747/*!
746 Sets the File property to \a filename. 748 Sets the File property to \a filename.
747 749
748 \sa file() name() 750 \sa file() name()
749*/ 751*/
750void AppLnk::setFile( const QString& filename ) 752void AppLnk::setFile( const QString& filename )
751{ 753{
752 mFile = filename; 754 mFile = filename;
753} 755}
754 756
755/*! 757/*!
756 Sets the LinkFile property to \a filename. 758 Sets the LinkFile property to \a filename.
757 759
758 \sa linkFile() 760 \sa linkFile()
759*/ 761*/
760void AppLnk::setLinkFile( const QString& filename ) 762void AppLnk::setLinkFile( const QString& filename )
761{ 763{
762 mLinkFile = filename; 764 mLinkFile = filename;
763} 765}
764 766
765/*! 767/*!
766 Sets the Comment property to \a comment. 768 Sets the Comment property to \a comment.
767 769
768 This text is displayed in the 'Details Dialog', for example if the 770 This text is displayed in the 'Details Dialog', for example if the
769 user uses the 'press-and-hold' gesture. 771 user uses the 'press-and-hold' gesture.
770 772
771 \sa comment() 773 \sa comment()
772*/ 774*/
773void AppLnk::setComment( const QString& comment ) 775void AppLnk::setComment( const QString& comment )
774{ 776{
775 mComment = comment; 777 mComment = comment;
776} 778}
777 779
778/*! 780/*!
779 Sets the Type property to \a type. 781 Sets the Type property to \a type.
780 782
781 For applications, games and settings the type should be \c 783 For applications, games and settings the type should be \c
782 Application; for documents the type should be the document's MIME 784 Application; for documents the type should be the document's MIME
783 type. 785 type.
784 786
785 \sa type() 787 \sa type()
786*/ 788*/
787void AppLnk::setType( const QString& type ) 789void AppLnk::setType( const QString& type )
788{ 790{
789 mType = type; 791 mType = type;
790} 792}
791 793
792/*! 794/*!
793 \fn QString AppLnk::icon() const 795 \fn QString AppLnk::icon() const
794 796
795 Returns the Icon property. 797 Returns the Icon property.
796 798
797 \sa setIcon() 799 \sa setIcon()
798*/ 800*/
799 801
800/*! 802/*!
801 Sets the Icon property to \a iconname. This is the filename from 803 Sets the Icon property to \a iconname. This is the filename from
802 which the pixmap() and bigPixmap() are obtained. 804 which the pixmap() and bigPixmap() are obtained.
803 805
804 \sa icon() setSmallIconSize() setBigIconSize() 806 \sa icon() setSmallIconSize() setBigIconSize()
805*/ 807*/
806void AppLnk::setIcon( const QString& iconname ) 808void AppLnk::setIcon( const QString& iconname )
807{ 809{
808 mIconFile = iconname; 810 mIconFile = iconname;
809 QImage unscaledIcon = Resource::loadImage( mIconFile ); 811 QImage unscaledIcon = Resource::loadImage( mIconFile );
810 d->mPixmaps[0].convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) ); 812 d->mPixmaps[0].convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) );
811 d->mPixmaps[1].convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) ); 813 d->mPixmaps[1].convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) );
812} 814}
813 815
814/*! 816/*!
815 Sets the Categories property to \a c. 817 Sets the Categories property to \a c.
816 818
817 See the CategoryWidget for more details. 819 See the CategoryWidget for more details.
818 820
819 \sa categories() 821 \sa categories()
820*/ 822*/
821void AppLnk::setCategories( const QArray<int>& c ) 823void AppLnk::setCategories( const QArray<int>& c )
822{ 824{
823 d->mCat = c; 825 d->mCat = c;
824 d->updateCatListFromArray(); 826 d->updateCatListFromArray();
825} 827}
826 828
827/*! 829/*!
828 \fn QStringList AppLnk::mimeTypeIcons() const 830 \fn QStringList AppLnk::mimeTypeIcons() const
829 831
830 Returns the MimeTypeIcons property of the AppLnk. 832 Returns the MimeTypeIcons property of the AppLnk.
831*/ 833*/
832 834
833/*! 835/*!
834 Attempts to ensure that the link file for this AppLnk exists, 836 Attempts to ensure that the link file for this AppLnk exists,
835 including creating any required directories. Returns TRUE if 837 including creating any required directories. Returns TRUE if
836 successful; otherwise returns FALSE. 838 successful; otherwise returns FALSE.
837 839
838 You should not need to use this function. 840 You should not need to use this function.
839*/ 841*/
840bool AppLnk::ensureLinkExists() const 842bool AppLnk::ensureLinkExists() const
841{ 843{
842 QString lf = linkFile(); 844 QString lf = linkFile();
843 return prepareDirectories(lf); 845 return prepareDirectories(lf);
844} 846}
845 847
846/*! 848/*!
847 Commits the AppLnk to disk. Returns TRUE if the operation succeeded; 849 Commits the AppLnk to disk. Returns TRUE if the operation succeeded;
848 otherwise returns FALSE. 850 otherwise returns FALSE.
849 851
850 In addition, the "linkChanged(QString)" message is sent to the 852 In addition, the "linkChanged(QString)" message is sent to the
851 "QPE/System" \link qcop.html QCop\endlink channel. 853 "QPE/System" \link qcop.html QCop\endlink channel.
852*/ 854*/
853bool AppLnk::writeLink() const 855bool AppLnk::writeLink() const
854{ 856{
855 // Only re-writes settable parts 857 // Only re-writes settable parts
856 QString lf = linkFile(); 858 QString lf = linkFile();
857 if ( !ensureLinkExists() ) 859 if ( !ensureLinkExists() )
858 return FALSE; 860 return FALSE;
859 storeLink(); 861 storeLink();
860 return TRUE; 862 return TRUE;
861} 863}
862 864
863/*! 865/*!
864 \internal 866 \internal
865*/ 867*/
866void AppLnk::storeLink() const 868void AppLnk::storeLink() const
867{ 869{
868 Config config( mLinkFile, Config::File ); 870 Config config( mLinkFile, Config::File );
869 config.setGroup("Desktop Entry"); 871 config.setGroup("Desktop Entry");
870 config.writeEntry("Name",mName); 872 config.writeEntry("Name",mName);
871 if ( !mIconFile.isNull() ) config.writeEntry("Icon",mIconFile); 873 if ( !mIconFile.isNull() ) config.writeEntry("Icon",mIconFile);
872 config.writeEntry("Type",type()); 874 config.writeEntry("Type",type());
873 if(!rotation().isEmpty()) 875 if(!rotation().isEmpty())
874 config.writeEntry("Rotation",rotation()); 876 config.writeEntry("Rotation",rotation());
875 else 877 else
876 config.removeEntry("Rotation"); 878 config.removeEntry("Rotation");
877 if ( !mComment.isNull() ) config.writeEntry("Comment",mComment); 879 if ( !mComment.isNull() ) config.writeEntry("Comment",mComment);
878 QString f = file(); 880 QString f = file();
879 int i = 0; 881 int i = 0;
880 while ( i < (int)f.length() && i < (int)mLinkFile.length() && f[i] == mLinkFile[i] ) 882 while ( i < (int)f.length() && i < (int)mLinkFile.length() && f[i] == mLinkFile[i] )
881 i++; 883 i++;
882 while ( i && f[i] != '/' ) 884 while ( i && f[i] != '/' )
883 i--; 885 i--;
884 // simple case where in the same directory 886 // simple case where in the same directory
885 if ( mLinkFile.find( '/', i + 1 ) < 0 ) 887 if ( mLinkFile.find( '/', i + 1 ) < 0 )
886 f = f.mid(i+1); 888 f = f.mid(i+1);
887 // ### could do relative ie ../../otherDocs/file.doc 889 // ### could do relative ie ../../otherDocs/file.doc
888 config.writeEntry("File",f); 890 config.writeEntry("File",f);
889 config.writeEntry( "Categories", d->mCatList, ';' ); 891 config.writeEntry( "Categories", d->mCatList, ';' );
890 892
891#ifndef QT_NO_COP 893#ifndef QT_NO_COP
892 QCopEnvelope e("QPE/System", "linkChanged(QString)"); 894 QCopEnvelope e("QPE/System", "linkChanged(QString)");
893 e << mLinkFile; 895 e << mLinkFile;
894#endif 896#endif
895} 897}
896 898
897/*! 899/*!
898 Sets the property named \a key to \a value. 900 Sets the property named \a key to \a value.
899 901
900 \sa property() 902 \sa property()
901*/ 903*/
902void AppLnk::setProperty(const QString& key, const QString& value) 904void AppLnk::setProperty(const QString& key, const QString& value)
903{ 905{
904 if ( ensureLinkExists() ) { 906 if ( ensureLinkExists() ) {
905 Config cfg(linkFile(), Config::File); 907 Config cfg(linkFile(), Config::File);
906 cfg.writeEntry(key,value); 908 cfg.writeEntry(key,value);
907 } 909 }
908} 910}
909 911
910/*! 912/*!
911 Returns the property named \a key. 913 Returns the property named \a key.
912 914
913 \sa setProperty() 915 \sa setProperty()
914*/ 916*/
915QString AppLnk::property(const QString& key) const 917QString AppLnk::property(const QString& key) const
916{ 918{
917 QString lf = linkFile(); 919 QString lf = linkFile();
918 if ( !QFile::exists(lf) ) 920 if ( !QFile::exists(lf) )
919 return QString::null; 921 return QString::null;
920 Config cfg(lf, Config::File); 922 Config cfg(lf, Config::File);
921 return cfg.readEntry(key); 923 return cfg.readEntry(key);
922} 924}
923 925
924bool AppLnk::isPreloaded() const { 926bool AppLnk::isPreloaded() const {
925 // Preload information is stored in the Launcher config in v1.5. 927 // Preload information is stored in the Launcher config in v1.5.
926 Config cfg("Launcher"); 928 Config cfg("Launcher");
927 cfg.setGroup("Preload"); 929 cfg.setGroup("Preload");
928 QStringList apps = cfg.readListEntry("Apps",','); 930 QStringList apps = cfg.readListEntry("Apps",',');
929 if (apps.contains(exec())) 931 if (apps.contains(exec()))
930 return true; 932 return true;
931 return false; 933 return false;
932} 934}
933 935
934void AppLnk::setPreloaded(bool yesNo) { 936void AppLnk::setPreloaded(bool yesNo) {
935 // Preload information is stored in the Launcher config in v1.5. 937 // Preload information is stored in the Launcher config in v1.5.
936 Config cfg("Launcher"); 938 Config cfg("Launcher");
937 cfg.setGroup("Preload"); 939 cfg.setGroup("Preload");
938 QStringList apps = cfg.readListEntry("Apps", ','); 940 QStringList apps = cfg.readListEntry("Apps", ',');
939 if (apps.contains(exec()) && !yesNo) 941 if (apps.contains(exec()) && !yesNo)
940 apps.remove(exec()); 942 apps.remove(exec());
941 else if (yesNo && !apps.contains(exec())) 943 else if (yesNo && !apps.contains(exec()))
942 apps.append(exec()); 944 apps.append(exec());
943 cfg.writeEntry("Apps", apps, ','); 945 cfg.writeEntry("Apps", apps, ',');
944} 946}
945 947
946 948
947/*! 949/*!
948 Deletes both the linkFile() and the file() associated with this AppLnk. 950 Deletes both the linkFile() and the file() associated with this AppLnk.
949 951
950 \sa removeLinkFile() 952 \sa removeLinkFile()
951*/ 953*/
952void AppLnk::removeFiles() 954void AppLnk::removeFiles()
953{ 955{
954 bool valid = isValid(); 956 bool valid = isValid();
955 if ( !valid || !linkFileKnown() || QFile::remove(linkFile()) ) { 957 if ( !valid || !linkFileKnown() || QFile::remove(linkFile()) ) {
956 if ( QFile::remove(file()) ) { 958 if ( QFile::remove(file()) ) {
957#ifndef QT_NO_COP 959#ifndef QT_NO_COP
958 QCopEnvelope e("QPE/System", "linkChanged(QString)"); 960 QCopEnvelope e("QPE/System", "linkChanged(QString)");
959 if ( linkFileKnown() ) 961 if ( linkFileKnown() )
960 e << linkFile(); 962 e << linkFile();
961 else 963 else
962 e << file(); 964 e << file();
963#endif 965#endif
964 } else if ( valid ) { 966 } else if ( valid ) {
965 // restore link 967 // restore link
966 writeLink(); 968 writeLink();
967 } 969 }
968 } 970 }
969} 971}
970 972
971/*! 973/*!
972 Deletes the linkFile(), leaving any file() untouched. 974 Deletes the linkFile(), leaving any file() untouched.
973 975
974 \sa removeFiles() 976 \sa removeFiles()
975*/ 977*/
976void AppLnk::removeLinkFile() 978void AppLnk::removeLinkFile()
977{ 979{
978 if ( isValid() && linkFileKnown() && QFile::remove(linkFile()) ) { 980 if ( isValid() && linkFileKnown() && QFile::remove(linkFile()) ) {
979#ifndef QT_NO_COP 981#ifndef QT_NO_COP
980 QCopEnvelope e("QPE/System", "linkChanged(QString)"); 982 QCopEnvelope e("QPE/System", "linkChanged(QString)");
981 e << linkFile(); 983 e << linkFile();
982#endif 984#endif
983 } 985 }
984} 986}
985 987
986class AppLnkImagePrivate { 988class AppLnkImagePrivate {
987public : 989public :
988 AppLnkImagePrivate( const QString & ImageName ) { 990 AppLnkImagePrivate( const QString & ImageName ) {
989 IconName = ImageName; 991 IconName = ImageName;
990 Small = 0; 992 Small = 0;
991 Big = 0; 993 Big = 0;
992 } 994 }
993 ~AppLnkImagePrivate( ) { 995 ~AppLnkImagePrivate( ) {
994 if ( Small ) delete Small; 996 if ( Small ) delete Small;
995 if ( Big ) delete Big; 997 if ( Big ) delete Big;
996 } 998 }
997 999
998 inline QPixmap * small( void ) { 1000 inline QPixmap * small( void ) {
999 if( ! Small ) { 1001 if( ! Small ) {
1000 QImage unscaledIcon = Resource::loadImage( IconName ); 1002 QImage unscaledIcon = Resource::loadImage( IconName );
1001 // works as long as smallSize remains static 1003 // works as long as smallSize remains static
1002 Small = new QPixmap(); 1004 Small = new QPixmap();
1003 Small->convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) ); 1005 Small->convertFromImage( unscaledIcon.smoothScale( smallSize, smallSize ) );
1004 } 1006 }
1005 return Small; 1007 return Small;
1006 } 1008 }
1007 1009
1008 inline QPixmap * big( void ) { 1010 inline QPixmap * big( void ) {
1009 if( ! Big ) { 1011 if( ! Big ) {
1010 QImage unscaledIcon = Resource::loadImage( IconName ); 1012 QImage unscaledIcon = Resource::loadImage( IconName );
1011 // works as long as bigSize remains static 1013 // works as long as bigSize remains static
1012 Big = new QPixmap(); 1014 Big = new QPixmap();
1013 Big->convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) ); 1015 Big->convertFromImage( unscaledIcon.smoothScale( bigSize, bigSize ) );
1014 } 1016 }
1015 return Big; 1017 return Big;
1016 } 1018 }
1017 1019
1018 QString IconName; 1020 QString IconName;
1019 QPixmap * Small; 1021 QPixmap * Small;
1020 QPixmap * Big; 1022 QPixmap * Big;
1021}; 1023};
1022 1024
1023class AppLnkSetPrivate { 1025class AppLnkSetPrivate {
1024public: 1026public:
1025 AppLnkSetPrivate() 1027 AppLnkSetPrivate()
1026 { 1028 {
1027 typPix.setAutoDelete(TRUE); 1029 typPix.setAutoDelete(TRUE);
1028 typName.setAutoDelete(TRUE); 1030 typName.setAutoDelete(TRUE);
1029 } 1031 }
1030 1032
1031 QDict<AppLnkImagePrivate> typPix; 1033 QDict<AppLnkImagePrivate> typPix;
1032 QDict<QString> typName; 1034 QDict<QString> typName;
1033}; 1035};
1034 1036
1035/*! 1037/*!
1036 \class AppLnkSet applnk.h 1038 \class AppLnkSet applnk.h
1037 \brief The AppLnkSet class is a set of AppLnk objects. 1039 \brief The AppLnkSet class is a set of AppLnk objects.
1038*/ 1040*/
1039 1041
1040/*! 1042/*!
1041 \fn QStringList AppLnkSet::types() const 1043 \fn QStringList AppLnkSet::types() const
1042 1044
1043 Returns the list of \link applnk.html#Types types\endlink in the set. 1045 Returns the list of \link applnk.html#Types types\endlink in the set.
1044 1046
1045 For applications, games and settings the type is \c Application; 1047 For applications, games and settings the type is \c Application;
1046 for documents the type is the document's MIME type. 1048 for documents the type is the document's MIME type.
1047 1049
1048 \sa AppLnk::type(), typeName(), typePixmap(), typeBigPixmap() 1050 \sa AppLnk::type(), typeName(), typePixmap(), typeBigPixmap()
1049*/ 1051*/
1050 1052
1051/*! 1053/*!
1052 \fn const QList<AppLnk>& AppLnkSet::children() const 1054 \fn const QList<AppLnk>& AppLnkSet::children() const
1053 1055
1054 Returns the members of the set. 1056 Returns the members of the set.
1055*/ 1057*/
1056 1058
1057/*! 1059/*!
1058 Constructs an empty AppLnkSet. 1060 Constructs an empty AppLnkSet.
1059*/ 1061*/
1060AppLnkSet::AppLnkSet() : 1062AppLnkSet::AppLnkSet() :
1061 d(new AppLnkSetPrivate) 1063 d(new AppLnkSetPrivate)
1062{ 1064{
1063} 1065}
1064 1066
1065/*! 1067/*!
1066 Constructs an AppLnkSet that contains AppLnk objects representing 1068 Constructs an AppLnkSet that contains AppLnk objects representing
1067 all the files in the given \a directory (and any subdirectories 1069 all the files in the given \a directory (and any subdirectories
1068 recursively). 1070 recursively).
1069 1071
1070 \omit 1072 \omit
1071 The directories may contain ".directory" files which override 1073 The directories may contain ".directory" files which override
1072 any AppLnk::type() values for AppLnk objects found in the directory. 1074 any AppLnk::type() values for AppLnk objects found in the directory.
1073 This allows simple localization of application types. 1075 This allows simple localization of application types.
1074 \endomit 1076 \endomit
1075*/ 1077*/
1076AppLnkSet::AppLnkSet( const QString &directory ) : 1078AppLnkSet::AppLnkSet( const QString &directory ) :
1077 d(new AppLnkSetPrivate) 1079 d(new AppLnkSetPrivate)
1078{ 1080{
1079 QDir dir( directory ); 1081 QDir dir( directory );
1080 mFile = directory; 1082 mFile = directory;
1081 findChildren(directory,QString::null,QString::null); 1083 findChildren(directory,QString::null,QString::null);
1082} 1084}
1083 1085
1084/*! 1086/*!
1085 Detaches all AppLnk objects from the set. The set become empty and 1087 Detaches all AppLnk objects from the set. The set become empty and
1086 the caller becomes responsible for deleting the AppLnk objects. 1088 the caller becomes responsible for deleting the AppLnk objects.
1087*/ 1089*/
1088void AppLnkSet::detachChildren() 1090void AppLnkSet::detachChildren()
1089{ 1091{
1090 QListIterator<AppLnk> it( mApps ); 1092 QListIterator<AppLnk> it( mApps );
1091 for ( ; it.current(); ) { 1093 for ( ; it.current(); ) {
1092 AppLnk* a = *it; 1094 AppLnk* a = *it;
1093 ++it; 1095 ++it;
1094 a->mId = 0; 1096 a->mId = 0;
1095 } 1097 }
1096 mApps.clear(); 1098 mApps.clear();
1097} 1099}
1098 1100
1099/*! 1101/*!
1100 Destroys the set, deleting all the AppLnk objects it contains. 1102 Destroys the set, deleting all the AppLnk objects it contains.
1101 1103
1102 \sa detachChildren() 1104 \sa detachChildren()
1103*/ 1105*/
1104AppLnkSet::~AppLnkSet() 1106AppLnkSet::~AppLnkSet()
1105{ 1107{
1106 QListIterator<AppLnk> it( mApps ); 1108 QListIterator<AppLnk> it( mApps );
1107 for ( ; it.current(); ) { 1109 for ( ; it.current(); ) {
1108 AppLnk* a = *it; 1110 AppLnk* a = *it;
1109 ++it; 1111 ++it;
1110 a->mId = 0; 1112 a->mId = 0;
1111 delete a; 1113 delete a;
1112 } 1114 }
1113 delete d; 1115 delete d;
1114} 1116}
1115 1117
1116void AppLnkSet::findChildren(const QString &dr, const QString& typ, const QString& typName, int depth) 1118void AppLnkSet::findChildren(const QString &dr, const QString& typ, const QString& typName, int depth)
1117{ 1119{
1118 depth++; 1120 depth++;
1119 if ( depth > 10 ) 1121 if ( depth > 10 )
1120 return; 1122 return;
1121 1123
1122 QDir dir( dr ); 1124 QDir dir( dr );
1123 QString typNameLocal = typName; 1125 QString typNameLocal = typName;
1124 1126
1125 if ( dir.exists( ".directory" ) ) { 1127 if ( dir.exists( ".directory" ) ) {
1126 Config config( dr + "/.directory", Config::File ); 1128 Config config( dr + "/.directory", Config::File );
1127 config.setGroup( "Desktop Entry" ); 1129 config.setGroup( "Desktop Entry" );
1128 typNameLocal = config.readEntry( "Name", typNameLocal ); 1130 typNameLocal = config.readEntry( "Name", typNameLocal );
1129 if ( !typ.isEmpty() ) { 1131 if ( !typ.isEmpty() ) {
1130 d->typPix.insert( typ, 1132 d->typPix.insert( typ,
1131 new AppLnkImagePrivate( config.readEntry( "Icon", "AppsIcon" ) ) 1133 new AppLnkImagePrivate( config.readEntry( "Icon", "AppsIcon" ) )
1132 ); 1134 );
1133 d->typName.insert(typ, new QString(typNameLocal)); 1135 d->typName.insert(typ, new QString(typNameLocal));
1134 1136
1135 } 1137 }
1136 } 1138 }
1137 1139
1138 const QFileInfoList *list = dir.entryInfoList(); 1140 const QFileInfoList *list = dir.entryInfoList();
1139 if ( list ) { 1141 if ( list ) {
1140 QFileInfo* fi; 1142 QFileInfo* fi;
1141 bool cadded=FALSE; 1143 bool cadded=FALSE;
1142 for ( QFileInfoListIterator it(*list); (fi=*it); ++it ) { 1144 for ( QFileInfoListIterator it(*list); (fi=*it); ++it ) {
1143 QString bn = fi->fileName(); 1145 QString bn = fi->fileName();
1144 // qDebug("findChildren "+bn); 1146 // qDebug("findChildren "+bn);
1145 if ( bn[0] != '.' && bn != "CVS" ) { 1147 if ( bn[0] != '.' && bn != "CVS" ) {
1146 if ( fi->isDir() ) { 1148 if ( fi->isDir() ) {
1147 QString c = typ.isNull() ? bn : typ+"/"+bn; 1149 QString c = typ.isNull() ? bn : typ+"/"+bn;
1148 QString d = typNameLocal.isNull() ? bn : typNameLocal+"/"+bn; 1150 QString d = typNameLocal.isNull() ? bn : typNameLocal+"/"+bn;
1149 findChildren(fi->filePath(), c, d, depth ); 1151 findChildren(fi->filePath(), c, d, depth );
1150 } else { 1152 } else {
1151 if ( fi->extension(FALSE) == "desktop" ) { 1153 if ( fi->extension(FALSE) == "desktop" ) {
1152 AppLnk* app = new AppLnk( fi->filePath() ); 1154 AppLnk* app = new AppLnk( fi->filePath() );
1153#ifdef QT_NO_QWS_MULTIPROCESS 1155#ifdef QT_NO_QWS_MULTIPROCESS
1154 if ( !Global::isBuiltinCommand( app->exec() ) ) 1156 if ( !Global::isBuiltinCommand( app->exec() ) )
1155 delete app; 1157 delete app;
1156 else 1158 else
1157#endif 1159#endif
1158 { 1160 {
1159 if ( !typ.isEmpty() ) { 1161 if ( !typ.isEmpty() ) {
1160 if ( !cadded ) { 1162 if ( !cadded ) {
1161 typs.append(typ); 1163 typs.append(typ);
1162 cadded = TRUE; 1164 cadded = TRUE;
1163 } 1165 }
1164 app->setType(typ); 1166 app->setType(typ);
1165 } 1167 }
1166 add(app); 1168 add(app);
1167 } 1169 }
1168 } 1170 }
1169 } 1171 }
1170 } 1172 }
1171 } 1173 }
1172 } 1174 }
1173} 1175}
1174 1176
1175/*! 1177/*!
1176 Adds AppLnk \a f to the set. The set takes responsibility for 1178 Adds AppLnk \a f to the set. The set takes responsibility for
1177 deleting \a f. 1179 deleting \a f.
1178 1180
1179 \sa remove() 1181 \sa remove()
1180*/ 1182*/
1181void AppLnkSet::add( AppLnk *f ) 1183void AppLnkSet::add( AppLnk *f )
1182{ 1184{
1183 if ( f->mId == 0 ) { 1185 if ( f->mId == 0 ) {
1184 AppLnk::lastId++; 1186 AppLnk::lastId++;
1185 f->mId = AppLnk::lastId; 1187 f->mId = AppLnk::lastId;
1186 mApps.append( f ); 1188 mApps.append( f );
1187 } else { 1189 } else {
1188 qWarning("Attempt to add an AppLnk twice"); 1190 qWarning("Attempt to add an AppLnk twice");
1189 } 1191 }
1190} 1192}
1191 1193
1192/*! 1194/*!
1193 Removes AppLnk \a f to the set. The caller becomes responsible for 1195 Removes AppLnk \a f to the set. The caller becomes responsible for
1194 deleting \a f. Returns TRUE if \a f was in the set; otherwise 1196 deleting \a f. Returns TRUE if \a f was in the set; otherwise
1195 returns FALSE. 1197 returns FALSE.
1196 1198
1197 \sa add() 1199 \sa add()
1198*/ 1200*/
1199bool AppLnkSet::remove( AppLnk *f ) 1201bool AppLnkSet::remove( AppLnk *f )
1200{ 1202{
1201 if ( mApps.remove( f ) ) { 1203 if ( mApps.remove( f ) ) {
1202 f->mId = 0; 1204 f->mId = 0;
1203 return TRUE; 1205 return TRUE;
1204 } 1206 }
1205 return FALSE; 1207 return FALSE;
1206} 1208}
1207 1209
1208 1210
1209/*! 1211/*!
1210 Returns the localized name for type \a t. 1212 Returns the localized name for type \a t.
1211 1213
1212 For applications, games and settings the type is \c Application; 1214 For applications, games and settings the type is \c Application;
1213 for documents the type is the document's MIME type. 1215 for documents the type is the document's MIME type.
1214*/ 1216*/
1215QString AppLnkSet::typeName( const QString& t ) const 1217QString AppLnkSet::typeName( const QString& t ) const
1216{ 1218{
1217 QString *st = d->typName.find(t); 1219 QString *st = d->typName.find(t);
1218 return st ? *st : QString::null; 1220 return st ? *st : QString::null;
1219} 1221}
1220 1222
1221/*! 1223/*!
1222 Returns the small pixmap associated with type \a t. 1224 Returns the small pixmap associated with type \a t.
1223 1225
1224 For applications, games and settings the type is \c Application; 1226 For applications, games and settings the type is \c Application;
1225 for documents the type is the document's MIME type. 1227 for documents the type is the document's MIME type.
1226*/ 1228*/
1227QPixmap AppLnkSet::typePixmap( const QString& t ) const 1229QPixmap AppLnkSet::typePixmap( const QString& t ) const
1228{ 1230{
1229 AppLnkImagePrivate *alip = d->typPix.find(t); 1231 AppLnkImagePrivate *alip = d->typPix.find(t);
1230 return alip ? *(alip->small()) : QPixmap(); 1232 return alip ? *(alip->small()) : QPixmap();
1231} 1233}
1232 1234
1233/*! 1235/*!
1234 Returns the large pixmap associated with type \a t. 1236 Returns the large pixmap associated with type \a t.
1235 1237
1236 For applications, games and settings the type is \c Application; 1238 For applications, games and settings the type is \c Application;
1237 for documents the type is the document's MIME type. 1239 for documents the type is the document's MIME type.
1238*/ 1240*/
1239QPixmap AppLnkSet::typeBigPixmap( const QString& t ) const 1241QPixmap AppLnkSet::typeBigPixmap( const QString& t ) const
1240{ 1242{
1241 AppLnkImagePrivate *alip = d->typPix.find(t); 1243 AppLnkImagePrivate *alip = d->typPix.find(t);
1242 return alip ? *(alip->big()) : QPixmap(); 1244 return alip ? *(alip->big()) : QPixmap();
1243} 1245}
1244 1246
1245/*! 1247/*!
1246 Returns the AppLnk with the given \a id. 1248 Returns the AppLnk with the given \a id.
1247*/ 1249*/
1248const AppLnk *AppLnkSet::find( int id ) const 1250const AppLnk *AppLnkSet::find( int id ) const
1249{ 1251{
1250 QListIterator<AppLnk> it( children() ); 1252 QListIterator<AppLnk> it( children() );
1251 1253
1252 for ( ; it.current(); ++it ) { 1254 for ( ; it.current(); ++it ) {
1253 const AppLnk *app = it.current(); 1255 const AppLnk *app = it.current();
1254 if ( app->id() == id ) 1256 if ( app->id() == id )
1255 return app; 1257 return app;
1256 } 1258 }
1257 1259
1258 return 0; 1260 return 0;
1259} 1261}
1260 1262
1261/*! 1263/*!
1262 Returns the AppLnk with the given \a exec attribute. 1264 Returns the AppLnk with the given \a exec attribute.
1263*/ 1265*/
1264const AppLnk *AppLnkSet::findExec( const QString& exec ) const 1266const AppLnk *AppLnkSet::findExec( const QString& exec ) const
1265{ 1267{
1266 QListIterator<AppLnk> it( children() ); 1268 QListIterator<AppLnk> it( children() );
1267 1269
1268 for ( ; it.current(); ++it ) { 1270 for ( ; it.current(); ++it ) {
1269 const AppLnk *app = it.current(); 1271 const AppLnk *app = it.current();
1270 if ( app->exec() == exec ) 1272 if ( app->exec() == exec )
1271 return app; 1273 return app;
1272 } 1274 }
1273 1275
1274 return 0; 1276 return 0;
1275} 1277}
1276 1278
1277/*! 1279/*!
1278 \class DocLnkSet applnk.h 1280 \class DocLnkSet applnk.h
1279 \brief The DocLnkSet class is a set of DocLnk objects. 1281 \brief The DocLnkSet class is a set of DocLnk objects.
1280*/ 1282*/
1281 1283
1282/*! 1284/*!
1283 \fn const QList<DocLnk>& DocLnkSet::children() const 1285 \fn const QList<DocLnk>& DocLnkSet::children() const
1284 1286
1285 Returns the members of the set. 1287 Returns the members of the set.
1286*/ 1288*/
1287 1289
1288/*! 1290/*!
1289 Constructs an empty DocLnkSet. 1291 Constructs an empty DocLnkSet.
1290 1292
1291 \sa appendFrom() 1293 \sa appendFrom()
1292*/ 1294*/
1293DocLnkSet::DocLnkSet() 1295DocLnkSet::DocLnkSet()
1294{ 1296{
1295} 1297}
1296 1298
1297/*! 1299/*!
1298 Constructs a DocLnkSet that contains DocLnk objects representing all 1300 Constructs a DocLnkSet that contains DocLnk objects representing all
1299 the files in the \a directory (and any subdirectories, recursively). 1301 the files in the \a directory (and any subdirectories, recursively).
1300 1302
1301 If \a mimefilter is not null, 1303 If \a mimefilter is not null,
1302 only documents with a MIME type matching \a mimefilter are selected. 1304 only documents with a MIME type matching \a mimefilter are selected.
1303 The value may contain multiple wild-card patterns separated by ";", 1305 The value may contain multiple wild-card patterns separated by ";",
1304 such as \c{*o/mpeg;audio/x-wav}. 1306 such as \c{*o/mpeg;audio/x-wav}.
1305 1307
1306 See also \link applnk.html#files-and-links Files and Links\endlink. 1308 See also \link applnk.html#files-and-links Files and Links\endlink.
1307 1309
1308*/ 1310*/
1309DocLnkSet::DocLnkSet( const QString &directory, const QString& mimefilter ) : 1311DocLnkSet::DocLnkSet( const QString &directory, const QString& mimefilter ) :
1310 AppLnkSet() 1312 AppLnkSet()
1311{ 1313{
1312 QDir dir( directory ); 1314 QDir dir( directory );
1313 mFile = dir.dirName(); 1315 mFile = dir.dirName();
1314 QDict<void> reference(1021); 1316 QDict<void> reference(1021);
1315 1317
1316 QStringList subFilter = QStringList::split(";", mimefilter); 1318 QStringList subFilter = QStringList::split(";", mimefilter);
1317 QValueList<QRegExp> mimeFilters; 1319 QValueList<QRegExp> mimeFilters;
1318 for( QStringList::Iterator it = subFilter.begin(); it != subFilter.end(); ++ it ) 1320 for( QStringList::Iterator it = subFilter.begin(); it != subFilter.end(); ++ it )
1319 mimeFilters.append( QRegExp(*it, FALSE, TRUE) ); 1321 mimeFilters.append( QRegExp(*it, FALSE, TRUE) );
1320 1322
1321 findChildren(directory, mimeFilters, reference); 1323 findChildren(directory, mimeFilters, reference);
1322 1324
1323 const QList<DocLnk> &list = children(); 1325 const QList<DocLnk> &list = children();
1324 for ( QListIterator<DocLnk> it( list ); it.current(); ++it ) { 1326 for ( QListIterator<DocLnk> it( list ); it.current(); ++it ) {
1325 reference.remove( (*it)->file() ); 1327 reference.remove( (*it)->file() );
1326 } 1328 }
1327 for ( QDictIterator<void> dit(reference); dit.current(); ++dit ) { 1329 for ( QDictIterator<void> dit(reference); dit.current(); ++dit ) {
1328 if ( dit.current() == (void*)2 ) { 1330 if ( dit.current() == (void*)2 ) {
1329 // Unreferenced, make an unwritten link 1331 // Unreferenced, make an unwritten link
1330 DocLnk* dl = new DocLnk; 1332 DocLnk* dl = new DocLnk;
1331 QFileInfo fi( dit.currentKey() ); 1333 QFileInfo fi( dit.currentKey() );
1332 dl->setFile(fi.filePath()); 1334 dl->setFile(fi.filePath());
1333 dl->setName(fi.baseName()); 1335 dl->setName(fi.baseName());
1334 // #### default to current path? 1336 // #### default to current path?
1335 // dl->setCategories( ... ); 1337 // dl->setCategories( ... );
1336 bool match = mimefilter.isNull(); 1338 bool match = mimefilter.isNull();
1337 if ( !match ) 1339 if ( !match )
1338 for( QValueList<QRegExp>::Iterator it = mimeFilters.begin(); it != mimeFilters.end() && !match; ++ it ) 1340 for( QValueList<QRegExp>::Iterator it = mimeFilters.begin(); it != mimeFilters.end() && !match; ++ it )
1339 if ( (*it).match(dl->type()) >= 0 ) 1341 if ( (*it).match(dl->type()) >= 0 )
1340 match = TRUE; 1342 match = TRUE;
1341 if ( match /* && dl->type() != "application/octet-stream" */ 1343 if ( match /* && dl->type() != "application/octet-stream" */
1342 && !!dl->exec() ) 1344 && !!dl->exec() )
1343 add(dl); 1345 add(dl);
1344 else 1346 else
1345 delete dl; 1347 delete dl;
1346 } 1348 }
1347 } 1349 }
1348} 1350}
1349 1351
1350// other becomes empty 1352// other becomes empty
1351/*! 1353/*!
1352 Transfers all DocLnk objects from \a other to this set. \a other becomes 1354 Transfers all DocLnk objects from \a other to this set. \a other becomes
1353 empty. 1355 empty.
1354*/ 1356*/
1355void DocLnkSet::appendFrom( DocLnkSet& other ) 1357void DocLnkSet::appendFrom( DocLnkSet& other )
1356{ 1358{
1357 if ( &other == this ) 1359 if ( &other == this )
1358 return; 1360 return;
1359 QListIterator<AppLnk> it( other.mApps ); 1361 QListIterator<AppLnk> it( other.mApps );
1360 for ( ; it.current(); ) { 1362 for ( ; it.current(); ) {
1361 mApps.append(*it); 1363 mApps.append(*it);
1362 ++it; 1364 ++it;
1363 } 1365 }
1364 other.mApps.clear(); 1366 other.mApps.clear();
1365} 1367}
1366 1368
1367void DocLnkSet::findChildren(const QString &dr, const QValueList<QRegExp> &mimeFilters, QDict<void> &reference, int depth) 1369void DocLnkSet::findChildren(const QString &dr, const QValueList<QRegExp> &mimeFilters, QDict<void> &reference, int depth)
1368{ 1370{
1369 depth++; 1371 depth++;
1370 if ( depth > 10 ) 1372 if ( depth > 10 )
1371 return; 1373 return;
1372 1374
1373 QDir dir( dr ); 1375 QDir dir( dr );
1374 1376
1375 /* Opie got a different approach 1377 /* Opie got a different approach
1376 * I guess it's geek vs. consumer 1378 * I guess it's geek vs. consumer
1377 * in this case to be discussed 1379 * in this case to be discussed
1378 */ 1380 */
1379 if ( dir.exists( ".Qtopia-ignore" ) ) 1381 if ( dir.exists( ".Qtopia-ignore" ) )
1380 return; 1382 return;
1381 1383
1382 const QFileInfoList *list = dir.entryInfoList(); 1384 const QFileInfoList *list = dir.entryInfoList();
1383 if ( list ) { 1385 if ( list ) {
1384 QFileInfo* fi; 1386 QFileInfo* fi;
1385 for ( QFileInfoListIterator it(*list); (fi=*it); ++it ) { 1387 for ( QFileInfoListIterator it(*list); (fi=*it); ++it ) {
1386 QString bn = fi->fileName(); 1388 QString bn = fi->fileName();
1387 if ( bn[0] != '.' ) { 1389 if ( bn[0] != '.' ) {
1388 if ( fi->isDir() ) { 1390 if ( fi->isDir() ) {
1389 if ( bn != "CVS" && bn != "Qtopia" && bn != "QtPalmtop" ) 1391 if ( bn != "CVS" && bn != "Qtopia" && bn != "QtPalmtop" )
1390 findChildren(fi->filePath(), mimeFilters, reference, depth); 1392 findChildren(fi->filePath(), mimeFilters, reference, depth);
1391 } else { 1393 } else {
1392 if ( fi->extension(FALSE) == "desktop" ) { 1394 if ( fi->extension(FALSE) == "desktop" ) {
1393 DocLnk* dl = new DocLnk( fi->filePath() ); 1395 DocLnk* dl = new DocLnk( fi->filePath() );
1394 QFileInfo fi2(dl->file()); 1396 QFileInfo fi2(dl->file());
1395 bool match = FALSE; 1397 bool match = FALSE;
1396 if ( !fi2.exists() ) { 1398 if ( !fi2.exists() ) {
1397 dir.remove( dl->file() ); 1399 dir.remove( dl->file() );
1398 } 1400 }
1399 if ( mimeFilters.count() == 0 ) { 1401 if ( mimeFilters.count() == 0 ) {
1400 add( dl ); 1402 add( dl );
1401 match = TRUE; 1403 match = TRUE;
1402 } else { 1404 } else {
1403 for( QValueList<QRegExp>::ConstIterator it = mimeFilters.begin(); it != mimeFilters.end(); ++ it ) { 1405 for( QValueList<QRegExp>::ConstIterator it = mimeFilters.begin(); it != mimeFilters.end(); ++ it ) {
1404 if ( (*it).match(dl->type()) >= 0 ) { 1406 if ( (*it).match(dl->type()) >= 0 ) {
1405 add(dl); 1407 add(dl);
1406 match = TRUE; 1408 match = TRUE;
1407 } 1409 }
1408 } 1410 }
1409 } 1411 }
1410 if ( !match ) 1412 if ( !match )
1411 delete dl; 1413 delete dl;
1412 } else { 1414 } else {
1413 if ( !reference.find(fi->fileName()) ) 1415 if ( !reference.find(fi->fileName()) )
1414 reference.insert(fi->filePath(), (void*)2); 1416 reference.insert(fi->filePath(), (void*)2);
1415 } 1417 }
1416 } 1418 }
1417 } 1419 }
1418 } 1420 }
1419 } 1421 }
1420} 1422}
1421 1423
1422/*! 1424/*!
1423 \class DocLnk applnk.h 1425 \class DocLnk applnk.h
1424 \brief The DocLnk class represents loaded document references. 1426 \brief The DocLnk class represents loaded document references.
1425*/ 1427*/
1426 1428
1427/*! 1429/*!
1428 \fn DocLnk::DocLnk( const DocLnk &o ) 1430 \fn DocLnk::DocLnk( const DocLnk &o )
1429 1431
1430 Copies \a o. 1432 Copies \a o.
1431*/ 1433*/
1432 1434
1433/*! 1435/*!
1434 Constructs a DocLnk from a valid .desktop \a file or a new .desktop 1436 Constructs a DocLnk from a valid .desktop \a file or a new .desktop
1435 \a file for other files. 1437 \a file for other files.
1436*/ 1438*/
1437DocLnk::DocLnk( const QString &file ) : 1439DocLnk::DocLnk( const QString &file ) :
1438 AppLnk(file) 1440 AppLnk(file)
1439{ 1441{
1440 init(file); 1442 init(file);
1441} 1443}
1442 1444
1443/*! 1445/*!
1444 Constructs a DocLnk from a valid .desktop \a file or a new .desktop 1446 Constructs a DocLnk from a valid .desktop \a file or a new .desktop
1445 \a file for other files. If \a may_be_desktopfile is TRUE, then an 1447 \a file for other files. If \a may_be_desktopfile is TRUE, then an
1446 attempt is made to read \a file as a .desktop file; if that fails it 1448 attempt is made to read \a file as a .desktop file; if that fails it
1447 is read as a normal file. 1449 is read as a normal file.
1448*/ 1450*/
1449DocLnk::DocLnk( const QString &file, bool may_be_desktopfile ) : 1451DocLnk::DocLnk( const QString &file, bool may_be_desktopfile ) :
1450 AppLnk(may_be_desktopfile ? file : QString::null) 1452 AppLnk(may_be_desktopfile ? file : QString::null)
1451{ 1453{
1452 init(file); 1454 init(file);
1453} 1455}
1454 1456
1455void DocLnk::init(const QString &file) 1457void DocLnk::init(const QString &file)
1456{ 1458{
1457 if ( isValid() ) { 1459 if ( isValid() ) {
1458#ifndef FORCED_DIR_STRUCTURE_WAY 1460#ifndef FORCED_DIR_STRUCTURE_WAY
1459 if ( mType.isNull() ) 1461 if ( mType.isNull() )
1460 // try to infer it 1462 // try to infer it
1461#endif 1463#endif
1462 { 1464 {
1463 int s0 = file.findRev('/'); 1465 int s0 = file.findRev('/');
1464 if ( s0 > 0 ) { 1466 if ( s0 > 0 ) {
1465 int s1 = file.findRev('/',s0-1); 1467 int s1 = file.findRev('/',s0-1);
1466 if ( s1 > 0 ) { 1468 if ( s1 > 0 ) {
1467 int s2 = file.findRev('/',s1-1); 1469 int s2 = file.findRev('/',s1-1);
1468 if ( s2 > 0 ) { 1470 if ( s2 > 0 ) {
1469 mType = file.mid(s2+1,s0-s2-1); 1471 mType = file.mid(s2+1,s0-s2-1);
1470 } 1472 }
1471 } 1473 }
1472 } 1474 }
1473 } 1475 }
1474 } else if ( QFile::exists(file) ) { 1476 } else if ( QFile::exists(file) ) {
1475 QString n = file; 1477 QString n = file;
1476 n.replace(QRegExp(".*/"),""); 1478 n.replace(QRegExp(".*/"),"");
1477 n.replace(QRegExp("\\..*"),""); 1479 n.replace(QRegExp("\\..*"),"");
1478 setName( n ); 1480 setName( n );
1479 setFile( file ); 1481 setFile( file );
1480 } 1482 }
1481 MimeType mt(mType); 1483 MimeType mt(mType);
1482 if( mt.application() ) 1484 if( mt.application() )
1483 mExec = mt.application()->exec(); 1485 mExec = mt.application()->exec();
1484} 1486}
1485 1487
1486/*! 1488/*!
1487 Constructs an invalid DocLnk. 1489 Constructs an invalid DocLnk.
1488*/ 1490*/
1489DocLnk::DocLnk() 1491DocLnk::DocLnk()
1490{ 1492{
1491} 1493}
1492 1494
1493/*! 1495/*!
1494 Destroys the DocLnk. Just like AppLnk objects, a run-time error 1496 Destroys the DocLnk. Just like AppLnk objects, a run-time error
1495 occurs if the DocLnk is a member of a DocLnkSet (or AppLnkSet). 1497 occurs if the DocLnk is a member of a DocLnkSet (or AppLnkSet).
1496*/ 1498*/
1497DocLnk::~DocLnk() 1499DocLnk::~DocLnk()
1498{ 1500{
1499} 1501}
1500 1502
1501/*! 1503/*!
1502 \reimp 1504 \reimp
1503*/ 1505*/
1504QString DocLnk::exec() const 1506QString DocLnk::exec() const
1505{ 1507{
1506 MimeType mt(type()); 1508 MimeType mt(type());
1507 const AppLnk* app = mt.application(); 1509 const AppLnk* app = mt.application();
1508 if ( app ) 1510 if ( app )
1509 return app->exec(); 1511 return app->exec();
1510 else 1512 else
1511 return QString::null; 1513 return QString::null;
1512} 1514}
1513 1515
1514/*! 1516/*!
1515 \reimp 1517 \reimp
1516*/ 1518*/
1517void DocLnk::invoke(const QStringList& args) const 1519void DocLnk::invoke(const QStringList& args) const
1518{ 1520{
1519 MimeType mt(type()); 1521 MimeType mt(type());
1520 const AppLnk* app = mt.application(); 1522 const AppLnk* app = mt.application();
1521 if ( app ) { 1523 if ( app ) {
1522 QStringList a = args; 1524 QStringList a = args;
1523 if ( linkFileKnown() && QFile::exists( linkFile() ) ) 1525 if ( linkFileKnown() && QFile::exists( linkFile() ) )
1524 a.append(linkFile()); 1526 a.append(linkFile());
1525 else 1527 else
1526 a.append(file()); 1528 a.append(file());
1527 app->execute(a); 1529 app->execute(a);
1528 } 1530 }
1529} 1531}
1530 1532
1531 1533
diff --git a/library/qpeapplication.cpp b/library/qpeapplication.cpp
index 0f3e4a4..19e99f2 100644
--- a/library/qpeapplication.cpp
+++ b/library/qpeapplication.cpp
@@ -1,2287 +1,2290 @@
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
103static bool useBigPixmaps = 0; 103static bool useBigPixmaps = 0;
104 104
105class HackWidget : public QWidget 105class HackWidget : public QWidget
106{ 106{
107public: 107public:
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
115class QPEApplicationData 115class QPEApplicationData
116{ 116{
117public: 117public:
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#ifndef OPIE_NO_WINDOWED
254 maximized = TRUE; 254 maximized = TRUE;
255 // 350 is the trigger in qwsdefaultdecoration for providing a resize button 255 // 350 is the trigger in qwsdefaultdecoration for providing a resize button
256 if ( qApp->desktop()->width() <= 350 ) 256 if ( qApp->desktop()->width() <= 350 )
257 return FALSE; 257 return FALSE;
258 258
259 Config cfg( "qpe" ); 259 Config cfg( "qpe" );
260 cfg.setGroup("ApplicationPositions"); 260 cfg.setGroup("ApplicationPositions");
261 QString str = cfg.readEntry( app, QString::null ); 261 QString str = cfg.readEntry( app, QString::null );
262 QStringList l = QStringList::split(",", str); 262 QStringList l = QStringList::split(",", str);
263 263
264 if ( l.count() == 5) { 264 if ( l.count() == 5) {
265 p.setX( l[0].toInt() ); 265 p.setX( l[0].toInt() );
266 p.setY( l[1].toInt() ); 266 p.setY( l[1].toInt() );
267 267
268 s.setWidth( l[2].toInt() ); 268 s.setWidth( l[2].toInt() );
269 s.setHeight( l[3].toInt() ); 269 s.setHeight( l[3].toInt() );
270 270
271 maximized = l[4].toInt(); 271 maximized = l[4].toInt();
272 272
273 return TRUE; 273 return TRUE;
274 } 274 }
275#endif 275#endif
276 return FALSE; 276 return FALSE;
277 } 277 }
278 278
279 279
280 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)
281 { 281 {
282#ifndef Q_WS_QWS 282#ifndef Q_WS_QWS
283 QRect qt_maxWindowRect = qApp->desktop()->geometry(); 283 QRect qt_maxWindowRect = qApp->desktop()->geometry();
284#endif 284#endif
285 int maxX = qt_maxWindowRect.width(); 285 int maxX = qt_maxWindowRect.width();
286 int maxY = qt_maxWindowRect.height(); 286 int maxY = qt_maxWindowRect.height();
287 int wWidth = s.width() + ( w->frameGeometry().width() - w->geometry().width() ); 287 int wWidth = s.width() + ( w->frameGeometry().width() - w->geometry().width() );
288 int wHeight = s.height() + ( w->frameGeometry().height() - w->geometry().height() ); 288 int wHeight = s.height() + ( w->frameGeometry().height() - w->geometry().height() );
289 289
290 // 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
291 if ( ( wWidth >= maxX ) && ( wHeight >= maxY ) ) 291 if ( ( wWidth >= maxX ) && ( wHeight >= maxY ) )
292 return FALSE; 292 return FALSE;
293 293
294 if ( wWidth > maxX ) { 294 if ( wWidth > maxX ) {
295 s.setWidth( maxX - (w->frameGeometry().width() - w->geometry().width() ) ); 295 s.setWidth( maxX - (w->frameGeometry().width() - w->geometry().width() ) );
296 wWidth = maxX; 296 wWidth = maxX;
297 } 297 }
298 298
299 if ( wHeight > maxY ) { 299 if ( wHeight > maxY ) {
300 s.setHeight( maxY - (w->frameGeometry().height() - w->geometry().height() ) ); 300 s.setHeight( maxY - (w->frameGeometry().height() - w->geometry().height() ) );
301 wHeight = maxY; 301 wHeight = maxY;
302 } 302 }
303 303
304 // 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
305 if ( wWidth < 80 || wHeight < 60 ) 305 if ( wWidth < 80 || wHeight < 60 )
306 return FALSE; 306 return FALSE;
307 307
308 if ( p.x() < 0 ) 308 if ( p.x() < 0 )
309 p.setX(0); 309 p.setX(0);
310 if ( p.y() < 0 ) 310 if ( p.y() < 0 )
311 p.setY(0); 311 p.setY(0);
312 312
313 if ( p.x() + wWidth > maxX ) 313 if ( p.x() + wWidth > maxX )
314 p.setX( maxX - wWidth ); 314 p.setX( maxX - wWidth );
315 if ( p.y() + wHeight > maxY ) 315 if ( p.y() + wHeight > maxY )
316 p.setY( maxY - wHeight ); 316 p.setY( maxY - wHeight );
317 317
318 return TRUE; 318 return TRUE;
319 } 319 }
320 320
321 static void store_widget_rect(QWidget *w, QString &app) 321 static void store_widget_rect(QWidget *w, QString &app)
322 { 322 {
323 if( !w ) 323 if( !w )
324 return; 324 return;
325#ifndef OPIE_NO_WINDOWED 325#ifndef OPIE_NO_WINDOWED
326 // 350 is the trigger in qwsdefaultdecoration for providing a resize button 326 // 350 is the trigger in qwsdefaultdecoration for providing a resize button
327 if ( qApp->desktop()->width() <= 350 ) 327 if ( qApp->desktop()->width() <= 350 )
328 return; 328 return;
329 // 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
330 // 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 )
331 int offsetX = w->x() - w->geometry().left(); 331 int offsetX = w->x() - w->geometry().left();
332 int offsetY = w->y() - w->geometry().top(); 332 int offsetY = w->y() - w->geometry().top();
333 333
334 QRect r; 334 QRect r;
335 if ( w->isMaximized() ) 335 if ( w->isMaximized() )
336 r = ( (HackWidget *) w)->normalGeometry(); 336 r = ( (HackWidget *) w)->normalGeometry();
337 else 337 else
338 r = w->geometry(); 338 r = w->geometry();
339 339
340 // 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)
341 Config cfg( "qpe" ); 341 Config cfg( "qpe" );
342 cfg.setGroup("ApplicationPositions"); 342 cfg.setGroup("ApplicationPositions");
343 QString s; 343 QString s;
344 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() );
345 cfg.writeEntry( app, s ); 345 cfg.writeEntry( app, s );
346#endif 346#endif
347 } 347 }
348 348
349 static bool setWidgetCaptionFromAppName( QWidget* /*mw*/, const QString& /*appName*/, const QString& /*appsPath*/ ) 349 static bool setWidgetCaptionFromAppName( QWidget* /*mw*/, const QString& /*appName*/, const QString& /*appsPath*/ )
350 { 350 {
351 /* 351 /*
352 // 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
353 // 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
354 // the applnk that has the corresponding argv[0] as this program 354 // 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 355 // then it uses the name stored in the .desktop file as the caption
356 // for the main widget. This saves duplicating translations for 356 // for the main widget. This saves duplicating translations for
357 // the app name in the program and in the .desktop files. 357 // the app name in the program and in the .desktop files.
358 358
359 AppLnkSet apps( appsPath ); 359 AppLnkSet apps( appsPath );
360 360
361 QList<AppLnk> appsList = apps.children(); 361 QList<AppLnk> appsList = apps.children();
362 for ( QListIterator<AppLnk> it(appsList); it.current(); ++it ) { 362 for ( QListIterator<AppLnk> it(appsList); it.current(); ++it ) {
363 if ( (*it)->exec() == appName ) { 363 if ( (*it)->exec() == appName ) {
364 mw->setCaption( (*it)->name() ); 364 mw->setCaption( (*it)->name() );
365 return TRUE; 365 return TRUE;
366 } 366 }
367 } 367 }
368 */ 368 */
369 return FALSE; 369 return FALSE;
370 } 370 }
371 371
372 372
373 void show(QWidget* mw, bool nomax) 373 void show(QWidget* mw, bool nomax)
374 { 374 {
375 setWidgetCaptionFromAppName( mw, appName, QPEApplication::qpeDir() + "apps" ); 375 setWidgetCaptionFromAppName( mw, appName, QPEApplication::qpeDir() + "apps" );
376 nomaximize = nomax; 376 nomaximize = nomax;
377 qpe_main_widget = mw; 377 qpe_main_widget = mw;
378 qcopQok = TRUE; 378 qcopQok = TRUE;
379#ifndef QT_NO_COP 379#ifndef QT_NO_COP
380 380
381 sendQCopQ(); 381 sendQCopQ();
382#endif 382#endif
383 383
384 if ( preloaded ) { 384 if ( preloaded ) {
385 if (forceshow) 385 if (forceshow)
386 show_mx(mw, nomax, appName); 386 show_mx(mw, nomax, appName);
387 } 387 }
388 else if ( keep_running ) { 388 else if ( keep_running ) {
389 show_mx(mw, nomax, appName); 389 show_mx(mw, nomax, appName);
390 } 390 }
391 } 391 }
392 392
393 void loadTextCodecs() 393 void loadTextCodecs()
394 { 394 {
395 QString path = QPEApplication::qpeDir() + "plugins/textcodecs"; 395 QString path = QPEApplication::qpeDir() + "plugins/textcodecs";
396#ifdef Q_OS_MACX 396#ifdef Q_OS_MACX
397 QDir dir( path, "lib*.dylib" ); 397 QDir dir( path, "lib*.dylib" );
398#else 398#else
399 QDir dir( path, "lib*.so" ); 399 QDir dir( path, "lib*.so" );
400#endif 400#endif
401 QStringList list; 401 QStringList list;
402 if ( dir. exists ( )) 402 if ( dir. exists ( ))
403 list = dir.entryList(); 403 list = dir.entryList();
404 QStringList::Iterator it; 404 QStringList::Iterator it;
405 for ( it = list.begin(); it != list.end(); ++it ) { 405 for ( it = list.begin(); it != list.end(); ++it ) {
406 TextCodecInterface *iface = 0; 406 TextCodecInterface *iface = 0;
407 QLibrary *lib = new QLibrary( path + "/" + *it ); 407 QLibrary *lib = new QLibrary( path + "/" + *it );
408 if ( lib->queryInterface( IID_QtopiaTextCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) { 408 if ( lib->queryInterface( IID_QtopiaTextCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) {
409 QValueList<int> mibs = iface->mibEnums(); 409 QValueList<int> mibs = iface->mibEnums();
410 for (QValueList<int>::ConstIterator i = mibs.begin(); i != mibs.end(); ++i) { 410 for (QValueList<int>::ConstIterator i = mibs.begin(); i != mibs.end(); ++i) {
411 (void)iface->createForMib(*i); 411 (void)iface->createForMib(*i);
412 // ### it exists now; need to remember if we can delete it 412 // ### it exists now; need to remember if we can delete it
413 } 413 }
414 } 414 }
415 else { 415 else {
416 lib->unload(); 416 lib->unload();
417 delete lib; 417 delete lib;
418 } 418 }
419 } 419 }
420 } 420 }
421 421
422 void loadImageCodecs() 422 void loadImageCodecs()
423 { 423 {
424 QString path = QPEApplication::qpeDir() + "plugins/imagecodecs"; 424 QString path = QPEApplication::qpeDir() + "plugins/imagecodecs";
425#ifdef Q_OS_MACX 425#ifdef Q_OS_MACX
426 QDir dir( path, "lib*.dylib" ); 426 QDir dir( path, "lib*.dylib" );
427#else 427#else
428 QDir dir( path, "lib*.so" ); 428 QDir dir( path, "lib*.so" );
429#endif 429#endif
430 QStringList list; 430 QStringList list;
431 if ( dir. exists ( )) 431 if ( dir. exists ( ))
432 list = dir.entryList(); 432 list = dir.entryList();
433 QStringList::Iterator it; 433 QStringList::Iterator it;
434 for ( it = list.begin(); it != list.end(); ++it ) { 434 for ( it = list.begin(); it != list.end(); ++it ) {
435 ImageCodecInterface *iface = 0; 435 ImageCodecInterface *iface = 0;
436 QLibrary *lib = new QLibrary( path + "/" + *it ); 436 QLibrary *lib = new QLibrary( path + "/" + *it );
437 if ( lib->queryInterface( IID_QtopiaImageCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) { 437 if ( lib->queryInterface( IID_QtopiaImageCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) {
438 QStringList formats = iface->keys(); 438 QStringList formats = iface->keys();
439 for (QStringList::ConstIterator i = formats.begin(); i != formats.end(); ++i) { 439 for (QStringList::ConstIterator i = formats.begin(); i != formats.end(); ++i) {
440 (void)iface->installIOHandler(*i); 440 (void)iface->installIOHandler(*i);
441 // ### it exists now; need to remember if we can delete it 441 // ### it exists now; need to remember if we can delete it
442 } 442 }
443 } 443 }
444 else { 444 else {
445 lib->unload(); 445 lib->unload();
446 delete lib; 446 delete lib;
447 } 447 }
448 } 448 }
449 } 449 }
450 450
451}; 451};
452 452
453class ResourceMimeFactory : public QMimeSourceFactory 453class ResourceMimeFactory : public QMimeSourceFactory
454{ 454{
455public: 455public:
456 ResourceMimeFactory() : resImage( 0 ) 456 ResourceMimeFactory() : resImage( 0 )
457 { 457 {
458 setFilePath( Global::helpPath() ); 458 setFilePath( Global::helpPath() );
459 setExtensionType( "html", "text/html;charset=UTF-8" ); 459 setExtensionType( "html", "text/html;charset=UTF-8" );
460 } 460 }
461 ~ResourceMimeFactory() { 461 ~ResourceMimeFactory() {
462 delete resImage; 462 delete resImage;
463 } 463 }
464 464
465 const QMimeSource* data( const QString& abs_name ) const 465 const QMimeSource* data( const QString& abs_name ) const
466 { 466 {
467 const QMimeSource * r = QMimeSourceFactory::data( abs_name ); 467 const QMimeSource * r = QMimeSourceFactory::data( abs_name );
468 if ( !r ) { 468 if ( !r ) {
469 int sl = abs_name.length(); 469 int sl = abs_name.length();
470 do { 470 do {
471 sl = abs_name.findRev( '/', sl - 1 ); 471 sl = abs_name.findRev( '/', sl - 1 );
472 QString name = sl >= 0 ? abs_name.mid( sl + 1 ) : abs_name; 472 QString name = sl >= 0 ? abs_name.mid( sl + 1 ) : abs_name;
473 int dot = name.findRev( '.' ); 473 int dot = name.findRev( '.' );
474 if ( dot >= 0 ) 474 if ( dot >= 0 )
475 name = name.left( dot ); 475 name = name.left( dot );
476 QImage img = Resource::loadImage( name ); 476 QImage img = Resource::loadImage( name );
477 if ( !img.isNull() ) { 477 if ( !img.isNull() ) {
478 delete resImage; 478 delete resImage;
479 resImage = new QImageDrag( img ); 479 resImage = new QImageDrag( img );
480 r = resImage; 480 r = resImage;
481 } 481 }
482 } 482 }
483 while ( !r && sl > 0 ); 483 while ( !r && sl > 0 );
484 } 484 }
485 return r; 485 return r;
486 } 486 }
487private: 487private:
488 mutable QImageDrag *resImage; 488 mutable QImageDrag *resImage;
489}; 489};
490 490
491static int& hack(int& i) 491static int& hack(int& i)
492{ 492{
493#if QT_VERSION <= 230 && defined(QT_NO_CODECS) 493#if QT_VERSION <= 230 && defined(QT_NO_CODECS)
494 // 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
495 (void)new QUtf8Codec; 495 (void)new QUtf8Codec;
496 (void)new QUtf16Codec; 496 (void)new QUtf16Codec;
497#endif 497#endif
498 return i; 498 return i;
499} 499}
500 500
501static int muted = 0; 501static int muted = 0;
502static int micMuted = 0; 502static int micMuted = 0;
503 503
504static void setVolume( int t = 0, int percent = -1 ) 504static void setVolume( int t = 0, int percent = -1 )
505{ 505{
506 switch ( t ) { 506 switch ( t ) {
507 case 0: { 507 case 0: {
508 Config cfg( "qpe" ); 508 Config cfg( "qpe" );
509 cfg.setGroup( "Volume" ); 509 cfg.setGroup( "Volume" );
510 if ( percent < 0 ) 510 if ( percent < 0 )
511 percent = cfg.readNumEntry( "VolumePercent", 50 ); 511 percent = cfg.readNumEntry( "VolumePercent", 50 );
512#ifndef QT_NO_SOUND 512#ifndef QT_NO_SOUND
513 int fd = 0; 513 int fd = 0;
514#ifdef QT_QWS_DEVFS 514#ifdef QT_QWS_DEVFS
515 if ( ( fd = open( "/dev/sound/mixer", O_RDWR ) ) >= 0 ) { 515 if ( ( fd = open( "/dev/sound/mixer", O_RDWR ) ) >= 0 ) {
516#else 516#else
517 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { 517 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
518#endif 518#endif
519 int vol = muted ? 0 : percent; 519 int vol = muted ? 0 : percent;
520 // set both channels to same volume 520 // set both channels to same volume
521 vol |= vol << 8; 521 vol |= vol << 8;
522 ioctl( fd, MIXER_WRITE( SOUND_MIXER_VOLUME ), &vol ); 522 ioctl( fd, MIXER_WRITE( SOUND_MIXER_VOLUME ), &vol );
523 ::close( fd ); 523 ::close( fd );
524 } 524 }
525#endif 525#endif
526 } 526 }
527 break; 527 break;
528 } 528 }
529} 529}
530 530
531static void setMic( int t = 0, int percent = -1 ) 531static void setMic( int t = 0, int percent = -1 )
532{ 532{
533 switch ( t ) { 533 switch ( t ) {
534 case 0: { 534 case 0: {
535 Config cfg( "qpe" ); 535 Config cfg( "qpe" );
536 cfg.setGroup( "Volume" ); 536 cfg.setGroup( "Volume" );
537 if ( percent < 0 ) 537 if ( percent < 0 )
538 percent = cfg.readNumEntry( "Mic", 50 ); 538 percent = cfg.readNumEntry( "Mic", 50 );
539 539
540#ifndef QT_NO_SOUND 540#ifndef QT_NO_SOUND
541 int fd = 0; 541 int fd = 0;
542 int mic = micMuted ? 0 : percent; 542 int mic = micMuted ? 0 : percent;
543#ifdef QT_QWS_DEVFS 543#ifdef QT_QWS_DEVFS
544 if ( ( fd = open( "/dev/sound/mixer", O_RDWR ) ) >= 0 ) { 544 if ( ( fd = open( "/dev/sound/mixer", O_RDWR ) ) >= 0 ) {
545#else 545#else
546 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { 546 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
547#endif 547#endif
548 ioctl( fd, MIXER_WRITE( SOUND_MIXER_MIC ), &mic ); 548 ioctl( fd, MIXER_WRITE( SOUND_MIXER_MIC ), &mic );
549 ::close( fd ); 549 ::close( fd );
550 } 550 }
551#endif 551#endif
552 } 552 }
553 break; 553 break;
554 } 554 }
555} 555}
556 556
557 557
558static void setBass( int t = 0, int percent = -1 ) 558static void setBass( int t = 0, int percent = -1 )
559{ 559{
560 switch ( t ) { 560 switch ( t ) {
561 case 0: { 561 case 0: {
562 Config cfg( "qpe" ); 562 Config cfg( "qpe" );
563 cfg.setGroup( "Volume" ); 563 cfg.setGroup( "Volume" );
564 if ( percent < 0 ) 564 if ( percent < 0 )
565 percent = cfg.readNumEntry( "BassPercent", 50 ); 565 percent = cfg.readNumEntry( "BassPercent", 50 );
566 566
567#ifndef QT_NO_SOUND 567#ifndef QT_NO_SOUND
568 int fd = 0; 568 int fd = 0;
569 int bass = percent; 569 int bass = percent;
570#ifdef QT_QWS_DEVFS 570#ifdef QT_QWS_DEVFS
571 if ( ( fd = open( "/dev/sound/mixer", O_RDWR ) ) >= 0 ) { 571 if ( ( fd = open( "/dev/sound/mixer", O_RDWR ) ) >= 0 ) {
572#else 572#else
573 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { 573 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
574#endif 574#endif
575 ioctl( fd, MIXER_WRITE( SOUND_MIXER_BASS ), &bass ); 575 ioctl( fd, MIXER_WRITE( SOUND_MIXER_BASS ), &bass );
576 ::close( fd ); 576 ::close( fd );
577 } 577 }
578#endif 578#endif
579 } 579 }
580 break; 580 break;
581 } 581 }
582} 582}
583 583
584 584
585static void setTreble( int t = 0, int percent = -1 ) 585static void setTreble( int t = 0, int percent = -1 )
586{ 586{
587 switch ( t ) { 587 switch ( t ) {
588 case 0: { 588 case 0: {
589 Config cfg( "qpe" ); 589 Config cfg( "qpe" );
590 cfg.setGroup( "Volume" ); 590 cfg.setGroup( "Volume" );
591 if ( percent < 0 ) 591 if ( percent < 0 )
592 percent = cfg.readNumEntry( "TreblePercent", 50 ); 592 percent = cfg.readNumEntry( "TreblePercent", 50 );
593 593
594#ifndef QT_NO_SOUND 594#ifndef QT_NO_SOUND
595 int fd = 0; 595 int fd = 0;
596 int treble = percent; 596 int treble = percent;
597#ifdef QT_QWS_DEVFS 597#ifdef QT_QWS_DEVFS
598 if ( ( fd = open( "/dev/sound/mixer", O_RDWR ) ) >= 0 ) { 598 if ( ( fd = open( "/dev/sound/mixer", O_RDWR ) ) >= 0 ) {
599#else 599#else
600 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { 600 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
601#endif 601#endif
602 ioctl( fd, MIXER_WRITE( SOUND_MIXER_TREBLE ), &treble ); 602 ioctl( fd, MIXER_WRITE( SOUND_MIXER_TREBLE ), &treble );
603 ::close( fd ); 603 ::close( fd );
604 } 604 }
605#endif 605#endif
606 } 606 }
607 break; 607 break;
608 } 608 }
609} 609}
610 610
611 611
612/** 612/**
613 \class QPEApplication 613 \class QPEApplication
614 \brief The QPEApplication class implements various system services 614 \brief The QPEApplication class implements various system services
615 that are available to all Qtopia applications. 615 that are available to all Qtopia applications.
616 616
617 Simply by using QPEApplication instead of QApplication, a standard Qt 617 Simply by using QPEApplication instead of QApplication, a standard Qt
618 application becomes a Qtopia application. It automatically follows 618 application becomes a Qtopia application. It automatically follows
619 style changes, quits and raises, and in the 619 style changes, quits and raises, and in the
620 case of \link docwidget.html document-oriented\endlink applications, 620 case of \link docwidget.html document-oriented\endlink applications,
621 changes the currently displayed document in response to the environment. 621 changes the currently displayed document in response to the environment.
622 622
623 To create a \link docwidget.html document-oriented\endlink 623 To create a \link docwidget.html document-oriented\endlink
624 application use showMainDocumentWidget(); to create a 624 application use showMainDocumentWidget(); to create a
625 non-document-oriented application use showMainWidget(). The 625 non-document-oriented application use showMainWidget(). The
626 keepRunning() function indicates whether the application will 626 keepRunning() function indicates whether the application will
627 continue running after it's processed the last \link qcop.html 627 continue running after it's processed the last \link qcop.html
628 QCop\endlink message. This can be changed using setKeepRunning(). 628 QCop\endlink message. This can be changed using setKeepRunning().
629 629
630 A variety of signals are emitted when certain events occur, for 630 A variety of signals are emitted when certain events occur, for
631 example, timeChanged(), clockChanged(), weekChanged(), 631 example, timeChanged(), clockChanged(), weekChanged(),
632 dateFormatChanged() and volumeChanged(). If the application receives 632 dateFormatChanged() and volumeChanged(). If the application receives
633 a \link qcop.html QCop\endlink message on the application's 633 a \link qcop.html QCop\endlink message on the application's
634 QPE/Application/\e{appname} channel, the appMessage() signal is 634 QPE/Application/\e{appname} channel, the appMessage() signal is
635 emitted. There are also flush() and reload() signals, which 635 emitted. There are also flush() and reload() signals, which
636 are emitted when synching begins and ends respectively - upon these 636 are emitted when synching begins and ends respectively - upon these
637 signals, the application should save and reload any data 637 signals, the application should save and reload any data
638 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
639 be received and unfiltered through the appMessage() signal. 639 be received and unfiltered through the appMessage() signal.
640 640
641 This class also provides a set of useful static functions. The 641 This class also provides a set of useful static functions. The
642 qpeDir() and documentDir() functions return the respective paths. 642 qpeDir() and documentDir() functions return the respective paths.
643 The grabKeyboard() and ungrabKeyboard() functions are used to 643 The grabKeyboard() and ungrabKeyboard() functions are used to
644 control whether the application takes control of the device's 644 control whether the application takes control of the device's
645 physical buttons (e.g. application launch keys). The stylus' mode of 645 physical buttons (e.g. application launch keys). The stylus' mode of
646 operation is set with setStylusOperation() and retrieved with 646 operation is set with setStylusOperation() and retrieved with
647 stylusOperation(). There are also setInputMethodHint() and 647 stylusOperation(). There are also setInputMethodHint() and
648 inputMethodHint() functions. 648 inputMethodHint() functions.
649 649
650 \ingroup qtopiaemb 650 \ingroup qtopiaemb
651*/ 651*/
652 652
653/*! 653/*!
654 \fn void QPEApplication::clientMoused() 654 \fn void QPEApplication::clientMoused()
655 655
656 \internal 656 \internal
657*/ 657*/
658 658
659/*! 659/*!
660 \fn void QPEApplication::timeChanged(); 660 \fn void QPEApplication::timeChanged();
661 This signal is emitted when the time changes outside the normal 661 This signal is emitted when the time changes outside the normal
662 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.
663*/ 663*/
664 664
665/*! 665/*!
666 \fn void QPEApplication::clockChanged( bool ampm ); 666 \fn void QPEApplication::clockChanged( bool ampm );
667 667
668 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
669 \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,
670 they want a 24-hour clock. 670 they want a 24-hour clock.
671*/ 671*/
672 672
673/*! 673/*!
674 \fn void QPEApplication::volumeChanged( bool muted ) 674 \fn void QPEApplication::volumeChanged( bool muted )
675 675
676 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
677 muted is TRUE, then sound output has been muted. 677 muted is TRUE, then sound output has been muted.
678*/ 678*/
679 679
680/*! 680/*!
681 \fn void QPEApplication::weekChanged( bool startOnMonday ) 681 \fn void QPEApplication::weekChanged( bool startOnMonday )
682 682
683 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
684 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
685 \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
686 Sunday. 686 Sunday.
687*/ 687*/
688 688
689/*! 689/*!
690 \fn void QPEApplication::dateFormatChanged(DateFormat) 690 \fn void QPEApplication::dateFormatChanged(DateFormat)
691 691
692 This signal is emitted whenever the date format is changed. 692 This signal is emitted whenever the date format is changed.
693*/ 693*/
694 694
695/*! 695/*!
696 \fn void QPEApplication::flush() 696 \fn void QPEApplication::flush()
697 697
698 ### 698 ###
699*/ 699*/
700 700
701/*! 701/*!
702 \fn void QPEApplication::reload() 702 \fn void QPEApplication::reload()
703 703
704*/ 704*/
705 705
706 706
707 707
708void QPEApplication::processQCopFile() 708void QPEApplication::processQCopFile()
709{ 709{
710 QString qcopfn("/tmp/qcop-msg-"); 710 QString qcopfn("/tmp/qcop-msg-");
711 qcopfn += d->appName; // append command name 711 qcopfn += d->appName; // append command name
712 712
713 QFile f(qcopfn); 713 QFile f(qcopfn);
714 if ( f.open(IO_ReadWrite) ) { 714 if ( f.open(IO_ReadWrite) ) {
715#ifndef Q_OS_WIN32 715#ifndef Q_OS_WIN32
716 flock(f.handle(), LOCK_EX); 716 flock(f.handle(), LOCK_EX);
717#endif 717#endif
718 QDataStream ds(&f); 718 QDataStream ds(&f);
719 QCString channel, message; 719 QCString channel, message;
720 QByteArray data; 720 QByteArray data;
721 while(!ds.atEnd()) { 721 while(!ds.atEnd()) {
722 ds >> channel >> message >> data; 722 ds >> channel >> message >> data;
723 d->enqueueQCop(channel,message,data); 723 d->enqueueQCop(channel,message,data);
724 } 724 }
725 ::ftruncate(f.handle(), 0); 725 ::ftruncate(f.handle(), 0);
726#ifndef Q_OS_WIN32 726#ifndef Q_OS_WIN32
727 f.flush(); 727 f.flush();
728 flock(f.handle(), LOCK_UN); 728 flock(f.handle(), LOCK_UN);
729#endif 729#endif
730 } 730 }
731#endif 731#endif
732} 732}
733 733
734 734
735/*! 735/*!
736 \fn void QPEApplication::appMessage( const QCString& msg, const QByteArray& data ) 736 \fn void QPEApplication::appMessage( const QCString& msg, const QByteArray& data )
737 737
738 This signal is emitted when a message is received on this 738 This signal is emitted when a message is received on this
739 application's QPE/Application/<i>appname</i> \link qcop.html 739 application's QPE/Application/<i>appname</i> \link qcop.html
740 QCop\endlink channel. 740 QCop\endlink channel.
741 741
742 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
743 in the following way: 743 in the following way:
744 744
745\code 745\code
746 void MyWidget::receive( const QCString& msg, const QByteArray& data ) 746 void MyWidget::receive( const QCString& msg, const QByteArray& data )
747 { 747 {
748 QDataStream stream( data, IO_ReadOnly ); 748 QDataStream stream( data, IO_ReadOnly );
749 if ( msg == "someMessage(int,int,int)" ) { 749 if ( msg == "someMessage(int,int,int)" ) {
750 int a,b,c; 750 int a,b,c;
751 stream >> a >> b >> c; 751 stream >> a >> b >> c;
752 ... 752 ...
753 } else if ( msg == "otherMessage(QString)" ) { 753 } else if ( msg == "otherMessage(QString)" ) {
754 ... 754 ...
755 } 755 }
756 } 756 }
757\endcode 757\endcode
758 758
759 \sa qcop.html 759 \sa qcop.html
760 Note that messages received here may be processed by qpe application 760 Note that messages received here may be processed by qpe application
761 and emitted as signals, such as flush() and reload(). 761 and emitted as signals, such as flush() and reload().
762*/ 762*/
763 763
764#ifndef QT_NO_TRANSLATION 764#ifndef QT_NO_TRANSLATION
765static void qtopia_loadTranslations( const QStringList& qms ) 765static void qtopia_loadTranslations( const QStringList& qms )
766{ 766{
767 QStringList langs = Global::languageList(); 767 QStringList langs = Global::languageList();
768 768
769 for (QStringList::ConstIterator it = langs.begin(); it!=langs.end(); ++it) { 769 for (QStringList::ConstIterator it = langs.begin(); it!=langs.end(); ++it) {
770 QString lang = *it; 770 QString lang = *it;
771 771
772 QTranslator * trans; 772 QTranslator * trans;
773 QString tfn; 773 QString tfn;
774 774
775 for (QStringList::ConstIterator qmit = qms.begin(); qmit!=qms.end(); ++qmit) { 775 for (QStringList::ConstIterator qmit = qms.begin(); qmit!=qms.end(); ++qmit) {
776 trans = new QTranslator(qApp); 776 trans = new QTranslator(qApp);
777 tfn = QPEApplication::qpeDir() + "i18n/" + lang + "/" + *qmit + ".qm"; 777 tfn = QPEApplication::qpeDir() + "i18n/" + lang + "/" + *qmit + ".qm";
778 if ( trans->load( tfn )) 778 if ( trans->load( tfn ))
779 qApp->installTranslator( trans ); 779 qApp->installTranslator( trans );
780 else 780 else
781 delete trans; 781 delete trans;
782 } 782 }
783 } 783 }
784} 784}
785#endif 785#endif
786 786
787/* 787/*
788 Turn off qDebug in release mode 788 Turn off qDebug in release mode
789 */ 789 */
790static void qtopiaMsgHandler(QtMsgType type, const char* msg) 790static void qtopiaMsgHandler(QtMsgType type, const char* msg)
791{ 791{
792 switch ( type ) { 792 switch ( type ) {
793 case QtDebugMsg: 793 case QtDebugMsg:
794#ifdef QT_DEBUG 794#ifdef QT_DEBUG
795 fprintf( stderr, "Debug: %s\n", msg ); 795 fprintf( stderr, "Debug: %s\n", msg );
796#endif 796#endif
797 break; 797 break;
798 case QtWarningMsg: 798 case QtWarningMsg:
799#ifdef QT_DEBUG 799#ifdef QT_DEBUG
800 fprintf( stderr, "Warning: %s\n", msg ); 800 fprintf( stderr, "Warning: %s\n", msg );
801#endif 801#endif
802 break; 802 break;
803 case QtFatalMsg: 803 case QtFatalMsg:
804 fprintf( stderr, "Fatal: %s\n", msg ); 804 fprintf( stderr, "Fatal: %s\n", msg );
805 abort(); 805 abort();
806 } 806 }
807} 807}
808 808
809/*! 809/*!
810 Constructs a QPEApplication just as you would construct 810 Constructs a QPEApplication just as you would construct
811 a QApplication, passing \a argc, \a argv, and \a t. 811 a QApplication, passing \a argc, \a argv, and \a t.
812 812
813 For applications, \a t should be the default, GuiClient. Only 813 For applications, \a t should be the default, GuiClient. Only
814 the Qtopia server passes GuiServer. 814 the Qtopia server passes GuiServer.
815*/ 815*/
816QPEApplication::QPEApplication( int & argc, char **argv, Type t ) 816QPEApplication::QPEApplication( int & argc, char **argv, Type t )
817 : QApplication( hack(argc), argv, t ), pidChannel( 0 ) 817 : QApplication( hack(argc), argv, t ), pidChannel( 0 )
818{ 818{
819 QPixmapCache::setCacheLimit(256); // sensible default for smaller devices. 819 QPixmapCache::setCacheLimit(256); // sensible default for smaller devices.
820 qInstallMsgHandler(qtopiaMsgHandler); 820 qInstallMsgHandler(qtopiaMsgHandler);
821 821
822 d = new QPEApplicationData; 822 d = new QPEApplicationData;
823 d->loadTextCodecs(); 823 d->loadTextCodecs();
824 d->loadImageCodecs(); 824 d->loadImageCodecs();
825 825
826 setFont( QFont( d->fontFamily, d->fontSize ) ); 826 setFont( QFont( d->fontFamily, d->fontSize ) );
827 AppLnk::setSmallIconSize( d->smallIconSize ); 827 AppLnk::setSmallIconSize( d->smallIconSize );
828 AppLnk::setBigIconSize( d->bigIconSize ); 828 AppLnk::setBigIconSize( d->bigIconSize );
829 829
830 QMimeSourceFactory::setDefaultFactory( new ResourceMimeFactory ); 830 QMimeSourceFactory::setDefaultFactory( new ResourceMimeFactory );
831 831
832 connect( this, SIGNAL( lastWindowClosed() ), this, SLOT( hideOrQuit() ) ); 832 connect( this, SIGNAL( lastWindowClosed() ), this, SLOT( hideOrQuit() ) );
833 833
834 834
835 sysChannel = new QCopChannel( "QPE/System", this ); 835 sysChannel = new QCopChannel( "QPE/System", this );
836 connect( sysChannel, SIGNAL( received(const QCString&,const QByteArray&) ), 836 connect( sysChannel, SIGNAL( received(const QCString&,const QByteArray&) ),
837 this, SLOT( systemMessage(const QCString&,const QByteArray&) ) ); 837 this, SLOT( systemMessage(const QCString&,const QByteArray&) ) );
838 838
839/* COde now in initapp */ 839/* COde now in initapp */
840#if 0 840#if 0
841#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 841#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
842 842
843 QString qcopfn( "/tmp/qcop-msg-" ); 843 QString qcopfn( "/tmp/qcop-msg-" );
844 qcopfn += QString( argv[ 0 ] ); // append command name 844 qcopfn += QString( argv[ 0 ] ); // append command name
845 845
846 QFile f( qcopfn ); 846 QFile f( qcopfn );
847 if ( f.open( IO_ReadOnly ) ) { 847 if ( f.open( IO_ReadOnly ) ) {
848 flock( f.handle(), LOCK_EX ); 848 flock( f.handle(), LOCK_EX );
849 } 849 }
850 850
851 851
852 852
853 QCString channel = QCString( argv[ 0 ] ); 853 QCString channel = QCString( argv[ 0 ] );
854 channel.replace( QRegExp( ".*/" ), "" ); 854 channel.replace( QRegExp( ".*/" ), "" );
855 d->appName = channel; 855 d->appName = channel;
856 channel = "QPE/Application/" + channel; 856 channel = "QPE/Application/" + channel;
857 pidChannel = new QCopChannel( channel, this ); 857 pidChannel = new QCopChannel( channel, this );
858 connect( pidChannel, SIGNAL( received(const QCString&,const QByteArray&) ), 858 connect( pidChannel, SIGNAL( received(const QCString&,const QByteArray&) ),
859 this, SLOT( pidMessage(const QCString&,const QByteArray&) ) ); 859 this, SLOT( pidMessage(const QCString&,const QByteArray&) ) );
860 860
861 if ( f.isOpen() ) { 861 if ( f.isOpen() ) {
862 d->keep_running = FALSE; 862 d->keep_running = FALSE;
863 QDataStream ds( &f ); 863 QDataStream ds( &f );
864 QCString channel, message; 864 QCString channel, message;
865 QByteArray data; 865 QByteArray data;
866 while ( !ds.atEnd() ) { 866 while ( !ds.atEnd() ) {
867 ds >> channel >> message >> data; 867 ds >> channel >> message >> data;
868 d->enqueueQCop( channel, message, data ); 868 d->enqueueQCop( channel, message, data );
869 } 869 }
870 870
871 flock( f.handle(), LOCK_UN ); 871 flock( f.handle(), LOCK_UN );
872 f.close(); 872 f.close();
873 f.remove(); 873 f.remove();
874 } 874 }
875 875
876 for ( int a = 0; a < argc; a++ ) { 876 for ( int a = 0; a < argc; a++ ) {
877 if ( qstrcmp( argv[ a ], "-preload" ) == 0 ) { 877 if ( qstrcmp( argv[ a ], "-preload" ) == 0 ) {
878 argv[ a ] = argv[ a + 1 ]; 878 argv[ a ] = argv[ a + 1 ];
879 a++; 879 a++;
880 d->preloaded = TRUE; 880 d->preloaded = TRUE;
881 argc -= 1; 881 argc -= 1;
882 } 882 }
883 else if ( qstrcmp( argv[ a ], "-preload-show" ) == 0 ) { 883 else if ( qstrcmp( argv[ a ], "-preload-show" ) == 0 ) {
884 argv[ a ] = argv[ a + 1 ]; 884 argv[ a ] = argv[ a + 1 ];
885 a++; 885 a++;
886 d->preloaded = TRUE; 886 d->preloaded = TRUE;
887 d->forceshow = TRUE; 887 d->forceshow = TRUE;
888 argc -= 1; 888 argc -= 1;
889 } 889 }
890 } 890 }
891 891
892 /* overide stored arguments */ 892 /* overide stored arguments */
893 setArgs( argc, argv ); 893 setArgs( argc, argv );
894 894
895#endif 895#endif
896#else 896#else
897 initApp( argc, argv ); 897 initApp( argc, argv );
898#endif 898#endif
899#ifdef Q_WS_QWS 899#ifdef Q_WS_QWS
900 /* load the font renderer factories */ 900 /* load the font renderer factories */
901 FontDatabase::loadRenderers(); 901 FontDatabase::loadRenderers();
902#endif 902#endif
903#ifndef QT_NO_TRANSLATION 903#ifndef QT_NO_TRANSLATION
904 QStringList qms; 904 QStringList qms;
905 qms << "libqpe"; 905 qms << "libqpe";
906 qms << "libopie"; 906 qms << "libopie";
907 qms << d->appName; 907 qms << d->appName;
908 908
909 qtopia_loadTranslations(qms); 909 qtopia_loadTranslations(qms);
910#endif 910#endif
911 911
912 applyStyle(); 912 applyStyle();
913 913
914 if ( type() == GuiServer ) { 914 if ( type() == GuiServer ) {
915 setVolume(); 915 setVolume();
916 } 916 }
917 917
918 installEventFilter( this ); 918 installEventFilter( this );
919 919
920 QPEMenuToolFocusManager::initialize(); 920 QPEMenuToolFocusManager::initialize();
921 921
922#ifdef QT_NO_QWS_CURSOR 922#ifdef QT_NO_QWS_CURSOR
923 // if we have no cursor, probably don't want tooltips 923 // if we have no cursor, probably don't want tooltips
924 QToolTip::setEnabled( FALSE ); 924 QToolTip::setEnabled( FALSE );
925#endif 925#endif
926} 926}
927 927
928 928
929#ifdef QTOPIA_INTERNAL_INITAPP 929#ifdef QTOPIA_INTERNAL_INITAPP
930void QPEApplication::initApp( int argc, char **argv ) 930void QPEApplication::initApp( int argc, char **argv )
931{ 931{
932 delete pidChannel; 932 delete pidChannel;
933 d->keep_running = TRUE; 933 d->keep_running = TRUE;
934 d->preloaded = FALSE; 934 d->preloaded = FALSE;
935 d->forceshow = FALSE; 935 d->forceshow = FALSE;
936 936
937 QCString channel = QCString(argv[0]); 937 QCString channel = QCString(argv[0]);
938 938
939 channel.replace(QRegExp(".*/"),""); 939 channel.replace(QRegExp(".*/"),"");
940 d->appName = channel; 940 d->appName = channel;
941 941
942#ifndef QT_NO_TRANSLATION 942#ifndef QT_NO_TRANSLATION
943 qtopia_loadTranslations( QStringList()<<channel ); 943 qtopia_loadTranslations( QStringList()<<channel );
944#endif 944#endif
945 945
946 #if QT_VERSION > 235 946 #if QT_VERSION > 235
947 qt_fbdpy->setIdentity( channel ); // In Qt/E 2.3.6 947 qt_fbdpy->setIdentity( channel ); // In Qt/E 2.3.6
948 #endif 948 #endif
949 949
950 channel = "QPE/Application/" + channel; 950 channel = "QPE/Application/" + channel;
951 pidChannel = new QCopChannel( channel, this); 951 pidChannel = new QCopChannel( channel, this);
952 connect( pidChannel, SIGNAL(received(const QCString&,const QByteArray&)), 952 connect( pidChannel, SIGNAL(received(const QCString&,const QByteArray&)),
953 this, SLOT(pidMessage(const QCString&,const QByteArray&))); 953 this, SLOT(pidMessage(const QCString&,const QByteArray&)));
954 954
955 955
956 956
957 processQCopFile(); 957 processQCopFile();
958 d->keep_running = d->qcopq.isEmpty(); 958 d->keep_running = d->qcopq.isEmpty();
959 959
960 for (int a=0; a<argc; a++) { 960 for (int a=0; a<argc; a++) {
961 if ( qstrcmp(argv[a],"-preload")==0 ) { 961 if ( qstrcmp(argv[a],"-preload")==0 ) {
962 argv[a] = argv[a+1]; 962 argv[a] = argv[a+1];
963 a++; 963 a++;
964 d->preloaded = TRUE; 964 d->preloaded = TRUE;
965 argc-=1; 965 argc-=1;
966 } else if ( qstrcmp(argv[a],"-preload-show")==0 ) { 966 } else if ( qstrcmp(argv[a],"-preload-show")==0 ) {
967 argv[a] = argv[a+1]; 967 argv[a] = argv[a+1];
968 a++; 968 a++;
969 d->preloaded = TRUE; 969 d->preloaded = TRUE;
970 d->forceshow = TRUE; 970 d->forceshow = TRUE;
971 argc-=1; 971 argc-=1;
972 } 972 }
973 } 973 }
974 974
975 /* overide stored arguments */ 975 /* overide stored arguments */
976 setArgs(argc, argv); 976 setArgs(argc, argv);
977} 977}
978#endif 978#endif
979 979
980 980
981static QPtrDict<void>* inputMethodDict = 0; 981static QPtrDict<void>* inputMethodDict = 0;
982static void createInputMethodDict() 982static void createInputMethodDict()
983{ 983{
984 if ( !inputMethodDict ) 984 if ( !inputMethodDict )
985 inputMethodDict = new QPtrDict<void>; 985 inputMethodDict = new QPtrDict<void>;
986} 986}
987 987
988/*! 988/*!
989 Returns the currently set hint to the system as to whether 989 Returns the currently set hint to the system as to whether
990 widget \a w has any use for text input methods. 990 widget \a w has any use for text input methods.
991 991
992 992
993 \sa setInputMethodHint() InputMethodHint 993 \sa setInputMethodHint() InputMethodHint
994*/ 994*/
995QPEApplication::InputMethodHint QPEApplication::inputMethodHint( QWidget * w ) 995QPEApplication::InputMethodHint QPEApplication::inputMethodHint( QWidget * w )
996{ 996{
997 if ( inputMethodDict && w ) 997 if ( inputMethodDict && w )
998 return ( InputMethodHint ) ( int ) inputMethodDict->find( w ); 998 return ( InputMethodHint ) ( int ) inputMethodDict->find( w );
999 return Normal; 999 return Normal;
1000} 1000}
1001 1001
1002/*! 1002/*!
1003 \enum QPEApplication::InputMethodHint 1003 \enum QPEApplication::InputMethodHint
1004 1004
1005 \value Normal the application sometimes needs text input (the default). 1005 \value Normal the application sometimes needs text input (the default).
1006 \value AlwaysOff the application never needs text input. 1006 \value AlwaysOff the application never needs text input.
1007 \value AlwaysOn the application always needs text input. 1007 \value AlwaysOn the application always needs text input.
1008*/ 1008*/
1009 1009
1010/*! 1010/*!
1011 Hints to the system that widget \a w has use for text input methods 1011 Hints to the system that widget \a w has use for text input methods
1012 as specified by \a mode. 1012 as specified by \a mode.
1013 1013
1014 \sa inputMethodHint() InputMethodHint 1014 \sa inputMethodHint() InputMethodHint
1015*/ 1015*/
1016void QPEApplication::setInputMethodHint( QWidget * w, InputMethodHint mode ) 1016void QPEApplication::setInputMethodHint( QWidget * w, InputMethodHint mode )
1017{ 1017{
1018 createInputMethodDict(); 1018 createInputMethodDict();
1019 if ( mode == Normal ) { 1019 if ( mode == Normal ) {
1020 inputMethodDict->remove 1020 inputMethodDict->remove
1021 ( w ); 1021 ( w );
1022 } 1022 }
1023 else { 1023 else {
1024 inputMethodDict->insert( w, ( void* ) mode ); 1024 inputMethodDict->insert( w, ( void* ) mode );
1025 } 1025 }
1026} 1026}
1027 1027
1028class HackDialog : public QDialog 1028class HackDialog : public QDialog
1029{ 1029{
1030public: 1030public:
1031 void acceptIt() 1031 void acceptIt()
1032 { 1032 {
1033 accept(); 1033 accept();
1034 } 1034 }
1035 void rejectIt() 1035 void rejectIt()
1036 { 1036 {
1037 reject(); 1037 reject();
1038 } 1038 }
1039}; 1039};
1040 1040
1041 1041
1042void QPEApplication::mapToDefaultAction( QWSKeyEvent * ke, int key ) 1042void QPEApplication::mapToDefaultAction( QWSKeyEvent * ke, int key )
1043{ 1043{
1044 // specialised actions for certain widgets. May want to 1044 // specialised actions for certain widgets. May want to
1045 // add more stuff here. 1045 // add more stuff here.
1046 if ( activePopupWidget() && activePopupWidget() ->inherits( "QListBox" ) 1046 if ( activePopupWidget() && activePopupWidget() ->inherits( "QListBox" )
1047 && activePopupWidget() ->parentWidget() 1047 && activePopupWidget() ->parentWidget()
1048 && activePopupWidget() ->parentWidget() ->inherits( "QComboBox" ) ) 1048 && activePopupWidget() ->parentWidget() ->inherits( "QComboBox" ) )
1049 key = Qt::Key_Return; 1049 key = Qt::Key_Return;
1050 1050
1051 if ( activePopupWidget() && activePopupWidget() ->inherits( "QPopupMenu" ) ) 1051 if ( activePopupWidget() && activePopupWidget() ->inherits( "QPopupMenu" ) )
1052 key = Qt::Key_Return; 1052 key = Qt::Key_Return;
1053 1053
1054#ifdef QWS 1054#ifdef QWS
1055 1055
1056 ke->simpleData.keycode = key; 1056 ke->simpleData.keycode = key;
1057#endif 1057#endif
1058} 1058}
1059 1059
1060 1060
1061/*! 1061/*!
1062 \internal 1062 \internal
1063*/ 1063*/
1064 1064
1065#ifdef QWS 1065#ifdef QWS
1066bool QPEApplication::qwsEventFilter( QWSEvent * e ) 1066bool QPEApplication::qwsEventFilter( QWSEvent * e )
1067{ 1067{
1068 if ( !d->notbusysent && e->type == QWSEvent::Focus ) { 1068 if ( !d->notbusysent && e->type == QWSEvent::Focus ) {
1069 if ( qApp->type() != QApplication::GuiServer ) { 1069 if ( qApp->type() != QApplication::GuiServer ) {
1070 QCopEnvelope e( "QPE/System", "notBusy(QString)" ); 1070 QCopEnvelope e( "QPE/System", "notBusy(QString)" );
1071 e << d->appName; 1071 e << d->appName;
1072 } 1072 }
1073 d->notbusysent = TRUE; 1073 d->notbusysent = TRUE;
1074 } 1074 }
1075 if ( type() == GuiServer ) { 1075 if ( type() == GuiServer ) {
1076 switch ( e->type ) { 1076 switch ( e->type ) {
1077 case QWSEvent::Mouse: 1077 case QWSEvent::Mouse:
1078 if ( e->asMouse() ->simpleData.state && !QWidget::find( e->window() ) ) 1078 if ( e->asMouse() ->simpleData.state && !QWidget::find( e->window() ) )
1079 emit clientMoused(); 1079 emit clientMoused();
1080 break; 1080 break;
1081 default: 1081 default:
1082 break; 1082 break;
1083 } 1083 }
1084 } 1084 }
1085 if ( e->type == QWSEvent::Key ) { 1085 if ( e->type == QWSEvent::Key ) {
1086 QWSKeyEvent *ke = ( QWSKeyEvent * ) e; 1086 QWSKeyEvent *ke = ( QWSKeyEvent * ) e;
1087 if ( ke->simpleData.keycode == Qt::Key_F33 ) { 1087 if ( ke->simpleData.keycode == Qt::Key_F33 ) {
1088 // Use special "OK" key to press "OK" on top level widgets 1088 // Use special "OK" key to press "OK" on top level widgets
1089 QWidget * active = activeWindow(); 1089 QWidget * active = activeWindow();
1090 QWidget *popup = 0; 1090 QWidget *popup = 0;
1091 if ( active && active->isPopup() ) { 1091 if ( active && active->isPopup() ) {
1092 popup = active; 1092 popup = active;
1093 active = active->parentWidget(); 1093 active = active->parentWidget();
1094 } 1094 }
1095 if ( active && ( int ) active->winId() == ke->simpleData.window && 1095 if ( active && ( int ) active->winId() == ke->simpleData.window &&
1096 !active->testWFlags( WStyle_Customize | WType_Popup | WType_Desktop ) ) { 1096 !active->testWFlags( WStyle_Customize | WType_Popup | WType_Desktop ) ) {
1097 if ( ke->simpleData.is_press ) { 1097 if ( ke->simpleData.is_press ) {
1098 if ( popup ) 1098 if ( popup )
1099 popup->close(); 1099 popup->close();
1100 if ( active->inherits( "QDialog" ) ) { 1100 if ( active->inherits( "QDialog" ) ) {
1101 HackDialog * d = ( HackDialog * ) active; 1101 HackDialog * d = ( HackDialog * ) active;
1102 d->acceptIt(); 1102 d->acceptIt();
1103 return TRUE; 1103 return TRUE;
1104 } 1104 }
1105 else if ( ( ( HackWidget * ) active ) ->needsOk() ) { 1105 else if ( ( ( HackWidget * ) active ) ->needsOk() ) {
1106 QSignal s; 1106 QSignal s;
1107 s.connect( active, SLOT( accept() ) ); 1107 s.connect( active, SLOT( accept() ) );
1108 s.activate(); 1108 s.activate();
1109 } 1109 }
1110 else { 1110 else {
1111 // do the same as with the select key: Map to the default action of the widget: 1111 // do the same as with the select key: Map to the default action of the widget:
1112 mapToDefaultAction( ke, Qt::Key_Return ); 1112 mapToDefaultAction( ke, Qt::Key_Return );
1113 } 1113 }
1114 } 1114 }
1115 } 1115 }
1116 } 1116 }
1117 else if ( ke->simpleData.keycode == Qt::Key_F30 ) { 1117 else if ( ke->simpleData.keycode == Qt::Key_F30 ) {
1118 // Use special "select" key to do whatever default action a widget has 1118 // Use special "select" key to do whatever default action a widget has
1119 mapToDefaultAction( ke, Qt::Key_Space ); 1119 mapToDefaultAction( ke, Qt::Key_Space );
1120 } 1120 }
1121 else if ( ke->simpleData.keycode == Qt::Key_Escape && 1121 else if ( ke->simpleData.keycode == Qt::Key_Escape &&
1122 ke->simpleData.is_press ) { 1122 ke->simpleData.is_press ) {
1123 // Escape key closes app if focus on toplevel 1123 // Escape key closes app if focus on toplevel
1124 QWidget * active = activeWindow(); 1124 QWidget * active = activeWindow();
1125 if ( active && active->testWFlags( WType_TopLevel ) && 1125 if ( active && active->testWFlags( WType_TopLevel ) &&
1126 ( int ) active->winId() == ke->simpleData.window && 1126 ( int ) active->winId() == ke->simpleData.window &&
1127 !active->testWFlags( WStyle_Dialog | WStyle_Customize | WType_Popup | WType_Desktop ) ) { 1127 !active->testWFlags( WStyle_Dialog | WStyle_Customize | WType_Popup | WType_Desktop ) ) {
1128 if ( active->inherits( "QDialog" ) ) { 1128 if ( active->inherits( "QDialog" ) ) {
1129 HackDialog * d = ( HackDialog * ) active; 1129 HackDialog * d = ( HackDialog * ) active;
1130 d->rejectIt(); 1130 d->rejectIt();
1131 return TRUE; 1131 return TRUE;
1132 } else /*if ( strcmp( argv() [ 0 ], "embeddedkonsole" ) != 0 )*/ { 1132 } else /*if ( strcmp( argv() [ 0 ], "embeddedkonsole" ) != 0 )*/ {
1133 active->close(); 1133 active->close();
1134 } 1134 }
1135 } 1135 }
1136 1136
1137 } 1137 }
1138 else if ( ke->simpleData.keycode >= Qt::Key_F1 && ke->simpleData.keycode <= Qt::Key_F29 ) { 1138 else if ( ke->simpleData.keycode >= Qt::Key_F1 && ke->simpleData.keycode <= Qt::Key_F29 ) {
1139 // this should be if ( ODevice::inst ( )-> buttonForKeycode ( ... )) 1139 // this should be if ( ODevice::inst ( )-> buttonForKeycode ( ... ))
1140 // but we cannot access libopie function within libqpe :( 1140 // but we cannot access libopie function within libqpe :(
1141 1141
1142 QWidget * active = activeWindow ( ); 1142 QWidget * active = activeWindow ( );
1143 if ( active && ((int) active-> winId ( ) == ke-> simpleData.window )) { 1143 if ( active && ((int) active-> winId ( ) == ke-> simpleData.window )) {
1144 if ( d-> kbgrabbed ) { // we grabbed the keyboard 1144 if ( d-> kbgrabbed ) { // we grabbed the keyboard
1145 QChar ch ( ke-> simpleData.unicode ); 1145 QChar ch ( ke-> simpleData.unicode );
1146 QKeyEvent qke ( ke-> simpleData. is_press ? QEvent::KeyPress : QEvent::KeyRelease, 1146 QKeyEvent qke ( ke-> simpleData. is_press ? QEvent::KeyPress : QEvent::KeyRelease,
1147 ke-> simpleData.keycode, 1147 ke-> simpleData.keycode,
1148 ch. latin1 ( ), 1148 ch. latin1 ( ),
1149 ke-> simpleData.modifiers, 1149 ke-> simpleData.modifiers,
1150 QString ( ch ), 1150 QString ( ch ),
1151 ke-> simpleData.is_auto_repeat, 1 ); 1151 ke-> simpleData.is_auto_repeat, 1 );
1152 1152
1153 QObject *which = QWidget::keyboardGrabber ( ); 1153 QObject *which = QWidget::keyboardGrabber ( );
1154 if ( !which ) 1154 if ( !which )
1155 which = QApplication::focusWidget ( ); 1155 which = QApplication::focusWidget ( );
1156 if ( !which ) 1156 if ( !which )
1157 which = QApplication::activeWindow ( ); 1157 which = QApplication::activeWindow ( );
1158 if ( !which ) 1158 if ( !which )
1159 which = qApp; 1159 which = qApp;
1160 1160
1161 QApplication::sendEvent ( which, &qke ); 1161 QApplication::sendEvent ( which, &qke );
1162 } 1162 }
1163 else { // we didn't grab the keyboard, so send the event to the launcher 1163 else { // we didn't grab the keyboard, so send the event to the launcher
1164 QCopEnvelope e ( "QPE/Launcher", "deviceButton(int,int,int)" ); 1164 QCopEnvelope e ( "QPE/Launcher", "deviceButton(int,int,int)" );
1165 e << int( ke-> simpleData.keycode ) << int( ke-> simpleData. is_press ) << int( ke-> simpleData.is_auto_repeat ); 1165 e << int( ke-> simpleData.keycode ) << int( ke-> simpleData. is_press ) << int( ke-> simpleData.is_auto_repeat );
1166 } 1166 }
1167 } 1167 }
1168 return true; 1168 return true;
1169 } 1169 }
1170 } 1170 }
1171 if ( e->type == QWSEvent::Focus ) { 1171 if ( e->type == QWSEvent::Focus ) {
1172 QWSFocusEvent * fe = ( QWSFocusEvent* ) e; 1172 QWSFocusEvent * fe = ( QWSFocusEvent* ) e;
1173 if ( !fe->simpleData.get_focus ) { 1173 if ( !fe->simpleData.get_focus ) {
1174 QWidget * active = activeWindow(); 1174 QWidget * active = activeWindow();
1175 while ( active && active->isPopup() ) { 1175 while ( active && active->isPopup() ) {
1176 active->close(); 1176 active->close();
1177 active = activeWindow(); 1177 active = activeWindow();
1178 } 1178 }
1179 } 1179 }
1180 else { 1180 else {
1181 // make sure our modal widget is ALWAYS on top 1181 // make sure our modal widget is ALWAYS on top
1182 QWidget *topm = activeModalWidget(); 1182 QWidget *topm = activeModalWidget();
1183 if ( topm && static_cast<int>( topm->winId() ) != fe->simpleData.window) { 1183 if ( topm && static_cast<int>( topm->winId() ) != fe->simpleData.window) {
1184 topm->raise(); 1184 topm->raise();
1185 } 1185 }
1186 } 1186 }
1187 if ( fe->simpleData.get_focus && inputMethodDict ) { 1187 if ( fe->simpleData.get_focus && inputMethodDict ) {
1188 InputMethodHint m = inputMethodHint( QWidget::find( e->window() ) ); 1188 InputMethodHint m = inputMethodHint( QWidget::find( e->window() ) );
1189 if ( m == AlwaysOff ) 1189 if ( m == AlwaysOff )
1190 Global::hideInputMethod(); 1190 Global::hideInputMethod();
1191 if ( m == AlwaysOn ) 1191 if ( m == AlwaysOn )
1192 Global::showInputMethod(); 1192 Global::showInputMethod();
1193 } 1193 }
1194 } 1194 }
1195 1195
1196 1196
1197 return QApplication::qwsEventFilter( e ); 1197 return QApplication::qwsEventFilter( e );
1198} 1198}
1199#endif 1199#endif
1200 1200
1201/*! 1201/*!
1202 Destroys the QPEApplication. 1202 Destroys the QPEApplication.
1203*/ 1203*/
1204QPEApplication::~QPEApplication() 1204QPEApplication::~QPEApplication()
1205{ 1205{
1206 ungrabKeyboard(); 1206 ungrabKeyboard();
1207#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 1207#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
1208 // Need to delete QCopChannels early, since the display will 1208 // Need to delete QCopChannels early, since the display will
1209 // be gone by the time we get to ~QObject(). 1209 // be gone by the time we get to ~QObject().
1210 delete sysChannel; 1210 delete sysChannel;
1211 delete pidChannel; 1211 delete pidChannel;
1212#endif 1212#endif
1213 1213
1214#ifdef OPIE_WITHROHFEEDBACK 1214#ifdef OPIE_WITHROHFEEDBACK
1215 if( d->RoH ) 1215 if( d->RoH )
1216 delete d->RoH; 1216 delete d->RoH;
1217#endif 1217#endif
1218 delete d; 1218 delete d;
1219} 1219}
1220 1220
1221/*! 1221/*!
1222 Returns <tt>$OPIEDIR/</tt>. 1222 Returns <tt>$OPIEDIR/</tt>.
1223*/ 1223*/
1224QString QPEApplication::qpeDir() 1224QString QPEApplication::qpeDir()
1225{ 1225{
1226 QString base, dir; 1226 QString base, dir;
1227 1227
1228 if (getenv( "OPIEDIR" )) 1228 if (getenv( "OPIEDIR" ))
1229 base = QString(getenv("OPIEDIR")).stripWhiteSpace(); 1229 base = QString(getenv("OPIEDIR")).stripWhiteSpace();
1230 if ( !base.isNull() && (base.length() > 0 )){ 1230 if ( !base.isNull() && (base.length() > 0 )){
1231#ifdef Q_OS_WIN32 1231#ifdef Q_OS_WIN32
1232 QString temp(base); 1232 QString temp(base);
1233 if (temp[(int)temp.length()-1] != QDir::separator()) 1233 if (temp[(int)temp.length()-1] != QDir::separator())
1234 temp.append(QDir::separator()); 1234 temp.append(QDir::separator());
1235 dir = temp; 1235 dir = temp;
1236#else 1236#else
1237 dir = QString( base ) + "/"; 1237 dir = QString( base ) + "/";
1238#endif 1238#endif
1239 }else{ 1239 }else{
1240 dir = QString( ".." ) + QDir::separator(); 1240 dir = QString( ".." ) + QDir::separator();
1241 } 1241 }
1242 1242
1243 return dir; 1243 return dir;
1244} 1244}
1245 1245
1246/*! 1246/*!
1247 Returns the user's current Document directory. There is a trailing "/". 1247 Returns the user's current Document directory. There is a trailing "/".
1248 .. well, it does now,, and there's no trailing '/' 1248 .. well, it does now,, and there's no trailing '/'
1249*/ 1249*/
1250QString QPEApplication::documentDir() 1250QString QPEApplication::documentDir()
1251{ 1251{
1252 const char* base = getenv( "HOME"); 1252 const char* base = getenv( "HOME");
1253 if ( base ) 1253 if ( base )
1254 return QString( base ) + "/Documents"; 1254 return QString( base ) + "/Documents";
1255 1255
1256 return QString( "../Documents" ); 1256 return QString( "../Documents" );
1257} 1257}
1258 1258
1259static int deforient = -1; 1259static int deforient = -1;
1260 1260
1261/*! 1261/*!
1262 \internal 1262 \internal
1263*/ 1263*/
1264int QPEApplication::defaultRotation() 1264int QPEApplication::defaultRotation()
1265{ 1265{
1266 if ( deforient < 0 ) { 1266 if ( deforient < 0 ) {
1267 QString d = getenv( "QWS_DISPLAY" ); 1267 QString d = getenv( "QWS_DISPLAY" );
1268 if ( d.contains( "Rot90" ) ) { 1268 if ( d.contains( "Rot90" ) ) {
1269 deforient = 90; 1269 deforient = 90;
1270 } 1270 }
1271 else if ( d.contains( "Rot180" ) ) { 1271 else if ( d.contains( "Rot180" ) ) {
1272 deforient = 180; 1272 deforient = 180;
1273 } 1273 }
1274 else if ( d.contains( "Rot270" ) ) { 1274 else if ( d.contains( "Rot270" ) ) {
1275 deforient = 270; 1275 deforient = 270;
1276 } 1276 }
1277 else { 1277 else {
1278 deforient = 0; 1278 deforient = 0;
1279 } 1279 }
1280 } 1280 }
1281 return deforient; 1281 return deforient;
1282} 1282}
1283 1283
1284/*! 1284/*!
1285 \internal 1285 \internal
1286*/ 1286*/
1287void QPEApplication::setDefaultRotation( int r ) 1287void QPEApplication::setDefaultRotation( int r )
1288{ 1288{
1289 if ( qApp->type() == GuiServer ) { 1289 if ( qApp->type() == GuiServer ) {
1290 deforient = r; 1290 deforient = r;
1291 setenv( "QWS_DISPLAY", QString( "Transformed:Rot%1:0" ).arg( r ).latin1(), 1 ); 1291 int j = 0;
1292 QCString old = getenv( "QWS_DISPLAY" ) ? getenv( "QWS_DISPLAY" ) : "Transformed";
1293 QString driver( old.left( ( ( j = old.find( ':' ) ) >= 0 ) ? j : old.size() ).data() );
1294 setenv( "QWS_DISPLAY", QString( "%1:Rot%2:0" ).arg(driver).arg( r ).latin1(), 1 );
1292 Config config("qpe"); 1295 Config config("qpe");
1293 config.setGroup( "Rotation" ); 1296 config.setGroup( "Rotation" );
1294 config.writeEntry( "Rot", r ); 1297 config.writeEntry( "Rot", r );
1295 } 1298 }
1296 else { 1299 else {
1297#ifndef QT_NO_COP 1300#ifndef QT_NO_COP
1298 { QCopEnvelope e( "QPE/System", "setDefaultRotation(int)" ); 1301 { QCopEnvelope e( "QPE/System", "setDefaultRotation(int)" );
1299 e << r; 1302 e << r;
1300 } 1303 }
1301#endif 1304#endif
1302 1305
1303 } 1306 }
1304} 1307}
1305 1308
1306#include <qgfx_qws.h> 1309#include <qgfx_qws.h>
1307#include <qwindowsystem_qws.h> 1310#include <qwindowsystem_qws.h>
1308 1311
1309#if QT_VERSION > 236 1312#if QT_VERSION > 236
1310extern void qws_clearLoadedFonts(); 1313extern void qws_clearLoadedFonts();
1311#endif 1314#endif
1312 1315
1313void QPEApplication::setCurrentMode( int x, int y, int depth ) 1316void QPEApplication::setCurrentMode( int x, int y, int depth )
1314{ 1317{
1315 // Reset the caches 1318 // Reset the caches
1316#if QT_VERSION > 236 1319#if QT_VERSION > 236
1317 qws_clearLoadedFonts(); 1320 qws_clearLoadedFonts();
1318#endif 1321#endif
1319 QPixmapCache::clear(); 1322 QPixmapCache::clear();
1320 1323
1321 // Change the screen mode 1324 // Change the screen mode
1322 qt_screen->setMode(x, y, depth); 1325 qt_screen->setMode(x, y, depth);
1323 1326
1324 if ( qApp->type() == GuiServer ) { 1327 if ( qApp->type() == GuiServer ) {
1325#if QT_VERSION > 236 1328#if QT_VERSION > 236
1326 // Reconfigure the GuiServer 1329 // Reconfigure the GuiServer
1327 qwsServer->beginDisplayReconfigure(); 1330 qwsServer->beginDisplayReconfigure();
1328 qwsServer->endDisplayReconfigure(); 1331 qwsServer->endDisplayReconfigure();
1329#endif 1332#endif
1330 // Get all the running apps to reset 1333 // Get all the running apps to reset
1331 QCopEnvelope env( "QPE/System", "reset()" ); 1334 QCopEnvelope env( "QPE/System", "reset()" );
1332 } 1335 }
1333} 1336}
1334 1337
1335void QPEApplication::reset() { 1338void QPEApplication::reset() {
1336 // Reconnect to the screen 1339 // Reconnect to the screen
1337 qt_screen->disconnect(); 1340 qt_screen->disconnect();
1338 qt_screen->connect( QString::null ); 1341 qt_screen->connect( QString::null );
1339 1342
1340 // Redraw everything 1343 // Redraw everything
1341 applyStyle(); 1344 applyStyle();
1342} 1345}
1343 1346
1344#if (QT_VERSION < 238) && defined Q_OS_MACX 1347#if (QT_VERSION < 238) && defined Q_OS_MACX
1345bool qt_left_hand_scrollbars = false; 1348bool qt_left_hand_scrollbars = false;
1346#else 1349#else
1347extern bool qt_left_hand_scrollbars QPE_WEAK_SYMBOL; 1350extern bool qt_left_hand_scrollbars QPE_WEAK_SYMBOL;
1348#endif 1351#endif
1349 1352
1350/*! 1353/*!
1351 \internal 1354 \internal
1352*/ 1355*/
1353void QPEApplication::applyStyle() 1356void QPEApplication::applyStyle()
1354{ 1357{
1355 Config config( "qpe" ); 1358 Config config( "qpe" );
1356 config.setGroup( "Appearance" ); 1359 config.setGroup( "Appearance" );
1357 1360
1358#if QT_VERSION > 233 1361#if QT_VERSION > 233
1359 // Widget style 1362 // Widget style
1360 QString style = config.readEntry( "Style", "FlatStyle" ); 1363 QString style = config.readEntry( "Style", "FlatStyle" );
1361 1364
1362 internalSetStyle ( style ); 1365 internalSetStyle ( style );
1363 1366
1364 // Colors - from /etc/colors/Liquid.scheme 1367 // Colors - from /etc/colors/Liquid.scheme
1365 QColor bgcolor( config.readEntry( "Background", "#E0E0E0" ) ); 1368 QColor bgcolor( config.readEntry( "Background", "#E0E0E0" ) );
1366 QColor btncolor( config.readEntry( "Button", "#96c8fa" ) ); 1369 QColor btncolor( config.readEntry( "Button", "#96c8fa" ) );
1367 QPalette pal( btncolor, bgcolor ); 1370 QPalette pal( btncolor, bgcolor );
1368 QString color = config.readEntry( "Highlight", "#73adef" ); 1371 QString color = config.readEntry( "Highlight", "#73adef" );
1369 pal.setColor( QColorGroup::Highlight, QColor( color ) ); 1372 pal.setColor( QColorGroup::Highlight, QColor( color ) );
1370 color = config.readEntry( "HighlightedText", "#FFFFFF" ); 1373 color = config.readEntry( "HighlightedText", "#FFFFFF" );
1371 pal.setColor( QColorGroup::HighlightedText, QColor( color ) ); 1374 pal.setColor( QColorGroup::HighlightedText, QColor( color ) );
1372 color = config.readEntry( "Text", "#000000" ); 1375 color = config.readEntry( "Text", "#000000" );
1373 pal.setColor( QColorGroup::Text, QColor( color ) ); 1376 pal.setColor( QColorGroup::Text, QColor( color ) );
1374 color = config.readEntry( "ButtonText", "#000000" ); 1377 color = config.readEntry( "ButtonText", "#000000" );
1375 pal.setColor( QPalette::Active, QColorGroup::ButtonText, QColor( color ) ); 1378 pal.setColor( QPalette::Active, QColorGroup::ButtonText, QColor( color ) );
1376 color = config.readEntry( "Base", "#FFFFFF" ); 1379 color = config.readEntry( "Base", "#FFFFFF" );
1377 pal.setColor( QColorGroup::Base, QColor( color ) ); 1380 pal.setColor( QColorGroup::Base, QColor( color ) );
1378 1381
1379 pal.setColor( QPalette::Disabled, QColorGroup::Text, 1382 pal.setColor( QPalette::Disabled, QColorGroup::Text,
1380 pal.color( QPalette::Active, QColorGroup::Background ).dark() ); 1383 pal.color( QPalette::Active, QColorGroup::Background ).dark() );
1381 1384
1382 setPalette( pal, TRUE ); 1385 setPalette( pal, TRUE );
1383 1386
1384 1387
1385 // Set the ScrollBar on the 'right' side but only if the weak symbol is present 1388 // Set the ScrollBar on the 'right' side but only if the weak symbol is present
1386 if (&qt_left_hand_scrollbars ) 1389 if (&qt_left_hand_scrollbars )
1387 qt_left_hand_scrollbars = config.readBoolEntry( "LeftHand", false ); 1390 qt_left_hand_scrollbars = config.readBoolEntry( "LeftHand", false );
1388 1391
1389 // Window Decoration 1392 // Window Decoration
1390 QString dec = config.readEntry( "Decoration", "Flat" ); 1393 QString dec = config.readEntry( "Decoration", "Flat" );
1391 1394
1392 if ( dec != d->decorationName ) { 1395 if ( dec != d->decorationName ) {
1393 qwsSetDecoration( new QPEDecoration( dec ) ); 1396 qwsSetDecoration( new QPEDecoration( dec ) );
1394 d->decorationName = dec; 1397 d->decorationName = dec;
1395 } 1398 }
1396 1399
1397 // Font 1400 // Font
1398 QString ff = config.readEntry( "FontFamily", font().family() ); 1401 QString ff = config.readEntry( "FontFamily", font().family() );
1399 int fs = config.readNumEntry( "FontSize", font().pointSize() ); 1402 int fs = config.readNumEntry( "FontSize", font().pointSize() );
1400 1403
1401 setFont ( QFont ( ff, fs ), true ); 1404 setFont ( QFont ( ff, fs ), true );
1402#endif 1405#endif
1403} 1406}
1404 1407
1405void QPEApplication::systemMessage( const QCString& msg, const QByteArray& data ) 1408void QPEApplication::systemMessage( const QCString& msg, const QByteArray& data )
1406{ 1409{
1407#ifdef Q_WS_QWS 1410#ifdef Q_WS_QWS
1408 QDataStream stream( data, IO_ReadOnly ); 1411 QDataStream stream( data, IO_ReadOnly );
1409 if ( msg == "applyStyle()" ) { 1412 if ( msg == "applyStyle()" ) {
1410 applyStyle(); 1413 applyStyle();
1411 } 1414 }
1412 else if ( msg == "toggleApplicationMenu()" ) { 1415 else if ( msg == "toggleApplicationMenu()" ) {
1413 QWidget *active = activeWindow ( ); 1416 QWidget *active = activeWindow ( );
1414 1417
1415 if ( active ) { 1418 if ( active ) {
1416 QPEMenuToolFocusManager *man = QPEMenuToolFocusManager::manager ( ); 1419 QPEMenuToolFocusManager *man = QPEMenuToolFocusManager::manager ( );
1417 bool oldactive = man-> isActive ( ); 1420 bool oldactive = man-> isActive ( );
1418 1421
1419 man-> setActive( !man-> isActive() ); 1422 man-> setActive( !man-> isActive() );
1420 1423
1421 if ( !oldactive && !man-> isActive ( )) { // no menubar to toggle -> try O-Menu 1424 if ( !oldactive && !man-> isActive ( )) { // no menubar to toggle -> try O-Menu
1422 QCopEnvelope e ( "QPE/TaskBar", "toggleStartMenu()" ); 1425 QCopEnvelope e ( "QPE/TaskBar", "toggleStartMenu()" );
1423 } 1426 }
1424 } 1427 }
1425 } 1428 }
1426 else if ( msg == "setDefaultRotation(int)" ) { 1429 else if ( msg == "setDefaultRotation(int)" ) {
1427 if ( type() == GuiServer ) { 1430 if ( type() == GuiServer ) {
1428 int r; 1431 int r;
1429 stream >> r; 1432 stream >> r;
1430 setDefaultRotation( r ); 1433 setDefaultRotation( r );
1431 } 1434 }
1432 } 1435 }
1433 else if ( msg == "setCurrentMode(int,int,int)" ) { // Added: 2003-06-11 by Tim Ansell <mithro@mithis.net> 1436 else if ( msg == "setCurrentMode(int,int,int)" ) { // Added: 2003-06-11 by Tim Ansell <mithro@mithis.net>
1434 if ( type() == GuiServer ) { 1437 if ( type() == GuiServer ) {
1435 int x, y, depth; 1438 int x, y, depth;
1436 stream >> x; 1439 stream >> x;
1437 stream >> y; 1440 stream >> y;
1438 stream >> depth; 1441 stream >> depth;
1439 setCurrentMode( x, y, depth ); 1442 setCurrentMode( x, y, depth );
1440 } 1443 }
1441 } 1444 }
1442 else if ( msg == "reset()" ) { 1445 else if ( msg == "reset()" ) {
1443 if ( type() != GuiServer ) 1446 if ( type() != GuiServer )
1444 reset(); 1447 reset();
1445 } 1448 }
1446 else if ( msg == "setCurrentRotation(int)" ) { 1449 else if ( msg == "setCurrentRotation(int)" ) {
1447 int r; 1450 int r;
1448 stream >> r; 1451 stream >> r;
1449 setCurrentRotation( r ); 1452 setCurrentRotation( r );
1450 } 1453 }
1451 else if ( msg == "shutdown()" ) { 1454 else if ( msg == "shutdown()" ) {
1452 if ( type() == GuiServer ) 1455 if ( type() == GuiServer )
1453 shutdown(); 1456 shutdown();
1454 } 1457 }
1455 else if ( msg == "quit()" ) { 1458 else if ( msg == "quit()" ) {
1456 if ( type() != GuiServer ) 1459 if ( type() != GuiServer )
1457 tryQuit(); 1460 tryQuit();
1458 } 1461 }
1459 else if ( msg == "forceQuit()" ) { 1462 else if ( msg == "forceQuit()" ) {
1460 if ( type() != GuiServer ) 1463 if ( type() != GuiServer )
1461 quit(); 1464 quit();
1462 } 1465 }
1463 else if ( msg == "restart()" ) { 1466 else if ( msg == "restart()" ) {
1464 if ( type() == GuiServer ) 1467 if ( type() == GuiServer )
1465 restart(); 1468 restart();
1466 } 1469 }
1467 else if ( msg == "language(QString)" ) { 1470 else if ( msg == "language(QString)" ) {
1468 if ( type() == GuiServer ) { 1471 if ( type() == GuiServer ) {
1469 QString l; 1472 QString l;
1470 stream >> l; 1473 stream >> l;
1471 QString cl = getenv( "LANG" ); 1474 QString cl = getenv( "LANG" );
1472 if ( cl != l ) { 1475 if ( cl != l ) {
1473 if ( l.isNull() ) 1476 if ( l.isNull() )
1474 unsetenv( "LANG" ); 1477 unsetenv( "LANG" );
1475 else 1478 else
1476 setenv( "LANG", l.latin1(), 1 ); 1479 setenv( "LANG", l.latin1(), 1 );
1477 restart(); 1480 restart();
1478 } 1481 }
1479 } 1482 }
1480 } 1483 }
1481 else if ( msg == "timeChange(QString)" ) { 1484 else if ( msg == "timeChange(QString)" ) {
1482 QString t; 1485 QString t;
1483 stream >> t; 1486 stream >> t;
1484 if ( t.isNull() ) 1487 if ( t.isNull() )
1485 unsetenv( "TZ" ); 1488 unsetenv( "TZ" );
1486 else 1489 else
1487 setenv( "TZ", t.latin1(), 1 ); 1490 setenv( "TZ", t.latin1(), 1 );
1488 // emit the signal so everyone else knows... 1491 // emit the signal so everyone else knows...
1489 emit timeChanged(); 1492 emit timeChanged();
1490 } 1493 }
1491 else if ( msg == "addAlarm(QDateTime,QCString,QCString,int)" ) { 1494 else if ( msg == "addAlarm(QDateTime,QCString,QCString,int)" ) {
1492 if ( type() == GuiServer ) { 1495 if ( type() == GuiServer ) {
1493 QDateTime when; 1496 QDateTime when;
1494 QCString channel, message; 1497 QCString channel, message;
1495 int data; 1498 int data;
1496 stream >> when >> channel >> message >> data; 1499 stream >> when >> channel >> message >> data;
1497 AlarmServer::addAlarm( when, channel, message, data ); 1500 AlarmServer::addAlarm( when, channel, message, data );
1498 } 1501 }
1499 } 1502 }
1500 else if ( msg == "deleteAlarm(QDateTime,QCString,QCString,int)" ) { 1503 else if ( msg == "deleteAlarm(QDateTime,QCString,QCString,int)" ) {
1501 if ( type() == GuiServer ) { 1504 if ( type() == GuiServer ) {
1502 QDateTime when; 1505 QDateTime when;
1503 QCString channel, message; 1506 QCString channel, message;
1504 int data; 1507 int data;
1505 stream >> when >> channel >> message >> data; 1508 stream >> when >> channel >> message >> data;
1506 AlarmServer::deleteAlarm( when, channel, message, data ); 1509 AlarmServer::deleteAlarm( when, channel, message, data );
1507 } 1510 }
1508 } 1511 }
1509 else if ( msg == "clockChange(bool)" ) { 1512 else if ( msg == "clockChange(bool)" ) {
1510 int tmp; 1513 int tmp;
1511 stream >> tmp; 1514 stream >> tmp;
1512 emit clockChanged( tmp ); 1515 emit clockChanged( tmp );
1513 } 1516 }
1514 else if ( msg == "weekChange(bool)" ) { 1517 else if ( msg == "weekChange(bool)" ) {
1515 int tmp; 1518 int tmp;
1516 stream >> tmp; 1519 stream >> tmp;
1517 emit weekChanged( tmp ); 1520 emit weekChanged( tmp );
1518 } 1521 }
1519 else if ( msg == "setDateFormat(DateFormat)" ) { 1522 else if ( msg == "setDateFormat(DateFormat)" ) {
1520 DateFormat tmp; 1523 DateFormat tmp;
1521 stream >> tmp; 1524 stream >> tmp;
1522 emit dateFormatChanged( tmp ); 1525 emit dateFormatChanged( tmp );
1523 } 1526 }
1524 else if ( msg == "setVolume(int,int)" ) { 1527 else if ( msg == "setVolume(int,int)" ) {
1525 int t, v; 1528 int t, v;
1526 stream >> t >> v; 1529 stream >> t >> v;
1527 setVolume( t, v ); 1530 setVolume( t, v );
1528 emit volumeChanged( muted ); 1531 emit volumeChanged( muted );
1529 } 1532 }
1530 else if ( msg == "volumeChange(bool)" ) { 1533 else if ( msg == "volumeChange(bool)" ) {
1531 stream >> muted; 1534 stream >> muted;
1532 setVolume(); 1535 setVolume();
1533 emit volumeChanged( muted ); 1536 emit volumeChanged( muted );
1534 } 1537 }
1535 else if ( msg == "setMic(int,int)" ) { // Added: 2002-02-08 by Jeremy Cowgar <jc@cowgar.com> 1538 else if ( msg == "setMic(int,int)" ) { // Added: 2002-02-08 by Jeremy Cowgar <jc@cowgar.com>
1536 int t, v; 1539 int t, v;
1537 stream >> t >> v; 1540 stream >> t >> v;
1538 setMic( t, v ); 1541 setMic( t, v );
1539 emit micChanged( micMuted ); 1542 emit micChanged( micMuted );
1540 } 1543 }
1541 else if ( msg == "micChange(bool)" ) { // Added: 2002-02-08 by Jeremy Cowgar <jc@cowgar.com> 1544 else if ( msg == "micChange(bool)" ) { // Added: 2002-02-08 by Jeremy Cowgar <jc@cowgar.com>
1542 stream >> micMuted; 1545 stream >> micMuted;
1543 setMic(); 1546 setMic();
1544 emit micChanged( micMuted ); 1547 emit micChanged( micMuted );
1545 } 1548 }
1546 else if ( msg == "setBass(int,int)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org> 1549 else if ( msg == "setBass(int,int)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org>
1547 int t, v; 1550 int t, v;
1548 stream >> t >> v; 1551 stream >> t >> v;
1549 setBass( t, v ); 1552 setBass( t, v );
1550 } 1553 }
1551 else if ( msg == "bassChange(bool)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org> 1554 else if ( msg == "bassChange(bool)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org>
1552 setBass(); 1555 setBass();
1553 } 1556 }
1554 else if ( msg == "setTreble(int,int)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org> 1557 else if ( msg == "setTreble(int,int)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org>
1555 int t, v; 1558 int t, v;
1556 stream >> t >> v; 1559 stream >> t >> v;
1557 setTreble( t, v ); 1560 setTreble( t, v );
1558 } 1561 }
1559 else if ( msg == "trebleChange(bool)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org> 1562 else if ( msg == "trebleChange(bool)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org>
1560 setTreble(); 1563 setTreble();
1561 } else if ( msg == "getMarkedText()" ) { 1564 } else if ( msg == "getMarkedText()" ) {
1562 if ( type() == GuiServer ) { 1565 if ( type() == GuiServer ) {
1563 const ushort unicode = 'C'-'@'; 1566 const ushort unicode = 'C'-'@';
1564 const int scan = Key_C; 1567 const int scan = Key_C;
1565 qwsServer->processKeyEvent( unicode, scan, ControlButton, TRUE, FALSE ); 1568 qwsServer->processKeyEvent( unicode, scan, ControlButton, TRUE, FALSE );
1566 qwsServer->processKeyEvent( unicode, scan, ControlButton, FALSE, FALSE ); 1569 qwsServer->processKeyEvent( unicode, scan, ControlButton, FALSE, FALSE );
1567 } 1570 }
1568 } else if ( msg == "newChannel(QString)") { 1571 } else if ( msg == "newChannel(QString)") {
1569 QString myChannel = "QPE/Application/" + d->appName; 1572 QString myChannel = "QPE/Application/" + d->appName;
1570 QString channel; 1573 QString channel;
1571 stream >> channel; 1574 stream >> channel;
1572 if (channel == myChannel) { 1575 if (channel == myChannel) {
1573 processQCopFile(); 1576 processQCopFile();
1574 d->sendQCopQ(); 1577 d->sendQCopQ();
1575 } 1578 }
1576 } 1579 }
1577 1580
1578 1581
1579#endif 1582#endif
1580} 1583}
1581 1584
1582 1585
1583 1586
1584 1587
1585 1588
1586/*! 1589/*!
1587 \internal 1590 \internal
1588*/ 1591*/
1589bool QPEApplication::raiseAppropriateWindow() 1592bool QPEApplication::raiseAppropriateWindow()
1590{ 1593{
1591 bool r=FALSE; 1594 bool r=FALSE;
1592 1595
1593 // 1. Raise the main widget 1596 // 1. Raise the main widget
1594 QWidget *top = d->qpe_main_widget; 1597 QWidget *top = d->qpe_main_widget;
1595 if ( !top ) top = mainWidget(); 1598 if ( !top ) top = mainWidget();
1596 1599
1597 if ( top && d->keep_running ) { 1600 if ( top && d->keep_running ) {
1598 if ( top->isVisible() ) 1601 if ( top->isVisible() )
1599 r = TRUE; 1602 r = TRUE;
1600 else if (d->preloaded) { 1603 else if (d->preloaded) {
1601 // We are preloaded and not visible.. pretend we just started.. 1604 // We are preloaded and not visible.. pretend we just started..
1602#ifndef QT_NO_COP 1605#ifndef QT_NO_COP
1603 QCopEnvelope e("QPE/System", "fastAppShowing(QString)"); 1606 QCopEnvelope e("QPE/System", "fastAppShowing(QString)");
1604 e << d->appName; 1607 e << d->appName;
1605#endif 1608#endif
1606 } 1609 }
1607 1610
1608 d->show_mx(top,d->nomaximize, d->appName); 1611 d->show_mx(top,d->nomaximize, d->appName);
1609 top->raise(); 1612 top->raise();
1610 } 1613 }
1611 1614
1612 QWidget *topm = activeModalWidget(); 1615 QWidget *topm = activeModalWidget();
1613 1616
1614 // 2. Raise any parentless widgets (except top and topm, as they 1617 // 2. Raise any parentless widgets (except top and topm, as they
1615 // are raised before and after this loop). Order from most 1618 // are raised before and after this loop). Order from most
1616 // recently raised as deepest to least recently as top, so 1619 // recently raised as deepest to least recently as top, so
1617 // that repeated calls cycle through widgets. 1620 // that repeated calls cycle through widgets.
1618 QWidgetList *list = topLevelWidgets(); 1621 QWidgetList *list = topLevelWidgets();
1619 if ( list ) { 1622 if ( list ) {
1620 bool foundlast = FALSE; 1623 bool foundlast = FALSE;
1621 QWidget* topsub = 0; 1624 QWidget* topsub = 0;
1622 if ( d->lastraised ) { 1625 if ( d->lastraised ) {
1623 for (QWidget* w = list->first(); w; w = list->next()) { 1626 for (QWidget* w = list->first(); w; w = list->next()) {
1624 if ( !w->parentWidget() && w != topm && w->isVisible() && !w->isDesktop() ) { 1627 if ( !w->parentWidget() && w != topm && w->isVisible() && !w->isDesktop() ) {
1625 if ( w == d->lastraised ) 1628 if ( w == d->lastraised )
1626 foundlast = TRUE; 1629 foundlast = TRUE;
1627 if ( foundlast ) { 1630 if ( foundlast ) {
1628 w->raise(); 1631 w->raise();
1629 topsub = w; 1632 topsub = w;
1630 } 1633 }
1631 } 1634 }
1632 } 1635 }
1633 } 1636 }
1634 for (QWidget* w = list->first(); w; w = list->next()) { 1637 for (QWidget* w = list->first(); w; w = list->next()) {
1635 if ( !w->parentWidget() && w != topm && w->isVisible() && !w->isDesktop() ) { 1638 if ( !w->parentWidget() && w != topm && w->isVisible() && !w->isDesktop() ) {
1636 if ( w == d->lastraised ) 1639 if ( w == d->lastraised )
1637 break; 1640 break;
1638 w->raise(); 1641 w->raise();
1639 topsub = w; 1642 topsub = w;
1640 } 1643 }
1641 } 1644 }
1642 d->lastraised = topsub; 1645 d->lastraised = topsub;
1643 delete list; 1646 delete list;
1644 } 1647 }
1645 1648
1646 // 3. Raise the active modal widget. 1649 // 3. Raise the active modal widget.
1647 if ( topm ) { 1650 if ( topm ) {
1648 topm->show(); 1651 topm->show();
1649 topm->raise(); 1652 topm->raise();
1650 // If we haven't already handled the fastAppShowing message 1653 // If we haven't already handled the fastAppShowing message
1651 if (!top && d->preloaded) { 1654 if (!top && d->preloaded) {
1652#ifndef QT_NO_COP 1655#ifndef QT_NO_COP
1653 QCopEnvelope e("QPE/System", "fastAppShowing(QString)"); 1656 QCopEnvelope e("QPE/System", "fastAppShowing(QString)");
1654 e << d->appName; 1657 e << d->appName;
1655#endif 1658#endif
1656 } 1659 }
1657 r = FALSE; 1660 r = FALSE;
1658 } 1661 }
1659 1662
1660 return r; 1663 return r;
1661} 1664}
1662 1665
1663 1666
1664void QPEApplication::pidMessage( const QCString& msg, const QByteArray& data) 1667void QPEApplication::pidMessage( const QCString& msg, const QByteArray& data)
1665{ 1668{
1666#ifdef Q_WS_QWS 1669#ifdef Q_WS_QWS
1667 1670
1668 if ( msg == "quit()" ) { 1671 if ( msg == "quit()" ) {
1669 tryQuit(); 1672 tryQuit();
1670 } 1673 }
1671 else if ( msg == "quitIfInvisible()" ) { 1674 else if ( msg == "quitIfInvisible()" ) {
1672 if ( d->qpe_main_widget && !d->qpe_main_widget->isVisible() ) 1675 if ( d->qpe_main_widget && !d->qpe_main_widget->isVisible() )
1673 quit(); 1676 quit();
1674 } 1677 }
1675 else if ( msg == "close()" ) { 1678 else if ( msg == "close()" ) {
1676 hideOrQuit(); 1679 hideOrQuit();
1677 } 1680 }
1678 else if ( msg == "disablePreload()" ) { 1681 else if ( msg == "disablePreload()" ) {
1679 d->preloaded = FALSE; 1682 d->preloaded = FALSE;
1680 d->keep_running = TRUE; 1683 d->keep_running = TRUE;
1681 /* so that quit will quit */ 1684 /* so that quit will quit */
1682 } 1685 }
1683 else if ( msg == "enablePreload()" ) { 1686 else if ( msg == "enablePreload()" ) {
1684 if (d->qpe_main_widget) 1687 if (d->qpe_main_widget)
1685 d->preloaded = TRUE; 1688 d->preloaded = TRUE;
1686 d->keep_running = TRUE; 1689 d->keep_running = TRUE;
1687 /* so next quit won't quit */ 1690 /* so next quit won't quit */
1688 } 1691 }
1689 else if ( msg == "raise()" ) { 1692 else if ( msg == "raise()" ) {
1690 d->keep_running = TRUE; 1693 d->keep_running = TRUE;
1691 d->notbusysent = FALSE; 1694 d->notbusysent = FALSE;
1692 raiseAppropriateWindow(); 1695 raiseAppropriateWindow();
1693 // Tell the system we're still chugging along... 1696 // Tell the system we're still chugging along...
1694 QCopEnvelope e("QPE/System", "appRaised(QString)"); 1697 QCopEnvelope e("QPE/System", "appRaised(QString)");
1695 e << d->appName; 1698 e << d->appName;
1696 } 1699 }
1697 else if ( msg == "flush()" ) { 1700 else if ( msg == "flush()" ) {
1698 emit flush(); 1701 emit flush();
1699 // we need to tell the desktop 1702 // we need to tell the desktop
1700 QCopEnvelope e( "QPE/Desktop", "flushDone(QString)" ); 1703 QCopEnvelope e( "QPE/Desktop", "flushDone(QString)" );
1701 e << d->appName; 1704 e << d->appName;
1702 } 1705 }
1703 else if ( msg == "reload()" ) { 1706 else if ( msg == "reload()" ) {
1704 emit reload(); 1707 emit reload();
1705 } 1708 }
1706 else if ( msg == "setDocument(QString)" ) { 1709 else if ( msg == "setDocument(QString)" ) {
1707 d->keep_running = TRUE; 1710 d->keep_running = TRUE;
1708 QDataStream stream( data, IO_ReadOnly ); 1711 QDataStream stream( data, IO_ReadOnly );
1709 QString doc; 1712 QString doc;
1710 stream >> doc; 1713 stream >> doc;
1711 QWidget *mw = mainWidget(); 1714 QWidget *mw = mainWidget();
1712 if ( !mw ) 1715 if ( !mw )
1713 mw = d->qpe_main_widget; 1716 mw = d->qpe_main_widget;
1714 if ( mw ) 1717 if ( mw )
1715 Global::setDocument( mw, doc ); 1718 Global::setDocument( mw, doc );
1716 1719
1717 } else if ( msg == "QPEProcessQCop()" ) { 1720 } else if ( msg == "QPEProcessQCop()" ) {
1718 processQCopFile(); 1721 processQCopFile();
1719 d->sendQCopQ(); 1722 d->sendQCopQ();
1720 }else 1723 }else
1721 { 1724 {
1722 bool p = d->keep_running; 1725 bool p = d->keep_running;
1723 d->keep_running = FALSE; 1726 d->keep_running = FALSE;
1724 emit appMessage( msg, data); 1727 emit appMessage( msg, data);
1725 if ( d->keep_running ) { 1728 if ( d->keep_running ) {
1726 d->notbusysent = FALSE; 1729 d->notbusysent = FALSE;
1727 raiseAppropriateWindow(); 1730 raiseAppropriateWindow();
1728 if ( !p ) { 1731 if ( !p ) {
1729 // Tell the system we're still chugging along... 1732 // Tell the system we're still chugging along...
1730#ifndef QT_NO_COP 1733#ifndef QT_NO_COP
1731 QCopEnvelope e("QPE/System", "appRaised(QString)"); 1734 QCopEnvelope e("QPE/System", "appRaised(QString)");
1732 e << d->appName; 1735 e << d->appName;
1733#endif 1736#endif
1734 } 1737 }
1735 } 1738 }
1736 if ( p ) 1739 if ( p )
1737 d->keep_running = p; 1740 d->keep_running = p;
1738 } 1741 }
1739#endif 1742#endif
1740} 1743}
1741 1744
1742 1745
1743/*! 1746/*!
1744 Sets widget \a mw as the mainWidget() and shows it. For small windows, 1747 Sets widget \a mw as the mainWidget() and shows it. For small windows,
1745 consider passing TRUE for \a nomaximize rather than the default FALSE. 1748 consider passing TRUE for \a nomaximize rather than the default FALSE.
1746 1749
1747 \sa showMainDocumentWidget() 1750 \sa showMainDocumentWidget()
1748*/ 1751*/
1749void QPEApplication::showMainWidget( QWidget* mw, bool nomaximize ) 1752void QPEApplication::showMainWidget( QWidget* mw, bool nomaximize )
1750{ 1753{
1751// setMainWidget(mw); this breaks FastLoading because lastWindowClose() would quit 1754// setMainWidget(mw); this breaks FastLoading because lastWindowClose() would quit
1752 d->show(mw, nomaximize ); 1755 d->show(mw, nomaximize );
1753} 1756}
1754 1757
1755/*! 1758/*!
1756 Sets widget \a mw as the mainWidget() and shows it. For small windows, 1759 Sets widget \a mw as the mainWidget() and shows it. For small windows,
1757 consider passing TRUE for \a nomaximize rather than the default FALSE. 1760 consider passing TRUE for \a nomaximize rather than the default FALSE.
1758 1761
1759 This calls designates the application as 1762 This calls designates the application as
1760 a \link docwidget.html document-oriented\endlink application. 1763 a \link docwidget.html document-oriented\endlink application.
1761 1764
1762 The \a mw widget \e must have this slot: setDocument(const QString&). 1765 The \a mw widget \e must have this slot: setDocument(const QString&).
1763 1766
1764 \sa showMainWidget() 1767 \sa showMainWidget()
1765*/ 1768*/
1766void QPEApplication::showMainDocumentWidget( QWidget* mw, bool nomaximize ) 1769void QPEApplication::showMainDocumentWidget( QWidget* mw, bool nomaximize )
1767{ 1770{
1768 if ( mw && argc() == 2 ) 1771 if ( mw && argc() == 2 )
1769 Global::setDocument( mw, QString::fromUtf8(argv()[1]) ); 1772 Global::setDocument( mw, QString::fromUtf8(argv()[1]) );
1770 1773
1771 1774
1772// setMainWidget(mw); see above 1775// setMainWidget(mw); see above
1773 d->show(mw, nomaximize ); 1776 d->show(mw, nomaximize );
1774} 1777}
1775 1778
1776 1779
1777/*! 1780/*!
1778 If an application is started via a \link qcop.html QCop\endlink 1781 If an application is started via a \link qcop.html QCop\endlink
1779 message, the application will process the \link qcop.html 1782 message, the application will process the \link qcop.html
1780 QCop\endlink message and then quit. If the application calls this 1783 QCop\endlink message and then quit. If the application calls this
1781 function while processing a \link qcop.html QCop\endlink message, 1784 function while processing a \link qcop.html QCop\endlink message,
1782 after processing its outstanding \link qcop.html QCop\endlink 1785 after processing its outstanding \link qcop.html QCop\endlink
1783 messages the application will start 'properly' and show itself. 1786 messages the application will start 'properly' and show itself.
1784 1787
1785 \sa keepRunning() 1788 \sa keepRunning()
1786*/ 1789*/
1787void QPEApplication::setKeepRunning() 1790void QPEApplication::setKeepRunning()
1788{ 1791{
1789 if ( qApp && qApp->inherits( "QPEApplication" ) ) { 1792 if ( qApp && qApp->inherits( "QPEApplication" ) ) {
1790 QPEApplication * qpeApp = ( QPEApplication* ) qApp; 1793 QPEApplication * qpeApp = ( QPEApplication* ) qApp;
1791 qpeApp->d->keep_running = TRUE; 1794 qpeApp->d->keep_running = TRUE;
1792 } 1795 }
1793} 1796}
1794 1797
1795/*! 1798/*!
1796 Returns TRUE if the application will quit after processing the 1799 Returns TRUE if the application will quit after processing the
1797 current list of qcop messages; otherwise returns FALSE. 1800 current list of qcop messages; otherwise returns FALSE.
1798 1801
1799 \sa setKeepRunning() 1802 \sa setKeepRunning()
1800*/ 1803*/
1801bool QPEApplication::keepRunning() const 1804bool QPEApplication::keepRunning() const
1802{ 1805{
1803 return d->keep_running; 1806 return d->keep_running;
1804} 1807}
1805 1808
1806/*! 1809/*!
1807 \internal 1810 \internal
1808*/ 1811*/
1809void QPEApplication::internalSetStyle( const QString &style ) 1812void QPEApplication::internalSetStyle( const QString &style )
1810{ 1813{
1811#if QT_VERSION >= 0x030000 1814#if QT_VERSION >= 0x030000
1812 if ( style == "QPE" ) { 1815 if ( style == "QPE" ) {
1813 setStyle( new QPEStyle ); 1816 setStyle( new QPEStyle );
1814 } 1817 }
1815 else { 1818 else {
1816 QStyle *s = QStyleFactory::create( style ); 1819 QStyle *s = QStyleFactory::create( style );
1817 if ( s ) 1820 if ( s )
1818 setStyle( s ); 1821 setStyle( s );
1819 } 1822 }
1820#else 1823#else
1821 if ( style == "Windows" ) { 1824 if ( style == "Windows" ) {
1822 setStyle( new QWindowsStyle ); 1825 setStyle( new QWindowsStyle );
1823 } 1826 }
1824 else if ( style == "QPE" ) { 1827 else if ( style == "QPE" ) {
1825 setStyle( new QPEStyle ); 1828 setStyle( new QPEStyle );
1826 } 1829 }
1827 else if ( style == "Light" ) { 1830 else if ( style == "Light" ) {
1828 setStyle( new LightStyle ); 1831 setStyle( new LightStyle );
1829 } 1832 }
1830#ifndef QT_NO_STYLE_PLATINUM 1833#ifndef QT_NO_STYLE_PLATINUM
1831 else if ( style == "Platinum" ) { 1834 else if ( style == "Platinum" ) {
1832 setStyle( new QPlatinumStyle ); 1835 setStyle( new QPlatinumStyle );
1833 } 1836 }
1834#endif 1837#endif
1835#ifndef QT_NO_STYLE_MOTIF 1838#ifndef QT_NO_STYLE_MOTIF
1836 else if ( style == "Motif" ) { 1839 else if ( style == "Motif" ) {
1837 setStyle( new QMotifStyle ); 1840 setStyle( new QMotifStyle );
1838 } 1841 }
1839#endif 1842#endif
1840#ifndef QT_NO_STYLE_MOTIFPLUS 1843#ifndef QT_NO_STYLE_MOTIFPLUS
1841 else if ( style == "MotifPlus" ) { 1844 else if ( style == "MotifPlus" ) {
1842 setStyle( new QMotifPlusStyle ); 1845 setStyle( new QMotifPlusStyle );
1843 } 1846 }
1844#endif 1847#endif
1845 1848
1846 else { 1849 else {
1847 QStyle *sty = 0; 1850 QStyle *sty = 0;
1848 QString path = QPEApplication::qpeDir ( ) + "plugins/styles/"; 1851 QString path = QPEApplication::qpeDir ( ) + "plugins/styles/";
1849 1852
1850#ifdef Q_OS_MACX 1853#ifdef Q_OS_MACX
1851 if ( style. find ( ".dylib" ) > 0 ) 1854 if ( style. find ( ".dylib" ) > 0 )
1852 path += style; 1855 path += style;
1853 else 1856 else
1854 path = path + "lib" + style. lower ( ) + ".dylib"; // compatibility 1857 path = path + "lib" + style. lower ( ) + ".dylib"; // compatibility
1855#else 1858#else
1856 if ( style. find ( ".so" ) > 0 ) 1859 if ( style. find ( ".so" ) > 0 )
1857 path += style; 1860 path += style;
1858 else 1861 else
1859 path = path + "lib" + style. lower ( ) + ".so"; // compatibility 1862 path = path + "lib" + style. lower ( ) + ".so"; // compatibility
1860#endif 1863#endif
1861 static QLibrary *lastlib = 0; 1864 static QLibrary *lastlib = 0;
1862 static StyleInterface *lastiface = 0; 1865 static StyleInterface *lastiface = 0;
1863 1866
1864 QLibrary *lib = new QLibrary ( path ); 1867 QLibrary *lib = new QLibrary ( path );
1865 StyleInterface *iface = 0; 1868 StyleInterface *iface = 0;
1866 1869
1867 if (( lib-> queryInterface ( IID_Style, ( QUnknownInterface ** ) &iface ) == QS_OK ) && iface ) 1870 if (( lib-> queryInterface ( IID_Style, ( QUnknownInterface ** ) &iface ) == QS_OK ) && iface )
1868 sty = iface-> style ( ); 1871 sty = iface-> style ( );
1869 1872
1870 if ( sty ) { 1873 if ( sty ) {
1871 setStyle ( sty ); 1874 setStyle ( sty );
1872 1875
1873 if ( lastiface ) 1876 if ( lastiface )
1874 lastiface-> release ( ); 1877 lastiface-> release ( );
1875 lastiface = iface; 1878 lastiface = iface;
1876 1879
1877 if ( lastlib ) { 1880 if ( lastlib ) {
1878 lastlib-> unload ( ); 1881 lastlib-> unload ( );
1879 delete lastlib; 1882 delete lastlib;
1880 } 1883 }
1881 lastlib = lib; 1884 lastlib = lib;
1882 } 1885 }
1883 else { 1886 else {
1884 if ( iface ) 1887 if ( iface )
1885 iface-> release ( ); 1888 iface-> release ( );
1886 delete lib; 1889 delete lib;
1887 1890
1888 setStyle ( new LightStyle ( )); 1891 setStyle ( new LightStyle ( ));
1889 } 1892 }
1890 } 1893 }
1891#endif 1894#endif
1892} 1895}
1893 1896
1894/*! 1897/*!
1895 \internal 1898 \internal
1896*/ 1899*/
1897void QPEApplication::prepareForTermination( bool willrestart ) 1900void QPEApplication::prepareForTermination( bool willrestart )
1898{ 1901{
1899 if ( willrestart ) { 1902 if ( willrestart ) {
1900 QLabel *lblWait = new QLabel( tr( "Please wait..." ), 0, "wait hack", QWidget::WStyle_Customize | 1903 QLabel *lblWait = new QLabel( tr( "Please wait..." ), 0, "wait hack", QWidget::WStyle_Customize |
1901 QWidget::WStyle_NoBorder | QWidget::WStyle_Tool ); 1904 QWidget::WStyle_NoBorder | QWidget::WStyle_Tool );
1902 lblWait->setAlignment( QWidget::AlignCenter ); 1905 lblWait->setAlignment( QWidget::AlignCenter );
1903 lblWait->show(); 1906 lblWait->show();
1904 lblWait->showMaximized(); 1907 lblWait->showMaximized();
1905 } 1908 }
1906 { QCopEnvelope envelope( "QPE/System", "forceQuit()" ); 1909 { QCopEnvelope envelope( "QPE/System", "forceQuit()" );
1907 } 1910 }
1908 processEvents(); // ensure the message goes out. 1911 processEvents(); // ensure the message goes out.
1909} 1912}
1910 1913
1911/*! 1914/*!
1912 \internal 1915 \internal
1913*/ 1916*/
1914void QPEApplication::shutdown() 1917void QPEApplication::shutdown()
1915{ 1918{
1916 // Implement in server's QPEApplication subclass 1919 // Implement in server's QPEApplication subclass
1917} 1920}
1918 1921
1919/*! 1922/*!
1920 \internal 1923 \internal
1921*/ 1924*/
1922void QPEApplication::restart() 1925void QPEApplication::restart()
1923{ 1926{
1924 // Implement in server's QPEApplication subclass 1927 // Implement in server's QPEApplication subclass
1925} 1928}
1926 1929
1927static QPtrDict<void>* stylusDict = 0; 1930static QPtrDict<void>* stylusDict = 0;
1928static void createDict() 1931static void createDict()
1929{ 1932{
1930 if ( !stylusDict ) 1933 if ( !stylusDict )
1931 stylusDict = new QPtrDict<void>; 1934 stylusDict = new QPtrDict<void>;
1932} 1935}
1933 1936
1934/*! 1937/*!
1935 Returns the current StylusMode for widget \a w. 1938 Returns the current StylusMode for widget \a w.
1936 1939
1937 \sa setStylusOperation() StylusMode 1940 \sa setStylusOperation() StylusMode
1938*/ 1941*/
1939QPEApplication::StylusMode QPEApplication::stylusOperation( QWidget* w ) 1942QPEApplication::StylusMode QPEApplication::stylusOperation( QWidget* w )
1940{ 1943{
1941 if ( stylusDict ) 1944 if ( stylusDict )
1942 return ( StylusMode ) ( int ) stylusDict->find( w ); 1945 return ( StylusMode ) ( int ) stylusDict->find( w );
1943 return LeftOnly; 1946 return LeftOnly;
1944} 1947}
1945 1948
1946/*! 1949/*!
1947 \enum QPEApplication::StylusMode 1950 \enum QPEApplication::StylusMode
1948 1951
1949 \value LeftOnly the stylus only generates LeftButton 1952 \value LeftOnly the stylus only generates LeftButton
1950 events (the default). 1953 events (the default).
1951 \value RightOnHold the stylus generates RightButton events 1954 \value RightOnHold the stylus generates RightButton events
1952 if the user uses the press-and-hold gesture. 1955 if the user uses the press-and-hold gesture.
1953 1956
1954 \sa setStylusOperation() stylusOperation() 1957 \sa setStylusOperation() stylusOperation()
1955*/ 1958*/
1956 1959
1957/*! 1960/*!
1958 Causes widget \a w to receive mouse events according to the stylus 1961 Causes widget \a w to receive mouse events according to the stylus
1959 \a mode. 1962 \a mode.
1960 1963
1961 \sa stylusOperation() StylusMode 1964 \sa stylusOperation() StylusMode
1962*/ 1965*/
1963void QPEApplication::setStylusOperation( QWidget * w, StylusMode mode ) 1966void QPEApplication::setStylusOperation( QWidget * w, StylusMode mode )
1964{ 1967{
1965 createDict(); 1968 createDict();
1966 if ( mode == LeftOnly ) { 1969 if ( mode == LeftOnly ) {
1967 stylusDict->remove 1970 stylusDict->remove
1968 ( w ); 1971 ( w );
1969 w->removeEventFilter( qApp ); 1972 w->removeEventFilter( qApp );
1970 } 1973 }
1971 else { 1974 else {
1972 stylusDict->insert( w, ( void* ) mode ); 1975 stylusDict->insert( w, ( void* ) mode );
1973 connect( w, SIGNAL( destroyed() ), qApp, SLOT( removeSenderFromStylusDict() ) ); 1976 connect( w, SIGNAL( destroyed() ), qApp, SLOT( removeSenderFromStylusDict() ) );
1974 w->installEventFilter( qApp ); 1977 w->installEventFilter( qApp );
1975 } 1978 }
1976} 1979}
1977 1980
1978 1981
1979/*! 1982/*!
1980 \reimp 1983 \reimp
1981*/ 1984*/
1982bool QPEApplication::eventFilter( QObject *o, QEvent *e ) 1985bool QPEApplication::eventFilter( QObject *o, QEvent *e )
1983{ 1986{
1984 if ( !o->isWidgetType() ) 1987 if ( !o->isWidgetType() )
1985 return FALSE; 1988 return FALSE;
1986 1989
1987 if ( stylusDict && e->type() >= QEvent::MouseButtonPress && e->type() <= QEvent::MouseMove ) { 1990 if ( stylusDict && e->type() >= QEvent::MouseButtonPress && e->type() <= QEvent::MouseMove ) {
1988 QMouseEvent * me = ( QMouseEvent* ) e; 1991 QMouseEvent * me = ( QMouseEvent* ) e;
1989 StylusMode mode = (StylusMode)(int)stylusDict->find(o); 1992 StylusMode mode = (StylusMode)(int)stylusDict->find(o);
1990 switch (mode) { 1993 switch (mode) {
1991 case RightOnHold: 1994 case RightOnHold:
1992 switch ( me->type() ) { 1995 switch ( me->type() ) {
1993 case QEvent::MouseButtonPress: 1996 case QEvent::MouseButtonPress:
1994 if ( me->button() == LeftButton ) { 1997 if ( me->button() == LeftButton ) {
1995 static long Pref = 500; // #### pref. 1998 static long Pref = 500; // #### pref.
1996 d->presswidget = (QWidget*)o; 1999 d->presswidget = (QWidget*)o;
1997 d->presspos = me->pos(); 2000 d->presspos = me->pos();
1998 d->rightpressed = FALSE; 2001 d->rightpressed = FALSE;
1999#ifdef OPIE_WITHROHFEEDBACK 2002#ifdef OPIE_WITHROHFEEDBACK
2000 if( ! d->RoH ) 2003 if( ! d->RoH )
2001 d->RoH = new Opie::Internal::RoHFeedback; 2004 d->RoH = new Opie::Internal::RoHFeedback;
2002 2005
2003 d->RoH->init( me->globalPos(), d->presswidget ); 2006 d->RoH->init( me->globalPos(), d->presswidget );
2004 Pref = d->RoH->delay(); 2007 Pref = d->RoH->delay();
2005 2008
2006#endif 2009#endif
2007 if (!d->presstimer ) 2010 if (!d->presstimer )
2008 d->presstimer = startTimer( Pref ); // #### pref. 2011 d->presstimer = startTimer( Pref ); // #### pref.
2009 2012
2010 } 2013 }
2011 break; 2014 break;
2012 case QEvent::MouseMove: 2015 case QEvent::MouseMove:
2013 if (d->presstimer && (me->pos() - d->presspos).manhattanLength() > 8) { 2016 if (d->presstimer && (me->pos() - d->presspos).manhattanLength() > 8) {
2014 killTimer(d->presstimer); 2017 killTimer(d->presstimer);
2015#ifdef OPIE_WITHROHFEEDBACK 2018#ifdef OPIE_WITHROHFEEDBACK
2016 d->RoH->stop(); 2019 d->RoH->stop();
2017#endif 2020#endif
2018 d->presstimer = 0; 2021 d->presstimer = 0;
2019 } 2022 }
2020 break; 2023 break;
2021 case QEvent::MouseButtonRelease: 2024 case QEvent::MouseButtonRelease:
2022 if ( me->button() == LeftButton ) { 2025 if ( me->button() == LeftButton ) {
2023 if ( d->presstimer ) { 2026 if ( d->presstimer ) {
2024 killTimer(d->presstimer); 2027 killTimer(d->presstimer);
2025#ifdef OPIE_WITHROHFEEDBACK 2028#ifdef OPIE_WITHROHFEEDBACK
2026 d->RoH->stop( ); 2029 d->RoH->stop( );
2027#endif 2030#endif
2028 d->presstimer = 0; 2031 d->presstimer = 0;
2029 } 2032 }
2030 if ( d->rightpressed && d->presswidget ) { 2033 if ( d->rightpressed && d->presswidget ) {
2031 printf( "Send ButtonRelease\n" ); 2034 printf( "Send ButtonRelease\n" );
2032 // Right released 2035 // Right released
2033 postEvent( d->presswidget, 2036 postEvent( d->presswidget,
2034 new QMouseEvent( QEvent::MouseButtonRelease, me->pos(), 2037 new QMouseEvent( QEvent::MouseButtonRelease, me->pos(),
2035 RightButton, LeftButton + RightButton ) ); 2038 RightButton, LeftButton + RightButton ) );
2036 // Left released, off-widget 2039 // Left released, off-widget
2037 postEvent( d->presswidget, 2040 postEvent( d->presswidget,
2038 new QMouseEvent( QEvent::MouseMove, QPoint( -1, -1), 2041 new QMouseEvent( QEvent::MouseMove, QPoint( -1, -1),
2039 LeftButton, LeftButton ) ); 2042 LeftButton, LeftButton ) );
2040 postEvent( d->presswidget, 2043 postEvent( d->presswidget,
2041 new QMouseEvent( QEvent::MouseButtonRelease, QPoint( -1, -1), 2044 new QMouseEvent( QEvent::MouseButtonRelease, QPoint( -1, -1),
2042 LeftButton, LeftButton ) ); 2045 LeftButton, LeftButton ) );
2043 d->rightpressed = FALSE; 2046 d->rightpressed = FALSE;
2044 return TRUE; // don't send the real Left release 2047 return TRUE; // don't send the real Left release
2045 } 2048 }
2046 } 2049 }
2047 break; 2050 break;
2048 default: 2051 default:
2049 break; 2052 break;
2050 } 2053 }
2051 break; 2054 break;
2052 default: 2055 default:
2053 ; 2056 ;
2054 } 2057 }
2055 } 2058 }
2056 else if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) { 2059 else if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) {
2057 QKeyEvent *ke = (QKeyEvent *)e; 2060 QKeyEvent *ke = (QKeyEvent *)e;
2058 if ( ke->key() == Key_Enter ) { 2061 if ( ke->key() == Key_Enter ) {
2059 if ( o->isA( "QRadioButton" ) || o->isA( "QCheckBox" ) ) { 2062 if ( o->isA( "QRadioButton" ) || o->isA( "QCheckBox" ) ) {
2060 postEvent( o, new QKeyEvent( e->type(), Key_Space, ' ', 2063 postEvent( o, new QKeyEvent( e->type(), Key_Space, ' ',
2061 ke->state(), " ", ke->isAutoRepeat(), ke->count() ) ); 2064 ke->state(), " ", ke->isAutoRepeat(), ke->count() ) );
2062 return TRUE; 2065 return TRUE;
2063 } 2066 }
2064 } 2067 }
2065 } 2068 }
2066 return FALSE; 2069 return FALSE;
2067} 2070}
2068 2071
2069/*! 2072/*!
2070 \reimp 2073 \reimp
2071*/ 2074*/
2072void QPEApplication::timerEvent( QTimerEvent *e ) 2075void QPEApplication::timerEvent( QTimerEvent *e )
2073{ 2076{
2074 if ( e->timerId() == d->presstimer && d->presswidget ) { 2077 if ( e->timerId() == d->presstimer && d->presswidget ) {
2075 2078
2076 // Right pressed 2079 // Right pressed
2077 postEvent( d->presswidget, 2080 postEvent( d->presswidget,
2078 new QMouseEvent( QEvent::MouseButtonPress, d->presspos, 2081 new QMouseEvent( QEvent::MouseButtonPress, d->presspos,
2079 RightButton, LeftButton ) ); 2082 RightButton, LeftButton ) );
2080 killTimer( d->presstimer ); 2083 killTimer( d->presstimer );
2081 d->presstimer = 0; 2084 d->presstimer = 0;
2082 d->rightpressed = TRUE; 2085 d->rightpressed = TRUE;
2083#ifdef OPIE_WITHROHFEEDBACK 2086#ifdef OPIE_WITHROHFEEDBACK
2084 d->RoH->stop(); 2087 d->RoH->stop();
2085#endif 2088#endif
2086 } 2089 }
2087} 2090}
2088 2091
2089void QPEApplication::removeSenderFromStylusDict() 2092void QPEApplication::removeSenderFromStylusDict()
2090{ 2093{
2091 stylusDict->remove 2094 stylusDict->remove
2092 ( ( void* ) sender() ); 2095 ( ( void* ) sender() );
2093 if ( d->presswidget == sender() ) 2096 if ( d->presswidget == sender() )
2094 d->presswidget = 0; 2097 d->presswidget = 0;
2095} 2098}
2096 2099
2097/*! 2100/*!
2098 \internal 2101 \internal
2099*/ 2102*/
2100bool QPEApplication::keyboardGrabbed() const 2103bool QPEApplication::keyboardGrabbed() const
2101{ 2104{
2102 return d->kbgrabbed; 2105 return d->kbgrabbed;
2103} 2106}
2104 2107
2105 2108
2106/*! 2109/*!
2107 Reverses the effect of grabKeyboard(). This is called automatically 2110 Reverses the effect of grabKeyboard(). This is called automatically
2108 on program exit. 2111 on program exit.
2109*/ 2112*/
2110void QPEApplication::ungrabKeyboard() 2113void QPEApplication::ungrabKeyboard()
2111{ 2114{
2112 ((QPEApplication *) qApp )-> d-> kbgrabbed = false; 2115 ((QPEApplication *) qApp )-> d-> kbgrabbed = false;
2113} 2116}
2114 2117
2115/*! 2118/*!
2116 Grabs the physical keyboard keys, e.g. the application's launching 2119 Grabs the physical keyboard keys, e.g. the application's launching
2117 keys. Instead of launching applications when these keys are pressed 2120 keys. Instead of launching applications when these keys are pressed
2118 the signals emitted are sent to this application instead. Some games 2121 the signals emitted are sent to this application instead. Some games
2119 programs take over the launch keys in this way to make interaction 2122 programs take over the launch keys in this way to make interaction
2120 easier. 2123 easier.
2121 2124
2122 \sa ungrabKeyboard() 2125 \sa ungrabKeyboard()
2123*/ 2126*/
2124void QPEApplication::grabKeyboard() 2127void QPEApplication::grabKeyboard()
2125{ 2128{
2126 ((QPEApplication *) qApp )-> d-> kbgrabbed = true; 2129 ((QPEApplication *) qApp )-> d-> kbgrabbed = true;
2127} 2130}
2128 2131
2129/*! 2132/*!
2130 \reimp 2133 \reimp
2131*/ 2134*/
2132int QPEApplication::exec() 2135int QPEApplication::exec()
2133{ 2136{
2134 d->qcopQok = true; 2137 d->qcopQok = true;
2135#ifndef QT_NO_COP 2138#ifndef QT_NO_COP
2136 d->sendQCopQ(); 2139 d->sendQCopQ();
2137 if ( !d->keep_running ) 2140 if ( !d->keep_running )
2138 processEvents(); // we may have received QCop messages in the meantime. 2141 processEvents(); // we may have received QCop messages in the meantime.
2139#endif 2142#endif
2140 2143
2141 if ( d->keep_running ) 2144 if ( d->keep_running )
2142 //|| d->qpe_main_widget && d->qpe_main_widget->isVisible() ) 2145 //|| d->qpe_main_widget && d->qpe_main_widget->isVisible() )
2143 return QApplication::exec(); 2146 return QApplication::exec();
2144 2147
2145#ifndef QT_NO_COP 2148#ifndef QT_NO_COP
2146 2149
2147 { 2150 {
2148 QCopEnvelope e( "QPE/System", "closing(QString)" ); 2151 QCopEnvelope e( "QPE/System", "closing(QString)" );
2149 e << d->appName; 2152 e << d->appName;
2150 } 2153 }
2151#endif 2154#endif
2152 processEvents(); 2155 processEvents();
2153 return 0; 2156 return 0;
2154} 2157}
2155 2158
2156/*! 2159/*!
2157 \internal 2160 \internal
2158 External request for application to quit. Quits if possible without 2161 External request for application to quit. Quits if possible without
2159 loosing state. 2162 loosing state.
2160*/ 2163*/
2161void QPEApplication::tryQuit() 2164void QPEApplication::tryQuit()
2162{ 2165{
2163 if ( activeModalWidget() ) 2166 if ( activeModalWidget() )
2164 return ; // Inside modal loop or konsole. Too hard to save state. 2167 return ; // Inside modal loop or konsole. Too hard to save state.
2165#ifndef QT_NO_COP 2168#ifndef QT_NO_COP
2166 2169
2167 { 2170 {
2168 QCopEnvelope e( "QPE/System", "closing(QString)" ); 2171 QCopEnvelope e( "QPE/System", "closing(QString)" );
2169 e << d->appName; 2172 e << d->appName;
2170 } 2173 }
2171#endif 2174#endif
2172 if ( d->keep_running ) 2175 if ( d->keep_running )
2173 d->store_widget_rect(d->qpe_main_widget, d->appName); 2176 d->store_widget_rect(d->qpe_main_widget, d->appName);
2174 processEvents(); 2177 processEvents();
2175 2178
2176 quit(); 2179 quit();
2177} 2180}
2178 2181
2179 2182
2180/*! 2183/*!
2181 \internal 2184 \internal
2182 User initiated quit. Makes the window 'Go Away'. If preloaded this means 2185 User initiated quit. Makes the window 'Go Away'. If preloaded this means
2183 hiding the window. If not it means quitting the application. 2186 hiding the window. If not it means quitting the application.
2184 As this is user initiated we don't need to check state. 2187 As this is user initiated we don't need to check state.
2185*/ 2188*/
2186void QPEApplication::hideOrQuit() 2189void QPEApplication::hideOrQuit()
2187{ 2190{
2188 if ( d->keep_running ) 2191 if ( d->keep_running )
2189 d->store_widget_rect(d->qpe_main_widget, d->appName); 2192 d->store_widget_rect(d->qpe_main_widget, d->appName);
2190 processEvents(); 2193 processEvents();
2191 2194
2192 // If we are a preloaded application we don't actually quit, so emit 2195 // If we are a preloaded application we don't actually quit, so emit
2193 // a System message indicating we're quasi-closing. 2196 // a System message indicating we're quasi-closing.
2194 if ( d->preloaded && d->qpe_main_widget ) 2197 if ( d->preloaded && d->qpe_main_widget )
2195#ifndef QT_NO_COP 2198#ifndef QT_NO_COP
2196 2199
2197 { 2200 {
2198 QCopEnvelope e("QPE/System", "fastAppHiding(QString)" ); 2201 QCopEnvelope e("QPE/System", "fastAppHiding(QString)" );
2199 e << d->appName; 2202 e << d->appName;
2200 d->qpe_main_widget->hide(); 2203 d->qpe_main_widget->hide();
2201 } 2204 }
2202#endif 2205#endif
2203 else 2206 else
2204 quit(); 2207 quit();
2205} 2208}
2206 2209
2207#if (__GNUC__ > 2 ) 2210#if (__GNUC__ > 2 )
2208extern "C" void __cxa_pure_virtual(); 2211extern "C" void __cxa_pure_virtual();
2209 2212
2210void __cxa_pure_virtual() 2213void __cxa_pure_virtual()
2211{ 2214{
2212 fprintf( stderr, "Pure virtual called\n"); 2215 fprintf( stderr, "Pure virtual called\n");
2213 abort(); 2216 abort();
2214 2217
2215} 2218}
2216 2219
2217#endif 2220#endif
2218 2221
2219 2222
2220#if defined(OPIE_NEW_MALLOC) 2223#if defined(OPIE_NEW_MALLOC)
2221 2224
2222// The libraries with the skiff package (and possibly others) have 2225// The libraries with the skiff package (and possibly others) have
2223// completely useless implementations of builtin new and delete that 2226// completely useless implementations of builtin new and delete that
2224// use about 50% of your CPU. Here we revert to the simple libc 2227// use about 50% of your CPU. Here we revert to the simple libc
2225// functions. 2228// functions.
2226 2229
2227void* operator new[]( size_t size ) 2230void* operator new[]( size_t size )
2228{ 2231{
2229 return malloc( size ); 2232 return malloc( size );
2230} 2233}
2231 2234
2232void* operator new( size_t size ) 2235void* operator new( size_t size )
2233{ 2236{
2234 return malloc( size ); 2237 return malloc( size );
2235} 2238}
2236 2239
2237void operator delete[]( void* p ) 2240void operator delete[]( void* p )
2238{ 2241{
2239 if ( p ) 2242 if ( p )
2240 free( p ); 2243 free( p );
2241} 2244}
2242 2245
2243void operator delete[]( void* p, size_t /*size*/ ) 2246void operator delete[]( void* p, size_t /*size*/ )
2244{ 2247{
2245 if ( p ) 2248 if ( p )
2246 free( p ); 2249 free( p );
2247} 2250}
2248 2251
2249 2252
2250void operator delete( void* p ) 2253void operator delete( void* p )
2251{ 2254{
2252 if ( p ) 2255 if ( p )
2253 free( p ); 2256 free( p );
2254} 2257}
2255 2258
2256void operator delete( void* p, size_t /*size*/ ) 2259void operator delete( void* p, size_t /*size*/ )
2257{ 2260{
2258 if ( p ) 2261 if ( p )
2259 free( p ); 2262 free( p );
2260} 2263}
2261 2264
2262#endif 2265#endif
2263 2266
2264#if ( QT_VERSION <= 230 ) && !defined(SINGLE_APP) 2267#if ( QT_VERSION <= 230 ) && !defined(SINGLE_APP)
2265#include <qwidgetlist.h> 2268#include <qwidgetlist.h>
2266#ifdef QWS 2269#ifdef QWS
2267#include <qgfx_qws.h> 2270#include <qgfx_qws.h>
2268extern QRect qt_maxWindowRect; 2271extern QRect qt_maxWindowRect;
2269void qt_setMaxWindowRect(const QRect& r ) 2272void qt_setMaxWindowRect(const QRect& r )
2270{ 2273{
2271 qt_maxWindowRect = qt_screen->mapFromDevice( r, 2274 qt_maxWindowRect = qt_screen->mapFromDevice( r,
2272 qt_screen->mapToDevice( QSize( qt_screen->width(), qt_screen->height() ) ) ); 2275 qt_screen->mapToDevice( QSize( qt_screen->width(), qt_screen->height() ) ) );
2273 // Re-resize any maximized windows 2276 // Re-resize any maximized windows
2274 QWidgetList* l = QApplication::topLevelWidgets(); 2277 QWidgetList* l = QApplication::topLevelWidgets();
2275 if ( l ) { 2278 if ( l ) {
2276 QWidget * w = l->first(); 2279 QWidget * w = l->first();
2277 while ( w ) { 2280 while ( w ) {
2278 if ( w->isVisible() && w->isMaximized() ) { 2281 if ( w->isVisible() && w->isMaximized() ) {
2279 w->showMaximized(); 2282 w->showMaximized();
2280 } 2283 }
2281 w = l->next(); 2284 w = l->next();
2282 } 2285 }
2283 delete l; 2286 delete l;
2284 } 2287 }
2285} 2288}
2286#endif 2289#endif
2287#endif 2290#endif
diff --git a/library/qpeapplication.h b/library/qpeapplication.h
index 167fe69..cff3e43 100644
--- a/library/qpeapplication.h
+++ b/library/qpeapplication.h
@@ -1,239 +1,242 @@
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#include "qpeglobal.h" 34#include "qpeglobal.h"
35 35
36class QCopChannel; 36class QCopChannel;
37class QPEApplicationData; 37class QPEApplicationData;
38class QWSEvent; 38class QWSEvent;
39class QWSKeyEvent; 39class QWSKeyEvent;
40 40
41/** 41/**
42 \brief The QPEApplication class implements various system services 42 \brief The QPEApplication class implements various system services
43 that are available to all Qtopia applications. 43 that are available to all Qtopia applications.
44 44
45 Simply by using QPEApplication instead of QApplication, a standard Qt 45 Simply by using QPEApplication instead of QApplication, a standard Qt
46 application becomes a Qtopia application. It automatically follows 46 application becomes a Qtopia application. It automatically follows
47 style changes, quits and raises, and in the 47 style changes, quits and raises, and in the
48 case of \link docwidget.html document-oriented\endlink applications, 48 case of \link docwidget.html document-oriented\endlink applications,
49 changes the currently displayed document in response to the environment. 49 changes the currently displayed document in response to the environment.
50 50
51 To create a \link docwidget.html document-oriented\endlink 51 To create a \link docwidget.html document-oriented\endlink
52 application use showMainDocumentWidget(); to create a 52 application use showMainDocumentWidget(); to create a
53 non-document-oriented application use showMainWidget(). The 53 non-document-oriented application use showMainWidget(). The
54 keepRunning() function indicates whether the application will 54 keepRunning() function indicates whether the application will
55 continue running after it's processed the last \link qcop.html 55 continue running after it's processed the last \link qcop.html
56 QCop\endlink message. This can be changed using setKeepRunning(). 56 QCop\endlink message. This can be changed using setKeepRunning().
57 57
58 A variety of signals are emitted when certain events occur, for 58 A variety of signals are emitted when certain events occur, for
59 example, timeChanged(), clockChanged(), weekChanged(), 59 example, timeChanged(), clockChanged(), weekChanged(),
60 dateFormatChanged() and volumeChanged(). If the application receives 60 dateFormatChanged() and volumeChanged(). If the application receives
61 a \link qcop.html QCop\endlink message on the application's 61 a \link qcop.html QCop\endlink message on the application's
62 QPE/Application/\e{appname} channel, the appMessage() signal is 62 QPE/Application/\e{appname} channel, the appMessage() signal is
63 emitted. There are also flush() and reload() signals, which 63 emitted. There are also flush() and reload() signals, which
64 are emitted when synching begins and ends respectively - upon these 64 are emitted when synching begins and ends respectively - upon these
65 signals, the application should save and reload any data 65 signals, the application should save and reload any data
66 files that are involved in synching. Most of these signals will initially 66 files that are involved in synching. Most of these signals will initially
67 be received and unfiltered through the appMessage() signal. 67 be received and unfiltered through the appMessage() signal.
68 68
69 This class also provides a set of useful static functions. The 69 This class also provides a set of useful static functions. The
70 qpeDir() and documentDir() functions return the respective paths. 70 qpeDir() and documentDir() functions return the respective paths.
71 The grabKeyboard() and ungrabKeyboard() functions are used to 71 The grabKeyboard() and ungrabKeyboard() functions are used to
72 control whether the application takes control of the device's 72 control whether the application takes control of the device's
73 physical buttons (e.g. application launch keys). The stylus' mode of 73 physical buttons (e.g. application launch keys). The stylus' mode of
74 operation is set with setStylusOperation() and retrieved with 74 operation is set with setStylusOperation() and retrieved with
75 stylusOperation(). There are also setInputMethodHint() and 75 stylusOperation(). There are also setInputMethodHint() and
76 inputMethodHint() functions. 76 inputMethodHint() functions.
77 77
78 \ingroup qtopiaemb 78 \ingroup qtopiaemb
79*/ 79*/
80class QPEApplication : public QApplication 80class QPEApplication : public QApplication
81{ 81{
82 Q_OBJECT 82 Q_OBJECT
83public: 83public:
84 QPEApplication( int& argc, char **argv, Type=GuiClient ); 84 QPEApplication( int& argc, char **argv, Type=GuiClient );
85 ~QPEApplication(); 85 ~QPEApplication();
86 86
87 static QString qpeDir(); 87 static QString qpeDir();
88 static QString documentDir(); 88 static QString documentDir();
89 void applyStyle(); 89 void applyStyle();
90 void reset(); 90 void reset();
91 static int defaultRotation(); 91 static int defaultRotation();
92 static void setDefaultRotation(int r); 92 static void setDefaultRotation(int r);
93 static void setCurrentRotation(int r); 93 static void setCurrentRotation(int r);
94 static void setCurrentMode(int x, int y, int depth ); 94 static void setCurrentMode(int x, int y, int depth );
95 static void grabKeyboard(); 95 static void grabKeyboard();
96 static void ungrabKeyboard(); 96 static void ungrabKeyboard();
97 97
98 enum StylusMode { 98 enum StylusMode {
99 LeftOnly, 99 LeftOnly,
100 RightOnHold 100 RightOnHold
101 // RightOnHoldLeftDelayed, etc. 101 // RightOnHoldLeftDelayed, etc.
102 }; 102 };
103 static void setStylusOperation( QWidget*, StylusMode ); 103 static void setStylusOperation( QWidget*, StylusMode );
104 static StylusMode stylusOperation( QWidget* ); 104 static StylusMode stylusOperation( QWidget* );
105 105
106 enum InputMethodHint { 106 enum InputMethodHint {
107 Normal, 107 Normal,
108 AlwaysOff, 108 AlwaysOff,
109 AlwaysOn 109 AlwaysOn
110 }; 110 };
111 111
112 enum screenSaverHint { 112 enum screenSaverHint {
113 Disable = 0, 113 Disable = 0,
114 DisableLightOff = 1, 114 DisableLightOff = 1,
115 DisableSuspend = 2, 115 DisableSuspend = 2,
116 Enable = 100 116 Enable = 100
117 }; 117 };
118 118
119 static void setInputMethodHint( QWidget *, InputMethodHint ); 119 static void setInputMethodHint( QWidget *, InputMethodHint );
120 static InputMethodHint inputMethodHint( QWidget * ); 120 static InputMethodHint inputMethodHint( QWidget * );
121 121
122 void showMainWidget( QWidget*, bool nomax=FALSE ); 122 void showMainWidget( QWidget*, bool nomax=FALSE );
123 void showMainDocumentWidget( QWidget*, bool nomax=FALSE ); 123 void showMainDocumentWidget( QWidget*, bool nomax=FALSE );
124 124
125 static void showDialog( QDialog*, bool nomax=FALSE ) QPE_WEAK_SYMBOL; 125 static void showDialog( QDialog*, bool nomax=FALSE ) QPE_WEAK_SYMBOL;
126 static int execDialog ( QDialog*, bool nomax=FALSE ) QPE_WEAK_SYMBOL; 126 static int execDialog ( QDialog*, bool nomax=FALSE ) QPE_WEAK_SYMBOL;
127 static void showWidget( QWidget*, bool nomax=FALSE ) QPE_WEAK_SYMBOL; 127 static void showWidget( QWidget*, bool nomax=FALSE ) QPE_WEAK_SYMBOL;
128 /* Merge setTempScreenSaverMode */ 128 /* Merge setTempScreenSaverMode */
129#ifdef QTOPIA_INTERNAL_INITAPP 129#ifdef QTOPIA_INTERNAL_INITAPP
130 void initApp( int argv, char **argv ); 130 void initApp( int argv, char **argv );
131#endif 131#endif
132 132
133 static void setKeepRunning(); 133 static void setKeepRunning();
134 bool keepRunning() const; 134 bool keepRunning() const;
135 135
136 bool keyboardGrabbed() const; 136 bool keyboardGrabbed() const;
137 137
138 int exec(); 138 int exec();
139 139
140signals: 140signals:
141 void clientMoused(); 141 void clientMoused();
142 void timeChanged(); 142 void timeChanged();
143 void clockChanged( bool pm ); 143 void clockChanged( bool pm );
144 void micChanged( bool muted ); 144 void micChanged( bool muted );
145 void volumeChanged( bool muted ); 145 void volumeChanged( bool muted );
146 void appMessage( const QCString& msg, const QByteArray& data); 146 void appMessage( const QCString& msg, const QByteArray& data);
147 void weekChanged( bool startOnMonday ); 147 void weekChanged( bool startOnMonday );
148 void dateFormatChanged( DateFormat ); 148 void dateFormatChanged( DateFormat );
149 void flush(); 149 void flush();
150 void reload(); 150 void reload();
151 /* linkChanged signal */ 151 /* linkChanged signal */
152 152
153private slots: 153private slots:
154 void systemMessage( const QCString &msg, const QByteArray &data ); 154 void systemMessage( const QCString &msg, const QByteArray &data );
155 void pidMessage( const QCString &msg, const QByteArray &data ); 155 void pidMessage( const QCString &msg, const QByteArray &data );
156 void removeSenderFromStylusDict(); 156 void removeSenderFromStylusDict();
157 void hideOrQuit(); 157 void hideOrQuit();
158 158
159protected: 159protected:
160 bool qwsEventFilter( QWSEvent * ); 160 bool qwsEventFilter( QWSEvent * );
161 void internalSetStyle( const QString &style ); 161 void internalSetStyle( const QString &style );
162 void prepareForTermination(bool willrestart); 162 void prepareForTermination(bool willrestart);
163 virtual void restart(); 163 virtual void restart();
164 virtual void shutdown(); 164 virtual void shutdown();
165 bool eventFilter( QObject *, QEvent * ); 165 bool eventFilter( QObject *, QEvent * );
166 void timerEvent( QTimerEvent * ); 166 void timerEvent( QTimerEvent * );
167 bool raiseAppropriateWindow(); 167 bool raiseAppropriateWindow();
168 virtual void tryQuit(); 168 virtual void tryQuit();
169private: 169private:
170 void mapToDefaultAction( QWSKeyEvent *ke, int defKey ); 170 void mapToDefaultAction( QWSKeyEvent *ke, int defKey );
171 void processQCopFile(); 171 void processQCopFile();
172 172
173#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 173#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
174 QCopChannel *sysChannel; 174 QCopChannel *sysChannel;
175 QCopChannel *pidChannel; 175 QCopChannel *pidChannel;
176#endif 176#endif
177 QPEApplicationData *d; 177 QPEApplicationData *d;
178 178
179 bool reserved_sh; 179 bool reserved_sh;
180 180
181}; 181};
182 182
183 183
184 184
185enum Transformation { Rot0, Rot90, Rot180, Rot270 }; /* from qgfxtransformed_qws.cpp */ 185enum Transformation { Rot0, Rot90, Rot180, Rot270 }; /* from qgfxtransformed_qws.cpp */
186 186
187inline int TransToDeg ( Transformation t ) 187inline int TransToDeg ( Transformation t )
188{ 188{
189 int d = static_cast<int>( t ); 189 int d = static_cast<int>( t );
190 return d * 90; 190 return d * 90;
191} 191}
192 192
193inline Transformation DegToTrans ( int d ) 193inline Transformation DegToTrans ( int d )
194{ 194{
195 Transformation t = static_cast<Transformation>( d / 90 ); 195 Transformation t = static_cast<Transformation>( d / 90 );
196 return t; 196 return t;
197} 197}
198 198
199/* 199/*
200 * Set current rotation of Opie, and rotation for newly started apps. 200 * Set current rotation of Opie, and rotation for newly started apps.
201 * Differs from setDefaultRotation in that 1) it rotates currently running apps, 201 * Differs from setDefaultRotation in that 1) it rotates currently running apps,
202 * and 2) does not set deforient or save orientation to qpe.conf. 202 * and 2) does not set deforient or save orientation to qpe.conf.
203 */ 203 */
204 204
205inline void QPEApplication::setCurrentRotation( int r ) 205inline void QPEApplication::setCurrentRotation( int r )
206{ 206{
207 // setTransformation has been introduced in Qt/Embedded 2.3.4 snapshots 207 // setTransformation has been introduced in Qt/Embedded 2.3.4 snapshots
208 // for compatibility with the SharpROM use fallback to setDefaultTransformation() 208 // for compatibility with the SharpROM use fallback to setDefaultTransformation()
209#if QT_VERSION > 233 209#if QT_VERSION > 233
210 Transformation e = DegToTrans( r ); 210 Transformation e = DegToTrans( r );
211 ::setenv( "QWS_DISPLAY", QString( "Transformed:Rot%1:0" ).arg( r ).latin1(), 1 ); 211 QCString old = getenv("QWS_DISPLAY") ? getenv( "QWS_DISPLAY" ) : "Transformed";
212 int j = 0;
213 QString driver( old.left( ( ( j = old.find( ':' ) ) >= 0 ) ? j : old.size() ).data() );
214 ::setenv( "QWS_DISPLAY", QString( "%1:Rot%2:0" ).arg( driver ).arg( r ).latin1(), 1 );
212 qApp->desktop()->qwsDisplay()->setTransformation( e ); 215 qApp->desktop()->qwsDisplay()->setTransformation( e );
213#else 216#else
214 setDefaultRotation( r ); 217 setDefaultRotation( r );
215#endif 218#endif
216} 219}
217 220
218/* 221/*
219 * Qtopia 1.7 SDK compatibility macros 222 * Qtopia 1.7 SDK compatibility macros
220 * FIXME: Support Opie Quicklaunch Interface 223 * FIXME: Support Opie Quicklaunch Interface
221 */ 224 */
222 #define QTOPIA_ADD_APPLICATION(NAME,IMPLEMENTATION) \ 225 #define QTOPIA_ADD_APPLICATION(NAME,IMPLEMENTATION) \
223 int main( int argc, char** argv ) \ 226 int main( int argc, char** argv ) \
224 { \ 227 { \
225 QPEApplication app = QPEApplication( argc, argv );\ 228 QPEApplication app = QPEApplication( argc, argv );\
226 IMPLEMENTATION* mw = new IMPLEMENTATION(); \ 229 IMPLEMENTATION* mw = new IMPLEMENTATION(); \
227 app.showMainWidget( mw ); \ 230 app.showMainWidget( mw ); \
228 app.exec(); \ 231 app.exec(); \
229 } 232 }
230#define QTOPIA_MAIN // Bee-Bop-Alula 233#define QTOPIA_MAIN // Bee-Bop-Alula
231 234
232/* 235/*
233 * -remove me 236 * -remove me
234 */ 237 */
235#ifdef Q_WS_QWS 238#ifdef Q_WS_QWS
236extern Q_EXPORT QRect qt_maxWindowRect; 239extern Q_EXPORT QRect qt_maxWindowRect;
237#endif 240#endif
238 241
239#endif 242#endif