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