summaryrefslogtreecommitdiff
path: root/library/global.cpp
authorkergoth <kergoth>2002-02-04 22:14:18 (UTC)
committer kergoth <kergoth>2002-02-04 22:14:18 (UTC)
commitd46cb220a09b41312d86bb33573940d3dcba2588 (patch) (unidiff)
tree6aacb1589d5de2ca908d067f99ba64dc608a6fa5 /library/global.cpp
parent500e2f0cdbe82035516b7a1c576e08e0b2ad72b3 (diff)
downloadopie-d46cb220a09b41312d86bb33573940d3dcba2588.zip
opie-d46cb220a09b41312d86bb33573940d3dcba2588.tar.gz
opie-d46cb220a09b41312d86bb33573940d3dcba2588.tar.bz2
latest qtopia merge as of 20020204.
Diffstat (limited to 'library/global.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--library/global.cpp55
1 files changed, 49 insertions, 6 deletions
diff --git a/library/global.cpp b/library/global.cpp
index fd7579a..dd15eb7 100644
--- a/library/global.cpp
+++ b/library/global.cpp
@@ -1,644 +1,687 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#define QTOPIA_INTERNAL_LANGLIST
20#include <qpe/qpedebug.h> 21#include <qpe/qpedebug.h>
21#include <qpe/global.h> 22#include <qpe/global.h>
22#include <qpe/qdawg.h> 23#include <qpe/qdawg.h>
23#include <qpe/qpeapplication.h> 24#include <qpe/qpeapplication.h>
24#include <qpe/resource.h> 25#include <qpe/resource.h>
25#include <qpe/storage.h> 26#include <qpe/storage.h>
26#include <qpe/applnk.h> 27#include <qpe/applnk.h>
27#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 28#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
28#include "qpe/qcopenvelope_qws.h" 29#include "qpe/qcopenvelope_qws.h"
29#endif 30#endif
30 31
31#include <qfile.h> 32#include <qfile.h>
32#include <qlabel.h> 33#include <qlabel.h>
33#include <qtimer.h> 34#include <qtimer.h>
34#include <qmap.h> 35#include <qmap.h>
35#include <qdict.h> 36#include <qdict.h>
36#include <qdir.h> 37#include <qdir.h>
37#include <qmessagebox.h> 38#include <qmessagebox.h>
38#include <qregexp.h> 39#include <qregexp.h>
39 40
40#include <stdlib.h> 41#include <stdlib.h>
41#include <sys/stat.h> 42#include <sys/stat.h>
42#include <sys/wait.h> 43#include <sys/wait.h>
43#include <sys/types.h> 44#include <sys/types.h>
44#include <fcntl.h> 45#include <fcntl.h>
45#include <unistd.h> 46#include <unistd.h>
46 47
47#include <qwindowsystem_qws.h> // for qwsServer 48#include <qwindowsystem_qws.h> // for qwsServer
48#include <qdatetime.h> 49#include <qdatetime.h>
49 50
50//#include "quickexec_p.h" 51//#include "quickexec_p.h"
51 52
52class Emitter : public QObject { 53class Emitter : public QObject {
53 Q_OBJECT 54 Q_OBJECT
54public: 55public:
55 Emitter( QWidget* receiver, const QString& document ) 56 Emitter( QWidget* receiver, const QString& document )
56 { 57 {
57 connect(this, SIGNAL(setDocument(const QString&)), 58 connect(this, SIGNAL(setDocument(const QString&)),
58 receiver, SLOT(setDocument(const QString&))); 59 receiver, SLOT(setDocument(const QString&)));
59 emit setDocument(document); 60 emit setDocument(document);
60 disconnect(this, SIGNAL(setDocument(const QString&)), 61 disconnect(this, SIGNAL(setDocument(const QString&)),
61 receiver, SLOT(setDocument(const QString&))); 62 receiver, SLOT(setDocument(const QString&)));
62 } 63 }
63 64
64signals: 65signals:
65 void setDocument(const QString&); 66 void setDocument(const QString&);
66}; 67};
67 68
68 69
69class StartingAppList : public QObject { 70class StartingAppList : public QObject {
70 Q_OBJECT 71 Q_OBJECT
71public: 72public:
72 static void add( const QString& name ); 73 static void add( const QString& name );
73 static bool isStarting( const QString name ); 74 static bool isStarting( const QString name );
74private slots: 75private slots:
75 void handleNewChannel( const QString &); 76 void handleNewChannel( const QString &);
76private: 77private:
77 StartingAppList( QObject *parent=0, const char* name=0 ) ; 78 StartingAppList( QObject *parent=0, const char* name=0 ) ;
78 79
79 QDict<QTime> dict; 80 QDict<QTime> dict;
80 static StartingAppList *appl; 81 static StartingAppList *appl;
81}; 82};
82 83
83StartingAppList* StartingAppList::appl = 0; 84StartingAppList* StartingAppList::appl = 0;
84 85
85StartingAppList::StartingAppList( QObject *parent, const char* name ) 86StartingAppList::StartingAppList( QObject *parent, const char* name )
86 :QObject( parent, name ) 87 :QObject( parent, name )
87{ 88{
88#if QT_VERSION >= 232 && !defined(QT_NO_COP) 89#if QT_VERSION >= 232 && !defined(QT_NO_COP)
89 connect( qwsServer, SIGNAL( newChannel(const QString&)), 90 connect( qwsServer, SIGNAL( newChannel(const QString&)),
90 this, SLOT( handleNewChannel(const QString&)) ); 91 this, SLOT( handleNewChannel(const QString&)) );
91 dict.setAutoDelete( TRUE ); 92 dict.setAutoDelete( TRUE );
92#endif 93#endif
93} 94}
94 95
95void StartingAppList::add( const QString& name ) 96void StartingAppList::add( const QString& name )
96{ 97{
97#if QT_VERSION >= 232 && !defined(QT_NO_COP) 98#if QT_VERSION >= 232 && !defined(QT_NO_COP)
98 if ( !appl ) 99 if ( !appl )
99 appl = new StartingAppList; 100 appl = new StartingAppList;
100 QTime *t = new QTime; 101 QTime *t = new QTime;
101 t->start(); 102 t->start();
102 appl->dict.insert( "QPE/Application/" + name, t ); 103 appl->dict.insert( "QPE/Application/" + name, t );
103#endif 104#endif
104} 105}
105 106
106bool StartingAppList::isStarting( const QString name ) 107bool StartingAppList::isStarting( const QString name )
107{ 108{
108#if QT_VERSION >= 232 && !defined(QT_NO_COP) 109#if QT_VERSION >= 232 && !defined(QT_NO_COP)
109 if ( appl ) { 110 if ( appl ) {
110 QTime *t = appl->dict.find( "QPE/Application/" + name ); 111 QTime *t = appl->dict.find( "QPE/Application/" + name );
111 if ( !t ) 112 if ( !t )
112 return FALSE; 113 return FALSE;
113 if ( t->elapsed() > 10000 ) { 114 if ( t->elapsed() > 10000 ) {
114 // timeout in case of crash or something 115 // timeout in case of crash or something
115 appl->dict.remove( "QPE/Application/" + name ); 116 appl->dict.remove( "QPE/Application/" + name );
116 return FALSE; 117 return FALSE;
117 } 118 }
118 return TRUE; 119 return TRUE;
119 } 120 }
120#endif 121#endif
121 return FALSE; 122 return FALSE;
122} 123}
123 124
124void StartingAppList::handleNewChannel( const QString & name ) 125void StartingAppList::handleNewChannel( const QString & name )
125{ 126{
126#if QT_VERSION >= 232 && !defined(QT_NO_COP) 127#if QT_VERSION >= 232 && !defined(QT_NO_COP)
127 dict.remove( name ); 128 dict.remove( name );
128#endif 129#endif
129} 130}
130 131
131static bool docDirCreated = FALSE; 132static bool docDirCreated = FALSE;
132static QDawg* fixed_dawg = 0; 133static QDawg* fixed_dawg = 0;
133static QDict<QDawg> *named_dawg = 0; 134static QDict<QDawg> *named_dawg = 0;
134 135
135static QString qpeDir() 136static QString qpeDir()
136{ 137{
137 QString dir = getenv("OPIEDIR"); 138 QString dir = getenv("OPIEDIR");
138 if ( dir.isEmpty() ) dir = ".."; 139 if ( dir.isEmpty() ) dir = "..";
139 return dir; 140 return dir;
140} 141}
141 142
142static QString dictDir() 143static QString dictDir()
143{ 144{
144 return qpeDir() + "/etc/dict"; 145 return qpeDir() + "/etc/dict";
145} 146}
146 147
147/*! 148/*!
148 \class Global global.h 149 \class Global global.h
149 \brief The Global class collects application-wide global functions. 150 \brief The Global class collects application-wide global functions.
150*/ 151*/
151 152
152/*! 153/*!
153 \internal 154 \internal
154*/ 155*/
155Global::Global() 156Global::Global()
156{ 157{
157} 158}
158 159
159/*! 160/*!
160 Returns the unchangeable QDawg that contains general 161 Returns the unchangeable QDawg that contains general
161 words for the current locale. 162 words for the current locale.
162 163
163 \sa addedDawg() 164 \sa addedDawg()
164*/ 165*/
165const QDawg& Global::fixedDawg() 166const QDawg& Global::fixedDawg()
166{ 167{
167 if ( !fixed_dawg ) { 168 if ( !fixed_dawg ) {
168 if ( !docDirCreated ) 169 if ( !docDirCreated )
169 createDocDir(); 170 createDocDir();
170 171
171 fixed_dawg = new QDawg; 172 fixed_dawg = new QDawg;
172 QString dawgfilename = dictDir() + "/dawg"; 173 QString dawgfilename = dictDir() + "/dawg";
173 QString lang = getenv( "LANG" ); 174 QString words_lang;
174 QString dawgfilename_lang = dawgfilename + "." + lang; 175 QStringList langs = Global::languageList();
175 QString words_lang = dictDir() + "/words." + lang; 176 for (QStringList::ConstIterator it = langs.begin(); it!=langs.end(); ++it) {
176 if ( QFile::exists(dawgfilename_lang) || 177 QString lang = *it;
177 QFile::exists(words_lang) ) 178 words_lang = dictDir() + "/words." + lang;
178 dawgfilename = dawgfilename_lang; 179 QString dawgfilename_lang = dawgfilename + "." + lang;
180 if ( QFile::exists(dawgfilename_lang) ||
181 QFile::exists(words_lang) ) {
182 dawgfilename = dawgfilename_lang;
183 break;
184 }
185 }
179 QFile dawgfile(dawgfilename); 186 QFile dawgfile(dawgfilename);
180 187
181 if ( !dawgfile.exists() ) { 188 if ( !dawgfile.exists() ) {
182 QString fn = dictDir() + "/words"; 189 QString fn = dictDir() + "/words";
183 if ( QFile::exists(words_lang) ) 190 if ( QFile::exists(words_lang) )
184 fn = words_lang; 191 fn = words_lang;
185 QFile in(fn); 192 QFile in(fn);
186 if ( in.open(IO_ReadOnly) ) { 193 if ( in.open(IO_ReadOnly) ) {
187 fixed_dawg->createFromWords(&in); 194 fixed_dawg->createFromWords(&in);
188 dawgfile.open(IO_WriteOnly); 195 dawgfile.open(IO_WriteOnly);
189 fixed_dawg->write(&dawgfile); 196 fixed_dawg->write(&dawgfile);
190 dawgfile.close(); 197 dawgfile.close();
191 } 198 }
192 } else { 199 } else {
193 fixed_dawg->readFile(dawgfilename); 200 fixed_dawg->readFile(dawgfilename);
194 } 201 }
195 } 202 }
196 203
197 return *fixed_dawg; 204 return *fixed_dawg;
198} 205}
199 206
200/*! 207/*!
201 Returns the changeable QDawg that contains general 208 Returns the changeable QDawg that contains general
202 words for the current locale. 209 words for the current locale.
203 210
204 \sa fixedDawg() 211 \sa fixedDawg()
205*/ 212*/
206const QDawg& Global::addedDawg() 213const QDawg& Global::addedDawg()
207{ 214{
208 return dawg("local"); 215 return dawg("local");
209} 216}
210 217
211/*! 218/*!
212 Returns the QDawg with the given \a name. 219 Returns the QDawg with the given \a name.
213 This is an application-specific word list. 220 This is an application-specific word list.
214 221
215 \a name should not contain "/". 222 \a name should not contain "/".
216*/ 223*/
217const QDawg& Global::dawg(const QString& name) 224const QDawg& Global::dawg(const QString& name)
218{ 225{
219 createDocDir(); 226 createDocDir();
220 if ( !named_dawg ) 227 if ( !named_dawg )
221 named_dawg = new QDict<QDawg>; 228 named_dawg = new QDict<QDawg>;
222 QDawg* r = named_dawg->find(name); 229 QDawg* r = named_dawg->find(name);
223 if ( !r ) { 230 if ( !r ) {
224 r = new QDawg; 231 r = new QDawg;
225 named_dawg->insert(name,r); 232 named_dawg->insert(name,r);
226 QString dawgfilename = dictDir() + "/" + name + ".dawg"; 233 QString dawgfilename = dictDir() + "/" + name + ".dawg";
227 QFile dawgfile(dawgfilename); 234 QFile dawgfile(dawgfilename);
228 if ( dawgfile.open(IO_ReadOnly) ) 235 if ( dawgfile.open(IO_ReadOnly) )
229 r->readFile(dawgfilename); 236 r->readFile(dawgfilename);
230 } 237 }
231 return *r; 238 return *r;
232} 239}
233 240
234/*! 241/*!
235 Adds \a wordlist to the addedDawg(). 242 Adds \a wordlist to the addedDawg().
236*/ 243*/
237void Global::addWords(const QStringList& wordlist) 244void Global::addWords(const QStringList& wordlist)
238{ 245{
239 addWords("local",wordlist); 246 addWords("local",wordlist);
240} 247}
241 248
242/*! 249/*!
243 Adds \a wordlist to the dawg() named \a dictname. 250 Adds \a wordlist to the dawg() named \a dictname.
244*/ 251*/
245void Global::addWords(const QString& dictname, const QStringList& wordlist) 252void Global::addWords(const QString& dictname, const QStringList& wordlist)
246{ 253{
247 QDawg& d = (QDawg&)dawg(dictname); 254 QDawg& d = (QDawg&)dawg(dictname);
248 QStringList all = d.allWords() + wordlist; 255 QStringList all = d.allWords() + wordlist;
249 d.createFromWords(all); 256 d.createFromWords(all);
250 257
251 QString dawgfilename = dictDir() + "/" + dictname + ".dawg"; 258 QString dawgfilename = dictDir() + "/" + dictname + ".dawg";
252 QFile dawgfile(dawgfilename); 259 QFile dawgfile(dawgfilename);
253 if ( dawgfile.open(IO_WriteOnly) ) { 260 if ( dawgfile.open(IO_WriteOnly) ) {
254 d.write(&dawgfile); 261 d.write(&dawgfile);
255 dawgfile.close(); 262 dawgfile.close();
256 } 263 }
257 264
258 // #### Re-read the dawg here if we use mmap(). 265 // #### Re-read the dawg here if we use mmap().
259 266
260 // #### Signal other processes to re-read. 267 // #### Signal other processes to re-read.
261} 268}
262 269
263 270
264/*! 271/*!
265 Returns a full path for the application named \a appname, with the 272 Returns a full path for the application named \a appname, with the
266 given \a filename or QString::null if there was a problem creating 273 given \a filename or QString::null if there was a problem creating
267 the directory tree for \a appname. 274 the directory tree for \a appname.
268 If \a filename contains "/", it is the caller's responsibility to 275 If \a filename contains "/", it is the caller's responsibility to
269 ensure those directories exist. 276 ensure those directories exist.
270*/ 277*/
271QString Global::applicationFileName(const QString& appname, const QString& filename) 278QString Global::applicationFileName(const QString& appname, const QString& filename)
272{ 279{
273 QDir d; 280 QDir d;
274 QString r = getenv("HOME"); 281 QString r = getenv("HOME");
275 r += "/Applications/"; 282 r += "/Applications/";
276 if ( !QFile::exists( r ) ) 283 if ( !QFile::exists( r ) )
277 if ( d.mkdir(r) == false ) 284 if ( d.mkdir(r) == false )
278 return QString::null; 285 return QString::null;
279 r += appname; 286 r += appname;
280 if ( !QFile::exists( r ) ) 287 if ( !QFile::exists( r ) )
281 if ( d.mkdir(r) == false ) 288 if ( d.mkdir(r) == false )
282 return QString::null; 289 return QString::null;
283 r += "/"; r += filename; 290 r += "/"; r += filename;
284 return r; 291 return r;
285} 292}
286 293
287/*! 294/*!
288 \internal 295 \internal
289*/ 296*/
290void Global::createDocDir() 297void Global::createDocDir()
291{ 298{
292 if ( !docDirCreated ) { 299 if ( !docDirCreated ) {
293 docDirCreated = TRUE; 300 docDirCreated = TRUE;
294 mkdir( QPEApplication::documentDir().latin1(), 0755 ); 301 mkdir( QPEApplication::documentDir().latin1(), 0755 );
295 } 302 }
296} 303}
297 304
298 305
299/*! 306/*!
300 Displays a status \a message to the user. This generally appears 307 Displays a status \a message to the user. This generally appears
301 in the taskbar for some amount of time, then disappears. 308 in the taskbar for some amount of time, then disappears.
302*/ 309*/
303void Global::statusMessage(const QString& message) 310void Global::statusMessage(const QString& message)
304{ 311{
305#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 312#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
306 QCopEnvelope e( "QPE/TaskBar", "message(QString)" ); 313 QCopEnvelope e( "QPE/TaskBar", "message(QString)" );
307 e << message; 314 e << message;
308#endif 315#endif
309} 316}
310 317
311/*! 318/*!
312 \internal 319 \internal
313*/ 320*/
314void Global::applyStyle() 321void Global::applyStyle()
315{ 322{
316#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 323#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
317 QCopChannel::send( "QPE/System", "applyStyle()" ); 324 QCopChannel::send( "QPE/System", "applyStyle()" );
318#else 325#else
319 ((QPEApplication *)qApp)->applyStyle(); // apply without needing QCop for floppy version 326 ((QPEApplication *)qApp)->applyStyle(); // apply without needing QCop for floppy version
320#endif 327#endif
321} 328}
322 329
323/*! 330/*!
324 \internal 331 \internal
325*/ 332*/
326QWidget *Global::shutdown( bool ) 333QWidget *Global::shutdown( bool )
327{ 334{
328#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 335#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
329 QCopChannel::send( "QPE/System", "shutdown()" ); 336 QCopChannel::send( "QPE/System", "shutdown()" );
330#endif 337#endif
331 return 0; 338 return 0;
332} 339}
333 340
334/*! 341/*!
335 \internal 342 \internal
336*/ 343*/
337QWidget *Global::restart( bool ) 344QWidget *Global::restart( bool )
338{ 345{
339#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 346#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
340 QCopChannel::send( "QPE/System", "restart()" ); 347 QCopChannel::send( "QPE/System", "restart()" );
341#endif 348#endif
342 return 0; 349 return 0;
343} 350}
344 351
345/*! 352/*!
346 Explicitly show the current input method. 353 Explicitly show the current input method.
347*/ 354*/
348void Global::showInputMethod() 355void Global::showInputMethod()
349{ 356{
350#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 357#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
351 QCopChannel::send( "QPE/TaskBar", "showInputMethod()" ); 358 QCopChannel::send( "QPE/TaskBar", "showInputMethod()" );
352#endif 359#endif
353} 360}
354 361
355/*! 362/*!
356 Explicitly hide the current input method. 363 Explicitly hide the current input method.
357*/ 364*/
358void Global::hideInputMethod() 365void Global::hideInputMethod()
359{ 366{
360#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 367#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
361 QCopChannel::send( "QPE/TaskBar", "hideInputMethod()" ); 368 QCopChannel::send( "QPE/TaskBar", "hideInputMethod()" );
362#endif 369#endif
363} 370}
364 371
365 372
366/*! 373/*!
367 \internal 374 \internal
368*/ 375*/
369bool Global::isBuiltinCommand( const QString &name ) 376bool Global::isBuiltinCommand( const QString &name )
370{ 377{
371 if(!builtin) 378 if(!builtin)
372 return FALSE; // yes, it can happen 379 return FALSE; // yes, it can happen
373 for (int i = 0; builtin[i].file; i++) { 380 for (int i = 0; builtin[i].file; i++) {
374 if ( builtin[i].file == name ) { 381 if ( builtin[i].file == name ) {
375 return TRUE; 382 return TRUE;
376 } 383 }
377 } 384 }
378 return FALSE; 385 return FALSE;
379} 386}
380 387
381Global::Command* Global::builtin=0; 388Global::Command* Global::builtin=0;
382QGuardedPtr<QWidget> *Global::running=0; 389QGuardedPtr<QWidget> *Global::running=0;
383 390
384/*! 391/*!
385 \class Global::Command 392 \class Global::Command
386 \brief The Global::Command class is internal. 393 \brief The Global::Command class is internal.
387 \internal 394 \internal
388*/ 395*/
389 396
390/*! 397/*!
391 \internal 398 \internal
392*/ 399*/
393void Global::setBuiltinCommands( Command* list ) 400void Global::setBuiltinCommands( Command* list )
394{ 401{
395 if ( running ) 402 if ( running )
396 delete [] running; 403 delete [] running;
397 404
398 builtin = list; 405 builtin = list;
399 int count = 0; 406 int count = 0;
400 if (!builtin) 407 if (!builtin)
401 return; 408 return;
402 while ( builtin[count].file ) 409 while ( builtin[count].file )
403 count++; 410 count++;
404 411
405 running = new QGuardedPtr<QWidget> [ count ]; 412 running = new QGuardedPtr<QWidget> [ count ];
406} 413}
407 414
408/*! 415/*!
409 \internal 416 \internal
410*/ 417*/
411void Global::setDocument( QWidget* receiver, const QString& document ) 418void Global::setDocument( QWidget* receiver, const QString& document )
412{ 419{
413 Emitter emitter(receiver,document); 420 Emitter emitter(receiver,document);
414} 421}
415 422
416/*! 423/*!
417 \internal 424 \internal
418*/ 425*/
419bool Global::terminateBuiltin( const QString& n ) 426bool Global::terminateBuiltin( const QString& n )
420{ 427{
421 if (!builtin) 428 if (!builtin)
422 return FALSE; 429 return FALSE;
423 for (int i = 0; builtin[i].file; i++) { 430 for (int i = 0; builtin[i].file; i++) {
424 if ( builtin[i].file == n ) { 431 if ( builtin[i].file == n ) {
425 delete running[i]; 432 delete running[i];
426 return TRUE; 433 return TRUE;
427 } 434 }
428 } 435 }
429 return FALSE; 436 return FALSE;
430} 437}
431 438
432/*! 439/*!
433 \internal 440 \internal
434*/ 441*/
435void Global::terminate( const AppLnk* app ) 442void Global::terminate( const AppLnk* app )
436{ 443{
437 //if ( terminateBuiltin(app->exec()) ) return; // maybe? haven't tried this 444 //if ( terminateBuiltin(app->exec()) ) return; // maybe? haven't tried this
438 445
439 QCString channel = "QPE/Application/" + app->exec().utf8(); 446 QCString channel = "QPE/Application/" + app->exec().utf8();
440 if ( QCopChannel::isRegistered(channel) ) { 447 if ( QCopChannel::isRegistered(channel) ) {
441 QCopEnvelope e(channel, "quit()"); 448 QCopEnvelope e(channel, "quit()");
442 } 449 }
443} 450}
444 451
445/*! 452/*!
446 Low-level function to run command \a c. Not recommended. 453 Low-level function to run command \a c. Not recommended.
447*/ 454*/
448void Global::invoke(const QString &c) 455void Global::invoke(const QString &c)
449{ 456{
450 // Convert the command line in to a list of arguments 457 // Convert the command line in to a list of arguments
451 QStringList list = QStringList::split(QRegExp(" *"),c); 458 QStringList list = QStringList::split(QRegExp(" *"),c);
452 459
453#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 460#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
454 QString ap=list[0]; 461 QString ap=list[0];
455 // see if the application is already running 462 // see if the application is already running
456 // XXX should lock file /tmp/qcop-msg-ap 463 // XXX should lock file /tmp/qcop-msg-ap
457 if ( QCopChannel::isRegistered( ("QPE/Application/" + ap).latin1() ) ) { 464 if ( QCopChannel::isRegistered( ("QPE/Application/" + ap).latin1() ) ) {
458 QCopEnvelope e("QPE/System", "notBusy(QString)" ); 465 QCopEnvelope e("QPE/System", "notBusy(QString)" );
459 e << ap; 466 e << ap;
460 return; 467 return;
461 } 468 }
462 // XXX should unlock file /tmp/qcop-msg-ap 469 // XXX should unlock file /tmp/qcop-msg-ap
463 //see if it is being started 470 //see if it is being started
464 if ( StartingAppList::isStarting( ap ) ) { 471 if ( StartingAppList::isStarting( ap ) ) {
465 QCopEnvelope e("QPE/System", "notBusy(QString)" ); 472 QCopEnvelope e("QPE/System", "notBusy(QString)" );
466 e << ap; 473 e << ap;
467 return; 474 return;
468 } 475 }
469 476
470#endif 477#endif
471 478
472#ifdef QT_NO_QWS_MULTIPROCESS 479#ifdef QT_NO_QWS_MULTIPROCESS
473 QMessageBox::warning( 0, "Error", "Could not find the application " + c, "Ok", 0, 0, 0, 1 ); 480 QMessageBox::warning( 0, "Error", "Could not find the application " + c, "Ok", 0, 0, 0, 1 );
474#else 481#else
475 482
476 QStrList slist; 483 QStrList slist;
477 unsigned int j; 484 unsigned int j;
478 for ( j = 0; j < list.count(); j++ ) 485 for ( j = 0; j < list.count(); j++ )
479 slist.append( list[j].utf8() ); 486 slist.append( list[j].utf8() );
480 487
481 const char **args = new (const char *)[slist.count() + 1]; 488 const char **args = new (const char *)[slist.count() + 1];
482 for ( j = 0; j < slist.count(); j++ ) 489 for ( j = 0; j < slist.count(); j++ )
483 args[j] = slist.at(j); 490 args[j] = slist.at(j);
484 args[j] = NULL; 491 args[j] = NULL;
485 492
486#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 493#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
487 // an attempt to show a wait... 494 // an attempt to show a wait...
488 // more logic should be used, but this will be fine for the moment... 495 // more logic should be used, but this will be fine for the moment...
489 QCopEnvelope ( "QPE/System", "busy()" ); 496 QCopEnvelope ( "QPE/System", "busy()" );
490#endif 497#endif
491 498
492#ifdef HAVE_QUICKEXEC 499#ifdef HAVE_QUICKEXEC
493 QString libexe = qpeDir()+"/binlib/lib"+args[0] + ".so"; 500 QString libexe = qpeDir()+"/binlib/lib"+args[0] + ".so";
494 qDebug("libfile = %s", libexe.latin1() ); 501 qDebug("libfile = %s", libexe.latin1() );
495 if ( QFile::exists( libexe ) ) { 502 if ( QFile::exists( libexe ) ) {
496 qDebug("calling quickexec %s", libexe.latin1() ); 503 qDebug("calling quickexec %s", libexe.latin1() );
497 quickexecv( libexe.utf8().data(), (const char **)args ); 504 quickexecv( libexe.utf8().data(), (const char **)args );
498 } else 505 } else
499#endif 506#endif
500 { 507 {
501 if ( !::vfork() ) { 508 if ( !::vfork() ) {
502 for ( int fd = 3; fd < 100; fd++ ) 509 for ( int fd = 3; fd < 100; fd++ )
503 ::close( fd ); 510 ::close( fd );
504 ::setpgid( ::getpid(), ::getppid() ); 511 ::setpgid( ::getpid(), ::getppid() );
505 // Try bindir first, so that foo/bar works too 512 // Try bindir first, so that foo/bar works too
506 ::execv( qpeDir()+"/bin/"+args[0], (char * const *)args ); 513 ::execv( qpeDir()+"/bin/"+args[0], (char * const *)args );
507 ::execvp( args[0], (char * const *)args ); 514 ::execvp( args[0], (char * const *)args );
508 _exit( -1 ); 515 _exit( -1 );
509 } 516 }
510 } 517 }
511 StartingAppList::add( list[0] ); 518 StartingAppList::add( list[0] );
512#endif //QT_NO_QWS_MULTIPROCESS 519#endif //QT_NO_QWS_MULTIPROCESS
513} 520}
514 521
515/*! 522/*!
516 Executes application identfied by \a c, passing \a document. 523 Executes application identfied by \a c, passing \a document.
517 524
518 Note that you might be better off sending a QCop message to 525 Note that you might be better off sending a QCop message to
519 the application's QPE/Application/<i>appname</i> channel. 526 the application's QPE/Application/<i>appname</i> channel.
520*/ 527*/
521void Global::execute( const QString &c, const QString& document ) 528void Global::execute( const QString &c, const QString& document )
522{ 529{
523 if ( qApp->type() != QApplication::GuiServer ) { 530 if ( qApp->type() != QApplication::GuiServer ) {
524 // ask the server to do the work 531 // ask the server to do the work
525#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 532#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
526 if ( document.isNull() ) { 533 if ( document.isNull() ) {
527 QCopEnvelope e( "QPE/System", "execute(QString)" ); 534 QCopEnvelope e( "QPE/System", "execute(QString)" );
528 e << c; 535 e << c;
529 } else { 536 } else {
530 QCopEnvelope e( "QPE/System", "execute(QString,QString)" ); 537 QCopEnvelope e( "QPE/System", "execute(QString,QString)" );
531 e << c << document; 538 e << c << document;
532 } 539 }
533#endif 540#endif
534 return; 541 return;
535 } 542 }
536 543
537 // Attempt to execute the app using a builtin class for the app first 544 // Attempt to execute the app using a builtin class for the app first
538 // else try and find it in the bin directory 545 // else try and find it in the bin directory
539 if (builtin) { 546 if (builtin) {
540 for (int i = 0; builtin[i].file; i++) { 547 for (int i = 0; builtin[i].file; i++) {
541 if ( builtin[i].file == c ) { 548 if ( builtin[i].file == c ) {
542 if ( running[i] ) { 549 if ( running[i] ) {
543 if ( !document.isNull() && builtin[i].documentary ) 550 if ( !document.isNull() && builtin[i].documentary )
544 setDocument(running[i], document); 551 setDocument(running[i], document);
545 running[i]->raise(); 552 running[i]->raise();
546 running[i]->show(); 553 running[i]->show();
547 running[i]->setActiveWindow(); 554 running[i]->setActiveWindow();
548 } else { 555 } else {
549 running[i] = builtin[i].func( builtin[i].maximized ); 556 running[i] = builtin[i].func( builtin[i].maximized );
550 } 557 }
551 QCopEnvelope e("QPE/System", "notBusy(QString)" ); 558 QCopEnvelope e("QPE/System", "notBusy(QString)" );
552 e << c; // that was quick ;-) 559 e << c; // that was quick ;-)
553 return; 560 return;
554 } 561 }
555 } 562 }
556 } 563 }
557 564
558 //Global::invoke(c, document); 565 //Global::invoke(c, document);
559 566
560 // Convert the command line in to a list of arguments 567 // Convert the command line in to a list of arguments
561 QStringList list = QStringList::split(QRegExp(" *"),c); 568 QStringList list = QStringList::split(QRegExp(" *"),c);
562 569
563#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 570#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
564 QString ap=list[0]; 571 QString ap=list[0];
565 572
566 qDebug("executing %s", ap.latin1() ); 573 qDebug("executing %s", ap.latin1() );
567 if ( ap == "suspend" ) { 574 if ( ap == "suspend" ) {
568 QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); 575 QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE );
569 return; 576 return;
570 } 577 }
571 578
572 /* if need be, sending a qcop message will result in an invoke, see 579 /* if need be, sending a qcop message will result in an invoke, see
573 preceeding function */ 580 preceeding function */
574 { QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "raise()" ); } 581 { QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "raise()" ); }
575 if ( !document.isEmpty() ) { 582 if ( !document.isEmpty() ) {
576 QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "setDocument(QString)" ); 583 QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "setDocument(QString)" );
577 env << document; 584 env << document;
578 } 585 }
579#endif 586#endif
580} 587}
581 588
582/*! 589/*!
583 Returns the string \a s with the characters backslash, ", and $ 590 Returns the string \a s with the characters backslash, ", and $
584 quoted by a preceeding backslash. 591 quoted by a preceeding backslash.
585*/ 592*/
586QString Global::shellQuote(const QString& s) 593QString Global::shellQuote(const QString& s)
587{ 594{
588 QString r="\""; 595 QString r="\"";
589 for (int i=0; i<(int)s.length(); i++) { 596 for (int i=0; i<(int)s.length(); i++) {
590 char c = s[i].latin1(); 597 char c = s[i].latin1();
591 switch (c) { 598 switch (c) {
592 case '\\': case '"': case '$': 599 case '\\': case '"': case '$':
593 r+="\\"; 600 r+="\\";
594 } 601 }
595 r += s[i]; 602 r += s[i];
596 } 603 }
597 r += "\""; 604 r += "\"";
598 return r; 605 return r;
599} 606}
600 607
601/*! 608/*!
602 Returns the string \a s with the characters backslash and " 609 Returns the string \a s with the characters backslash and "
603 quoted by a preceeding backslash. 610 quoted by a preceeding backslash.
604*/ 611*/
605QString Global::stringQuote(const QString& s) 612QString Global::stringQuote(const QString& s)
606{ 613{
607 QString r="\""; 614 QString r="\"";
608 for (int i=0; i<(int)s.length(); i++) { 615 for (int i=0; i<(int)s.length(); i++) {
609 char c = s[i].latin1(); 616 char c = s[i].latin1();
610 switch (c) { 617 switch (c) {
611 case '\\': case '"': 618 case '\\': case '"':
612 r+="\\"; 619 r+="\\";
613 } 620 }
614 r += s[i]; 621 r += s[i];
615 } 622 }
616 r += "\""; 623 r += "\"";
617 return r; 624 return r;
618} 625}
619 626
620/*! 627/*!
621 Finds all documents on the system's document directories which 628 Finds all documents on the system's document directories which
622 match the filter \a mimefilter, and appends the resulting DocLnk 629 match the filter \a mimefilter, and appends the resulting DocLnk
623 objects to \a folder. 630 objects to \a folder.
624*/ 631*/
625void Global::findDocuments(DocLnkSet* folder, const QString &mimefilter) 632void Global::findDocuments(DocLnkSet* folder, const QString &mimefilter)
626{ 633{
627 QString homedocs = QString(getenv("HOME")) + "/Documents"; 634 QString homedocs = QString(getenv("HOME")) + "/Documents";
628 DocLnkSet d(homedocs,mimefilter); 635 DocLnkSet d(homedocs,mimefilter);
629 folder->appendFrom(d); 636 folder->appendFrom(d);
630 StorageInfo storage; 637 StorageInfo storage;
631 const QList<FileSystem> &fs = storage.fileSystems(); 638 const QList<FileSystem> &fs = storage.fileSystems();
632 QListIterator<FileSystem> it ( fs ); 639 QListIterator<FileSystem> it ( fs );
633 for ( ; it.current(); ++it ) { 640 for ( ; it.current(); ++it ) {
634 if ( (*it)->isRemovable() ) { 641 if ( (*it)->isRemovable() ) {
635 QString path = (*it)->path(); 642 QString path = (*it)->path();
636 DocLnkSet ide( path, mimefilter ); 643 DocLnkSet ide( path, mimefilter );
637 folder->appendFrom(ide); 644 folder->appendFrom(ide);
638 } 645 }
639 } 646 }
640} 647}
641 648
649QStringList Global::languageList()
650{
651 QString lang = getenv("LANG");
652 QStringList langs;
653 langs.append(lang);
654 int i = lang.find(".");
655 if ( i > 0 )
656 lang = lang.left( i );
657 i = lang.find( "_" );
658 if ( i > 0 )
659 langs.append(lang.left(i));
660 return langs;
661}
662
663QStringList Global::helpPath()
664{
665 QStringList path;
666 QStringList langs = Global::languageList();
667 for (QStringList::ConstIterator it = langs.fromLast(); it!=langs.end(); --it) {
668 QString lang = *it;
669 if ( !lang.isEmpty() )
670 path += QPEApplication::qpeDir() + "/help/" + lang + "/html";
671 }
672 path += QPEApplication::qpeDir() + "/pics";
673 path += QPEApplication::qpeDir() + "/help/en/html";
674 path += QPEApplication::qpeDir() + "/docs";
675 QString dir = QDir::current().canonicalPath();
676 if ( dir == "/" )
677 dir += "/docs";
678 else {
679 path += dir + "/../pics";
680 dir += "/../docs";
681 path += dir;
682 }
683 return path;
684}
642 685
643 686
644#include "global.moc" 687#include "global.moc"