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