summaryrefslogtreecommitdiff
path: root/library
authorerik <erik>2007-01-24 19:46:19 (UTC)
committer erik <erik>2007-01-24 19:46:19 (UTC)
commita017bf21dd89159052f2f7a3fbc043a24956c08c (patch) (unidiff)
tree008be2b62ee5487dc55b8a7c7f043c94268f8362 /library
parenta4a7bd22feb060a80e20c81cded43cc24f5cd423 (diff)
downloadopie-a017bf21dd89159052f2f7a3fbc043a24956c08c.zip
opie-a017bf21dd89159052f2f7a3fbc043a24956c08c.tar.gz
opie-a017bf21dd89159052f2f7a3fbc043a24956c08c.tar.bz2
Every file in this commit has a memory leak of some kind or another. I think
all of them are minor and should not effect properly running code. But if I were you I would give libstocks and the stockticker plugin in Today a wide berth. That library is atrocious.
Diffstat (limited to 'library') (more/less context) (ignore whitespace changes)
-rw-r--r--library/global.cpp30
1 files changed, 17 insertions, 13 deletions
diff --git a/library/global.cpp b/library/global.cpp
index 7bdd0b1..1895006 100644
--- a/library/global.cpp
+++ b/library/global.cpp
@@ -1,860 +1,864 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#define QTOPIA_INTERNAL_LANGLIST 20#define QTOPIA_INTERNAL_LANGLIST
21#include <qpe/qpedebug.h> 21#include <qpe/qpedebug.h>
22#include <qpe/global.h> 22#include <qpe/global.h>
23#include <qpe/qdawg.h> 23#include <qpe/qdawg.h>
24#include <qpe/qpeapplication.h> 24#include <qpe/qpeapplication.h>
25#include <qpe/resource.h> 25#include <qpe/resource.h>
26#include <qpe/storage.h> 26#include <qpe/storage.h>
27#include <qpe/applnk.h> 27#include <qpe/applnk.h>
28#include <qpe/qcopenvelope_qws.h> 28#include <qpe/qcopenvelope_qws.h>
29#include <qpe/config.h> 29#include <qpe/config.h>
30 30
31#include <qlabel.h> 31#include <qlabel.h>
32#include <qtimer.h> 32#include <qtimer.h>
33#include <qmap.h> 33#include <qmap.h>
34#include <qdict.h> 34#include <qdict.h>
35#include <qdir.h> 35#include <qdir.h>
36#include <qmessagebox.h> 36#include <qmessagebox.h>
37#include <qregexp.h> 37#include <qregexp.h>
38 38
39#include <stdlib.h> 39#include <stdlib.h>
40#include <sys/stat.h> 40#include <sys/stat.h>
41#include <sys/wait.h> 41#include <sys/wait.h>
42#include <sys/types.h> 42#include <sys/types.h>
43#include <fcntl.h> 43#include <fcntl.h>
44#include <unistd.h> 44#include <unistd.h>
45#include <errno.h> 45#include <errno.h>
46 46
47#include <qwindowsystem_qws.h> // for qwsServer 47#include <qwindowsystem_qws.h> // for qwsServer
48#include <qdatetime.h> 48#include <qdatetime.h>
49 49
50 50
51//#include "quickexec_p.h" 51//#include "quickexec_p.h"
52 52
53class Emitter : public QObject { 53class Emitter : public QObject {
54 Q_OBJECT 54 Q_OBJECT
55public: 55public:
56 Emitter( QWidget* receiver, const QString& document ) 56 Emitter( QWidget* receiver, const QString& document )
57 { 57 {
58 connect(this, SIGNAL(setDocument(const QString&)), 58 connect(this, SIGNAL(setDocument(const QString&)),
59 receiver, SLOT(setDocument(const QString&))); 59 receiver, SLOT(setDocument(const QString&)));
60 emit setDocument(document); 60 emit setDocument(document);
61 disconnect(this, SIGNAL(setDocument(const QString&)), 61 disconnect(this, SIGNAL(setDocument(const QString&)),
62 receiver, SLOT(setDocument(const QString&))); 62 receiver, SLOT(setDocument(const QString&)));
63 } 63 }
64 64
65signals: 65signals:
66 void setDocument(const QString&); 66 void setDocument(const QString&);
67}; 67};
68 68
69 69
70class StartingAppList : public QObject { 70class StartingAppList : public QObject {
71 Q_OBJECT 71 Q_OBJECT
72public: 72public:
73 static void add( const QString& name ); 73 static void add( const QString& name );
74 static bool isStarting( const QString name ); 74 static bool isStarting( const QString name );
75private slots: 75private slots:
76 void handleNewChannel( const QString &); 76 void handleNewChannel( const QString &);
77private: 77private:
78 StartingAppList( QObject *parent=0, const char* name=0 ) ; 78 StartingAppList( QObject *parent=0, const char* name=0 ) ;
79 79
80 QDict<QTime> dict; 80 QDict<QTime> dict;
81 static StartingAppList *appl; 81 static StartingAppList *appl;
82}; 82};
83 83
84StartingAppList* StartingAppList::appl = 0; 84StartingAppList* StartingAppList::appl = 0;
85 85
86StartingAppList::StartingAppList( QObject *parent, const char* name ) 86StartingAppList::StartingAppList( QObject *parent, const char* name )
87 :QObject( parent, name ) 87 :QObject( parent, name )
88{ 88{
89#if QT_VERSION >= 232 && defined(QWS) 89#if QT_VERSION >= 232 && defined(QWS)
90 connect( qwsServer, SIGNAL( newChannel(const QString&)), 90 connect( qwsServer, SIGNAL( newChannel(const QString&)),
91 this, SLOT( handleNewChannel(const QString&)) ); 91 this, SLOT( handleNewChannel(const QString&)) );
92#endif 92#endif
93 dict.setAutoDelete( TRUE ); 93 dict.setAutoDelete( TRUE );
94} 94}
95 95
96void StartingAppList::add( const QString& name ) 96void StartingAppList::add( const QString& name )
97{ 97{
98#if QT_VERSION >= 232 && !defined(QT_NO_COP) 98#if QT_VERSION >= 232 && !defined(QT_NO_COP)
99 if ( !appl ) 99 if ( !appl )
100 appl = new StartingAppList; 100 appl = new StartingAppList;
101 QTime *t = new QTime; 101 QTime *t = new QTime;
102 t->start(); 102 t->start();
103 appl->dict.insert( "QPE/Application/" + name, t ); 103 appl->dict.insert( "QPE/Application/" + name, t );
104#endif 104#endif
105} 105}
106 106
107bool StartingAppList::isStarting( const QString name ) 107bool StartingAppList::isStarting( const QString name )
108{ 108{
109#if QT_VERSION >= 232 && !defined(QT_NO_COP) 109#if QT_VERSION >= 232 && !defined(QT_NO_COP)
110 if ( appl ) { 110 if ( appl ) {
111 QTime *t = appl->dict.find( "QPE/Application/" + name ); 111 QTime *t = appl->dict.find( "QPE/Application/" + name );
112 if ( !t ) 112 if ( !t )
113 return FALSE; 113 return FALSE;
114 if ( t->elapsed() > 10000 ) { 114 if ( t->elapsed() > 10000 ) {
115 // timeout in case of crash or something 115 // timeout in case of crash or something
116 appl->dict.remove( "QPE/Application/" + name ); 116 appl->dict.remove( "QPE/Application/" + name );
117 return FALSE; 117 return FALSE;
118 } 118 }
119 return TRUE; 119 return TRUE;
120 } 120 }
121#endif 121#endif
122 return FALSE; 122 return FALSE;
123} 123}
124 124
125void StartingAppList::handleNewChannel( const QString & name ) 125void StartingAppList::handleNewChannel( const QString & name )
126{ 126{
127#if QT_VERSION >= 232 && !defined(QT_NO_COP) 127#if QT_VERSION >= 232 && !defined(QT_NO_COP)
128 dict.remove( name ); 128 dict.remove( name );
129#endif 129#endif
130} 130}
131 131
132static bool docDirCreated = FALSE; 132static bool docDirCreated = FALSE;
133static QDawg* fixed_dawg = 0; 133static QDawg* fixed_dawg = 0;
134static QDict<QDawg> *named_dawg = 0; 134static QDict<QDawg> *named_dawg = 0;
135 135
136static QString qpeDir() 136static QString qpeDir()
137{ 137{
138 QString dir = getenv("OPIEDIR"); 138 QString dir = getenv("OPIEDIR");
139 if ( dir.isEmpty() ) dir = ".."; 139 if ( dir.isEmpty() ) dir = "..";
140 return dir; 140 return dir;
141} 141}
142 142
143static QString dictDir() 143static QString dictDir()
144{ 144{
145 return qpeDir() + "/etc/dict"; 145 return qpeDir() + "/etc/dict";
146} 146}
147 147
148/*! 148/*!
149 \class Global global.h 149 \class Global global.h
150 \brief The Global class provides application-wide global functions. 150 \brief The Global class provides application-wide global functions.
151 151
152 The Global functions are grouped as follows: 152 The Global functions are grouped as follows:
153 \tableofcontents 153 \tableofcontents
154 154
155 \section1 User Interface 155 \section1 User Interface
156 156
157 The statusMessage() function provides short-duration messages to the 157 The statusMessage() function provides short-duration messages to the
158 user. The showInputMethod() function shows the current input method, 158 user. The showInputMethod() function shows the current input method,
159 and hideInputMethod() hides the input method. 159 and hideInputMethod() hides the input method.
160 160
161 \section1 Document related 161 \section1 Document related
162 162
163 The findDocuments() function creates a set of \link doclnk.html 163 The findDocuments() function creates a set of \link doclnk.html
164 DocLnk\endlink objects in a particular folder. 164 DocLnk\endlink objects in a particular folder.
165 165
166 \section1 Filesystem related 166 \section1 Filesystem related
167 167
168 Global provides an applicationFileName() function that returns the 168 Global provides an applicationFileName() function that returns the
169 full path of an application-specific file. 169 full path of an application-specific file.
170 170
171 The execute() function runs an application. 171 The execute() function runs an application.
172 172
173 \section1 Word list related 173 \section1 Word list related
174 174
175 A list of words relevant to the current locale is maintained by the 175 A list of words relevant to the current locale is maintained by the
176 system. The list is held in a \link qdawg.html DAWG\endlink 176 system. The list is held in a \link qdawg.html DAWG\endlink
177 (implemented by the QDawg class). This list is used, for example, by 177 (implemented by the QDawg class). This list is used, for example, by
178 the pickboard input method. 178 the pickboard input method.
179 179
180 The global QDawg is returned by fixedDawg(); this cannot be updated. 180 The global QDawg is returned by fixedDawg(); this cannot be updated.
181 An updatable copy of the global QDawg is returned by addedDawg(). 181 An updatable copy of the global QDawg is returned by addedDawg().
182 Applications may have their own word lists stored in \l{QDawg}s 182 Applications may have their own word lists stored in \l{QDawg}s
183 which are returned by dawg(). Use addWords() to add words to the 183 which are returned by dawg(). Use addWords() to add words to the
184 updateable copy of the global QDawg or to named application 184 updateable copy of the global QDawg or to named application
185 \l{QDawg}s. 185 \l{QDawg}s.
186 186
187 \section1 Quoting 187 \section1 Quoting
188 188
189 The shellQuote() function quotes a string suitable for passing to a 189 The shellQuote() function quotes a string suitable for passing to a
190 shell. The stringQuote() function backslash escapes '\' and '"' 190 shell. The stringQuote() function backslash escapes '\' and '"'
191 characters. 191 characters.
192 192
193 \section1 Hardware 193 \section1 Hardware
194 194
195 The implementation of the writeHWClock() function depends on the AlarmServer 195 The implementation of the writeHWClock() function depends on the AlarmServer
196 implementation. If the AlarmServer is using atd the clock will be synced to 196 implementation. If the AlarmServer is using atd the clock will be synced to
197 hardware. If opie-alarm is used the hardware clock will be synced before 197 hardware. If opie-alarm is used the hardware clock will be synced before
198 suspending the device. opie-alarm is used by iPAQ and Zaurii implementation 198 suspending the device. opie-alarm is used by iPAQ and Zaurii implementation
199 199
200 \ingroup qtopiaemb 200 \ingroup qtopiaemb
201*/ 201*/
202 202
203/*! 203/*!
204 \internal 204 \internal
205*/ 205*/
206Global::Global() 206Global::Global()
207{ 207{
208} 208}
209 209
210/*! 210/*!
211 Returns the unchangeable QDawg that contains general 211 Returns the unchangeable QDawg that contains general
212 words for the current locale. 212 words for the current locale.
213 213
214 \sa addedDawg() 214 \sa addedDawg()
215*/ 215*/
216const QDawg& Global::fixedDawg() 216const QDawg& Global::fixedDawg()
217{ 217{
218 if ( !fixed_dawg ) { 218 if ( !fixed_dawg ) {
219 if ( !docDirCreated ) 219 if ( !docDirCreated )
220 createDocDir(); 220 createDocDir();
221 221
222 fixed_dawg = new QDawg; 222 fixed_dawg = new QDawg;
223 QString dawgfilename = dictDir() + "/dawg"; 223 QString dawgfilename = dictDir() + "/dawg";
224 QString words_lang; 224 QString words_lang;
225 QStringList langs = Global::languageList(); 225 QStringList langs = Global::languageList();
226 for (QStringList::ConstIterator it = langs.begin(); it!=langs.end(); ++it) { 226 for (QStringList::ConstIterator it = langs.begin(); it!=langs.end(); ++it) {
227 QString lang = *it; 227 QString lang = *it;
228 words_lang = dictDir() + "/words." + lang; 228 words_lang = dictDir() + "/words." + lang;
229 QString dawgfilename_lang = dawgfilename + "." + lang; 229 QString dawgfilename_lang = dawgfilename + "." + lang;
230 if ( QFile::exists(dawgfilename_lang) || 230 if ( QFile::exists(dawgfilename_lang) ||
231 QFile::exists(words_lang) ) { 231 QFile::exists(words_lang) ) {
232 dawgfilename = dawgfilename_lang; 232 dawgfilename = dawgfilename_lang;
233 break; 233 break;
234 } 234 }
235 } 235 }
236 QFile dawgfile(dawgfilename); 236 QFile dawgfile(dawgfilename);
237 237
238 if ( !dawgfile.exists() ) { 238 if ( !dawgfile.exists() ) {
239 QString fn = dictDir() + "/words"; 239 QString fn = dictDir() + "/words";
240 if ( QFile::exists(words_lang) ) 240 if ( QFile::exists(words_lang) )
241 fn = words_lang; 241 fn = words_lang;
242 QFile in(fn); 242 QFile in(fn);
243 if ( in.open(IO_ReadOnly) ) { 243 if ( in.open(IO_ReadOnly) ) {
244 fixed_dawg->createFromWords(&in); 244 fixed_dawg->createFromWords(&in);
245 if (dawgfile.open(IO_WriteOnly)) 245 if (dawgfile.open(IO_WriteOnly))
246 fixed_dawg->write(&dawgfile); 246 fixed_dawg->write(&dawgfile);
247 dawgfile.close(); 247 dawgfile.close();
248 } 248 }
249 } else 249 } else
250 fixed_dawg->readFile(dawgfilename); 250 fixed_dawg->readFile(dawgfilename);
251 } 251 }
252 252
253 return *fixed_dawg; 253 return *fixed_dawg;
254} 254}
255 255
256/*! 256/*!
257 Returns the changeable QDawg that contains general 257 Returns the changeable QDawg that contains general
258 words for the current locale. 258 words for the current locale.
259 259
260 \sa fixedDawg() 260 \sa fixedDawg()
261*/ 261*/
262const QDawg& Global::addedDawg() 262const QDawg& Global::addedDawg()
263{ 263{
264 return dawg("local"); 264 return dawg("local");
265} 265}
266 266
267/*! 267/*!
268 Returns the QDawg with the given \a name. 268 Returns the QDawg with the given \a name.
269 This is an application-specific word list. 269 This is an application-specific word list.
270 270
271 \a name should not contain "/". 271 \a name should not contain "/".
272*/ 272*/
273const QDawg& Global::dawg(const QString& name) 273const QDawg& Global::dawg(const QString& name)
274{ 274{
275 createDocDir(); 275 createDocDir();
276 if ( !named_dawg ) 276 if ( !named_dawg )
277 named_dawg = new QDict<QDawg>; 277 named_dawg = new QDict<QDawg>;
278 QDawg* r = named_dawg->find(name); 278 QDawg* r = named_dawg->find(name);
279 if ( !r ) { 279 if ( !r ) {
280 r = new QDawg; 280 r = new QDawg;
281 named_dawg->insert(name,r); 281 named_dawg->insert(name,r);
282 QString dawgfilename = applicationFileName("Dictionary", name ) + ".dawg"; 282 QString dawgfilename = applicationFileName("Dictionary", name ) + ".dawg";
283 QFile dawgfile(dawgfilename); 283 QFile dawgfile(dawgfilename);
284 if ( dawgfile.open(IO_ReadOnly) ) 284 if ( dawgfile.open(IO_ReadOnly) )
285 r->readFile(dawgfilename); 285 r->readFile(dawgfilename);
286 } 286 }
287 return *r; 287 return *r;
288} 288}
289 289
290/*! 290/*!
291 \overload 291 \overload
292 Adds \a wordlist to the addedDawg(). 292 Adds \a wordlist to the addedDawg().
293 293
294 Note that the addition of words persists between program executions 294 Note that the addition of words persists between program executions
295 (they are saved in the dictionary files), so you should confirm the 295 (they are saved in the dictionary files), so you should confirm the
296 words with the user before adding them. 296 words with the user before adding them.
297*/ 297*/
298void Global::addWords(const QStringList& wordlist) 298void Global::addWords(const QStringList& wordlist)
299{ 299{
300 addWords("local",wordlist); 300 addWords("local",wordlist);
301} 301}
302 302
303/*! 303/*!
304 \overload 304 \overload
305 Adds \a wordlist to the addedDawg(). 305 Adds \a wordlist to the addedDawg().
306 306
307 Note that the addition of words persists between program executions 307 Note that the addition of words persists between program executions
308 (they are saved in the dictionary files), so you should confirm the 308 (they are saved in the dictionary files), so you should confirm the
309 words with the user before adding them. 309 words with the user before adding them.
310*/ 310*/
311void Global::addWords(const QString& dictname, const QStringList& wordlist) 311void Global::addWords(const QString& dictname, const QStringList& wordlist)
312{ 312{
313 QDawg& d = (QDawg&)dawg(dictname); 313 QDawg& d = (QDawg&)dawg(dictname);
314 QStringList all = d.allWords() + wordlist; 314 QStringList all = d.allWords() + wordlist;
315 d.createFromWords(all); 315 d.createFromWords(all);
316 316
317 QString dawgfilename = applicationFileName("Dictionary", dictname) + ".dawg"; 317 QString dawgfilename = applicationFileName("Dictionary", dictname) + ".dawg";
318 QFile dawgfile(dawgfilename); 318 QFile dawgfile(dawgfilename);
319 if ( dawgfile.open(IO_WriteOnly) ) { 319 if ( dawgfile.open(IO_WriteOnly) ) {
320 d.write(&dawgfile); 320 d.write(&dawgfile);
321 dawgfile.close(); 321 dawgfile.close();
322 } 322 }
323 323
324 // #### Re-read the dawg here if we use mmap(). 324 // #### Re-read the dawg here if we use mmap().
325 325
326 // #### Signal other processes to re-read. 326 // #### Signal other processes to re-read.
327} 327}
328 328
329 329
330/*! 330/*!
331 Returns the full path for the application called \a appname, with the 331 Returns the full path for the application called \a appname, with the
332 given \a filename. Returns QString::null if there was a problem creating 332 given \a filename. Returns QString::null if there was a problem creating
333 the directory tree for \a appname. 333 the directory tree for \a appname.
334 If \a filename contains "/", it is the caller's responsibility to 334 If \a filename contains "/", it is the caller's responsibility to
335 ensure that those directories exist. 335 ensure that those directories exist.
336*/ 336*/
337QString Global::applicationFileName(const QString& appname, const QString& filename) 337QString Global::applicationFileName(const QString& appname, const QString& filename)
338{ 338{
339 QDir d; 339 QDir d;
340 QString r = getenv("HOME"); 340 QString r = getenv("HOME");
341 r += "/Applications/"; 341 r += "/Applications/";
342 if ( !QFile::exists( r ) ) 342 if ( !QFile::exists( r ) )
343 if ( d.mkdir(r) == false ) 343 if ( d.mkdir(r) == false )
344 return QString::null; 344 return QString::null;
345 r += appname; 345 r += appname;
346 if ( !QFile::exists( r ) ) 346 if ( !QFile::exists( r ) )
347 if ( d.mkdir(r) == false ) 347 if ( d.mkdir(r) == false )
348 return QString::null; 348 return QString::null;
349 r += "/"; r += filename; 349 r += "/"; r += filename;
350 return r; 350 return r;
351} 351}
352 352
353/*! 353/*!
354 \internal 354 \internal
355*/ 355*/
356void Global::createDocDir() 356void Global::createDocDir()
357{ 357{
358 if ( !docDirCreated ) { 358 if ( !docDirCreated ) {
359 docDirCreated = TRUE; 359 docDirCreated = TRUE;
360 mkdir( QPEApplication::documentDir().latin1(), 0755 ); 360 mkdir( QPEApplication::documentDir().latin1(), 0755 );
361 } 361 }
362} 362}
363 363
364 364
365/*! 365/*!
366 Displays a status \a message to the user. This usually appears 366 Displays a status \a message to the user. This usually appears
367 in the taskbar for a short amount of time, then disappears. 367 in the taskbar for a short amount of time, then disappears.
368*/ 368*/
369void Global::statusMessage(const QString& message) 369void Global::statusMessage(const QString& message)
370{ 370{
371#if !defined(QT_NO_COP) 371#if !defined(QT_NO_COP)
372 QCopEnvelope e( "QPE/TaskBar", "message(QString)" ); 372 QCopEnvelope e( "QPE/TaskBar", "message(QString)" );
373 e << message; 373 e << message;
374#endif 374#endif
375} 375}
376 376
377/*! 377/*!
378 \internal 378 \internal
379*/ 379*/
380void Global::applyStyle() 380void Global::applyStyle()
381{ 381{
382#if !defined(QT_NO_COP) 382#if !defined(QT_NO_COP)
383 QCopChannel::send( "QPE/System", "applyStyle()" ); 383 QCopChannel::send( "QPE/System", "applyStyle()" );
384#else 384#else
385 ((QPEApplication *)qApp)->applyStyle(); // apply without needing QCop for floppy version 385 ((QPEApplication *)qApp)->applyStyle(); // apply without needing QCop for floppy version
386#endif 386#endif
387} 387}
388 388
389/*! 389/*!
390 \internal 390 \internal
391*/ 391*/
392QWidget *Global::shutdown( bool ) 392QWidget *Global::shutdown( bool )
393{ 393{
394#if !defined(QT_NO_COP) 394#if !defined(QT_NO_COP)
395 QCopChannel::send( "QPE/System", "shutdown()" ); 395 QCopChannel::send( "QPE/System", "shutdown()" );
396#endif 396#endif
397 return 0; 397 return 0;
398} 398}
399 399
400/*! 400/*!
401 \internal 401 \internal
402*/ 402*/
403QWidget *Global::restart( bool ) 403QWidget *Global::restart( bool )
404{ 404{
405#if !defined(QT_NO_COP) 405#if !defined(QT_NO_COP)
406 QCopChannel::send( "QPE/System", "restart()" ); 406 QCopChannel::send( "QPE/System", "restart()" );
407#endif 407#endif
408 return 0; 408 return 0;
409} 409}
410 410
411/*! 411/*!
412 Explicitly show the current input method. 412 Explicitly show the current input method.
413 413
414 Input methods are indicated in the taskbar by a small icon. If the 414 Input methods are indicated in the taskbar by a small icon. If the
415 input method is activated (shown) then it takes up some proportion 415 input method is activated (shown) then it takes up some proportion
416 of the bottom of the screen, to allow the user to interact (input 416 of the bottom of the screen, to allow the user to interact (input
417 characters) with it. 417 characters) with it.
418 418
419 \sa hideInputMethod() 419 \sa hideInputMethod()
420*/ 420*/
421void Global::showInputMethod() 421void Global::showInputMethod()
422{ 422{
423#if !defined(QT_NO_COP) 423#if !defined(QT_NO_COP)
424 QCopChannel::send( "QPE/TaskBar", "showInputMethod()" ); 424 QCopChannel::send( "QPE/TaskBar", "showInputMethod()" );
425#endif 425#endif
426} 426}
427 427
428/*! 428/*!
429 Explicitly hide the current input method. 429 Explicitly hide the current input method.
430 430
431 The current input method is still indicated in the taskbar, but no 431 The current input method is still indicated in the taskbar, but no
432 longer takes up screen space, and can no longer be interacted with. 432 longer takes up screen space, and can no longer be interacted with.
433 433
434 \sa showInputMethod() 434 \sa showInputMethod()
435*/ 435*/
436void Global::hideInputMethod() 436void Global::hideInputMethod()
437{ 437{
438#if !defined(QT_NO_COP) 438#if !defined(QT_NO_COP)
439 QCopChannel::send( "QPE/TaskBar", "hideInputMethod()" ); 439 QCopChannel::send( "QPE/TaskBar", "hideInputMethod()" );
440#endif 440#endif
441} 441}
442 442
443 443
444/*! 444/*!
445 \internal 445 \internal
446*/ 446*/
447bool Global::isBuiltinCommand( const QString &name ) 447bool Global::isBuiltinCommand( const QString &name )
448{ 448{
449 if(!builtin) 449 if(!builtin)
450 return FALSE; // yes, it can happen 450 return FALSE; // yes, it can happen
451 for (int i = 0; builtin[i].file; i++) { 451 for (int i = 0; builtin[i].file; i++) {
452 if ( builtin[i].file == name ) { 452 if ( builtin[i].file == name ) {
453 return TRUE; 453 return TRUE;
454 } 454 }
455 } 455 }
456 return FALSE; 456 return FALSE;
457} 457}
458 458
459Global::Command* Global::builtin=0; 459Global::Command* Global::builtin=0;
460QGuardedPtr<QWidget> *Global::running=0; 460QGuardedPtr<QWidget> *Global::running=0;
461 461
462/*! 462/*!
463 \class Global::Command 463 \class Global::Command
464 \brief The Global::Command class is internal. 464 \brief The Global::Command class is internal.
465 \internal 465 \internal
466*/ 466*/
467 467
468/*! 468/*!
469 \internal 469 \internal
470*/ 470*/
471void Global::setBuiltinCommands( Command* list ) 471void Global::setBuiltinCommands( Command* list )
472{ 472{
473 if ( running ) 473 if ( running )
474 delete [] running; 474 delete [] running;
475 475
476 builtin = list; 476 builtin = list;
477 int count = 0; 477 int count = 0;
478 if (!builtin) 478 if (!builtin)
479 return; 479 return;
480 while ( builtin[count].file ) 480 while ( builtin[count].file )
481 count++; 481 count++;
482 482
483 running = new QGuardedPtr<QWidget> [ count ]; 483 running = new QGuardedPtr<QWidget> [ count ];
484} 484}
485 485
486/*! 486/*!
487 \internal 487 \internal
488*/ 488*/
489void Global::setDocument( QWidget* receiver, const QString& document ) 489void Global::setDocument( QWidget* receiver, const QString& document )
490{ 490{
491 Emitter emitter(receiver,document); 491 Emitter emitter(receiver,document);
492} 492}
493 493
494/*! 494/*!
495 \internal 495 \internal
496*/ 496*/
497bool Global::terminateBuiltin( const QString& n ) 497bool Global::terminateBuiltin( const QString& n )
498{ 498{
499 if (!builtin) 499 if (!builtin)
500 return FALSE; 500 return FALSE;
501 for (int i = 0; builtin[i].file; i++) { 501 for (int i = 0; builtin[i].file; i++) {
502 if ( builtin[i].file == n ) { 502 if ( builtin[i].file == n ) {
503 delete running[i]; 503 delete running[i];
504 return TRUE; 504 return TRUE;
505 } 505 }
506 } 506 }
507 return FALSE; 507 return FALSE;
508} 508}
509 509
510/*! 510/*!
511 \internal 511 \internal
512*/ 512*/
513void Global::terminate( const AppLnk* app ) 513void Global::terminate( const AppLnk* app )
514{ 514{
515 //if ( terminateBuiltin(app->exec()) ) return; // maybe? haven't tried this 515 //if ( terminateBuiltin(app->exec()) ) return; // maybe? haven't tried this
516 516
517#ifndef QT_NO_COP 517#ifndef QT_NO_COP
518 QCString channel = "QPE/Application/" + app->exec().utf8(); 518 QCString channel = "QPE/Application/" + app->exec().utf8();
519 if ( QCopChannel::isRegistered(channel) ) { 519 if ( QCopChannel::isRegistered(channel) ) {
520 QCopEnvelope e(channel, "quit()"); 520 QCopEnvelope e(channel, "quit()");
521 } 521 }
522#endif 522#endif
523} 523}
524 524
525/*! 525/*!
526 Low-level function to run command \a c. 526 Low-level function to run command \a c.
527 527
528 \warning Do not use this function. Use execute instead. 528 \warning Do not use this function. Use execute instead.
529 529
530 \sa execute() 530 \sa execute()
531*/ 531*/
532void Global::invoke(const QString &c) 532void Global::invoke(const QString &c)
533{ 533{
534 // Convert the command line in to a list of arguments 534 // Convert the command line in to a list of arguments
535 QStringList list = QStringList::split(QRegExp(" *"),c); 535 QStringList list = QStringList::split(QRegExp(" *"),c);
536 536
537#if !defined(QT_NO_COP) 537#if !defined(QT_NO_COP)
538 QString ap=list[0]; 538 QString ap=list[0];
539 // see if the application is already running 539 // see if the application is already running
540 // XXX should lock file /tmp/qcop-msg-ap 540 // XXX should lock file /tmp/qcop-msg-ap
541 if ( QCopChannel::isRegistered( ("QPE/Application/" + ap).latin1() ) ) { 541 if ( QCopChannel::isRegistered( ("QPE/Application/" + ap).latin1() ) ) {
542 // If the channel is already register, the app is already running, so show it. 542 // If the channel is already register, the app is already running, so show it.
543 { QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "raise()" ); } 543 {
544 544 QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "raise()" );
545 //QCopEnvelope e("QPE/System", "notBusy(QString)" ); 545 }
546 //e << ap; 546
547 return; 547 //QCopEnvelope e("QPE/System", "notBusy(QString)" );
548 //e << ap;
549 return;
548 } 550 }
549 // XXX should unlock file /tmp/qcop-msg-ap 551 // XXX should unlock file /tmp/qcop-msg-ap
550 //see if it is being started 552 //see if it is being started
551 if ( StartingAppList::isStarting( ap ) ) { 553 if ( StartingAppList::isStarting( ap ) ) {
552 // FIXME take it out for now, since it leads to a much to short showing of wait if 554 // FIXME take it out for now, since it leads to a much to short showing of wait if
553 // some entry is clicked. 555 // some entry is clicked.
554 // Real cause is that ::execute is called twice for document tab. But it would need some larger changes 556 // Real cause is that ::execute is called twice for document tab. But it would need some larger changes
555 // to fix that, and with future syncs with qtopia 1.6 it will change anyway big time since somebody there 557 // to fix that, and with future syncs with qtopia 1.6 it will change anyway big time since somebody there
556 // had the idea that an apploader belongs to the launcher ... 558 // had the idea that an apploader belongs to the launcher ...
557 //QCopEnvelope e("QPE/System", "notBusy(QString)" ); 559 //QCopEnvelope e("QPE/System", "notBusy(QString)" );
558 //e << ap; 560 //e << ap;
559 return; 561 return;
560 } 562 }
561 563
562#endif 564#endif
563 565
564#ifdef QT_NO_QWS_MULTIPROCESS 566#ifdef QT_NO_QWS_MULTIPROCESS
565 QMessageBox::warning( 0, "Error", "Could not find the application " + c, "Ok", 0, 0, 0, 1 ); 567 QMessageBox::warning( 0, "Error", "Could not find the application " + c, "Ok", 0, 0, 0, 1 );
566#else 568#else
567 569
568 QStrList slist; 570 QStrList slist;
569 unsigned int j; 571 unsigned int j;
570 for ( j = 0; j < list.count(); j++ ) 572 for ( j = 0; j < list.count(); j++ )
571 slist.append( list[j].utf8() ); 573 slist.append( list[j].utf8() );
572 574
573 const char **args = new const char *[slist.count() + 1]; 575 const char **args = new const char *[slist.count() + 1];
574 for ( j = 0; j < slist.count(); j++ ) 576 for ( j = 0; j < slist.count(); j++ )
575 args[j] = slist.at(j); 577 args[j] = slist.at(j);
578
576 args[j] = NULL; 579 args[j] = NULL;
577 580
578#if !defined(QT_NO_COP) 581#if !defined(QT_NO_COP)
579 // an attempt to show a wait... 582 // an attempt to show a wait...
580 // more logic should be used, but this will be fine for the moment... 583 // more logic should be used, but this will be fine for the moment...
581 QCopEnvelope ( "QPE/System", "busy()" ); 584 QCopEnvelope ( "QPE/System", "busy()" );
582#endif 585#endif
583 586
584#ifdef HAVE_QUICKEXEC 587#ifdef HAVE_QUICKEXEC
585#ifdef Q_OS_MACX 588#ifdef Q_OS_MACX
586 QString libexe = qpeDir()+"/binlib/lib"+args[0] + ".dylib"; 589 QString libexe = qpeDir()+"/binlib/lib"+args[0] + ".dylib";
587#else 590#else
588 QString libexe = qpeDir()+"/binlib/lib"+args[0] + ".so"; 591 QString libexe = qpeDir()+"/binlib/lib"+args[0] + ".so";
589#endif 592#endif
590 qDebug("libfile = %s", libexe.latin1() ); 593 qDebug("libfile = %s", libexe.latin1() );
591 if ( QFile::exists( libexe ) ) { 594 if ( QFile::exists( libexe ) ) {
592 qDebug("calling quickexec %s", libexe.latin1() ); 595 qDebug("calling quickexec %s", libexe.latin1() );
593 quickexecv( libexe.utf8().data(), (const char **)args ); 596 quickexecv( libexe.utf8().data(), (const char **)args );
594 } else 597 } else
595#endif 598#endif
596 { 599 {
597 bool success = false; 600 bool success = false;
598 int pfd [2]; 601 int pfd [2];
599 if ( ::pipe ( pfd ) < 0 ) 602 if ( ::pipe ( pfd ) < 0 )
600 pfd [0] = pfd [1] = -1; 603 pfd [0] = pfd [1] = -1;
601 604
602 pid_t pid = ::fork ( ); 605 pid_t pid = ::fork ( );
603 606
604 if ( pid == 0 ) { // child 607 if ( pid == 0 ) { // child
605 for ( int fd = 3; fd < 100; fd++ ) { 608 for ( int fd = 3; fd < 100; fd++ ) {
606 if ( fd != pfd [1] ) 609 if ( fd != pfd [1] )
607 ::close ( fd ); 610 ::close ( fd );
608 } 611 }
609 ::setpgid ( ::getpid ( ), ::getppid ( )); 612 ::setpgid ( ::getpid ( ), ::getppid ( ));
610 613
611 // Closing of fd[1] indicates that the execvp succeeded! 614 // Closing of fd[1] indicates that the execvp succeeded!
612 if ( pfd [1] >= 0 ) 615 if ( pfd [1] >= 0 )
613 ::fcntl ( pfd [1], F_SETFD, FD_CLOEXEC ); 616 ::fcntl ( pfd [1], F_SETFD, FD_CLOEXEC );
614 617
615 // Try bindir first, so that foo/bar works too 618 // Try bindir first, so that foo/bar works too
616 ::execv ( qpeDir ( ) + "/bin/" + args [0], (char * const *) args ); 619 ::execv ( qpeDir ( ) + "/bin/" + args [0], (char * const *) args );
617 ::execvp ( args [0], (char * const *) args ); 620 ::execvp ( args [0], (char * const *) args );
618 621
619 char resultByte = 1; 622 char resultByte = 1;
620 if ( pfd [1] >= 0 ) 623 if ( pfd [1] >= 0 )
621 ::write ( pfd [1], &resultByte, 1 ); 624 ::write ( pfd [1], &resultByte, 1 );
622 ::_exit ( -1 ); 625 ::_exit ( -1 );
623 } 626 }
624 else if ( pid > 0 ) { 627 else if ( pid > 0 ) {
625 success = true; 628 success = true;
626 629
627 if ( pfd [1] >= 0 ) 630 if ( pfd [1] >= 0 )
628 ::close ( pfd [1] ); 631 ::close ( pfd [1] );
629 if ( pfd [0] >= 0 ) { 632 if ( pfd [0] >= 0 ) {
630 while ( true ) { 633 while ( true ) {
631 char resultByte; 634 char resultByte;
632 int n = ::read ( pfd [0], &resultByte, 1 ); 635 int n = ::read ( pfd [0], &resultByte, 1 );
633 if ( n == 1 ) { 636 if ( n == 1 ) {
634 success = false; 637 success = false;
635 break; 638 break;
636 } 639 }
637 if (( n == -1 ) && (( errno == ECHILD ) || ( errno == EINTR ))) 640 if (( n == -1 ) && (( errno == ECHILD ) || ( errno == EINTR )))
638 continue; 641 continue;
639 642
640 break; // success 643 break; // success
641 } 644 }
642 ::close ( pfd [0] ); 645 ::close ( pfd [0] );
643 } 646 }
644 } 647 }
645 if ( success ) 648 if ( success )
646 StartingAppList::add( list[0] ); 649 StartingAppList::add( list[0] );
647 else 650 else
648 QMessageBox::warning( 0, "Error", "Could not start the application " + c, "Ok", 0, 0, 0, 1 ); 651 QMessageBox::warning( 0, "Error", "Could not start the application " + c, "Ok", 0, 0, 0, 1 );
649 } 652 }
653 delete [] args;
650#endif //QT_NO_QWS_MULTIPROCESS 654#endif //QT_NO_QWS_MULTIPROCESS
651} 655}
652 656
653 657
654/*! 658/*!
655 Executes the application identfied by \a c, passing \a 659 Executes the application identfied by \a c, passing \a
656 document if it isn't null. 660 document if it isn't null.
657 661
658 Note that a better approach might be to send a QCop message to the 662 Note that a better approach might be to send a QCop message to the
659 application's QPE/Application/\e{appname} channel. 663 application's QPE/Application/\e{appname} channel.
660*/ 664*/
661void Global::execute( const QString &c, const QString& document ) 665void Global::execute( const QString &c, const QString& document )
662{ 666{
663 // ask the server to do the work 667 // ask the server to do the work
664#if !defined(QT_NO_COP) 668#if !defined(QT_NO_COP)
665 if ( document.isNull() ) { 669 if ( document.isNull() ) {
666 QCopEnvelope e( "QPE/System", "execute(QString)" ); 670 QCopEnvelope e( "QPE/System", "execute(QString)" );
667 e << c; 671 e << c;
668 } else { 672 } else {
669 QCopEnvelope e( "QPE/System", "execute(QString,QString)" ); 673 QCopEnvelope e( "QPE/System", "execute(QString,QString)" );
670 e << c << document; 674 e << c << document;
671 } 675 }
672#endif 676#endif
673 return; 677 return;
674} 678}
675 679
676/*! 680/*!
677 Returns the string \a s with the characters '\', '"', and '$' quoted 681 Returns the string \a s with the characters '\', '"', and '$' quoted
678 by a preceeding '\'. 682 by a preceeding '\'.
679 683
680 \sa stringQuote() 684 \sa stringQuote()
681*/ 685*/
682QString Global::shellQuote(const QString& s) 686QString Global::shellQuote(const QString& s)
683{ 687{
684 QString r="\""; 688 QString r="\"";
685 for (int i=0; i<(int)s.length(); i++) { 689 for (int i=0; i<(int)s.length(); i++) {
686 char c = s[i].latin1(); 690 char c = s[i].latin1();
687 switch (c) { 691 switch (c) {
688 case '\\': case '"': case '$': 692 case '\\': case '"': case '$':
689 r+="\\"; 693 r+="\\";
690 } 694 }
691 r += s[i]; 695 r += s[i];
692 } 696 }
693 r += "\""; 697 r += "\"";
694 return r; 698 return r;
695} 699}
696 700
697/*! 701/*!
698 Returns the string \a s with the characters '\' and '"' quoted by a 702 Returns the string \a s with the characters '\' and '"' quoted by a
699 preceeding '\'. 703 preceeding '\'.
700 704
701 \sa shellQuote() 705 \sa shellQuote()
702*/ 706*/
703QString Global::stringQuote(const QString& s) 707QString Global::stringQuote(const QString& s)
704{ 708{
705 QString r="\""; 709 QString r="\"";
706 for (int i=0; i<(int)s.length(); i++) { 710 for (int i=0; i<(int)s.length(); i++) {
707 char c = s[i].latin1(); 711 char c = s[i].latin1();
708 switch (c) { 712 switch (c) {
709 case '\\': case '"': 713 case '\\': case '"':
710 r+="\\"; 714 r+="\\";
711 } 715 }
712 r += s[i]; 716 r += s[i];
713 } 717 }
714 r += "\""; 718 r += "\"";
715 return r; 719 return r;
716} 720}
717 721
718/*! 722/*!
719 Finds all documents on the system's document directories which 723 Finds all documents on the system's document directories which
720 match the filter \a mimefilter, and appends the resulting DocLnk 724 match the filter \a mimefilter, and appends the resulting DocLnk
721 objects to \a folder. 725 objects to \a folder.
722*/ 726*/
723void Global::findDocuments(DocLnkSet* folder, const QString &mimefilter) 727void Global::findDocuments(DocLnkSet* folder, const QString &mimefilter)
724{ 728{
725 QString homedocs = QString(getenv("HOME")) + "/Documents"; 729 QString homedocs = QString(getenv("HOME")) + "/Documents";
726 DocLnkSet d(homedocs,mimefilter); 730 DocLnkSet d(homedocs,mimefilter);
727 folder->appendFrom(d); 731 folder->appendFrom(d);
728 /** let's do intellegint way of searching these files 732 /** let's do intellegint way of searching these files
729 * a) the user don't want to check mediums global 733 * a) the user don't want to check mediums global
730 * b) the user wants to check but use the global options for it 734 * b) the user wants to check but use the global options for it
731 * c) the user wants to check it but not this medium 735 * c) the user wants to check it but not this medium
732 * d) the user wants to check and this medium as well 736 * d) the user wants to check and this medium as well
733 * 737 *
734 * In all cases we need to apply a different mimefilter to 738 * In all cases we need to apply a different mimefilter to
735 * the medium. 739 * the medium.
736 * a) mimefilter.isEmpty() we need to apply the responding filter 740 * a) mimefilter.isEmpty() we need to apply the responding filter
737 * either the global or the one on the medium 741 * either the global or the one on the medium
738 * 742 *
739 * b) mimefilter is set to an application we need to find out if the 743 * b) mimefilter is set to an application we need to find out if the
740 * mimetypes are included in the mime mask of the medium 744 * mimetypes are included in the mime mask of the medium
741 */ 745 */
742 StorageInfo storage; 746 StorageInfo storage;
743 const QList<FileSystem> &fs = storage.fileSystems(); 747 const QList<FileSystem> &fs = storage.fileSystems();
744 QListIterator<FileSystem> it ( fs ); 748 QListIterator<FileSystem> it ( fs );
745 for ( ; it.current(); ++it ) { 749 for ( ; it.current(); ++it ) {
746 if ( (*it)->isRemovable() ) { // let's find out if we should search on it 750 if ( (*it)->isRemovable() ) { // let's find out if we should search on it
747 // this is a candidate look at the cf and see if we should search on it 751 // this is a candidate look at the cf and see if we should search on it
748 QString path = (*it)->path(); 752 QString path = (*it)->path();
749 Config conf((*it)->path() + "/.opiestorage.cf", Config::File ); 753 Config conf((*it)->path() + "/.opiestorage.cf", Config::File );
750 conf.setGroup("main"); 754 conf.setGroup("main");
751 if (!conf.readBoolEntry("check",true)) { 755 if (!conf.readBoolEntry("check",true)) {
752 continue; 756 continue;
753 } 757 }
754 conf.setGroup("subdirs"); 758 conf.setGroup("subdirs");
755 if (conf.readBoolEntry("wholemedia",true)) { 759 if (conf.readBoolEntry("wholemedia",true)) {
756 DocLnkSet ide( path,mimefilter); 760 DocLnkSet ide( path,mimefilter);
757 folder->appendFrom(ide); 761 folder->appendFrom(ide);
758 } else { 762 } else {
759 QStringList subDirs = conf.readListEntry("subdirs",':'); 763 QStringList subDirs = conf.readListEntry("subdirs",':');
760 if (subDirs.isEmpty()) { 764 if (subDirs.isEmpty()) {
761 subDirs.append("Documents"); 765 subDirs.append("Documents");
762 } 766 }
763 for (unsigned c = 0; c < subDirs.count();++c) { 767 for (unsigned c = 0; c < subDirs.count();++c) {
764 DocLnkSet ide( path+"/"+subDirs[c], mimefilter ); 768 DocLnkSet ide( path+"/"+subDirs[c], mimefilter );
765 folder->appendFrom(ide); 769 folder->appendFrom(ide);
766 } 770 }
767 } 771 }
768 } else if ( (*it)->disk() == "/dev/mtdblock6" || (*it)->disk() == "tmpfs" ) { 772 } else if ( (*it)->disk() == "/dev/mtdblock6" || (*it)->disk() == "tmpfs" ) {
769 QString path = (*it)->path() + "/Documents"; 773 QString path = (*it)->path() + "/Documents";
770 DocLnkSet ide( path, mimefilter ); 774 DocLnkSet ide( path, mimefilter );
771 folder->appendFrom(ide); 775 folder->appendFrom(ide);
772 } 776 }
773 } 777 }
774} 778}
775 779
776QStringList Global::languageList() 780QStringList Global::languageList()
777{ 781{
778 QString lang = getenv("LANG"); 782 QString lang = getenv("LANG");
779 QStringList langs; 783 QStringList langs;
780 langs.append(lang); 784 langs.append(lang);
781 int i = lang.find("."); 785 int i = lang.find(".");
782 if ( i > 0 ) 786 if ( i > 0 )
783 lang = lang.left( i ); 787 lang = lang.left( i );
784 i = lang.find( "_" ); 788 i = lang.find( "_" );
785 if ( i > 0 ) 789 if ( i > 0 )
786 langs.append(lang.left(i)); 790 langs.append(lang.left(i));
787 return langs; 791 return langs;
788} 792}
789 793
790QStringList Global::helpPath() 794QStringList Global::helpPath()
791{ 795{
792 QString qpeDir = QPEApplication::qpeDir(); 796 QString qpeDir = QPEApplication::qpeDir();
793 QStringList path; 797 QStringList path;
794 QStringList langs = Global::languageList(); 798 QStringList langs = Global::languageList();
795 for (QStringList::ConstIterator it = langs.fromLast(); it!=langs.end(); --it) { 799 for (QStringList::ConstIterator it = langs.fromLast(); it!=langs.end(); --it) {
796 QString lang = *it; 800 QString lang = *it;
797 if ( !lang.isEmpty() ) 801 if ( !lang.isEmpty() )
798 path += qpeDir + "/help/" + lang + "/html"; 802 path += qpeDir + "/help/" + lang + "/html";
799 } 803 }
800 path += qpeDir + "/pics"; 804 path += qpeDir + "/pics";
801 path += qpeDir + "/help/html"; 805 path += qpeDir + "/help/html";
802 /* we even put english into the en dir so try it as fallback as well for opie */ 806 /* we even put english into the en dir so try it as fallback as well for opie */
803 path += qpeDir + "/help/en/html"; 807 path += qpeDir + "/help/en/html";
804 path += qpeDir + "/docs"; 808 path += qpeDir + "/docs";
805 809
806 810
807 return path; 811 return path;
808} 812}
809 813
810/*! 814/*!
811 \internal 815 \internal
812 Truncate file to size specified 816 Truncate file to size specified
813 \a f must be an open file 817 \a f must be an open file
814 \a size must be a positive value 818 \a size must be a positive value
815 */ 819 */
816bool Global::truncateFile(QFile &f, int size){ 820bool Global::truncateFile(QFile &f, int size){
817 if (!f.isOpen()) 821 if (!f.isOpen())
818 return FALSE; 822 return FALSE;
819 823
820 return ::ftruncate(f.handle(), size) != -1; 824 return ::ftruncate(f.handle(), size) != -1;
821} 825}
822 826
823 827
824 828
825 829
826// #if defined(Q_OS_UNIX) && defined(Q_WS_QWS) 830// #if defined(Q_OS_UNIX) && defined(Q_WS_QWS)
827// extern int qws_display_id; 831// extern int qws_display_id;
828// #endif 832// #endif
829 833
830/*! 834/*!
831 /internal 835 /internal
832 Returns the default system path for storing temporary files. 836 Returns the default system path for storing temporary files.
833 Note: This does not it ensure that the provided directory exists 837 Note: This does not it ensure that the provided directory exists
834*/ 838*/
835QString Global::tempDir() 839QString Global::tempDir()
836{ 840{
837 QString result; 841 QString result;
838#ifdef Q_OS_UNIX 842#ifdef Q_OS_UNIX
839#ifdef Q_WS_QWS 843#ifdef Q_WS_QWS
840 result = QString("/tmp/qtopia-%1/").arg(QString::number(qws_display_id)); 844 result = QString("/tmp/qtopia-%1/").arg(QString::number(qws_display_id));
841#else 845#else
842 result="/tmp/"; 846 result="/tmp/";
843#endif 847#endif
844#else 848#else
845 if (getenv("TEMP")) 849 if (getenv("TEMP"))
846 result = getenv("TEMP"); 850 result = getenv("TEMP");
847 else 851 else
848 result = getenv("TMP"); 852 result = getenv("TMP");
849 853
850 if (result[(int)result.length() - 1] != QDir::separator()) 854 if (result[(int)result.length() - 1] != QDir::separator())
851 result.append(QDir::separator()); 855 result.append(QDir::separator());
852#endif 856#endif
853 857
854 return result; 858 return result;
855} 859}
856 860
857//#endif 861//#endif
858 862
859 863
860#include "global.moc" 864#include "global.moc"