summaryrefslogtreecommitdiff
path: root/library
Unidiff
Diffstat (limited to 'library') (more/less context) (ignore whitespace changes)
-rw-r--r--library/filemanager.cpp67
-rw-r--r--library/fontdatabase.cpp4
-rw-r--r--library/global.cpp4
-rw-r--r--library/library.pro2
-rw-r--r--library/network.cpp4
-rw-r--r--library/qlibrary_unix.cpp113
-rw-r--r--library/qpeapplication.cpp29
-rw-r--r--library/qpedecoration_qws.cpp8
-rw-r--r--library/sound.cpp3
-rw-r--r--library/storage.cpp42
10 files changed, 255 insertions, 21 deletions
diff --git a/library/filemanager.cpp b/library/filemanager.cpp
index cc657fa..91986a0 100644
--- a/library/filemanager.cpp
+++ b/library/filemanager.cpp
@@ -1,341 +1,384 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of 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#include "filemanager.h" 20#include "filemanager.h"
21#include "applnk.h" 21#include "applnk.h"
22 22
23#include <qdir.h> 23#include <qdir.h>
24#include <qfile.h> 24#include <qfile.h>
25#include <qfileinfo.h> 25#include <qfileinfo.h>
26#include <qtextstream.h> 26#include <qtextstream.h>
27#include <qtextcodec.h> 27#include <qtextcodec.h>
28 28
29#include <errno.h> 29#include <errno.h>
30#include <stdlib.h> 30#include <stdlib.h>
31#include <unistd.h> 31#include <unistd.h>
32#include <sys/stat.h> 32#include <sys/stat.h>
33#include <dirent.h> 33#include <dirent.h>
34#include <sys/sendfile.h> 34#ifdef Q_OS_MACX
35// MacOS X does not have sendfile.. :(
36// But maybe in the future.. !?
37# ifdef SENDFILE
38# include <sys/types.h>
39# include <sys/socket.h>
40# endif
41#else
42# include <sys/sendfile.h>
43#endif /* Q_OS_MACX */
35#include <fcntl.h> 44#include <fcntl.h>
36 45
37/*! 46/*!
38 \class FileManager 47 \class FileManager
39 \brief The FileManager class assists with AppLnk input/output. 48 \brief The FileManager class assists with AppLnk input/output.
40*/ 49*/
41 50
42/*! 51/*!
43 Constructs a FileManager. 52 Constructs a FileManager.
44*/ 53*/
45FileManager::FileManager() 54FileManager::FileManager()
46{ 55{
47} 56}
48 57
49/*! 58/*!
50 Destroys a FileManager. 59 Destroys a FileManager.
51*/ 60*/
52FileManager::~FileManager() 61FileManager::~FileManager()
53{ 62{
54 63
55} 64}
56 65
57/*! 66/*!
58 Saves \a data as the document specified by \a f. 67 Saves \a data as the document specified by \a f.
59 68
60 Returns whether the operation succeeded. 69 Returns whether the operation succeeded.
61*/ 70*/
62bool FileManager::saveFile( const DocLnk &f, const QByteArray &data ) 71bool FileManager::saveFile( const DocLnk &f, const QByteArray &data )
63{ 72{
64 QString fn = f.file() + ".new"; 73 QString fn = f.file() + ".new";
65 ensurePathExists( fn ); 74 ensurePathExists( fn );
66 QFile fl( fn ); 75 QFile fl( fn );
67 if ( !fl.open( IO_WriteOnly|IO_Raw ) ) { 76 if ( !fl.open( IO_WriteOnly|IO_Raw ) ) {
68 qWarning("open failed"); 77 qWarning("open failed");
69 return FALSE; 78 return FALSE;
70 } 79 }
71 int total_written = fl.writeBlock( data ); 80 int total_written = fl.writeBlock( data );
72 fl.close(); 81 fl.close();
73 if ( total_written != int(data.size()) || !f.writeLink() ) { 82 if ( total_written != int(data.size()) || !f.writeLink() ) {
74 QFile::remove( fn ); 83 QFile::remove( fn );
75 return FALSE; 84 return FALSE;
76 } 85 }
77 qDebug("total written %d out of %d", total_written, data.size()); 86 qDebug("total written %d out of %d", total_written, data.size());
78 // else rename the file... 87 // else rename the file...
79 if ( !renameFile( fn.latin1(), f.file().latin1() ) ) { 88 if ( !renameFile( fn.latin1(), f.file().latin1() ) ) {
80 qWarning( "problem renaming file %s to %s, errno: %d", fn.latin1(), 89 qWarning( "problem renaming file %s to %s, errno: %d", fn.latin1(),
81 f.file().latin1(), errno ); 90 f.file().latin1(), errno );
82 // remove the file... 91 // remove the file...
83 } 92 }
84 return TRUE; 93 return TRUE;
85} 94}
86 95
87/*! 96/*!
88 Saves \a text as the document specified by \a f. 97 Saves \a text as the document specified by \a f.
89 98
90 The text is saved in UTF8 format. 99 The text is saved in UTF8 format.
91 100
92 Returns whether the operation succeeded. 101 Returns whether the operation succeeded.
93*/ 102*/
94bool FileManager::saveFile( const DocLnk &f, const QString &text ) 103bool FileManager::saveFile( const DocLnk &f, const QString &text )
95{ 104{
96 QString fn = f.file() + ".new"; 105 QString fn = f.file() + ".new";
97 ensurePathExists( fn ); 106 ensurePathExists( fn );
98 QFile fl( fn ); 107 QFile fl( fn );
99 if ( !fl.open( IO_WriteOnly|IO_Raw ) ) { 108 if ( !fl.open( IO_WriteOnly|IO_Raw ) ) {
100 qWarning("open failed"); 109 qWarning("open failed");
101 return FALSE; 110 return FALSE;
102 } 111 }
103 112
104 QCString cstr = text.utf8(); 113 QCString cstr = text.utf8();
105 int total_written; 114 int total_written;
106 total_written = fl.writeBlock( cstr.data(), cstr.length() ); 115 total_written = fl.writeBlock( cstr.data(), cstr.length() );
107 fl.close(); 116 fl.close();
108 if ( total_written != int(cstr.length()) || !f.writeLink() ) { 117 if ( total_written != int(cstr.length()) || !f.writeLink() ) {
109 QFile::remove( fn ); 118 QFile::remove( fn );
110 return FALSE; 119 return FALSE;
111 } 120 }
112 // okay now rename the file.. 121 // okay now rename the file..
113 if ( !renameFile( fn.latin1(), f.file().latin1() ) ) { 122 if ( !renameFile( fn.latin1(), f.file().latin1() ) ) {
114 qWarning( "problem renaming file %s to %s, errno: %d", fn.latin1(), 123 qWarning( "problem renaming file %s to %s, errno: %d", fn.latin1(),
115 f.file().latin1(), errno ); 124 f.file().latin1(), errno );
116 125
117 } 126 }
118 return TRUE; 127 return TRUE;
119} 128}
120 129
121 130
122/*! 131/*!
123 Loads \a text from the document specified by \a f. 132 Loads \a text from the document specified by \a f.
124 133
125 The text is required to be in UTF8 format. 134 The text is required to be in UTF8 format.
126 135
127 Returns whether the operation succeeded. 136 Returns whether the operation succeeded.
128*/ 137*/
129bool FileManager::loadFile( const DocLnk &f, QString &text ) 138bool FileManager::loadFile( const DocLnk &f, QString &text )
130{ 139{
131 QString fn = f.file(); 140 QString fn = f.file();
132 QFile fl( fn ); 141 QFile fl( fn );
133 if ( !fl.open( IO_ReadOnly ) ) 142 if ( !fl.open( IO_ReadOnly ) )
134 return FALSE; 143 return FALSE;
135 QTextStream ts( &fl ); 144 QTextStream ts( &fl );
136#if QT_VERSION <= 230 && defined(QT_NO_CODECS) 145#if QT_VERSION <= 230 && defined(QT_NO_CODECS)
137 // The below should work, but doesn't in Qt 2.3.0 146 // The below should work, but doesn't in Qt 2.3.0
138 ts.setCodec( QTextCodec::codecForMib( 106 ) ); 147 ts.setCodec( QTextCodec::codecForMib( 106 ) );
139#else 148#else
140 ts.setEncoding( QTextStream::UnicodeUTF8 ); 149 ts.setEncoding( QTextStream::UnicodeUTF8 );
141#endif 150#endif
142 text = ts.read(); 151 text = ts.read();
143 fl.close(); 152 fl.close();
144 return TRUE; 153 return TRUE;
145} 154}
146 155
147 156
148/*! 157/*!
149 Loads \a ba from the document specified by \a f. 158 Loads \a ba from the document specified by \a f.
150 159
151 Returns whether the operation succeeded. 160 Returns whether the operation succeeded.
152*/ 161*/
153bool FileManager::loadFile( const DocLnk &f, QByteArray &ba ) 162bool FileManager::loadFile( const DocLnk &f, QByteArray &ba )
154{ 163{
155 QString fn = f.file(); 164 QString fn = f.file();
156 QFile fl( fn ); 165 QFile fl( fn );
157 if ( !fl.open( IO_ReadOnly ) ) 166 if ( !fl.open( IO_ReadOnly ) )
158 return FALSE; 167 return FALSE;
159 ba.resize( fl.size() ); 168 ba.resize( fl.size() );
160 if ( fl.size() > 0 ) 169 if ( fl.size() > 0 )
161 fl.readBlock( ba.data(), fl.size() ); 170 fl.readBlock( ba.data(), fl.size() );
162 fl.close(); 171 fl.close();
163 return TRUE; 172 return TRUE;
164} 173}
165 174
166/*! 175/*!
167 Copies the document specified by \a src to the document specified 176 Copies the document specified by \a src to the document specified
168 by \a dest. 177 by \a dest.
169 178
170 Returns whether the operation succeeded. 179 Returns whether the operation succeeded.
171*/ 180*/
172bool FileManager::copyFile( const AppLnk &src, const AppLnk &dest ) 181bool FileManager::copyFile( const AppLnk &src, const AppLnk &dest )
173{ 182{
174 QFile sf( src.file() ); 183 QFile sf( src.file() );
175 if ( !sf.open( IO_ReadOnly ) ) 184 if ( !sf.open( IO_ReadOnly ) )
176 return FALSE; 185 return FALSE;
177 186
178 QString fn = dest.file() + ".new"; 187 QString fn = dest.file() + ".new";
179 ensurePathExists( fn ); 188 ensurePathExists( fn );
180 QFile df( fn ); 189 QFile df( fn );
181 if ( !df.open( IO_WriteOnly|IO_Raw ) ) 190 if ( !df.open( IO_WriteOnly|IO_Raw ) )
182 return FALSE; 191 return FALSE;
183 192
184 const int bufsize = 16384; 193 const int bufsize = 16384;
185 char buffer[bufsize]; 194 char buffer[bufsize];
186 bool ok = TRUE; 195 bool ok = TRUE;
187 int bytesRead = 0; 196 int bytesRead = 0;
188 while ( ok && !sf.atEnd() ) { 197 while ( ok && !sf.atEnd() ) {
189 bytesRead = sf.readBlock( buffer, bufsize ); 198 bytesRead = sf.readBlock( buffer, bufsize );
190 if ( bytesRead < 0 ) 199 if ( bytesRead < 0 )
191 ok = FALSE; 200 ok = FALSE;
192 while ( ok && bytesRead > 0 ) { 201 while ( ok && bytesRead > 0 ) {
193 int bytesWritten = df.writeBlock( buffer, bytesRead ); 202 int bytesWritten = df.writeBlock( buffer, bytesRead );
194 if ( bytesWritten < 0 ) 203 if ( bytesWritten < 0 )
195 ok = FALSE; 204 ok = FALSE;
196 else 205 else
197 bytesRead -= bytesWritten; 206 bytesRead -= bytesWritten;
198 } 207 }
199 } 208 }
200 209
201 if ( ok ) 210 if ( ok )
202 ok = dest.writeLink(); 211 ok = dest.writeLink();
203 212
204 if ( ok ) { 213 if ( ok ) {
205 // okay now rename the file... 214 // okay now rename the file...
206 if ( !renameFile( fn.latin1(), dest.file().latin1() ) ) { 215 if ( !renameFile( fn.latin1(), dest.file().latin1() ) ) {
207 qWarning( "problem renaming file %s to %s, errno: %d", fn.latin1(), 216 qWarning( "problem renaming file %s to %s, errno: %d", fn.latin1(),
208 dest.file().latin1(), errno ); 217 dest.file().latin1(), errno );
209 // remove the tmp file, otherwise, it will just lay around... 218 // remove the tmp file, otherwise, it will just lay around...
210 QFile::remove( fn.latin1() ); 219 QFile::remove( fn.latin1() );
211 } 220 }
212 } else { 221 } else {
213 QFile::remove( fn.latin1() ); 222 QFile::remove( fn.latin1() );
214 } 223 }
215 224
216 return ok; 225 return ok;
217} 226}
218 227
228
229
219bool FileManager::copyFile( const QString & src, const QString & dest ) { 230bool FileManager::copyFile( const QString & src, const QString & dest ) {
220 bool success = true; 231 bool success = true;
221 struct stat status; 232 struct stat status;
222 int read_fd=0; 233 int read_fd=0;
223 int write_fd=0; 234 int write_fd=0;
224 struct stat stat_buf; 235 struct stat stat_buf;
225 off_t offset = 0; 236 off_t offset = 0;
226 QFile srcFile(src); 237 QFile srcFile(src);
227 QFile destFile(dest); 238 QFile destFile(dest);
228 239
229 if(!srcFile.open( IO_ReadOnly|IO_Raw)) { 240 if(!srcFile.open( IO_ReadOnly|IO_Raw)) {
230 return success = false; 241 return success = false;
231 } 242 }
232 read_fd = srcFile.handle(); 243 read_fd = srcFile.handle();
233 if(read_fd != -1) { 244 if(read_fd != -1) {
234 fstat (read_fd, &stat_buf); 245 fstat (read_fd, &stat_buf);
235 if( !destFile.open( IO_WriteOnly|IO_Raw ) ) 246 if( !destFile.open( IO_WriteOnly|IO_Raw ) )
236 return success = false; 247 return success = false;
237 write_fd = destFile.handle(); 248 write_fd = destFile.handle();
238 if(write_fd != -1) { 249 if(write_fd != -1) {
239 int err=0; 250 int err=0;
240 QString msg; 251 QString msg;
241 err = sendfile(write_fd, read_fd, &offset, stat_buf.st_size); 252#ifdef Q_OS_MACX
242 if( err == -1) { 253#ifdef SENDMAIL
243 switch(err) { 254 /* FreeBSD does support a different kind of
244 case EBADF : msg = "The input file was not opened for reading or the output file was not opened for writing. "; 255 * sendfile. (eilers)
245 case EINVAL: msg = "Descriptor is not valid or locked. "; 256 * I took this from Very Secure FTPd
246 case ENOMEM: msg = "Insufficient memory to read from in_fd."; 257 * Licence: GPL
247 case EIO: msg = "Unspecified error while reading from in_fd."; 258 * Author: Chris Evans
248 }; 259 * sysdeputil.c
249 success = false; 260 */
250 } 261 /* XXX - start_pos will truncate on 32-bit machines - can we
251 } else { 262 * say "start from current pos"?
263 */
264 off_t written = 0;
265 int retval = 0;
266 retval = sendfile(read_fd, write_fd, offset, stat_buf.st_size, NULL,
267 &written, 0);
268 /* Translate to Linux-like retval */
269 if (written > 0)
270 {
271 err = (int) written;
272 }
273#else /* SENDMAIL */
274 err == -1;
275 msg = "FAILURE: Using unsupported function \"sendfile()\" Need Workaround !!";
276 success = false;
277# warning "Need workaround for sendfile!!(eilers)"
278#endif /* SENDMAIL */
279
280#else
281 err = sendfile(write_fd, read_fd, &offset, stat_buf.st_size);
282 if( err == -1) {
283 switch(err) {
284 case EBADF : msg = "The input file was not opened for reading or the output file was not opened for writing. ";
285 case EINVAL: msg = "Descriptor is not valid or locked. ";
286 case ENOMEM: msg = "Insufficient memory to read from in_fd.";
287 case EIO: msg = "Unspecified error while reading from in_fd.";
288 };
289 success = false;
290 }
291#endif /* Q_OS_MACX */
292 if( !success )
293 qWarning( msg );
294 } else {
252 qWarning("open write failed %s, %s",src.latin1(), dest.latin1()); 295 qWarning("open write failed %s, %s",src.latin1(), dest.latin1());
253 success = false; 296 success = false;
254 } 297 }
255 } else { 298 } else {
256 qWarning("open read failed %s, %s",src.latin1(), dest.latin1()); 299 qWarning("open read failed %s, %s",src.latin1(), dest.latin1());
257 success = false; 300 success = false;
258 } 301 }
259 srcFile.close(); 302 srcFile.close();
260 destFile.close(); 303 destFile.close();
261 // Set file permissions 304 // Set file permissions
262 if( stat( (const char *) src, &status ) == 0 ) { 305 if( stat( (const char *) src, &status ) == 0 ) {
263 chmod( (const char *) dest, status.st_mode ); 306 chmod( (const char *) dest, status.st_mode );
264 } 307 }
265 308
266 return success; 309 return success;
267} 310}
268 311
269 312
270bool FileManager::renameFile( const QString & src, const QString & dest ) { 313bool FileManager::renameFile( const QString & src, const QString & dest ) {
271 if(copyFile( src, dest )) { 314 if(copyFile( src, dest )) {
272 if(QFile::remove(src) ) { 315 if(QFile::remove(src) ) {
273 return true; 316 return true;
274 } 317 }
275 } 318 }
276 return false; 319 return false;
277} 320}
278 321
279 322
280/*! 323/*!
281 Opens the document specified by \a f as a readable QIODevice. 324 Opens the document specified by \a f as a readable QIODevice.
282 The caller must delete the return value. 325 The caller must delete the return value.
283 326
284 Returns 0 if the operation fails. 327 Returns 0 if the operation fails.
285*/ 328*/
286QIODevice* FileManager::openFile( const DocLnk& f ) 329QIODevice* FileManager::openFile( const DocLnk& f )
287{ 330{
288 QString fn = f.file(); 331 QString fn = f.file();
289 QFile* fl = new QFile( fn ); 332 QFile* fl = new QFile( fn );
290 if ( !fl->open( IO_ReadOnly ) ) { 333 if ( !fl->open( IO_ReadOnly ) ) {
291 delete fl; 334 delete fl;
292 fl = 0; 335 fl = 0;
293 } 336 }
294 return fl; 337 return fl;
295} 338}
296 339
297/*! 340/*!
298 Opens the document specified by \a f as a writable QIODevice. 341 Opens the document specified by \a f as a writable QIODevice.
299 The caller must delete the return value. 342 The caller must delete the return value.
300 343
301 Returns 0 if the operation fails. 344 Returns 0 if the operation fails.
302*/ 345*/
303QIODevice* FileManager::saveFile( const DocLnk& f ) 346QIODevice* FileManager::saveFile( const DocLnk& f )
304{ 347{
305 QString fn = f.file(); 348 QString fn = f.file();
306 ensurePathExists( fn ); 349 ensurePathExists( fn );
307 QFile* fl = new QFile( fn ); 350 QFile* fl = new QFile( fn );
308 if ( fl->open( IO_WriteOnly ) ) { 351 if ( fl->open( IO_WriteOnly ) ) {
309 f.writeLink(); 352 f.writeLink();
310 } else { 353 } else {
311 delete fl; 354 delete fl;
312 fl = 0; 355 fl = 0;
313 } 356 }
314 return fl; 357 return fl;
315} 358}
316 359
317/*! 360/*!
318 Returns whether the document specified by \a f current exists 361 Returns whether the document specified by \a f current exists
319 as a file on disk. 362 as a file on disk.
320*/ 363*/
321bool FileManager::exists( const DocLnk &f ) 364bool FileManager::exists( const DocLnk &f )
322{ 365{
323 return QFile::exists(f.file()); 366 return QFile::exists(f.file());
324} 367}
325 368
326 369
327/*! 370/*!
328 Ensures that the path \a fn exists, by creating required directories. 371 Ensures that the path \a fn exists, by creating required directories.
329 Returns TRUE if successful. 372 Returns TRUE if successful.
330*/ 373*/
331bool FileManager::ensurePathExists( const QString &fn ) 374bool FileManager::ensurePathExists( const QString &fn )
332{ 375{
333 QFileInfo fi(fn); 376 QFileInfo fi(fn);
334 fi.setFile( fi.dirPath(TRUE) ); 377 fi.setFile( fi.dirPath(TRUE) );
335 if ( !fi.exists() ) { 378 if ( !fi.exists() ) {
336 if ( system(("mkdir -p "+fi.filePath())) ) 379 if ( system(("mkdir -p "+fi.filePath())) )
337 return FALSE; 380 return FALSE;
338 } 381 }
339 382
340 return TRUE; 383 return TRUE;
341} 384}
diff --git a/library/fontdatabase.cpp b/library/fontdatabase.cpp
index c7a5211..2ad8e95 100644
--- a/library/fontdatabase.cpp
+++ b/library/fontdatabase.cpp
@@ -1,249 +1,253 @@
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#include <qpe/qpeapplication.h> 21#include <qpe/qpeapplication.h>
22#include "fontfactoryinterface.h" 22#include "fontfactoryinterface.h"
23#include "fontdatabase.h" 23#include "fontdatabase.h"
24 24
25#include <qpe/qlibrary.h> 25#include <qpe/qlibrary.h>
26 26
27#include <qfontmanager_qws.h> 27#include <qfontmanager_qws.h>
28#include <qdir.h> 28#include <qdir.h>
29#include <qdict.h> 29#include <qdict.h>
30#include <stdio.h> 30#include <stdio.h>
31#include <stdlib.h> 31#include <stdlib.h>
32 32
33static QString fontDir() 33static QString fontDir()
34{ 34{
35 QString qtdir = getenv("QTDIR"); 35 QString qtdir = getenv("QTDIR");
36 if ( qtdir.isEmpty() ) qtdir = "/usr/local/qt-embedded"; 36 if ( qtdir.isEmpty() ) qtdir = "/usr/local/qt-embedded";
37 return qtdir+"/lib/fonts/"; 37 return qtdir+"/lib/fonts/";
38} 38}
39 39
40#ifdef QT_NO_FONTDATABASE 40#ifdef QT_NO_FONTDATABASE
41static QString fontFamily( const QString& key ) 41static QString fontFamily( const QString& key )
42{ 42{
43 int u0 = key.find('_'); 43 int u0 = key.find('_');
44 int u1 = key.find('_',u0+1); 44 int u1 = key.find('_',u0+1);
45 int u2 = key.find('_',u1+1); 45 int u2 = key.find('_',u1+1);
46 QString family = key.left(u0); 46 QString family = key.left(u0);
47 //int pointSize = key.mid(u0+1,u1-u0-1).toInt(); 47 //int pointSize = key.mid(u0+1,u1-u0-1).toInt();
48 //int weight = key.mid(u1+1,u2-u1-1).toInt(); 48 //int weight = key.mid(u1+1,u2-u1-1).toInt();
49 //bool italic = key.mid(u2-1,1) == "i"; 49 //bool italic = key.mid(u2-1,1) == "i";
50 // #### ignores _t and _I fields 50 // #### ignores _t and _I fields
51 return family; 51 return family;
52} 52}
53#endif 53#endif
54 54
55 55
56QValueList<FontFactory> *FontDatabase::factoryList = 0; 56QValueList<FontFactory> *FontDatabase::factoryList = 0;
57/*! 57/*!
58 \class FontDatabase fontdatabase.h 58 \class FontDatabase fontdatabase.h
59 \brief The FontDatabase class provides information about available fonts. 59 \brief The FontDatabase class provides information about available fonts.
60 60
61 Most often you will simply want to query the database for the 61 Most often you will simply want to query the database for the
62 available font families(). 62 available font families().
63 63
64 Use FontDatabase rather than QFontDatabase when you may need access 64 Use FontDatabase rather than QFontDatabase when you may need access
65 to fonts that are not normally available. For example, if the 65 to fonts that are not normally available. For example, if the
66 freetype library and the Qtopia freetype plugin are installed, 66 freetype library and the Qtopia freetype plugin are installed,
67 TrueType fonts will be available to your application. Font renderer 67 TrueType fonts will be available to your application. Font renderer
68 plugins have greater resource requirements than system fonts so they 68 plugins have greater resource requirements than system fonts so they
69 should be used only when necessary. You can force the loading of 69 should be used only when necessary. You can force the loading of
70 font renderer plugins with loadRenderers(). 70 font renderer plugins with loadRenderers().
71 71
72 \ingroup qtopiaemb 72 \ingroup qtopiaemb
73*/ 73*/
74 74
75/*! 75/*!
76 Constructs a FontDatabase object. 76 Constructs a FontDatabase object.
77*/ 77*/
78FontDatabase::FontDatabase() 78FontDatabase::FontDatabase()
79#ifndef QT_NO_FONTDATABASE 79#ifndef QT_NO_FONTDATABASE
80 : QFontDatabase() 80 : QFontDatabase()
81#endif 81#endif
82{ 82{
83 if ( !factoryList ) 83 if ( !factoryList )
84 loadRenderers(); 84 loadRenderers();
85} 85}
86 86
87/*! 87/*!
88 Returns a list of names of all the available font families. 88 Returns a list of names of all the available font families.
89*/ 89*/
90QStringList FontDatabase::families() const 90QStringList FontDatabase::families() const
91{ 91{
92#ifndef QT_NO_FONTDATABASE 92#ifndef QT_NO_FONTDATABASE
93 return QFontDatabase::families(); 93 return QFontDatabase::families();
94#else 94#else
95 95
96#ifndef QWS 96#ifndef QWS
97 QStringList list; 97 QStringList list;
98 return list; 98 return list;
99#else 99#else
100 QStringList list; 100 QStringList list;
101 QDict<void> familyDict; 101 QDict<void> familyDict;
102 QDiskFont *qdf; 102 QDiskFont *qdf;
103 for ( qdf=qt_fontmanager->diskfonts.first(); qdf!=0; 103 for ( qdf=qt_fontmanager->diskfonts.first(); qdf!=0;
104 qdf=qt_fontmanager->diskfonts.next()) { 104 qdf=qt_fontmanager->diskfonts.next()) {
105 QString familyname = qdf->name; 105 QString familyname = qdf->name;
106 if ( !familyDict.find( familyname ) ) { 106 if ( !familyDict.find( familyname ) ) {
107 familyDict.insert( familyname, (void *)1 ); 107 familyDict.insert( familyname, (void *)1 );
108 list.append( familyname ); 108 list.append( familyname );
109 } 109 }
110 } 110 }
111 111
112 QDir dir(fontDir(),"*.qpf"); 112 QDir dir(fontDir(),"*.qpf");
113 for (int i=0; i<(int)dir.count(); i++) { 113 for (int i=0; i<(int)dir.count(); i++) {
114 QString familyname = fontFamily(dir[i]); 114 QString familyname = fontFamily(dir[i]);
115 if ( !familyDict.find( familyname ) ) { 115 if ( !familyDict.find( familyname ) ) {
116 familyDict.insert( familyname, (void *)1 ); 116 familyDict.insert( familyname, (void *)1 );
117 list.append( familyname ); 117 list.append( familyname );
118 } 118 }
119 } 119 }
120 120
121 return list; 121 return list;
122#endif 122#endif
123#endif 123#endif
124} 124}
125 125
126#ifdef QT_NO_FONTDATABASE 126#ifdef QT_NO_FONTDATABASE
127/*! 127/*!
128 Returns a list of standard fontsizes. 128 Returns a list of standard fontsizes.
129*/ 129*/
130QValueList<int> FontDatabase::standardSizes() 130QValueList<int> FontDatabase::standardSizes()
131{ 131{
132 static int s[]={ 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 132 static int s[]={ 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28,
133 36, 48, 72, 0 }; 133 36, 48, 72, 0 };
134 static bool first = TRUE; 134 static bool first = TRUE;
135 static QValueList<int> sList; 135 static QValueList<int> sList;
136 if ( first ) { 136 if ( first ) {
137 first = FALSE; 137 first = FALSE;
138 int i = 0; 138 int i = 0;
139 while( s[i] ) 139 while( s[i] )
140 sList.append( s[i++] ); 140 sList.append( s[i++] );
141 } 141 }
142 return sList; 142 return sList;
143} 143}
144 144
145#endif 145#endif
146 146
147/*! 147/*!
148 Load any font renderer plugins that are available and make the fonts 148 Load any font renderer plugins that are available and make the fonts
149 that the plugins can read available. 149 that the plugins can read available.
150*/ 150*/
151void FontDatabase::loadRenderers() 151void FontDatabase::loadRenderers()
152{ 152{
153#ifndef QWS 153#ifndef QWS
154 return; 154 return;
155#else 155#else
156 156
157#ifndef QT_NO_COMPONENT 157#ifndef QT_NO_COMPONENT
158 if ( !factoryList ) 158 if ( !factoryList )
159 factoryList = new QValueList<FontFactory>; 159 factoryList = new QValueList<FontFactory>;
160 160
161 QValueList<FontFactory>::Iterator mit; 161 QValueList<FontFactory>::Iterator mit;
162 for ( mit = factoryList->begin(); mit != factoryList->end(); ++mit ) { 162 for ( mit = factoryList->begin(); mit != factoryList->end(); ++mit ) {
163 qt_fontmanager->factories.setAutoDelete( false ); 163 qt_fontmanager->factories.setAutoDelete( false );
164 qt_fontmanager->factories.removeRef( (*mit).factory ); 164 qt_fontmanager->factories.removeRef( (*mit).factory );
165 qt_fontmanager->factories.setAutoDelete( true ); 165 qt_fontmanager->factories.setAutoDelete( true );
166 (*mit).interface->release(); 166 (*mit).interface->release();
167 (*mit).library->unload(); 167 (*mit).library->unload();
168 delete (*mit).library; 168 delete (*mit).library;
169 } 169 }
170 factoryList->clear(); 170 factoryList->clear();
171 171
172 QString path = QPEApplication::qpeDir() + "/plugins/fontfactories"; 172 QString path = QPEApplication::qpeDir() + "/plugins/fontfactories";
173#ifdef Q_OS_MACX
174 QDir dir( path, "lib*.dylib" );
175#else
173 QDir dir( path, "lib*.so" ); 176 QDir dir( path, "lib*.so" );
177#endif
174 178
175 if ( !dir.exists()) 179 if ( !dir.exists())
176 return; 180 return;
177 181
178 QStringList list = dir.entryList(); 182 QStringList list = dir.entryList();
179 QStringList::Iterator it; 183 QStringList::Iterator it;
180 for ( it = list.begin(); it != list.end(); ++it ) { 184 for ( it = list.begin(); it != list.end(); ++it ) {
181 FontFactoryInterface *iface = 0; 185 FontFactoryInterface *iface = 0;
182 QLibrary *lib = new QLibrary( path + "/" + *it ); 186 QLibrary *lib = new QLibrary( path + "/" + *it );
183 if ( lib->queryInterface( IID_FontFactory, (QUnknownInterface**)&iface ) == QS_OK ) { 187 if ( lib->queryInterface( IID_FontFactory, (QUnknownInterface**)&iface ) == QS_OK ) {
184 FontFactory factory; 188 FontFactory factory;
185 factory.library = lib; 189 factory.library = lib;
186 factory.interface = iface; 190 factory.interface = iface;
187 factory.factory = factory.interface->fontFactory(); 191 factory.factory = factory.interface->fontFactory();
188 factoryList->append( factory ); 192 factoryList->append( factory );
189 qt_fontmanager->factories.append( factory.factory ); 193 qt_fontmanager->factories.append( factory.factory );
190 readFonts( factory.factory ); 194 readFonts( factory.factory );
191 } else { 195 } else {
192 delete lib; 196 delete lib;
193 } 197 }
194 } 198 }
195#endif 199#endif
196#endif 200#endif
197} 201}
198 202
199/*! 203/*!
200 \internal 204 \internal
201*/ 205*/
202void FontDatabase::readFonts( QFontFactory *factory ) 206void FontDatabase::readFonts( QFontFactory *factory )
203{ 207{
204#ifndef QWS 208#ifndef QWS
205return; 209return;
206#else 210#else
207 // Load in font definition file 211 // Load in font definition file
208 QString fn = fontDir() + "fontdir"; 212 QString fn = fontDir() + "fontdir";
209 FILE* fontdef=fopen(fn.local8Bit(),"r"); 213 FILE* fontdef=fopen(fn.local8Bit(),"r");
210 if(!fontdef) { 214 if(!fontdef) {
211 QCString temp=fn.local8Bit(); 215 QCString temp=fn.local8Bit();
212 qWarning("Cannot find font definition file %s - is $QTDIR set correctly?", 216 qWarning("Cannot find font definition file %s - is $QTDIR set correctly?",
213 temp.data()); 217 temp.data());
214 return; 218 return;
215 } 219 }
216 char buf[200]=""; 220 char buf[200]="";
217 char name[200]=""; 221 char name[200]="";
218 char render[200]=""; 222 char render[200]="";
219 char file[200]=""; 223 char file[200]="";
220 char flags[200]=""; 224 char flags[200]="";
221 char isitalic[10]=""; 225 char isitalic[10]="";
222 fgets(buf,200,fontdef); 226 fgets(buf,200,fontdef);
223 while(!feof(fontdef)) { 227 while(!feof(fontdef)) {
224 if ( buf[0] != '#' ) { 228 if ( buf[0] != '#' ) {
225 int weight=50; 229 int weight=50;
226 int size=0; 230 int size=0;
227 flags[0]=0; 231 flags[0]=0;
228 sscanf(buf,"%s %s %s %s %d %d %s",name,file,render,isitalic,&weight,&size,flags); 232 sscanf(buf,"%s %s %s %s %d %d %s",name,file,render,isitalic,&weight,&size,flags);
229 QString filename; 233 QString filename;
230 if ( file[0] != '/' ) 234 if ( file[0] != '/' )
231 filename = fontDir(); 235 filename = fontDir();
232 filename += file; 236 filename += file;
233 if ( QFile::exists(filename) ) { 237 if ( QFile::exists(filename) ) {
234 if( factory->name() == render ) { 238 if( factory->name() == render ) {
235 QDiskFont * qdf=new QDiskFont(factory,name,isitalic[0]=='y', 239 QDiskFont * qdf=new QDiskFont(factory,name,isitalic[0]=='y',
236 weight,size,flags,filename); 240 weight,size,flags,filename);
237 qt_fontmanager->diskfonts.append(qdf); 241 qt_fontmanager->diskfonts.append(qdf);
238#if QT_VERSION >= 232 242#if QT_VERSION >= 232
239 QFontDatabase::qwsAddDiskFont( qdf ); 243 QFontDatabase::qwsAddDiskFont( qdf );
240#endif 244#endif
241 } 245 }
242 } 246 }
243 } 247 }
244 fgets(buf,200,fontdef); 248 fgets(buf,200,fontdef);
245 } 249 }
246 fclose(fontdef); 250 fclose(fontdef);
247#endif 251#endif
248} 252}
249 253
diff --git a/library/global.cpp b/library/global.cpp
index 90954fe..05d23ac 100644
--- a/library/global.cpp
+++ b/library/global.cpp
@@ -1,814 +1,818 @@
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 <qpe/qpedebug.h> 21#include <qpe/qpedebug.h>
22#include <qpe/global.h> 22#include <qpe/global.h>
23#include <qpe/qdawg.h> 23#include <qpe/qdawg.h>
24#include <qpe/qpeapplication.h> 24#include <qpe/qpeapplication.h>
25#include <qpe/resource.h> 25#include <qpe/resource.h>
26#include <qpe/storage.h> 26#include <qpe/storage.h>
27#include <qpe/applnk.h> 27#include <qpe/applnk.h>
28#include <qpe/qcopenvelope_qws.h> 28#include <qpe/qcopenvelope_qws.h>
29 29
30#include <qfile.h> 30#include <qfile.h>
31#include <qlabel.h> 31#include <qlabel.h>
32#include <qtimer.h> 32#include <qtimer.h>
33#include <qmap.h> 33#include <qmap.h>
34#include <qdict.h> 34#include <qdict.h>
35#include <qdir.h> 35#include <qdir.h>
36#include <qmessagebox.h> 36#include <qmessagebox.h>
37#include <qregexp.h> 37#include <qregexp.h>
38 38
39#include <stdlib.h> 39#include <stdlib.h>
40#include <sys/stat.h> 40#include <sys/stat.h>
41#include <sys/wait.h> 41#include <sys/wait.h>
42#include <sys/types.h> 42#include <sys/types.h>
43#include <fcntl.h> 43#include <fcntl.h>
44#include <unistd.h> 44#include <unistd.h>
45#include <errno.h> 45#include <errno.h>
46 46
47#include <qwindowsystem_qws.h> // for qwsServer 47#include <qwindowsystem_qws.h> // for qwsServer
48#include <qdatetime.h> 48#include <qdatetime.h>
49 49
50#include <qfile.h> 50#include <qfile.h>
51 51
52namespace { 52namespace {
53 // checks if the storage should be searched 53 // checks if the storage should be searched
54 bool checkStorage(const QString &path ){ // this is a small Config replacement cause config is too limited -zecke 54 bool checkStorage(const QString &path ){ // this is a small Config replacement cause config is too limited -zecke
55 QFile file(path ); 55 QFile file(path );
56 if(!file.open(IO_ReadOnly ) ) 56 if(!file.open(IO_ReadOnly ) )
57 return true; 57 return true;
58 58
59 QByteArray array = file.readAll(); 59 QByteArray array = file.readAll();
60 QStringList list = QStringList::split('\n', QString( array ) ); 60 QStringList list = QStringList::split('\n', QString( array ) );
61 for(QStringList::Iterator it = list.begin(); it != list.end(); ++it ){ 61 for(QStringList::Iterator it = list.begin(); it != list.end(); ++it ){
62 if( (*it).startsWith("autocheck = 0" ) ){ 62 if( (*it).startsWith("autocheck = 0" ) ){
63 return false; 63 return false;
64 }else if( (*it).startsWith("autocheck = 1" ) ){ 64 }else if( (*it).startsWith("autocheck = 1" ) ){
65 return true; 65 return true;
66 } 66 }
67 } 67 }
68 return true; 68 return true;
69 } 69 }
70} 70}
71 71
72//#include "quickexec_p.h" 72//#include "quickexec_p.h"
73 73
74class Emitter : public QObject { 74class Emitter : public QObject {
75 Q_OBJECT 75 Q_OBJECT
76public: 76public:
77 Emitter( QWidget* receiver, const QString& document ) 77 Emitter( QWidget* receiver, const QString& document )
78 { 78 {
79 connect(this, SIGNAL(setDocument(const QString&)), 79 connect(this, SIGNAL(setDocument(const QString&)),
80 receiver, SLOT(setDocument(const QString&))); 80 receiver, SLOT(setDocument(const QString&)));
81 emit setDocument(document); 81 emit setDocument(document);
82 disconnect(this, SIGNAL(setDocument(const QString&)), 82 disconnect(this, SIGNAL(setDocument(const QString&)),
83 receiver, SLOT(setDocument(const QString&))); 83 receiver, SLOT(setDocument(const QString&)));
84 } 84 }
85 85
86signals: 86signals:
87 void setDocument(const QString&); 87 void setDocument(const QString&);
88}; 88};
89 89
90 90
91class StartingAppList : public QObject { 91class StartingAppList : public QObject {
92 Q_OBJECT 92 Q_OBJECT
93public: 93public:
94 static void add( const QString& name ); 94 static void add( const QString& name );
95 static bool isStarting( const QString name ); 95 static bool isStarting( const QString name );
96private slots: 96private slots:
97 void handleNewChannel( const QString &); 97 void handleNewChannel( const QString &);
98private: 98private:
99 StartingAppList( QObject *parent=0, const char* name=0 ) ; 99 StartingAppList( QObject *parent=0, const char* name=0 ) ;
100 100
101 QDict<QTime> dict; 101 QDict<QTime> dict;
102 static StartingAppList *appl; 102 static StartingAppList *appl;
103}; 103};
104 104
105StartingAppList* StartingAppList::appl = 0; 105StartingAppList* StartingAppList::appl = 0;
106 106
107StartingAppList::StartingAppList( QObject *parent, const char* name ) 107StartingAppList::StartingAppList( QObject *parent, const char* name )
108 :QObject( parent, name ) 108 :QObject( parent, name )
109{ 109{
110#if QT_VERSION >= 232 && defined(QWS) 110#if QT_VERSION >= 232 && defined(QWS)
111 connect( qwsServer, SIGNAL( newChannel(const QString&)), 111 connect( qwsServer, SIGNAL( newChannel(const QString&)),
112 this, SLOT( handleNewChannel(const QString&)) ); 112 this, SLOT( handleNewChannel(const QString&)) );
113#endif 113#endif
114 dict.setAutoDelete( TRUE ); 114 dict.setAutoDelete( TRUE );
115} 115}
116 116
117void StartingAppList::add( const QString& name ) 117void StartingAppList::add( const QString& name )
118{ 118{
119#if QT_VERSION >= 232 && !defined(QT_NO_COP) 119#if QT_VERSION >= 232 && !defined(QT_NO_COP)
120 if ( !appl ) 120 if ( !appl )
121 appl = new StartingAppList; 121 appl = new StartingAppList;
122 QTime *t = new QTime; 122 QTime *t = new QTime;
123 t->start(); 123 t->start();
124 appl->dict.insert( "QPE/Application/" + name, t ); 124 appl->dict.insert( "QPE/Application/" + name, t );
125#endif 125#endif
126} 126}
127 127
128bool StartingAppList::isStarting( const QString name ) 128bool StartingAppList::isStarting( const QString name )
129{ 129{
130#if QT_VERSION >= 232 && !defined(QT_NO_COP) 130#if QT_VERSION >= 232 && !defined(QT_NO_COP)
131 if ( appl ) { 131 if ( appl ) {
132 QTime *t = appl->dict.find( "QPE/Application/" + name ); 132 QTime *t = appl->dict.find( "QPE/Application/" + name );
133 if ( !t ) 133 if ( !t )
134 return FALSE; 134 return FALSE;
135 if ( t->elapsed() > 10000 ) { 135 if ( t->elapsed() > 10000 ) {
136 // timeout in case of crash or something 136 // timeout in case of crash or something
137 appl->dict.remove( "QPE/Application/" + name ); 137 appl->dict.remove( "QPE/Application/" + name );
138 return FALSE; 138 return FALSE;
139 } 139 }
140 return TRUE; 140 return TRUE;
141 } 141 }
142#endif 142#endif
143 return FALSE; 143 return FALSE;
144} 144}
145 145
146void StartingAppList::handleNewChannel( const QString & name ) 146void StartingAppList::handleNewChannel( const QString & name )
147{ 147{
148#if QT_VERSION >= 232 && !defined(QT_NO_COP) 148#if QT_VERSION >= 232 && !defined(QT_NO_COP)
149 dict.remove( name ); 149 dict.remove( name );
150#endif 150#endif
151} 151}
152 152
153static bool docDirCreated = FALSE; 153static bool docDirCreated = FALSE;
154static QDawg* fixed_dawg = 0; 154static QDawg* fixed_dawg = 0;
155static QDict<QDawg> *named_dawg = 0; 155static QDict<QDawg> *named_dawg = 0;
156 156
157static QString qpeDir() 157static QString qpeDir()
158{ 158{
159 QString dir = getenv("OPIEDIR"); 159 QString dir = getenv("OPIEDIR");
160 if ( dir.isEmpty() ) dir = ".."; 160 if ( dir.isEmpty() ) dir = "..";
161 return dir; 161 return dir;
162} 162}
163 163
164static QString dictDir() 164static QString dictDir()
165{ 165{
166 return qpeDir() + "/etc/dict"; 166 return qpeDir() + "/etc/dict";
167} 167}
168 168
169/*! 169/*!
170 \class Global global.h 170 \class Global global.h
171 \brief The Global class provides application-wide global functions. 171 \brief The Global class provides application-wide global functions.
172 172
173 The Global functions are grouped as follows: 173 The Global functions are grouped as follows:
174 \tableofcontents 174 \tableofcontents
175 175
176 \section1 User Interface 176 \section1 User Interface
177 177
178 The statusMessage() function provides short-duration messages to the 178 The statusMessage() function provides short-duration messages to the
179 user. The showInputMethod() function shows the current input method, 179 user. The showInputMethod() function shows the current input method,
180 and hideInputMethod() hides the input method. 180 and hideInputMethod() hides the input method.
181 181
182 \section1 Document related 182 \section1 Document related
183 183
184 The findDocuments() function creates a set of \link doclnk.html 184 The findDocuments() function creates a set of \link doclnk.html
185 DocLnk\endlink objects in a particular folder. 185 DocLnk\endlink objects in a particular folder.
186 186
187 \section1 Filesystem related 187 \section1 Filesystem related
188 188
189 Global provides an applicationFileName() function that returns the 189 Global provides an applicationFileName() function that returns the
190 full path of an application-specific file. 190 full path of an application-specific file.
191 191
192 The execute() function runs an application. 192 The execute() function runs an application.
193 193
194 \section1 Word list related 194 \section1 Word list related
195 195
196 A list of words relevant to the current locale is maintained by the 196 A list of words relevant to the current locale is maintained by the
197 system. The list is held in a \link qdawg.html DAWG\endlink 197 system. The list is held in a \link qdawg.html DAWG\endlink
198 (implemented by the QDawg class). This list is used, for example, by 198 (implemented by the QDawg class). This list is used, for example, by
199 the pickboard input method. 199 the pickboard input method.
200 200
201 The global QDawg is returned by fixedDawg(); this cannot be updated. 201 The global QDawg is returned by fixedDawg(); this cannot be updated.
202 An updatable copy of the global QDawg is returned by addedDawg(). 202 An updatable copy of the global QDawg is returned by addedDawg().
203 Applications may have their own word lists stored in \l{QDawg}s 203 Applications may have their own word lists stored in \l{QDawg}s
204 which are returned by dawg(). Use addWords() to add words to the 204 which are returned by dawg(). Use addWords() to add words to the
205 updateable copy of the global QDawg or to named application 205 updateable copy of the global QDawg or to named application
206 \l{QDawg}s. 206 \l{QDawg}s.
207 207
208 \section1 Quoting 208 \section1 Quoting
209 209
210 The shellQuote() function quotes a string suitable for passing to a 210 The shellQuote() function quotes a string suitable for passing to a
211 shell. The stringQuote() function backslash escapes '\' and '"' 211 shell. The stringQuote() function backslash escapes '\' and '"'
212 characters. 212 characters.
213 213
214 \section1 Hardware 214 \section1 Hardware
215 215
216 The implementation of the writeHWClock() function depends on the AlarmServer 216 The implementation of the writeHWClock() function depends on the AlarmServer
217 implementation. If the AlarmServer is using atd the clock will be synced to 217 implementation. If the AlarmServer is using atd the clock will be synced to
218 hardware. If opie-alarm is used the hardware clock will be synced before 218 hardware. If opie-alarm is used the hardware clock will be synced before
219 suspending the device. opie-alarm is used by iPAQ and Zaurii implementation 219 suspending the device. opie-alarm is used by iPAQ and Zaurii implementation
220 220
221 \ingroup qtopiaemb 221 \ingroup qtopiaemb
222*/ 222*/
223 223
224/*! 224/*!
225 \internal 225 \internal
226*/ 226*/
227Global::Global() 227Global::Global()
228{ 228{
229} 229}
230 230
231/*! 231/*!
232 Returns the unchangeable QDawg that contains general 232 Returns the unchangeable QDawg that contains general
233 words for the current locale. 233 words for the current locale.
234 234
235 \sa addedDawg() 235 \sa addedDawg()
236*/ 236*/
237const QDawg& Global::fixedDawg() 237const QDawg& Global::fixedDawg()
238{ 238{
239 if ( !fixed_dawg ) { 239 if ( !fixed_dawg ) {
240 if ( !docDirCreated ) 240 if ( !docDirCreated )
241 createDocDir(); 241 createDocDir();
242 242
243 fixed_dawg = new QDawg; 243 fixed_dawg = new QDawg;
244 QString dawgfilename = dictDir() + "/dawg"; 244 QString dawgfilename = dictDir() + "/dawg";
245 QString words_lang; 245 QString words_lang;
246 QStringList langs = Global::languageList(); 246 QStringList langs = Global::languageList();
247 for (QStringList::ConstIterator it = langs.begin(); it!=langs.end(); ++it) { 247 for (QStringList::ConstIterator it = langs.begin(); it!=langs.end(); ++it) {
248 QString lang = *it; 248 QString lang = *it;
249 words_lang = dictDir() + "/words." + lang; 249 words_lang = dictDir() + "/words." + lang;
250 QString dawgfilename_lang = dawgfilename + "." + lang; 250 QString dawgfilename_lang = dawgfilename + "." + lang;
251 if ( QFile::exists(dawgfilename_lang) || 251 if ( QFile::exists(dawgfilename_lang) ||
252 QFile::exists(words_lang) ) { 252 QFile::exists(words_lang) ) {
253 dawgfilename = dawgfilename_lang; 253 dawgfilename = dawgfilename_lang;
254 break; 254 break;
255 } 255 }
256 } 256 }
257 QFile dawgfile(dawgfilename); 257 QFile dawgfile(dawgfilename);
258 258
259 if ( !dawgfile.exists() ) { 259 if ( !dawgfile.exists() ) {
260 QString fn = dictDir() + "/words"; 260 QString fn = dictDir() + "/words";
261 if ( QFile::exists(words_lang) ) 261 if ( QFile::exists(words_lang) )
262 fn = words_lang; 262 fn = words_lang;
263 QFile in(fn); 263 QFile in(fn);
264 if ( in.open(IO_ReadOnly) ) { 264 if ( in.open(IO_ReadOnly) ) {
265 fixed_dawg->createFromWords(&in); 265 fixed_dawg->createFromWords(&in);
266 dawgfile.open(IO_WriteOnly); 266 dawgfile.open(IO_WriteOnly);
267 fixed_dawg->write(&dawgfile); 267 fixed_dawg->write(&dawgfile);
268 dawgfile.close(); 268 dawgfile.close();
269 } 269 }
270 } else { 270 } else {
271 fixed_dawg->readFile(dawgfilename); 271 fixed_dawg->readFile(dawgfilename);
272 } 272 }
273 } 273 }
274 274
275 return *fixed_dawg; 275 return *fixed_dawg;
276} 276}
277 277
278/*! 278/*!
279 Returns the changeable QDawg that contains general 279 Returns the changeable QDawg that contains general
280 words for the current locale. 280 words for the current locale.
281 281
282 \sa fixedDawg() 282 \sa fixedDawg()
283*/ 283*/
284const QDawg& Global::addedDawg() 284const QDawg& Global::addedDawg()
285{ 285{
286 return dawg("local"); 286 return dawg("local");
287} 287}
288 288
289/*! 289/*!
290 Returns the QDawg with the given \a name. 290 Returns the QDawg with the given \a name.
291 This is an application-specific word list. 291 This is an application-specific word list.
292 292
293 \a name should not contain "/". 293 \a name should not contain "/".
294*/ 294*/
295const QDawg& Global::dawg(const QString& name) 295const QDawg& Global::dawg(const QString& name)
296{ 296{
297 createDocDir(); 297 createDocDir();
298 if ( !named_dawg ) 298 if ( !named_dawg )
299 named_dawg = new QDict<QDawg>; 299 named_dawg = new QDict<QDawg>;
300 QDawg* r = named_dawg->find(name); 300 QDawg* r = named_dawg->find(name);
301 if ( !r ) { 301 if ( !r ) {
302 r = new QDawg; 302 r = new QDawg;
303 named_dawg->insert(name,r); 303 named_dawg->insert(name,r);
304 QString dawgfilename = applicationFileName("Dictionary", name ) + ".dawg"; 304 QString dawgfilename = applicationFileName("Dictionary", name ) + ".dawg";
305 QFile dawgfile(dawgfilename); 305 QFile dawgfile(dawgfilename);
306 if ( dawgfile.open(IO_ReadOnly) ) 306 if ( dawgfile.open(IO_ReadOnly) )
307 r->readFile(dawgfilename); 307 r->readFile(dawgfilename);
308 } 308 }
309 return *r; 309 return *r;
310} 310}
311 311
312/*! 312/*!
313 \overload 313 \overload
314 Adds \a wordlist to the addedDawg(). 314 Adds \a wordlist to the addedDawg().
315 315
316 Note that the addition of words persists between program executions 316 Note that the addition of words persists between program executions
317 (they are saved in the dictionary files), so you should confirm the 317 (they are saved in the dictionary files), so you should confirm the
318 words with the user before adding them. 318 words with the user before adding them.
319*/ 319*/
320void Global::addWords(const QStringList& wordlist) 320void Global::addWords(const QStringList& wordlist)
321{ 321{
322 addWords("local",wordlist); 322 addWords("local",wordlist);
323} 323}
324 324
325/*! 325/*!
326 \overload 326 \overload
327 Adds \a wordlist to the addedDawg(). 327 Adds \a wordlist to the addedDawg().
328 328
329 Note that the addition of words persists between program executions 329 Note that the addition of words persists between program executions
330 (they are saved in the dictionary files), so you should confirm the 330 (they are saved in the dictionary files), so you should confirm the
331 words with the user before adding them. 331 words with the user before adding them.
332*/ 332*/
333void Global::addWords(const QString& dictname, const QStringList& wordlist) 333void Global::addWords(const QString& dictname, const QStringList& wordlist)
334{ 334{
335 QDawg& d = (QDawg&)dawg(dictname); 335 QDawg& d = (QDawg&)dawg(dictname);
336 QStringList all = d.allWords() + wordlist; 336 QStringList all = d.allWords() + wordlist;
337 d.createFromWords(all); 337 d.createFromWords(all);
338 338
339 QString dawgfilename = applicationFileName("Dictionary", dictname) + ".dawg"; 339 QString dawgfilename = applicationFileName("Dictionary", dictname) + ".dawg";
340 QFile dawgfile(dawgfilename); 340 QFile dawgfile(dawgfilename);
341 if ( dawgfile.open(IO_WriteOnly) ) { 341 if ( dawgfile.open(IO_WriteOnly) ) {
342 d.write(&dawgfile); 342 d.write(&dawgfile);
343 dawgfile.close(); 343 dawgfile.close();
344 } 344 }
345 345
346 // #### Re-read the dawg here if we use mmap(). 346 // #### Re-read the dawg here if we use mmap().
347 347
348 // #### Signal other processes to re-read. 348 // #### Signal other processes to re-read.
349} 349}
350 350
351 351
352/*! 352/*!
353 Returns the full path for the application called \a appname, with the 353 Returns the full path for the application called \a appname, with the
354 given \a filename. Returns QString::null if there was a problem creating 354 given \a filename. Returns QString::null if there was a problem creating
355 the directory tree for \a appname. 355 the directory tree for \a appname.
356 If \a filename contains "/", it is the caller's responsibility to 356 If \a filename contains "/", it is the caller's responsibility to
357 ensure that those directories exist. 357 ensure that those directories exist.
358*/ 358*/
359QString Global::applicationFileName(const QString& appname, const QString& filename) 359QString Global::applicationFileName(const QString& appname, const QString& filename)
360{ 360{
361 QDir d; 361 QDir d;
362 QString r = getenv("HOME"); 362 QString r = getenv("HOME");
363 r += "/Applications/"; 363 r += "/Applications/";
364 if ( !QFile::exists( r ) ) 364 if ( !QFile::exists( r ) )
365 if ( d.mkdir(r) == false ) 365 if ( d.mkdir(r) == false )
366 return QString::null; 366 return QString::null;
367 r += appname; 367 r += appname;
368 if ( !QFile::exists( r ) ) 368 if ( !QFile::exists( r ) )
369 if ( d.mkdir(r) == false ) 369 if ( d.mkdir(r) == false )
370 return QString::null; 370 return QString::null;
371 r += "/"; r += filename; 371 r += "/"; r += filename;
372 return r; 372 return r;
373} 373}
374 374
375/*! 375/*!
376 \internal 376 \internal
377*/ 377*/
378void Global::createDocDir() 378void Global::createDocDir()
379{ 379{
380 if ( !docDirCreated ) { 380 if ( !docDirCreated ) {
381 docDirCreated = TRUE; 381 docDirCreated = TRUE;
382 mkdir( QPEApplication::documentDir().latin1(), 0755 ); 382 mkdir( QPEApplication::documentDir().latin1(), 0755 );
383 } 383 }
384} 384}
385 385
386 386
387/*! 387/*!
388 Displays a status \a message to the user. This usually appears 388 Displays a status \a message to the user. This usually appears
389 in the taskbar for a short amount of time, then disappears. 389 in the taskbar for a short amount of time, then disappears.
390*/ 390*/
391void Global::statusMessage(const QString& message) 391void Global::statusMessage(const QString& message)
392{ 392{
393#if !defined(QT_NO_COP) 393#if !defined(QT_NO_COP)
394 QCopEnvelope e( "QPE/TaskBar", "message(QString)" ); 394 QCopEnvelope e( "QPE/TaskBar", "message(QString)" );
395 e << message; 395 e << message;
396#endif 396#endif
397} 397}
398 398
399/*! 399/*!
400 \internal 400 \internal
401*/ 401*/
402void Global::applyStyle() 402void Global::applyStyle()
403{ 403{
404#if !defined(QT_NO_COP) 404#if !defined(QT_NO_COP)
405 QCopChannel::send( "QPE/System", "applyStyle()" ); 405 QCopChannel::send( "QPE/System", "applyStyle()" );
406#else 406#else
407 ((QPEApplication *)qApp)->applyStyle(); // apply without needing QCop for floppy version 407 ((QPEApplication *)qApp)->applyStyle(); // apply without needing QCop for floppy version
408#endif 408#endif
409} 409}
410 410
411/*! 411/*!
412 \internal 412 \internal
413*/ 413*/
414QWidget *Global::shutdown( bool ) 414QWidget *Global::shutdown( bool )
415{ 415{
416#if !defined(QT_NO_COP) 416#if !defined(QT_NO_COP)
417 QCopChannel::send( "QPE/System", "shutdown()" ); 417 QCopChannel::send( "QPE/System", "shutdown()" );
418#endif 418#endif
419 return 0; 419 return 0;
420} 420}
421 421
422/*! 422/*!
423 \internal 423 \internal
424*/ 424*/
425QWidget *Global::restart( bool ) 425QWidget *Global::restart( bool )
426{ 426{
427#if !defined(QT_NO_COP) 427#if !defined(QT_NO_COP)
428 QCopChannel::send( "QPE/System", "restart()" ); 428 QCopChannel::send( "QPE/System", "restart()" );
429#endif 429#endif
430 return 0; 430 return 0;
431} 431}
432 432
433/*! 433/*!
434 Explicitly show the current input method. 434 Explicitly show the current input method.
435 435
436 Input methods are indicated in the taskbar by a small icon. If the 436 Input methods are indicated in the taskbar by a small icon. If the
437 input method is activated (shown) then it takes up some proportion 437 input method is activated (shown) then it takes up some proportion
438 of the bottom of the screen, to allow the user to interact (input 438 of the bottom of the screen, to allow the user to interact (input
439 characters) with it. 439 characters) with it.
440 440
441 \sa hideInputMethod() 441 \sa hideInputMethod()
442*/ 442*/
443void Global::showInputMethod() 443void Global::showInputMethod()
444{ 444{
445#if !defined(QT_NO_COP) 445#if !defined(QT_NO_COP)
446 QCopChannel::send( "QPE/TaskBar", "showInputMethod()" ); 446 QCopChannel::send( "QPE/TaskBar", "showInputMethod()" );
447#endif 447#endif
448} 448}
449 449
450/*! 450/*!
451 Explicitly hide the current input method. 451 Explicitly hide the current input method.
452 452
453 The current input method is still indicated in the taskbar, but no 453 The current input method is still indicated in the taskbar, but no
454 longer takes up screen space, and can no longer be interacted with. 454 longer takes up screen space, and can no longer be interacted with.
455 455
456 \sa showInputMethod() 456 \sa showInputMethod()
457*/ 457*/
458void Global::hideInputMethod() 458void Global::hideInputMethod()
459{ 459{
460#if !defined(QT_NO_COP) 460#if !defined(QT_NO_COP)
461 QCopChannel::send( "QPE/TaskBar", "hideInputMethod()" ); 461 QCopChannel::send( "QPE/TaskBar", "hideInputMethod()" );
462#endif 462#endif
463} 463}
464 464
465 465
466/*! 466/*!
467 \internal 467 \internal
468*/ 468*/
469bool Global::isBuiltinCommand( const QString &name ) 469bool Global::isBuiltinCommand( const QString &name )
470{ 470{
471 if(!builtin) 471 if(!builtin)
472 return FALSE; // yes, it can happen 472 return FALSE; // yes, it can happen
473 for (int i = 0; builtin[i].file; i++) { 473 for (int i = 0; builtin[i].file; i++) {
474 if ( builtin[i].file == name ) { 474 if ( builtin[i].file == name ) {
475 return TRUE; 475 return TRUE;
476 } 476 }
477 } 477 }
478 return FALSE; 478 return FALSE;
479} 479}
480 480
481Global::Command* Global::builtin=0; 481Global::Command* Global::builtin=0;
482QGuardedPtr<QWidget> *Global::running=0; 482QGuardedPtr<QWidget> *Global::running=0;
483 483
484/*! 484/*!
485 \class Global::Command 485 \class Global::Command
486 \brief The Global::Command class is internal. 486 \brief The Global::Command class is internal.
487 \internal 487 \internal
488*/ 488*/
489 489
490/*! 490/*!
491 \internal 491 \internal
492*/ 492*/
493void Global::setBuiltinCommands( Command* list ) 493void Global::setBuiltinCommands( Command* list )
494{ 494{
495 if ( running ) 495 if ( running )
496 delete [] running; 496 delete [] running;
497 497
498 builtin = list; 498 builtin = list;
499 int count = 0; 499 int count = 0;
500 if (!builtin) 500 if (!builtin)
501 return; 501 return;
502 while ( builtin[count].file ) 502 while ( builtin[count].file )
503 count++; 503 count++;
504 504
505 running = new QGuardedPtr<QWidget> [ count ]; 505 running = new QGuardedPtr<QWidget> [ count ];
506} 506}
507 507
508/*! 508/*!
509 \internal 509 \internal
510*/ 510*/
511void Global::setDocument( QWidget* receiver, const QString& document ) 511void Global::setDocument( QWidget* receiver, const QString& document )
512{ 512{
513 Emitter emitter(receiver,document); 513 Emitter emitter(receiver,document);
514} 514}
515 515
516/*! 516/*!
517 \internal 517 \internal
518*/ 518*/
519bool Global::terminateBuiltin( const QString& n ) 519bool Global::terminateBuiltin( const QString& n )
520{ 520{
521 if (!builtin) 521 if (!builtin)
522 return FALSE; 522 return FALSE;
523 for (int i = 0; builtin[i].file; i++) { 523 for (int i = 0; builtin[i].file; i++) {
524 if ( builtin[i].file == n ) { 524 if ( builtin[i].file == n ) {
525 delete running[i]; 525 delete running[i];
526 return TRUE; 526 return TRUE;
527 } 527 }
528 } 528 }
529 return FALSE; 529 return FALSE;
530} 530}
531 531
532/*! 532/*!
533 \internal 533 \internal
534*/ 534*/
535void Global::terminate( const AppLnk* app ) 535void Global::terminate( const AppLnk* app )
536{ 536{
537 //if ( terminateBuiltin(app->exec()) ) return; // maybe? haven't tried this 537 //if ( terminateBuiltin(app->exec()) ) return; // maybe? haven't tried this
538 538
539#ifndef QT_NO_COP 539#ifndef QT_NO_COP
540 QCString channel = "QPE/Application/" + app->exec().utf8(); 540 QCString channel = "QPE/Application/" + app->exec().utf8();
541 if ( QCopChannel::isRegistered(channel) ) { 541 if ( QCopChannel::isRegistered(channel) ) {
542 QCopEnvelope e(channel, "quit()"); 542 QCopEnvelope e(channel, "quit()");
543 } 543 }
544#endif 544#endif
545} 545}
546 546
547/*! 547/*!
548 Low-level function to run command \a c. 548 Low-level function to run command \a c.
549 549
550 \warning Do not use this function. Use execute instead. 550 \warning Do not use this function. Use execute instead.
551 551
552 \sa execute() 552 \sa execute()
553*/ 553*/
554void Global::invoke(const QString &c) 554void Global::invoke(const QString &c)
555{ 555{
556 // Convert the command line in to a list of arguments 556 // Convert the command line in to a list of arguments
557 QStringList list = QStringList::split(QRegExp(" *"),c); 557 QStringList list = QStringList::split(QRegExp(" *"),c);
558 558
559#if !defined(QT_NO_COP) 559#if !defined(QT_NO_COP)
560 QString ap=list[0]; 560 QString ap=list[0];
561 // see if the application is already running 561 // see if the application is already running
562 // XXX should lock file /tmp/qcop-msg-ap 562 // XXX should lock file /tmp/qcop-msg-ap
563 if ( QCopChannel::isRegistered( ("QPE/Application/" + ap).latin1() ) ) { 563 if ( QCopChannel::isRegistered( ("QPE/Application/" + ap).latin1() ) ) {
564 // If the channel is already register, the app is already running, so show it. 564 // If the channel is already register, the app is already running, so show it.
565 { QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "raise()" ); } 565 { QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "raise()" ); }
566 566
567 //QCopEnvelope e("QPE/System", "notBusy(QString)" ); 567 //QCopEnvelope e("QPE/System", "notBusy(QString)" );
568 //e << ap; 568 //e << ap;
569 return; 569 return;
570 } 570 }
571 // XXX should unlock file /tmp/qcop-msg-ap 571 // XXX should unlock file /tmp/qcop-msg-ap
572 //see if it is being started 572 //see if it is being started
573 if ( StartingAppList::isStarting( ap ) ) { 573 if ( StartingAppList::isStarting( ap ) ) {
574 // FIXME take it out for now, since it leads to a much to short showing of wait if 574 // FIXME take it out for now, since it leads to a much to short showing of wait if
575 // some entry is clicked. 575 // some entry is clicked.
576 // Real cause is that ::execute is called twice for document tab. But it would need some larger changes 576 // Real cause is that ::execute is called twice for document tab. But it would need some larger changes
577 // to fix that, and with future syncs with qtopia 1.6 it will change anyway big time since somebody there 577 // to fix that, and with future syncs with qtopia 1.6 it will change anyway big time since somebody there
578 // had the idea that an apploader belongs to the launcher ... 578 // had the idea that an apploader belongs to the launcher ...
579 //QCopEnvelope e("QPE/System", "notBusy(QString)" ); 579 //QCopEnvelope e("QPE/System", "notBusy(QString)" );
580 //e << ap; 580 //e << ap;
581 return; 581 return;
582 } 582 }
583 583
584#endif 584#endif
585 585
586#ifdef QT_NO_QWS_MULTIPROCESS 586#ifdef QT_NO_QWS_MULTIPROCESS
587 QMessageBox::warning( 0, "Error", "Could not find the application " + c, "Ok", 0, 0, 0, 1 ); 587 QMessageBox::warning( 0, "Error", "Could not find the application " + c, "Ok", 0, 0, 0, 1 );
588#else 588#else
589 589
590 QStrList slist; 590 QStrList slist;
591 unsigned int j; 591 unsigned int j;
592 for ( j = 0; j < list.count(); j++ ) 592 for ( j = 0; j < list.count(); j++ )
593 slist.append( list[j].utf8() ); 593 slist.append( list[j].utf8() );
594 594
595 const char **args = new (const char *)[slist.count() + 1]; 595 const char **args = new (const char *)[slist.count() + 1];
596 for ( j = 0; j < slist.count(); j++ ) 596 for ( j = 0; j < slist.count(); j++ )
597 args[j] = slist.at(j); 597 args[j] = slist.at(j);
598 args[j] = NULL; 598 args[j] = NULL;
599 599
600#if !defined(QT_NO_COP) 600#if !defined(QT_NO_COP)
601 // an attempt to show a wait... 601 // an attempt to show a wait...
602 // more logic should be used, but this will be fine for the moment... 602 // more logic should be used, but this will be fine for the moment...
603 QCopEnvelope ( "QPE/System", "busy()" ); 603 QCopEnvelope ( "QPE/System", "busy()" );
604#endif 604#endif
605 605
606#ifdef HAVE_QUICKEXEC 606#ifdef HAVE_QUICKEXEC
607#ifdef Q_OS_MACX
608 QString libexe = qpeDir()+"/binlib/lib"+args[0] + ".dylib";
609#else
607 QString libexe = qpeDir()+"/binlib/lib"+args[0] + ".so"; 610 QString libexe = qpeDir()+"/binlib/lib"+args[0] + ".so";
611#endif
608 qDebug("libfile = %s", libexe.latin1() ); 612 qDebug("libfile = %s", libexe.latin1() );
609 if ( QFile::exists( libexe ) ) { 613 if ( QFile::exists( libexe ) ) {
610 qDebug("calling quickexec %s", libexe.latin1() ); 614 qDebug("calling quickexec %s", libexe.latin1() );
611 quickexecv( libexe.utf8().data(), (const char **)args ); 615 quickexecv( libexe.utf8().data(), (const char **)args );
612 } else 616 } else
613#endif 617#endif
614 { 618 {
615 bool success = false; 619 bool success = false;
616 int pfd [2]; 620 int pfd [2];
617 if ( ::pipe ( pfd ) < 0 ) 621 if ( ::pipe ( pfd ) < 0 )
618 pfd [0] = pfd [1] = -1; 622 pfd [0] = pfd [1] = -1;
619 623
620 pid_t pid = ::fork ( ); 624 pid_t pid = ::fork ( );
621 625
622 if ( pid == 0 ) { // child 626 if ( pid == 0 ) { // child
623 for ( int fd = 3; fd < 100; fd++ ) { 627 for ( int fd = 3; fd < 100; fd++ ) {
624 if ( fd != pfd [1] ) 628 if ( fd != pfd [1] )
625 ::close ( fd ); 629 ::close ( fd );
626 } 630 }
627 ::setpgid ( ::getpid ( ), ::getppid ( )); 631 ::setpgid ( ::getpid ( ), ::getppid ( ));
628 632
629 // Closing of fd[1] indicates that the execvp succeeded! 633 // Closing of fd[1] indicates that the execvp succeeded!
630 if ( pfd [1] >= 0 ) 634 if ( pfd [1] >= 0 )
631 ::fcntl ( pfd [1], F_SETFD, FD_CLOEXEC ); 635 ::fcntl ( pfd [1], F_SETFD, FD_CLOEXEC );
632 636
633 // Try bindir first, so that foo/bar works too 637 // Try bindir first, so that foo/bar works too
634 ::execv ( qpeDir ( ) + "/bin/" + args [0], (char * const *) args ); 638 ::execv ( qpeDir ( ) + "/bin/" + args [0], (char * const *) args );
635 ::execvp ( args [0], (char * const *) args ); 639 ::execvp ( args [0], (char * const *) args );
636 640
637 char resultByte = 1; 641 char resultByte = 1;
638 if ( pfd [1] >= 0 ) 642 if ( pfd [1] >= 0 )
639 ::write ( pfd [1], &resultByte, 1 ); 643 ::write ( pfd [1], &resultByte, 1 );
640 ::_exit ( -1 ); 644 ::_exit ( -1 );
641 } 645 }
642 else if ( pid > 0 ) { 646 else if ( pid > 0 ) {
643 success = true; 647 success = true;
644 648
645 if ( pfd [1] >= 0 ) 649 if ( pfd [1] >= 0 )
646 ::close ( pfd [1] ); 650 ::close ( pfd [1] );
647 if ( pfd [0] >= 0 ) { 651 if ( pfd [0] >= 0 ) {
648 while ( true ) { 652 while ( true ) {
649 char resultByte; 653 char resultByte;
650 int n = ::read ( pfd [0], &resultByte, 1 ); 654 int n = ::read ( pfd [0], &resultByte, 1 );
651 if ( n == 1 ) { 655 if ( n == 1 ) {
652 success = false; 656 success = false;
653 break; 657 break;
654 } 658 }
655 if (( n == -1 ) && (( errno == ECHILD ) || ( errno == EINTR ))) 659 if (( n == -1 ) && (( errno == ECHILD ) || ( errno == EINTR )))
656 continue; 660 continue;
657 661
658 break; // success 662 break; // success
659 } 663 }
660 ::close ( pfd [0] ); 664 ::close ( pfd [0] );
661 } 665 }
662 } 666 }
663 if ( success ) 667 if ( success )
664 StartingAppList::add( list[0] ); 668 StartingAppList::add( list[0] );
665 else 669 else
666 QMessageBox::warning( 0, "Error", "Could not start the application " + c, "Ok", 0, 0, 0, 1 ); 670 QMessageBox::warning( 0, "Error", "Could not start the application " + c, "Ok", 0, 0, 0, 1 );
667 } 671 }
668#endif //QT_NO_QWS_MULTIPROCESS 672#endif //QT_NO_QWS_MULTIPROCESS
669} 673}
670 674
671 675
672/*! 676/*!
673 Executes the application identfied by \a c, passing \a 677 Executes the application identfied by \a c, passing \a
674 document if it isn't null. 678 document if it isn't null.
675 679
676 Note that a better approach might be to send a QCop message to the 680 Note that a better approach might be to send a QCop message to the
677 application's QPE/Application/\e{appname} channel. 681 application's QPE/Application/\e{appname} channel.
678*/ 682*/
679void Global::execute( const QString &c, const QString& document ) 683void Global::execute( const QString &c, const QString& document )
680{ 684{
681 // ask the server to do the work 685 // ask the server to do the work
682#if !defined(QT_NO_COP) 686#if !defined(QT_NO_COP)
683 if ( document.isNull() ) { 687 if ( document.isNull() ) {
684 QCopEnvelope e( "QPE/System", "execute(QString)" ); 688 QCopEnvelope e( "QPE/System", "execute(QString)" );
685 e << c; 689 e << c;
686 } else { 690 } else {
687 QCopEnvelope e( "QPE/System", "execute(QString,QString)" ); 691 QCopEnvelope e( "QPE/System", "execute(QString,QString)" );
688 e << c << document; 692 e << c << document;
689 } 693 }
690#endif 694#endif
691 return; 695 return;
692} 696}
693 697
694/*! 698/*!
695 Returns the string \a s with the characters '\', '"', and '$' quoted 699 Returns the string \a s with the characters '\', '"', and '$' quoted
696 by a preceeding '\'. 700 by a preceeding '\'.
697 701
698 \sa stringQuote() 702 \sa stringQuote()
699*/ 703*/
700QString Global::shellQuote(const QString& s) 704QString Global::shellQuote(const QString& s)
701{ 705{
702 QString r="\""; 706 QString r="\"";
703 for (int i=0; i<(int)s.length(); i++) { 707 for (int i=0; i<(int)s.length(); i++) {
704 char c = s[i].latin1(); 708 char c = s[i].latin1();
705 switch (c) { 709 switch (c) {
706 case '\\': case '"': case '$': 710 case '\\': case '"': case '$':
707 r+="\\"; 711 r+="\\";
708 } 712 }
709 r += s[i]; 713 r += s[i];
710 } 714 }
711 r += "\""; 715 r += "\"";
712 return r; 716 return r;
713} 717}
714 718
715/*! 719/*!
716 Returns the string \a s with the characters '\' and '"' quoted by a 720 Returns the string \a s with the characters '\' and '"' quoted by a
717 preceeding '\'. 721 preceeding '\'.
718 722
719 \sa shellQuote() 723 \sa shellQuote()
720*/ 724*/
721QString Global::stringQuote(const QString& s) 725QString Global::stringQuote(const QString& s)
722{ 726{
723 QString r="\""; 727 QString r="\"";
724 for (int i=0; i<(int)s.length(); i++) { 728 for (int i=0; i<(int)s.length(); i++) {
725 char c = s[i].latin1(); 729 char c = s[i].latin1();
726 switch (c) { 730 switch (c) {
727 case '\\': case '"': 731 case '\\': case '"':
728 r+="\\"; 732 r+="\\";
729 } 733 }
730 r += s[i]; 734 r += s[i];
731 } 735 }
732 r += "\""; 736 r += "\"";
733 return r; 737 return r;
734} 738}
735 739
736/*! 740/*!
737 Finds all documents on the system's document directories which 741 Finds all documents on the system's document directories which
738 match the filter \a mimefilter, and appends the resulting DocLnk 742 match the filter \a mimefilter, and appends the resulting DocLnk
739 objects to \a folder. 743 objects to \a folder.
740*/ 744*/
741void Global::findDocuments(DocLnkSet* folder, const QString &mimefilter) 745void Global::findDocuments(DocLnkSet* folder, const QString &mimefilter)
742{ 746{
743 QString homedocs = QString(getenv("HOME")) + "/Documents"; 747 QString homedocs = QString(getenv("HOME")) + "/Documents";
744 DocLnkSet d(homedocs,mimefilter); 748 DocLnkSet d(homedocs,mimefilter);
745 folder->appendFrom(d); 749 folder->appendFrom(d);
746 /** let's do intellegint way of searching these files 750 /** let's do intellegint way of searching these files
747 * a) the user don't want to check mediums global 751 * a) the user don't want to check mediums global
748 * b) the user wants to check but use the global options for it 752 * b) the user wants to check but use the global options for it
749 * c) the user wants to check it but not this medium 753 * c) the user wants to check it but not this medium
750 * d) the user wants to check and this medium as well 754 * d) the user wants to check and this medium as well
751 * 755 *
752 * In all cases we need to apply a different mimefilter to 756 * In all cases we need to apply a different mimefilter to
753 * the medium. 757 * the medium.
754 * a) mimefilter.isEmpty() we need to apply the responding filter 758 * a) mimefilter.isEmpty() we need to apply the responding filter
755 * either the global or the one on the medium 759 * either the global or the one on the medium
756 * 760 *
757 * b) mimefilter is set to an application we need to find out if the 761 * b) mimefilter is set to an application we need to find out if the
758 * mimetypes are included in the mime mask of the medium 762 * mimetypes are included in the mime mask of the medium
759 */ 763 */
760 StorageInfo storage; 764 StorageInfo storage;
761 const QList<FileSystem> &fs = storage.fileSystems(); 765 const QList<FileSystem> &fs = storage.fileSystems();
762 QListIterator<FileSystem> it ( fs ); 766 QListIterator<FileSystem> it ( fs );
763 for ( ; it.current(); ++it ) { 767 for ( ; it.current(); ++it ) {
764 if ( (*it)->isRemovable() ) { // let's find out if we should search on it 768 if ( (*it)->isRemovable() ) { // let's find out if we should search on it
765 // this is a candidate look at the cf and see if we should search on it 769 // this is a candidate look at the cf and see if we should search on it
766 QString path = (*it)->path(); 770 QString path = (*it)->path();
767 if( !checkStorage((*it)->path() + "/.opiestorage.cf" ) ) 771 if( !checkStorage((*it)->path() + "/.opiestorage.cf" ) )
768 continue; 772 continue;
769 DocLnkSet ide( path, mimefilter ); 773 DocLnkSet ide( path, mimefilter );
770 folder->appendFrom(ide); 774 folder->appendFrom(ide);
771 } else if ( (*it)->disk() == "/dev/mtdblock6" || (*it)->disk() == "tmpfs" ) { 775 } else if ( (*it)->disk() == "/dev/mtdblock6" || (*it)->disk() == "tmpfs" ) {
772 QString path = (*it)->path() + "/Documents"; 776 QString path = (*it)->path() + "/Documents";
773 DocLnkSet ide( path, mimefilter ); 777 DocLnkSet ide( path, mimefilter );
774 folder->appendFrom(ide); 778 folder->appendFrom(ide);
775 } 779 }
776 } 780 }
777} 781}
778 782
779QStringList Global::languageList() 783QStringList Global::languageList()
780{ 784{
781 QString lang = getenv("LANG"); 785 QString lang = getenv("LANG");
782 QStringList langs; 786 QStringList langs;
783 langs.append(lang); 787 langs.append(lang);
784 int i = lang.find("."); 788 int i = lang.find(".");
785 if ( i > 0 ) 789 if ( i > 0 )
786 lang = lang.left( i ); 790 lang = lang.left( i );
787 i = lang.find( "_" ); 791 i = lang.find( "_" );
788 if ( i > 0 ) 792 if ( i > 0 )
789 langs.append(lang.left(i)); 793 langs.append(lang.left(i));
790 return langs; 794 return langs;
791} 795}
792 796
793QStringList Global::helpPath() 797QStringList Global::helpPath()
794{ 798{
795 QString qpeDir = QPEApplication::qpeDir(); 799 QString qpeDir = QPEApplication::qpeDir();
796 QStringList path; 800 QStringList path;
797 QStringList langs = Global::languageList(); 801 QStringList langs = Global::languageList();
798 for (QStringList::ConstIterator it = langs.fromLast(); it!=langs.end(); --it) { 802 for (QStringList::ConstIterator it = langs.fromLast(); it!=langs.end(); --it) {
799 QString lang = *it; 803 QString lang = *it;
800 if ( !lang.isEmpty() ) 804 if ( !lang.isEmpty() )
801 path += qpeDir + "/help/" + lang + "/html"; 805 path += qpeDir + "/help/" + lang + "/html";
802 } 806 }
803 path += qpeDir + "/pics"; 807 path += qpeDir + "/pics";
804 path += qpeDir + "/help/html"; 808 path += qpeDir + "/help/html";
805 /* we even put english into the en dir so try it as fallback as well for opie */ 809 /* we even put english into the en dir so try it as fallback as well for opie */
806 path += qpeDir + "/help/en/html"; 810 path += qpeDir + "/help/en/html";
807 path += qpeDir + "/docs"; 811 path += qpeDir + "/docs";
808 812
809 813
810 return path; 814 return path;
811} 815}
812 816
813 817
814#include "global.moc" 818#include "global.moc"
diff --git a/library/library.pro b/library/library.pro
index ab1f451..5acfc0c 100644
--- a/library/library.pro
+++ b/library/library.pro
@@ -1,157 +1,157 @@
1 TEMPLATE= lib 1 TEMPLATE= lib
2 #CONFIG += qt warn_on release 2 #CONFIG += qt warn_on release
3 CONFIG += qt warn_on debug 3 CONFIG += qt warn_on debug
4 HEADERS= calendar.h \ 4 HEADERS= calendar.h \
5 global.h \ 5 global.h \
6 resource.h \ 6 resource.h \
7 xmlreader.h \ 7 xmlreader.h \
8 mimetype.h \ 8 mimetype.h \
9 menubutton.h \ 9 menubutton.h \
10 network.h \ 10 network.h \
11 networkinterface.h \ 11 networkinterface.h \
12 filemanager.h \ 12 filemanager.h \
13 fontmanager.h \ 13 fontmanager.h \
14 qdawg.h \ 14 qdawg.h \
15 datebookmonth.h \ 15 datebookmonth.h \
16 fileselector.h \ 16 fileselector.h \
17 fileselector_p.h \ 17 fileselector_p.h \
18 imageedit.h \ 18 imageedit.h \
19 qcopenvelope_qws.h \ 19 qcopenvelope_qws.h \
20 qpedecoration_qws.h \ 20 qpedecoration_qws.h \
21 qpeapplication.h \ 21 qpeapplication.h \
22 qpestyle.h \ 22 qpestyle.h \
23 qpedialog.h \ 23 qpedialog.h \
24 lightstyle.h \ 24 lightstyle.h \
25 config.h \ 25 config.h \
26 applnk.h \ 26 applnk.h \
27 sound.h \ 27 sound.h \
28 tzselect.h \ 28 tzselect.h \
29 qmath.h \ 29 qmath.h \
30 datebookdb.h \ 30 datebookdb.h \
31 alarmserver.h \ 31 alarmserver.h \
32 process.h \ 32 process.h \
33 password.h \ 33 password.h \
34 timestring.h \ 34 timestring.h \
35 fontfactoryinterface.h \ 35 fontfactoryinterface.h \
36 fontdatabase.h \ 36 fontdatabase.h \
37 power.h \ 37 power.h \
38 storage.h \ 38 storage.h \
39 qpemessagebox.h \ 39 qpemessagebox.h \
40 timeconversion.h \ 40 timeconversion.h \
41 qpedebug.h \ 41 qpedebug.h \
42 qpemenubar.h \ 42 qpemenubar.h \
43 qpetoolbar.h \ 43 qpetoolbar.h \
44 backend/categories.h \ 44 backend/categories.h \
45 stringutil.h \ 45 stringutil.h \
46 backend/palmtoprecord.h \ 46 backend/palmtoprecord.h \
47 backend/task.h \ 47 backend/task.h \
48 backend/event.h \ 48 backend/event.h \
49 backend/contact.h\ 49 backend/contact.h\
50 categorymenu.h \ 50 categorymenu.h \
51 categoryedit_p.h \ 51 categoryedit_p.h \
52 categoryselect.h \ 52 categoryselect.h \
53 categorywidget.h \ 53 categorywidget.h \
54 ir.h \ 54 ir.h \
55 backend/vobject_p.h \ 55 backend/vobject_p.h \
56 findwidget_p.h \ 56 findwidget_p.h \
57 finddialog.h \ 57 finddialog.h \
58 lnkproperties.h \ 58 lnkproperties.h \
59 windowdecorationinterface.h \ 59 windowdecorationinterface.h \
60 textcodecinterface.h \ 60 textcodecinterface.h \
61 imagecodecinterface.h \ 61 imagecodecinterface.h \
62 qt_override_p.h 62 qt_override_p.h
63 63
64 SOURCES= calendar.cpp \ 64 SOURCES= calendar.cpp \
65 global.cpp \ 65 global.cpp \
66 xmlreader.cpp \ 66 xmlreader.cpp \
67 mimetype.cpp \ 67 mimetype.cpp \
68 menubutton.cpp \ 68 menubutton.cpp \
69 network.cpp \ 69 network.cpp \
70 networkinterface.cpp \ 70 networkinterface.cpp \
71 filemanager.cpp \ 71 filemanager.cpp \
72 fontmanager.cpp \ 72 fontmanager.cpp \
73 qdawg.cpp \ 73 qdawg.cpp \
74 datebookmonth.cpp \ 74 datebookmonth.cpp \
75 fileselector.cpp \ 75 fileselector.cpp \
76 imageedit.cpp \ 76 imageedit.cpp \
77 resource.cpp \ 77 resource.cpp \
78 qpedecoration_qws.cpp \ 78 qpedecoration_qws.cpp \
79 qcopenvelope_qws.cpp \ 79 qcopenvelope_qws.cpp \
80 qpeapplication.cpp \ 80 qpeapplication.cpp \
81 qpestyle.cpp \ 81 qpestyle.cpp \
82 qpedialog.cpp \ 82 qpedialog.cpp \
83 lightstyle.cpp \ 83 lightstyle.cpp \
84 config.cpp \ 84 config.cpp \
85 applnk.cpp \ 85 applnk.cpp \
86 sound.cpp \ 86 sound.cpp \
87 tzselect.cpp \ 87 tzselect.cpp \
88 qmath.c \ 88 qmath.c \
89 datebookdb.cpp \ 89 datebookdb.cpp \
90 alarmserver.cpp \ 90 alarmserver.cpp \
91 password.cpp \ 91 password.cpp \
92 process.cpp \ 92 process.cpp \
93 process_unix.cpp \ 93 process_unix.cpp \
94 timestring.cpp \ 94 timestring.cpp \
95 fontdatabase.cpp \ 95 fontdatabase.cpp \
96 power.cpp \ 96 power.cpp \
97 storage.cpp \ 97 storage.cpp \
98 qpemessagebox.cpp \ 98 qpemessagebox.cpp \
99 backend/timeconversion.cpp \ 99 backend/timeconversion.cpp \
100 qpedebug.cpp \ 100 qpedebug.cpp \
101 qpemenubar.cpp \ 101 qpemenubar.cpp \
102 qpetoolbar.cpp \ 102 qpetoolbar.cpp \
103 backend/categories.cpp \ 103 backend/categories.cpp \
104 backend/stringutil.cpp \ 104 backend/stringutil.cpp \
105 backend/palmtoprecord.cpp \ 105 backend/palmtoprecord.cpp \
106 backend/task.cpp \ 106 backend/task.cpp \
107 backend/event.cpp \ 107 backend/event.cpp \
108 backend/contact.cpp \ 108 backend/contact.cpp \
109 categorymenu.cpp \ 109 categorymenu.cpp \
110 categoryedit_p.cpp \ 110 categoryedit_p.cpp \
111 categoryselect.cpp \ 111 categoryselect.cpp \
112 categorywidget.cpp \ 112 categorywidget.cpp \
113 ir.cpp \ 113 ir.cpp \
114 backend/vcc_yacc.cpp \ 114 backend/vcc_yacc.cpp \
115 backend/vobject.cpp \ 115 backend/vobject.cpp \
116 findwidget_p.cpp \ 116 findwidget_p.cpp \
117 finddialog.cpp \ 117 finddialog.cpp \
118 lnkproperties.cpp \ 118 lnkproperties.cpp \
119 qt_override.cpp 119 qt_override.cpp
120 120
121 121
122 122
123# Qt 3 compatibility 123# Qt 3 compatibility
124HEADERS += quuid.h qcom.h qlibrary.h qlibrary_p.h 124HEADERS += quuid.h qcom.h qlibrary.h qlibrary_p.h
125SOURCES += quuid.cpp qlibrary.cpp qlibrary_unix.cpp 125SOURCES += quuid.cpp qlibrary.cpp qlibrary_unix.cpp
126INCLUDEPATH += $(OPIEDIR)/include backend 126INCLUDEPATH += $(OPIEDIR)/include backend
127 LIBS += -ldl -lcrypt -lm 127 # LIBS += -ldl -lcrypt -lm
128INTERFACES = passwordbase_p.ui categoryeditbase_p.ui findwidgetbase_p.ui lnkpropertiesbase_p.ui 128INTERFACES = passwordbase_p.ui categoryeditbase_p.ui findwidgetbase_p.ui lnkpropertiesbase_p.ui
129 TARGET = qpe 129 TARGET = qpe
130 DESTDIR = $(OPIEDIR)/lib$(PROJMAK) 130 DESTDIR = $(OPIEDIR)/lib$(PROJMAK)
131 VERSION = 1.5.0.1 131 VERSION = 1.5.0.1
132 132
133TRANSLATIONS = ../i18n/de/libqpe.ts \ 133TRANSLATIONS = ../i18n/de/libqpe.ts \
134 ../i18n/nl/libqpe.ts \ 134 ../i18n/nl/libqpe.ts \
135 ../i18n/xx/libqpe.ts \ 135 ../i18n/xx/libqpe.ts \
136 ../i18n/en/libqpe.ts \ 136 ../i18n/en/libqpe.ts \
137 ../i18n/es/libqpe.ts \ 137 ../i18n/es/libqpe.ts \
138 ../i18n/fr/libqpe.ts \ 138 ../i18n/fr/libqpe.ts \
139 ../i18n/hu/libqpe.ts \ 139 ../i18n/hu/libqpe.ts \
140 ../i18n/ja/libqpe.ts \ 140 ../i18n/ja/libqpe.ts \
141 ../i18n/ko/libqpe.ts \ 141 ../i18n/ko/libqpe.ts \
142 ../i18n/no/libqpe.ts \ 142 ../i18n/no/libqpe.ts \
143 ../i18n/pl/libqpe.ts \ 143 ../i18n/pl/libqpe.ts \
144 ../i18n/pt/libqpe.ts \ 144 ../i18n/pt/libqpe.ts \
145 ../i18n/pt_BR/libqpe.ts \ 145 ../i18n/pt_BR/libqpe.ts \
146 ../i18n/sl/libqpe.ts \ 146 ../i18n/sl/libqpe.ts \
147 ../i18n/zh_CN/libqpe.ts \ 147 ../i18n/zh_CN/libqpe.ts \
148 ../i18n/it/libqpe.ts \ 148 ../i18n/it/libqpe.ts \
149 ../i18n/zh_TW/libqpe.ts \ 149 ../i18n/zh_TW/libqpe.ts \
150 ../i18n/da/libqpe.ts 150 ../i18n/da/libqpe.ts
151 151
152 152
153include ( $(OPIEDIR)/include.pro ) 153include ( $(OPIEDIR)/include.pro )
154 154
155contains( CONFIG, no-override ){ 155contains( CONFIG, no-override ){
156 DEFINES += OPIE_NO_OVERRIDE_QT 156 DEFINES += OPIE_NO_OVERRIDE_QT
157} 157}
diff --git a/library/network.cpp b/library/network.cpp
index 3568809..991e11a 100644
--- a/library/network.cpp
+++ b/library/network.cpp
@@ -1,444 +1,448 @@
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_LANGLIST 21#define QTOPIA_INTERNAL_LANGLIST
22#include "qpe/network.h" 22#include "qpe/network.h"
23#include "qpe/networkinterface.h" 23#include "qpe/networkinterface.h"
24#include "qpe/global.h" 24#include "qpe/global.h"
25#include "qpe/config.h" 25#include "qpe/config.h"
26#include "qpe/resource.h" 26#include "qpe/resource.h"
27#include "qpe/qpeapplication.h" 27#include "qpe/qpeapplication.h"
28#include <qpe/qcopenvelope_qws.h> 28#include <qpe/qcopenvelope_qws.h>
29#include <qpe/qlibrary.h> 29#include <qpe/qlibrary.h>
30 30
31#include <qlistbox.h> 31#include <qlistbox.h>
32#include <qdir.h> 32#include <qdir.h>
33#include <qlayout.h> 33#include <qlayout.h>
34#include <qdict.h> 34#include <qdict.h>
35#include <qtranslator.h> 35#include <qtranslator.h>
36 36
37#include <stdlib.h> 37#include <stdlib.h>
38 38
39#ifndef QT_NO_COP 39#ifndef QT_NO_COP
40class NetworkEmitter : public QCopChannel { 40class NetworkEmitter : public QCopChannel {
41 Q_OBJECT 41 Q_OBJECT
42public: 42public:
43 NetworkEmitter() : QCopChannel("QPE/Network",qApp) 43 NetworkEmitter() : QCopChannel("QPE/Network",qApp)
44 { 44 {
45 } 45 }
46 46
47 void receive(const QCString &msg, const QByteArray&) 47 void receive(const QCString &msg, const QByteArray&)
48 { 48 {
49 if ( msg == "choicesChanged()" ) 49 if ( msg == "choicesChanged()" )
50 emit changed(); 50 emit changed();
51 } 51 }
52 52
53signals: 53signals:
54 void changed(); 54 void changed();
55}; 55};
56 56
57/*! 57/*!
58 \internal 58 \internal
59 59
60 Requests that the service \a choice be started. The \a password is 60 Requests that the service \a choice be started. The \a password is
61 the password to use if required. 61 the password to use if required.
62*/ 62*/
63void Network::start(const QString& choice, const QString& password) 63void Network::start(const QString& choice, const QString& password)
64{ 64{
65 QCopEnvelope e("QPE/Network", "start(QString,QString)"); 65 QCopEnvelope e("QPE/Network", "start(QString,QString)");
66 e << choice << password; 66 e << choice << password;
67} 67}
68 68
69/*! 69/*!
70 \class Network network.h 70 \class Network network.h
71 \brief The Network class provides network access functionality. 71 \brief The Network class provides network access functionality.
72 \internal 72 \internal
73*/ 73*/
74 74
75// copy the proxy settings of the active config over to the Proxies.conf file 75// copy the proxy settings of the active config over to the Proxies.conf file
76/*! 76/*!
77 \internal 77 \internal
78*/ 78*/
79void Network::writeProxySettings( Config &cfg ) 79void Network::writeProxySettings( Config &cfg )
80{ 80{
81 Config proxy( Network::settingsDir() + "/Proxies.conf", Config::File ); 81 Config proxy( Network::settingsDir() + "/Proxies.conf", Config::File );
82 proxy.setGroup("Properties"); 82 proxy.setGroup("Properties");
83 cfg.setGroup("Proxy"); 83 cfg.setGroup("Proxy");
84 proxy.writeEntry("type", cfg.readEntry("type") ); 84 proxy.writeEntry("type", cfg.readEntry("type") );
85 proxy.writeEntry("autoconfig", cfg.readEntry("autoconfig") ); 85 proxy.writeEntry("autoconfig", cfg.readEntry("autoconfig") );
86 proxy.writeEntry("httphost", cfg.readEntry("httphost") ); 86 proxy.writeEntry("httphost", cfg.readEntry("httphost") );
87 proxy.writeEntry("httpport", cfg.readEntry("httpport") ); 87 proxy.writeEntry("httpport", cfg.readEntry("httpport") );
88 proxy.writeEntry("ftphost", cfg.readEntry("ftphost") ); 88 proxy.writeEntry("ftphost", cfg.readEntry("ftphost") );
89 proxy.writeEntry("ftpport", cfg.readEntry("ftpport") ); 89 proxy.writeEntry("ftpport", cfg.readEntry("ftpport") );
90 proxy.writeEntry("noproxies", cfg.readEntry("noproxies") ); 90 proxy.writeEntry("noproxies", cfg.readEntry("noproxies") );
91 cfg.setGroup("Properties"); 91 cfg.setGroup("Properties");
92} 92}
93 93
94 94
95 95
96/*! 96/*!
97 \internal 97 \internal
98 98
99 Stops the current network service. 99 Stops the current network service.
100*/ 100*/
101void Network::stop() 101void Network::stop()
102{ 102{
103 QCopEnvelope e("QPE/Network", "stop()"); 103 QCopEnvelope e("QPE/Network", "stop()");
104} 104}
105 105
106static NetworkEmitter *emitter = 0; 106static NetworkEmitter *emitter = 0;
107 107
108/*! 108/*!
109 \internal 109 \internal
110*/ 110*/
111void Network::connectChoiceChange(QObject* receiver, const char* slot) 111void Network::connectChoiceChange(QObject* receiver, const char* slot)
112{ 112{
113 if ( !emitter ) 113 if ( !emitter )
114 emitter = new NetworkEmitter; 114 emitter = new NetworkEmitter;
115 QObject::connect(emitter,SIGNAL(changed()),receiver,slot); 115 QObject::connect(emitter,SIGNAL(changed()),receiver,slot);
116} 116}
117 117
118 #endif// QT_NO_COP 118 #endif// QT_NO_COP
119/*! 119/*!
120 \internal 120 \internal
121*/ 121*/
122QString Network::settingsDir() 122QString Network::settingsDir()
123{ 123{
124 return Global::applicationFileName("Network", "modules"); 124 return Global::applicationFileName("Network", "modules");
125} 125}
126 126
127#ifndef QT_NO_COP 127#ifndef QT_NO_COP
128/*! 128/*!
129 \internal 129 \internal
130*/ 130*/
131QStringList Network::choices(QListBox* lb, const QString& dir) 131QStringList Network::choices(QListBox* lb, const QString& dir)
132{ 132{
133 QStringList list; 133 QStringList list;
134 134
135 if ( lb ) 135 if ( lb )
136 lb->clear(); 136 lb->clear();
137 137
138 QString adir = dir.isEmpty() ? settingsDir() : dir; 138 QString adir = dir.isEmpty() ? settingsDir() : dir;
139 QDir settingsdir(adir); 139 QDir settingsdir(adir);
140 settingsdir.mkdir(adir); 140 settingsdir.mkdir(adir);
141 141
142 QStringList files = settingsdir.entryList("*.conf"); 142 QStringList files = settingsdir.entryList("*.conf");
143 for (QStringList::ConstIterator it=files.begin(); it!=files.end(); ++it ) { 143 for (QStringList::ConstIterator it=files.begin(); it!=files.end(); ++it ) {
144 QString filename = settingsdir.filePath(*it); 144 QString filename = settingsdir.filePath(*it);
145 Config cfg(filename, Config::File); 145 Config cfg(filename, Config::File);
146 cfg.setGroup("Info"); 146 cfg.setGroup("Info");
147 if ( lb ) 147 if ( lb )
148 lb->insertItem(Resource::loadPixmap("Network/" + cfg.readEntry("Type")), 148 lb->insertItem(Resource::loadPixmap("Network/" + cfg.readEntry("Type")),
149 cfg.readEntry("Name")); 149 cfg.readEntry("Name"));
150 list.append(filename); 150 list.append(filename);
151 } 151 }
152 152
153 return list; 153 return list;
154} 154}
155 155
156class NetworkServer : public QCopChannel { 156class NetworkServer : public QCopChannel {
157 Q_OBJECT 157 Q_OBJECT
158public: 158public:
159 NetworkServer(QObject* parent) : QCopChannel("QPE/Network",parent), wait(0) 159 NetworkServer(QObject* parent) : QCopChannel("QPE/Network",parent), wait(0)
160 { 160 {
161 up = FALSE; 161 up = FALSE;
162 examineNetworks( TRUE ); 162 examineNetworks( TRUE );
163 QCopChannel* card = new QCopChannel("QPE/Card",parent); 163 QCopChannel* card = new QCopChannel("QPE/Card",parent);
164 connect(card,SIGNAL(received(const QCString &, const QByteArray&)), 164 connect(card,SIGNAL(received(const QCString &, const QByteArray&)),
165 this,SLOT(cardMessage(const QCString &, const QByteArray&))); 165 this,SLOT(cardMessage(const QCString &, const QByteArray&)));
166 } 166 }
167 167
168 ~NetworkServer() 168 ~NetworkServer()
169 { 169 {
170 stop(); 170 stop();
171 } 171 }
172 172
173 bool networkOnline() const 173 bool networkOnline() const
174 { 174 {
175 return up; 175 return up;
176 } 176 }
177 177
178private: 178private:
179 void receive(const QCString &msg, const QByteArray& data) 179 void receive(const QCString &msg, const QByteArray& data)
180 { 180 {
181 if ( msg == "start(QString,QString)" ) { 181 if ( msg == "start(QString,QString)" ) {
182 QDataStream stream(data,IO_ReadOnly); 182 QDataStream stream(data,IO_ReadOnly);
183 QString file,password; 183 QString file,password;
184 stream >> file >> password; 184 stream >> file >> password;
185 if ( file.isEmpty() ) { 185 if ( file.isEmpty() ) {
186 QStringList l = Network::choices(); 186 QStringList l = Network::choices();
187 for (QStringList::ConstIterator i=l.begin(); i!=l.end(); ++i) { 187 for (QStringList::ConstIterator i=l.begin(); i!=l.end(); ++i) {
188 Config cfg(*i,Config::File); 188 Config cfg(*i,Config::File);
189 cfg.setGroup("Info"); 189 cfg.setGroup("Info");
190 QString type = cfg.readEntry("Type"); 190 QString type = cfg.readEntry("Type");
191 NetworkInterface* plugin = Network::loadPlugin(type); 191 NetworkInterface* plugin = Network::loadPlugin(type);
192 cfg.setGroup("Properties"); 192 cfg.setGroup("Properties");
193 if ( plugin && plugin->isAvailable(cfg) ) { 193 if ( plugin && plugin->isAvailable(cfg) ) {
194 file = *i; 194 file = *i;
195 break; 195 break;
196 } 196 }
197 } 197 }
198 if ( file.isEmpty() ) { 198 if ( file.isEmpty() ) {
199 QCopEnvelope("QPE/Network", "failed()"); 199 QCopEnvelope("QPE/Network", "failed()");
200 return; 200 return;
201 } 201 }
202 } 202 }
203 start(file,password); 203 start(file,password);
204 } else if ( msg == "stop()" ) { 204 } else if ( msg == "stop()" ) {
205 stop(); 205 stop();
206 } else if ( msg == "choicesChanged()" ) { 206 } else if ( msg == "choicesChanged()" ) {
207 examineNetworks(); 207 examineNetworks();
208 } 208 }
209 } 209 }
210 210
211private slots: 211private slots:
212 void cardMessage(const QCString &msg, const QByteArray&) 212 void cardMessage(const QCString &msg, const QByteArray&)
213 { 213 {
214 if ( msg == "stabChanged()" ) 214 if ( msg == "stabChanged()" )
215 examineNetworks(); 215 examineNetworks();
216 } 216 }
217 217
218private: 218private:
219 void examineNetworks( bool firstStart = FALSE ) 219 void examineNetworks( bool firstStart = FALSE )
220 { 220 {
221 QStringList l = Network::choices(); 221 QStringList l = Network::choices();
222 bool wasup = up; up=FALSE; 222 bool wasup = up; up=FALSE;
223 QStringList pavailable = available; 223 QStringList pavailable = available;
224 available.clear(); 224 available.clear();
225 for (QStringList::ConstIterator it=l.begin(); it!=l.end(); ++it) { 225 for (QStringList::ConstIterator it=l.begin(); it!=l.end(); ++it) {
226 Config cfg(*it,Config::File); 226 Config cfg(*it,Config::File);
227 cfg.setGroup("Info"); 227 cfg.setGroup("Info");
228 QString type = cfg.readEntry("Type"); 228 QString type = cfg.readEntry("Type");
229 NetworkInterface* plugin = Network::loadPlugin(type); 229 NetworkInterface* plugin = Network::loadPlugin(type);
230 cfg.setGroup("Properties"); 230 cfg.setGroup("Properties");
231 if ( plugin ) { 231 if ( plugin ) {
232 if ( plugin->isActive(cfg) ) { 232 if ( plugin->isActive(cfg) ) {
233 up = TRUE; 233 up = TRUE;
234 if ( firstStart ) 234 if ( firstStart )
235 plugin->start( cfg ); 235 plugin->start( cfg );
236 } 236 }
237 if ( plugin->isAvailable(cfg) ) 237 if ( plugin->isAvailable(cfg) )
238 available.append(*it); 238 available.append(*it);
239 } 239 }
240 } 240 }
241 241
242 // Try to work around unreproducible bug whereby 242 // Try to work around unreproducible bug whereby
243 // the netmon applet shows wrong state. 243 // the netmon applet shows wrong state.
244 bool reannounce = wait<0; 244 bool reannounce = wait<0;
245 245
246 if ( available != pavailable || reannounce ) { 246 if ( available != pavailable || reannounce ) {
247 QCopEnvelope e("QPE/Network", "available(QStringList)"); 247 QCopEnvelope e("QPE/Network", "available(QStringList)");
248 e << available; 248 e << available;
249 } 249 }
250 if ( up != wasup || reannounce ) { 250 if ( up != wasup || reannounce ) {
251 QCopEnvelope("QPE/Network", up ? "up()" : "down()"); 251 QCopEnvelope("QPE/Network", up ? "up()" : "down()");
252 } 252 }
253 } 253 }
254 254
255 void start( const QString& file, const QString& password ) 255 void start( const QString& file, const QString& password )
256 { 256 {
257 if ( !current.isEmpty() ) 257 if ( !current.isEmpty() )
258 stop(); 258 stop();
259 current = QString::null; 259 current = QString::null;
260 Config cfg(file, Config::File); 260 Config cfg(file, Config::File);
261 cfg.setGroup("Info"); 261 cfg.setGroup("Info");
262 QString type = cfg.readEntry("Type"); 262 QString type = cfg.readEntry("Type");
263 NetworkInterface* plugin = Network::loadPlugin(type); 263 NetworkInterface* plugin = Network::loadPlugin(type);
264 bool started = FALSE; 264 bool started = FALSE;
265 if ( plugin ) { 265 if ( plugin ) {
266 cfg.setGroup("Properties"); 266 cfg.setGroup("Properties");
267 if ( plugin->start(cfg,password) ) { 267 if ( plugin->start(cfg,password) ) {
268 Network::writeProxySettings( cfg ); 268 Network::writeProxySettings( cfg );
269 current = file; 269 current = file;
270 wait=0; 270 wait=0;
271 startTimer(400); 271 startTimer(400);
272 started = TRUE; 272 started = TRUE;
273 } 273 }
274 } 274 }
275 if ( !started ) { 275 if ( !started ) {
276 QCopEnvelope("QPE/Network", "failed()"); 276 QCopEnvelope("QPE/Network", "failed()");
277 } 277 }
278 } 278 }
279 279
280 void stop() 280 void stop()
281 { 281 {
282 bool stopped = FALSE; 282 bool stopped = FALSE;
283 if ( !current.isEmpty() ) { 283 if ( !current.isEmpty() ) {
284 Config cfg(current, Config::File); 284 Config cfg(current, Config::File);
285 cfg.setGroup("Info"); 285 cfg.setGroup("Info");
286 QString type = cfg.readEntry("Type"); 286 QString type = cfg.readEntry("Type");
287 NetworkInterface* plugin = Network::loadPlugin(type); 287 NetworkInterface* plugin = Network::loadPlugin(type);
288 if ( plugin ) { 288 if ( plugin ) {
289 cfg.setGroup("Properties"); 289 cfg.setGroup("Properties");
290 if ( plugin->stop(cfg) ) { 290 if ( plugin->stop(cfg) ) {
291 current = QString::null; 291 current = QString::null;
292 wait=0; 292 wait=0;
293 startTimer(400); 293 startTimer(400);
294 stopped = TRUE; 294 stopped = TRUE;
295 } 295 }
296 } 296 }
297 } 297 }
298 if ( !stopped ) { 298 if ( !stopped ) {
299 QCopEnvelope("QPE/Network", "failed()"); 299 QCopEnvelope("QPE/Network", "failed()");
300 } 300 }
301 } 301 }
302 302
303 void timerEvent(QTimerEvent*) 303 void timerEvent(QTimerEvent*)
304 { 304 {
305 examineNetworks(); 305 examineNetworks();
306 if ( wait >= 0 ) { 306 if ( wait >= 0 ) {
307 if ( up == !current.isNull() ) { 307 if ( up == !current.isNull() ) {
308 // done 308 // done
309 killTimers(); 309 killTimers();
310 if ( up ) { 310 if ( up ) {
311 startTimer(3000); // monitor link 311 startTimer(3000); // monitor link
312 wait = -1; 312 wait = -1;
313 } 313 }
314 } else { 314 } else {
315 wait++; 315 wait++;
316 if ( wait == 600 ) { 316 if ( wait == 600 ) {
317 killTimers(); // forget about it after 240 s 317 killTimers(); // forget about it after 240 s
318 QCopEnvelope("QPE/Network", "failed()"); 318 QCopEnvelope("QPE/Network", "failed()");
319 up = !current.isNull(); 319 up = !current.isNull();
320 } 320 }
321 } 321 }
322 } else if ( !up ) { 322 } else if ( !up ) {
323 killTimers(); 323 killTimers();
324 } 324 }
325 } 325 }
326 326
327private: 327private:
328 QStringList available; 328 QStringList available;
329 QString current; 329 QString current;
330 bool up; 330 bool up;
331 int wait; 331 int wait;
332}; 332};
333 333
334static NetworkServer* ns=0; 334static NetworkServer* ns=0;
335 335
336/*! 336/*!
337 \internal 337 \internal
338*/ 338*/
339QString Network::serviceName(const QString& service) 339QString Network::serviceName(const QString& service)
340{ 340{
341 Config cfg(service, Config::File); 341 Config cfg(service, Config::File);
342 cfg.setGroup("Info"); 342 cfg.setGroup("Info");
343 return cfg.readEntry("Name"); 343 return cfg.readEntry("Name");
344} 344}
345 345
346/*! 346/*!
347 \internal 347 \internal
348*/ 348*/
349QString Network::serviceType(const QString& service) 349QString Network::serviceType(const QString& service)
350{ 350{
351 Config cfg(service, Config::File); 351 Config cfg(service, Config::File);
352 cfg.setGroup("Info"); 352 cfg.setGroup("Info");
353 return cfg.readEntry("Type"); 353 return cfg.readEntry("Type");
354} 354}
355 355
356/*! 356/*!
357 \internal 357 \internal
358*/ 358*/
359bool Network::serviceNeedsPassword(const QString& service) 359bool Network::serviceNeedsPassword(const QString& service)
360{ 360{
361 Config cfg(service,Config::File); 361 Config cfg(service,Config::File);
362 cfg.setGroup("Info"); 362 cfg.setGroup("Info");
363 QString type = cfg.readEntry("Type"); 363 QString type = cfg.readEntry("Type");
364 NetworkInterface* plugin = Network::loadPlugin(type); 364 NetworkInterface* plugin = Network::loadPlugin(type);
365 cfg.setGroup("Properties"); 365 cfg.setGroup("Properties");
366 return plugin ? plugin->needPassword(cfg) : FALSE; 366 return plugin ? plugin->needPassword(cfg) : FALSE;
367} 367}
368 368
369/*! 369/*!
370 \internal 370 \internal
371*/ 371*/
372bool Network::networkOnline() 372bool Network::networkOnline()
373{ 373{
374 return ns && ns->networkOnline(); 374 return ns && ns->networkOnline();
375} 375}
376 376
377/*! 377/*!
378 \internal 378 \internal
379*/ 379*/
380void Network::createServer(QObject* parent) 380void Network::createServer(QObject* parent)
381{ 381{
382 ns = new NetworkServer(parent); 382 ns = new NetworkServer(parent);
383} 383}
384 384
385/*! 385/*!
386 \internal 386 \internal
387*/ 387*/
388int Network::addStateWidgets(QWidget* parent) 388int Network::addStateWidgets(QWidget* parent)
389{ 389{
390 int n=0; 390 int n=0;
391 QStringList l = Network::choices(); 391 QStringList l = Network::choices();
392 QVBoxLayout* vb = new QVBoxLayout(parent); 392 QVBoxLayout* vb = new QVBoxLayout(parent);
393 for (QStringList::ConstIterator it=l.begin(); it!=l.end(); ++it) { 393 for (QStringList::ConstIterator it=l.begin(); it!=l.end(); ++it) {
394 Config cfg(*it,Config::File); 394 Config cfg(*it,Config::File);
395 cfg.setGroup("Info"); 395 cfg.setGroup("Info");
396 QString type = cfg.readEntry("Type"); 396 QString type = cfg.readEntry("Type");
397 NetworkInterface* plugin = Network::loadPlugin(type); 397 NetworkInterface* plugin = Network::loadPlugin(type);
398 cfg.setGroup("Properties"); 398 cfg.setGroup("Properties");
399 if ( plugin ) { 399 if ( plugin ) {
400 QWidget* w; 400 QWidget* w;
401 if ( (w=plugin->addStateWidget(parent,cfg)) ) { 401 if ( (w=plugin->addStateWidget(parent,cfg)) ) {
402 n++; 402 n++;
403 vb->addWidget(w); 403 vb->addWidget(w);
404 } 404 }
405 } 405 }
406 } 406 }
407 return n; 407 return n;
408} 408}
409 409
410static QDict<NetworkInterface> *ifaces; 410static QDict<NetworkInterface> *ifaces;
411 411
412/*! 412/*!
413 \internal 413 \internal
414*/ 414*/
415NetworkInterface* Network::loadPlugin(const QString& type) 415NetworkInterface* Network::loadPlugin(const QString& type)
416{ 416{
417#ifndef QT_NO_COMPONENT 417#ifndef QT_NO_COMPONENT
418 if ( !ifaces ) ifaces = new QDict<NetworkInterface>; 418 if ( !ifaces ) ifaces = new QDict<NetworkInterface>;
419 NetworkInterface *iface = ifaces->find(type); 419 NetworkInterface *iface = ifaces->find(type);
420 if ( !iface ) { 420 if ( !iface ) {
421#ifdef Q_OS_MACX
422 QString libfile = QPEApplication::qpeDir() + "/plugins/network/lib" + type + ".dylib";
423#else
421 QString libfile = QPEApplication::qpeDir() + "/plugins/network/lib" + type + ".so"; 424 QString libfile = QPEApplication::qpeDir() + "/plugins/network/lib" + type + ".so";
425#endif
422 QLibrary lib(libfile); 426 QLibrary lib(libfile);
423 if ( !lib.queryInterface( IID_Network, (QUnknownInterface**)&iface ) == QS_OK ) 427 if ( !lib.queryInterface( IID_Network, (QUnknownInterface**)&iface ) == QS_OK )
424 return 0; 428 return 0;
425 ifaces->insert(type,iface); 429 ifaces->insert(type,iface);
426 QStringList langs = Global::languageList(); 430 QStringList langs = Global::languageList();
427 for (QStringList::ConstIterator it = langs.begin(); it!=langs.end(); ++it) { 431 for (QStringList::ConstIterator it = langs.begin(); it!=langs.end(); ++it) {
428 QString lang = *it; 432 QString lang = *it;
429 QTranslator * trans = new QTranslator(qApp); 433 QTranslator * trans = new QTranslator(qApp);
430 QString tfn = QPEApplication::qpeDir()+"/i18n/"+lang+"/lib"+type+".qm"; 434 QString tfn = QPEApplication::qpeDir()+"/i18n/"+lang+"/lib"+type+".qm";
431 if ( trans->load( tfn )) 435 if ( trans->load( tfn ))
432 qApp->installTranslator( trans ); 436 qApp->installTranslator( trans );
433 else 437 else
434 delete trans; 438 delete trans;
435 } 439 }
436 } 440 }
437 return iface; 441 return iface;
438#else 442#else
439 return 0; 443 return 0;
440#endif 444#endif
441} 445}
442 446
443#include "network.moc" 447#include "network.moc"
444 #endif// QT_NO_COP 448 #endif// QT_NO_COP
diff --git a/library/qlibrary_unix.cpp b/library/qlibrary_unix.cpp
index 7740321..0229b7b 100644
--- a/library/qlibrary_unix.cpp
+++ b/library/qlibrary_unix.cpp
@@ -1,132 +1,243 @@
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#include "qlibrary_p.h" 21#include "qlibrary_p.h"
22 22
23#ifndef QT_NO_COMPONENT 23#ifndef QT_NO_COMPONENT
24 24
25/* 25/*
26 The platform dependent implementations of 26 The platform dependent implementations of
27 - loadLibrary 27 - loadLibrary
28 - freeLibrary 28 - freeLibrary
29 - resolveSymbol 29 - resolveSymbol
30 30
31 It's not too hard to guess what the functions do. 31 It's not too hard to guess what the functions do.
32*/ 32*/
33#if defined(Q_OS_HPUX) 33#if defined(Q_OS_HPUX)
34// for HP-UX < 11.x and 32 bit 34// for HP-UX < 11.x and 32 bit
35#include <dl.h> 35#include <dl.h>
36 36
37bool QLibraryPrivate::loadLibrary() 37bool QLibraryPrivate::loadLibrary()
38{ 38{
39 if ( pHnd ) 39 if ( pHnd )
40 return TRUE; 40 return TRUE;
41 41
42 QString filename = library->library(); 42 QString filename = library->library();
43 43
44 pHnd = (void*)shl_load( filename.latin1(), BIND_DEFERRED | BIND_NONFATAL | DYNAMIC_PATH, 0 ); 44 pHnd = (void*)shl_load( filename.latin1(), BIND_DEFERRED | BIND_NONFATAL | DYNAMIC_PATH, 0 );
45#if defined(QT_DEBUG) || defined(QT_DEBUG_COMPONENT) 45#if defined(QT_DEBUG) || defined(QT_DEBUG_COMPONENT)
46 if ( !pHnd ) 46 if ( !pHnd )
47 qDebug( "Failed to load library %s!", filename.latin1() ); 47 qDebug( "Failed to load library %s!", filename.latin1() );
48#endif 48#endif
49 return pHnd != 0; 49 return pHnd != 0;
50} 50}
51 51
52bool QLibraryPrivate::freeLibrary() 52bool QLibraryPrivate::freeLibrary()
53{ 53{
54 if ( !pHnd ) 54 if ( !pHnd )
55 return TRUE; 55 return TRUE;
56 56
57 if ( !shl_unload( (shl_t)pHnd ) ) { 57 if ( !shl_unload( (shl_t)pHnd ) ) {
58 pHnd = 0; 58 pHnd = 0;
59 return TRUE; 59 return TRUE;
60 } 60 }
61 return FALSE; 61 return FALSE;
62} 62}
63 63
64void* QLibraryPrivate::resolveSymbol( const char* symbol ) 64void* QLibraryPrivate::resolveSymbol( const char* symbol )
65{ 65{
66 if ( !pHnd ) 66 if ( !pHnd )
67 return 0; 67 return 0;
68 68
69 void* address = 0; 69 void* address = 0;
70 if ( shl_findsym( (shl_t*)&pHnd, symbol, TYPE_UNDEFINED, address ) < 0 ) { 70 if ( shl_findsym( (shl_t*)&pHnd, symbol, TYPE_UNDEFINED, address ) < 0 ) {
71#if defined(QT_DEBUG) || defined(QT_DEBUG_COMPONENT) 71#if defined(QT_DEBUG) || defined(QT_DEBUG_COMPONENT)
72 qDebug( "Couldn't resolve symbol \"%s\"", symbol ); 72 qDebug( "Couldn't resolve symbol \"%s\"", symbol );
73#endif 73#endif
74 return 0; 74 return 0;
75 } 75 }
76 return address; 76 return address;
77} 77}
78 78
79#else // Q_OS_HPUX 79#elif defined(_NULL_LIB_)
80
81bool QLibraryPrivate::loadLibrary()
82{
83 //qDebug("QLibraryPrivate::loadLibrary\n");
84 return FALSE;
85}
86bool QLibraryPrivate::freeLibrary()
87{
88 //qDebug("QLibraryPrivate::freeLibrary\n");
89 return FALSE;
90}
91void* QLibraryPrivate::resolveSymbol( const char* symbol )
92{
93 //qDebug("QLibraryPrivate::resolveSymbol\n");
94 return FALSE;
95}
96
97#elif defined(Q_OS_MACX)
98
99#define ENUM_DYLD_BOOL
100enum DYLD_BOOL {
101 DYLD_FALSE,
102 DYLD_TRUE
103};
104#include <mach-o/dyld.h>
105typedef struct {
106 NSObjectFileImage img;
107 NSModule mod;
108} DyldLibDesc;
109
110bool QLibraryPrivate::loadLibrary()
111{
112 // qDebug("QLibraryPrivate::loadLibrary\n");
113 // return FALSE;
114 if ( pHnd )
115 return TRUE;
116
117 QString filename = library->library();
118
119 NSObjectFileImage img = 0;
120 NSModule mod = 0;
121 NSObjectFileImageReturnCode ret = NSCreateObjectFileImageFromFile( filename.latin1() , &img );
122 if ( ret != NSObjectFileImageSuccess ) {
123 qWarning( "Error in NSCreateObjectFileImageFromFile(): %d; Filename: %s", ret, filename.latin1() );
124 if (ret == NSObjectFileImageAccess) {
125 qWarning ("(NSObjectFileImageAccess)" );
126 }
127 } else {
128 mod = NSLinkModule(img, filename.latin1(), NSLINKMODULE_OPTION_BINDNOW |
129 NSLINKMODULE_OPTION_PRIVATE |
130 NSLINKMODULE_OPTION_RETURN_ON_ERROR);
131 if (mod == 0) {
132 qWarning( "Error in NSLinkModule()" );
133 NSDestroyObjectFileImage(img);
134 }
135 }
136 DyldLibDesc* desc = 0;
137 if (img != 0 && mod != 0) {
138 desc = new DyldLibDesc;
139 desc->img = img;
140 desc->mod = mod;
141 }
142 pHnd = desc;
143 return pHnd != 0;
144}
145
146bool QLibraryPrivate::freeLibrary()
147{
148 //qDebug("QLibraryPrivate::freeLibrary\n");
149 //return FALSE;
150 if ( !pHnd )
151 return TRUE;
152
153 DyldLibDesc* desc = (DyldLibDesc*) pHnd;
154 NSModule mod = desc->mod;
155 NSObjectFileImage img = desc->img;
156 DYLD_BOOL success = NSUnLinkModule(mod, NSUNLINKMODULE_OPTION_NONE);
157 if ( success ) {
158 NSDestroyObjectFileImage(img);
159 delete desc;
160 pHnd = 0;
161 }
162#if defined(QT_DEBUG) || defined(QT_DEBUG_COMPONENT)
163 else {
164 qWarning( "Error in NSUnLinkModule(): %d", ret );
165 }
166#endif
167 return pHnd == 0;
168}
169
170void* QLibraryPrivate::resolveSymbol( const char* symbol )
171{
172 //qDebug("QLibraryPrivate::resolveSymbol\n");
173 //return FALSE;
174 if ( !pHnd )
175 return 0;
176
177 DyldLibDesc* desc = (DyldLibDesc*) pHnd;
178 NSSymbol sym = NSLookupSymbolInModule(desc->mod, symbol);
179 void* address = 0;
180 if (sym != 0) {
181 address = NSAddressOfSymbol(sym);
182 }
183#if defined(QT_DEBUG) || defined(QT_DEBUG_COMPONENT)
184 if ( address == 0 )
185 qWarning( "Cannot find symbol: %s", symbol );
186#endif
187 return address;
188}
189
190#else
80// Something else, assuming POSIX 191// Something else, assuming POSIX
81#include <dlfcn.h> 192#include <dlfcn.h>
82 193
83bool QLibraryPrivate::loadLibrary() 194bool QLibraryPrivate::loadLibrary()
84{ 195{
85 if ( pHnd ) 196 if ( pHnd )
86 return TRUE; 197 return TRUE;
87 198
88 QString filename = library->library(); 199 QString filename = library->library();
89 200
90 pHnd = dlopen( filename.latin1() , RTLD_LAZY ); 201 pHnd = dlopen( filename.latin1() , RTLD_LAZY );
91#if defined(QT_DEBUG) || defined(QT_DEBUG_COMPONENT) 202#if defined(QT_DEBUG) || defined(QT_DEBUG_COMPONENT)
92 if ( !pHnd ) 203 if ( !pHnd )
93 qWarning( "%s", dlerror() ); 204 qWarning( "%s", dlerror() );
94#endif 205#endif
95 return pHnd != 0; 206 return pHnd != 0;
96} 207}
97 208
98bool QLibraryPrivate::freeLibrary() 209bool QLibraryPrivate::freeLibrary()
99{ 210{
100 if ( !pHnd ) 211 if ( !pHnd )
101 return TRUE; 212 return TRUE;
102 213
103 int ec = dlclose( pHnd ); 214 int ec = dlclose( pHnd );
104 if ( !ec ) 215 if ( !ec )
105 pHnd = 0; 216 pHnd = 0;
106#if defined(QT_DEBUG) || defined(QT_DEBUG_COMPONENT) 217#if defined(QT_DEBUG) || defined(QT_DEBUG_COMPONENT)
107 else { 218 else {
108 const char* error = dlerror(); 219 const char* error = dlerror();
109 if ( error ) 220 if ( error )
110 qWarning( "%s", error ); 221 qWarning( "%s", error );
111 } 222 }
112#endif 223#endif
113 return pHnd == 0; 224 return pHnd == 0;
114} 225}
115 226
116void* QLibraryPrivate::resolveSymbol( const char* f ) 227void* QLibraryPrivate::resolveSymbol( const char* f )
117{ 228{
118 if ( !pHnd ) 229 if ( !pHnd )
119 return 0; 230 return 0;
120 231
121 void* address = dlsym( pHnd, f ); 232 void* address = dlsym( pHnd, f );
122#if defined(QT_DEBUG) || defined(QT_DEBUG_COMPONENT) 233#if defined(QT_DEBUG) || defined(QT_DEBUG_COMPONENT)
123 const char* error = dlerror(); 234 const char* error = dlerror();
124 if ( error ) 235 if ( error )
125 qWarning( "%s", error ); 236 qWarning( "%s", error );
126#endif 237#endif
127 return address; 238 return address;
128} 239}
129 240
130#endif // POSIX 241#endif // POSIX
131 242
132#endif // QT_NO_COMPONENT 243#endif // QT_NO_COMPONENT
diff --git a/library/qpeapplication.cpp b/library/qpeapplication.cpp
index d4734ae..a97efc0 100644
--- a/library/qpeapplication.cpp
+++ b/library/qpeapplication.cpp
@@ -1,2074 +1,2099 @@
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#include <linux/limits.h> // needed for some toolchains (PATH_MAX) 24#include <linux/limits.h> // needed for some toolchains (PATH_MAX)
25#endif
24#include <qfile.h> 26#include <qfile.h>
25#include <qqueue.h> 27#include <qqueue.h>
26#ifdef Q_WS_QWS 28#ifdef Q_WS_QWS
27#ifndef QT_NO_COP 29#ifndef QT_NO_COP
28#if QT_VERSION <= 231 30#if QT_VERSION <= 231
29#define private public 31#define private public
30#define sendLocally processEvent 32#define sendLocally processEvent
31#include "qcopenvelope_qws.h" 33#include "qcopenvelope_qws.h"
32#undef private 34#undef private
33#else 35#else
34#include "qcopenvelope_qws.h" 36#include "qcopenvelope_qws.h"
35#endif 37#endif
36#endif 38#endif
37#include <qwindowsystem_qws.h> 39#include <qwindowsystem_qws.h>
38#endif 40#endif
39#include <qtextstream.h> 41#include <qtextstream.h>
40#include <qpalette.h> 42#include <qpalette.h>
41#include <qbuffer.h> 43#include <qbuffer.h>
42#include <qptrdict.h> 44#include <qptrdict.h>
43#include <qregexp.h> 45#include <qregexp.h>
44#include <qdir.h> 46#include <qdir.h>
45#include <qlabel.h> 47#include <qlabel.h>
46#include <qdialog.h> 48#include <qdialog.h>
47#include <qdragobject.h> 49#include <qdragobject.h>
48#include <qtextcodec.h> 50#include <qtextcodec.h>
49#include <qevent.h> 51#include <qevent.h>
50#include <qtooltip.h> 52#include <qtooltip.h>
51#include <qsignal.h> 53#include <qsignal.h>
52#include <qmainwindow.h> 54#include <qmainwindow.h>
53#include <qwidgetlist.h> 55#include <qwidgetlist.h>
54#include <qpixmapcache.h> 56#include <qpixmapcache.h>
55 57
56#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 58#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
57#define QTOPIA_INTERNAL_INITAPP 59#define QTOPIA_INTERNAL_INITAPP
58#include "qpeapplication.h" 60#include "qpeapplication.h"
59#include "qpestyle.h" 61#include "qpestyle.h"
60#include "styleinterface.h" 62#include "styleinterface.h"
61#if QT_VERSION >= 300 63#if QT_VERSION >= 300
62#include <qstylefactory.h> 64#include <qstylefactory.h>
63#else 65#else
64#include <qplatinumstyle.h> 66#include <qplatinumstyle.h>
65#include <qwindowsstyle.h> 67#include <qwindowsstyle.h>
66#include <qmotifstyle.h> 68#include <qmotifstyle.h>
67#include <qmotifplusstyle.h> 69#include <qmotifplusstyle.h>
68#include "lightstyle.h" 70#include "lightstyle.h"
69 71
70#include <qpe/qlibrary.h> 72#include <qpe/qlibrary.h>
71#endif 73#endif
72#include "global.h" 74#include "global.h"
73#include "resource.h" 75#include "resource.h"
74#if QT_VERSION <= 230 && defined(QT_NO_CODECS) 76#if QT_VERSION <= 230 && defined(QT_NO_CODECS)
75#include "qutfcodec.h" 77#include "qutfcodec.h"
76#endif 78#endif
77#include "config.h" 79#include "config.h"
78#include "network.h" 80#include "network.h"
79#ifdef QWS 81#ifdef QWS
80#include "fontmanager.h" 82#include "fontmanager.h"
81#endif 83#endif
82 84
83#include "alarmserver.h" 85#include "alarmserver.h"
84#include "applnk.h" 86#include "applnk.h"
85#include "qpemenubar.h" 87#include "qpemenubar.h"
86#include "textcodecinterface.h" 88#include "textcodecinterface.h"
87#include "imagecodecinterface.h" 89#include "imagecodecinterface.h"
88 90
89#include <unistd.h> 91#include <unistd.h>
90#include <sys/file.h> 92#include <sys/file.h>
91#include <sys/ioctl.h> 93#include <sys/ioctl.h>
94#ifndef QT_NO_SOUND
92#include <sys/soundcard.h> 95#include <sys/soundcard.h>
93 96#endif
94#include "qt_override_p.h" 97#include "qt_override_p.h"
95 98
96 99
97class QPEApplicationData 100class QPEApplicationData
98{ 101{
99public: 102public:
100 QPEApplicationData ( ) 103 QPEApplicationData ( )
101 : presstimer( 0 ), presswidget( 0 ), rightpressed( false ), kbgrabbed( false ), 104 : presstimer( 0 ), presswidget( 0 ), rightpressed( false ), kbgrabbed( false ),
102 notbusysent( false ), preloaded( false ), forceshow( false ), nomaximize( false ), 105 notbusysent( false ), preloaded( false ), forceshow( false ), nomaximize( false ),
103 keep_running( true ), qcopQok( false ), qpe_main_widget( 0 ) 106 keep_running( true ), qcopQok( false ), qpe_main_widget( 0 )
104 107
105 {} 108 {}
106 109
107 int presstimer; 110 int presstimer;
108 QWidget* presswidget; 111 QWidget* presswidget;
109 QPoint presspos; 112 QPoint presspos;
110 113
111 bool rightpressed : 1; 114 bool rightpressed : 1;
112 bool kbgrabbed : 1; 115 bool kbgrabbed : 1;
113 bool notbusysent : 1; 116 bool notbusysent : 1;
114 bool preloaded : 1; 117 bool preloaded : 1;
115 bool forceshow : 1; 118 bool forceshow : 1;
116 bool nomaximize : 1; 119 bool nomaximize : 1;
117 bool keep_running : 1; 120 bool keep_running : 1;
118 bool qcopQok : 1; 121 bool qcopQok : 1;
119 122
120 123
121 QStringList langs; 124 QStringList langs;
122 QString appName; 125 QString appName;
123 struct QCopRec 126 struct QCopRec
124 { 127 {
125 QCopRec( const QCString &ch, const QCString &msg, 128 QCopRec( const QCString &ch, const QCString &msg,
126 const QByteArray &d ) : 129 const QByteArray &d ) :
127 channel( ch ), message( msg ), data( d ) 130 channel( ch ), message( msg ), data( d )
128 { } 131 { }
129 132
130 QCString channel; 133 QCString channel;
131 QCString message; 134 QCString message;
132 QByteArray data; 135 QByteArray data;
133 }; 136 };
134 QWidget* qpe_main_widget; 137 QWidget* qpe_main_widget;
135 QGuardedPtr<QWidget> lastraised; 138 QGuardedPtr<QWidget> lastraised;
136 QQueue<QCopRec> qcopq; 139 QQueue<QCopRec> qcopq;
137 QString styleName; 140 QString styleName;
138 QString decorationName; 141 QString decorationName;
139 142
140 void enqueueQCop( const QCString &ch, const QCString &msg, 143 void enqueueQCop( const QCString &ch, const QCString &msg,
141 const QByteArray &data ) 144 const QByteArray &data )
142 { 145 {
143 qcopq.enqueue( new QCopRec( ch, msg, data ) ); 146 qcopq.enqueue( new QCopRec( ch, msg, data ) );
144 } 147 }
145 void sendQCopQ() 148 void sendQCopQ()
146 { 149 {
147 if (!qcopQok ) 150 if (!qcopQok )
148 return; 151 return;
149 152
150 QCopRec * r; 153 QCopRec * r;
151 154
152 while((r=qcopq.dequeue())) { 155 while((r=qcopq.dequeue())) {
153 // remove from queue before sending... 156 // remove from queue before sending...
154 // event loop can come around again before getting 157 // event loop can come around again before getting
155 // back from sendLocally 158 // back from sendLocally
156#ifndef QT_NO_COP 159#ifndef QT_NO_COP
157 QCopChannel::sendLocally( r->channel, r->message, r->data ); 160 QCopChannel::sendLocally( r->channel, r->message, r->data );
158#endif 161#endif
159 162
160 delete r; 163 delete r;
161 } 164 }
162 } 165 }
163 static void show_mx(QWidget* mw, bool nomaximize, const QString & = QString::null ) 166 static void show_mx(QWidget* mw, bool nomaximize, const QString & = QString::null )
164 { 167 {
165 168
166 // ugly hack, remove that later after finding a sane solution 169 // ugly hack, remove that later after finding a sane solution
167 // Addendum: Only Sharp currently has models with high resolution but (physically) small displays, 170 // Addendum: Only Sharp currently has models with high resolution but (physically) small displays,
168 // so this is only useful if QT_QWS_SIMPAD is NOT defined. E.g. SIMpad has 800x600 but has 171 // so this is only useful if QT_QWS_SIMPAD is NOT defined. E.g. SIMpad has 800x600 but has
169 // a (physically) large enough display to use the small icons 172 // a (physically) large enough display to use the small icons
170#if defined(OPIE_HIGH_RES_SMALL_PHY) 173#if defined(OPIE_HIGH_RES_SMALL_PHY)
171 if ( QPEApplication::desktop() ->width() >= 600 && ( mw->inherits("QMainWindow") || mw->isA("QMainWindow") ) ) { 174 if ( QPEApplication::desktop() ->width() >= 600 && ( mw->inherits("QMainWindow") || mw->isA("QMainWindow") ) ) {
172 ( ( QMainWindow* ) mw )->setUsesBigPixmaps( true ); 175 ( ( QMainWindow* ) mw )->setUsesBigPixmaps( true );
173 } 176 }
174#endif 177#endif
175 178
176 if ( mw->layout() && mw->inherits("QDialog") ) { 179 if ( mw->layout() && mw->inherits("QDialog") ) {
177 QPEApplication::showDialog((QDialog*)mw, nomaximize); 180 QPEApplication::showDialog((QDialog*)mw, nomaximize);
178 } 181 }
179 else { 182 else {
180#ifdef Q_WS_QWS 183#ifdef Q_WS_QWS
181 if ( !nomaximize ) 184 if ( !nomaximize )
182 mw->showMaximized(); 185 mw->showMaximized();
183 else 186 else
184#endif 187#endif
185 188
186 mw->show(); 189 mw->show();
187 } 190 }
188 } 191 }
189 static bool setWidgetCaptionFromAppName( QWidget* /*mw*/, const QString& /*appName*/, const QString& /*appsPath*/ ) 192 static bool setWidgetCaptionFromAppName( QWidget* /*mw*/, const QString& /*appName*/, const QString& /*appsPath*/ )
190 { 193 {
191 /* 194 /*
192 // This works but disable it for now until it is safe to apply 195 // This works but disable it for now until it is safe to apply
193 // What is does is scan the .desktop files of all the apps for 196 // What is does is scan the .desktop files of all the apps for
194 // the applnk that has the corresponding argv[0] as this program 197 // the applnk that has the corresponding argv[0] as this program
195 // then it uses the name stored in the .desktop file as the caption 198 // then it uses the name stored in the .desktop file as the caption
196 // for the main widget. This saves duplicating translations for 199 // for the main widget. This saves duplicating translations for
197 // the app name in the program and in the .desktop files. 200 // the app name in the program and in the .desktop files.
198 201
199 AppLnkSet apps( appsPath ); 202 AppLnkSet apps( appsPath );
200 203
201 QList<AppLnk> appsList = apps.children(); 204 QList<AppLnk> appsList = apps.children();
202 for ( QListIterator<AppLnk> it(appsList); it.current(); ++it ) { 205 for ( QListIterator<AppLnk> it(appsList); it.current(); ++it ) {
203 if ( (*it)->exec() == appName ) { 206 if ( (*it)->exec() == appName ) {
204 mw->setCaption( (*it)->name() ); 207 mw->setCaption( (*it)->name() );
205 return TRUE; 208 return TRUE;
206 } 209 }
207 } 210 }
208 */ 211 */
209 return FALSE; 212 return FALSE;
210 } 213 }
211 214
212 215
213 void show(QWidget* mw, bool nomax) 216 void show(QWidget* mw, bool nomax)
214 { 217 {
215 setWidgetCaptionFromAppName( mw, appName, QPEApplication::qpeDir() + "apps" ); 218 setWidgetCaptionFromAppName( mw, appName, QPEApplication::qpeDir() + "apps" );
216 nomaximize = nomax; 219 nomaximize = nomax;
217 qpe_main_widget = mw; 220 qpe_main_widget = mw;
218 qcopQok = TRUE; 221 qcopQok = TRUE;
219#ifndef QT_NO_COP 222#ifndef QT_NO_COP
220 223
221 sendQCopQ(); 224 sendQCopQ();
222#endif 225#endif
223 226
224 if ( preloaded ) { 227 if ( preloaded ) {
225 if (forceshow) 228 if (forceshow)
226 show_mx(mw, nomax); 229 show_mx(mw, nomax);
227 } 230 }
228 else if ( keep_running ) { 231 else if ( keep_running ) {
229 show_mx(mw, nomax); 232 show_mx(mw, nomax);
230 } 233 }
231 } 234 }
232 235
233 void loadTextCodecs() 236 void loadTextCodecs()
234 { 237 {
235 QString path = QPEApplication::qpeDir() + "/plugins/textcodecs"; 238 QString path = QPEApplication::qpeDir() + "/plugins/textcodecs";
239#ifdef Q_OS_MACX
240 QDir dir( path, "lib*.dylib" );
241#else
236 QDir dir( path, "lib*.so" ); 242 QDir dir( path, "lib*.so" );
243#endif
237 QStringList list; 244 QStringList list;
238 if ( dir. exists ( )) 245 if ( dir. exists ( ))
239 list = dir.entryList(); 246 list = dir.entryList();
240 QStringList::Iterator it; 247 QStringList::Iterator it;
241 for ( it = list.begin(); it != list.end(); ++it ) { 248 for ( it = list.begin(); it != list.end(); ++it ) {
242 TextCodecInterface *iface = 0; 249 TextCodecInterface *iface = 0;
243 QLibrary *lib = new QLibrary( path + "/" + *it ); 250 QLibrary *lib = new QLibrary( path + "/" + *it );
244 if ( lib->queryInterface( IID_QtopiaTextCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) { 251 if ( lib->queryInterface( IID_QtopiaTextCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) {
245 QValueList<int> mibs = iface->mibEnums(); 252 QValueList<int> mibs = iface->mibEnums();
246 for (QValueList<int>::ConstIterator i = mibs.begin(); i != mibs.end(); ++i) { 253 for (QValueList<int>::ConstIterator i = mibs.begin(); i != mibs.end(); ++i) {
247 (void)iface->createForMib(*i); 254 (void)iface->createForMib(*i);
248 // ### it exists now; need to remember if we can delete it 255 // ### it exists now; need to remember if we can delete it
249 } 256 }
250 } 257 }
251 else { 258 else {
252 lib->unload(); 259 lib->unload();
253 delete lib; 260 delete lib;
254 } 261 }
255 } 262 }
256 } 263 }
257 264
258 void loadImageCodecs() 265 void loadImageCodecs()
259 { 266 {
260 QString path = QPEApplication::qpeDir() + "/plugins/imagecodecs"; 267 QString path = QPEApplication::qpeDir() + "/plugins/imagecodecs";
268#ifdef Q_OS_MACX
269 QDir dir( path, "lib*.dylib" );
270#else
261 QDir dir( path, "lib*.so" ); 271 QDir dir( path, "lib*.so" );
272#endif
262 QStringList list; 273 QStringList list;
263 if ( dir. exists ( )) 274 if ( dir. exists ( ))
264 list = dir.entryList(); 275 list = dir.entryList();
265 QStringList::Iterator it; 276 QStringList::Iterator it;
266 for ( it = list.begin(); it != list.end(); ++it ) { 277 for ( it = list.begin(); it != list.end(); ++it ) {
267 ImageCodecInterface *iface = 0; 278 ImageCodecInterface *iface = 0;
268 QLibrary *lib = new QLibrary( path + "/" + *it ); 279 QLibrary *lib = new QLibrary( path + "/" + *it );
269 if ( lib->queryInterface( IID_QtopiaImageCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) { 280 if ( lib->queryInterface( IID_QtopiaImageCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) {
270 QStringList formats = iface->keys(); 281 QStringList formats = iface->keys();
271 for (QStringList::ConstIterator i = formats.begin(); i != formats.end(); ++i) { 282 for (QStringList::ConstIterator i = formats.begin(); i != formats.end(); ++i) {
272 (void)iface->installIOHandler(*i); 283 (void)iface->installIOHandler(*i);
273 // ### it exists now; need to remember if we can delete it 284 // ### it exists now; need to remember if we can delete it
274 } 285 }
275 } 286 }
276 else { 287 else {
277 lib->unload(); 288 lib->unload();
278 delete lib; 289 delete lib;
279 } 290 }
280 } 291 }
281 } 292 }
282}; 293};
283 294
284class ResourceMimeFactory : public QMimeSourceFactory 295class ResourceMimeFactory : public QMimeSourceFactory
285{ 296{
286public: 297public:
287 ResourceMimeFactory() : resImage( 0 ) 298 ResourceMimeFactory() : resImage( 0 )
288 { 299 {
289 setFilePath( Global::helpPath() ); 300 setFilePath( Global::helpPath() );
290 setExtensionType( "html", "text/html;charset=UTF-8" ); 301 setExtensionType( "html", "text/html;charset=UTF-8" );
291 } 302 }
292 ~ResourceMimeFactory() { 303 ~ResourceMimeFactory() {
293 delete resImage; 304 delete resImage;
294 } 305 }
295 306
296 const QMimeSource* data( const QString& abs_name ) const 307 const QMimeSource* data( const QString& abs_name ) const
297 { 308 {
298 const QMimeSource * r = QMimeSourceFactory::data( abs_name ); 309 const QMimeSource * r = QMimeSourceFactory::data( abs_name );
299 if ( !r ) { 310 if ( !r ) {
300 int sl = abs_name.length(); 311 int sl = abs_name.length();
301 do { 312 do {
302 sl = abs_name.findRev( '/', sl - 1 ); 313 sl = abs_name.findRev( '/', sl - 1 );
303 QString name = sl >= 0 ? abs_name.mid( sl + 1 ) : abs_name; 314 QString name = sl >= 0 ? abs_name.mid( sl + 1 ) : abs_name;
304 int dot = name.findRev( '.' ); 315 int dot = name.findRev( '.' );
305 if ( dot >= 0 ) 316 if ( dot >= 0 )
306 name = name.left( dot ); 317 name = name.left( dot );
307 QImage img = Resource::loadImage( name ); 318 QImage img = Resource::loadImage( name );
308 if ( !img.isNull() ) { 319 if ( !img.isNull() ) {
309 delete resImage; 320 delete resImage;
310 resImage = new QImageDrag( img ); 321 resImage = new QImageDrag( img );
311 r = resImage; 322 r = resImage;
312 } 323 }
313 } 324 }
314 while ( !r && sl > 0 ); 325 while ( !r && sl > 0 );
315 } 326 }
316 return r; 327 return r;
317 } 328 }
318private: 329private:
319 mutable QImageDrag *resImage; 330 mutable QImageDrag *resImage;
320}; 331};
321 332
322static int& hack(int& i) 333static int& hack(int& i)
323{ 334{
324#if QT_VERSION <= 230 && defined(QT_NO_CODECS) 335#if QT_VERSION <= 230 && defined(QT_NO_CODECS)
325 // These should be created, but aren't in Qt 2.3.0 336 // These should be created, but aren't in Qt 2.3.0
326 (void)new QUtf8Codec; 337 (void)new QUtf8Codec;
327 (void)new QUtf16Codec; 338 (void)new QUtf16Codec;
328#endif 339#endif
329 return i; 340 return i;
330} 341}
331 342
332static int muted = 0; 343static int muted = 0;
333static int micMuted = 0; 344static int micMuted = 0;
334 345
335static void setVolume( int t = 0, int percent = -1 ) 346static void setVolume( int t = 0, int percent = -1 )
336{ 347{
337 switch ( t ) { 348 switch ( t ) {
338 case 0: { 349 case 0: {
339 Config cfg( "qpe" ); 350 Config cfg( "qpe" );
340 cfg.setGroup( "Volume" ); 351 cfg.setGroup( "Volume" );
341 if ( percent < 0 ) 352 if ( percent < 0 )
342 percent = cfg.readNumEntry( "VolumePercent", 50 ); 353 percent = cfg.readNumEntry( "VolumePercent", 50 );
354#ifndef QT_NO_SOUND
343 int fd = 0; 355 int fd = 0;
344 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { 356 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
345 int vol = muted ? 0 : percent; 357 int vol = muted ? 0 : percent;
346 // set both channels to same volume 358 // set both channels to same volume
347 vol |= vol << 8; 359 vol |= vol << 8;
348 ioctl( fd, MIXER_WRITE( 0 ), &vol ); 360 ioctl( fd, MIXER_WRITE( 0 ), &vol );
349 ::close( fd ); 361 ::close( fd );
350 } 362 }
363#endif
351 } 364 }
352 break; 365 break;
353 } 366 }
354} 367}
355 368
356static void setMic( int t = 0, int percent = -1 ) 369static void setMic( int t = 0, int percent = -1 )
357{ 370{
358 switch ( t ) { 371 switch ( t ) {
359 case 0: { 372 case 0: {
360 Config cfg( "qpe" ); 373 Config cfg( "qpe" );
361 cfg.setGroup( "Volume" ); 374 cfg.setGroup( "Volume" );
362 if ( percent < 0 ) 375 if ( percent < 0 )
363 percent = cfg.readNumEntry( "Mic", 50 ); 376 percent = cfg.readNumEntry( "Mic", 50 );
364 377
378#ifndef QT_NO_SOUND
365 int fd = 0; 379 int fd = 0;
366 int mic = micMuted ? 0 : percent; 380 int mic = micMuted ? 0 : percent;
367 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { 381 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
368 ioctl( fd, MIXER_WRITE( SOUND_MIXER_MIC ), &mic ); 382 ioctl( fd, MIXER_WRITE( SOUND_MIXER_MIC ), &mic );
369 ::close( fd ); 383 ::close( fd );
370 } 384 }
385#endif
371 } 386 }
372 break; 387 break;
373 } 388 }
374} 389}
375 390
376 391
377static void setBass( int t = 0, int percent = -1 ) 392static void setBass( int t = 0, int percent = -1 )
378{ 393{
379 switch ( t ) { 394 switch ( t ) {
380 case 0: { 395 case 0: {
381 Config cfg( "qpe" ); 396 Config cfg( "qpe" );
382 cfg.setGroup( "Volume" ); 397 cfg.setGroup( "Volume" );
383 if ( percent < 0 ) 398 if ( percent < 0 )
384 percent = cfg.readNumEntry( "BassPercent", 50 ); 399 percent = cfg.readNumEntry( "BassPercent", 50 );
385 400
401#ifndef QT_NO_SOUND
386 int fd = 0; 402 int fd = 0;
387 int bass = percent; 403 int bass = percent;
388 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { 404 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
389 ioctl( fd, MIXER_WRITE( SOUND_MIXER_BASS ), &bass ); 405 ioctl( fd, MIXER_WRITE( SOUND_MIXER_BASS ), &bass );
390 ::close( fd ); 406 ::close( fd );
391 } 407 }
408#endif
392 } 409 }
393 break; 410 break;
394 } 411 }
395} 412}
396 413
397 414
398static void setTreble( int t = 0, int percent = -1 ) 415static void setTreble( int t = 0, int percent = -1 )
399{ 416{
400 switch ( t ) { 417 switch ( t ) {
401 case 0: { 418 case 0: {
402 Config cfg( "qpe" ); 419 Config cfg( "qpe" );
403 cfg.setGroup( "Volume" ); 420 cfg.setGroup( "Volume" );
404 if ( percent < 0 ) 421 if ( percent < 0 )
405 percent = cfg.readNumEntry( "TreblePercent", 50 ); 422 percent = cfg.readNumEntry( "TreblePercent", 50 );
406 423
424#ifndef QT_NO_SOUND
407 int fd = 0; 425 int fd = 0;
408 int treble = percent; 426 int treble = percent;
409 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { 427 if ( ( fd = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
410 ioctl( fd, MIXER_WRITE( SOUND_MIXER_TREBLE ), &treble ); 428 ioctl( fd, MIXER_WRITE( SOUND_MIXER_TREBLE ), &treble );
411 ::close( fd ); 429 ::close( fd );
412 } 430 }
431#endif
413 } 432 }
414 break; 433 break;
415 } 434 }
416} 435}
417 436
418 437
419/*! 438/*!
420 \class QPEApplication qpeapplication.h 439 \class QPEApplication qpeapplication.h
421 \brief The QPEApplication class implements various system services 440 \brief The QPEApplication class implements various system services
422 that are available to all Qtopia applications. 441 that are available to all Qtopia applications.
423 442
424 Simply by using QPEApplication instead of QApplication, a standard Qt 443 Simply by using QPEApplication instead of QApplication, a standard Qt
425 application becomes a Qtopia application. It automatically follows 444 application becomes a Qtopia application. It automatically follows
426 style changes, quits and raises, and in the 445 style changes, quits and raises, and in the
427 case of \link docwidget.html document-oriented\endlink applications, 446 case of \link docwidget.html document-oriented\endlink applications,
428 changes the currently displayed document in response to the environment. 447 changes the currently displayed document in response to the environment.
429 448
430 To create a \link docwidget.html document-oriented\endlink 449 To create a \link docwidget.html document-oriented\endlink
431 application use showMainDocumentWidget(); to create a 450 application use showMainDocumentWidget(); to create a
432 non-document-oriented application use showMainWidget(). The 451 non-document-oriented application use showMainWidget(). The
433 keepRunning() function indicates whether the application will 452 keepRunning() function indicates whether the application will
434 continue running after it's processed the last \link qcop.html 453 continue running after it's processed the last \link qcop.html
435 QCop\endlink message. This can be changed using setKeepRunning(). 454 QCop\endlink message. This can be changed using setKeepRunning().
436 455
437 A variety of signals are emitted when certain events occur, for 456 A variety of signals are emitted when certain events occur, for
438 example, timeChanged(), clockChanged(), weekChanged(), 457 example, timeChanged(), clockChanged(), weekChanged(),
439 dateFormatChanged() and volumeChanged(). If the application receives 458 dateFormatChanged() and volumeChanged(). If the application receives
440 a \link qcop.html QCop\endlink message on the application's 459 a \link qcop.html QCop\endlink message on the application's
441 QPE/Application/\e{appname} channel, the appMessage() signal is 460 QPE/Application/\e{appname} channel, the appMessage() signal is
442 emitted. There are also flush() and reload() signals, which 461 emitted. There are also flush() and reload() signals, which
443 are emitted when synching begins and ends respectively - upon these 462 are emitted when synching begins and ends respectively - upon these
444 signals, the application should save and reload any data 463 signals, the application should save and reload any data
445 files that are involved in synching. Most of these signals will initially 464 files that are involved in synching. Most of these signals will initially
446 be received and unfiltered through the appMessage() signal. 465 be received and unfiltered through the appMessage() signal.
447 466
448 This class also provides a set of useful static functions. The 467 This class also provides a set of useful static functions. The
449 qpeDir() and documentDir() functions return the respective paths. 468 qpeDir() and documentDir() functions return the respective paths.
450 The grabKeyboard() and ungrabKeyboard() functions are used to 469 The grabKeyboard() and ungrabKeyboard() functions are used to
451 control whether the application takes control of the device's 470 control whether the application takes control of the device's
452 physical buttons (e.g. application launch keys). The stylus' mode of 471 physical buttons (e.g. application launch keys). The stylus' mode of
453 operation is set with setStylusOperation() and retrieved with 472 operation is set with setStylusOperation() and retrieved with
454 stylusOperation(). There are also setInputMethodHint() and 473 stylusOperation(). There are also setInputMethodHint() and
455 inputMethodHint() functions. 474 inputMethodHint() functions.
456 475
457 \ingroup qtopiaemb 476 \ingroup qtopiaemb
458*/ 477*/
459 478
460/*! 479/*!
461 \fn void QPEApplication::clientMoused() 480 \fn void QPEApplication::clientMoused()
462 481
463 \internal 482 \internal
464*/ 483*/
465 484
466/*! 485/*!
467 \fn void QPEApplication::timeChanged(); 486 \fn void QPEApplication::timeChanged();
468 This signal is emitted when the time changes outside the normal 487 This signal is emitted when the time changes outside the normal
469 passage of time, i.e. if the time is set backwards or forwards. 488 passage of time, i.e. if the time is set backwards or forwards.
470*/ 489*/
471 490
472/*! 491/*!
473 \fn void QPEApplication::clockChanged( bool ampm ); 492 \fn void QPEApplication::clockChanged( bool ampm );
474 493
475 This signal is emitted when the user changes the clock's style. If 494 This signal is emitted when the user changes the clock's style. If
476 \a ampm is TRUE, the user wants a 12-hour AM/PM clock, otherwise, 495 \a ampm is TRUE, the user wants a 12-hour AM/PM clock, otherwise,
477 they want a 24-hour clock. 496 they want a 24-hour clock.
478*/ 497*/
479 498
480/*! 499/*!
481 \fn void QPEApplication::volumeChanged( bool muted ) 500 \fn void QPEApplication::volumeChanged( bool muted )
482 501
483 This signal is emitted whenever the mute state is changed. If \a 502 This signal is emitted whenever the mute state is changed. If \a
484 muted is TRUE, then sound output has been muted. 503 muted is TRUE, then sound output has been muted.
485*/ 504*/
486 505
487/*! 506/*!
488 \fn void QPEApplication::weekChanged( bool startOnMonday ) 507 \fn void QPEApplication::weekChanged( bool startOnMonday )
489 508
490 This signal is emitted if the week start day is changed. If \a 509 This signal is emitted if the week start day is changed. If \a
491 startOnMonday is TRUE then the first day of the week is Monday; if 510 startOnMonday is TRUE then the first day of the week is Monday; if
492 \a startOnMonday is FALSE then the first day of the week is 511 \a startOnMonday is FALSE then the first day of the week is
493 Sunday. 512 Sunday.
494*/ 513*/
495 514
496/*! 515/*!
497 \fn void QPEApplication::dateFormatChanged(DateFormat) 516 \fn void QPEApplication::dateFormatChanged(DateFormat)
498 517
499 This signal is emitted whenever the date format is changed. 518 This signal is emitted whenever the date format is changed.
500*/ 519*/
501 520
502/*! 521/*!
503 \fn void QPEApplication::flush() 522 \fn void QPEApplication::flush()
504 523
505 ### 524 ###
506*/ 525*/
507 526
508/*! 527/*!
509 \fn void QPEApplication::reload() 528 \fn void QPEApplication::reload()
510 529
511*/ 530*/
512 531
513 532
514 533
515void QPEApplication::processQCopFile() 534void QPEApplication::processQCopFile()
516{ 535{
517 QString qcopfn("/tmp/qcop-msg-"); 536 QString qcopfn("/tmp/qcop-msg-");
518 qcopfn += d->appName; // append command name 537 qcopfn += d->appName; // append command name
519 538
520 QFile f(qcopfn); 539 QFile f(qcopfn);
521 if ( f.open(IO_ReadWrite) ) { 540 if ( f.open(IO_ReadWrite) ) {
522#ifndef Q_OS_WIN32 541#ifndef Q_OS_WIN32
523 flock(f.handle(), LOCK_EX); 542 flock(f.handle(), LOCK_EX);
524#endif 543#endif
525 QDataStream ds(&f); 544 QDataStream ds(&f);
526 QCString channel, message; 545 QCString channel, message;
527 QByteArray data; 546 QByteArray data;
528 while(!ds.atEnd()) { 547 while(!ds.atEnd()) {
529 ds >> channel >> message >> data; 548 ds >> channel >> message >> data;
530 d->enqueueQCop(channel,message,data); 549 d->enqueueQCop(channel,message,data);
531 } 550 }
532 ::ftruncate(f.handle(), 0); 551 ::ftruncate(f.handle(), 0);
533#ifndef Q_OS_WIN32 552#ifndef Q_OS_WIN32
534 f.flush(); 553 f.flush();
535 flock(f.handle(), LOCK_UN); 554 flock(f.handle(), LOCK_UN);
536#endif 555#endif
537 } 556 }
538#endif 557#endif
539} 558}
540 559
541 560
542/*! 561/*!
543 \fn void QPEApplication::appMessage( const QCString& msg, const QByteArray& data ) 562 \fn void QPEApplication::appMessage( const QCString& msg, const QByteArray& data )
544 563
545 This signal is emitted when a message is received on this 564 This signal is emitted when a message is received on this
546 application's QPE/Application/<i>appname</i> \link qcop.html 565 application's QPE/Application/<i>appname</i> \link qcop.html
547 QCop\endlink channel. 566 QCop\endlink channel.
548 567
549 The slot to which you connect this signal uses \a msg and \a data 568 The slot to which you connect this signal uses \a msg and \a data
550 in the following way: 569 in the following way:
551 570
552\code 571\code
553 void MyWidget::receive( const QCString& msg, const QByteArray& data ) 572 void MyWidget::receive( const QCString& msg, const QByteArray& data )
554 { 573 {
555 QDataStream stream( data, IO_ReadOnly ); 574 QDataStream stream( data, IO_ReadOnly );
556 if ( msg == "someMessage(int,int,int)" ) { 575 if ( msg == "someMessage(int,int,int)" ) {
557 int a,b,c; 576 int a,b,c;
558 stream >> a >> b >> c; 577 stream >> a >> b >> c;
559 ... 578 ...
560 } else if ( msg == "otherMessage(QString)" ) { 579 } else if ( msg == "otherMessage(QString)" ) {
561 ... 580 ...
562 } 581 }
563 } 582 }
564\endcode 583\endcode
565 584
566 \sa qcop.html 585 \sa qcop.html
567 Note that messages received here may be processed by qpe application 586 Note that messages received here may be processed by qpe application
568 and emitted as signals, such as flush() and reload(). 587 and emitted as signals, such as flush() and reload().
569*/ 588*/
570 589
571/*! 590/*!
572 Constructs a QPEApplication just as you would construct 591 Constructs a QPEApplication just as you would construct
573 a QApplication, passing \a argc, \a argv, and \a t. 592 a QApplication, passing \a argc, \a argv, and \a t.
574 593
575 For applications, \a t should be the default, GuiClient. Only 594 For applications, \a t should be the default, GuiClient. Only
576 the Qtopia server passes GuiServer. 595 the Qtopia server passes GuiServer.
577*/ 596*/
578QPEApplication::QPEApplication( int & argc, char **argv, Type t ) 597QPEApplication::QPEApplication( int & argc, char **argv, Type t )
579 : QApplication( hack(argc), argv, t ), pidChannel( 0 ) 598 : QApplication( hack(argc), argv, t ), pidChannel( 0 )
580{ 599{
581 QPixmapCache::setCacheLimit(256); // sensible default for smaller devices. 600 QPixmapCache::setCacheLimit(256); // sensible default for smaller devices.
582 601
583 d = new QPEApplicationData; 602 d = new QPEApplicationData;
584 d->loadTextCodecs(); 603 d->loadTextCodecs();
585 d->loadImageCodecs(); 604 d->loadImageCodecs();
586 int dw = desktop() ->width(); 605 int dw = desktop() ->width();
587 606
588 if ( dw < 200 ) { 607 if ( dw < 200 ) {
589 setFont( QFont( "vera", 8 ) ); 608 setFont( QFont( "vera", 8 ) );
590 AppLnk::setSmallIconSize( 10 ); 609 AppLnk::setSmallIconSize( 10 );
591 AppLnk::setBigIconSize( 28 ); 610 AppLnk::setBigIconSize( 28 );
592 } 611 }
593#if defined(OPIE_HIGH_RES_SMALL_PHY) 612#if defined(OPIE_HIGH_RES_SMALL_PHY)
594 else if ( dw > 600 ) { 613 else if ( dw > 600 ) {
595 setFont( QFont( "vera", 16 ) ); 614 setFont( QFont( "vera", 16 ) );
596 AppLnk::setSmallIconSize( 24 ); 615 AppLnk::setSmallIconSize( 24 );
597 AppLnk::setBigIconSize( 48 ); 616 AppLnk::setBigIconSize( 48 );
598 } 617 }
599#endif 618#endif
600 else if ( dw > 200 ) { 619 else if ( dw > 200 ) {
601 setFont( QFont( "vera", 10 ) ); 620 setFont( QFont( "vera", 10 ) );
602 AppLnk::setSmallIconSize( 14 ); 621 AppLnk::setSmallIconSize( 14 );
603 AppLnk::setBigIconSize( 32 ); 622 AppLnk::setBigIconSize( 32 );
604 } 623 }
605 624
606 QMimeSourceFactory::setDefaultFactory( new ResourceMimeFactory ); 625 QMimeSourceFactory::setDefaultFactory( new ResourceMimeFactory );
607 626
608 connect( this, SIGNAL( lastWindowClosed() ), this, SLOT( hideOrQuit() ) ); 627 connect( this, SIGNAL( lastWindowClosed() ), this, SLOT( hideOrQuit() ) );
609 628
610 629
611 sysChannel = new QCopChannel( "QPE/System", this ); 630 sysChannel = new QCopChannel( "QPE/System", this );
612 connect( sysChannel, SIGNAL( received( const QCString &, const QByteArray & ) ), 631 connect( sysChannel, SIGNAL( received( const QCString &, const QByteArray & ) ),
613 this, SLOT( systemMessage( const QCString &, const QByteArray & ) ) ); 632 this, SLOT( systemMessage( const QCString &, const QByteArray & ) ) );
614 633
615/* COde now in initapp */ 634/* COde now in initapp */
616#if 0 635#if 0
617#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 636#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
618 637
619 QString qcopfn( "/tmp/qcop-msg-" ); 638 QString qcopfn( "/tmp/qcop-msg-" );
620 qcopfn += QString( argv[ 0 ] ); // append command name 639 qcopfn += QString( argv[ 0 ] ); // append command name
621 640
622 QFile f( qcopfn ); 641 QFile f( qcopfn );
623 if ( f.open( IO_ReadOnly ) ) { 642 if ( f.open( IO_ReadOnly ) ) {
624 flock( f.handle(), LOCK_EX ); 643 flock( f.handle(), LOCK_EX );
625 } 644 }
626 645
627 646
628 647
629 QCString channel = QCString( argv[ 0 ] ); 648 QCString channel = QCString( argv[ 0 ] );
630 channel.replace( QRegExp( ".*/" ), "" ); 649 channel.replace( QRegExp( ".*/" ), "" );
631 d->appName = channel; 650 d->appName = channel;
632 channel = "QPE/Application/" + channel; 651 channel = "QPE/Application/" + channel;
633 pidChannel = new QCopChannel( channel, this ); 652 pidChannel = new QCopChannel( channel, this );
634 connect( pidChannel, SIGNAL( received( const QCString &, const QByteArray & ) ), 653 connect( pidChannel, SIGNAL( received( const QCString &, const QByteArray & ) ),
635 this, SLOT( pidMessage( const QCString &, const QByteArray & ) ) ); 654 this, SLOT( pidMessage( const QCString &, const QByteArray & ) ) );
636 655
637 if ( f.isOpen() ) { 656 if ( f.isOpen() ) {
638 d->keep_running = FALSE; 657 d->keep_running = FALSE;
639 QDataStream ds( &f ); 658 QDataStream ds( &f );
640 QCString channel, message; 659 QCString channel, message;
641 QByteArray data; 660 QByteArray data;
642 while ( !ds.atEnd() ) { 661 while ( !ds.atEnd() ) {
643 ds >> channel >> message >> data; 662 ds >> channel >> message >> data;
644 d->enqueueQCop( channel, message, data ); 663 d->enqueueQCop( channel, message, data );
645 } 664 }
646 665
647 flock( f.handle(), LOCK_UN ); 666 flock( f.handle(), LOCK_UN );
648 f.close(); 667 f.close();
649 f.remove(); 668 f.remove();
650 } 669 }
651 670
652 for ( int a = 0; a < argc; a++ ) { 671 for ( int a = 0; a < argc; a++ ) {
653 if ( qstrcmp( argv[ a ], "-preload" ) == 0 ) { 672 if ( qstrcmp( argv[ a ], "-preload" ) == 0 ) {
654 argv[ a ] = argv[ a + 1 ]; 673 argv[ a ] = argv[ a + 1 ];
655 a++; 674 a++;
656 d->preloaded = TRUE; 675 d->preloaded = TRUE;
657 argc -= 1; 676 argc -= 1;
658 } 677 }
659 else if ( qstrcmp( argv[ a ], "-preload-show" ) == 0 ) { 678 else if ( qstrcmp( argv[ a ], "-preload-show" ) == 0 ) {
660 argv[ a ] = argv[ a + 1 ]; 679 argv[ a ] = argv[ a + 1 ];
661 a++; 680 a++;
662 d->preloaded = TRUE; 681 d->preloaded = TRUE;
663 d->forceshow = TRUE; 682 d->forceshow = TRUE;
664 argc -= 1; 683 argc -= 1;
665 } 684 }
666 } 685 }
667 686
668 /* overide stored arguments */ 687 /* overide stored arguments */
669 setArgs( argc, argv ); 688 setArgs( argc, argv );
670 689
671#endif 690#endif
672#else 691#else
673 initApp( argc, argv ); 692 initApp( argc, argv );
674#endif 693#endif
675 // qwsSetDecoration( new QPEDecoration() ); 694 // qwsSetDecoration( new QPEDecoration() );
676 695
677#ifndef QT_NO_TRANSLATION 696#ifndef QT_NO_TRANSLATION
678 697
679 d->langs = Global::languageList(); 698 d->langs = Global::languageList();
680 for ( QStringList::ConstIterator it = d->langs.begin(); it != d->langs.end(); ++it ) { 699 for ( QStringList::ConstIterator it = d->langs.begin(); it != d->langs.end(); ++it ) {
681 QString lang = *it; 700 QString lang = *it;
682 701
683 installTranslation( lang + "/libopie.qm"); 702 installTranslation( lang + "/libopie.qm");
684 installTranslation( lang + "/libqpe.qm" ); 703 installTranslation( lang + "/libqpe.qm" );
685 installTranslation( lang + "/" + d->appName + ".qm" ); 704 installTranslation( lang + "/" + d->appName + ".qm" );
686 705
687 706
688 //###language/font hack; should look it up somewhere 707 //###language/font hack; should look it up somewhere
689#ifdef QWS 708#ifdef QWS
690 709
691 if ( lang == "ja" || lang == "zh_CN" || lang == "zh_TW" || lang == "ko" ) { 710 if ( lang == "ja" || lang == "zh_CN" || lang == "zh_TW" || lang == "ko" ) {
692 QFont fn = FontManager::unicodeFont( FontManager::Proportional ); 711 QFont fn = FontManager::unicodeFont( FontManager::Proportional );
693 setFont( fn ); 712 setFont( fn );
694 } 713 }
695#endif 714#endif
696 } 715 }
697#endif 716#endif
698 717
699 applyStyle(); 718 applyStyle();
700 719
701 if ( type() == GuiServer ) { 720 if ( type() == GuiServer ) {
702 setVolume(); 721 setVolume();
703 } 722 }
704 723
705 installEventFilter( this ); 724 installEventFilter( this );
706 725
707 QPEMenuToolFocusManager::initialize(); 726 QPEMenuToolFocusManager::initialize();
708 727
709#ifdef QT_NO_QWS_CURSOR 728#ifdef QT_NO_QWS_CURSOR
710 // if we have no cursor, probably don't want tooltips 729 // if we have no cursor, probably don't want tooltips
711 QToolTip::setEnabled( FALSE ); 730 QToolTip::setEnabled( FALSE );
712#endif 731#endif
713} 732}
714 733
715 734
716#ifdef QTOPIA_INTERNAL_INITAPP 735#ifdef QTOPIA_INTERNAL_INITAPP
717void QPEApplication::initApp( int argc, char **argv ) 736void QPEApplication::initApp( int argc, char **argv )
718{ 737{
719 bool initial = pidChannel; // was set to 0 in the initializer 738 bool initial = pidChannel; // was set to 0 in the initializer
720 delete pidChannel; 739 delete pidChannel;
721 d->keep_running = TRUE; 740 d->keep_running = TRUE;
722 d->preloaded = FALSE; 741 d->preloaded = FALSE;
723 d->forceshow = FALSE; 742 d->forceshow = FALSE;
724 743
725 QCString channel = QCString(argv[0]); 744 QCString channel = QCString(argv[0]);
726 745
727 channel.replace(QRegExp(".*/"),""); 746 channel.replace(QRegExp(".*/"),"");
728 d->appName = channel; 747 d->appName = channel;
729 748
730 #if QT_VERSION > 235 749 #if QT_VERSION > 235
731 qt_fbdpy->setIdentity( channel ); // In Qt/E 2.3.6 750 qt_fbdpy->setIdentity( channel ); // In Qt/E 2.3.6
732 #endif 751 #endif
733 752
734 channel = "QPE/Application/" + channel; 753 channel = "QPE/Application/" + channel;
735 pidChannel = new QCopChannel( channel, this); 754 pidChannel = new QCopChannel( channel, this);
736 connect( pidChannel, SIGNAL(received(const QCString &, const QByteArray &)), 755 connect( pidChannel, SIGNAL(received(const QCString &, const QByteArray &)),
737 this, SLOT(pidMessage(const QCString &, const QByteArray &))); 756 this, SLOT(pidMessage(const QCString &, const QByteArray &)));
738 757
739 if (!initial) { 758 if (!initial) {
740 processQCopFile(); 759 processQCopFile();
741 d->keep_running = d->qcopq.isEmpty(); 760 d->keep_running = d->qcopq.isEmpty();
742 } 761 }
743 762
744 for (int a=0; a<argc; a++) { 763 for (int a=0; a<argc; a++) {
745 if ( qstrcmp(argv[a],"-preload")==0 ) { 764 if ( qstrcmp(argv[a],"-preload")==0 ) {
746 argv[a] = argv[a+1]; 765 argv[a] = argv[a+1];
747 a++; 766 a++;
748 d->preloaded = TRUE; 767 d->preloaded = TRUE;
749 argc-=1; 768 argc-=1;
750 } else if ( qstrcmp(argv[a],"-preload-show")==0 ) { 769 } else if ( qstrcmp(argv[a],"-preload-show")==0 ) {
751 argv[a] = argv[a+1]; 770 argv[a] = argv[a+1];
752 a++; 771 a++;
753 d->preloaded = TRUE; 772 d->preloaded = TRUE;
754 d->forceshow = TRUE; 773 d->forceshow = TRUE;
755 argc-=1; 774 argc-=1;
756 } 775 }
757 } 776 }
758 777
759 /* overide stored arguments */ 778 /* overide stored arguments */
760 setArgs(argc, argv); 779 setArgs(argc, argv);
761 780
762 /* install translation here */ 781 /* install translation here */
763 for ( QStringList::ConstIterator it = d->langs.begin(); it != d->langs.end(); ++it ) 782 for ( QStringList::ConstIterator it = d->langs.begin(); it != d->langs.end(); ++it )
764 installTranslation( (*it) + "/" + d->appName + ".qm" ); 783 installTranslation( (*it) + "/" + d->appName + ".qm" );
765} 784}
766#endif 785#endif
767 786
768 787
769static QPtrDict<void>* inputMethodDict = 0; 788static QPtrDict<void>* inputMethodDict = 0;
770static void createInputMethodDict() 789static void createInputMethodDict()
771{ 790{
772 if ( !inputMethodDict ) 791 if ( !inputMethodDict )
773 inputMethodDict = new QPtrDict<void>; 792 inputMethodDict = new QPtrDict<void>;
774} 793}
775 794
776/*! 795/*!
777 Returns the currently set hint to the system as to whether 796 Returns the currently set hint to the system as to whether
778 widget \a w has any use for text input methods. 797 widget \a w has any use for text input methods.
779 798
780 799
781 \sa setInputMethodHint() InputMethodHint 800 \sa setInputMethodHint() InputMethodHint
782*/ 801*/
783QPEApplication::InputMethodHint QPEApplication::inputMethodHint( QWidget * w ) 802QPEApplication::InputMethodHint QPEApplication::inputMethodHint( QWidget * w )
784{ 803{
785 if ( inputMethodDict && w ) 804 if ( inputMethodDict && w )
786 return ( InputMethodHint ) ( int ) inputMethodDict->find( w ); 805 return ( InputMethodHint ) ( int ) inputMethodDict->find( w );
787 return Normal; 806 return Normal;
788} 807}
789 808
790/*! 809/*!
791 \enum QPEApplication::InputMethodHint 810 \enum QPEApplication::InputMethodHint
792 811
793 \value Normal the application sometimes needs text input (the default). 812 \value Normal the application sometimes needs text input (the default).
794 \value AlwaysOff the application never needs text input. 813 \value AlwaysOff the application never needs text input.
795 \value AlwaysOn the application always needs text input. 814 \value AlwaysOn the application always needs text input.
796*/ 815*/
797 816
798/*! 817/*!
799 Hints to the system that widget \a w has use for text input methods 818 Hints to the system that widget \a w has use for text input methods
800 as specified by \a mode. 819 as specified by \a mode.
801 820
802 \sa inputMethodHint() InputMethodHint 821 \sa inputMethodHint() InputMethodHint
803*/ 822*/
804void QPEApplication::setInputMethodHint( QWidget * w, InputMethodHint mode ) 823void QPEApplication::setInputMethodHint( QWidget * w, InputMethodHint mode )
805{ 824{
806 createInputMethodDict(); 825 createInputMethodDict();
807 if ( mode == Normal ) { 826 if ( mode == Normal ) {
808 inputMethodDict->remove 827 inputMethodDict->remove
809 ( w ); 828 ( w );
810 } 829 }
811 else { 830 else {
812 inputMethodDict->insert( w, ( void* ) mode ); 831 inputMethodDict->insert( w, ( void* ) mode );
813 } 832 }
814} 833}
815 834
816class HackDialog : public QDialog 835class HackDialog : public QDialog
817{ 836{
818public: 837public:
819 void acceptIt() 838 void acceptIt()
820 { 839 {
821 accept(); 840 accept();
822 } 841 }
823 void rejectIt() 842 void rejectIt()
824 { 843 {
825 reject(); 844 reject();
826 } 845 }
827}; 846};
828 847
829 848
830void QPEApplication::mapToDefaultAction( QWSKeyEvent * ke, int key ) 849void QPEApplication::mapToDefaultAction( QWSKeyEvent * ke, int key )
831{ 850{
832 // specialised actions for certain widgets. May want to 851 // specialised actions for certain widgets. May want to
833 // add more stuff here. 852 // add more stuff here.
834 if ( activePopupWidget() && activePopupWidget() ->inherits( "QListBox" ) 853 if ( activePopupWidget() && activePopupWidget() ->inherits( "QListBox" )
835 && activePopupWidget() ->parentWidget() 854 && activePopupWidget() ->parentWidget()
836 && activePopupWidget() ->parentWidget() ->inherits( "QComboBox" ) ) 855 && activePopupWidget() ->parentWidget() ->inherits( "QComboBox" ) )
837 key = Qt::Key_Return; 856 key = Qt::Key_Return;
838 857
839 if ( activePopupWidget() && activePopupWidget() ->inherits( "QPopupMenu" ) ) 858 if ( activePopupWidget() && activePopupWidget() ->inherits( "QPopupMenu" ) )
840 key = Qt::Key_Return; 859 key = Qt::Key_Return;
841 860
842#ifdef QWS 861#ifdef QWS
843 862
844 ke->simpleData.keycode = key; 863 ke->simpleData.keycode = key;
845#endif 864#endif
846} 865}
847 866
848class HackWidget : public QWidget 867class HackWidget : public QWidget
849{ 868{
850public: 869public:
851 bool needsOk() 870 bool needsOk()
852 { 871 {
853 return ( getWState() & WState_Reserved1 ); 872 return ( getWState() & WState_Reserved1 );
854 } 873 }
855}; 874};
856 875
857/*! 876/*!
858 \internal 877 \internal
859*/ 878*/
860 879
861#ifdef QWS 880#ifdef QWS
862bool QPEApplication::qwsEventFilter( QWSEvent * e ) 881bool QPEApplication::qwsEventFilter( QWSEvent * e )
863{ 882{
864 if ( !d->notbusysent && e->type == QWSEvent::Focus ) { 883 if ( !d->notbusysent && e->type == QWSEvent::Focus ) {
865 if ( qApp->type() != QApplication::GuiServer ) { 884 if ( qApp->type() != QApplication::GuiServer ) {
866 QCopEnvelope e( "QPE/System", "notBusy(QString)" ); 885 QCopEnvelope e( "QPE/System", "notBusy(QString)" );
867 e << d->appName; 886 e << d->appName;
868 } 887 }
869 d->notbusysent = TRUE; 888 d->notbusysent = TRUE;
870 } 889 }
871 if ( type() == GuiServer ) { 890 if ( type() == GuiServer ) {
872 switch ( e->type ) { 891 switch ( e->type ) {
873 case QWSEvent::Mouse: 892 case QWSEvent::Mouse:
874 if ( e->asMouse() ->simpleData.state && !QWidget::find( e->window() ) ) 893 if ( e->asMouse() ->simpleData.state && !QWidget::find( e->window() ) )
875 emit clientMoused(); 894 emit clientMoused();
876 break; 895 break;
877 default: 896 default:
878 break; 897 break;
879 } 898 }
880 } 899 }
881 if ( e->type == QWSEvent::Key ) { 900 if ( e->type == QWSEvent::Key ) {
882 QWSKeyEvent *ke = ( QWSKeyEvent * ) e; 901 QWSKeyEvent *ke = ( QWSKeyEvent * ) e;
883 if ( ke->simpleData.keycode == Qt::Key_F33 ) { 902 if ( ke->simpleData.keycode == Qt::Key_F33 ) {
884 // Use special "OK" key to press "OK" on top level widgets 903 // Use special "OK" key to press "OK" on top level widgets
885 QWidget * active = activeWindow(); 904 QWidget * active = activeWindow();
886 QWidget *popup = 0; 905 QWidget *popup = 0;
887 if ( active && active->isPopup() ) { 906 if ( active && active->isPopup() ) {
888 popup = active; 907 popup = active;
889 active = active->parentWidget(); 908 active = active->parentWidget();
890 } 909 }
891 if ( active && ( int ) active->winId() == ke->simpleData.window && 910 if ( active && ( int ) active->winId() == ke->simpleData.window &&
892 !active->testWFlags( WStyle_Customize | WType_Popup | WType_Desktop ) ) { 911 !active->testWFlags( WStyle_Customize | WType_Popup | WType_Desktop ) ) {
893 if ( ke->simpleData.is_press ) { 912 if ( ke->simpleData.is_press ) {
894 if ( popup ) 913 if ( popup )
895 popup->close(); 914 popup->close();
896 if ( active->inherits( "QDialog" ) ) { 915 if ( active->inherits( "QDialog" ) ) {
897 HackDialog * d = ( HackDialog * ) active; 916 HackDialog * d = ( HackDialog * ) active;
898 d->acceptIt(); 917 d->acceptIt();
899 return TRUE; 918 return TRUE;
900 } 919 }
901 else if ( ( ( HackWidget * ) active ) ->needsOk() ) { 920 else if ( ( ( HackWidget * ) active ) ->needsOk() ) {
902 QSignal s; 921 QSignal s;
903 s.connect( active, SLOT( accept() ) ); 922 s.connect( active, SLOT( accept() ) );
904 s.activate(); 923 s.activate();
905 } 924 }
906 else { 925 else {
907 // do the same as with the select key: Map to the default action of the widget: 926 // do the same as with the select key: Map to the default action of the widget:
908 mapToDefaultAction( ke, Qt::Key_Return ); 927 mapToDefaultAction( ke, Qt::Key_Return );
909 } 928 }
910 } 929 }
911 } 930 }
912 } 931 }
913 else if ( ke->simpleData.keycode == Qt::Key_F30 ) { 932 else if ( ke->simpleData.keycode == Qt::Key_F30 ) {
914 // Use special "select" key to do whatever default action a widget has 933 // Use special "select" key to do whatever default action a widget has
915 mapToDefaultAction( ke, Qt::Key_Space ); 934 mapToDefaultAction( ke, Qt::Key_Space );
916 } 935 }
917 else if ( ke->simpleData.keycode == Qt::Key_Escape && 936 else if ( ke->simpleData.keycode == Qt::Key_Escape &&
918 ke->simpleData.is_press ) { 937 ke->simpleData.is_press ) {
919 // Escape key closes app if focus on toplevel 938 // Escape key closes app if focus on toplevel
920 QWidget * active = activeWindow(); 939 QWidget * active = activeWindow();
921 if ( active && active->testWFlags( WType_TopLevel ) && 940 if ( active && active->testWFlags( WType_TopLevel ) &&
922 ( int ) active->winId() == ke->simpleData.window && 941 ( int ) active->winId() == ke->simpleData.window &&
923 !active->testWFlags( WStyle_Dialog | WStyle_Customize | WType_Popup | WType_Desktop ) ) { 942 !active->testWFlags( WStyle_Dialog | WStyle_Customize | WType_Popup | WType_Desktop ) ) {
924 if ( active->inherits( "QDialog" ) ) { 943 if ( active->inherits( "QDialog" ) ) {
925 HackDialog * d = ( HackDialog * ) active; 944 HackDialog * d = ( HackDialog * ) active;
926 d->rejectIt(); 945 d->rejectIt();
927 return TRUE; 946 return TRUE;
928 } 947 }
929 else if ( strcmp( argv() [ 0 ], "embeddedkonsole" ) != 0 ) { 948 else if ( strcmp( argv() [ 0 ], "embeddedkonsole" ) != 0 ) {
930 active->close(); 949 active->close();
931 } 950 }
932 } 951 }
933 } 952 }
934 else if ( ke->simpleData.keycode >= Qt::Key_F1 && ke->simpleData.keycode <= Qt::Key_F29 ) { 953 else if ( ke->simpleData.keycode >= Qt::Key_F1 && ke->simpleData.keycode <= Qt::Key_F29 ) {
935 // this should be if ( ODevice::inst ( )-> buttonForKeycode ( ... )) 954 // this should be if ( ODevice::inst ( )-> buttonForKeycode ( ... ))
936 // but we cannot access libopie function within libqpe :( 955 // but we cannot access libopie function within libqpe :(
937 956
938 QWidget * active = activeWindow ( ); 957 QWidget * active = activeWindow ( );
939 if ( active && ((int) active-> winId ( ) == ke-> simpleData.window )) { 958 if ( active && ((int) active-> winId ( ) == ke-> simpleData.window )) {
940 if ( d-> kbgrabbed ) { // we grabbed the keyboard 959 if ( d-> kbgrabbed ) { // we grabbed the keyboard
941 QChar ch ( ke-> simpleData.unicode ); 960 QChar ch ( ke-> simpleData.unicode );
942 QKeyEvent qke ( ke-> simpleData. is_press ? QEvent::KeyPress : QEvent::KeyRelease, 961 QKeyEvent qke ( ke-> simpleData. is_press ? QEvent::KeyPress : QEvent::KeyRelease,
943 ke-> simpleData.keycode, 962 ke-> simpleData.keycode,
944 ch. latin1 ( ), 963 ch. latin1 ( ),
945 ke-> simpleData.modifiers, 964 ke-> simpleData.modifiers,
946 QString ( ch ), 965 QString ( ch ),
947 ke-> simpleData.is_auto_repeat, 1 ); 966 ke-> simpleData.is_auto_repeat, 1 );
948 967
949 QObject *which = QWidget::keyboardGrabber ( ); 968 QObject *which = QWidget::keyboardGrabber ( );
950 if ( !which ) 969 if ( !which )
951 which = QApplication::focusWidget ( ); 970 which = QApplication::focusWidget ( );
952 if ( !which ) 971 if ( !which )
953 which = QApplication::activeWindow ( ); 972 which = QApplication::activeWindow ( );
954 if ( !which ) 973 if ( !which )
955 which = qApp; 974 which = qApp;
956 975
957 QApplication::sendEvent ( which, &qke ); 976 QApplication::sendEvent ( which, &qke );
958 } 977 }
959 else { // we didn't grab the keyboard, so send the event to the launcher 978 else { // we didn't grab the keyboard, so send the event to the launcher
960 QCopEnvelope e ( "QPE/Launcher", "deviceButton(int,int,int)" ); 979 QCopEnvelope e ( "QPE/Launcher", "deviceButton(int,int,int)" );
961 e << int( ke-> simpleData.keycode ) << int( ke-> simpleData. is_press ) << int( ke-> simpleData.is_auto_repeat ); 980 e << int( ke-> simpleData.keycode ) << int( ke-> simpleData. is_press ) << int( ke-> simpleData.is_auto_repeat );
962 } 981 }
963 } 982 }
964 return true; 983 return true;
965 } 984 }
966 } 985 }
967 if ( e->type == QWSEvent::Focus ) { 986 if ( e->type == QWSEvent::Focus ) {
968 QWSFocusEvent * fe = ( QWSFocusEvent* ) e; 987 QWSFocusEvent * fe = ( QWSFocusEvent* ) e;
969 if ( !fe->simpleData.get_focus ) { 988 if ( !fe->simpleData.get_focus ) {
970 QWidget * active = activeWindow(); 989 QWidget * active = activeWindow();
971 while ( active && active->isPopup() ) { 990 while ( active && active->isPopup() ) {
972 active->close(); 991 active->close();
973 active = activeWindow(); 992 active = activeWindow();
974 } 993 }
975 } 994 }
976 else { 995 else {
977 // make sure our modal widget is ALWAYS on top 996 // make sure our modal widget is ALWAYS on top
978 QWidget *topm = activeModalWidget(); 997 QWidget *topm = activeModalWidget();
979 if ( topm ) { 998 if ( topm ) {
980 topm->raise(); 999 topm->raise();
981 } 1000 }
982 } 1001 }
983 if ( fe->simpleData.get_focus && inputMethodDict ) { 1002 if ( fe->simpleData.get_focus && inputMethodDict ) {
984 InputMethodHint m = inputMethodHint( QWidget::find( e->window() ) ); 1003 InputMethodHint m = inputMethodHint( QWidget::find( e->window() ) );
985 if ( m == AlwaysOff ) 1004 if ( m == AlwaysOff )
986 Global::hideInputMethod(); 1005 Global::hideInputMethod();
987 if ( m == AlwaysOn ) 1006 if ( m == AlwaysOn )
988 Global::showInputMethod(); 1007 Global::showInputMethod();
989 } 1008 }
990 } 1009 }
991 1010
992 1011
993 return QApplication::qwsEventFilter( e ); 1012 return QApplication::qwsEventFilter( e );
994} 1013}
995#endif 1014#endif
996 1015
997/*! 1016/*!
998 Destroys the QPEApplication. 1017 Destroys the QPEApplication.
999*/ 1018*/
1000QPEApplication::~QPEApplication() 1019QPEApplication::~QPEApplication()
1001{ 1020{
1002 ungrabKeyboard(); 1021 ungrabKeyboard();
1003#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 1022#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
1004 // Need to delete QCopChannels early, since the display will 1023 // Need to delete QCopChannels early, since the display will
1005 // be gone by the time we get to ~QObject(). 1024 // be gone by the time we get to ~QObject().
1006 delete sysChannel; 1025 delete sysChannel;
1007 delete pidChannel; 1026 delete pidChannel;
1008#endif 1027#endif
1009 1028
1010 delete d; 1029 delete d;
1011} 1030}
1012 1031
1013/*! 1032/*!
1014 Returns <tt>$OPIEDIR/</tt>. 1033 Returns <tt>$OPIEDIR/</tt>.
1015*/ 1034*/
1016QString QPEApplication::qpeDir() 1035QString QPEApplication::qpeDir()
1017{ 1036{
1018 const char * base = getenv( "OPIEDIR" ); 1037 const char * base = getenv( "OPIEDIR" );
1019 if ( base ) 1038 if ( base )
1020 return QString( base ) + "/"; 1039 return QString( base ) + "/";
1021 1040
1022 return QString( "../" ); 1041 return QString( "../" );
1023} 1042}
1024 1043
1025/*! 1044/*!
1026 Returns the user's current Document directory. There is a trailing "/". 1045 Returns the user's current Document directory. There is a trailing "/".
1027 .. well, it does now,, and there's no trailing '/' 1046 .. well, it does now,, and there's no trailing '/'
1028*/ 1047*/
1029QString QPEApplication::documentDir() 1048QString QPEApplication::documentDir()
1030{ 1049{
1031 const char* base = getenv( "HOME"); 1050 const char* base = getenv( "HOME");
1032 if ( base ) 1051 if ( base )
1033 return QString( base ) + "/Documents"; 1052 return QString( base ) + "/Documents";
1034 1053
1035 return QString( "../Documents" ); 1054 return QString( "../Documents" );
1036} 1055}
1037 1056
1038static int deforient = -1; 1057static int deforient = -1;
1039 1058
1040/*! 1059/*!
1041 \internal 1060 \internal
1042*/ 1061*/
1043int QPEApplication::defaultRotation() 1062int QPEApplication::defaultRotation()
1044{ 1063{
1045 if ( deforient < 0 ) { 1064 if ( deforient < 0 ) {
1046 QString d = getenv( "QWS_DISPLAY" ); 1065 QString d = getenv( "QWS_DISPLAY" );
1047 if ( d.contains( "Rot90" ) ) { 1066 if ( d.contains( "Rot90" ) ) {
1048 deforient = 90; 1067 deforient = 90;
1049 } 1068 }
1050 else if ( d.contains( "Rot180" ) ) { 1069 else if ( d.contains( "Rot180" ) ) {
1051 deforient = 180; 1070 deforient = 180;
1052 } 1071 }
1053 else if ( d.contains( "Rot270" ) ) { 1072 else if ( d.contains( "Rot270" ) ) {
1054 deforient = 270; 1073 deforient = 270;
1055 } 1074 }
1056 else { 1075 else {
1057 deforient = 0; 1076 deforient = 0;
1058 } 1077 }
1059 } 1078 }
1060 return deforient; 1079 return deforient;
1061} 1080}
1062 1081
1063/*! 1082/*!
1064 \internal 1083 \internal
1065*/ 1084*/
1066void QPEApplication::setDefaultRotation( int r ) 1085void QPEApplication::setDefaultRotation( int r )
1067{ 1086{
1068 if ( qApp->type() == GuiServer ) { 1087 if ( qApp->type() == GuiServer ) {
1069 deforient = r; 1088 deforient = r;
1070 setenv( "QWS_DISPLAY", QString( "Transformed:Rot%1:0" ).arg( r ).latin1(), 1 ); 1089 setenv( "QWS_DISPLAY", QString( "Transformed:Rot%1:0" ).arg( r ).latin1(), 1 );
1071 Config config("qpe"); 1090 Config config("qpe");
1072 config.setGroup( "Rotation" ); 1091 config.setGroup( "Rotation" );
1073 config.writeEntry( "Rot", r ); 1092 config.writeEntry( "Rot", r );
1074 } 1093 }
1075 else { 1094 else {
1076#ifndef QT_NO_COP 1095#ifndef QT_NO_COP
1077 { QCopEnvelope e( "QPE/System", "setDefaultRotation(int)" ); 1096 { QCopEnvelope e( "QPE/System", "setDefaultRotation(int)" );
1078 e << r; 1097 e << r;
1079 } 1098 }
1080#endif 1099#endif
1081 1100
1082 } 1101 }
1083} 1102}
1084 1103
1085#include <qgfx_qws.h> 1104#include <qgfx_qws.h>
1086#include <qwindowsystem_qws.h> 1105#include <qwindowsystem_qws.h>
1087#include <qpixmapcache.h> 1106#include <qpixmapcache.h>
1088 1107
1089extern void qws_clearLoadedFonts(); 1108extern void qws_clearLoadedFonts();
1090 1109
1091void QPEApplication::setCurrentMode( int x, int y, int depth ) 1110void QPEApplication::setCurrentMode( int x, int y, int depth )
1092{ 1111{
1093 // Reset the caches 1112 // Reset the caches
1094 qws_clearLoadedFonts(); 1113 qws_clearLoadedFonts();
1095 QPixmapCache::clear(); 1114 QPixmapCache::clear();
1096 1115
1097 // Change the screen mode 1116 // Change the screen mode
1098 qt_screen->setMode(x, y, depth); 1117 qt_screen->setMode(x, y, depth);
1099 1118
1100 if ( qApp->type() == GuiServer ) { 1119 if ( qApp->type() == GuiServer ) {
1101 // Reconfigure the GuiServer 1120 // Reconfigure the GuiServer
1102 qwsServer->beginDisplayReconfigure(); 1121 qwsServer->beginDisplayReconfigure();
1103 qwsServer->endDisplayReconfigure(); 1122 qwsServer->endDisplayReconfigure();
1104 1123
1105 // Get all the running apps to reset 1124 // Get all the running apps to reset
1106 QCopEnvelope env( "QPE/System", "reset()" ); 1125 QCopEnvelope env( "QPE/System", "reset()" );
1107 } 1126 }
1108} 1127}
1109 1128
1110void QPEApplication::reset() { 1129void QPEApplication::reset() {
1111 // Reconnect to the screen 1130 // Reconnect to the screen
1112 qt_screen->disconnect(); 1131 qt_screen->disconnect();
1113 qt_screen->connect( QString::null ); 1132 qt_screen->connect( QString::null );
1114 1133
1115 // Redraw everything 1134 // Redraw everything
1116 applyStyle(); 1135 applyStyle();
1117} 1136}
1118 1137
1119/*! 1138/*!
1120 \internal 1139 \internal
1121*/ 1140*/
1122void QPEApplication::applyStyle() 1141void QPEApplication::applyStyle()
1123{ 1142{
1124 Config config( "qpe" ); 1143 Config config( "qpe" );
1125 config.setGroup( "Appearance" ); 1144 config.setGroup( "Appearance" );
1126 1145
1127#if QT_VERSION > 233 1146#if QT_VERSION > 233
1128#if !defined(OPIE_NO_OVERRIDE_QT) 1147#if !defined(OPIE_NO_OVERRIDE_QT)
1129 // don't block ourselves ... 1148 // don't block ourselves ...
1130 Opie::force_appearance = 0; 1149 Opie::force_appearance = 0;
1131 1150
1132 static QString appname = Opie::binaryName ( ); 1151 static QString appname = Opie::binaryName ( );
1133 1152
1134 QStringList ex = config. readListEntry ( "NoStyle", ';' ); 1153 QStringList ex = config. readListEntry ( "NoStyle", ';' );
1135 int nostyle = 0; 1154 int nostyle = 0;
1136 for ( QStringList::Iterator it = ex. begin ( ); it != ex. end ( ); ++it ) { 1155 for ( QStringList::Iterator it = ex. begin ( ); it != ex. end ( ); ++it ) {
1137 if ( QRegExp (( *it ). mid ( 1 ), false, true ). find ( appname, 0 ) >= 0 ) { 1156 if ( QRegExp (( *it ). mid ( 1 ), false, true ). find ( appname, 0 ) >= 0 ) {
1138 nostyle = ( *it ). left ( 1 ). toInt ( 0, 32 ); 1157 nostyle = ( *it ). left ( 1 ). toInt ( 0, 32 );
1139 break; 1158 break;
1140 } 1159 }
1141 } 1160 }
1142#else 1161#else
1143 int nostyle = 0; 1162 int nostyle = 0;
1144#endif 1163#endif
1145 1164
1146 // Widget style 1165 // Widget style
1147 QString style = config.readEntry( "Style", "FlatStyle" ); 1166 QString style = config.readEntry( "Style", "FlatStyle" );
1148 1167
1149 // don't set a custom style 1168 // don't set a custom style
1150 if ( nostyle & Opie::Force_Style ) 1169 if ( nostyle & Opie::Force_Style )
1151 style = "FlatStyle"; 1170 style = "FlatStyle";
1152 1171
1153 internalSetStyle ( style ); 1172 internalSetStyle ( style );
1154 1173
1155 // Colors - from /etc/colors/Liquid.scheme 1174 // Colors - from /etc/colors/Liquid.scheme
1156 QColor bgcolor( config.readEntry( "Background", "#E0E0E0" ) ); 1175 QColor bgcolor( config.readEntry( "Background", "#E0E0E0" ) );
1157 QColor btncolor( config.readEntry( "Button", "#96c8fa" ) ); 1176 QColor btncolor( config.readEntry( "Button", "#96c8fa" ) );
1158 QPalette pal( btncolor, bgcolor ); 1177 QPalette pal( btncolor, bgcolor );
1159 QString color = config.readEntry( "Highlight", "#73adef" ); 1178 QString color = config.readEntry( "Highlight", "#73adef" );
1160 pal.setColor( QColorGroup::Highlight, QColor( color ) ); 1179 pal.setColor( QColorGroup::Highlight, QColor( color ) );
1161 color = config.readEntry( "HighlightedText", "#FFFFFF" ); 1180 color = config.readEntry( "HighlightedText", "#FFFFFF" );
1162 pal.setColor( QColorGroup::HighlightedText, QColor( color ) ); 1181 pal.setColor( QColorGroup::HighlightedText, QColor( color ) );
1163 color = config.readEntry( "Text", "#000000" ); 1182 color = config.readEntry( "Text", "#000000" );
1164 pal.setColor( QColorGroup::Text, QColor( color ) ); 1183 pal.setColor( QColorGroup::Text, QColor( color ) );
1165 color = config.readEntry( "ButtonText", "#000000" ); 1184 color = config.readEntry( "ButtonText", "#000000" );
1166 pal.setColor( QPalette::Active, QColorGroup::ButtonText, QColor( color ) ); 1185 pal.setColor( QPalette::Active, QColorGroup::ButtonText, QColor( color ) );
1167 color = config.readEntry( "Base", "#FFFFFF" ); 1186 color = config.readEntry( "Base", "#FFFFFF" );
1168 pal.setColor( QColorGroup::Base, QColor( color ) ); 1187 pal.setColor( QColorGroup::Base, QColor( color ) );
1169 1188
1170 pal.setColor( QPalette::Disabled, QColorGroup::Text, 1189 pal.setColor( QPalette::Disabled, QColorGroup::Text,
1171 pal.color( QPalette::Active, QColorGroup::Background ).dark() ); 1190 pal.color( QPalette::Active, QColorGroup::Background ).dark() );
1172 1191
1173 setPalette( pal, TRUE ); 1192 setPalette( pal, TRUE );
1174 1193
1175 // Window Decoration 1194 // Window Decoration
1176 QString dec = config.readEntry( "Decoration", "Flat" ); 1195 QString dec = config.readEntry( "Decoration", "Flat" );
1177 1196
1178 // don't set a custom deco 1197 // don't set a custom deco
1179 if ( nostyle & Opie::Force_Decoration ) 1198 if ( nostyle & Opie::Force_Decoration )
1180 dec = ""; 1199 dec = "";
1181 1200
1182 //qDebug ( "Setting Deco: %s -- old %s (%d)", dec.latin1(), d-> decorationName.latin1(), nostyle); 1201 //qDebug ( "Setting Deco: %s -- old %s (%d)", dec.latin1(), d-> decorationName.latin1(), nostyle);
1183 1202
1184 if ( dec != d->decorationName ) { 1203 if ( dec != d->decorationName ) {
1185 qwsSetDecoration( new QPEDecoration( dec ) ); 1204 qwsSetDecoration( new QPEDecoration( dec ) );
1186 d->decorationName = dec; 1205 d->decorationName = dec;
1187 } 1206 }
1188 1207
1189 // Font 1208 // Font
1190 QString ff = config.readEntry( "FontFamily", font().family() ); 1209 QString ff = config.readEntry( "FontFamily", font().family() );
1191 int fs = config.readNumEntry( "FontSize", font().pointSize() ); 1210 int fs = config.readNumEntry( "FontSize", font().pointSize() );
1192 1211
1193 // don't set a custom font 1212 // don't set a custom font
1194 if ( nostyle & Opie::Force_Font ) { 1213 if ( nostyle & Opie::Force_Font ) {
1195 ff = "Vera"; 1214 ff = "Vera";
1196 fs = 10; 1215 fs = 10;
1197 } 1216 }
1198 1217
1199 setFont ( QFont ( ff, fs ), true ); 1218 setFont ( QFont ( ff, fs ), true );
1200 1219
1201#if !defined(OPIE_NO_OVERRIDE_QT) 1220#if !defined(OPIE_NO_OVERRIDE_QT)
1202 // revert to global blocking policy ... 1221 // revert to global blocking policy ...
1203 Opie::force_appearance = config. readBoolEntry ( "ForceStyle", false ) ? Opie::Force_All : Opie::Force_None; 1222 Opie::force_appearance = config. readBoolEntry ( "ForceStyle", false ) ? Opie::Force_All : Opie::Force_None;
1204 Opie::force_appearance &= ~nostyle; 1223 Opie::force_appearance &= ~nostyle;
1205#endif 1224#endif
1206#endif 1225#endif
1207} 1226}
1208 1227
1209void QPEApplication::systemMessage( const QCString& msg, const QByteArray& data ) 1228void QPEApplication::systemMessage( const QCString& msg, const QByteArray& data )
1210{ 1229{
1211#ifdef Q_WS_QWS 1230#ifdef Q_WS_QWS
1212 QDataStream stream( data, IO_ReadOnly ); 1231 QDataStream stream( data, IO_ReadOnly );
1213 if ( msg == "applyStyle()" ) { 1232 if ( msg == "applyStyle()" ) {
1214 applyStyle(); 1233 applyStyle();
1215 } 1234 }
1216 else if ( msg == "toggleApplicationMenu()" ) { 1235 else if ( msg == "toggleApplicationMenu()" ) {
1217 QWidget *active = activeWindow ( ); 1236 QWidget *active = activeWindow ( );
1218 1237
1219 if ( active ) { 1238 if ( active ) {
1220 QPEMenuToolFocusManager *man = QPEMenuToolFocusManager::manager ( ); 1239 QPEMenuToolFocusManager *man = QPEMenuToolFocusManager::manager ( );
1221 bool oldactive = man-> isActive ( ); 1240 bool oldactive = man-> isActive ( );
1222 1241
1223 man-> setActive( !man-> isActive() ); 1242 man-> setActive( !man-> isActive() );
1224 1243
1225 if ( !oldactive && !man-> isActive ( )) { // no menubar to toggle -> try O-Menu 1244 if ( !oldactive && !man-> isActive ( )) { // no menubar to toggle -> try O-Menu
1226 QCopEnvelope e ( "QPE/TaskBar", "toggleStartMenu()" ); 1245 QCopEnvelope e ( "QPE/TaskBar", "toggleStartMenu()" );
1227 } 1246 }
1228 } 1247 }
1229 } 1248 }
1230 else if ( msg == "setDefaultRotation(int)" ) { 1249 else if ( msg == "setDefaultRotation(int)" ) {
1231 if ( type() == GuiServer ) { 1250 if ( type() == GuiServer ) {
1232 int r; 1251 int r;
1233 stream >> r; 1252 stream >> r;
1234 setDefaultRotation( r ); 1253 setDefaultRotation( r );
1235 } 1254 }
1236 } 1255 }
1237 else if ( msg == "setCurrentMode(int,int,int)" ) { // Added: 2003-06-11 by Tim Ansell <mithro@mithis.net> 1256 else if ( msg == "setCurrentMode(int,int,int)" ) { // Added: 2003-06-11 by Tim Ansell <mithro@mithis.net>
1238 if ( type() == GuiServer ) { 1257 if ( type() == GuiServer ) {
1239 int x, y, depth; 1258 int x, y, depth;
1240 stream >> x; 1259 stream >> x;
1241 stream >> y; 1260 stream >> y;
1242 stream >> depth; 1261 stream >> depth;
1243 setCurrentMode( x, y, depth ); 1262 setCurrentMode( x, y, depth );
1244 } 1263 }
1245 } 1264 }
1246 else if ( msg == "reset()" ) { 1265 else if ( msg == "reset()" ) {
1247 if ( type() != GuiServer ) 1266 if ( type() != GuiServer )
1248 reset(); 1267 reset();
1249 } 1268 }
1250 else if ( msg == "setCurrentRotation(int)" ) { 1269 else if ( msg == "setCurrentRotation(int)" ) {
1251 int r; 1270 int r;
1252 stream >> r; 1271 stream >> r;
1253 setCurrentRotation( r ); 1272 setCurrentRotation( r );
1254 } 1273 }
1255 else if ( msg == "shutdown()" ) { 1274 else if ( msg == "shutdown()" ) {
1256 if ( type() == GuiServer ) 1275 if ( type() == GuiServer )
1257 shutdown(); 1276 shutdown();
1258 } 1277 }
1259 else if ( msg == "quit()" ) { 1278 else if ( msg == "quit()" ) {
1260 if ( type() != GuiServer ) 1279 if ( type() != GuiServer )
1261 tryQuit(); 1280 tryQuit();
1262 } 1281 }
1263 else if ( msg == "forceQuit()" ) { 1282 else if ( msg == "forceQuit()" ) {
1264 if ( type() != GuiServer ) 1283 if ( type() != GuiServer )
1265 quit(); 1284 quit();
1266 } 1285 }
1267 else if ( msg == "restart()" ) { 1286 else if ( msg == "restart()" ) {
1268 if ( type() == GuiServer ) 1287 if ( type() == GuiServer )
1269 restart(); 1288 restart();
1270 } 1289 }
1271 else if ( msg == "language(QString)" ) { 1290 else if ( msg == "language(QString)" ) {
1272 if ( type() == GuiServer ) { 1291 if ( type() == GuiServer ) {
1273 QString l; 1292 QString l;
1274 stream >> l; 1293 stream >> l;
1275 QString cl = getenv( "LANG" ); 1294 QString cl = getenv( "LANG" );
1276 if ( cl != l ) { 1295 if ( cl != l ) {
1277 if ( l.isNull() ) 1296 if ( l.isNull() )
1278 unsetenv( "LANG" ); 1297 unsetenv( "LANG" );
1279 else 1298 else
1280 setenv( "LANG", l.latin1(), 1 ); 1299 setenv( "LANG", l.latin1(), 1 );
1281 restart(); 1300 restart();
1282 } 1301 }
1283 } 1302 }
1284 } 1303 }
1285 else if ( msg == "timeChange(QString)" ) { 1304 else if ( msg == "timeChange(QString)" ) {
1286 QString t; 1305 QString t;
1287 stream >> t; 1306 stream >> t;
1288 if ( t.isNull() ) 1307 if ( t.isNull() )
1289 unsetenv( "TZ" ); 1308 unsetenv( "TZ" );
1290 else 1309 else
1291 setenv( "TZ", t.latin1(), 1 ); 1310 setenv( "TZ", t.latin1(), 1 );
1292 // emit the signal so everyone else knows... 1311 // emit the signal so everyone else knows...
1293 emit timeChanged(); 1312 emit timeChanged();
1294 } 1313 }
1295 else if ( msg == "addAlarm(QDateTime,QCString,QCString,int)" ) { 1314 else if ( msg == "addAlarm(QDateTime,QCString,QCString,int)" ) {
1296 if ( type() == GuiServer ) { 1315 if ( type() == GuiServer ) {
1297 QDateTime when; 1316 QDateTime when;
1298 QCString channel, message; 1317 QCString channel, message;
1299 int data; 1318 int data;
1300 stream >> when >> channel >> message >> data; 1319 stream >> when >> channel >> message >> data;
1301 AlarmServer::addAlarm( when, channel, message, data ); 1320 AlarmServer::addAlarm( when, channel, message, data );
1302 } 1321 }
1303 } 1322 }
1304 else if ( msg == "deleteAlarm(QDateTime,QCString,QCString,int)" ) { 1323 else if ( msg == "deleteAlarm(QDateTime,QCString,QCString,int)" ) {
1305 if ( type() == GuiServer ) { 1324 if ( type() == GuiServer ) {
1306 QDateTime when; 1325 QDateTime when;
1307 QCString channel, message; 1326 QCString channel, message;
1308 int data; 1327 int data;
1309 stream >> when >> channel >> message >> data; 1328 stream >> when >> channel >> message >> data;
1310 AlarmServer::deleteAlarm( when, channel, message, data ); 1329 AlarmServer::deleteAlarm( when, channel, message, data );
1311 } 1330 }
1312 } 1331 }
1313 else if ( msg == "clockChange(bool)" ) { 1332 else if ( msg == "clockChange(bool)" ) {
1314 int tmp; 1333 int tmp;
1315 stream >> tmp; 1334 stream >> tmp;
1316 emit clockChanged( tmp ); 1335 emit clockChanged( tmp );
1317 } 1336 }
1318 else if ( msg == "weekChange(bool)" ) { 1337 else if ( msg == "weekChange(bool)" ) {
1319 int tmp; 1338 int tmp;
1320 stream >> tmp; 1339 stream >> tmp;
1321 emit weekChanged( tmp ); 1340 emit weekChanged( tmp );
1322 } 1341 }
1323 else if ( msg == "setDateFormat(DateFormat)" ) { 1342 else if ( msg == "setDateFormat(DateFormat)" ) {
1324 DateFormat tmp; 1343 DateFormat tmp;
1325 stream >> tmp; 1344 stream >> tmp;
1326 emit dateFormatChanged( tmp ); 1345 emit dateFormatChanged( tmp );
1327 } 1346 }
1328 else if ( msg == "setVolume(int,int)" ) { 1347 else if ( msg == "setVolume(int,int)" ) {
1329 int t, v; 1348 int t, v;
1330 stream >> t >> v; 1349 stream >> t >> v;
1331 setVolume( t, v ); 1350 setVolume( t, v );
1332 emit volumeChanged( muted ); 1351 emit volumeChanged( muted );
1333 } 1352 }
1334 else if ( msg == "volumeChange(bool)" ) { 1353 else if ( msg == "volumeChange(bool)" ) {
1335 stream >> muted; 1354 stream >> muted;
1336 setVolume(); 1355 setVolume();
1337 emit volumeChanged( muted ); 1356 emit volumeChanged( muted );
1338 } 1357 }
1339 else if ( msg == "setMic(int,int)" ) { // Added: 2002-02-08 by Jeremy Cowgar <jc@cowgar.com> 1358 else if ( msg == "setMic(int,int)" ) { // Added: 2002-02-08 by Jeremy Cowgar <jc@cowgar.com>
1340 int t, v; 1359 int t, v;
1341 stream >> t >> v; 1360 stream >> t >> v;
1342 setMic( t, v ); 1361 setMic( t, v );
1343 emit micChanged( micMuted ); 1362 emit micChanged( micMuted );
1344 } 1363 }
1345 else if ( msg == "micChange(bool)" ) { // Added: 2002-02-08 by Jeremy Cowgar <jc@cowgar.com> 1364 else if ( msg == "micChange(bool)" ) { // Added: 2002-02-08 by Jeremy Cowgar <jc@cowgar.com>
1346 stream >> micMuted; 1365 stream >> micMuted;
1347 setMic(); 1366 setMic();
1348 emit micChanged( micMuted ); 1367 emit micChanged( micMuted );
1349 } 1368 }
1350 else if ( msg == "setBass(int,int)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org> 1369 else if ( msg == "setBass(int,int)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org>
1351 int t, v; 1370 int t, v;
1352 stream >> t >> v; 1371 stream >> t >> v;
1353 setBass( t, v ); 1372 setBass( t, v );
1354 } 1373 }
1355 else if ( msg == "bassChange(bool)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org> 1374 else if ( msg == "bassChange(bool)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org>
1356 setBass(); 1375 setBass();
1357 } 1376 }
1358 else if ( msg == "setTreble(int,int)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org> 1377 else if ( msg == "setTreble(int,int)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org>
1359 int t, v; 1378 int t, v;
1360 stream >> t >> v; 1379 stream >> t >> v;
1361 setTreble( t, v ); 1380 setTreble( t, v );
1362 } 1381 }
1363 else if ( msg == "trebleChange(bool)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org> 1382 else if ( msg == "trebleChange(bool)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org>
1364 setTreble(); 1383 setTreble();
1365 } else if ( msg == "getMarkedText()" ) { 1384 } else if ( msg == "getMarkedText()" ) {
1366 if ( type() == GuiServer ) { 1385 if ( type() == GuiServer ) {
1367 const ushort unicode = 'C'-'@'; 1386 const ushort unicode = 'C'-'@';
1368 const int scan = Key_C; 1387 const int scan = Key_C;
1369 qwsServer->processKeyEvent( unicode, scan, ControlButton, TRUE, FALSE ); 1388 qwsServer->processKeyEvent( unicode, scan, ControlButton, TRUE, FALSE );
1370 qwsServer->processKeyEvent( unicode, scan, ControlButton, FALSE, FALSE ); 1389 qwsServer->processKeyEvent( unicode, scan, ControlButton, FALSE, FALSE );
1371 } 1390 }
1372 } else if ( msg == "newChannel(QString)") { 1391 } else if ( msg == "newChannel(QString)") {
1373 QString myChannel = "QPE/Application/" + d->appName; 1392 QString myChannel = "QPE/Application/" + d->appName;
1374 QString channel; 1393 QString channel;
1375 stream >> channel; 1394 stream >> channel;
1376 if (channel == myChannel) { 1395 if (channel == myChannel) {
1377 processQCopFile(); 1396 processQCopFile();
1378 d->sendQCopQ(); 1397 d->sendQCopQ();
1379 } 1398 }
1380 } 1399 }
1381 1400
1382 1401
1383#endif 1402#endif
1384} 1403}
1385 1404
1386 1405
1387 1406
1388 1407
1389 1408
1390/*! 1409/*!
1391 \internal 1410 \internal
1392*/ 1411*/
1393bool QPEApplication::raiseAppropriateWindow() 1412bool QPEApplication::raiseAppropriateWindow()
1394{ 1413{
1395 bool r=FALSE; 1414 bool r=FALSE;
1396 1415
1397 // 1. Raise the main widget 1416 // 1. Raise the main widget
1398 QWidget *top = d->qpe_main_widget; 1417 QWidget *top = d->qpe_main_widget;
1399 if ( !top ) top = mainWidget(); 1418 if ( !top ) top = mainWidget();
1400 1419
1401 if ( top && d->keep_running ) { 1420 if ( top && d->keep_running ) {
1402 if ( top->isVisible() ) 1421 if ( top->isVisible() )
1403 r = TRUE; 1422 r = TRUE;
1404 else if (d->preloaded) { 1423 else if (d->preloaded) {
1405 // We are preloaded and not visible.. pretend we just started.. 1424 // We are preloaded and not visible.. pretend we just started..
1406#ifndef QT_NO_COP 1425#ifndef QT_NO_COP
1407 QCopEnvelope e("QPE/System", "fastAppShowing(QString)"); 1426 QCopEnvelope e("QPE/System", "fastAppShowing(QString)");
1408 e << d->appName; 1427 e << d->appName;
1409#endif 1428#endif
1410 } 1429 }
1411 1430
1412 d->show_mx(top,d->nomaximize, d->appName); 1431 d->show_mx(top,d->nomaximize, d->appName);
1413 top->raise(); 1432 top->raise();
1414 } 1433 }
1415 1434
1416 QWidget *topm = activeModalWidget(); 1435 QWidget *topm = activeModalWidget();
1417 1436
1418 // 2. Raise any parentless widgets (except top and topm, as they 1437 // 2. Raise any parentless widgets (except top and topm, as they
1419 // are raised before and after this loop). Order from most 1438 // are raised before and after this loop). Order from most
1420 // recently raised as deepest to least recently as top, so 1439 // recently raised as deepest to least recently as top, so
1421 // that repeated calls cycle through widgets. 1440 // that repeated calls cycle through widgets.
1422 QWidgetList *list = topLevelWidgets(); 1441 QWidgetList *list = topLevelWidgets();
1423 if ( list ) { 1442 if ( list ) {
1424 bool foundlast = FALSE; 1443 bool foundlast = FALSE;
1425 QWidget* topsub = 0; 1444 QWidget* topsub = 0;
1426 if ( d->lastraised ) { 1445 if ( d->lastraised ) {
1427 for (QWidget* w = list->first(); w; w = list->next()) { 1446 for (QWidget* w = list->first(); w; w = list->next()) {
1428 if ( !w->parentWidget() && w != topm && w->isVisible() && !w->isDesktop() ) { 1447 if ( !w->parentWidget() && w != topm && w->isVisible() && !w->isDesktop() ) {
1429 if ( w == d->lastraised ) 1448 if ( w == d->lastraised )
1430 foundlast = TRUE; 1449 foundlast = TRUE;
1431 if ( foundlast ) { 1450 if ( foundlast ) {
1432 w->raise(); 1451 w->raise();
1433 topsub = w; 1452 topsub = w;
1434 } 1453 }
1435 } 1454 }
1436 } 1455 }
1437 } 1456 }
1438 for (QWidget* w = list->first(); w; w = list->next()) { 1457 for (QWidget* w = list->first(); w; w = list->next()) {
1439 if ( !w->parentWidget() && w != topm && w->isVisible() && !w->isDesktop() ) { 1458 if ( !w->parentWidget() && w != topm && w->isVisible() && !w->isDesktop() ) {
1440 if ( w == d->lastraised ) 1459 if ( w == d->lastraised )
1441 break; 1460 break;
1442 w->raise(); 1461 w->raise();
1443 topsub = w; 1462 topsub = w;
1444 } 1463 }
1445 } 1464 }
1446 d->lastraised = topsub; 1465 d->lastraised = topsub;
1447 delete list; 1466 delete list;
1448 } 1467 }
1449 1468
1450 // 3. Raise the active modal widget. 1469 // 3. Raise the active modal widget.
1451 if ( topm && topm != top ) { 1470 if ( topm && topm != top ) {
1452 topm->show(); 1471 topm->show();
1453 topm->raise(); 1472 topm->raise();
1454 // If we haven't already handled the fastAppShowing message 1473 // If we haven't already handled the fastAppShowing message
1455 if (!top && d->preloaded) { 1474 if (!top && d->preloaded) {
1456#ifndef QT_NO_COP 1475#ifndef QT_NO_COP
1457 QCopEnvelope e("QPE/System", "fastAppShowing(QString)"); 1476 QCopEnvelope e("QPE/System", "fastAppShowing(QString)");
1458 e << d->appName; 1477 e << d->appName;
1459#endif 1478#endif
1460 } 1479 }
1461 r = FALSE; 1480 r = FALSE;
1462 } 1481 }
1463 1482
1464 return r; 1483 return r;
1465} 1484}
1466 1485
1467 1486
1468void QPEApplication::pidMessage( const QCString& msg, const QByteArray& data) 1487void QPEApplication::pidMessage( const QCString& msg, const QByteArray& data)
1469{ 1488{
1470#ifdef Q_WS_QWS 1489#ifdef Q_WS_QWS
1471 1490
1472 if ( msg == "quit()" ) { 1491 if ( msg == "quit()" ) {
1473 tryQuit(); 1492 tryQuit();
1474 } 1493 }
1475 else if ( msg == "quitIfInvisible()" ) { 1494 else if ( msg == "quitIfInvisible()" ) {
1476 if ( d->qpe_main_widget && !d->qpe_main_widget->isVisible() ) 1495 if ( d->qpe_main_widget && !d->qpe_main_widget->isVisible() )
1477 quit(); 1496 quit();
1478 } 1497 }
1479 else if ( msg == "close()" ) { 1498 else if ( msg == "close()" ) {
1480 hideOrQuit(); 1499 hideOrQuit();
1481 } 1500 }
1482 else if ( msg == "disablePreload()" ) { 1501 else if ( msg == "disablePreload()" ) {
1483 d->preloaded = FALSE; 1502 d->preloaded = FALSE;
1484 d->keep_running = TRUE; 1503 d->keep_running = TRUE;
1485 /* so that quit will quit */ 1504 /* so that quit will quit */
1486 } 1505 }
1487 else if ( msg == "enablePreload()" ) { 1506 else if ( msg == "enablePreload()" ) {
1488 if (d->qpe_main_widget) 1507 if (d->qpe_main_widget)
1489 d->preloaded = TRUE; 1508 d->preloaded = TRUE;
1490 d->keep_running = TRUE; 1509 d->keep_running = TRUE;
1491 /* so next quit won't quit */ 1510 /* so next quit won't quit */
1492 } 1511 }
1493 else if ( msg == "raise()" ) { 1512 else if ( msg == "raise()" ) {
1494 d->keep_running = TRUE; 1513 d->keep_running = TRUE;
1495 d->notbusysent = FALSE; 1514 d->notbusysent = FALSE;
1496 raiseAppropriateWindow(); 1515 raiseAppropriateWindow();
1497 // Tell the system we're still chugging along... 1516 // Tell the system we're still chugging along...
1498 QCopEnvelope e("QPE/System", "appRaised(QString)"); 1517 QCopEnvelope e("QPE/System", "appRaised(QString)");
1499 e << d->appName; 1518 e << d->appName;
1500 } 1519 }
1501 else if ( msg == "flush()" ) { 1520 else if ( msg == "flush()" ) {
1502 emit flush(); 1521 emit flush();
1503 // we need to tell the desktop 1522 // we need to tell the desktop
1504 QCopEnvelope e( "QPE/Desktop", "flushDone(QString)" ); 1523 QCopEnvelope e( "QPE/Desktop", "flushDone(QString)" );
1505 e << d->appName; 1524 e << d->appName;
1506 } 1525 }
1507 else if ( msg == "reload()" ) { 1526 else if ( msg == "reload()" ) {
1508 emit reload(); 1527 emit reload();
1509 } 1528 }
1510 else if ( msg == "setDocument(QString)" ) { 1529 else if ( msg == "setDocument(QString)" ) {
1511 d->keep_running = TRUE; 1530 d->keep_running = TRUE;
1512 QDataStream stream( data, IO_ReadOnly ); 1531 QDataStream stream( data, IO_ReadOnly );
1513 QString doc; 1532 QString doc;
1514 stream >> doc; 1533 stream >> doc;
1515 QWidget *mw = mainWidget(); 1534 QWidget *mw = mainWidget();
1516 if ( !mw ) 1535 if ( !mw )
1517 mw = d->qpe_main_widget; 1536 mw = d->qpe_main_widget;
1518 if ( mw ) 1537 if ( mw )
1519 Global::setDocument( mw, doc ); 1538 Global::setDocument( mw, doc );
1520 1539
1521 } else if ( msg == "QPEProcessQCop()" ) { 1540 } else if ( msg == "QPEProcessQCop()" ) {
1522 processQCopFile(); 1541 processQCopFile();
1523 d->sendQCopQ(); 1542 d->sendQCopQ();
1524 }else 1543 }else
1525 { 1544 {
1526 bool p = d->keep_running; 1545 bool p = d->keep_running;
1527 d->keep_running = FALSE; 1546 d->keep_running = FALSE;
1528 emit appMessage( msg, data); 1547 emit appMessage( msg, data);
1529 if ( d->keep_running ) { 1548 if ( d->keep_running ) {
1530 d->notbusysent = FALSE; 1549 d->notbusysent = FALSE;
1531 raiseAppropriateWindow(); 1550 raiseAppropriateWindow();
1532 if ( !p ) { 1551 if ( !p ) {
1533 // Tell the system we're still chugging along... 1552 // Tell the system we're still chugging along...
1534#ifndef QT_NO_COP 1553#ifndef QT_NO_COP
1535 QCopEnvelope e("QPE/System", "appRaised(QString)"); 1554 QCopEnvelope e("QPE/System", "appRaised(QString)");
1536 e << d->appName; 1555 e << d->appName;
1537#endif 1556#endif
1538 } 1557 }
1539 } 1558 }
1540 if ( p ) 1559 if ( p )
1541 d->keep_running = p; 1560 d->keep_running = p;
1542 } 1561 }
1543#endif 1562#endif
1544} 1563}
1545 1564
1546 1565
1547/*! 1566/*!
1548 Sets widget \a mw as the mainWidget() and shows it. For small windows, 1567 Sets widget \a mw as the mainWidget() and shows it. For small windows,
1549 consider passing TRUE for \a nomaximize rather than the default FALSE. 1568 consider passing TRUE for \a nomaximize rather than the default FALSE.
1550 1569
1551 \sa showMainDocumentWidget() 1570 \sa showMainDocumentWidget()
1552*/ 1571*/
1553void QPEApplication::showMainWidget( QWidget* mw, bool nomaximize ) 1572void QPEApplication::showMainWidget( QWidget* mw, bool nomaximize )
1554{ 1573{
1555 d->show(mw, nomaximize ); 1574 d->show(mw, nomaximize );
1556} 1575}
1557 1576
1558/*! 1577/*!
1559 Sets widget \a mw as the mainWidget() and shows it. For small windows, 1578 Sets widget \a mw as the mainWidget() and shows it. For small windows,
1560 consider passing TRUE for \a nomaximize rather than the default FALSE. 1579 consider passing TRUE for \a nomaximize rather than the default FALSE.
1561 1580
1562 This calls designates the application as 1581 This calls designates the application as
1563 a \link docwidget.html document-oriented\endlink application. 1582 a \link docwidget.html document-oriented\endlink application.
1564 1583
1565 The \a mw widget \e must have this slot: setDocument(const QString&). 1584 The \a mw widget \e must have this slot: setDocument(const QString&).
1566 1585
1567 \sa showMainWidget() 1586 \sa showMainWidget()
1568*/ 1587*/
1569void QPEApplication::showMainDocumentWidget( QWidget* mw, bool nomaximize ) 1588void QPEApplication::showMainDocumentWidget( QWidget* mw, bool nomaximize )
1570{ 1589{
1571 if ( mw && argc() == 2 ) 1590 if ( mw && argc() == 2 )
1572 Global::setDocument( mw, QString::fromUtf8(argv()[1]) ); 1591 Global::setDocument( mw, QString::fromUtf8(argv()[1]) );
1573 1592
1574 1593
1575 d->show(mw, nomaximize ); 1594 d->show(mw, nomaximize );
1576} 1595}
1577 1596
1578 1597
1579/*! 1598/*!
1580 If an application is started via a \link qcop.html QCop\endlink 1599 If an application is started via a \link qcop.html QCop\endlink
1581 message, the application will process the \link qcop.html 1600 message, the application will process the \link qcop.html
1582 QCop\endlink message and then quit. If the application calls this 1601 QCop\endlink message and then quit. If the application calls this
1583 function while processing a \link qcop.html QCop\endlink message, 1602 function while processing a \link qcop.html QCop\endlink message,
1584 after processing its outstanding \link qcop.html QCop\endlink 1603 after processing its outstanding \link qcop.html QCop\endlink
1585 messages the application will start 'properly' and show itself. 1604 messages the application will start 'properly' and show itself.
1586 1605
1587 \sa keepRunning() 1606 \sa keepRunning()
1588*/ 1607*/
1589void QPEApplication::setKeepRunning() 1608void QPEApplication::setKeepRunning()
1590{ 1609{
1591 if ( qApp && qApp->inherits( "QPEApplication" ) ) { 1610 if ( qApp && qApp->inherits( "QPEApplication" ) ) {
1592 QPEApplication * qpeApp = ( QPEApplication* ) qApp; 1611 QPEApplication * qpeApp = ( QPEApplication* ) qApp;
1593 qpeApp->d->keep_running = TRUE; 1612 qpeApp->d->keep_running = TRUE;
1594 } 1613 }
1595} 1614}
1596 1615
1597/*! 1616/*!
1598 Returns TRUE if the application will quit after processing the 1617 Returns TRUE if the application will quit after processing the
1599 current list of qcop messages; otherwise returns FALSE. 1618 current list of qcop messages; otherwise returns FALSE.
1600 1619
1601 \sa setKeepRunning() 1620 \sa setKeepRunning()
1602*/ 1621*/
1603bool QPEApplication::keepRunning() const 1622bool QPEApplication::keepRunning() const
1604{ 1623{
1605 return d->keep_running; 1624 return d->keep_running;
1606} 1625}
1607 1626
1608/*! 1627/*!
1609 \internal 1628 \internal
1610*/ 1629*/
1611void QPEApplication::internalSetStyle( const QString &style ) 1630void QPEApplication::internalSetStyle( const QString &style )
1612{ 1631{
1613#if QT_VERSION >= 300 1632#if QT_VERSION >= 300
1614 if ( style == "QPE" ) { 1633 if ( style == "QPE" ) {
1615 setStyle( new QPEStyle ); 1634 setStyle( new QPEStyle );
1616 } 1635 }
1617 else { 1636 else {
1618 QStyle *s = QStyleFactory::create( style ); 1637 QStyle *s = QStyleFactory::create( style );
1619 if ( s ) 1638 if ( s )
1620 setStyle( s ); 1639 setStyle( s );
1621 } 1640 }
1622#else 1641#else
1623 if ( style == "Windows" ) { 1642 if ( style == "Windows" ) {
1624 setStyle( new QWindowsStyle ); 1643 setStyle( new QWindowsStyle );
1625 } 1644 }
1626 else if ( style == "QPE" ) { 1645 else if ( style == "QPE" ) {
1627 setStyle( new QPEStyle ); 1646 setStyle( new QPEStyle );
1628 } 1647 }
1629 else if ( style == "Light" ) { 1648 else if ( style == "Light" ) {
1630 setStyle( new LightStyle ); 1649 setStyle( new LightStyle );
1631 } 1650 }
1632#ifndef QT_NO_STYLE_PLATINUM 1651#ifndef QT_NO_STYLE_PLATINUM
1633 else if ( style == "Platinum" ) { 1652 else if ( style == "Platinum" ) {
1634 setStyle( new QPlatinumStyle ); 1653 setStyle( new QPlatinumStyle );
1635 } 1654 }
1636#endif 1655#endif
1637#ifndef QT_NO_STYLE_MOTIF 1656#ifndef QT_NO_STYLE_MOTIF
1638 else if ( style == "Motif" ) { 1657 else if ( style == "Motif" ) {
1639 setStyle( new QMotifStyle ); 1658 setStyle( new QMotifStyle );
1640 } 1659 }
1641#endif 1660#endif
1642#ifndef QT_NO_STYLE_MOTIFPLUS 1661#ifndef QT_NO_STYLE_MOTIFPLUS
1643 else if ( style == "MotifPlus" ) { 1662 else if ( style == "MotifPlus" ) {
1644 setStyle( new QMotifPlusStyle ); 1663 setStyle( new QMotifPlusStyle );
1645 } 1664 }
1646#endif 1665#endif
1647 1666
1648 else { 1667 else {
1649 QStyle *sty = 0; 1668 QStyle *sty = 0;
1650 QString path = QPEApplication::qpeDir ( ) + "/plugins/styles/"; 1669 QString path = QPEApplication::qpeDir ( ) + "/plugins/styles/";
1651 1670
1671#ifdef Q_OS_MACX
1672 if ( style. find ( ".dylib" ) > 0 )
1673 path += style;
1674 else
1675 path = path + "lib" + style. lower ( ) + ".dylib"; // compatibility
1676#else
1652 if ( style. find ( ".so" ) > 0 ) 1677 if ( style. find ( ".so" ) > 0 )
1653 path += style; 1678 path += style;
1654 else 1679 else
1655 path = path + "lib" + style. lower ( ) + ".so"; // compatibility 1680 path = path + "lib" + style. lower ( ) + ".so"; // compatibility
1656 1681#endif
1657 static QLibrary *lastlib = 0; 1682 static QLibrary *lastlib = 0;
1658 static StyleInterface *lastiface = 0; 1683 static StyleInterface *lastiface = 0;
1659 1684
1660 QLibrary *lib = new QLibrary ( path ); 1685 QLibrary *lib = new QLibrary ( path );
1661 StyleInterface *iface = 0; 1686 StyleInterface *iface = 0;
1662 1687
1663 if (( lib-> queryInterface ( IID_Style, ( QUnknownInterface ** ) &iface ) == QS_OK ) && iface ) 1688 if (( lib-> queryInterface ( IID_Style, ( QUnknownInterface ** ) &iface ) == QS_OK ) && iface )
1664 sty = iface-> style ( ); 1689 sty = iface-> style ( );
1665 1690
1666 if ( sty ) { 1691 if ( sty ) {
1667 setStyle ( sty ); 1692 setStyle ( sty );
1668 1693
1669 if ( lastiface ) 1694 if ( lastiface )
1670 lastiface-> release ( ); 1695 lastiface-> release ( );
1671 lastiface = iface; 1696 lastiface = iface;
1672 1697
1673 if ( lastlib ) { 1698 if ( lastlib ) {
1674 lastlib-> unload ( ); 1699 lastlib-> unload ( );
1675 delete lastlib; 1700 delete lastlib;
1676 } 1701 }
1677 lastlib = lib; 1702 lastlib = lib;
1678 } 1703 }
1679 else { 1704 else {
1680 if ( iface ) 1705 if ( iface )
1681 iface-> release ( ); 1706 iface-> release ( );
1682 delete lib; 1707 delete lib;
1683 1708
1684 setStyle ( new LightStyle ( )); 1709 setStyle ( new LightStyle ( ));
1685 } 1710 }
1686 } 1711 }
1687#endif 1712#endif
1688} 1713}
1689 1714
1690/*! 1715/*!
1691 \internal 1716 \internal
1692*/ 1717*/
1693void QPEApplication::prepareForTermination( bool willrestart ) 1718void QPEApplication::prepareForTermination( bool willrestart )
1694{ 1719{
1695 if ( willrestart ) { 1720 if ( willrestart ) {
1696 // Draw a big wait icon, the image can be altered in later revisions 1721 // Draw a big wait icon, the image can be altered in later revisions
1697 // QWidget *d = QApplication::desktop(); 1722 // QWidget *d = QApplication::desktop();
1698 QImage img = Resource::loadImage( "launcher/new_wait" ); 1723 QImage img = Resource::loadImage( "launcher/new_wait" );
1699 QPixmap pix; 1724 QPixmap pix;
1700 pix.convertFromImage( img.smoothScale( 1 * img.width(), 1 * img.height() ) ); 1725 pix.convertFromImage( img.smoothScale( 1 * img.width(), 1 * img.height() ) );
1701 QLabel *lblWait = new QLabel( 0, "wait hack!", QWidget::WStyle_Customize | 1726 QLabel *lblWait = new QLabel( 0, "wait hack!", QWidget::WStyle_Customize |
1702 QWidget::WStyle_NoBorder | QWidget::WStyle_Tool ); 1727 QWidget::WStyle_NoBorder | QWidget::WStyle_Tool );
1703 lblWait->setPixmap( pix ); 1728 lblWait->setPixmap( pix );
1704 lblWait->setAlignment( QWidget::AlignCenter ); 1729 lblWait->setAlignment( QWidget::AlignCenter );
1705 lblWait->show(); 1730 lblWait->show();
1706 lblWait->showMaximized(); 1731 lblWait->showMaximized();
1707 } 1732 }
1708#ifndef SINGLE_APP 1733#ifndef SINGLE_APP
1709 { QCopEnvelope envelope( "QPE/System", "forceQuit()" ); 1734 { QCopEnvelope envelope( "QPE/System", "forceQuit()" );
1710 } 1735 }
1711 processEvents(); // ensure the message goes out. 1736 processEvents(); // ensure the message goes out.
1712 sleep( 1 ); // You have 1 second to comply. 1737 sleep( 1 ); // You have 1 second to comply.
1713#endif 1738#endif
1714} 1739}
1715 1740
1716/*! 1741/*!
1717 \internal 1742 \internal
1718*/ 1743*/
1719void QPEApplication::shutdown() 1744void QPEApplication::shutdown()
1720{ 1745{
1721 // Implement in server's QPEApplication subclass 1746 // Implement in server's QPEApplication subclass
1722} 1747}
1723 1748
1724/*! 1749/*!
1725 \internal 1750 \internal
1726*/ 1751*/
1727void QPEApplication::restart() 1752void QPEApplication::restart()
1728{ 1753{
1729 // Implement in server's QPEApplication subclass 1754 // Implement in server's QPEApplication subclass
1730} 1755}
1731 1756
1732static QPtrDict<void>* stylusDict = 0; 1757static QPtrDict<void>* stylusDict = 0;
1733static void createDict() 1758static void createDict()
1734{ 1759{
1735 if ( !stylusDict ) 1760 if ( !stylusDict )
1736 stylusDict = new QPtrDict<void>; 1761 stylusDict = new QPtrDict<void>;
1737} 1762}
1738 1763
1739/*! 1764/*!
1740 Returns the current StylusMode for widget \a w. 1765 Returns the current StylusMode for widget \a w.
1741 1766
1742 \sa setStylusOperation() StylusMode 1767 \sa setStylusOperation() StylusMode
1743*/ 1768*/
1744QPEApplication::StylusMode QPEApplication::stylusOperation( QWidget* w ) 1769QPEApplication::StylusMode QPEApplication::stylusOperation( QWidget* w )
1745{ 1770{
1746 if ( stylusDict ) 1771 if ( stylusDict )
1747 return ( StylusMode ) ( int ) stylusDict->find( w ); 1772 return ( StylusMode ) ( int ) stylusDict->find( w );
1748 return LeftOnly; 1773 return LeftOnly;
1749} 1774}
1750 1775
1751/*! 1776/*!
1752 \enum QPEApplication::StylusMode 1777 \enum QPEApplication::StylusMode
1753 1778
1754 \value LeftOnly the stylus only generates LeftButton 1779 \value LeftOnly the stylus only generates LeftButton
1755 events (the default). 1780 events (the default).
1756 \value RightOnHold the stylus generates RightButton events 1781 \value RightOnHold the stylus generates RightButton events
1757 if the user uses the press-and-hold gesture. 1782 if the user uses the press-and-hold gesture.
1758 1783
1759 \sa setStylusOperation() stylusOperation() 1784 \sa setStylusOperation() stylusOperation()
1760*/ 1785*/
1761 1786
1762/*! 1787/*!
1763 Causes widget \a w to receive mouse events according to the stylus 1788 Causes widget \a w to receive mouse events according to the stylus
1764 \a mode. 1789 \a mode.
1765 1790
1766 \sa stylusOperation() StylusMode 1791 \sa stylusOperation() StylusMode
1767*/ 1792*/
1768void QPEApplication::setStylusOperation( QWidget * w, StylusMode mode ) 1793void QPEApplication::setStylusOperation( QWidget * w, StylusMode mode )
1769{ 1794{
1770 createDict(); 1795 createDict();
1771 if ( mode == LeftOnly ) { 1796 if ( mode == LeftOnly ) {
1772 stylusDict->remove 1797 stylusDict->remove
1773 ( w ); 1798 ( w );
1774 w->removeEventFilter( qApp ); 1799 w->removeEventFilter( qApp );
1775 } 1800 }
1776 else { 1801 else {
1777 stylusDict->insert( w, ( void* ) mode ); 1802 stylusDict->insert( w, ( void* ) mode );
1778 connect( w, SIGNAL( destroyed() ), qApp, SLOT( removeSenderFromStylusDict() ) ); 1803 connect( w, SIGNAL( destroyed() ), qApp, SLOT( removeSenderFromStylusDict() ) );
1779 w->installEventFilter( qApp ); 1804 w->installEventFilter( qApp );
1780 } 1805 }
1781} 1806}
1782 1807
1783 1808
1784/*! 1809/*!
1785 \reimp 1810 \reimp
1786*/ 1811*/
1787bool QPEApplication::eventFilter( QObject *o, QEvent *e ) 1812bool QPEApplication::eventFilter( QObject *o, QEvent *e )
1788{ 1813{
1789 if ( !o->isWidgetType() ) 1814 if ( !o->isWidgetType() )
1790 return FALSE; 1815 return FALSE;
1791 1816
1792 if ( stylusDict && e->type() >= QEvent::MouseButtonPress && e->type() <= QEvent::MouseMove ) { 1817 if ( stylusDict && e->type() >= QEvent::MouseButtonPress && e->type() <= QEvent::MouseMove ) {
1793 QMouseEvent * me = ( QMouseEvent* ) e; 1818 QMouseEvent * me = ( QMouseEvent* ) e;
1794 StylusMode mode = (StylusMode)(int)stylusDict->find(o); 1819 StylusMode mode = (StylusMode)(int)stylusDict->find(o);
1795 switch (mode) { 1820 switch (mode) {
1796 case RightOnHold: 1821 case RightOnHold:
1797 switch ( me->type() ) { 1822 switch ( me->type() ) {
1798 case QEvent::MouseButtonPress: 1823 case QEvent::MouseButtonPress:
1799 if ( me->button() == LeftButton ) { 1824 if ( me->button() == LeftButton ) {
1800 if (!d->presstimer ) 1825 if (!d->presstimer )
1801 d->presstimer = startTimer(500); // #### pref. 1826 d->presstimer = startTimer(500); // #### pref.
1802 d->presswidget = (QWidget*)o; 1827 d->presswidget = (QWidget*)o;
1803 d->presspos = me->pos(); 1828 d->presspos = me->pos();
1804 d->rightpressed = FALSE; 1829 d->rightpressed = FALSE;
1805 } 1830 }
1806 break; 1831 break;
1807 case QEvent::MouseMove: 1832 case QEvent::MouseMove:
1808 if (d->presstimer && (me->pos() - d->presspos).manhattanLength() > 8) { 1833 if (d->presstimer && (me->pos() - d->presspos).manhattanLength() > 8) {
1809 killTimer(d->presstimer); 1834 killTimer(d->presstimer);
1810 d->presstimer = 0; 1835 d->presstimer = 0;
1811 } 1836 }
1812 break; 1837 break;
1813 case QEvent::MouseButtonRelease: 1838 case QEvent::MouseButtonRelease:
1814 if ( me->button() == LeftButton ) { 1839 if ( me->button() == LeftButton ) {
1815 if ( d->presstimer ) { 1840 if ( d->presstimer ) {
1816 killTimer(d->presstimer); 1841 killTimer(d->presstimer);
1817 d->presstimer = 0; 1842 d->presstimer = 0;
1818 } 1843 }
1819 if ( d->rightpressed && d->presswidget ) { 1844 if ( d->rightpressed && d->presswidget ) {
1820 // Right released 1845 // Right released
1821 postEvent( d->presswidget, 1846 postEvent( d->presswidget,
1822 new QMouseEvent( QEvent::MouseButtonRelease, me->pos(), 1847 new QMouseEvent( QEvent::MouseButtonRelease, me->pos(),
1823 RightButton, LeftButton + RightButton ) ); 1848 RightButton, LeftButton + RightButton ) );
1824 // Left released, off-widget 1849 // Left released, off-widget
1825 postEvent( d->presswidget, 1850 postEvent( d->presswidget,
1826 new QMouseEvent( QEvent::MouseMove, QPoint( -1, -1), 1851 new QMouseEvent( QEvent::MouseMove, QPoint( -1, -1),
1827 LeftButton, LeftButton ) ); 1852 LeftButton, LeftButton ) );
1828 postEvent( d->presswidget, 1853 postEvent( d->presswidget,
1829 new QMouseEvent( QEvent::MouseButtonRelease, QPoint( -1, -1), 1854 new QMouseEvent( QEvent::MouseButtonRelease, QPoint( -1, -1),
1830 LeftButton, LeftButton ) ); 1855 LeftButton, LeftButton ) );
1831 d->rightpressed = FALSE; 1856 d->rightpressed = FALSE;
1832 return TRUE; // don't send the real Left release 1857 return TRUE; // don't send the real Left release
1833 } 1858 }
1834 } 1859 }
1835 break; 1860 break;
1836 default: 1861 default:
1837 break; 1862 break;
1838 } 1863 }
1839 break; 1864 break;
1840 default: 1865 default:
1841 ; 1866 ;
1842 } 1867 }
1843 } 1868 }
1844 else if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) { 1869 else if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) {
1845 QKeyEvent *ke = (QKeyEvent *)e; 1870 QKeyEvent *ke = (QKeyEvent *)e;
1846 if ( ke->key() == Key_Enter ) { 1871 if ( ke->key() == Key_Enter ) {
1847 if ( o->isA( "QRadioButton" ) || o->isA( "QCheckBox" ) ) { 1872 if ( o->isA( "QRadioButton" ) || o->isA( "QCheckBox" ) ) {
1848 postEvent( o, new QKeyEvent( e->type(), Key_Space, ' ', 1873 postEvent( o, new QKeyEvent( e->type(), Key_Space, ' ',
1849 ke->state(), " ", ke->isAutoRepeat(), ke->count() ) ); 1874 ke->state(), " ", ke->isAutoRepeat(), ke->count() ) );
1850 return TRUE; 1875 return TRUE;
1851 } 1876 }
1852 } 1877 }
1853 } 1878 }
1854 return FALSE; 1879 return FALSE;
1855} 1880}
1856 1881
1857/*! 1882/*!
1858 \reimp 1883 \reimp
1859*/ 1884*/
1860void QPEApplication::timerEvent( QTimerEvent *e ) 1885void QPEApplication::timerEvent( QTimerEvent *e )
1861{ 1886{
1862 if ( e->timerId() == d->presstimer && d->presswidget ) { 1887 if ( e->timerId() == d->presstimer && d->presswidget ) {
1863 // Right pressed 1888 // Right pressed
1864 postEvent( d->presswidget, 1889 postEvent( d->presswidget,
1865 new QMouseEvent( QEvent::MouseButtonPress, d->presspos, 1890 new QMouseEvent( QEvent::MouseButtonPress, d->presspos,
1866 RightButton, LeftButton ) ); 1891 RightButton, LeftButton ) );
1867 killTimer( d->presstimer ); 1892 killTimer( d->presstimer );
1868 d->presstimer = 0; 1893 d->presstimer = 0;
1869 d->rightpressed = TRUE; 1894 d->rightpressed = TRUE;
1870 } 1895 }
1871} 1896}
1872 1897
1873void QPEApplication::removeSenderFromStylusDict() 1898void QPEApplication::removeSenderFromStylusDict()
1874{ 1899{
1875 stylusDict->remove 1900 stylusDict->remove
1876 ( ( void* ) sender() ); 1901 ( ( void* ) sender() );
1877 if ( d->presswidget == sender() ) 1902 if ( d->presswidget == sender() )
1878 d->presswidget = 0; 1903 d->presswidget = 0;
1879} 1904}
1880 1905
1881/*! 1906/*!
1882 \internal 1907 \internal
1883*/ 1908*/
1884bool QPEApplication::keyboardGrabbed() const 1909bool QPEApplication::keyboardGrabbed() const
1885{ 1910{
1886 return d->kbgrabbed; 1911 return d->kbgrabbed;
1887} 1912}
1888 1913
1889 1914
1890/*! 1915/*!
1891 Reverses the effect of grabKeyboard(). This is called automatically 1916 Reverses the effect of grabKeyboard(). This is called automatically
1892 on program exit. 1917 on program exit.
1893*/ 1918*/
1894void QPEApplication::ungrabKeyboard() 1919void QPEApplication::ungrabKeyboard()
1895{ 1920{
1896 ((QPEApplication *) qApp )-> d-> kbgrabbed = false; 1921 ((QPEApplication *) qApp )-> d-> kbgrabbed = false;
1897} 1922}
1898 1923
1899/*! 1924/*!
1900 Grabs the physical keyboard keys, e.g. the application's launching 1925 Grabs the physical keyboard keys, e.g. the application's launching
1901 keys. Instead of launching applications when these keys are pressed 1926 keys. Instead of launching applications when these keys are pressed
1902 the signals emitted are sent to this application instead. Some games 1927 the signals emitted are sent to this application instead. Some games
1903 programs take over the launch keys in this way to make interaction 1928 programs take over the launch keys in this way to make interaction
1904 easier. 1929 easier.
1905 1930
1906 \sa ungrabKeyboard() 1931 \sa ungrabKeyboard()
1907*/ 1932*/
1908void QPEApplication::grabKeyboard() 1933void QPEApplication::grabKeyboard()
1909{ 1934{
1910 ((QPEApplication *) qApp )-> d-> kbgrabbed = true; 1935 ((QPEApplication *) qApp )-> d-> kbgrabbed = true;
1911} 1936}
1912 1937
1913/*! 1938/*!
1914 \reimp 1939 \reimp
1915*/ 1940*/
1916int QPEApplication::exec() 1941int QPEApplication::exec()
1917{ 1942{
1918 d->qcopQok = true; 1943 d->qcopQok = true;
1919#ifndef QT_NO_COP 1944#ifndef QT_NO_COP
1920 d->sendQCopQ(); 1945 d->sendQCopQ();
1921 if ( !d->keep_running ) 1946 if ( !d->keep_running )
1922 processEvents(); // we may have received QCop messages in the meantime. 1947 processEvents(); // we may have received QCop messages in the meantime.
1923#endif 1948#endif
1924 1949
1925 if ( d->keep_running ) 1950 if ( d->keep_running )
1926 //|| d->qpe_main_widget && d->qpe_main_widget->isVisible() ) 1951 //|| d->qpe_main_widget && d->qpe_main_widget->isVisible() )
1927 return QApplication::exec(); 1952 return QApplication::exec();
1928 1953
1929#ifndef QT_NO_COP 1954#ifndef QT_NO_COP
1930 1955
1931 { 1956 {
1932 QCopEnvelope e( "QPE/System", "closing(QString)" ); 1957 QCopEnvelope e( "QPE/System", "closing(QString)" );
1933 e << d->appName; 1958 e << d->appName;
1934 } 1959 }
1935#endif 1960#endif
1936 processEvents(); 1961 processEvents();
1937 return 0; 1962 return 0;
1938} 1963}
1939 1964
1940/*! 1965/*!
1941 \internal 1966 \internal
1942 External request for application to quit. Quits if possible without 1967 External request for application to quit. Quits if possible without
1943 loosing state. 1968 loosing state.
1944*/ 1969*/
1945void QPEApplication::tryQuit() 1970void QPEApplication::tryQuit()
1946{ 1971{
1947 if ( activeModalWidget() || strcmp( argv() [ 0 ], "embeddedkonsole" ) == 0 ) 1972 if ( activeModalWidget() || strcmp( argv() [ 0 ], "embeddedkonsole" ) == 0 )
1948 return ; // Inside modal loop or konsole. Too hard to save state. 1973 return ; // Inside modal loop or konsole. Too hard to save state.
1949#ifndef QT_NO_COP 1974#ifndef QT_NO_COP
1950 1975
1951 { 1976 {
1952 QCopEnvelope e( "QPE/System", "closing(QString)" ); 1977 QCopEnvelope e( "QPE/System", "closing(QString)" );
1953 e << d->appName; 1978 e << d->appName;
1954 } 1979 }
1955#endif 1980#endif
1956 processEvents(); 1981 processEvents();
1957 1982
1958 quit(); 1983 quit();
1959} 1984}
1960 1985
1961/*! 1986/*!
1962 \internal 1987 \internal
1963*/ 1988*/
1964void QPEApplication::installTranslation( const QString& baseName ) { 1989void QPEApplication::installTranslation( const QString& baseName ) {
1965 QTranslator* trans = new QTranslator(this); 1990 QTranslator* trans = new QTranslator(this);
1966 QString tfn = qpeDir() + "/i18n/"+baseName; 1991 QString tfn = qpeDir() + "/i18n/"+baseName;
1967 if ( trans->load( tfn ) ) 1992 if ( trans->load( tfn ) )
1968 installTranslator( trans ); 1993 installTranslator( trans );
1969 else 1994 else
1970 delete trans; 1995 delete trans;
1971} 1996}
1972 1997
1973/*! 1998/*!
1974 \internal 1999 \internal
1975 User initiated quit. Makes the window 'Go Away'. If preloaded this means 2000 User initiated quit. Makes the window 'Go Away'. If preloaded this means
1976 hiding the window. If not it means quitting the application. 2001 hiding the window. If not it means quitting the application.
1977 As this is user initiated we don't need to check state. 2002 As this is user initiated we don't need to check state.
1978*/ 2003*/
1979void QPEApplication::hideOrQuit() 2004void QPEApplication::hideOrQuit()
1980{ 2005{
1981 processEvents(); 2006 processEvents();
1982 2007
1983 // If we are a preloaded application we don't actually quit, so emit 2008 // If we are a preloaded application we don't actually quit, so emit
1984 // a System message indicating we're quasi-closing. 2009 // a System message indicating we're quasi-closing.
1985 if ( d->preloaded && d->qpe_main_widget ) 2010 if ( d->preloaded && d->qpe_main_widget )
1986#ifndef QT_NO_COP 2011#ifndef QT_NO_COP
1987 2012
1988 { 2013 {
1989 QCopEnvelope e("QPE/System", "fastAppHiding(QString)" ); 2014 QCopEnvelope e("QPE/System", "fastAppHiding(QString)" );
1990 e << d->appName; 2015 e << d->appName;
1991 d->qpe_main_widget->hide(); 2016 d->qpe_main_widget->hide();
1992 } 2017 }
1993#endif 2018#endif
1994 else 2019 else
1995 quit(); 2020 quit();
1996} 2021}
1997 2022
1998#if (__GNUC__ > 2 ) 2023#if (__GNUC__ > 2 )
1999extern "C" void __cxa_pure_virtual(); 2024extern "C" void __cxa_pure_virtual();
2000 2025
2001void __cxa_pure_virtual() 2026void __cxa_pure_virtual()
2002{ 2027{
2003 fprintf( stderr, "Pure virtual called\n"); 2028 fprintf( stderr, "Pure virtual called\n");
2004 abort(); 2029 abort();
2005 2030
2006} 2031}
2007 2032
2008#endif 2033#endif
2009 2034
2010 2035
2011#if defined(OPIE_NEW_MALLOC) 2036#if defined(OPIE_NEW_MALLOC)
2012 2037
2013// The libraries with the skiff package (and possibly others) have 2038// The libraries with the skiff package (and possibly others) have
2014// completely useless implementations of builtin new and delete that 2039// completely useless implementations of builtin new and delete that
2015// use about 50% of your CPU. Here we revert to the simple libc 2040// use about 50% of your CPU. Here we revert to the simple libc
2016// functions. 2041// functions.
2017 2042
2018void* operator new[]( size_t size ) 2043void* operator new[]( size_t size )
2019{ 2044{
2020 return malloc( size ); 2045 return malloc( size );
2021} 2046}
2022 2047
2023void* operator new( size_t size ) 2048void* operator new( size_t size )
2024{ 2049{
2025 return malloc( size ); 2050 return malloc( size );
2026} 2051}
2027 2052
2028void operator delete[]( void* p ) 2053void operator delete[]( void* p )
2029{ 2054{
2030 free( p ); 2055 free( p );
2031} 2056}
2032 2057
2033void operator delete[]( void* p, size_t /*size*/ ) 2058void operator delete[]( void* p, size_t /*size*/ )
2034{ 2059{
2035 free( p ); 2060 free( p );
2036} 2061}
2037 2062
2038 2063
2039void operator delete( void* p ) 2064void operator delete( void* p )
2040{ 2065{
2041 free( p ); 2066 free( p );
2042} 2067}
2043 2068
2044void operator delete( void* p, size_t /*size*/ ) 2069void operator delete( void* p, size_t /*size*/ )
2045{ 2070{
2046 free( p ); 2071 free( p );
2047} 2072}
2048 2073
2049#endif 2074#endif
2050 2075
2051#if ( QT_VERSION <= 230 ) && !defined(SINGLE_APP) 2076#if ( QT_VERSION <= 230 ) && !defined(SINGLE_APP)
2052#include <qwidgetlist.h> 2077#include <qwidgetlist.h>
2053#ifdef QWS 2078#ifdef QWS
2054#include <qgfx_qws.h> 2079#include <qgfx_qws.h>
2055extern QRect qt_maxWindowRect; 2080extern QRect qt_maxWindowRect;
2056void qt_setMaxWindowRect(const QRect& r ) 2081void qt_setMaxWindowRect(const QRect& r )
2057{ 2082{
2058 qt_maxWindowRect = qt_screen->mapFromDevice( r, 2083 qt_maxWindowRect = qt_screen->mapFromDevice( r,
2059 qt_screen->mapToDevice( QSize( qt_screen->width(), qt_screen->height() ) ) ); 2084 qt_screen->mapToDevice( QSize( qt_screen->width(), qt_screen->height() ) ) );
2060 // Re-resize any maximized windows 2085 // Re-resize any maximized windows
2061 QWidgetList* l = QApplication::topLevelWidgets(); 2086 QWidgetList* l = QApplication::topLevelWidgets();
2062 if ( l ) { 2087 if ( l ) {
2063 QWidget * w = l->first(); 2088 QWidget * w = l->first();
2064 while ( w ) { 2089 while ( w ) {
2065 if ( w->isVisible() && w->isMaximized() ) { 2090 if ( w->isVisible() && w->isMaximized() ) {
2066 w->showMaximized(); 2091 w->showMaximized();
2067 } 2092 }
2068 w = l->next(); 2093 w = l->next();
2069 } 2094 }
2070 delete l; 2095 delete l;
2071 } 2096 }
2072} 2097}
2073#endif 2098#endif
2074#endif 2099#endif
diff --git a/library/qpedecoration_qws.cpp b/library/qpedecoration_qws.cpp
index 933542d..bac1a75 100644
--- a/library/qpedecoration_qws.cpp
+++ b/library/qpedecoration_qws.cpp
@@ -1,918 +1,926 @@
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 <qapplication.h> 21#include <qapplication.h>
22#include <qstyle.h> 22#include <qstyle.h>
23#include <qwidget.h> 23#include <qwidget.h>
24#include <qpainter.h> 24#include <qpainter.h>
25#include <qtimer.h> 25#include <qtimer.h>
26#include <qwhatsthis.h> 26#include <qwhatsthis.h>
27#include "qcopenvelope_qws.h" 27#include "qcopenvelope_qws.h"
28#include "qpedecoration_qws.h" 28#include "qpedecoration_qws.h"
29#include <qdialog.h> 29#include <qdialog.h>
30#include <qdrawutil.h> 30#include <qdrawutil.h>
31#include <qgfx_qws.h> 31#include <qgfx_qws.h>
32#include "qpeapplication.h" 32#include "qpeapplication.h"
33#include "resource.h" 33#include "resource.h"
34#include "global.h" 34#include "global.h"
35#include "qlibrary.h" 35#include "qlibrary.h"
36#include "windowdecorationinterface.h" 36#include "windowdecorationinterface.h"
37#include <qfile.h> 37#include <qfile.h>
38#include <qsignal.h> 38#include <qsignal.h>
39 39
40#include <stdlib.h> 40#include <stdlib.h>
41 41
42extern QRect qt_maxWindowRect; 42extern QRect qt_maxWindowRect;
43 43
44#define WHATSTHIS_MODE 44#define WHATSTHIS_MODE
45 45
46#ifndef QT_NO_QWS_QPE_WM_STYLE 46#ifndef QT_NO_QWS_QPE_WM_STYLE
47 47
48#ifndef QT_NO_IMAGEIO_XPM 48#ifndef QT_NO_IMAGEIO_XPM
49 49
50/* XPM */ 50/* XPM */
51static const char * const qpe_close_xpm[] = { 51static const char * const qpe_close_xpm[] = {
52"16 16 3 1", 52"16 16 3 1",
53" c None", 53" c None",
54". c #FFFFFF", 54". c #FFFFFF",
55"+ c #000000", 55"+ c #000000",
56" ", 56" ",
57" ", 57" ",
58" ..... ", 58" ..... ",
59" ..+++++.. ", 59" ..+++++.. ",
60" .+++++++++. ", 60" .+++++++++. ",
61" .+..+++..+. ", 61" .+..+++..+. ",
62" .++...+...++. ", 62" .++...+...++. ",
63" .+++.....+++. ", 63" .+++.....+++. ",
64" .++++...++++. ", 64" .++++...++++. ",
65" .+++.....+++. ", 65" .+++.....+++. ",
66" .++...+...++. ", 66" .++...+...++. ",
67" .+..+++..+. ", 67" .+..+++..+. ",
68" .+++++++++. ", 68" .+++++++++. ",
69" ..+++++.. ", 69" ..+++++.. ",
70" ..... ", 70" ..... ",
71" "}; 71" "};
72 72
73/* XPM */ 73/* XPM */
74static const char * const qpe_accept_xpm[] = { 74static const char * const qpe_accept_xpm[] = {
75"16 16 3 1", 75"16 16 3 1",
76" c None", 76" c None",
77". c #FFFFFF", 77". c #FFFFFF",
78"+ c #000000", 78"+ c #000000",
79" ", 79" ",
80" ", 80" ",
81" ..... ", 81" ..... ",
82" ..+++++.. ", 82" ..+++++.. ",
83" .+++++++++. ", 83" .+++++++++. ",
84" .+++++++++. ", 84" .+++++++++. ",
85" .+++++++..++. ", 85" .+++++++..++. ",
86" .++.+++...++. ", 86" .++.+++...++. ",
87" .+...+...+++. ", 87" .+...+...+++. ",
88" .+......++++. ", 88" .+......++++. ",
89" .++....+++++. ", 89" .++....+++++. ",
90" .++..+++++. ", 90" .++..+++++. ",
91" .+++++++++. ", 91" .+++++++++. ",
92" ..+++++.. ", 92" ..+++++.. ",
93" ..... ", 93" ..... ",
94" "}; 94" "};
95 95
96#endif // QT_NO_IMAGEIO_XPM 96#endif // QT_NO_IMAGEIO_XPM
97 97
98class HackWidget : public QWidget 98class HackWidget : public QWidget
99{ 99{
100public: 100public:
101 bool needsOk() { 101 bool needsOk() {
102 return (getWState() & WState_Reserved1 ) || 102 return (getWState() & WState_Reserved1 ) ||
103 (inherits( "QDialog" ) && !inherits( "QMessageBox" ) ); 103 (inherits( "QDialog" ) && !inherits( "QMessageBox" ) );
104 } 104 }
105}; 105};
106 106
107static QImage scaleButton( const QImage &img, int height ) 107static QImage scaleButton( const QImage &img, int height )
108{ 108{
109 if ( img.height() != 0 && img.height() != height ) { 109 if ( img.height() != 0 && img.height() != height ) {
110 return img.smoothScale( img.width()*height/img.height(), height ); 110 return img.smoothScale( img.width()*height/img.height(), height );
111 } else { 111 } else {
112 return img; 112 return img;
113 } 113 }
114} 114}
115 115
116class TLWidget : public QWidget 116class TLWidget : public QWidget
117{ 117{
118public: 118public:
119 QWSManager *manager() 119 QWSManager *manager()
120 { 120 {
121 return topData()->qwsManager; 121 return topData()->qwsManager;
122 } 122 }
123 123
124 QTLWExtra *topExtra() 124 QTLWExtra *topExtra()
125 { 125 {
126 return topData(); 126 return topData();
127 } 127 }
128 128
129 void setWState( uint s ) { QWidget::setWState( s ); } 129 void setWState( uint s ) { QWidget::setWState( s ); }
130 void clearWState( uint s ) { QWidget::clearWState( s ); } 130 void clearWState( uint s ) { QWidget::clearWState( s ); }
131}; 131};
132 132
133 133
134QPEManager::QPEManager( QPEDecoration *d, QObject *parent ) 134QPEManager::QPEManager( QPEDecoration *d, QObject *parent )
135 : QObject( parent ), decoration( d ), helpState(0), inWhatsThis(FALSE) 135 : QObject( parent ), decoration( d ), helpState(0), inWhatsThis(FALSE)
136{ 136{
137 wtTimer = new QTimer( this ); 137 wtTimer = new QTimer( this );
138 connect( wtTimer, SIGNAL(timeout()), this, SLOT(whatsThisTimeout()) ); 138 connect( wtTimer, SIGNAL(timeout()), this, SLOT(whatsThisTimeout()) );
139} 139}
140 140
141 141
142void QPEManager::updateActive() 142void QPEManager::updateActive()
143{ 143{
144 QWidget *newActive = qApp->activeWindow(); 144 QWidget *newActive = qApp->activeWindow();
145 if ( newActive && (QWidget*)active == newActive ) 145 if ( newActive && (QWidget*)active == newActive )
146 return; 146 return;
147 147
148 if ( active && (!newActive || ((TLWidget *)newActive)->manager()) ) { 148 if ( active && (!newActive || ((TLWidget *)newActive)->manager()) ) {
149 ((TLWidget *)(QWidget*)active)->manager()->removeEventFilter( this ); 149 ((TLWidget *)(QWidget*)active)->manager()->removeEventFilter( this );
150 } 150 }
151 151
152 if ( newActive && ((TLWidget *)newActive)->manager() ) { 152 if ( newActive && ((TLWidget *)newActive)->manager() ) {
153 active = newActive; 153 active = newActive;
154 ((TLWidget *)(QWidget*)active)->manager()->installEventFilter( this ); 154 ((TLWidget *)(QWidget*)active)->manager()->installEventFilter( this );
155 } else if ( !newActive ) { 155 } else if ( !newActive ) {
156 active = 0; 156 active = 0;
157 } 157 }
158} 158}
159 159
160int QPEManager::pointInQpeRegion( QWidget *w, const QPoint &p ) 160int QPEManager::pointInQpeRegion( QWidget *w, const QPoint &p )
161{ 161{
162 QRect rect(w->geometry()); 162 QRect rect(w->geometry());
163 163
164 if ( decoration->region( w, rect, 164 if ( decoration->region( w, rect,
165 (QWSDecoration::Region)QPEDecoration::Help ).contains(p) ) 165 (QWSDecoration::Region)QPEDecoration::Help ).contains(p) )
166 return QPEDecoration::Help; 166 return QPEDecoration::Help;
167 167
168 for (int i = QWSDecoration::LastRegion; i >= QWSDecoration::Title; i--) { 168 for (int i = QWSDecoration::LastRegion; i >= QWSDecoration::Title; i--) {
169 if (decoration->region(w, rect, (QWSDecoration::Region)i).contains(p)) 169 if (decoration->region(w, rect, (QWSDecoration::Region)i).contains(p))
170 return (QWSDecoration::Region)i; 170 return (QWSDecoration::Region)i;
171 } 171 }
172 172
173 return QWSDecoration::None; 173 return QWSDecoration::None;
174} 174}
175 175
176bool QPEManager::eventFilter( QObject *o, QEvent *e ) 176bool QPEManager::eventFilter( QObject *o, QEvent *e )
177{ 177{
178 QWSManager *mgr = (QWSManager *)o; 178 QWSManager *mgr = (QWSManager *)o;
179 QWidget *w = mgr->widget(); 179 QWidget *w = mgr->widget();
180 switch ( e->type() ) { 180 switch ( e->type() ) {
181 case QEvent::MouseButtonPress: 181 case QEvent::MouseButtonPress:
182 { 182 {
183 pressTime = QTime::currentTime(); 183 pressTime = QTime::currentTime();
184 QPoint p = ((QMouseEvent*)e)->globalPos(); 184 QPoint p = ((QMouseEvent*)e)->globalPos();
185 int inRegion = pointInQpeRegion( w, p ); 185 int inRegion = pointInQpeRegion( w, p );
186#ifdef WHATSTHIS_MODE 186#ifdef WHATSTHIS_MODE
187 if ( !w->geometry().contains(p) && QWhatsThis::inWhatsThisMode() ) { 187 if ( !w->geometry().contains(p) && QWhatsThis::inWhatsThisMode() ) {
188 QString text; 188 QString text;
189 switch ( inRegion ) { 189 switch ( inRegion ) {
190 case QWSDecoration::Close: 190 case QWSDecoration::Close:
191 if ( ((HackWidget*)w)->needsOk() ) 191 if ( ((HackWidget*)w)->needsOk() )
192 text = QObject::tr("Click to close this window, discarding changes."); 192 text = QObject::tr("Click to close this window, discarding changes.");
193 else 193 else
194 text = QObject::tr("Click to close this window."); 194 text = QObject::tr("Click to close this window.");
195 break; 195 break;
196 case QWSDecoration::Minimize: 196 case QWSDecoration::Minimize:
197 text = QObject::tr("Click to close this window and apply changes."); 197 text = QObject::tr("Click to close this window and apply changes.");
198 break; 198 break;
199 case QWSDecoration::Maximize: 199 case QWSDecoration::Maximize:
200 if ( w->isMaximized() ) 200 if ( w->isMaximized() )
201 text = QObject::tr("Click to make this window moveable."); 201 text = QObject::tr("Click to make this window moveable.");
202 else 202 else
203 text = QObject::tr("Click to make this window use all available screen area."); 203 text = QObject::tr("Click to make this window use all available screen area.");
204 break; 204 break;
205 default: 205 default:
206 break; 206 break;
207 } 207 }
208 QWhatsThis::leaveWhatsThisMode( text ); 208 QWhatsThis::leaveWhatsThisMode( text );
209 whatsThisTimeout(); 209 whatsThisTimeout();
210 helpState = 0; 210 helpState = 0;
211 return true; 211 return true;
212 } 212 }
213#endif 213#endif
214 if ( inRegion == QPEDecoration::Help ) { 214 if ( inRegion == QPEDecoration::Help ) {
215#ifdef WHATSTHIS_MODE 215#ifdef WHATSTHIS_MODE
216 wtTimer->start( 400, TRUE ); 216 wtTimer->start( 400, TRUE );
217#endif 217#endif
218 helpState = QWSButton::Clicked|QWSButton::MouseOver; 218 helpState = QWSButton::Clicked|QWSButton::MouseOver;
219 drawButton( w, QPEDecoration::Help, helpState ); 219 drawButton( w, QPEDecoration::Help, helpState );
220 return true; 220 return true;
221 } 221 }
222 } 222 }
223 break; 223 break;
224 case QEvent::MouseButtonRelease: 224 case QEvent::MouseButtonRelease:
225 if ( helpState & QWSButton::Clicked ) { 225 if ( helpState & QWSButton::Clicked ) {
226 wtTimer->stop(); 226 wtTimer->stop();
227 helpState = 0; 227 helpState = 0;
228 drawButton( w, QPEDecoration::Help, helpState ); 228 drawButton( w, QPEDecoration::Help, helpState );
229 QPoint p = ((QMouseEvent*)e)->globalPos(); 229 QPoint p = ((QMouseEvent*)e)->globalPos();
230 if ( pointInQpeRegion( w, p ) == QPEDecoration::Help ) { 230 if ( pointInQpeRegion( w, p ) == QPEDecoration::Help ) {
231 decoration->help( w ); 231 decoration->help( w );
232 } 232 }
233 return true; 233 return true;
234 } 234 }
235 break; 235 break;
236 case QEvent::MouseMove: 236 case QEvent::MouseMove:
237 if ( helpState & QWSButton::Clicked ) { 237 if ( helpState & QWSButton::Clicked ) {
238 int oldState = helpState; 238 int oldState = helpState;
239 QPoint p = ((QMouseEvent*)e)->globalPos(); 239 QPoint p = ((QMouseEvent*)e)->globalPos();
240 if ( pointInQpeRegion( w, p ) == QPEDecoration::Help ) { 240 if ( pointInQpeRegion( w, p ) == QPEDecoration::Help ) {
241 helpState = QWSButton::Clicked|QWSButton::MouseOver; 241 helpState = QWSButton::Clicked|QWSButton::MouseOver;
242 } else { 242 } else {
243 helpState = 0; 243 helpState = 0;
244 } 244 }
245 if ( helpState != oldState ) 245 if ( helpState != oldState )
246 drawButton( w, QPEDecoration::Help, helpState ); 246 drawButton( w, QPEDecoration::Help, helpState );
247 } 247 }
248 break; 248 break;
249 default: 249 default:
250 break; 250 break;
251 } 251 }
252 return QObject::eventFilter( o, e ); 252 return QObject::eventFilter( o, e );
253} 253}
254 254
255void QPEManager::drawButton( QWidget *w, QPEDecoration::QPERegion r, int state ) 255void QPEManager::drawButton( QWidget *w, QPEDecoration::QPERegion r, int state )
256{ 256{
257 QPainter painter(w); 257 QPainter painter(w);
258 QRegion rgn = ((TLWidget *)w)->topExtra()->decor_allocated_region; 258 QRegion rgn = ((TLWidget *)w)->topExtra()->decor_allocated_region;
259 painter.internalGfx()->setWidgetDeviceRegion( rgn ); 259 painter.internalGfx()->setWidgetDeviceRegion( rgn );
260 painter.setClipRegion(decoration->region(w, w->rect(),QWSDecoration::All)); 260 painter.setClipRegion(decoration->region(w, w->rect(),QWSDecoration::All));
261 decoration->paintButton( &painter, w, (QWSDecoration::Region)r, state ); 261 decoration->paintButton( &painter, w, (QWSDecoration::Region)r, state );
262} 262}
263 263
264void QPEManager::drawTitle( QWidget *w ) 264void QPEManager::drawTitle( QWidget *w )
265{ 265{
266 QPainter painter(w); 266 QPainter painter(w);
267 QRegion rgn = ((TLWidget *)w)->topExtra()->decor_allocated_region; 267 QRegion rgn = ((TLWidget *)w)->topExtra()->decor_allocated_region;
268 painter.internalGfx()->setWidgetDeviceRegion( rgn ); 268 painter.internalGfx()->setWidgetDeviceRegion( rgn );
269 painter.setClipRegion(decoration->region(w, w->rect(),QWSDecoration::All)); 269 painter.setClipRegion(decoration->region(w, w->rect(),QWSDecoration::All));
270 decoration->paint( &painter, w ); 270 decoration->paint( &painter, w );
271 decoration->paintButton(&painter, w, QWSDecoration::Menu, 0); 271 decoration->paintButton(&painter, w, QWSDecoration::Menu, 0);
272 decoration->paintButton(&painter, w, QWSDecoration::Close, 0); 272 decoration->paintButton(&painter, w, QWSDecoration::Close, 0);
273 decoration->paintButton(&painter, w, QWSDecoration::Minimize, 0); 273 decoration->paintButton(&painter, w, QWSDecoration::Minimize, 0);
274 decoration->paintButton(&painter, w, QWSDecoration::Maximize, 0); 274 decoration->paintButton(&painter, w, QWSDecoration::Maximize, 0);
275} 275}
276 276
277void QPEManager::whatsThisTimeout() 277void QPEManager::whatsThisTimeout()
278{ 278{
279 if ( !QWhatsThis::inWhatsThisMode() ) { 279 if ( !QWhatsThis::inWhatsThisMode() ) {
280 if ( inWhatsThis ) { 280 if ( inWhatsThis ) {
281 if ( whatsThis ) { 281 if ( whatsThis ) {
282 QWidget *w = whatsThis; 282 QWidget *w = whatsThis;
283 whatsThis = 0; 283 whatsThis = 0;
284 drawTitle( w ); 284 drawTitle( w );
285 } 285 }
286 wtTimer->stop(); 286 wtTimer->stop();
287 } else { 287 } else {
288 QWhatsThis::enterWhatsThisMode(); 288 QWhatsThis::enterWhatsThisMode();
289 helpState = 0; 289 helpState = 0;
290 updateActive(); 290 updateActive();
291 if ( active ) { 291 if ( active ) {
292 whatsThis = active; 292 whatsThis = active;
293 drawTitle( active ); 293 drawTitle( active );
294 // check periodically to see if we've left whats this mode 294 // check periodically to see if we've left whats this mode
295 wtTimer->start( 250 ); 295 wtTimer->start( 250 );
296 } 296 }
297 } 297 }
298 inWhatsThis = !inWhatsThis; 298 inWhatsThis = !inWhatsThis;
299 } 299 }
300} 300}
301 301
302//=========================================================================== 302//===========================================================================
303 303
304static QImage *okImage( int th ) 304static QImage *okImage( int th )
305{ 305{
306 static QImage *i = 0; 306 static QImage *i = 0;
307 if ( !i || i->height() != th ) { 307 if ( !i || i->height() != th ) {
308 delete i; 308 delete i;
309 i = new QImage(scaleButton(Resource::loadImage("OKButton"),th)); 309 i = new QImage(scaleButton(Resource::loadImage("OKButton"),th));
310 } 310 }
311 return i; 311 return i;
312} 312}
313 313
314static QImage *closeImage( int th ) 314static QImage *closeImage( int th )
315{ 315{
316 static QImage *i = 0; 316 static QImage *i = 0;
317 if ( !i || i->height() != th ) { 317 if ( !i || i->height() != th ) {
318 delete i; 318 delete i;
319 i = new QImage(scaleButton(Resource::loadImage("CloseButton"),th)); 319 i = new QImage(scaleButton(Resource::loadImage("CloseButton"),th));
320 } 320 }
321 return i; 321 return i;
322} 322}
323 323
324static QImage *helpImage( int th ) 324static QImage *helpImage( int th )
325{ 325{
326 static QImage *i = 0; 326 static QImage *i = 0;
327 if ( !i || i->height() != th ) { 327 if ( !i || i->height() != th ) {
328 delete i; 328 delete i;
329 i = new QImage(scaleButton(Resource::loadImage("HelpButton"),th)); 329 i = new QImage(scaleButton(Resource::loadImage("HelpButton"),th));
330 } 330 }
331 return i; 331 return i;
332} 332}
333 333
334static QImage *maximizeImage( int th ) 334static QImage *maximizeImage( int th )
335{ 335{
336 static QImage *i = 0; 336 static QImage *i = 0;
337 if ( !i || i->height() != th ) { 337 if ( !i || i->height() != th ) {
338 delete i; 338 delete i;
339 i = new QImage(scaleButton(Resource::loadImage("MaximizeButton"),th)); 339 i = new QImage(scaleButton(Resource::loadImage("MaximizeButton"),th));
340 } 340 }
341 return i; 341 return i;
342} 342}
343 343
344int WindowDecorationInterface::metric( Metric m, const WindowData *wd ) const 344int WindowDecorationInterface::metric( Metric m, const WindowData *wd ) const
345{ 345{
346 switch ( m ) { 346 switch ( m ) {
347 case TitleHeight: 347 case TitleHeight:
348 if ( QApplication::desktop()->height() > 320 ) 348 if ( QApplication::desktop()->height() > 320 )
349 return 19; 349 return 19;
350 else 350 else
351 return 15; 351 return 15;
352 case LeftBorder: 352 case LeftBorder:
353 case RightBorder: 353 case RightBorder:
354 case TopBorder: 354 case TopBorder:
355 case BottomBorder: 355 case BottomBorder:
356 return 4; 356 return 4;
357 case OKWidth: 357 case OKWidth:
358 return okImage(metric(TitleHeight,wd))->width(); 358 return okImage(metric(TitleHeight,wd))->width();
359 case CloseWidth: 359 case CloseWidth:
360 return closeImage(metric(TitleHeight,wd))->width(); 360 return closeImage(metric(TitleHeight,wd))->width();
361 case HelpWidth: 361 case HelpWidth:
362 return helpImage(metric(TitleHeight,wd))->width(); 362 return helpImage(metric(TitleHeight,wd))->width();
363 case MaximizeWidth: 363 case MaximizeWidth:
364 return maximizeImage(metric(TitleHeight,wd))->width(); 364 return maximizeImage(metric(TitleHeight,wd))->width();
365 case CornerGrabSize: 365 case CornerGrabSize:
366 return 16; 366 return 16;
367 } 367 }
368 368
369 return 0; 369 return 0;
370} 370}
371 371
372void WindowDecorationInterface::drawArea( Area a, QPainter *p, const WindowData *wd ) const 372void WindowDecorationInterface::drawArea( Area a, QPainter *p, const WindowData *wd ) const
373{ 373{
374 int th = metric( TitleHeight, wd ); 374 int th = metric( TitleHeight, wd );
375 QRect r = wd->rect; 375 QRect r = wd->rect;
376 376
377 switch ( a ) { 377 switch ( a ) {
378 case Border: 378 case Border:
379 { 379 {
380 const QColorGroup &cg = wd->palette.active(); 380 const QColorGroup &cg = wd->palette.active();
381 qDrawWinPanel(p, r.x()-metric(LeftBorder,wd), 381 qDrawWinPanel(p, r.x()-metric(LeftBorder,wd),
382 r.y()-th-metric(TopBorder,wd), 382 r.y()-th-metric(TopBorder,wd),
383 r.width()+metric(LeftBorder,wd)+metric(RightBorder,wd), 383 r.width()+metric(LeftBorder,wd)+metric(RightBorder,wd),
384 r.height()+th+metric(TopBorder,wd)+metric(BottomBorder,wd), 384 r.height()+th+metric(TopBorder,wd)+metric(BottomBorder,wd),
385 cg, FALSE, &cg.brush(QColorGroup::Background)); 385 cg, FALSE, &cg.brush(QColorGroup::Background));
386 } 386 }
387 break; 387 break;
388 case Title: 388 case Title:
389 { 389 {
390 const QColorGroup &cg = wd->palette.active(); 390 const QColorGroup &cg = wd->palette.active();
391 QBrush titleBrush; 391 QBrush titleBrush;
392 QPen titleLines; 392 QPen titleLines;
393 393
394 if ( wd->flags & WindowData::Active ) { 394 if ( wd->flags & WindowData::Active ) {
395 titleBrush = cg.brush(QColorGroup::Highlight); 395 titleBrush = cg.brush(QColorGroup::Highlight);
396 titleLines = titleBrush.color().dark(); 396 titleLines = titleBrush.color().dark();
397 } else { 397 } else {
398 titleBrush = cg.brush(QColorGroup::Background); 398 titleBrush = cg.brush(QColorGroup::Background);
399 titleLines = titleBrush.color(); 399 titleLines = titleBrush.color();
400 } 400 }
401 401
402 p->fillRect( r.x(), r.y()-th, r.width(), th, titleBrush); 402 p->fillRect( r.x(), r.y()-th, r.width(), th, titleBrush);
403 403
404 p->setPen( titleLines ); 404 p->setPen( titleLines );
405 for ( int i = r.y()-th; i < r.y(); i += 2 ) 405 for ( int i = r.y()-th; i < r.y(); i += 2 )
406 p->drawLine( r.left(), i, r.right(), i ); 406 p->drawLine( r.left(), i, r.right(), i );
407 } 407 }
408 break; 408 break;
409 case TitleText: 409 case TitleText:
410 p->drawText( r.x()+3+metric(HelpWidth,wd), r.top()-th, 410 p->drawText( r.x()+3+metric(HelpWidth,wd), r.top()-th,
411 r.width()-metric(OKWidth,wd)-metric(CloseWidth,wd), 411 r.width()-metric(OKWidth,wd)-metric(CloseWidth,wd),
412 th, QPainter::AlignVCenter, wd->caption); 412 th, QPainter::AlignVCenter, wd->caption);
413 break; 413 break;
414 } 414 }
415} 415}
416 416
417void WindowDecorationInterface::drawButton( Button b, QPainter *p, const WindowData *wd, int x, int y, int, int, QWSButton::State state ) const 417void WindowDecorationInterface::drawButton( Button b, QPainter *p, const WindowData *wd, int x, int y, int, int, QWSButton::State state ) const
418{ 418{
419 QImage *img = 0; 419 QImage *img = 0;
420 switch ( b ) { 420 switch ( b ) {
421 case OK: 421 case OK:
422 img = okImage(metric(TitleHeight,wd)); 422 img = okImage(metric(TitleHeight,wd));
423 break; 423 break;
424 case Close: 424 case Close:
425 img = closeImage(metric(TitleHeight,wd)); 425 img = closeImage(metric(TitleHeight,wd));
426 break; 426 break;
427 case Help: 427 case Help:
428 img = helpImage(metric(TitleHeight,wd)); 428 img = helpImage(metric(TitleHeight,wd));
429 break; 429 break;
430 case Maximize: 430 case Maximize:
431 img = maximizeImage(metric(TitleHeight,wd)); 431 img = maximizeImage(metric(TitleHeight,wd));
432 break; 432 break;
433 } 433 }
434 434
435 if ( img ) { 435 if ( img ) {
436 if ((state & QWSButton::MouseOver) && (state & QWSButton::Clicked)) 436 if ((state & QWSButton::MouseOver) && (state & QWSButton::Clicked))
437 p->drawImage(x+2, y+2, *img); 437 p->drawImage(x+2, y+2, *img);
438 else 438 else
439 p->drawImage(x+1, y+1, *img); 439 p->drawImage(x+1, y+1, *img);
440 } 440 }
441} 441}
442 442
443QRegion WindowDecorationInterface::mask( const WindowData *wd ) const 443QRegion WindowDecorationInterface::mask( const WindowData *wd ) const
444{ 444{
445 int th = metric(TitleHeight,wd); 445 int th = metric(TitleHeight,wd);
446 QRect rect( wd->rect ); 446 QRect rect( wd->rect );
447 QRect r(rect.left() - metric(LeftBorder,wd), 447 QRect r(rect.left() - metric(LeftBorder,wd),
448 rect.top() - th - metric(TopBorder,wd), 448 rect.top() - th - metric(TopBorder,wd),
449 rect.width() + metric(LeftBorder,wd) + metric(RightBorder,wd), 449 rect.width() + metric(LeftBorder,wd) + metric(RightBorder,wd),
450 rect.height() + th + metric(TopBorder,wd) + metric(BottomBorder,wd)); 450 rect.height() + th + metric(TopBorder,wd) + metric(BottomBorder,wd));
451 return QRegion(r) - rect; 451 return QRegion(r) - rect;
452} 452}
453 453
454class DefaultWindowDecoration : public WindowDecorationInterface 454class DefaultWindowDecoration : public WindowDecorationInterface
455{ 455{
456public: 456public:
457 DefaultWindowDecoration() : ref(0) {} 457 DefaultWindowDecoration() : ref(0) {}
458 QString name() const { 458 QString name() const {
459 return "Default"; 459 return "Default";
460 } 460 }
461 QPixmap icon() const { 461 QPixmap icon() const {
462 return QPixmap(); 462 return QPixmap();
463 } 463 }
464 QRESULT queryInterface( const QUuid &uuid, QUnknownInterface **iface ) { 464 QRESULT queryInterface( const QUuid &uuid, QUnknownInterface **iface ) {
465 *iface = 0; 465 *iface = 0;
466 if ( uuid == IID_QUnknown ) 466 if ( uuid == IID_QUnknown )
467 *iface = this; 467 *iface = this;
468 else if ( uuid == IID_WindowDecoration ) 468 else if ( uuid == IID_WindowDecoration )
469 *iface = this; 469 *iface = this;
470 470
471 if ( *iface ) 471 if ( *iface )
472 (*iface)->addRef(); 472 (*iface)->addRef();
473 return QS_OK; 473 return QS_OK;
474 } 474 }
475 Q_REFCOUNT 475 Q_REFCOUNT
476 476
477private: 477private:
478 ulong ref; 478 ulong ref;
479}; 479};
480 480
481static WindowDecorationInterface *wdiface = 0; 481static WindowDecorationInterface *wdiface = 0;
482static QLibrary *wdlib = 0; 482static QLibrary *wdlib = 0;
483static QString libname; 483static QString libname;
484 484
485//=========================================================================== 485//===========================================================================
486 486
487QPEDecoration::QPEDecoration() 487QPEDecoration::QPEDecoration()
488 : QWSDefaultDecoration() 488 : QWSDefaultDecoration()
489{ 489{
490 init ( libname ); 490 init ( libname );
491} 491}
492 492
493QPEDecoration::QPEDecoration( const QString &plugin ) 493QPEDecoration::QPEDecoration( const QString &plugin )
494 : QWSDefaultDecoration() 494 : QWSDefaultDecoration()
495{ 495{
496 init ( plugin ); 496 init ( plugin );
497} 497}
498 498
499void QPEDecoration::init ( const QString &plugin ) 499void QPEDecoration::init ( const QString &plugin )
500{ 500{
501 libname = plugin; 501 libname = plugin;
502 502
503 if ( wdlib ) { 503 if ( wdlib ) {
504 wdiface->release(); 504 wdiface->release();
505 wdlib->unload(); 505 wdlib->unload();
506 delete wdlib; 506 delete wdlib;
507 wdlib = 0; 507 wdlib = 0;
508 } else { 508 } else {
509 delete wdiface; 509 delete wdiface;
510 } 510 }
511 511
512 WindowDecorationInterface *iface = 0; 512 WindowDecorationInterface *iface = 0;
513 QString path = QPEApplication::qpeDir() + "/plugins/decorations/"; 513 QString path = QPEApplication::qpeDir() + "/plugins/decorations/";
514 514
515#ifdef Q_OS_MACX
516 if ( plugin.find( ".dylib" ) > 0 ) {
517#else
515 if ( plugin.find( ".so" ) > 0 ) { 518 if ( plugin.find( ".so" ) > 0 ) {
519#endif
516 // full library name supplied 520 // full library name supplied
517 path += plugin; 521 path += plugin;
518 } else { 522 } else {
523#ifdef Q_OS_MACX
524 path += "lib" + plugin.lower() + ".dylib"; // compatibility
525#else
519 path += "lib" + plugin.lower() + ".so"; // compatibility 526 path += "lib" + plugin.lower() + ".so"; // compatibility
527#endif
520 } 528 }
521 529
522 QLibrary *lib = new QLibrary( path ); 530 QLibrary *lib = new QLibrary( path );
523 if ( lib->queryInterface( IID_WindowDecoration, (QUnknownInterface**)&iface ) == QS_OK && iface ) { 531 if ( lib->queryInterface( IID_WindowDecoration, (QUnknownInterface**)&iface ) == QS_OK && iface ) {
524 wdiface = iface; 532 wdiface = iface;
525 wdlib = lib; 533 wdlib = lib;
526 } else { 534 } else {
527 delete lib; 535 delete lib;
528 wdiface = new DefaultWindowDecoration; 536 wdiface = new DefaultWindowDecoration;
529 } 537 }
530 538
531 helpFile = QString(qApp->argv()[0]) + ".html"; 539 helpFile = QString(qApp->argv()[0]) + ".html";
532 QStringList helpPath = Global::helpPath(); 540 QStringList helpPath = Global::helpPath();
533 helpExists = FALSE; 541 helpExists = FALSE;
534 for (QStringList::ConstIterator it=helpPath.begin(); it!=helpPath.end() && !helpExists; ++it) { 542 for (QStringList::ConstIterator it=helpPath.begin(); it!=helpPath.end() && !helpExists; ++it) {
535 helpExists = QFile::exists( *it + "/" + helpFile ); 543 helpExists = QFile::exists( *it + "/" + helpFile );
536 //qDebug ( "Checking %s/%s for help: %d", (*it).latin1(), helpFile.latin1(),helpExists); 544 //qDebug ( "Checking %s/%s for help: %d", (*it).latin1(), helpFile.latin1(),helpExists);
537 } 545 }
538 qpeManager = new QPEManager( this ); 546 qpeManager = new QPEManager( this );
539 547
540 // Qtopia 1.5 compatibility 548 // Qtopia 1.5 compatibility
541 imageOk = *okImage ( 15 ); 549 imageOk = *okImage ( 15 );
542 imageClose = *closeImage ( 15 ); 550 imageClose = *closeImage ( 15 );
543 imageHelp = *helpImage ( 15 ); 551 imageHelp = *helpImage ( 15 );
544} 552}
545 553
546QPEDecoration::~QPEDecoration() 554QPEDecoration::~QPEDecoration()
547{ 555{
548 delete qpeManager; 556 delete qpeManager;
549} 557}
550 558
551const char **QPEDecoration::menuPixmap() 559const char **QPEDecoration::menuPixmap()
552{ 560{
553 return (const char **)0; 561 return (const char **)0;
554} 562}
555 563
556const char **QPEDecoration::closePixmap() 564const char **QPEDecoration::closePixmap()
557{ 565{
558 return (const char **)qpe_close_xpm; 566 return (const char **)qpe_close_xpm;
559} 567}
560 568
561const char **QPEDecoration::minimizePixmap() 569const char **QPEDecoration::minimizePixmap()
562{ 570{
563 return (const char **)qpe_accept_xpm; 571 return (const char **)qpe_accept_xpm;
564} 572}
565 573
566const char **QPEDecoration::maximizePixmap() 574const char **QPEDecoration::maximizePixmap()
567{ 575{
568 return (const char **)0; 576 return (const char **)0;
569} 577}
570 578
571const char **QPEDecoration::normalizePixmap() 579const char **QPEDecoration::normalizePixmap()
572{ 580{
573 return (const char **)0; 581 return (const char **)0;
574} 582}
575 583
576int QPEDecoration::getTitleHeight( const QWidget *w ) 584int QPEDecoration::getTitleHeight( const QWidget *w )
577{ 585{
578 WindowDecorationInterface::WindowData wd; 586 WindowDecorationInterface::WindowData wd;
579 windowData( w, wd ); 587 windowData( w, wd );
580 return wdiface->metric(WindowDecorationInterface::TitleHeight,&wd); 588 return wdiface->metric(WindowDecorationInterface::TitleHeight,&wd);
581} 589}
582 590
583/* 591/*
584 If rect is empty, no frame is added. (a hack, really) 592 If rect is empty, no frame is added. (a hack, really)
585*/ 593*/
586QRegion QPEDecoration::region(const QWidget *widget, const QRect &rect, QWSDecoration::Region type) 594QRegion QPEDecoration::region(const QWidget *widget, const QRect &rect, QWSDecoration::Region type)
587{ 595{
588 qpeManager->updateActive(); 596 qpeManager->updateActive();
589 597
590 WindowDecorationInterface::WindowData wd; 598 WindowDecorationInterface::WindowData wd;
591 windowData( widget, wd ); 599 windowData( widget, wd );
592 wd.rect = rect; 600 wd.rect = rect;
593 601
594 int titleHeight = wdiface->metric(WindowDecorationInterface::TitleHeight,&wd); 602 int titleHeight = wdiface->metric(WindowDecorationInterface::TitleHeight,&wd);
595 int okWidth = wdiface->metric(WindowDecorationInterface::OKWidth,&wd); 603 int okWidth = wdiface->metric(WindowDecorationInterface::OKWidth,&wd);
596 int closeWidth = wdiface->metric(WindowDecorationInterface::CloseWidth,&wd); 604 int closeWidth = wdiface->metric(WindowDecorationInterface::CloseWidth,&wd);
597 int helpWidth = wdiface->metric(WindowDecorationInterface::HelpWidth,&wd); 605 int helpWidth = wdiface->metric(WindowDecorationInterface::HelpWidth,&wd);
598 int grab = wdiface->metric(WindowDecorationInterface::CornerGrabSize,&wd); 606 int grab = wdiface->metric(WindowDecorationInterface::CornerGrabSize,&wd);
599 607
600 QRegion region; 608 QRegion region;
601 609
602 switch ((int)type) { 610 switch ((int)type) {
603 case Menu: 611 case Menu:
604 break; 612 break;
605 case Maximize: 613 case Maximize:
606 if ( !widget->inherits( "QDialog" ) && qApp->desktop()->width() > 350 ) { 614 if ( !widget->inherits( "QDialog" ) && qApp->desktop()->width() > 350 ) {
607 int maximizeWidth = wdiface->metric(WindowDecorationInterface::MaximizeWidth,&wd); 615 int maximizeWidth = wdiface->metric(WindowDecorationInterface::MaximizeWidth,&wd);
608 int left = rect.right() - maximizeWidth - closeWidth; 616 int left = rect.right() - maximizeWidth - closeWidth;
609 if ( ((HackWidget *)widget)->needsOk() ) 617 if ( ((HackWidget *)widget)->needsOk() )
610 left -= okWidth; 618 left -= okWidth;
611 QRect r(left, rect.top() - titleHeight, closeWidth, titleHeight); 619 QRect r(left, rect.top() - titleHeight, closeWidth, titleHeight);
612 region = r; 620 region = r;
613 } 621 }
614 break; 622 break;
615 case Minimize: 623 case Minimize:
616 if ( ((HackWidget *)widget)->needsOk() ) { 624 if ( ((HackWidget *)widget)->needsOk() ) {
617 QRect r(rect.right() - okWidth, 625 QRect r(rect.right() - okWidth,
618 rect.top() - titleHeight, okWidth, titleHeight); 626 rect.top() - titleHeight, okWidth, titleHeight);
619 if (r.left() > rect.left() + titleHeight) 627 if (r.left() > rect.left() + titleHeight)
620 region = r; 628 region = r;
621 } 629 }
622 break; 630 break;
623 case Close: 631 case Close:
624 { 632 {
625 int left = rect.right() - closeWidth; 633 int left = rect.right() - closeWidth;
626 if ( ((HackWidget *)widget)->needsOk() ) 634 if ( ((HackWidget *)widget)->needsOk() )
627 left -= okWidth; 635 left -= okWidth;
628 QRect r(left, rect.top() - titleHeight, closeWidth, titleHeight); 636 QRect r(left, rect.top() - titleHeight, closeWidth, titleHeight);
629 region = r; 637 region = r;
630 } 638 }
631 break; 639 break;
632 case Title: 640 case Title:
633 if ( !widget->isMaximized() ) { 641 if ( !widget->isMaximized() ) {
634 int width = rect.width() - helpWidth - closeWidth; 642 int width = rect.width() - helpWidth - closeWidth;
635 if ( ((HackWidget *)widget)->needsOk() ) 643 if ( ((HackWidget *)widget)->needsOk() )
636 width -= okWidth; 644 width -= okWidth;
637 QRect r(rect.left()+helpWidth, rect.top() - titleHeight, 645 QRect r(rect.left()+helpWidth, rect.top() - titleHeight,
638 width, titleHeight); 646 width, titleHeight);
639 if (r.width() > 0) 647 if (r.width() > 0)
640 region = r; 648 region = r;
641 } 649 }
642 break; 650 break;
643 case Help: 651 case Help:
644 if ( helpExists || widget->testWFlags(Qt::WStyle_ContextHelp) ) { 652 if ( helpExists || widget->testWFlags(Qt::WStyle_ContextHelp) ) {
645 QRect r(rect.left(), rect.top() - titleHeight, 653 QRect r(rect.left(), rect.top() - titleHeight,
646 helpWidth, titleHeight); 654 helpWidth, titleHeight);
647 region = r; 655 region = r;
648 } 656 }
649 break; 657 break;
650 case Top: 658 case Top:
651 if ( !widget->isMaximized() ) { 659 if ( !widget->isMaximized() ) {
652 QRegion m = wdiface->mask(&wd); 660 QRegion m = wdiface->mask(&wd);
653 QRect br = m.boundingRect(); 661 QRect br = m.boundingRect();
654 int b = wdiface->metric(WindowDecorationInterface::TopBorder,&wd); 662 int b = wdiface->metric(WindowDecorationInterface::TopBorder,&wd);
655 region = m & QRect( br.left()+grab, br.top(), 663 region = m & QRect( br.left()+grab, br.top(),
656 br.width()-2*grab, b ); 664 br.width()-2*grab, b );
657 } 665 }
658 break; 666 break;
659 case Left: 667 case Left:
660 if ( !widget->isMaximized() ) { 668 if ( !widget->isMaximized() ) {
661 QRegion m = wdiface->mask(&wd); 669 QRegion m = wdiface->mask(&wd);
662 QRect br = m.boundingRect(); 670 QRect br = m.boundingRect();
663 int b = wdiface->metric(WindowDecorationInterface::LeftBorder,&wd); 671 int b = wdiface->metric(WindowDecorationInterface::LeftBorder,&wd);
664 region = m & QRect( br.left(), br.top()+grab, 672 region = m & QRect( br.left(), br.top()+grab,
665 b, br.height()-2*grab ); 673 b, br.height()-2*grab );
666 } 674 }
667 break; 675 break;
668 case Right: 676 case Right:
669 if ( !widget->isMaximized() ) { 677 if ( !widget->isMaximized() ) {
670 QRegion m = wdiface->mask(&wd); 678 QRegion m = wdiface->mask(&wd);
671 QRect br = m.boundingRect(); 679 QRect br = m.boundingRect();
672 int b = wdiface->metric(WindowDecorationInterface::RightBorder,&wd); 680 int b = wdiface->metric(WindowDecorationInterface::RightBorder,&wd);
673 region = m & QRect( rect.right(), br.top()+grab, 681 region = m & QRect( rect.right(), br.top()+grab,
674 b, br.height()-2*grab ); 682 b, br.height()-2*grab );
675 } 683 }
676 break; 684 break;
677 case Bottom: 685 case Bottom:
678 if ( !widget->isMaximized() ) { 686 if ( !widget->isMaximized() ) {
679 QRegion m = wdiface->mask(&wd); 687 QRegion m = wdiface->mask(&wd);
680 QRect br = m.boundingRect(); 688 QRect br = m.boundingRect();
681 int b = wdiface->metric(WindowDecorationInterface::BottomBorder,&wd); 689 int b = wdiface->metric(WindowDecorationInterface::BottomBorder,&wd);
682 region = m & QRect( br.left()+grab, rect.bottom(), 690 region = m & QRect( br.left()+grab, rect.bottom(),
683 br.width()-2*grab, b ); 691 br.width()-2*grab, b );
684 } 692 }
685 break; 693 break;
686 case TopLeft: 694 case TopLeft:
687 if ( !widget->isMaximized() ) { 695 if ( !widget->isMaximized() ) {
688 QRegion m = wdiface->mask(&wd); 696 QRegion m = wdiface->mask(&wd);
689 QRect br = m.boundingRect(); 697 QRect br = m.boundingRect();
690 int tb = wdiface->metric(WindowDecorationInterface::TopBorder,&wd); 698 int tb = wdiface->metric(WindowDecorationInterface::TopBorder,&wd);
691 int lb = wdiface->metric(WindowDecorationInterface::LeftBorder,&wd); 699 int lb = wdiface->metric(WindowDecorationInterface::LeftBorder,&wd);
692 QRegion crgn( br.left(), br.top(), grab, tb ); 700 QRegion crgn( br.left(), br.top(), grab, tb );
693 crgn |= QRect( br.left(), br.top(), lb, grab ); 701 crgn |= QRect( br.left(), br.top(), lb, grab );
694 region = m & crgn; 702 region = m & crgn;
695 } 703 }
696 break; 704 break;
697 case TopRight: 705 case TopRight:
698 if ( !widget->isMaximized() ) { 706 if ( !widget->isMaximized() ) {
699 QRegion m = wdiface->mask(&wd); 707 QRegion m = wdiface->mask(&wd);
700 QRect br = m.boundingRect(); 708 QRect br = m.boundingRect();
701 int tb = wdiface->metric(WindowDecorationInterface::TopBorder,&wd); 709 int tb = wdiface->metric(WindowDecorationInterface::TopBorder,&wd);
702 int rb = wdiface->metric(WindowDecorationInterface::RightBorder,&wd); 710 int rb = wdiface->metric(WindowDecorationInterface::RightBorder,&wd);
703 QRegion crgn( br.right()-grab, br.top(), grab, tb ); 711 QRegion crgn( br.right()-grab, br.top(), grab, tb );
704 crgn |= QRect( br.right()-rb, br.top(), rb, grab ); 712 crgn |= QRect( br.right()-rb, br.top(), rb, grab );
705 region = m & crgn; 713 region = m & crgn;
706 } 714 }
707 break; 715 break;
708 case BottomLeft: 716 case BottomLeft:
709 if ( !widget->isMaximized() ) { 717 if ( !widget->isMaximized() ) {
710 QRegion m = wdiface->mask(&wd); 718 QRegion m = wdiface->mask(&wd);
711 QRect br = m.boundingRect(); 719 QRect br = m.boundingRect();
712 region = m & QRect( br.left(), br.bottom()-grab, grab, grab ); 720 region = m & QRect( br.left(), br.bottom()-grab, grab, grab );
713 } 721 }
714 break; 722 break;
715 case BottomRight: 723 case BottomRight:
716 if ( !widget->isMaximized() ) { 724 if ( !widget->isMaximized() ) {
717 QRegion m = wdiface->mask(&wd); 725 QRegion m = wdiface->mask(&wd);
718 QRect br = m.boundingRect(); 726 QRect br = m.boundingRect();
719 region = m & QRect( br.right()-grab, br.bottom()-grab, grab, grab ); 727 region = m & QRect( br.right()-grab, br.bottom()-grab, grab, grab );
720 } 728 }
721 break; 729 break;
722 case All: 730 case All:
723 if ( widget->isMaximized() ) 731 if ( widget->isMaximized() )
724 region = QWSDefaultDecoration::region(widget, rect, type); 732 region = QWSDefaultDecoration::region(widget, rect, type);
725 else 733 else
726 region = wdiface->mask(&wd) - rect; 734 region = wdiface->mask(&wd) - rect;
727 break; 735 break;
728 default: 736 default:
729 region = QWSDefaultDecoration::region(widget, rect, type); 737 region = QWSDefaultDecoration::region(widget, rect, type);
730 break; 738 break;
731 } 739 }
732 740
733 return region; 741 return region;
734} 742}
735 743
736void QPEDecoration::paint(QPainter *painter, const QWidget *widget) 744void QPEDecoration::paint(QPainter *painter, const QWidget *widget)
737{ 745{
738 WindowDecorationInterface::WindowData wd; 746 WindowDecorationInterface::WindowData wd;
739 windowData( widget, wd ); 747 windowData( widget, wd );
740 748
741 int titleWidth = getTitleWidth(widget); 749 int titleWidth = getTitleWidth(widget);
742 int titleHeight = wdiface->metric(WindowDecorationInterface::TitleHeight,&wd); 750 int titleHeight = wdiface->metric(WindowDecorationInterface::TitleHeight,&wd);
743 751
744 QRect rect(widget->rect()); 752 QRect rect(widget->rect());
745 753
746 // title bar rect 754 // title bar rect
747 QRect tr( rect.left(), rect.top() - titleHeight, rect.width(), titleHeight ); 755 QRect tr( rect.left(), rect.top() - titleHeight, rect.width(), titleHeight );
748 756
749#ifndef QT_NO_PALETTE 757#ifndef QT_NO_PALETTE
750 QRegion oldClip = painter->clipRegion(); 758 QRegion oldClip = painter->clipRegion();
751 painter->setClipRegion( oldClip - QRegion( tr ) );// reduce flicker 759 painter->setClipRegion( oldClip - QRegion( tr ) );// reduce flicker
752 wdiface->drawArea( WindowDecorationInterface::Border, painter, &wd ); 760 wdiface->drawArea( WindowDecorationInterface::Border, painter, &wd );
753 painter->setClipRegion( oldClip ); 761 painter->setClipRegion( oldClip );
754 762
755 if (titleWidth > 0) { 763 if (titleWidth > 0) {
756 const QColorGroup &cg = widget->palette().active(); 764 const QColorGroup &cg = widget->palette().active();
757 QBrush titleBrush; 765 QBrush titleBrush;
758 QPen titlePen; 766 QPen titlePen;
759 767
760 if ( wd.flags & WindowDecorationInterface::WindowData::Active ) { 768 if ( wd.flags & WindowDecorationInterface::WindowData::Active ) {
761 titleBrush = cg.brush(QColorGroup::Highlight); 769 titleBrush = cg.brush(QColorGroup::Highlight);
762 titlePen = cg.color(QColorGroup::HighlightedText); 770 titlePen = cg.color(QColorGroup::HighlightedText);
763 } else { 771 } else {
764 titleBrush = cg.brush(QColorGroup::Background); 772 titleBrush = cg.brush(QColorGroup::Background);
765 titlePen = cg.color(QColorGroup::Text); 773 titlePen = cg.color(QColorGroup::Text);
766 } 774 }
767 775
768 wdiface->drawArea( WindowDecorationInterface::Title, painter, &wd ); 776 wdiface->drawArea( WindowDecorationInterface::Title, painter, &wd );
769 777
770 // Draw caption 778 // Draw caption
771 painter->setPen(titlePen); 779 painter->setPen(titlePen);
772 QFont f( QApplication::font() ); 780 QFont f( QApplication::font() );
773 f.setWeight( QFont::Bold ); 781 f.setWeight( QFont::Bold );
774 painter->setFont(f); 782 painter->setFont(f);
775 wdiface->drawArea( WindowDecorationInterface::TitleText, painter, &wd ); 783 wdiface->drawArea( WindowDecorationInterface::TitleText, painter, &wd );
776 } 784 }
777#endif //QT_NO_PALETTE 785#endif //QT_NO_PALETTE
778 786
779 paintButton( painter, widget, (QWSDecoration::Region)Help, 0 ); 787 paintButton( painter, widget, (QWSDecoration::Region)Help, 0 );
780} 788}
781 789
782void QPEDecoration::paintButton(QPainter *painter, const QWidget *w, 790void QPEDecoration::paintButton(QPainter *painter, const QWidget *w,
783 QWSDecoration::Region type, int state) 791 QWSDecoration::Region type, int state)
784{ 792{
785 WindowDecorationInterface::Button b; 793 WindowDecorationInterface::Button b;
786 switch ((int)type) { 794 switch ((int)type) {
787 case Close: 795 case Close:
788 b = WindowDecorationInterface::Close; 796 b = WindowDecorationInterface::Close;
789 break; 797 break;
790 case Minimize: 798 case Minimize:
791 if ( ((HackWidget *)w)->needsOk() ) 799 if ( ((HackWidget *)w)->needsOk() )
792 b = WindowDecorationInterface::OK; 800 b = WindowDecorationInterface::OK;
793 else if ( helpExists ) 801 else if ( helpExists )
794 b = WindowDecorationInterface::Help; 802 b = WindowDecorationInterface::Help;
795 else 803 else
796 return; 804 return;
797 break; 805 break;
798 case Help: 806 case Help:
799 b = WindowDecorationInterface::Help; 807 b = WindowDecorationInterface::Help;
800 break; 808 break;
801 case Maximize: 809 case Maximize:
802 b = WindowDecorationInterface::Maximize; 810 b = WindowDecorationInterface::Maximize;
803 break; 811 break;
804 default: 812 default:
805 return; 813 return;
806 } 814 }
807 815
808 WindowDecorationInterface::WindowData wd; 816 WindowDecorationInterface::WindowData wd;
809 windowData( w, wd ); 817 windowData( w, wd );
810 818
811 int titleHeight = wdiface->metric(WindowDecorationInterface::TitleHeight,&wd); 819 int titleHeight = wdiface->metric(WindowDecorationInterface::TitleHeight,&wd);
812 QRect rect(w->rect()); 820 QRect rect(w->rect());
813 QRect tr( rect.left(), rect.top() - titleHeight, rect.width(), titleHeight ); 821 QRect tr( rect.left(), rect.top() - titleHeight, rect.width(), titleHeight );
814 QRect brect(region(w, w->rect(), type).boundingRect()); 822 QRect brect(region(w, w->rect(), type).boundingRect());
815 823
816 const QColorGroup &cg = w->palette().active(); 824 const QColorGroup &cg = w->palette().active();
817 if ( wd.flags & WindowDecorationInterface::WindowData::Active ) 825 if ( wd.flags & WindowDecorationInterface::WindowData::Active )
818 painter->setPen( cg.color(QColorGroup::HighlightedText) ); 826 painter->setPen( cg.color(QColorGroup::HighlightedText) );
819 else 827 else
820 painter->setPen( cg.color(QColorGroup::Text) ); 828 painter->setPen( cg.color(QColorGroup::Text) );
821 829
822 QRegion oldClip = painter->clipRegion(); 830 QRegion oldClip = painter->clipRegion();
823 painter->setClipRegion( QRect(brect.x(), tr.y(), brect.width(), tr.height()) ); // reduce flicker 831 painter->setClipRegion( QRect(brect.x(), tr.y(), brect.width(), tr.height()) ); // reduce flicker
824 wdiface->drawArea( WindowDecorationInterface::Title, painter, &wd ); 832 wdiface->drawArea( WindowDecorationInterface::Title, painter, &wd );
825 wdiface->drawButton( b, painter, &wd, brect.x(), brect.y(), brect.width(), brect.height(), (QWSButton::State)state ); 833 wdiface->drawButton( b, painter, &wd, brect.x(), brect.y(), brect.width(), brect.height(), (QWSButton::State)state );
826 painter->setClipRegion( oldClip ); 834 painter->setClipRegion( oldClip );
827} 835}
828 836
829//#define QPE_DONT_SHOW_TITLEBAR 837//#define QPE_DONT_SHOW_TITLEBAR
830 838
831void QPEDecoration::maximize( QWidget *widget ) 839void QPEDecoration::maximize( QWidget *widget )
832{ 840{
833#ifdef QPE_DONT_SHOW_TITLEBAR 841#ifdef QPE_DONT_SHOW_TITLEBAR
834 if ( !widget->inherits( "QDialog" ) ) { 842 if ( !widget->inherits( "QDialog" ) ) {
835 widget->setGeometry( qt_maxWindowRect ); 843 widget->setGeometry( qt_maxWindowRect );
836 } else 844 } else
837#endif 845#endif
838 { 846 {
839 QWSDecoration::maximize( widget ); 847 QWSDecoration::maximize( widget );
840 } 848 }
841} 849}
842 850
843#ifndef QT_NO_DIALOG 851#ifndef QT_NO_DIALOG
844class HackDialog : public QDialog 852class HackDialog : public QDialog
845{ 853{
846public: 854public:
847 void acceptIt() { 855 void acceptIt() {
848 if ( isA( "QMessageBox" ) ) 856 if ( isA( "QMessageBox" ) )
849 qApp->postEvent( this, new QKeyEvent( QEvent::KeyPress, Key_Enter, '\n', 0, "\n" ) ); 857 qApp->postEvent( this, new QKeyEvent( QEvent::KeyPress, Key_Enter, '\n', 0, "\n" ) );
850 else 858 else
851 accept(); 859 accept();
852 } 860 }
853}; 861};
854#endif 862#endif
855 863
856 864
857void QPEDecoration::minimize( QWidget *widget ) 865void QPEDecoration::minimize( QWidget *widget )
858{ 866{
859#ifndef QT_NO_DIALOG 867#ifndef QT_NO_DIALOG
860 // We use the minimize button as an "accept" button. 868 // We use the minimize button as an "accept" button.
861 if ( widget->inherits( "QDialog" ) ) { 869 if ( widget->inherits( "QDialog" ) ) {
862 HackDialog *d = (HackDialog *)widget; 870 HackDialog *d = (HackDialog *)widget;
863 d->acceptIt(); 871 d->acceptIt();
864 } 872 }
865#endif 873#endif
866 else if ( ((HackWidget *)widget)->needsOk() ) { 874 else if ( ((HackWidget *)widget)->needsOk() ) {
867 QSignal s; 875 QSignal s;
868 s.connect( widget, SLOT( accept() ) ); 876 s.connect( widget, SLOT( accept() ) );
869 s.activate(); 877 s.activate();
870 } else { 878 } else {
871 help( widget ); 879 help( widget );
872 } 880 }
873} 881}
874 882
875void QPEDecoration::help( QWidget *w ) 883void QPEDecoration::help( QWidget *w )
876{ 884{
877 if ( helpExists ) { 885 if ( helpExists ) {
878 Global::execute( "helpbrowser", helpFile ); 886 Global::execute( "helpbrowser", helpFile );
879 } else if ( w && w->testWFlags(Qt::WStyle_ContextHelp) ) { 887 } else if ( w && w->testWFlags(Qt::WStyle_ContextHelp) ) {
880 QWhatsThis::enterWhatsThisMode(); 888 QWhatsThis::enterWhatsThisMode();
881 QWhatsThis::leaveWhatsThisMode( QObject::tr( 889 QWhatsThis::leaveWhatsThisMode( QObject::tr(
882 "<Qt>Comprehensive help is not available for this application, " 890 "<Qt>Comprehensive help is not available for this application, "
883 "however there is context-sensitive help.<p>To use context-sensitive help:<p>" 891 "however there is context-sensitive help.<p>To use context-sensitive help:<p>"
884 "<ol><li>click and hold the help button." 892 "<ol><li>click and hold the help button."
885 "<li>when the title bar shows <b>What's this...</b>, " 893 "<li>when the title bar shows <b>What's this...</b>, "
886 "click on any control.</ol></Qt>" ) ); 894 "click on any control.</ol></Qt>" ) );
887 } 895 }
888} 896}
889 897
890void QPEDecoration::windowData( const QWidget *w, WindowDecorationInterface::WindowData &wd ) const 898void QPEDecoration::windowData( const QWidget *w, WindowDecorationInterface::WindowData &wd ) const
891{ 899{
892 wd.rect = w->rect(); 900 wd.rect = w->rect();
893 if ( qpeManager->whatsThisWidget() == w ) 901 if ( qpeManager->whatsThisWidget() == w )
894 wd.caption = QObject::tr("What's this..." ); 902 wd.caption = QObject::tr("What's this..." );
895 else 903 else
896 wd.caption = w->caption(); 904 wd.caption = w->caption();
897 wd.palette = qApp->palette(); 905 wd.palette = qApp->palette();
898 wd.flags = 0; 906 wd.flags = 0;
899 wd.flags |= w->isMaximized() ? WindowDecorationInterface::WindowData::Maximized : 0; 907 wd.flags |= w->isMaximized() ? WindowDecorationInterface::WindowData::Maximized : 0;
900 wd.flags |= w->testWFlags(Qt::WStyle_Dialog) ? WindowDecorationInterface::WindowData::Dialog : 0; 908 wd.flags |= w->testWFlags(Qt::WStyle_Dialog) ? WindowDecorationInterface::WindowData::Dialog : 0;
901 const QWidget *active = qpeManager->activeWidget(); 909 const QWidget *active = qpeManager->activeWidget();
902 wd.flags |= w == active ? WindowDecorationInterface::WindowData::Active : 0; 910 wd.flags |= w == active ? WindowDecorationInterface::WindowData::Active : 0;
903 wd.reserved = 1; 911 wd.reserved = 1;
904} 912}
905 913
906/* 914/*
907#ifndef QT_NO_POPUPMENU 915#ifndef QT_NO_POPUPMENU
908QPopupMenu *QPEDecoration::menu(QWSManager*, const QWidget*, const QPoint&) 916QPopupMenu *QPEDecoration::menu(QWSManager*, const QWidget*, const QPoint&)
909{ 917{
910 return 0; 918 return 0;
911} 919}
912#endif 920#endif
913*/ 921*/
914 922
915 923
916 924
917 925
918#endif // QT_NO_QWS_QPE_WM_STYLE 926#endif // QT_NO_QWS_QPE_WM_STYLE
diff --git a/library/sound.cpp b/library/sound.cpp
index c8704f9..5b67995 100644
--- a/library/sound.cpp
+++ b/library/sound.cpp
@@ -1,221 +1,224 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of 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#include <qpe/resource.h> 21#include <qpe/resource.h>
22#include <qpe/sound.h> 22#include <qpe/sound.h>
23#include <qpe/qcopenvelope_qws.h> 23#include <qpe/qcopenvelope_qws.h>
24 24
25#include <qsound.h> 25#include <qsound.h>
26#include <qfile.h> 26#include <qfile.h>
27 27
28#include <unistd.h> 28#include <unistd.h>
29#include <fcntl.h> 29#include <fcntl.h>
30#include <sys/ioctl.h> 30#include <sys/ioctl.h>
31
32#ifndef QT_NO_SOUND
31#include <sys/soundcard.h> 33#include <sys/soundcard.h>
34#endif
32 35
33#include "config.h" 36#include "config.h"
34#include <qmessagebox.h> 37#include <qmessagebox.h>
35#ifndef QT_NO_SOUND 38#ifndef QT_NO_SOUND
36static int WAVsoundDuration(const QString& filename) 39static int WAVsoundDuration(const QString& filename)
37{ 40{
38 // bad solution 41 // bad solution
39 42
40 // most of this is copied from qsoundqss.cpp 43 // most of this is copied from qsoundqss.cpp
41 44
42 QFile input(filename); 45 QFile input(filename);
43 if ( !input.open(IO_ReadOnly) ) 46 if ( !input.open(IO_ReadOnly) )
44 return 0; 47 return 0;
45 48
46 struct QRiffChunk { 49 struct QRiffChunk {
47 char id[4]; 50 char id[4];
48 Q_UINT32 size; 51 Q_UINT32 size;
49 char data[4/*size*/]; 52 char data[4/*size*/];
50 } chunk; 53 } chunk;
51 54
52 struct { 55 struct {
53 Q_INT16 formatTag; 56 Q_INT16 formatTag;
54 Q_INT16 channels; 57 Q_INT16 channels;
55 Q_INT32 samplesPerSec; 58 Q_INT32 samplesPerSec;
56 Q_INT32 avgBytesPerSec; 59 Q_INT32 avgBytesPerSec;
57 Q_INT16 blockAlign; 60 Q_INT16 blockAlign;
58 Q_INT16 wBitsPerSample; 61 Q_INT16 wBitsPerSample;
59 } chunkdata; 62 } chunkdata;
60 63
61 int total = 0; 64 int total = 0;
62 65
63 while(1) { 66 while(1) {
64 // Keep reading chunks... 67 // Keep reading chunks...
65 const int n = sizeof(chunk)-sizeof(chunk.data); 68 const int n = sizeof(chunk)-sizeof(chunk.data);
66 if ( input.readBlock((char*)&chunk,n) != n ) 69 if ( input.readBlock((char*)&chunk,n) != n )
67 break; 70 break;
68 if ( qstrncmp(chunk.id,"data",4) == 0 ) { 71 if ( qstrncmp(chunk.id,"data",4) == 0 ) {
69 total += chunkdata.avgBytesPerSec ? 72 total += chunkdata.avgBytesPerSec ?
70 chunk.size * 1000 / chunkdata.avgBytesPerSec : 0; 73 chunk.size * 1000 / chunkdata.avgBytesPerSec : 0;
71//qDebug("%d bytes of PCM (%dms)", chunk.size,chunkdata.avgBytesPerSec ? chunk.size * 1000 / chunkdata.avgBytesPerSec : 0); 74//qDebug("%d bytes of PCM (%dms)", chunk.size,chunkdata.avgBytesPerSec ? chunk.size * 1000 / chunkdata.avgBytesPerSec : 0);
72 input.at(input.at()+chunk.size-4); 75 input.at(input.at()+chunk.size-4);
73 } else if ( qstrncmp(chunk.id,"RIFF",4) == 0 ) { 76 } else if ( qstrncmp(chunk.id,"RIFF",4) == 0 ) {
74 char d[4]; 77 char d[4];
75 if ( input.readBlock(d,4) != 4 ) 78 if ( input.readBlock(d,4) != 4 )
76 return 0; 79 return 0;
77 if ( qstrncmp(d,"WAVE",4) != 0 ) { 80 if ( qstrncmp(d,"WAVE",4) != 0 ) {
78 // skip 81 // skip
79//qDebug("skip %.4s RIFF chunk",d); 82//qDebug("skip %.4s RIFF chunk",d);
80 if ( chunk.size < 10000000 ) 83 if ( chunk.size < 10000000 )
81 (void)input.at(input.at()+chunk.size-4); 84 (void)input.at(input.at()+chunk.size-4);
82 } 85 }
83 } else if ( qstrncmp(chunk.id,"fmt ",4) == 0 ) { 86 } else if ( qstrncmp(chunk.id,"fmt ",4) == 0 ) {
84 if ( input.readBlock((char*)&chunkdata,sizeof(chunkdata)) != sizeof(chunkdata) ) 87 if ( input.readBlock((char*)&chunkdata,sizeof(chunkdata)) != sizeof(chunkdata) )
85 return 0; 88 return 0;
86#define WAVE_FORMAT_PCM 1 89#define WAVE_FORMAT_PCM 1
87 if ( chunkdata.formatTag != WAVE_FORMAT_PCM ) { 90 if ( chunkdata.formatTag != WAVE_FORMAT_PCM ) {
88 //qDebug("WAV file: UNSUPPORTED FORMAT %d",chunkdata.formatTag); 91 //qDebug("WAV file: UNSUPPORTED FORMAT %d",chunkdata.formatTag);
89 return 0; 92 return 0;
90 } 93 }
91 } else { 94 } else {
92//qDebug("skip %.4s chunk",chunk.id); 95//qDebug("skip %.4s chunk",chunk.id);
93 // ignored chunk 96 // ignored chunk
94 if ( chunk.size < 10000000 ) 97 if ( chunk.size < 10000000 )
95 (void)input.at(input.at()+chunk.size); 98 (void)input.at(input.at()+chunk.size);
96 } 99 }
97 } 100 }
98 101
99//qDebug("%dms",total); 102//qDebug("%dms",total);
100 return total; 103 return total;
101} 104}
102 105
103class SoundData : public QSound { 106class SoundData : public QSound {
104public: 107public:
105 SoundData ( const QString& name ) : 108 SoundData ( const QString& name ) :
106 QSound ( Resource::findSound ( name )), 109 QSound ( Resource::findSound ( name )),
107 filename ( Resource::findSound ( name )) 110 filename ( Resource::findSound ( name ))
108 { 111 {
109 loopsleft=0; 112 loopsleft=0;
110 ms = WAVsoundDuration(filename); 113 ms = WAVsoundDuration(filename);
111 } 114 }
112 115
113 void playLoop ( int loopcnt = -1 ) 116 void playLoop ( int loopcnt = -1 )
114 { 117 {
115 // needs server support 118 // needs server support
116 loopsleft = loopcnt; 119 loopsleft = loopcnt;
117 120
118 if ( ms ) 121 if ( ms )
119 startTimer ( ms > 50 ? ms-50 : 0 ); // 50 for latency 122 startTimer ( ms > 50 ? ms-50 : 0 ); // 50 for latency
120 play ( ); 123 play ( );
121 } 124 }
122 125
123 void timerEvent ( QTimerEvent *e ) 126 void timerEvent ( QTimerEvent *e )
124 { 127 {
125 if ( loopsleft >= 0 ) { 128 if ( loopsleft >= 0 ) {
126 if ( --loopsleft <= 0 ) { 129 if ( --loopsleft <= 0 ) {
127 killTimer ( e-> timerId ( )); 130 killTimer ( e-> timerId ( ));
128 loopsleft = 0; 131 loopsleft = 0;
129 return; 132 return;
130 } 133 }
131 } 134 }
132 play(); 135 play();
133 } 136 }
134 137
135 bool isFinished ( ) const 138 bool isFinished ( ) const
136 { 139 {
137 return ( loopsleft == 0 ); 140 return ( loopsleft == 0 );
138 } 141 }
139 142
140private: 143private:
141 QString filename; 144 QString filename;
142 int loopsleft; 145 int loopsleft;
143 int ms; 146 int ms;
144}; 147};
145 148
146#endif 149#endif
147 150
148/*! Opens a wave sound file \a name for playing 151/*! Opens a wave sound file \a name for playing
149 * Resource is used for finding the file 152 * Resource is used for finding the file
150 **/ 153 **/
151Sound::Sound(const QString& name) 154Sound::Sound(const QString& name)
152{ 155{
153#ifndef QT_NO_SOUND 156#ifndef QT_NO_SOUND
154 d = new SoundData(name); 157 d = new SoundData(name);
155#endif 158#endif
156} 159}
157 160
158/*! Destroys the sound */ 161/*! Destroys the sound */
159Sound::~Sound() 162Sound::~Sound()
160{ 163{
161#ifndef QT_NO_SOUND 164#ifndef QT_NO_SOUND
162 delete d; 165 delete d;
163#endif 166#endif
164} 167}
165 168
166/*! Play the sound once */ 169/*! Play the sound once */
167void Sound::play() 170void Sound::play()
168{ 171{
169#ifndef QT_NO_SOUND 172#ifndef QT_NO_SOUND
170 d->playLoop(1); 173 d->playLoop(1);
171#endif 174#endif
172} 175}
173 176
174/*! Play the sound, repeatedly until stop() is called */ 177/*! Play the sound, repeatedly until stop() is called */
175void Sound::playLoop() 178void Sound::playLoop()
176{ 179{
177#ifndef QT_NO_SOUND 180#ifndef QT_NO_SOUND
178 d->killTimers(); 181 d->killTimers();
179 d->playLoop(); 182 d->playLoop();
180#endif 183#endif
181} 184}
182 185
183/*! Do not repeat the sound after it finishes. This will end a playLoop() */ 186/*! Do not repeat the sound after it finishes. This will end a playLoop() */
184void Sound::stop() 187void Sound::stop()
185{ 188{
186#ifndef QT_NO_SOUND 189#ifndef QT_NO_SOUND
187 d->killTimers(); 190 d->killTimers();
188#endif 191#endif
189} 192}
190 193
191bool Sound::isFinished() const 194bool Sound::isFinished() const
192{ 195{
193#ifndef QT_NO_SOUND 196#ifndef QT_NO_SOUND
194 return d->isFinished(); 197 return d->isFinished();
195#else 198#else
196 return true; 199 return true;
197#endif 200#endif
198} 201}
199 202
200/*! Sounds the audible system alarm. This is used for applications such 203/*! Sounds the audible system alarm. This is used for applications such
201 as Calendar when it needs to alarm the user of an event. 204 as Calendar when it needs to alarm the user of an event.
202*/ 205*/
203void Sound::soundAlarm() 206void Sound::soundAlarm()
204{ 207{
205#ifndef QT_NO_COP 208#ifndef QT_NO_COP
206 QCopEnvelope( "QPE/TaskBar", "soundAlarm()" ); 209 QCopEnvelope( "QPE/TaskBar", "soundAlarm()" );
207#endif 210#endif
208} 211}
209 212
210 213
211/*! \class Sound 214/*! \class Sound
212 \brief The Sound class plays WAVE sound files and can invoke the audible alarm. 215 \brief The Sound class plays WAVE sound files and can invoke the audible alarm.
213 216
214 The Sound class is constructed with the .wav music file name. The Sound 217 The Sound class is constructed with the .wav music file name. The Sound
215 class retrieves the sound file from the shared Resource class. This class 218 class retrieves the sound file from the shared Resource class. This class
216 ties together QSound and the available sound resources. 219 ties together QSound and the available sound resources.
217 220
218 To sound an audible system alarm, call the static method soundAlarm() 221 To sound an audible system alarm, call the static method soundAlarm()
219 222
220 \ingroup qtopiaemb 223 \ingroup qtopiaemb
221*/ 224*/
diff --git a/library/storage.cpp b/library/storage.cpp
index dc5cc22..f8b75d0 100644
--- a/library/storage.cpp
+++ b/library/storage.cpp
@@ -1,344 +1,376 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) Holger 'zecke' Freyther <freyther@kde.org> 2** Copyright (C) Holger 'zecke' Freyther <freyther@kde.org>
3** Copyright (C) Lorn Potter <llornkcor@handhelds.org> 3** Copyright (C) Lorn Potter <llornkcor@handhelds.org>
4** Copyright (C) 2000 Trolltech AS. All rights reserved. 4** Copyright (C) 2000 Trolltech AS. All rights reserved.
5** 5**
6** This file is part of Opie Environment. 6** This file is part of Opie Environment.
7** 7**
8** This file may be distributed and/or modified under the terms of the 8** This file may be distributed and/or modified under the terms of the
9** GNU General Public License version 2 as published by the Free Software 9** GNU General Public License version 2 as published by the Free Software
10** Foundation and appearing in the file LICENSE.GPL included in the 10** Foundation and appearing in the file LICENSE.GPL included in the
11** packaging of this file. 11** packaging of this file.
12** 12**
13** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 13** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
14** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 14** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
15** 15**
16** See http://www.trolltech.com/gpl/ for GPL licensing information. 16** See http://www.trolltech.com/gpl/ for GPL licensing information.
17** 17**
18** Contact info@trolltech.com if any conditions of this licensing are 18** Contact info@trolltech.com if any conditions of this licensing are
19** not clear to you. 19** not clear to you.
20** 20**
21**********************************************************************/ 21**********************************************************************/
22 22
23#include <qpe/storage.h> 23#include <qpe/storage.h>
24#include <qpe/custom.h> 24#include <qpe/custom.h>
25 25
26#include <qfile.h> 26#include <qfile.h>
27#include <qtimer.h> 27#include <qtimer.h>
28#include <qcopchannel_qws.h> 28#include <qcopchannel_qws.h>
29 29
30#include <stdio.h> 30#include <stdio.h>
31 31
32#if defined(_OS_LINUX_) || defined(Q_OS_LINUX) 32#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
33#include <sys/vfs.h> 33#include <sys/vfs.h>
34#include <mntent.h> 34#include <mntent.h>
35#endif 35#endif
36 36
37#ifdef Q_OS_MACX
38# include <sys/param.h>
39# include <sys/ucred.h>
40# include <sys/mount.h>
41# include <stdio.h> // For strerror()
42# include <errno.h>
43#endif /* Q_OS_MACX */
44
37#include <qstringlist.h> 45#include <qstringlist.h>
38 46
39#include <sys/vfs.h> 47// Shouldn't be here ! (eilers)
40#include <mntent.h> 48// #include <sys/vfs.h>
49// #include <mntent.h>
41 50
42 51
43static bool isCF(const QString& m) 52static bool isCF(const QString& m)
44{ 53{
54
55#ifndef Q_OS_MACX
45 FILE* f = fopen("/var/run/stab", "r"); 56 FILE* f = fopen("/var/run/stab", "r");
46 if (!f) f = fopen("/var/state/pcmcia/stab", "r"); 57 if (!f) f = fopen("/var/state/pcmcia/stab", "r");
47 if (!f) f = fopen("/var/lib/pcmcia/stab", "r"); 58 if (!f) f = fopen("/var/lib/pcmcia/stab", "r");
48 if ( f ) { 59 if ( f ) {
49 char line[1024]; 60 char line[1024];
50 char devtype[80]; 61 char devtype[80];
51 char devname[80]; 62 char devname[80];
52 while ( fgets( line, 1024, f ) ) { 63 while ( fgets( line, 1024, f ) ) {
53 // 0 ide ide-cs 0 hda 3 0 64 // 0 ide ide-cs 0 hda 3 0
54 if ( sscanf(line,"%*d %s %*s %*s %s", devtype, devname )==2 ) 65 if ( sscanf(line,"%*d %s %*s %*s %s", devtype, devname )==2 )
55 { 66 {
56 if ( QString(devtype) == "ide" && m.find(devname)>0 ) { 67 if ( QString(devtype) == "ide" && m.find(devname)>0 ) {
57 fclose(f); 68 fclose(f);
58 return TRUE; 69 return TRUE;
59 } 70 }
60 } 71 }
61 } 72 }
62 fclose(f); 73 fclose(f);
63 } 74 }
75#endif /* Q_OS_MACX */
64 return FALSE; 76 return FALSE;
65} 77}
66 78
67/*! \class StorageInfo storage.h 79/*! \class StorageInfo storage.h
68 \brief The StorageInfo class describes the disks mounted on the file system. 80 \brief The StorageInfo class describes the disks mounted on the file system.
69 81
70 This class provides access to the mount information for the Linux 82 This class provides access to the mount information for the Linux
71 filesystem. Each mount point is represented by the FileSystem class. 83 filesystem. Each mount point is represented by the FileSystem class.
72 To ensure this class has the most up to date size information, call 84 To ensure this class has the most up to date size information, call
73 the update() method. Note that this will automatically be signaled 85 the update() method. Note that this will automatically be signaled
74 by the operating system when a disk has been mounted or unmounted. 86 by the operating system when a disk has been mounted or unmounted.
75 87
76 \ingroup qtopiaemb 88 \ingroup qtopiaemb
77*/ 89*/
78 90
79/*! Constructor that determines the current mount points of the filesystem. 91/*! Constructor that determines the current mount points of the filesystem.
80 The standard \a parent parameters is passed on to QObject. 92 The standard \a parent parameters is passed on to QObject.
81 */ 93 */
82StorageInfo::StorageInfo( QObject *parent ) 94StorageInfo::StorageInfo( QObject *parent )
83 : QObject( parent ) 95 : QObject( parent )
84{ 96{
85 mFileSystems.setAutoDelete( TRUE ); 97 mFileSystems.setAutoDelete( TRUE );
86 channel = new QCopChannel( "QPE/Card", this ); 98 channel = new QCopChannel( "QPE/Card", this );
87 connect( channel, SIGNAL(received(const QCString &, const QByteArray &)), 99 connect( channel, SIGNAL(received(const QCString &, const QByteArray &)),
88 this, SLOT(cardMessage( const QCString &, const QByteArray &)) ); 100 this, SLOT(cardMessage( const QCString &, const QByteArray &)) );
89 update(); 101 update();
90} 102}
91 103
92/*! Returns the longest matching FileSystem that starts with the 104/*! Returns the longest matching FileSystem that starts with the
93 same prefix as \a filename as its mount point. 105 same prefix as \a filename as its mount point.
94*/ 106*/
95const FileSystem *StorageInfo::fileSystemOf( const QString &filename ) 107const FileSystem *StorageInfo::fileSystemOf( const QString &filename )
96{ 108{
97 for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i) { 109 for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i) {
98 if ( filename.startsWith( (*i)->path() ) ) 110 if ( filename.startsWith( (*i)->path() ) )
99 return (*i); 111 return (*i);
100 } 112 }
101 return 0; 113 return 0;
102} 114}
103 115
104 116
105void StorageInfo::cardMessage( const QCString& msg, const QByteArray& ) 117void StorageInfo::cardMessage( const QCString& msg, const QByteArray& )
106{ 118{
107 if ( msg == "mtabChanged()" ) 119 if ( msg == "mtabChanged()" )
108 update(); 120 update();
109} 121}
110 122
111 123
112/*! Updates the mount and free space available information for each mount 124/*! Updates the mount and free space available information for each mount
113 point. This method is automatically called when a disk is mounted or 125 point. This method is automatically called when a disk is mounted or
114 unmounted. 126 unmounted.
115*/ 127*/
116// cause of the lack of a d pointer we need 128// cause of the lack of a d pointer we need
117// to store informations in a config file :( 129// to store informations in a config file :(
118void StorageInfo::update() 130void StorageInfo::update()
119{ 131{
120 //qDebug("StorageInfo::updating"); 132 //qDebug("StorageInfo::updating");
121#if defined(_OS_LINUX_) || defined(Q_OS_LINUX) 133#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
122 struct mntent *me; 134 struct mntent *me;
123 FILE *mntfp = setmntent( "/etc/mtab", "r" ); 135 FILE *mntfp = setmntent( "/etc/mtab", "r" );
124 136
125 QStringList curdisks; 137 QStringList curdisks;
126 QStringList curopts; 138 QStringList curopts;
127 QStringList curfs; 139 QStringList curfs;
128 bool rebuild = FALSE; 140 bool rebuild = FALSE;
129 int n=0; 141 int n=0;
130 if ( mntfp ) { 142 if ( mntfp ) {
131 while ( (me = getmntent( mntfp )) != 0 ) { 143 while ( (me = getmntent( mntfp )) != 0 ) {
132 QString fs = me->mnt_fsname; 144 QString fs = me->mnt_fsname;
133 if ( fs.left(7)=="/dev/hd" || fs.left(7)=="/dev/sd" 145 if ( fs.left(7)=="/dev/hd" || fs.left(7)=="/dev/sd"
134 || fs.left(8)=="/dev/mtd" || fs.left(9) == "/dev/mmcd" 146 || fs.left(8)=="/dev/mtd" || fs.left(9) == "/dev/mmcd"
135 || fs.left( 14 ) == "/dev/mmc/part1" 147 || fs.left( 14 ) == "/dev/mmc/part1"
136 || fs.left(5)=="tmpfs" || fs.left(9)=="/dev/root" ) 148 || fs.left(5)=="tmpfs" || fs.left(9)=="/dev/root" )
137 { 149 {
138 n++; 150 n++;
139 curdisks.append(fs); 151 curdisks.append(fs);
140 curopts.append( me->mnt_opts ); 152 curopts.append( me->mnt_opts );
141 //qDebug("-->fs %s opts %s", fs.latin1(), me->mnt_opts ); 153 //qDebug("-->fs %s opts %s", fs.latin1(), me->mnt_opts );
142 curfs.append( me->mnt_dir ); 154 curfs.append( me->mnt_dir );
143 bool found = FALSE; 155 bool found = FALSE;
144 for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i) { 156 for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i) {
145 if ( (*i)->disk() == fs ) { 157 if ( (*i)->disk() == fs ) {
146 found = TRUE; 158 found = TRUE;
147 break; 159 break;
148 } 160 }
149 } 161 }
150 if ( !found ) 162 if ( !found )
151 rebuild = TRUE; 163 rebuild = TRUE;
152 } 164 }
153 } 165 }
154 endmntent( mntfp ); 166 endmntent( mntfp );
155 } 167 }
156 if ( rebuild || n != (int)mFileSystems.count() ) { 168 if ( rebuild || n != (int)mFileSystems.count() ) {
157 mFileSystems.clear(); 169 mFileSystems.clear();
158 QStringList::ConstIterator it=curdisks.begin(); 170 QStringList::ConstIterator it=curdisks.begin();
159 QStringList::ConstIterator fsit=curfs.begin(); 171 QStringList::ConstIterator fsit=curfs.begin();
160 QStringList::ConstIterator optsIt=curopts.begin(); 172 QStringList::ConstIterator optsIt=curopts.begin();
161 for (; it!=curdisks.end(); ++it, ++fsit, ++optsIt) { 173 for (; it!=curdisks.end(); ++it, ++fsit, ++optsIt) {
162 QString opts = *optsIt; 174 QString opts = *optsIt;
163 175
164 QString disk = *it; 176 QString disk = *it;
165 QString humanname; 177 QString humanname;
166 bool removable = FALSE; 178 bool removable = FALSE;
167 if ( isCF(disk) ) { 179 if ( isCF(disk) ) {
168 humanname = tr("CF Card"); 180 humanname = tr("CF Card");
169 removable = TRUE; 181 removable = TRUE;
170 } else if ( disk == "/dev/hda1" ) { 182 } else if ( disk == "/dev/hda1" ) {
171 humanname = tr("Hard Disk"); 183 humanname = tr("Hard Disk");
172 } else if ( disk.left(9) == "/dev/mmcd" ) { 184 } else if ( disk.left(9) == "/dev/mmcd" ) {
173 humanname = tr("SD Card"); 185 humanname = tr("SD Card");
174 removable = TRUE; 186 removable = TRUE;
175 } else if ( disk.left( 14 ) == "/dev/mmc/part1" ) { 187 } else if ( disk.left( 14 ) == "/dev/mmc/part1" ) {
176 humanname = tr("MMC Card"); 188 humanname = tr("MMC Card");
177 removable = TRUE; 189 removable = TRUE;
178 } else if ( disk.left(7) == "/dev/hd" ) 190 } else if ( disk.left(7) == "/dev/hd" )
179 humanname = tr("Hard Disk") + " " + disk; 191 humanname = tr("Hard Disk") + " " + disk;
180 else if ( disk.left(7) == "/dev/sd" ) 192 else if ( disk.left(7) == "/dev/sd" )
181 humanname = tr("SCSI Hard Disk") + " " + disk; 193 humanname = tr("SCSI Hard Disk") + " " + disk;
182 else if ( disk.left(14) == "/dev/mtdblock6" ) //openzaurus ramfs 194 else if ( disk.left(14) == "/dev/mtdblock6" ) //openzaurus ramfs
183 humanname = tr("Internal Memory"); 195 humanname = tr("Internal Memory");
184 else if ( disk == "/dev/mtdblock1" || humanname == "/dev/mtdblock/1" ) 196 else if ( disk == "/dev/mtdblock1" || humanname == "/dev/mtdblock/1" )
185 humanname = tr("Internal Storage"); 197 humanname = tr("Internal Storage");
186 else if ( disk.left(14) == "/dev/mtdblock/" ) 198 else if ( disk.left(14) == "/dev/mtdblock/" )
187 humanname = tr("Internal Storage") + " " + disk; 199 humanname = tr("Internal Storage") + " " + disk;
188 else if ( disk.left(13) == "/dev/mtdblock" ) 200 else if ( disk.left(13) == "/dev/mtdblock" )
189 humanname = tr("Internal Storage") + " " + disk; 201 humanname = tr("Internal Storage") + " " + disk;
190 else if ( disk.left(9) == "/dev/root" ) 202 else if ( disk.left(9) == "/dev/root" )
191 humanname = tr("Internal Storage") + " " + disk; 203 humanname = tr("Internal Storage") + " " + disk;
192 else if ( disk.left(5) == "tmpfs" ) //ipaqs /mnt/ramfs 204 else if ( disk.left(5) == "tmpfs" ) //ipaqs /mnt/ramfs
193 humanname = tr("Internal Memory"); 205 humanname = tr("Internal Memory");
194 FileSystem *fs = new FileSystem( disk, *fsit, humanname, removable, opts ); 206 FileSystem *fs = new FileSystem( disk, *fsit, humanname, removable, opts );
195 mFileSystems.append( fs ); 207 mFileSystems.append( fs );
196 } 208 }
197 emit disksChanged(); 209 emit disksChanged();
198 } else { 210 } else {
199 // just update them 211 // just update them
200 for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i) 212 for (QListIterator<FileSystem> i(mFileSystems); i.current(); ++i)
201 i.current()->update(); 213 i.current()->update();
202 } 214 }
203#endif 215#endif
204} 216}
205 217
206bool deviceTab( const char *device) { 218bool deviceTab( const char *device) {
207 QString name = device; 219 QString name = device;
208 bool hasDevice=false; 220 bool hasDevice=false;
221
222#ifdef Q_OS_MACX
223 // Darwin (MacOS X)
224 struct statfs** mntbufp;
225 int count = 0;
226 if ( ( count = getmntinfo( mntbufp, MNT_WAIT ) ) == 0 ){
227 qWarning("deviceTab: Error in getmntinfo(): %s",strerror( errno ) );
228 hasDevice = false;
229 }
230 for( int i = 0; i < count; i++ ){
231 QString deviceName = mntbufp[i]->f_mntfromname;
232 qDebug(deviceName);
233 if( deviceName.left( name.length() ) == name )
234 hasDevice = true;
235 }
236#else
237 // Linux
209 struct mntent *me; 238 struct mntent *me;
210 FILE *mntfp = setmntent( "/etc/mtab", "r" ); 239 FILE *mntfp = setmntent( "/etc/mtab", "r" );
211 if ( mntfp ) { 240 if ( mntfp ) {
212 while ( (me = getmntent( mntfp )) != 0 ) { 241 while ( (me = getmntent( mntfp )) != 0 ) {
213 QString deviceName = me->mnt_fsname; 242 QString deviceName = me->mnt_fsname;
214// qDebug(deviceName); 243// qDebug(deviceName);
215 if( deviceName.left(name.length()) == name) { 244 if( deviceName.left(name.length()) == name) {
216 hasDevice = true; 245 hasDevice = true;
217 } 246 }
218 } 247 }
219 } 248 }
220 endmntent( mntfp ); 249 endmntent( mntfp );
250#endif /* Q_OS_MACX */
251
252
221 return hasDevice; 253 return hasDevice;
222} 254}
223 255
224/*! 256/*!
225 * @fn static bool StorageInfo::hasCf() 257 * @fn static bool StorageInfo::hasCf()
226 * @brief returns whether device has Cf mounted 258 * @brief returns whether device has Cf mounted
227 * 259 *
228 */ 260 */
229bool StorageInfo::hasCf() 261bool StorageInfo::hasCf()
230{ 262{
231 return deviceTab("/dev/hd"); 263 return deviceTab("/dev/hd");
232} 264}
233 265
234/*! 266/*!
235 * @fn static bool StorageInfo::hasSd() 267 * @fn static bool StorageInfo::hasSd()
236 * @brief returns whether device has SD mounted 268 * @brief returns whether device has SD mounted
237 * 269 *
238 */ 270 */
239bool StorageInfo::hasSd() 271bool StorageInfo::hasSd()
240{ 272{
241 return deviceTab("/dev/mmcd"); 273 return deviceTab("/dev/mmcd");
242} 274}
243 275
244/*! 276/*!
245 * @fn static bool StorageInfo::hasMmc() 277 * @fn static bool StorageInfo::hasMmc()
246 * @brief reutrns whether device has mmc mounted 278 * @brief reutrns whether device has mmc mounted
247 * 279 *
248 */ 280 */
249bool StorageInfo::hasMmc() 281bool StorageInfo::hasMmc()
250{ 282{
251 bool hasMmc=false; 283 bool hasMmc=false;
252 if( deviceTab("/dev/mmc/part")) 284 if( deviceTab("/dev/mmc/part"))
253 hasMmc=true; 285 hasMmc=true;
254 if( deviceTab("/dev/mmcd")) 286 if( deviceTab("/dev/mmcd"))
255 hasMmc=true; 287 hasMmc=true;
256 return hasMmc; 288 return hasMmc;
257} 289}
258 290
259/*! \fn const QList<FileSystem> &StorageInfo::fileSystems() const 291/*! \fn const QList<FileSystem> &StorageInfo::fileSystems() const
260 Returns a list of all available mounted file systems. 292 Returns a list of all available mounted file systems.
261 293
262 \warning This may change in Qtopia 3.x to return only relevant Qtopia file systems (and ignore mount points such as /tmp) 294 \warning This may change in Qtopia 3.x to return only relevant Qtopia file systems (and ignore mount points such as /tmp)
263*/ 295*/
264 296
265/*! \fn void StorageInfo::disksChanged() 297/*! \fn void StorageInfo::disksChanged()
266 Gets emitted when a disk has been mounted or unmounted, such as when 298 Gets emitted when a disk has been mounted or unmounted, such as when
267 a CF c 299 a CF c
268*/ 300*/
269//--------------------------------------------------------------------------- 301//---------------------------------------------------------------------------
270 302
271FileSystem::FileSystem( const QString &disk, const QString &path, const QString &name, bool rem, const QString &o ) 303FileSystem::FileSystem( const QString &disk, const QString &path, const QString &name, bool rem, const QString &o )
272 : fsdisk( disk ), fspath( path ), humanname( name ), blkSize(512), totalBlks(0), availBlks(0), removable( rem ), opts( o ) 304 : fsdisk( disk ), fspath( path ), humanname( name ), blkSize(512), totalBlks(0), availBlks(0), removable( rem ), opts( o )
273{ 305{
274 update(); 306 update();
275} 307}
276 308
277void FileSystem::update() 309void FileSystem::update()
278{ 310{
279#if defined(_OS_LINUX_) || defined(Q_OS_LINUX) 311#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
280 struct statfs fs; 312 struct statfs fs;
281 if ( !statfs( fspath.latin1(), &fs ) ) { 313 if ( !statfs( fspath.latin1(), &fs ) ) {
282 blkSize = fs.f_bsize; 314 blkSize = fs.f_bsize;
283 totalBlks = fs.f_blocks; 315 totalBlks = fs.f_blocks;
284 availBlks = fs.f_bavail; 316 availBlks = fs.f_bavail;
285 } else { 317 } else {
286 blkSize = 0; 318 blkSize = 0;
287 totalBlks = 0; 319 totalBlks = 0;
288 availBlks = 0; 320 availBlks = 0;
289 } 321 }
290#endif 322#endif
291} 323}
292 324
293/*! \class FileSystem storage.h 325/*! \class FileSystem storage.h
294 \brief The FileSystem class describes a single mount point. 326 \brief The FileSystem class describes a single mount point.
295 327
296 This class simply returns information about a mount point, including 328 This class simply returns information about a mount point, including
297 file system name, mount point, human readable name, size information 329 file system name, mount point, human readable name, size information
298 and mount options information. 330 and mount options information.
299 \ingroup qtopiaemb 331 \ingroup qtopiaemb
300 332
301 \sa StorageInfo 333 \sa StorageInfo
302*/ 334*/
303 335
304/*! \fn const QString &FileSystem::disk() const 336/*! \fn const QString &FileSystem::disk() const
305 Returns the file system name, such as /dev/hda3 337 Returns the file system name, such as /dev/hda3
306*/ 338*/
307 339
308/*! \fn const QString &FileSystem::path() const 340/*! \fn const QString &FileSystem::path() const
309 Returns the mount path, such as /home 341 Returns the mount path, such as /home
310*/ 342*/
311 343
312/*! \fn const QString &FileSystem::name() const 344/*! \fn const QString &FileSystem::name() const
313 Returns the translated, human readable name for the mount directory. 345 Returns the translated, human readable name for the mount directory.
314*/ 346*/
315 347
316/*! \fn const QString &FileSystem::options() const 348/*! \fn const QString &FileSystem::options() const
317 Returns the mount options 349 Returns the mount options
318*/ 350*/
319 351
320/*! \fn long FileSystem::blockSize() const 352/*! \fn long FileSystem::blockSize() const
321 Returns the size of each block on the file system. 353 Returns the size of each block on the file system.
322*/ 354*/
323 355
324/*! \fn long FileSystem::totalBlocks() const 356/*! \fn long FileSystem::totalBlocks() const
325 Returns the total number of blocks on the file system 357 Returns the total number of blocks on the file system
326*/ 358*/
327 359
328/*! \fn long FileSystem::availBlocks() const 360/*! \fn long FileSystem::availBlocks() const
329 Returns the number of available blocks on the file system 361 Returns the number of available blocks on the file system
330 */ 362 */
331 363
332/*! \fn bool FileSystem::isRemovable() const 364/*! \fn bool FileSystem::isRemovable() const
333 Returns flag whether the file system can be removed, such as a CF card 365 Returns flag whether the file system can be removed, such as a CF card
334 would be removable, but the internal memory wouldn't 366 would be removable, but the internal memory wouldn't
335*/ 367*/
336 368
337/*! \fn bool FileSystem::isWritable() const 369/*! \fn bool FileSystem::isWritable() const
338 Returns flag whether the file system is mounted as writable or read-only. 370 Returns flag whether the file system is mounted as writable or read-only.
339 Returns FALSE if read-only, TRUE if read and write. 371 Returns FALSE if read-only, TRUE if read and write.
340*/ 372*/
341 373
342/*! \fn QStringList StorageInfo::fileSystemNames() const 374/*! \fn QStringList StorageInfo::fileSystemNames() const
343 Returns a list of filesystem names. 375 Returns a list of filesystem names.
344*/ 376*/