-rw-r--r-- | library/global.cpp | 55 |
1 files changed, 49 insertions, 6 deletions
diff --git a/library/global.cpp b/library/global.cpp index fd7579a..dd15eb7 100644 --- a/library/global.cpp +++ b/library/global.cpp | |||
@@ -1,83 +1,84 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #define QTOPIA_INTERNAL_LANGLIST | ||
20 | #include <qpe/qpedebug.h> | 21 | #include <qpe/qpedebug.h> |
21 | #include <qpe/global.h> | 22 | #include <qpe/global.h> |
22 | #include <qpe/qdawg.h> | 23 | #include <qpe/qdawg.h> |
23 | #include <qpe/qpeapplication.h> | 24 | #include <qpe/qpeapplication.h> |
24 | #include <qpe/resource.h> | 25 | #include <qpe/resource.h> |
25 | #include <qpe/storage.h> | 26 | #include <qpe/storage.h> |
26 | #include <qpe/applnk.h> | 27 | #include <qpe/applnk.h> |
27 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 28 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
28 | #include "qpe/qcopenvelope_qws.h" | 29 | #include "qpe/qcopenvelope_qws.h" |
29 | #endif | 30 | #endif |
30 | 31 | ||
31 | #include <qfile.h> | 32 | #include <qfile.h> |
32 | #include <qlabel.h> | 33 | #include <qlabel.h> |
33 | #include <qtimer.h> | 34 | #include <qtimer.h> |
34 | #include <qmap.h> | 35 | #include <qmap.h> |
35 | #include <qdict.h> | 36 | #include <qdict.h> |
36 | #include <qdir.h> | 37 | #include <qdir.h> |
37 | #include <qmessagebox.h> | 38 | #include <qmessagebox.h> |
38 | #include <qregexp.h> | 39 | #include <qregexp.h> |
39 | 40 | ||
40 | #include <stdlib.h> | 41 | #include <stdlib.h> |
41 | #include <sys/stat.h> | 42 | #include <sys/stat.h> |
42 | #include <sys/wait.h> | 43 | #include <sys/wait.h> |
43 | #include <sys/types.h> | 44 | #include <sys/types.h> |
44 | #include <fcntl.h> | 45 | #include <fcntl.h> |
45 | #include <unistd.h> | 46 | #include <unistd.h> |
46 | 47 | ||
47 | #include <qwindowsystem_qws.h> // for qwsServer | 48 | #include <qwindowsystem_qws.h> // for qwsServer |
48 | #include <qdatetime.h> | 49 | #include <qdatetime.h> |
49 | 50 | ||
50 | //#include "quickexec_p.h" | 51 | //#include "quickexec_p.h" |
51 | 52 | ||
52 | class Emitter : public QObject { | 53 | class Emitter : public QObject { |
53 | Q_OBJECT | 54 | Q_OBJECT |
54 | public: | 55 | public: |
55 | Emitter( QWidget* receiver, const QString& document ) | 56 | Emitter( QWidget* receiver, const QString& document ) |
56 | { | 57 | { |
57 | connect(this, SIGNAL(setDocument(const QString&)), | 58 | connect(this, SIGNAL(setDocument(const QString&)), |
58 | receiver, SLOT(setDocument(const QString&))); | 59 | receiver, SLOT(setDocument(const QString&))); |
59 | emit setDocument(document); | 60 | emit setDocument(document); |
60 | disconnect(this, SIGNAL(setDocument(const QString&)), | 61 | disconnect(this, SIGNAL(setDocument(const QString&)), |
61 | receiver, SLOT(setDocument(const QString&))); | 62 | receiver, SLOT(setDocument(const QString&))); |
62 | } | 63 | } |
63 | 64 | ||
64 | signals: | 65 | signals: |
65 | void setDocument(const QString&); | 66 | void setDocument(const QString&); |
66 | }; | 67 | }; |
67 | 68 | ||
68 | 69 | ||
69 | class StartingAppList : public QObject { | 70 | class StartingAppList : public QObject { |
70 | Q_OBJECT | 71 | Q_OBJECT |
71 | public: | 72 | public: |
72 | static void add( const QString& name ); | 73 | static void add( const QString& name ); |
73 | static bool isStarting( const QString name ); | 74 | static bool isStarting( const QString name ); |
74 | private slots: | 75 | private slots: |
75 | void handleNewChannel( const QString &); | 76 | void handleNewChannel( const QString &); |
76 | private: | 77 | private: |
77 | StartingAppList( QObject *parent=0, const char* name=0 ) ; | 78 | StartingAppList( QObject *parent=0, const char* name=0 ) ; |
78 | 79 | ||
79 | QDict<QTime> dict; | 80 | QDict<QTime> dict; |
80 | static StartingAppList *appl; | 81 | static StartingAppList *appl; |
81 | }; | 82 | }; |
82 | 83 | ||
83 | StartingAppList* StartingAppList::appl = 0; | 84 | StartingAppList* StartingAppList::appl = 0; |
@@ -109,134 +110,140 @@ bool StartingAppList::isStarting( const QString name ) | |||
109 | if ( appl ) { | 110 | if ( appl ) { |
110 | QTime *t = appl->dict.find( "QPE/Application/" + name ); | 111 | QTime *t = appl->dict.find( "QPE/Application/" + name ); |
111 | if ( !t ) | 112 | if ( !t ) |
112 | return FALSE; | 113 | return FALSE; |
113 | if ( t->elapsed() > 10000 ) { | 114 | if ( t->elapsed() > 10000 ) { |
114 | // timeout in case of crash or something | 115 | // timeout in case of crash or something |
115 | appl->dict.remove( "QPE/Application/" + name ); | 116 | appl->dict.remove( "QPE/Application/" + name ); |
116 | return FALSE; | 117 | return FALSE; |
117 | } | 118 | } |
118 | return TRUE; | 119 | return TRUE; |
119 | } | 120 | } |
120 | #endif | 121 | #endif |
121 | return FALSE; | 122 | return FALSE; |
122 | } | 123 | } |
123 | 124 | ||
124 | void StartingAppList::handleNewChannel( const QString & name ) | 125 | void StartingAppList::handleNewChannel( const QString & name ) |
125 | { | 126 | { |
126 | #if QT_VERSION >= 232 && !defined(QT_NO_COP) | 127 | #if QT_VERSION >= 232 && !defined(QT_NO_COP) |
127 | dict.remove( name ); | 128 | dict.remove( name ); |
128 | #endif | 129 | #endif |
129 | } | 130 | } |
130 | 131 | ||
131 | static bool docDirCreated = FALSE; | 132 | static bool docDirCreated = FALSE; |
132 | static QDawg* fixed_dawg = 0; | 133 | static QDawg* fixed_dawg = 0; |
133 | static QDict<QDawg> *named_dawg = 0; | 134 | static QDict<QDawg> *named_dawg = 0; |
134 | 135 | ||
135 | static QString qpeDir() | 136 | static QString qpeDir() |
136 | { | 137 | { |
137 | QString dir = getenv("OPIEDIR"); | 138 | QString dir = getenv("OPIEDIR"); |
138 | if ( dir.isEmpty() ) dir = ".."; | 139 | if ( dir.isEmpty() ) dir = ".."; |
139 | return dir; | 140 | return dir; |
140 | } | 141 | } |
141 | 142 | ||
142 | static QString dictDir() | 143 | static QString dictDir() |
143 | { | 144 | { |
144 | return qpeDir() + "/etc/dict"; | 145 | return qpeDir() + "/etc/dict"; |
145 | } | 146 | } |
146 | 147 | ||
147 | /*! | 148 | /*! |
148 | \class Global global.h | 149 | \class Global global.h |
149 | \brief The Global class collects application-wide global functions. | 150 | \brief The Global class collects application-wide global functions. |
150 | */ | 151 | */ |
151 | 152 | ||
152 | /*! | 153 | /*! |
153 | \internal | 154 | \internal |
154 | */ | 155 | */ |
155 | Global::Global() | 156 | Global::Global() |
156 | { | 157 | { |
157 | } | 158 | } |
158 | 159 | ||
159 | /*! | 160 | /*! |
160 | Returns the unchangeable QDawg that contains general | 161 | Returns the unchangeable QDawg that contains general |
161 | words for the current locale. | 162 | words for the current locale. |
162 | 163 | ||
163 | \sa addedDawg() | 164 | \sa addedDawg() |
164 | */ | 165 | */ |
165 | const QDawg& Global::fixedDawg() | 166 | const QDawg& Global::fixedDawg() |
166 | { | 167 | { |
167 | if ( !fixed_dawg ) { | 168 | if ( !fixed_dawg ) { |
168 | if ( !docDirCreated ) | 169 | if ( !docDirCreated ) |
169 | createDocDir(); | 170 | createDocDir(); |
170 | 171 | ||
171 | fixed_dawg = new QDawg; | 172 | fixed_dawg = new QDawg; |
172 | QString dawgfilename = dictDir() + "/dawg"; | 173 | QString dawgfilename = dictDir() + "/dawg"; |
173 | QString lang = getenv( "LANG" ); | 174 | QString words_lang; |
174 | QString dawgfilename_lang = dawgfilename + "." + lang; | 175 | QStringList langs = Global::languageList(); |
175 | QString words_lang = dictDir() + "/words." + lang; | 176 | for (QStringList::ConstIterator it = langs.begin(); it!=langs.end(); ++it) { |
176 | if ( QFile::exists(dawgfilename_lang) || | 177 | QString lang = *it; |
177 | QFile::exists(words_lang) ) | 178 | words_lang = dictDir() + "/words." + lang; |
178 | dawgfilename = dawgfilename_lang; | 179 | QString dawgfilename_lang = dawgfilename + "." + lang; |
180 | if ( QFile::exists(dawgfilename_lang) || | ||
181 | QFile::exists(words_lang) ) { | ||
182 | dawgfilename = dawgfilename_lang; | ||
183 | break; | ||
184 | } | ||
185 | } | ||
179 | QFile dawgfile(dawgfilename); | 186 | QFile dawgfile(dawgfilename); |
180 | 187 | ||
181 | if ( !dawgfile.exists() ) { | 188 | if ( !dawgfile.exists() ) { |
182 | QString fn = dictDir() + "/words"; | 189 | QString fn = dictDir() + "/words"; |
183 | if ( QFile::exists(words_lang) ) | 190 | if ( QFile::exists(words_lang) ) |
184 | fn = words_lang; | 191 | fn = words_lang; |
185 | QFile in(fn); | 192 | QFile in(fn); |
186 | if ( in.open(IO_ReadOnly) ) { | 193 | if ( in.open(IO_ReadOnly) ) { |
187 | fixed_dawg->createFromWords(&in); | 194 | fixed_dawg->createFromWords(&in); |
188 | dawgfile.open(IO_WriteOnly); | 195 | dawgfile.open(IO_WriteOnly); |
189 | fixed_dawg->write(&dawgfile); | 196 | fixed_dawg->write(&dawgfile); |
190 | dawgfile.close(); | 197 | dawgfile.close(); |
191 | } | 198 | } |
192 | } else { | 199 | } else { |
193 | fixed_dawg->readFile(dawgfilename); | 200 | fixed_dawg->readFile(dawgfilename); |
194 | } | 201 | } |
195 | } | 202 | } |
196 | 203 | ||
197 | return *fixed_dawg; | 204 | return *fixed_dawg; |
198 | } | 205 | } |
199 | 206 | ||
200 | /*! | 207 | /*! |
201 | Returns the changeable QDawg that contains general | 208 | Returns the changeable QDawg that contains general |
202 | words for the current locale. | 209 | words for the current locale. |
203 | 210 | ||
204 | \sa fixedDawg() | 211 | \sa fixedDawg() |
205 | */ | 212 | */ |
206 | const QDawg& Global::addedDawg() | 213 | const QDawg& Global::addedDawg() |
207 | { | 214 | { |
208 | return dawg("local"); | 215 | return dawg("local"); |
209 | } | 216 | } |
210 | 217 | ||
211 | /*! | 218 | /*! |
212 | Returns the QDawg with the given \a name. | 219 | Returns the QDawg with the given \a name. |
213 | This is an application-specific word list. | 220 | This is an application-specific word list. |
214 | 221 | ||
215 | \a name should not contain "/". | 222 | \a name should not contain "/". |
216 | */ | 223 | */ |
217 | const QDawg& Global::dawg(const QString& name) | 224 | const QDawg& Global::dawg(const QString& name) |
218 | { | 225 | { |
219 | createDocDir(); | 226 | createDocDir(); |
220 | if ( !named_dawg ) | 227 | if ( !named_dawg ) |
221 | named_dawg = new QDict<QDawg>; | 228 | named_dawg = new QDict<QDawg>; |
222 | QDawg* r = named_dawg->find(name); | 229 | QDawg* r = named_dawg->find(name); |
223 | if ( !r ) { | 230 | if ( !r ) { |
224 | r = new QDawg; | 231 | r = new QDawg; |
225 | named_dawg->insert(name,r); | 232 | named_dawg->insert(name,r); |
226 | QString dawgfilename = dictDir() + "/" + name + ".dawg"; | 233 | QString dawgfilename = dictDir() + "/" + name + ".dawg"; |
227 | QFile dawgfile(dawgfilename); | 234 | QFile dawgfile(dawgfilename); |
228 | if ( dawgfile.open(IO_ReadOnly) ) | 235 | if ( dawgfile.open(IO_ReadOnly) ) |
229 | r->readFile(dawgfilename); | 236 | r->readFile(dawgfilename); |
230 | } | 237 | } |
231 | return *r; | 238 | return *r; |
232 | } | 239 | } |
233 | 240 | ||
234 | /*! | 241 | /*! |
235 | Adds \a wordlist to the addedDawg(). | 242 | Adds \a wordlist to the addedDawg(). |
236 | */ | 243 | */ |
237 | void Global::addWords(const QStringList& wordlist) | 244 | void Global::addWords(const QStringList& wordlist) |
238 | { | 245 | { |
239 | addWords("local",wordlist); | 246 | addWords("local",wordlist); |
240 | } | 247 | } |
241 | 248 | ||
242 | /*! | 249 | /*! |
@@ -578,67 +585,103 @@ void Global::execute( const QString &c, const QString& document ) | |||
578 | } | 585 | } |
579 | #endif | 586 | #endif |
580 | } | 587 | } |
581 | 588 | ||
582 | /*! | 589 | /*! |
583 | Returns the string \a s with the characters backslash, ", and $ | 590 | Returns the string \a s with the characters backslash, ", and $ |
584 | quoted by a preceeding backslash. | 591 | quoted by a preceeding backslash. |
585 | */ | 592 | */ |
586 | QString Global::shellQuote(const QString& s) | 593 | QString Global::shellQuote(const QString& s) |
587 | { | 594 | { |
588 | QString r="\""; | 595 | QString r="\""; |
589 | for (int i=0; i<(int)s.length(); i++) { | 596 | for (int i=0; i<(int)s.length(); i++) { |
590 | char c = s[i].latin1(); | 597 | char c = s[i].latin1(); |
591 | switch (c) { | 598 | switch (c) { |
592 | case '\\': case '"': case '$': | 599 | case '\\': case '"': case '$': |
593 | r+="\\"; | 600 | r+="\\"; |
594 | } | 601 | } |
595 | r += s[i]; | 602 | r += s[i]; |
596 | } | 603 | } |
597 | r += "\""; | 604 | r += "\""; |
598 | return r; | 605 | return r; |
599 | } | 606 | } |
600 | 607 | ||
601 | /*! | 608 | /*! |
602 | Returns the string \a s with the characters backslash and " | 609 | Returns the string \a s with the characters backslash and " |
603 | quoted by a preceeding backslash. | 610 | quoted by a preceeding backslash. |
604 | */ | 611 | */ |
605 | QString Global::stringQuote(const QString& s) | 612 | QString Global::stringQuote(const QString& s) |
606 | { | 613 | { |
607 | QString r="\""; | 614 | QString r="\""; |
608 | for (int i=0; i<(int)s.length(); i++) { | 615 | for (int i=0; i<(int)s.length(); i++) { |
609 | char c = s[i].latin1(); | 616 | char c = s[i].latin1(); |
610 | switch (c) { | 617 | switch (c) { |
611 | case '\\': case '"': | 618 | case '\\': case '"': |
612 | r+="\\"; | 619 | r+="\\"; |
613 | } | 620 | } |
614 | r += s[i]; | 621 | r += s[i]; |
615 | } | 622 | } |
616 | r += "\""; | 623 | r += "\""; |
617 | return r; | 624 | return r; |
618 | } | 625 | } |
619 | 626 | ||
620 | /*! | 627 | /*! |
621 | Finds all documents on the system's document directories which | 628 | Finds all documents on the system's document directories which |
622 | match the filter \a mimefilter, and appends the resulting DocLnk | 629 | match the filter \a mimefilter, and appends the resulting DocLnk |
623 | objects to \a folder. | 630 | objects to \a folder. |
624 | */ | 631 | */ |
625 | void Global::findDocuments(DocLnkSet* folder, const QString &mimefilter) | 632 | void Global::findDocuments(DocLnkSet* folder, const QString &mimefilter) |
626 | { | 633 | { |
627 | QString homedocs = QString(getenv("HOME")) + "/Documents"; | 634 | QString homedocs = QString(getenv("HOME")) + "/Documents"; |
628 | DocLnkSet d(homedocs,mimefilter); | 635 | DocLnkSet d(homedocs,mimefilter); |
629 | folder->appendFrom(d); | 636 | folder->appendFrom(d); |
630 | StorageInfo storage; | 637 | StorageInfo storage; |
631 | const QList<FileSystem> &fs = storage.fileSystems(); | 638 | const QList<FileSystem> &fs = storage.fileSystems(); |
632 | QListIterator<FileSystem> it ( fs ); | 639 | QListIterator<FileSystem> it ( fs ); |
633 | for ( ; it.current(); ++it ) { | 640 | for ( ; it.current(); ++it ) { |
634 | if ( (*it)->isRemovable() ) { | 641 | if ( (*it)->isRemovable() ) { |
635 | QString path = (*it)->path(); | 642 | QString path = (*it)->path(); |
636 | DocLnkSet ide( path, mimefilter ); | 643 | DocLnkSet ide( path, mimefilter ); |
637 | folder->appendFrom(ide); | 644 | folder->appendFrom(ide); |
638 | } | 645 | } |
639 | } | 646 | } |
640 | } | 647 | } |
641 | 648 | ||
649 | QStringList Global::languageList() | ||
650 | { | ||
651 | QString lang = getenv("LANG"); | ||
652 | QStringList langs; | ||
653 | langs.append(lang); | ||
654 | int i = lang.find("."); | ||
655 | if ( i > 0 ) | ||
656 | lang = lang.left( i ); | ||
657 | i = lang.find( "_" ); | ||
658 | if ( i > 0 ) | ||
659 | langs.append(lang.left(i)); | ||
660 | return langs; | ||
661 | } | ||
662 | |||
663 | QStringList Global::helpPath() | ||
664 | { | ||
665 | QStringList path; | ||
666 | QStringList langs = Global::languageList(); | ||
667 | for (QStringList::ConstIterator it = langs.fromLast(); it!=langs.end(); --it) { | ||
668 | QString lang = *it; | ||
669 | if ( !lang.isEmpty() ) | ||
670 | path += QPEApplication::qpeDir() + "/help/" + lang + "/html"; | ||
671 | } | ||
672 | path += QPEApplication::qpeDir() + "/pics"; | ||
673 | path += QPEApplication::qpeDir() + "/help/en/html"; | ||
674 | path += QPEApplication::qpeDir() + "/docs"; | ||
675 | QString dir = QDir::current().canonicalPath(); | ||
676 | if ( dir == "/" ) | ||
677 | dir += "/docs"; | ||
678 | else { | ||
679 | path += dir + "/../pics"; | ||
680 | dir += "/../docs"; | ||
681 | path += dir; | ||
682 | } | ||
683 | return path; | ||
684 | } | ||
642 | 685 | ||
643 | 686 | ||
644 | #include "global.moc" | 687 | #include "global.moc" |