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
@@ -351,464 +351,468 @@ void Global::addWords(const QString& dictname, const QStringList& wordlist)
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
@@ -165,280 +165,284 @@ public:
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,668 +1,687 @@
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 */
@@ -1396,517 +1415,523 @@ bool QPEApplication::raiseAppropriateWindow()
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
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
@@ -259,517 +259,525 @@ void QPEManager::drawButton( QWidget *w, QPEDecoration::QPERegion r, int state )
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 );
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*/