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