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