-rw-r--r-- | library/global.cpp | 141 |
1 files changed, 112 insertions, 29 deletions
diff --git a/library/global.cpp b/library/global.cpp index ab27b3f..7438891 100644 --- a/library/global.cpp +++ b/library/global.cpp | |||
@@ -1,8 +1,8 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of 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 |
@@ -44,9 +44,11 @@ | |||
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 | #ifdef QWS | ||
48 | #include <qwindowsystem_qws.h> // for qwsServer | 49 | #include <qwindowsystem_qws.h> // for qwsServer |
50 | #endif | ||
49 | #include <qdatetime.h> | 51 | #include <qdatetime.h> |
50 | 52 | ||
51 | #include <qfile.h> | 53 | #include <qfile.h> |
52 | 54 | ||
@@ -107,13 +109,15 @@ StartingAppList* StartingAppList::appl = 0; | |||
107 | 109 | ||
108 | StartingAppList::StartingAppList( QObject *parent, const char* name ) | 110 | StartingAppList::StartingAppList( QObject *parent, const char* name ) |
109 | :QObject( parent, name ) | 111 | :QObject( parent, name ) |
110 | { | 112 | { |
113 | #ifdef QWS | ||
111 | #if QT_VERSION >= 232 && !defined(QT_NO_COP) | 114 | #if QT_VERSION >= 232 && !defined(QT_NO_COP) |
112 | connect( qwsServer, SIGNAL( newChannel(const QString&)), | 115 | connect( qwsServer, SIGNAL( newChannel(const QString&)), |
113 | this, SLOT( handleNewChannel(const QString&)) ); | 116 | this, SLOT( handleNewChannel(const QString&)) ); |
114 | dict.setAutoDelete( TRUE ); | 117 | dict.setAutoDelete( TRUE ); |
115 | #endif | 118 | #endif |
119 | #endif | ||
116 | } | 120 | } |
117 | 121 | ||
118 | void StartingAppList::add( const QString& name ) | 122 | void StartingAppList::add( const QString& name ) |
119 | { | 123 | { |
@@ -168,9 +172,57 @@ static QString dictDir() | |||
168 | } | 172 | } |
169 | 173 | ||
170 | /*! | 174 | /*! |
171 | \class Global global.h | 175 | \class Global global.h |
172 | \brief The Global class collects application-wide global functions. | 176 | \brief The Global class provides application-wide global functions. |
177 | |||
178 | The Global functions are grouped as follows: | ||
179 | \tableofcontents | ||
180 | |||
181 | \section1 User Interface | ||
182 | |||
183 | The statusMessage() function provides short-duration messages to the | ||
184 | user. The showInputMethod() function shows the current input method, | ||
185 | and hideInputMethod() hides the input method. | ||
186 | |||
187 | \section1 Document related | ||
188 | |||
189 | The findDocuments() function creates a set of \link doclnk.html | ||
190 | DocLnk\endlink objects in a particular folder. | ||
191 | |||
192 | \section1 Filesystem related | ||
193 | |||
194 | Global provides an applicationFileName() function that returns the | ||
195 | full path of an application-specific file. | ||
196 | |||
197 | The execute() function runs an application. | ||
198 | |||
199 | \section1 Word list related | ||
200 | |||
201 | 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 | ||
203 | (implemented by the QDawg class). This list is used, for example, by | ||
204 | the pickboard input method. | ||
205 | |||
206 | The global QDawg is returned by fixedDawg(); this cannot be updated. | ||
207 | An updatable copy of the global QDawg is returned by addedDawg(). | ||
208 | 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 | ||
210 | updateable copy of the global QDawg or to named application | ||
211 | \l{QDawg}s. | ||
212 | |||
213 | \section1 Quoting | ||
214 | |||
215 | The shellQuote() function quotes a string suitable for passing to a | ||
216 | shell. The stringQuote() function backslash escapes '\' and '"' | ||
217 | characters. | ||
218 | |||
219 | \section1 Hardware | ||
220 | |||
221 | The writeHWClock() function sets the hardware clock to the system | ||
222 | clock's date and time. | ||
223 | |||
224 | \ingroup qtopiaemb | ||
173 | */ | 225 | */ |
174 | 226 | ||
175 | /*! | 227 | /*! |
176 | \internal | 228 | \internal |
@@ -251,34 +303,44 @@ const QDawg& Global::dawg(const QString& name) | |||
251 | QDawg* r = named_dawg->find(name); | 303 | QDawg* r = named_dawg->find(name); |
252 | if ( !r ) { | 304 | if ( !r ) { |
253 | r = new QDawg; | 305 | r = new QDawg; |
254 | named_dawg->insert(name,r); | 306 | named_dawg->insert(name,r); |
255 | QString dawgfilename = dictDir() + "/" + name + ".dawg"; | 307 | QString dawgfilename = applicationFileName("Dictionary", name ) + ".dawg"; |
256 | QFile dawgfile(dawgfilename); | 308 | QFile dawgfile(dawgfilename); |
257 | if ( dawgfile.open(IO_ReadOnly) ) | 309 | if ( dawgfile.open(IO_ReadOnly) ) |
258 | r->readFile(dawgfilename); | 310 | r->readFile(dawgfilename); |
259 | } | 311 | } |
260 | return *r; | 312 | return *r; |
261 | } | 313 | } |
262 | 314 | ||
263 | /*! | 315 | /*! |
316 | \overload | ||
264 | Adds \a wordlist to the addedDawg(). | 317 | Adds \a wordlist to the addedDawg(). |
318 | |||
319 | Note that the addition of words persists between program executions | ||
320 | (they are saved in the dictionary files), so you should confirm the | ||
321 | words with the user before adding them. | ||
265 | */ | 322 | */ |
266 | void Global::addWords(const QStringList& wordlist) | 323 | void Global::addWords(const QStringList& wordlist) |
267 | { | 324 | { |
268 | addWords("local",wordlist); | 325 | addWords("local",wordlist); |
269 | } | 326 | } |
270 | 327 | ||
271 | /*! | 328 | /*! |
272 | Adds \a wordlist to the dawg() named \a dictname. | 329 | \overload |
330 | Adds \a wordlist to the addedDawg(). | ||
331 | |||
332 | Note that the addition of words persists between program executions | ||
333 | (they are saved in the dictionary files), so you should confirm the | ||
334 | words with the user before adding them. | ||
273 | */ | 335 | */ |
274 | void Global::addWords(const QString& dictname, const QStringList& wordlist) | 336 | void Global::addWords(const QString& dictname, const QStringList& wordlist) |
275 | { | 337 | { |
276 | QDawg& d = (QDawg&)dawg(dictname); | 338 | QDawg& d = (QDawg&)dawg(dictname); |
277 | QStringList all = d.allWords() + wordlist; | 339 | QStringList all = d.allWords() + wordlist; |
278 | d.createFromWords(all); | 340 | d.createFromWords(all); |
279 | 341 | ||
280 | QString dawgfilename = dictDir() + "/" + dictname + ".dawg"; | 342 | QString dawgfilename = applicationFileName("Dictionary", dictname) + ".dawg"; |
281 | QFile dawgfile(dawgfilename); | 343 | QFile dawgfile(dawgfilename); |
282 | if ( dawgfile.open(IO_WriteOnly) ) { | 344 | if ( dawgfile.open(IO_WriteOnly) ) { |
283 | d.write(&dawgfile); | 345 | d.write(&dawgfile); |
284 | dawgfile.close(); | 346 | dawgfile.close(); |
@@ -290,13 +352,13 @@ void Global::addWords(const QString& dictname, const QStringList& wordlist) | |||
290 | } | 352 | } |
291 | 353 | ||
292 | 354 | ||
293 | /*! | 355 | /*! |
294 | Returns a full path for the application named \a appname, with the | 356 | Returns the full path for the application called \a appname, with the |
295 | given \a filename or QString::null if there was a problem creating | 357 | given \a filename. Returns QString::null if there was a problem creating |
296 | the directory tree for \a appname. | 358 | the directory tree for \a appname. |
297 | If \a filename contains "/", it is the caller's responsibility to | 359 | If \a filename contains "/", it is the caller's responsibility to |
298 | ensure those directories exist. | 360 | ensure that those directories exist. |
299 | */ | 361 | */ |
300 | QString Global::applicationFileName(const QString& appname, const QString& filename) | 362 | QString Global::applicationFileName(const QString& appname, const QString& filename) |
301 | { | 363 | { |
302 | QDir d; | 364 | QDir d; |
@@ -325,10 +387,10 @@ void Global::createDocDir() | |||
325 | } | 387 | } |
326 | 388 | ||
327 | 389 | ||
328 | /*! | 390 | /*! |
329 | Displays a status \a message to the user. This generally appears | 391 | Displays a status \a message to the user. This usually appears |
330 | in the taskbar for some amount of time, then disappears. | 392 | in the taskbar for a short amount of time, then disappears. |
331 | */ | 393 | */ |
332 | void Global::statusMessage(const QString& message) | 394 | void Global::statusMessage(const QString& message) |
333 | { | 395 | { |
334 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 396 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
@@ -372,8 +434,15 @@ QWidget *Global::restart( bool ) | |||
372 | } | 434 | } |
373 | 435 | ||
374 | /*! | 436 | /*! |
375 | Explicitly show the current input method. | 437 | Explicitly show the current input method. |
438 | |||
439 | 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 | ||
441 | of the bottom of the screen, to allow the user to interact (input | ||
442 | characters) with it. | ||
443 | |||
444 | \sa hideInputMethod() | ||
376 | */ | 445 | */ |
377 | void Global::showInputMethod() | 446 | void Global::showInputMethod() |
378 | { | 447 | { |
379 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 448 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
@@ -382,8 +451,13 @@ void Global::showInputMethod() | |||
382 | } | 451 | } |
383 | 452 | ||
384 | /*! | 453 | /*! |
385 | Explicitly hide the current input method. | 454 | Explicitly hide the current input method. |
455 | |||
456 | 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. | ||
458 | |||
459 | \sa showInputMethod() | ||
386 | */ | 460 | */ |
387 | void Global::hideInputMethod() | 461 | void Global::hideInputMethod() |
388 | { | 462 | { |
389 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 463 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
@@ -464,16 +538,22 @@ bool Global::terminateBuiltin( const QString& n ) | |||
464 | void Global::terminate( const AppLnk* app ) | 538 | void Global::terminate( const AppLnk* app ) |
465 | { | 539 | { |
466 | //if ( terminateBuiltin(app->exec()) ) return; // maybe? haven't tried this | 540 | //if ( terminateBuiltin(app->exec()) ) return; // maybe? haven't tried this |
467 | 541 | ||
542 | #ifndef QT_NO_COP | ||
468 | QCString channel = "QPE/Application/" + app->exec().utf8(); | 543 | QCString channel = "QPE/Application/" + app->exec().utf8(); |
469 | if ( QCopChannel::isRegistered(channel) ) { | 544 | if ( QCopChannel::isRegistered(channel) ) { |
470 | QCopEnvelope e(channel, "quit()"); | 545 | QCopEnvelope e(channel, "quit()"); |
471 | } | 546 | } |
547 | #endif | ||
472 | } | 548 | } |
473 | 549 | ||
474 | /*! | 550 | /*! |
475 | Low-level function to run command \a c. Not recommended. | 551 | Low-level function to run command \a c. |
552 | |||
553 | \warning Do not use this function. Use execute instead. | ||
554 | |||
555 | \sa execute() | ||
476 | */ | 556 | */ |
477 | void Global::invoke(const QString &c) | 557 | void Global::invoke(const QString &c) |
478 | { | 558 | { |
479 | // Convert the command line in to a list of arguments | 559 | // Convert the command line in to a list of arguments |
@@ -540,13 +620,15 @@ void Global::invoke(const QString &c) | |||
540 | StartingAppList::add( list[0] ); | 620 | StartingAppList::add( list[0] ); |
541 | #endif //QT_NO_QWS_MULTIPROCESS | 621 | #endif //QT_NO_QWS_MULTIPROCESS |
542 | } | 622 | } |
543 | 623 | ||
624 | |||
544 | /*! | 625 | /*! |
545 | Executes application identfied by \a c, passing \a document. | 626 | Executes the application identfied by \a c, passing \a |
627 | document if it isn't null. | ||
546 | 628 | ||
547 | Note that you might be better off sending a QCop message to | 629 | Note that a better approach might be to send a QCop message to the |
548 | the application's QPE/Application/<i>appname</i> channel. | 630 | application's QPE/Application/\e{appname} channel. |
549 | */ | 631 | */ |
550 | void Global::execute( const QString &c, const QString& document ) | 632 | void Global::execute( const QString &c, const QString& document ) |
551 | { | 633 | { |
552 | if ( qApp->type() != QApplication::GuiServer ) { | 634 | if ( qApp->type() != QApplication::GuiServer ) { |
@@ -576,10 +658,12 @@ void Global::execute( const QString &c, const QString& document ) | |||
576 | running[i]->setActiveWindow(); | 658 | running[i]->setActiveWindow(); |
577 | } else { | 659 | } else { |
578 | running[i] = builtin[i].func( builtin[i].maximized ); | 660 | running[i] = builtin[i].func( builtin[i].maximized ); |
579 | } | 661 | } |
662 | #ifndef QT_NO_COP | ||
580 | QCopEnvelope e("QPE/System", "notBusy(QString)" ); | 663 | QCopEnvelope e("QPE/System", "notBusy(QString)" ); |
581 | e << c; // that was quick ;-) | 664 | e << c; // that was quick ;-) |
665 | #endif | ||
582 | return; | 666 | return; |
583 | } | 667 | } |
584 | } | 668 | } |
585 | } | 669 | } |
@@ -599,19 +683,22 @@ void Global::execute( const QString &c, const QString& document ) | |||
599 | } | 683 | } |
600 | 684 | ||
601 | /* if need be, sending a qcop message will result in an invoke, see | 685 | /* if need be, sending a qcop message will result in an invoke, see |
602 | preceeding function */ | 686 | preceeding function */ |
603 | { QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "raise()" ); } | 687 | invoke( ap ); |
688 | //{ QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "raise()" ); } | ||
604 | if ( !document.isEmpty() ) { | 689 | if ( !document.isEmpty() ) { |
605 | QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "setDocument(QString)" ); | 690 | QCopEnvelope env( ("QPE/Application/" + ap).latin1(), "setDocument(QString)" ); |
606 | env << document; | 691 | env << document; |
607 | } | 692 | } |
608 | #endif | 693 | #endif |
609 | } | 694 | } |
610 | 695 | ||
611 | /*! | 696 | /*! |
612 | Returns the string \a s with the characters backslash, ", and $ | 697 | Returns the string \a s with the characters '\', '"', and '$' quoted |
613 | quoted by a preceeding backslash. | 698 | by a preceeding '\'. |
699 | |||
700 | \sa stringQuote() | ||
614 | */ | 701 | */ |
615 | QString Global::shellQuote(const QString& s) | 702 | QString Global::shellQuote(const QString& s) |
616 | { | 703 | { |
617 | QString r="\""; | 704 | QString r="\""; |
@@ -627,10 +714,12 @@ QString Global::shellQuote(const QString& s) | |||
627 | return r; | 714 | return r; |
628 | } | 715 | } |
629 | 716 | ||
630 | /*! | 717 | /*! |
631 | Returns the string \a s with the characters backslash and " | 718 | Returns the string \a s with the characters '\' and '"' quoted by a |
632 | quoted by a preceeding backslash. | 719 | preceeding '\'. |
720 | |||
721 | \sa shellQuote() | ||
633 | */ | 722 | */ |
634 | QString Global::stringQuote(const QString& s) | 723 | QString Global::stringQuote(const QString& s) |
635 | { | 724 | { |
636 | QString r="\""; | 725 | QString r="\""; |
@@ -712,18 +801,12 @@ QStringList Global::helpPath() | |||
712 | if ( !lang.isEmpty() ) | 801 | if ( !lang.isEmpty() ) |
713 | path += QPEApplication::qpeDir() + "/help/" + lang + "/html"; | 802 | path += QPEApplication::qpeDir() + "/help/" + lang + "/html"; |
714 | } | 803 | } |
715 | path += QPEApplication::qpeDir() + "/pics"; | 804 | path += QPEApplication::qpeDir() + "/pics"; |
716 | path += QPEApplication::qpeDir() + "/help/en/html"; | 805 | path += QPEApplication::qpeDir() + "/help/html"; |
717 | path += QPEApplication::qpeDir() + "/docs"; | 806 | path += QPEApplication::qpeDir() + "/docs"; |
718 | QString dir = QDir::current().canonicalPath(); | 807 | |
719 | if ( dir == "/" ) | 808 | |
720 | dir += "/docs"; | ||
721 | else { | ||
722 | path += dir + "/../pics"; | ||
723 | dir += "/../docs"; | ||
724 | path += dir; | ||
725 | } | ||
726 | return path; | 809 | return path; |
727 | } | 810 | } |
728 | 811 | ||
729 | 812 | ||