-rw-r--r-- | library/global.cpp | 165 |
1 files changed, 124 insertions, 41 deletions
diff --git a/library/global.cpp b/library/global.cpp index ab27b3f..7438891 100644 --- a/library/global.cpp +++ b/library/global.cpp | |||
@@ -1,730 +1,813 @@ | |||
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 |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #define QTOPIA_INTERNAL_LANGLIST | 20 | #define QTOPIA_INTERNAL_LANGLIST |
21 | #include <qpe/qpedebug.h> | 21 | #include <qpe/qpedebug.h> |
22 | #include <qpe/global.h> | 22 | #include <qpe/global.h> |
23 | #include <qpe/qdawg.h> | 23 | #include <qpe/qdawg.h> |
24 | #include <qpe/qpeapplication.h> | 24 | #include <qpe/qpeapplication.h> |
25 | #include <qpe/resource.h> | 25 | #include <qpe/resource.h> |
26 | #include <qpe/storage.h> | 26 | #include <qpe/storage.h> |
27 | #include <qpe/applnk.h> | 27 | #include <qpe/applnk.h> |
28 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 28 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
29 | #include "qpe/qcopenvelope_qws.h" | 29 | #include "qpe/qcopenvelope_qws.h" |
30 | #endif | 30 | #endif |
31 | 31 | ||
32 | #include <qfile.h> | 32 | #include <qfile.h> |
33 | #include <qlabel.h> | 33 | #include <qlabel.h> |
34 | #include <qtimer.h> | 34 | #include <qtimer.h> |
35 | #include <qmap.h> | 35 | #include <qmap.h> |
36 | #include <qdict.h> | 36 | #include <qdict.h> |
37 | #include <qdir.h> | 37 | #include <qdir.h> |
38 | #include <qmessagebox.h> | 38 | #include <qmessagebox.h> |
39 | #include <qregexp.h> | 39 | #include <qregexp.h> |
40 | 40 | ||
41 | #include <stdlib.h> | 41 | #include <stdlib.h> |
42 | #include <sys/stat.h> | 42 | #include <sys/stat.h> |
43 | #include <sys/wait.h> | 43 | #include <sys/wait.h> |
44 | #include <sys/types.h> | 44 | #include <sys/types.h> |
45 | #include <fcntl.h> | 45 | #include <fcntl.h> |
46 | #include <unistd.h> | 46 | #include <unistd.h> |
47 | 47 | ||
48 | #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 | ||
53 | namespace { | 55 | namespace { |
54 | // checks if the storage should be searched | 56 | // checks if the storage should be searched |
55 | bool checkStorage(const QString &path ){ // this is a small Config replacement cause config is too limited -zecke | 57 | bool checkStorage(const QString &path ){ // this is a small Config replacement cause config is too limited -zecke |
56 | QFile file(path ); | 58 | QFile file(path ); |
57 | if(!file.open(IO_ReadOnly ) ) | 59 | if(!file.open(IO_ReadOnly ) ) |
58 | return true; | 60 | return true; |
59 | 61 | ||
60 | QByteArray array = file.readAll(); | 62 | QByteArray array = file.readAll(); |
61 | QStringList list = QStringList::split('\n', QString( array ) ); | 63 | QStringList list = QStringList::split('\n', QString( array ) ); |
62 | for(QStringList::Iterator it = list.begin(); it != list.end(); ++it ){ | 64 | for(QStringList::Iterator it = list.begin(); it != list.end(); ++it ){ |
63 | if( (*it).startsWith("autocheck = 0" ) ){ | 65 | if( (*it).startsWith("autocheck = 0" ) ){ |
64 | return false; | 66 | return false; |
65 | }else if( (*it).startsWith("autocheck = 1" ) ){ | 67 | }else if( (*it).startsWith("autocheck = 1" ) ){ |
66 | return true; | 68 | return true; |
67 | } | 69 | } |
68 | } | 70 | } |
69 | return true; | 71 | return true; |
70 | } | 72 | } |
71 | } | 73 | } |
72 | 74 | ||
73 | //#include "quickexec_p.h" | 75 | //#include "quickexec_p.h" |
74 | 76 | ||
75 | class Emitter : public QObject { | 77 | class Emitter : public QObject { |
76 | Q_OBJECT | 78 | Q_OBJECT |
77 | public: | 79 | public: |
78 | Emitter( QWidget* receiver, const QString& document ) | 80 | Emitter( QWidget* receiver, const QString& document ) |
79 | { | 81 | { |
80 | connect(this, SIGNAL(setDocument(const QString&)), | 82 | connect(this, SIGNAL(setDocument(const QString&)), |
81 | receiver, SLOT(setDocument(const QString&))); | 83 | receiver, SLOT(setDocument(const QString&))); |
82 | emit setDocument(document); | 84 | emit setDocument(document); |
83 | disconnect(this, SIGNAL(setDocument(const QString&)), | 85 | disconnect(this, SIGNAL(setDocument(const QString&)), |
84 | receiver, SLOT(setDocument(const QString&))); | 86 | receiver, SLOT(setDocument(const QString&))); |
85 | } | 87 | } |
86 | 88 | ||
87 | signals: | 89 | signals: |
88 | void setDocument(const QString&); | 90 | void setDocument(const QString&); |
89 | }; | 91 | }; |
90 | 92 | ||
91 | 93 | ||
92 | class StartingAppList : public QObject { | 94 | class StartingAppList : public QObject { |
93 | Q_OBJECT | 95 | Q_OBJECT |
94 | public: | 96 | public: |
95 | static void add( const QString& name ); | 97 | static void add( const QString& name ); |
96 | static bool isStarting( const QString name ); | 98 | static bool isStarting( const QString name ); |
97 | private slots: | 99 | private slots: |
98 | void handleNewChannel( const QString &); | 100 | void handleNewChannel( const QString &); |
99 | private: | 101 | private: |
100 | StartingAppList( QObject *parent=0, const char* name=0 ) ; | 102 | StartingAppList( QObject *parent=0, const char* name=0 ) ; |
101 | 103 | ||
102 | QDict<QTime> dict; | 104 | QDict<QTime> dict; |
103 | static StartingAppList *appl; | 105 | static StartingAppList *appl; |
104 | }; | 106 | }; |
105 | 107 | ||
106 | StartingAppList* StartingAppList::appl = 0; | 108 | 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 | { |
120 | #if QT_VERSION >= 232 && !defined(QT_NO_COP) | 124 | #if QT_VERSION >= 232 && !defined(QT_NO_COP) |
121 | if ( !appl ) | 125 | if ( !appl ) |
122 | appl = new StartingAppList; | 126 | appl = new StartingAppList; |
123 | QTime *t = new QTime; | 127 | QTime *t = new QTime; |
124 | t->start(); | 128 | t->start(); |
125 | appl->dict.insert( "QPE/Application/" + name, t ); | 129 | appl->dict.insert( "QPE/Application/" + name, t ); |
126 | #endif | 130 | #endif |
127 | } | 131 | } |
128 | 132 | ||
129 | bool StartingAppList::isStarting( const QString name ) | 133 | bool StartingAppList::isStarting( const QString name ) |
130 | { | 134 | { |
131 | #if QT_VERSION >= 232 && !defined(QT_NO_COP) | 135 | #if QT_VERSION >= 232 && !defined(QT_NO_COP) |
132 | if ( appl ) { | 136 | if ( appl ) { |
133 | QTime *t = appl->dict.find( "QPE/Application/" + name ); | 137 | QTime *t = appl->dict.find( "QPE/Application/" + name ); |
134 | if ( !t ) | 138 | if ( !t ) |
135 | return FALSE; | 139 | return FALSE; |
136 | if ( t->elapsed() > 10000 ) { | 140 | if ( t->elapsed() > 10000 ) { |
137 | // timeout in case of crash or something | 141 | // timeout in case of crash or something |
138 | appl->dict.remove( "QPE/Application/" + name ); | 142 | appl->dict.remove( "QPE/Application/" + name ); |
139 | return FALSE; | 143 | return FALSE; |
140 | } | 144 | } |
141 | return TRUE; | 145 | return TRUE; |
142 | } | 146 | } |
143 | #endif | 147 | #endif |
144 | return FALSE; | 148 | return FALSE; |
145 | } | 149 | } |
146 | 150 | ||
147 | void StartingAppList::handleNewChannel( const QString & name ) | 151 | void StartingAppList::handleNewChannel( const QString & name ) |
148 | { | 152 | { |
149 | #if QT_VERSION >= 232 && !defined(QT_NO_COP) | 153 | #if QT_VERSION >= 232 && !defined(QT_NO_COP) |
150 | dict.remove( name ); | 154 | dict.remove( name ); |
151 | #endif | 155 | #endif |
152 | } | 156 | } |
153 | 157 | ||
154 | static bool docDirCreated = FALSE; | 158 | static bool docDirCreated = FALSE; |
155 | static QDawg* fixed_dawg = 0; | 159 | static QDawg* fixed_dawg = 0; |
156 | static QDict<QDawg> *named_dawg = 0; | 160 | static QDict<QDawg> *named_dawg = 0; |
157 | 161 | ||
158 | static QString qpeDir() | 162 | static QString qpeDir() |
159 | { | 163 | { |
160 | QString dir = getenv("OPIEDIR"); | 164 | QString dir = getenv("OPIEDIR"); |
161 | if ( dir.isEmpty() ) dir = ".."; | 165 | if ( dir.isEmpty() ) dir = ".."; |
162 | return dir; | 166 | return dir; |
163 | } | 167 | } |
164 | 168 | ||
165 | static QString dictDir() | 169 | static QString dictDir() |
166 | { | 170 | { |
167 | return qpeDir() + "/etc/dict"; | 171 | return qpeDir() + "/etc/dict"; |
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 |
177 | */ | 229 | */ |
178 | Global::Global() | 230 | Global::Global() |
179 | { | 231 | { |
180 | } | 232 | } |
181 | 233 | ||
182 | /*! | 234 | /*! |
183 | Returns the unchangeable QDawg that contains general | 235 | Returns the unchangeable QDawg that contains general |
184 | words for the current locale. | 236 | words for the current locale. |
185 | 237 | ||
186 | \sa addedDawg() | 238 | \sa addedDawg() |
187 | */ | 239 | */ |
188 | const QDawg& Global::fixedDawg() | 240 | const QDawg& Global::fixedDawg() |
189 | { | 241 | { |
190 | if ( !fixed_dawg ) { | 242 | if ( !fixed_dawg ) { |
191 | if ( !docDirCreated ) | 243 | if ( !docDirCreated ) |
192 | createDocDir(); | 244 | createDocDir(); |
193 | 245 | ||
194 | fixed_dawg = new QDawg; | 246 | fixed_dawg = new QDawg; |
195 | QString dawgfilename = dictDir() + "/dawg"; | 247 | QString dawgfilename = dictDir() + "/dawg"; |
196 | QString words_lang; | 248 | QString words_lang; |
197 | QStringList langs = Global::languageList(); | 249 | QStringList langs = Global::languageList(); |
198 | for (QStringList::ConstIterator it = langs.begin(); it!=langs.end(); ++it) { | 250 | for (QStringList::ConstIterator it = langs.begin(); it!=langs.end(); ++it) { |
199 | QString lang = *it; | 251 | QString lang = *it; |
200 | words_lang = dictDir() + "/words." + lang; | 252 | words_lang = dictDir() + "/words." + lang; |
201 | QString dawgfilename_lang = dawgfilename + "." + lang; | 253 | QString dawgfilename_lang = dawgfilename + "." + lang; |
202 | if ( QFile::exists(dawgfilename_lang) || | 254 | if ( QFile::exists(dawgfilename_lang) || |
203 | QFile::exists(words_lang) ) { | 255 | QFile::exists(words_lang) ) { |
204 | dawgfilename = dawgfilename_lang; | 256 | dawgfilename = dawgfilename_lang; |
205 | break; | 257 | break; |
206 | } | 258 | } |
207 | } | 259 | } |
208 | QFile dawgfile(dawgfilename); | 260 | QFile dawgfile(dawgfilename); |
209 | 261 | ||
210 | if ( !dawgfile.exists() ) { | 262 | if ( !dawgfile.exists() ) { |
211 | QString fn = dictDir() + "/words"; | 263 | QString fn = dictDir() + "/words"; |
212 | if ( QFile::exists(words_lang) ) | 264 | if ( QFile::exists(words_lang) ) |
213 | fn = words_lang; | 265 | fn = words_lang; |
214 | QFile in(fn); | 266 | QFile in(fn); |
215 | if ( in.open(IO_ReadOnly) ) { | 267 | if ( in.open(IO_ReadOnly) ) { |
216 | fixed_dawg->createFromWords(&in); | 268 | fixed_dawg->createFromWords(&in); |
217 | dawgfile.open(IO_WriteOnly); | 269 | dawgfile.open(IO_WriteOnly); |
218 | fixed_dawg->write(&dawgfile); | 270 | fixed_dawg->write(&dawgfile); |
219 | dawgfile.close(); | 271 | dawgfile.close(); |
220 | } | 272 | } |
221 | } else { | 273 | } else { |
222 | fixed_dawg->readFile(dawgfilename); | 274 | fixed_dawg->readFile(dawgfilename); |
223 | } | 275 | } |
224 | } | 276 | } |
225 | 277 | ||
226 | return *fixed_dawg; | 278 | return *fixed_dawg; |
227 | } | 279 | } |
228 | 280 | ||
229 | /*! | 281 | /*! |
230 | Returns the changeable QDawg that contains general | 282 | Returns the changeable QDawg that contains general |
231 | words for the current locale. | 283 | words for the current locale. |
232 | 284 | ||
233 | \sa fixedDawg() | 285 | \sa fixedDawg() |
234 | */ | 286 | */ |
235 | const QDawg& Global::addedDawg() | 287 | const QDawg& Global::addedDawg() |
236 | { | 288 | { |
237 | return dawg("local"); | 289 | return dawg("local"); |
238 | } | 290 | } |
239 | 291 | ||
240 | /*! | 292 | /*! |
241 | Returns the QDawg with the given \a name. | 293 | Returns the QDawg with the given \a name. |
242 | This is an application-specific word list. | 294 | This is an application-specific word list. |
243 | 295 | ||
244 | \a name should not contain "/". | 296 | \a name should not contain "/". |
245 | */ | 297 | */ |
246 | const QDawg& Global::dawg(const QString& name) | 298 | const QDawg& Global::dawg(const QString& name) |
247 | { | 299 | { |
248 | createDocDir(); | 300 | createDocDir(); |
249 | if ( !named_dawg ) | 301 | if ( !named_dawg ) |
250 | named_dawg = new QDict<QDawg>; | 302 | named_dawg = new QDict<QDawg>; |
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(); |
285 | } | 347 | } |
286 | 348 | ||
287 | // #### Re-read the dawg here if we use mmap(). | 349 | // #### Re-read the dawg here if we use mmap(). |
288 | 350 | ||
289 | // #### Signal other processes to re-read. | 351 | // #### Signal other processes to re-read. |
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; |
303 | QString r = getenv("HOME"); | 365 | QString r = getenv("HOME"); |
304 | r += "/Applications/"; | 366 | r += "/Applications/"; |
305 | if ( !QFile::exists( r ) ) | 367 | if ( !QFile::exists( r ) ) |
306 | if ( d.mkdir(r) == false ) | 368 | if ( d.mkdir(r) == false ) |
307 | return QString::null; | 369 | return QString::null; |
308 | r += appname; | 370 | r += appname; |
309 | if ( !QFile::exists( r ) ) | 371 | if ( !QFile::exists( r ) ) |
310 | if ( d.mkdir(r) == false ) | 372 | if ( d.mkdir(r) == false ) |
311 | return QString::null; | 373 | return QString::null; |
312 | r += "/"; r += filename; | 374 | r += "/"; r += filename; |
313 | return r; | 375 | return r; |
314 | } | 376 | } |
315 | 377 | ||
316 | /*! | 378 | /*! |
317 | \internal | 379 | \internal |
318 | */ | 380 | */ |
319 | void Global::createDocDir() | 381 | void Global::createDocDir() |
320 | { | 382 | { |
321 | if ( !docDirCreated ) { | 383 | if ( !docDirCreated ) { |
322 | docDirCreated = TRUE; | 384 | docDirCreated = TRUE; |
323 | mkdir( QPEApplication::documentDir().latin1(), 0755 ); | 385 | mkdir( QPEApplication::documentDir().latin1(), 0755 ); |
324 | } | 386 | } |
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) |
335 | QCopEnvelope e( "QPE/TaskBar", "message(QString)" ); | 397 | QCopEnvelope e( "QPE/TaskBar", "message(QString)" ); |
336 | e << message; | 398 | e << message; |
337 | #endif | 399 | #endif |
338 | } | 400 | } |
339 | 401 | ||
340 | /*! | 402 | /*! |
341 | \internal | 403 | \internal |
342 | */ | 404 | */ |
343 | void Global::applyStyle() | 405 | void Global::applyStyle() |
344 | { | 406 | { |
345 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 407 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
346 | QCopChannel::send( "QPE/System", "applyStyle()" ); | 408 | QCopChannel::send( "QPE/System", "applyStyle()" ); |
347 | #else | 409 | #else |
348 | ((QPEApplication *)qApp)->applyStyle(); // apply without needing QCop for floppy version | 410 | ((QPEApplication *)qApp)->applyStyle(); // apply without needing QCop for floppy version |
349 | #endif | 411 | #endif |
350 | } | 412 | } |
351 | 413 | ||
352 | /*! | 414 | /*! |
353 | \internal | 415 | \internal |
354 | */ | 416 | */ |
355 | QWidget *Global::shutdown( bool ) | 417 | QWidget *Global::shutdown( bool ) |
356 | { | 418 | { |
357 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 419 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
358 | QCopChannel::send( "QPE/System", "shutdown()" ); | 420 | QCopChannel::send( "QPE/System", "shutdown()" ); |
359 | #endif | 421 | #endif |
360 | return 0; | 422 | return 0; |
361 | } | 423 | } |
362 | 424 | ||
363 | /*! | 425 | /*! |
364 | \internal | 426 | \internal |
365 | */ | 427 | */ |
366 | QWidget *Global::restart( bool ) | 428 | QWidget *Global::restart( bool ) |
367 | { | 429 | { |
368 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 430 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
369 | QCopChannel::send( "QPE/System", "restart()" ); | 431 | QCopChannel::send( "QPE/System", "restart()" ); |
370 | #endif | 432 | #endif |
371 | return 0; | 433 | return 0; |
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) |
380 | QCopChannel::send( "QPE/TaskBar", "showInputMethod()" ); | 449 | QCopChannel::send( "QPE/TaskBar", "showInputMethod()" ); |
381 | #endif | 450 | #endif |
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) |
390 | QCopChannel::send( "QPE/TaskBar", "hideInputMethod()" ); | 464 | QCopChannel::send( "QPE/TaskBar", "hideInputMethod()" ); |
391 | #endif | 465 | #endif |
392 | } | 466 | } |
393 | 467 | ||
394 | 468 | ||
395 | /*! | 469 | /*! |
396 | \internal | 470 | \internal |
397 | */ | 471 | */ |
398 | bool Global::isBuiltinCommand( const QString &name ) | 472 | bool Global::isBuiltinCommand( const QString &name ) |
399 | { | 473 | { |
400 | if(!builtin) | 474 | if(!builtin) |
401 | return FALSE; // yes, it can happen | 475 | return FALSE; // yes, it can happen |
402 | for (int i = 0; builtin[i].file; i++) { | 476 | for (int i = 0; builtin[i].file; i++) { |
403 | if ( builtin[i].file == name ) { | 477 | if ( builtin[i].file == name ) { |
404 | return TRUE; | 478 | return TRUE; |
405 | } | 479 | } |
406 | } | 480 | } |
407 | return FALSE; | 481 | return FALSE; |
408 | } | 482 | } |
409 | 483 | ||
410 | Global::Command* Global::builtin=0; | 484 | Global::Command* Global::builtin=0; |
411 | QGuardedPtr<QWidget> *Global::running=0; | 485 | QGuardedPtr<QWidget> *Global::running=0; |
412 | 486 | ||
413 | /*! | 487 | /*! |
414 | \class Global::Command | 488 | \class Global::Command |
415 | \brief The Global::Command class is internal. | 489 | \brief The Global::Command class is internal. |
416 | \internal | 490 | \internal |
417 | */ | 491 | */ |
418 | 492 | ||
419 | /*! | 493 | /*! |
420 | \internal | 494 | \internal |
421 | */ | 495 | */ |
422 | void Global::setBuiltinCommands( Command* list ) | 496 | void Global::setBuiltinCommands( Command* list ) |
423 | { | 497 | { |
424 | if ( running ) | 498 | if ( running ) |
425 | delete [] running; | 499 | delete [] running; |
426 | 500 | ||
427 | builtin = list; | 501 | builtin = list; |
428 | int count = 0; | 502 | int count = 0; |
429 | if (!builtin) | 503 | if (!builtin) |
430 | return; | 504 | return; |
431 | while ( builtin[count].file ) | 505 | while ( builtin[count].file ) |
432 | count++; | 506 | count++; |
433 | 507 | ||
434 | running = new QGuardedPtr<QWidget> [ count ]; | 508 | running = new QGuardedPtr<QWidget> [ count ]; |
435 | } | 509 | } |
436 | 510 | ||
437 | /*! | 511 | /*! |
438 | \internal | 512 | \internal |
439 | */ | 513 | */ |
440 | void Global::setDocument( QWidget* receiver, const QString& document ) | 514 | void Global::setDocument( QWidget* receiver, const QString& document ) |
441 | { | 515 | { |
442 | Emitter emitter(receiver,document); | 516 | Emitter emitter(receiver,document); |
443 | } | 517 | } |
444 | 518 | ||
445 | /*! | 519 | /*! |
446 | \internal | 520 | \internal |
447 | */ | 521 | */ |
448 | bool Global::terminateBuiltin( const QString& n ) | 522 | bool Global::terminateBuiltin( const QString& n ) |
449 | { | 523 | { |
450 | if (!builtin) | 524 | if (!builtin) |
451 | return FALSE; | 525 | return FALSE; |
452 | for (int i = 0; builtin[i].file; i++) { | 526 | for (int i = 0; builtin[i].file; i++) { |
453 | if ( builtin[i].file == n ) { | 527 | if ( builtin[i].file == n ) { |
454 | delete running[i]; | 528 | delete running[i]; |
455 | return TRUE; | 529 | return TRUE; |
456 | } | 530 | } |
457 | } | 531 | } |
458 | return FALSE; | 532 | return FALSE; |
459 | } | 533 | } |
460 | 534 | ||
461 | /*! | 535 | /*! |
462 | \internal | 536 | \internal |
463 | */ | 537 | */ |
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 |
480 | QStringList list = QStringList::split(QRegExp(" *"),c); | 560 | QStringList list = QStringList::split(QRegExp(" *"),c); |
481 | 561 | ||
482 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 562 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
483 | QString ap=list[0]; | 563 | QString ap=list[0]; |
484 | // see if the application is already running | 564 | // see if the application is already running |
485 | // XXX should lock file /tmp/qcop-msg-ap | 565 | // XXX should lock file /tmp/qcop-msg-ap |
486 | if ( QCopChannel::isRegistered( ("QPE/Application/" + ap).latin1() ) ) { | 566 | if ( QCopChannel::isRegistered( ("QPE/Application/" + ap).latin1() ) ) { |
487 | QCopEnvelope e("QPE/System", "notBusy(QString)" ); | 567 | QCopEnvelope e("QPE/System", "notBusy(QString)" ); |
488 | e << ap; | 568 | e << ap; |
489 | return; | 569 | return; |
490 | } | 570 | } |
491 | // XXX should unlock file /tmp/qcop-msg-ap | 571 | // XXX should unlock file /tmp/qcop-msg-ap |
492 | //see if it is being started | 572 | //see if it is being started |
493 | if ( StartingAppList::isStarting( ap ) ) { | 573 | if ( StartingAppList::isStarting( ap ) ) { |
494 | QCopEnvelope e("QPE/System", "notBusy(QString)" ); | 574 | QCopEnvelope e("QPE/System", "notBusy(QString)" ); |
495 | e << ap; | 575 | e << ap; |
496 | return; | 576 | return; |
497 | } | 577 | } |
498 | 578 | ||
499 | #endif | 579 | #endif |
500 | 580 | ||
501 | #ifdef QT_NO_QWS_MULTIPROCESS | 581 | #ifdef QT_NO_QWS_MULTIPROCESS |
502 | QMessageBox::warning( 0, "Error", "Could not find the application " + c, "Ok", 0, 0, 0, 1 ); | 582 | QMessageBox::warning( 0, "Error", "Could not find the application " + c, "Ok", 0, 0, 0, 1 ); |
503 | #else | 583 | #else |
504 | 584 | ||
505 | QStrList slist; | 585 | QStrList slist; |
506 | unsigned int j; | 586 | unsigned int j; |
507 | for ( j = 0; j < list.count(); j++ ) | 587 | for ( j = 0; j < list.count(); j++ ) |
508 | slist.append( list[j].utf8() ); | 588 | slist.append( list[j].utf8() ); |
509 | 589 | ||
510 | const char **args = new (const char *)[slist.count() + 1]; | 590 | const char **args = new (const char *)[slist.count() + 1]; |
511 | for ( j = 0; j < slist.count(); j++ ) | 591 | for ( j = 0; j < slist.count(); j++ ) |
512 | args[j] = slist.at(j); | 592 | args[j] = slist.at(j); |
513 | args[j] = NULL; | 593 | args[j] = NULL; |
514 | 594 | ||
515 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 595 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
516 | // an attempt to show a wait... | 596 | // an attempt to show a wait... |
517 | // more logic should be used, but this will be fine for the moment... | 597 | // more logic should be used, but this will be fine for the moment... |
518 | QCopEnvelope ( "QPE/System", "busy()" ); | 598 | QCopEnvelope ( "QPE/System", "busy()" ); |
519 | #endif | 599 | #endif |
520 | 600 | ||
521 | #ifdef HAVE_QUICKEXEC | 601 | #ifdef HAVE_QUICKEXEC |
522 | QString libexe = qpeDir()+"/binlib/lib"+args[0] + ".so"; | 602 | QString libexe = qpeDir()+"/binlib/lib"+args[0] + ".so"; |
523 | qDebug("libfile = %s", libexe.latin1() ); | 603 | qDebug("libfile = %s", libexe.latin1() ); |
524 | if ( QFile::exists( libexe ) ) { | 604 | if ( QFile::exists( libexe ) ) { |
525 | qDebug("calling quickexec %s", libexe.latin1() ); | 605 | qDebug("calling quickexec %s", libexe.latin1() ); |
526 | quickexecv( libexe.utf8().data(), (const char **)args ); | 606 | quickexecv( libexe.utf8().data(), (const char **)args ); |
527 | } else | 607 | } else |
528 | #endif | 608 | #endif |
529 | { | 609 | { |
530 | if ( !::vfork() ) { | 610 | if ( !::vfork() ) { |
531 | for ( int fd = 3; fd < 100; fd++ ) | 611 | for ( int fd = 3; fd < 100; fd++ ) |
532 | ::close( fd ); | 612 | ::close( fd ); |
533 | ::setpgid( ::getpid(), ::getppid() ); | 613 | ::setpgid( ::getpid(), ::getppid() ); |
534 | // Try bindir first, so that foo/bar works too | 614 | // Try bindir first, so that foo/bar works too |
535 | ::execv( qpeDir()+"/bin/"+args[0], (char * const *)args ); | 615 | ::execv( qpeDir()+"/bin/"+args[0], (char * const *)args ); |
536 | ::execvp( args[0], (char * const *)args ); | 616 | ::execvp( args[0], (char * const *)args ); |
537 | _exit( -1 ); | 617 | _exit( -1 ); |
538 | } | 618 | } |
539 | } | 619 | } |
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 ) { |
553 | // ask the server to do the work | 635 | // ask the server to do the work |
554 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 636 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
555 | if ( document.isNull() ) { | 637 | if ( document.isNull() ) { |
556 | QCopEnvelope e( "QPE/System", "execute(QString)" ); | 638 | QCopEnvelope e( "QPE/System", "execute(QString)" ); |
557 | e << c; | 639 | e << c; |
558 | } else { | 640 | } else { |
559 | QCopEnvelope e( "QPE/System", "execute(QString,QString)" ); | 641 | QCopEnvelope e( "QPE/System", "execute(QString,QString)" ); |
560 | e << c << document; | 642 | e << c << document; |
561 | } | 643 | } |
562 | #endif | 644 | #endif |
563 | return; | 645 | return; |
564 | } | 646 | } |
565 | 647 | ||
566 | // Attempt to execute the app using a builtin class for the app first | 648 | // Attempt to execute the app using a builtin class for the app first |
567 | // else try and find it in the bin directory | 649 | // else try and find it in the bin directory |
568 | if (builtin) { | 650 | if (builtin) { |
569 | for (int i = 0; builtin[i].file; i++) { | 651 | for (int i = 0; builtin[i].file; i++) { |
570 | if ( builtin[i].file == c ) { | 652 | if ( builtin[i].file == c ) { |
571 | if ( running[i] ) { | 653 | if ( running[i] ) { |
572 | if ( !document.isNull() && builtin[i].documentary ) | 654 | if ( !document.isNull() && builtin[i].documentary ) |
573 | setDocument(running[i], document); | 655 | setDocument(running[i], document); |
574 | running[i]->raise(); | 656 | running[i]->raise(); |
575 | running[i]->show(); | 657 | running[i]->show(); |
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 | } |
586 | 670 | ||
587 | //Global::invoke(c, document); | 671 | //Global::invoke(c, document); |
588 | 672 | ||
589 | // Convert the command line in to a list of arguments | 673 | // Convert the command line in to a list of arguments |
590 | QStringList list = QStringList::split(QRegExp(" *"),c); | 674 | QStringList list = QStringList::split(QRegExp(" *"),c); |
591 | 675 | ||
592 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 676 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
593 | QString ap=list[0]; | 677 | QString ap=list[0]; |
594 | 678 | ||
595 | qDebug("executing %s", ap.latin1() ); | 679 | qDebug("executing %s", ap.latin1() ); |
596 | if ( ap == "suspend" ) { | 680 | if ( ap == "suspend" ) { |
597 | QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); | 681 | QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); |
598 | return; | 682 | return; |
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="\""; |
618 | for (int i=0; i<(int)s.length(); i++) { | 705 | for (int i=0; i<(int)s.length(); i++) { |
619 | char c = s[i].latin1(); | 706 | char c = s[i].latin1(); |
620 | switch (c) { | 707 | switch (c) { |
621 | case '\\': case '"': case '$': | 708 | case '\\': case '"': case '$': |
622 | r+="\\"; | 709 | r+="\\"; |
623 | } | 710 | } |
624 | r += s[i]; | 711 | r += s[i]; |
625 | } | 712 | } |
626 | r += "\""; | 713 | r += "\""; |
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="\""; |
637 | for (int i=0; i<(int)s.length(); i++) { | 726 | for (int i=0; i<(int)s.length(); i++) { |
638 | char c = s[i].latin1(); | 727 | char c = s[i].latin1(); |
639 | switch (c) { | 728 | switch (c) { |
640 | case '\\': case '"': | 729 | case '\\': case '"': |
641 | r+="\\"; | 730 | r+="\\"; |
642 | } | 731 | } |
643 | r += s[i]; | 732 | r += s[i]; |
644 | } | 733 | } |
645 | r += "\""; | 734 | r += "\""; |
646 | return r; | 735 | return r; |
647 | } | 736 | } |
648 | 737 | ||
649 | /*! | 738 | /*! |
650 | Finds all documents on the system's document directories which | 739 | Finds all documents on the system's document directories which |
651 | match the filter \a mimefilter, and appends the resulting DocLnk | 740 | match the filter \a mimefilter, and appends the resulting DocLnk |
652 | objects to \a folder. | 741 | objects to \a folder. |
653 | */ | 742 | */ |
654 | void Global::findDocuments(DocLnkSet* folder, const QString &mimefilter) | 743 | void Global::findDocuments(DocLnkSet* folder, const QString &mimefilter) |
655 | { | 744 | { |
656 | QString homedocs = QString(getenv("HOME")) + "/Documents"; | 745 | QString homedocs = QString(getenv("HOME")) + "/Documents"; |
657 | DocLnkSet d(homedocs,mimefilter); | 746 | DocLnkSet d(homedocs,mimefilter); |
658 | folder->appendFrom(d); | 747 | folder->appendFrom(d); |
659 | /** let's do intellegint way of searching these files | 748 | /** let's do intellegint way of searching these files |
660 | * a) the user don't want to check mediums global | 749 | * a) the user don't want to check mediums global |
661 | * b) the user wants to check but use the global options for it | 750 | * b) the user wants to check but use the global options for it |
662 | * c) the user wants to check it but not this medium | 751 | * c) the user wants to check it but not this medium |
663 | * d) the user wants to check and this medium as well | 752 | * d) the user wants to check and this medium as well |
664 | * | 753 | * |
665 | * In all cases we need to apply a different mimefilter to | 754 | * In all cases we need to apply a different mimefilter to |
666 | * the medium. | 755 | * the medium. |
667 | * a) mimefilter.isEmpty() we need to apply the responding filter | 756 | * a) mimefilter.isEmpty() we need to apply the responding filter |
668 | * either the global or the one on the medium | 757 | * either the global or the one on the medium |
669 | * | 758 | * |
670 | * b) mimefilter is set to an application we need to find out if the | 759 | * b) mimefilter is set to an application we need to find out if the |
671 | * mimetypes are included in the mime mask of the medium | 760 | * mimetypes are included in the mime mask of the medium |
672 | */ | 761 | */ |
673 | StorageInfo storage; | 762 | StorageInfo storage; |
674 | const QList<FileSystem> &fs = storage.fileSystems(); | 763 | const QList<FileSystem> &fs = storage.fileSystems(); |
675 | QListIterator<FileSystem> it ( fs ); | 764 | QListIterator<FileSystem> it ( fs ); |
676 | for ( ; it.current(); ++it ) { | 765 | for ( ; it.current(); ++it ) { |
677 | if ( (*it)->isRemovable() ) { // let's find out if we should search on it | 766 | if ( (*it)->isRemovable() ) { // let's find out if we should search on it |
678 | // this is a candidate look at the cf and see if we should search on it | 767 | // this is a candidate look at the cf and see if we should search on it |
679 | QString path = (*it)->path(); | 768 | QString path = (*it)->path(); |
680 | if( !checkStorage((*it)->path() + "/.opiestorage.cf" ) ) | 769 | if( !checkStorage((*it)->path() + "/.opiestorage.cf" ) ) |
681 | continue; | 770 | continue; |
682 | DocLnkSet ide( path, mimefilter ); | 771 | DocLnkSet ide( path, mimefilter ); |
683 | folder->appendFrom(ide); | 772 | folder->appendFrom(ide); |
684 | } else if ( (*it)->disk() == "/dev/mtdblock6" || (*it)->disk() == "tmpfs" ) { | 773 | } else if ( (*it)->disk() == "/dev/mtdblock6" || (*it)->disk() == "tmpfs" ) { |
685 | QString path = (*it)->path() + "/Documents"; | 774 | QString path = (*it)->path() + "/Documents"; |
686 | DocLnkSet ide( path, mimefilter ); | 775 | DocLnkSet ide( path, mimefilter ); |
687 | folder->appendFrom(ide); | 776 | folder->appendFrom(ide); |
688 | } | 777 | } |
689 | } | 778 | } |
690 | } | 779 | } |
691 | 780 | ||
692 | QStringList Global::languageList() | 781 | QStringList Global::languageList() |
693 | { | 782 | { |
694 | QString lang = getenv("LANG"); | 783 | QString lang = getenv("LANG"); |
695 | QStringList langs; | 784 | QStringList langs; |
696 | langs.append(lang); | 785 | langs.append(lang); |
697 | int i = lang.find("."); | 786 | int i = lang.find("."); |
698 | if ( i > 0 ) | 787 | if ( i > 0 ) |
699 | lang = lang.left( i ); | 788 | lang = lang.left( i ); |
700 | i = lang.find( "_" ); | 789 | i = lang.find( "_" ); |
701 | if ( i > 0 ) | 790 | if ( i > 0 ) |
702 | langs.append(lang.left(i)); | 791 | langs.append(lang.left(i)); |
703 | return langs; | 792 | return langs; |
704 | } | 793 | } |
705 | 794 | ||
706 | QStringList Global::helpPath() | 795 | QStringList Global::helpPath() |
707 | { | 796 | { |
708 | QStringList path; | 797 | QStringList path; |
709 | QStringList langs = Global::languageList(); | 798 | QStringList langs = Global::languageList(); |
710 | for (QStringList::ConstIterator it = langs.fromLast(); it!=langs.end(); --it) { | 799 | for (QStringList::ConstIterator it = langs.fromLast(); it!=langs.end(); --it) { |
711 | QString lang = *it; | 800 | QString lang = *it; |
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 | ||
730 | #include "global.moc" | 813 | #include "global.moc" |