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