summaryrefslogtreecommitdiff
path: root/library
authorerik <erik>2007-01-19 01:18:01 (UTC)
committer erik <erik>2007-01-19 01:18:01 (UTC)
commit32343107b30904806d02672955c57ed53d39fe79 (patch) (unidiff)
tree9114a0ea170e3adc807a2445b49360f1bfde9626 /library
parentac0ce844e90a64247c0adb210e0a23021b011d57 (diff)
downloadopie-32343107b30904806d02672955c57ed53d39fe79.zip
opie-32343107b30904806d02672955c57ed53d39fe79.tar.gz
opie-32343107b30904806d02672955c57ed53d39fe79.tar.bz2
Every file in this commit has a change to check the return value of a call.
Diffstat (limited to 'library') (more/less context) (ignore whitespace changes)
-rw-r--r--library/global.cpp63
1 files changed, 31 insertions, 32 deletions
diff --git a/library/global.cpp b/library/global.cpp
index f7a0767..7bdd0b1 100644
--- a/library/global.cpp
+++ b/library/global.cpp
@@ -1,763 +1,762 @@
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 }
236 QFile dawgfile(dawgfilename);
237
238 if ( !dawgfile.exists() ) {
239 QString fn = dictDir() + "/words";
240 if ( QFile::exists(words_lang) )
241 fn = words_lang;
242 QFile in(fn);
243 if ( in.open(IO_ReadOnly) ) {
244 fixed_dawg->createFromWords(&in);
245 dawgfile.open(IO_WriteOnly);
246 fixed_dawg->write(&dawgfile);
247 dawgfile.close();
248 } 235 }
249 } else { 236 QFile dawgfile(dawgfilename);
250 fixed_dawg->readFile(dawgfilename); 237
251 } 238 if ( !dawgfile.exists() ) {
239 QString fn = dictDir() + "/words";
240 if ( QFile::exists(words_lang) )
241 fn = words_lang;
242 QFile in(fn);
243 if ( in.open(IO_ReadOnly) ) {
244 fixed_dawg->createFromWords(&in);
245 if (dawgfile.open(IO_WriteOnly))
246 fixed_dawg->write(&dawgfile);
247 dawgfile.close();
248 }
249 } else
250 fixed_dawg->readFile(dawgfilename);
252 } 251 }
253 252
254 return *fixed_dawg; 253 return *fixed_dawg;
255} 254}
256 255
257/*! 256/*!
258 Returns the changeable QDawg that contains general 257 Returns the changeable QDawg that contains general
259 words for the current locale. 258 words for the current locale.
260 259
261 \sa fixedDawg() 260 \sa fixedDawg()
262*/ 261*/
263const QDawg& Global::addedDawg() 262const QDawg& Global::addedDawg()
264{ 263{
265 return dawg("local"); 264 return dawg("local");
266} 265}
267 266
268/*! 267/*!
269 Returns the QDawg with the given \a name. 268 Returns the QDawg with the given \a name.
270 This is an application-specific word list. 269 This is an application-specific word list.
271 270
272 \a name should not contain "/". 271 \a name should not contain "/".
273*/ 272*/
274const QDawg& Global::dawg(const QString& name) 273const QDawg& Global::dawg(const QString& name)
275{ 274{
276 createDocDir(); 275 createDocDir();
277 if ( !named_dawg ) 276 if ( !named_dawg )
278 named_dawg = new QDict<QDawg>; 277 named_dawg = new QDict<QDawg>;
279 QDawg* r = named_dawg->find(name); 278 QDawg* r = named_dawg->find(name);
280 if ( !r ) { 279 if ( !r ) {
281 r = new QDawg; 280 r = new QDawg;
282 named_dawg->insert(name,r); 281 named_dawg->insert(name,r);
283 QString dawgfilename = applicationFileName("Dictionary", name ) + ".dawg"; 282 QString dawgfilename = applicationFileName("Dictionary", name ) + ".dawg";
284 QFile dawgfile(dawgfilename); 283 QFile dawgfile(dawgfilename);
285 if ( dawgfile.open(IO_ReadOnly) ) 284 if ( dawgfile.open(IO_ReadOnly) )
286 r->readFile(dawgfilename); 285 r->readFile(dawgfilename);
287 } 286 }
288 return *r; 287 return *r;
289} 288}
290 289
291/*! 290/*!
292 \overload 291 \overload
293 Adds \a wordlist to the addedDawg(). 292 Adds \a wordlist to the addedDawg().
294 293
295 Note that the addition of words persists between program executions 294 Note that the addition of words persists between program executions
296 (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
297 words with the user before adding them. 296 words with the user before adding them.
298*/ 297*/
299void Global::addWords(const QStringList& wordlist) 298void Global::addWords(const QStringList& wordlist)
300{ 299{
301 addWords("local",wordlist); 300 addWords("local",wordlist);
302} 301}
303 302
304/*! 303/*!
305 \overload 304 \overload
306 Adds \a wordlist to the addedDawg(). 305 Adds \a wordlist to the addedDawg().
307 306
308 Note that the addition of words persists between program executions 307 Note that the addition of words persists between program executions
309 (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
310 words with the user before adding them. 309 words with the user before adding them.
311*/ 310*/
312void Global::addWords(const QString& dictname, const QStringList& wordlist) 311void Global::addWords(const QString& dictname, const QStringList& wordlist)
313{ 312{
314 QDawg& d = (QDawg&)dawg(dictname); 313 QDawg& d = (QDawg&)dawg(dictname);
315 QStringList all = d.allWords() + wordlist; 314 QStringList all = d.allWords() + wordlist;
316 d.createFromWords(all); 315 d.createFromWords(all);
317 316
318 QString dawgfilename = applicationFileName("Dictionary", dictname) + ".dawg"; 317 QString dawgfilename = applicationFileName("Dictionary", dictname) + ".dawg";
319 QFile dawgfile(dawgfilename); 318 QFile dawgfile(dawgfilename);
320 if ( dawgfile.open(IO_WriteOnly) ) { 319 if ( dawgfile.open(IO_WriteOnly) ) {
321 d.write(&dawgfile); 320 d.write(&dawgfile);
322 dawgfile.close(); 321 dawgfile.close();
323 } 322 }
324 323
325 // #### Re-read the dawg here if we use mmap(). 324 // #### Re-read the dawg here if we use mmap().
326 325
327 // #### Signal other processes to re-read. 326 // #### Signal other processes to re-read.
328} 327}
329 328
330 329
331/*! 330/*!
332 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
333 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
334 the directory tree for \a appname. 333 the directory tree for \a appname.
335 If \a filename contains "/", it is the caller's responsibility to 334 If \a filename contains "/", it is the caller's responsibility to
336 ensure that those directories exist. 335 ensure that those directories exist.
337*/ 336*/
338QString Global::applicationFileName(const QString& appname, const QString& filename) 337QString Global::applicationFileName(const QString& appname, const QString& filename)
339{ 338{
340 QDir d; 339 QDir d;
341 QString r = getenv("HOME"); 340 QString r = getenv("HOME");
342 r += "/Applications/"; 341 r += "/Applications/";
343 if ( !QFile::exists( r ) ) 342 if ( !QFile::exists( r ) )
344 if ( d.mkdir(r) == false ) 343 if ( d.mkdir(r) == false )
345 return QString::null; 344 return QString::null;
346 r += appname; 345 r += appname;
347 if ( !QFile::exists( r ) ) 346 if ( !QFile::exists( r ) )
348 if ( d.mkdir(r) == false ) 347 if ( d.mkdir(r) == false )
349 return QString::null; 348 return QString::null;
350 r += "/"; r += filename; 349 r += "/"; r += filename;
351 return r; 350 return r;
352} 351}
353 352
354/*! 353/*!
355 \internal 354 \internal
356*/ 355*/
357void Global::createDocDir() 356void Global::createDocDir()
358{ 357{
359 if ( !docDirCreated ) { 358 if ( !docDirCreated ) {
360 docDirCreated = TRUE; 359 docDirCreated = TRUE;
361 mkdir( QPEApplication::documentDir().latin1(), 0755 ); 360 mkdir( QPEApplication::documentDir().latin1(), 0755 );
362 } 361 }
363} 362}
364 363
365 364
366/*! 365/*!
367 Displays a status \a message to the user. This usually appears 366 Displays a status \a message to the user. This usually appears
368 in the taskbar for a short amount of time, then disappears. 367 in the taskbar for a short amount of time, then disappears.
369*/ 368*/
370void Global::statusMessage(const QString& message) 369void Global::statusMessage(const QString& message)
371{ 370{
372#if !defined(QT_NO_COP) 371#if !defined(QT_NO_COP)
373 QCopEnvelope e( "QPE/TaskBar", "message(QString)" ); 372 QCopEnvelope e( "QPE/TaskBar", "message(QString)" );
374 e << message; 373 e << message;
375#endif 374#endif
376} 375}
377 376
378/*! 377/*!
379 \internal 378 \internal
380*/ 379*/
381void Global::applyStyle() 380void Global::applyStyle()
382{ 381{
383#if !defined(QT_NO_COP) 382#if !defined(QT_NO_COP)
384 QCopChannel::send( "QPE/System", "applyStyle()" ); 383 QCopChannel::send( "QPE/System", "applyStyle()" );
385#else 384#else
386 ((QPEApplication *)qApp)->applyStyle(); // apply without needing QCop for floppy version 385 ((QPEApplication *)qApp)->applyStyle(); // apply without needing QCop for floppy version
387#endif 386#endif
388} 387}
389 388
390/*! 389/*!
391 \internal 390 \internal
392*/ 391*/
393QWidget *Global::shutdown( bool ) 392QWidget *Global::shutdown( bool )
394{ 393{
395#if !defined(QT_NO_COP) 394#if !defined(QT_NO_COP)
396 QCopChannel::send( "QPE/System", "shutdown()" ); 395 QCopChannel::send( "QPE/System", "shutdown()" );
397#endif 396#endif
398 return 0; 397 return 0;
399} 398}
400 399
401/*! 400/*!
402 \internal 401 \internal
403*/ 402*/
404QWidget *Global::restart( bool ) 403QWidget *Global::restart( bool )
405{ 404{
406#if !defined(QT_NO_COP) 405#if !defined(QT_NO_COP)
407 QCopChannel::send( "QPE/System", "restart()" ); 406 QCopChannel::send( "QPE/System", "restart()" );
408#endif 407#endif
409 return 0; 408 return 0;
410} 409}
411 410
412/*! 411/*!
413 Explicitly show the current input method. 412 Explicitly show the current input method.
414 413
415 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
416 input method is activated (shown) then it takes up some proportion 415 input method is activated (shown) then it takes up some proportion
417 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
418 characters) with it. 417 characters) with it.
419 418
420 \sa hideInputMethod() 419 \sa hideInputMethod()
421*/ 420*/
422void Global::showInputMethod() 421void Global::showInputMethod()
423{ 422{
424#if !defined(QT_NO_COP) 423#if !defined(QT_NO_COP)
425 QCopChannel::send( "QPE/TaskBar", "showInputMethod()" ); 424 QCopChannel::send( "QPE/TaskBar", "showInputMethod()" );
426#endif 425#endif
427} 426}
428 427
429/*! 428/*!
430 Explicitly hide the current input method. 429 Explicitly hide the current input method.
431 430
432 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
433 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.
434 433
435 \sa showInputMethod() 434 \sa showInputMethod()
436*/ 435*/
437void Global::hideInputMethod() 436void Global::hideInputMethod()
438{ 437{
439#if !defined(QT_NO_COP) 438#if !defined(QT_NO_COP)
440 QCopChannel::send( "QPE/TaskBar", "hideInputMethod()" ); 439 QCopChannel::send( "QPE/TaskBar", "hideInputMethod()" );
441#endif 440#endif
442} 441}
443 442
444 443
445/*! 444/*!
446 \internal 445 \internal
447*/ 446*/
448bool Global::isBuiltinCommand( const QString &name ) 447bool Global::isBuiltinCommand( const QString &name )
449{ 448{
450 if(!builtin) 449 if(!builtin)
451 return FALSE; // yes, it can happen 450 return FALSE; // yes, it can happen
452 for (int i = 0; builtin[i].file; i++) { 451 for (int i = 0; builtin[i].file; i++) {
453 if ( builtin[i].file == name ) { 452 if ( builtin[i].file == name ) {
454 return TRUE; 453 return TRUE;
455 } 454 }
456 } 455 }
457 return FALSE; 456 return FALSE;
458} 457}
459 458
460Global::Command* Global::builtin=0; 459Global::Command* Global::builtin=0;
461QGuardedPtr<QWidget> *Global::running=0; 460QGuardedPtr<QWidget> *Global::running=0;
462 461
463/*! 462/*!
464 \class Global::Command 463 \class Global::Command
465 \brief The Global::Command class is internal. 464 \brief The Global::Command class is internal.
466 \internal 465 \internal
467*/ 466*/
468 467
469/*! 468/*!
470 \internal 469 \internal
471*/ 470*/
472void Global::setBuiltinCommands( Command* list ) 471void Global::setBuiltinCommands( Command* list )
473{ 472{
474 if ( running ) 473 if ( running )
475 delete [] running; 474 delete [] running;
476 475
477 builtin = list; 476 builtin = list;
478 int count = 0; 477 int count = 0;
479 if (!builtin) 478 if (!builtin)
480 return; 479 return;
481 while ( builtin[count].file ) 480 while ( builtin[count].file )
482 count++; 481 count++;
483 482
484 running = new QGuardedPtr<QWidget> [ count ]; 483 running = new QGuardedPtr<QWidget> [ count ];
485} 484}
486 485
487/*! 486/*!
488 \internal 487 \internal
489*/ 488*/
490void Global::setDocument( QWidget* receiver, const QString& document ) 489void Global::setDocument( QWidget* receiver, const QString& document )
491{ 490{
492 Emitter emitter(receiver,document); 491 Emitter emitter(receiver,document);
493} 492}
494 493
495/*! 494/*!
496 \internal 495 \internal
497*/ 496*/
498bool Global::terminateBuiltin( const QString& n ) 497bool Global::terminateBuiltin( const QString& n )
499{ 498{
500 if (!builtin) 499 if (!builtin)
501 return FALSE; 500 return FALSE;
502 for (int i = 0; builtin[i].file; i++) { 501 for (int i = 0; builtin[i].file; i++) {
503 if ( builtin[i].file == n ) { 502 if ( builtin[i].file == n ) {
504 delete running[i]; 503 delete running[i];
505 return TRUE; 504 return TRUE;
506 } 505 }
507 } 506 }
508 return FALSE; 507 return FALSE;
509} 508}
510 509
511/*! 510/*!
512 \internal 511 \internal
513*/ 512*/
514void Global::terminate( const AppLnk* app ) 513void Global::terminate( const AppLnk* app )
515{ 514{
516 //if ( terminateBuiltin(app->exec()) ) return; // maybe? haven't tried this 515 //if ( terminateBuiltin(app->exec()) ) return; // maybe? haven't tried this
517 516
518#ifndef QT_NO_COP 517#ifndef QT_NO_COP
519 QCString channel = "QPE/Application/" + app->exec().utf8(); 518 QCString channel = "QPE/Application/" + app->exec().utf8();
520 if ( QCopChannel::isRegistered(channel) ) { 519 if ( QCopChannel::isRegistered(channel) ) {
521 QCopEnvelope e(channel, "quit()"); 520 QCopEnvelope e(channel, "quit()");
522 } 521 }
523#endif 522#endif
524} 523}
525 524
526/*! 525/*!
527 Low-level function to run command \a c. 526 Low-level function to run command \a c.
528 527
529 \warning Do not use this function. Use execute instead. 528 \warning Do not use this function. Use execute instead.
530 529
531 \sa execute() 530 \sa execute()
532*/ 531*/
533void Global::invoke(const QString &c) 532void Global::invoke(const QString &c)
534{ 533{
535 // Convert the command line in to a list of arguments 534 // Convert the command line in to a list of arguments
536 QStringList list = QStringList::split(QRegExp(" *"),c); 535 QStringList list = QStringList::split(QRegExp(" *"),c);
537 536
538#if !defined(QT_NO_COP) 537#if !defined(QT_NO_COP)
539 QString ap=list[0]; 538 QString ap=list[0];
540 // see if the application is already running 539 // see if the application is already running
541 // XXX should lock file /tmp/qcop-msg-ap 540 // XXX should lock file /tmp/qcop-msg-ap
542 if ( QCopChannel::isRegistered( ("QPE/Application/" + ap).latin1() ) ) { 541 if ( QCopChannel::isRegistered( ("QPE/Application/" + ap).latin1() ) ) {
543 // 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.
544 { QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "raise()" ); } 543 { QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "raise()" ); }
545 544
546 //QCopEnvelope e("QPE/System", "notBusy(QString)" ); 545 //QCopEnvelope e("QPE/System", "notBusy(QString)" );
547 //e << ap; 546 //e << ap;
548 return; 547 return;
549 } 548 }
550 // XXX should unlock file /tmp/qcop-msg-ap 549 // XXX should unlock file /tmp/qcop-msg-ap
551 //see if it is being started 550 //see if it is being started
552 if ( StartingAppList::isStarting( ap ) ) { 551 if ( StartingAppList::isStarting( ap ) ) {
553 // FIXME take it out for now, since it leads to a much to short showing of wait if 552 // FIXME take it out for now, since it leads to a much to short showing of wait if
554 // some entry is clicked. 553 // some entry is clicked.
555 // Real cause is that ::execute is called twice for document tab. But it would need some larger changes 554 // Real cause is that ::execute is called twice for document tab. But it would need some larger changes
556 // to fix that, and with future syncs with qtopia 1.6 it will change anyway big time since somebody there 555 // to fix that, and with future syncs with qtopia 1.6 it will change anyway big time since somebody there
557 // had the idea that an apploader belongs to the launcher ... 556 // had the idea that an apploader belongs to the launcher ...
558 //QCopEnvelope e("QPE/System", "notBusy(QString)" ); 557 //QCopEnvelope e("QPE/System", "notBusy(QString)" );
559 //e << ap; 558 //e << ap;
560 return; 559 return;
561 } 560 }
562 561
563#endif 562#endif
564 563
565#ifdef QT_NO_QWS_MULTIPROCESS 564#ifdef QT_NO_QWS_MULTIPROCESS
566 QMessageBox::warning( 0, "Error", "Could not find the application " + c, "Ok", 0, 0, 0, 1 ); 565 QMessageBox::warning( 0, "Error", "Could not find the application " + c, "Ok", 0, 0, 0, 1 );
567#else 566#else
568 567
569 QStrList slist; 568 QStrList slist;
570 unsigned int j; 569 unsigned int j;
571 for ( j = 0; j < list.count(); j++ ) 570 for ( j = 0; j < list.count(); j++ )
572 slist.append( list[j].utf8() ); 571 slist.append( list[j].utf8() );
573 572
574 const char **args = new const char *[slist.count() + 1]; 573 const char **args = new const char *[slist.count() + 1];
575 for ( j = 0; j < slist.count(); j++ ) 574 for ( j = 0; j < slist.count(); j++ )
576 args[j] = slist.at(j); 575 args[j] = slist.at(j);
577 args[j] = NULL; 576 args[j] = NULL;
578 577
579#if !defined(QT_NO_COP) 578#if !defined(QT_NO_COP)
580 // an attempt to show a wait... 579 // an attempt to show a wait...
581 // more logic should be used, but this will be fine for the moment... 580 // more logic should be used, but this will be fine for the moment...
582 QCopEnvelope ( "QPE/System", "busy()" ); 581 QCopEnvelope ( "QPE/System", "busy()" );
583#endif 582#endif
584 583
585#ifdef HAVE_QUICKEXEC 584#ifdef HAVE_QUICKEXEC
586#ifdef Q_OS_MACX 585#ifdef Q_OS_MACX
587 QString libexe = qpeDir()+"/binlib/lib"+args[0] + ".dylib"; 586 QString libexe = qpeDir()+"/binlib/lib"+args[0] + ".dylib";
588#else 587#else
589 QString libexe = qpeDir()+"/binlib/lib"+args[0] + ".so"; 588 QString libexe = qpeDir()+"/binlib/lib"+args[0] + ".so";
590#endif 589#endif
591 qDebug("libfile = %s", libexe.latin1() ); 590 qDebug("libfile = %s", libexe.latin1() );
592 if ( QFile::exists( libexe ) ) { 591 if ( QFile::exists( libexe ) ) {
593 qDebug("calling quickexec %s", libexe.latin1() ); 592 qDebug("calling quickexec %s", libexe.latin1() );
594 quickexecv( libexe.utf8().data(), (const char **)args ); 593 quickexecv( libexe.utf8().data(), (const char **)args );
595 } else 594 } else
596#endif 595#endif
597 { 596 {
598 bool success = false; 597 bool success = false;
599 int pfd [2]; 598 int pfd [2];
600 if ( ::pipe ( pfd ) < 0 ) 599 if ( ::pipe ( pfd ) < 0 )
601 pfd [0] = pfd [1] = -1; 600 pfd [0] = pfd [1] = -1;
602 601
603 pid_t pid = ::fork ( ); 602 pid_t pid = ::fork ( );
604 603
605 if ( pid == 0 ) { // child 604 if ( pid == 0 ) { // child
606 for ( int fd = 3; fd < 100; fd++ ) { 605 for ( int fd = 3; fd < 100; fd++ ) {
607 if ( fd != pfd [1] ) 606 if ( fd != pfd [1] )
608 ::close ( fd ); 607 ::close ( fd );
609 } 608 }
610 ::setpgid ( ::getpid ( ), ::getppid ( )); 609 ::setpgid ( ::getpid ( ), ::getppid ( ));
611 610
612 // Closing of fd[1] indicates that the execvp succeeded! 611 // Closing of fd[1] indicates that the execvp succeeded!
613 if ( pfd [1] >= 0 ) 612 if ( pfd [1] >= 0 )
614 ::fcntl ( pfd [1], F_SETFD, FD_CLOEXEC ); 613 ::fcntl ( pfd [1], F_SETFD, FD_CLOEXEC );
615 614
616 // Try bindir first, so that foo/bar works too 615 // Try bindir first, so that foo/bar works too
617 ::execv ( qpeDir ( ) + "/bin/" + args [0], (char * const *) args ); 616 ::execv ( qpeDir ( ) + "/bin/" + args [0], (char * const *) args );
618 ::execvp ( args [0], (char * const *) args ); 617 ::execvp ( args [0], (char * const *) args );
619 618
620 char resultByte = 1; 619 char resultByte = 1;
621 if ( pfd [1] >= 0 ) 620 if ( pfd [1] >= 0 )
622 ::write ( pfd [1], &resultByte, 1 ); 621 ::write ( pfd [1], &resultByte, 1 );
623 ::_exit ( -1 ); 622 ::_exit ( -1 );
624 } 623 }
625 else if ( pid > 0 ) { 624 else if ( pid > 0 ) {
626 success = true; 625 success = true;
627 626
628 if ( pfd [1] >= 0 ) 627 if ( pfd [1] >= 0 )
629 ::close ( pfd [1] ); 628 ::close ( pfd [1] );
630 if ( pfd [0] >= 0 ) { 629 if ( pfd [0] >= 0 ) {
631 while ( true ) { 630 while ( true ) {
632 char resultByte; 631 char resultByte;
633 int n = ::read ( pfd [0], &resultByte, 1 ); 632 int n = ::read ( pfd [0], &resultByte, 1 );
634 if ( n == 1 ) { 633 if ( n == 1 ) {
635 success = false; 634 success = false;
636 break; 635 break;
637 } 636 }
638 if (( n == -1 ) && (( errno == ECHILD ) || ( errno == EINTR ))) 637 if (( n == -1 ) && (( errno == ECHILD ) || ( errno == EINTR )))
639 continue; 638 continue;
640 639
641 break; // success 640 break; // success
642 } 641 }
643 ::close ( pfd [0] ); 642 ::close ( pfd [0] );
644 } 643 }
645 } 644 }
646 if ( success ) 645 if ( success )
647 StartingAppList::add( list[0] ); 646 StartingAppList::add( list[0] );
648 else 647 else
649 QMessageBox::warning( 0, "Error", "Could not start the application " + c, "Ok", 0, 0, 0, 1 ); 648 QMessageBox::warning( 0, "Error", "Could not start the application " + c, "Ok", 0, 0, 0, 1 );
650 } 649 }
651#endif //QT_NO_QWS_MULTIPROCESS 650#endif //QT_NO_QWS_MULTIPROCESS
652} 651}
653 652
654 653
655/*! 654/*!
656 Executes the application identfied by \a c, passing \a 655 Executes the application identfied by \a c, passing \a
657 document if it isn't null. 656 document if it isn't null.
658 657
659 Note that a better approach might be to send a QCop message to the 658 Note that a better approach might be to send a QCop message to the
660 application's QPE/Application/\e{appname} channel. 659 application's QPE/Application/\e{appname} channel.
661*/ 660*/
662void Global::execute( const QString &c, const QString& document ) 661void Global::execute( const QString &c, const QString& document )
663{ 662{
664 // ask the server to do the work 663 // ask the server to do the work
665#if !defined(QT_NO_COP) 664#if !defined(QT_NO_COP)
666 if ( document.isNull() ) { 665 if ( document.isNull() ) {
667 QCopEnvelope e( "QPE/System", "execute(QString)" ); 666 QCopEnvelope e( "QPE/System", "execute(QString)" );
668 e << c; 667 e << c;
669 } else { 668 } else {
670 QCopEnvelope e( "QPE/System", "execute(QString,QString)" ); 669 QCopEnvelope e( "QPE/System", "execute(QString,QString)" );
671 e << c << document; 670 e << c << document;
672 } 671 }
673#endif 672#endif
674 return; 673 return;
675} 674}
676 675
677/*! 676/*!
678 Returns the string \a s with the characters '\', '"', and '$' quoted 677 Returns the string \a s with the characters '\', '"', and '$' quoted
679 by a preceeding '\'. 678 by a preceeding '\'.
680 679
681 \sa stringQuote() 680 \sa stringQuote()
682*/ 681*/
683QString Global::shellQuote(const QString& s) 682QString Global::shellQuote(const QString& s)
684{ 683{
685 QString r="\""; 684 QString r="\"";
686 for (int i=0; i<(int)s.length(); i++) { 685 for (int i=0; i<(int)s.length(); i++) {
687 char c = s[i].latin1(); 686 char c = s[i].latin1();
688 switch (c) { 687 switch (c) {
689 case '\\': case '"': case '$': 688 case '\\': case '"': case '$':
690 r+="\\"; 689 r+="\\";
691 } 690 }
692 r += s[i]; 691 r += s[i];
693 } 692 }
694 r += "\""; 693 r += "\"";
695 return r; 694 return r;
696} 695}
697 696
698/*! 697/*!
699 Returns the string \a s with the characters '\' and '"' quoted by a 698 Returns the string \a s with the characters '\' and '"' quoted by a
700 preceeding '\'. 699 preceeding '\'.
701 700
702 \sa shellQuote() 701 \sa shellQuote()
703*/ 702*/
704QString Global::stringQuote(const QString& s) 703QString Global::stringQuote(const QString& s)
705{ 704{
706 QString r="\""; 705 QString r="\"";
707 for (int i=0; i<(int)s.length(); i++) { 706 for (int i=0; i<(int)s.length(); i++) {
708 char c = s[i].latin1(); 707 char c = s[i].latin1();
709 switch (c) { 708 switch (c) {
710 case '\\': case '"': 709 case '\\': case '"':
711 r+="\\"; 710 r+="\\";
712 } 711 }
713 r += s[i]; 712 r += s[i];
714 } 713 }
715 r += "\""; 714 r += "\"";
716 return r; 715 return r;
717} 716}
718 717
719/*! 718/*!
720 Finds all documents on the system's document directories which 719 Finds all documents on the system's document directories which
721 match the filter \a mimefilter, and appends the resulting DocLnk 720 match the filter \a mimefilter, and appends the resulting DocLnk
722 objects to \a folder. 721 objects to \a folder.
723*/ 722*/
724void Global::findDocuments(DocLnkSet* folder, const QString &mimefilter) 723void Global::findDocuments(DocLnkSet* folder, const QString &mimefilter)
725{ 724{
726 QString homedocs = QString(getenv("HOME")) + "/Documents"; 725 QString homedocs = QString(getenv("HOME")) + "/Documents";
727 DocLnkSet d(homedocs,mimefilter); 726 DocLnkSet d(homedocs,mimefilter);
728 folder->appendFrom(d); 727 folder->appendFrom(d);
729 /** let's do intellegint way of searching these files 728 /** let's do intellegint way of searching these files
730 * a) the user don't want to check mediums global 729 * a) the user don't want to check mediums global
731 * b) the user wants to check but use the global options for it 730 * b) the user wants to check but use the global options for it
732 * c) the user wants to check it but not this medium 731 * c) the user wants to check it but not this medium
733 * d) the user wants to check and this medium as well 732 * d) the user wants to check and this medium as well
734 * 733 *
735 * In all cases we need to apply a different mimefilter to 734 * In all cases we need to apply a different mimefilter to
736 * the medium. 735 * the medium.
737 * a) mimefilter.isEmpty() we need to apply the responding filter 736 * a) mimefilter.isEmpty() we need to apply the responding filter
738 * either the global or the one on the medium 737 * either the global or the one on the medium
739 * 738 *
740 * b) mimefilter is set to an application we need to find out if the 739 * b) mimefilter is set to an application we need to find out if the
741 * mimetypes are included in the mime mask of the medium 740 * mimetypes are included in the mime mask of the medium
742 */ 741 */
743 StorageInfo storage; 742 StorageInfo storage;
744 const QList<FileSystem> &fs = storage.fileSystems(); 743 const QList<FileSystem> &fs = storage.fileSystems();
745 QListIterator<FileSystem> it ( fs ); 744 QListIterator<FileSystem> it ( fs );
746 for ( ; it.current(); ++it ) { 745 for ( ; it.current(); ++it ) {
747 if ( (*it)->isRemovable() ) { // let's find out if we should search on it 746 if ( (*it)->isRemovable() ) { // let's find out if we should search on it
748 // this is a candidate look at the cf and see if we should search on it 747 // this is a candidate look at the cf and see if we should search on it
749 QString path = (*it)->path(); 748 QString path = (*it)->path();
750 Config conf((*it)->path() + "/.opiestorage.cf", Config::File ); 749 Config conf((*it)->path() + "/.opiestorage.cf", Config::File );
751 conf.setGroup("main"); 750 conf.setGroup("main");
752 if (!conf.readBoolEntry("check",true)) { 751 if (!conf.readBoolEntry("check",true)) {
753 continue; 752 continue;
754 } 753 }
755 conf.setGroup("subdirs"); 754 conf.setGroup("subdirs");
756 if (conf.readBoolEntry("wholemedia",true)) { 755 if (conf.readBoolEntry("wholemedia",true)) {
757 DocLnkSet ide( path,mimefilter); 756 DocLnkSet ide( path,mimefilter);
758 folder->appendFrom(ide); 757 folder->appendFrom(ide);
759 } else { 758 } else {
760 QStringList subDirs = conf.readListEntry("subdirs",':'); 759 QStringList subDirs = conf.readListEntry("subdirs",':');
761 if (subDirs.isEmpty()) { 760 if (subDirs.isEmpty()) {
762 subDirs.append("Documents"); 761 subDirs.append("Documents");
763 } 762 }