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