-rw-r--r-- | library/global.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/library/global.cpp b/library/global.cpp index e1bbf3e..e5fc2b3 100644 --- a/library/global.cpp +++ b/library/global.cpp | |||
@@ -1,329 +1,329 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #include <qpe/qpedebug.h> | 20 | #include <qpe/qpedebug.h> |
21 | #include <qpe/global.h> | 21 | #include <qpe/global.h> |
22 | #include <qpe/qdawg.h> | 22 | #include <qpe/qdawg.h> |
23 | #include <qpe/qpeapplication.h> | 23 | #include <qpe/qpeapplication.h> |
24 | #include <qpe/resource.h> | 24 | #include <qpe/resource.h> |
25 | #include <qpe/storage.h> | 25 | #include <qpe/storage.h> |
26 | #include <qpe/applnk.h> | 26 | #include <qpe/applnk.h> |
27 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 27 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
28 | #include "qpe/qcopenvelope_qws.h" | 28 | #include "qpe/qcopenvelope_qws.h" |
29 | #endif | 29 | #endif |
30 | 30 | ||
31 | #include <qfile.h> | 31 | #include <qfile.h> |
32 | #include <qlabel.h> | 32 | #include <qlabel.h> |
33 | #include <qtimer.h> | 33 | #include <qtimer.h> |
34 | #include <qmap.h> | 34 | #include <qmap.h> |
35 | #include <qdict.h> | 35 | #include <qdict.h> |
36 | #include <qdir.h> | 36 | #include <qdir.h> |
37 | #include <qmessagebox.h> | 37 | #include <qmessagebox.h> |
38 | #include <qregexp.h> | 38 | #include <qregexp.h> |
39 | 39 | ||
40 | #include <stdlib.h> | 40 | #include <stdlib.h> |
41 | #include <sys/stat.h> | 41 | #include <sys/stat.h> |
42 | #include <sys/wait.h> | 42 | #include <sys/wait.h> |
43 | #include <sys/types.h> | 43 | #include <sys/types.h> |
44 | #include <fcntl.h> | 44 | #include <fcntl.h> |
45 | #include <unistd.h> | 45 | #include <unistd.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 "quickexec_p.h" | 50 | //#include "quickexec_p.h" |
51 | 51 | ||
52 | class Emitter : public QObject { | 52 | class Emitter : public QObject { |
53 | Q_OBJECT | 53 | Q_OBJECT |
54 | public: | 54 | public: |
55 | Emitter( QWidget* receiver, const QString& document ) | 55 | Emitter( QWidget* receiver, const QString& document ) |
56 | { | 56 | { |
57 | connect(this, SIGNAL(setDocument(const QString&)), | 57 | connect(this, SIGNAL(setDocument(const QString&)), |
58 | receiver, SLOT(setDocument(const QString&))); | 58 | receiver, SLOT(setDocument(const QString&))); |
59 | emit setDocument(document); | 59 | emit setDocument(document); |
60 | disconnect(this, SIGNAL(setDocument(const QString&)), | 60 | disconnect(this, SIGNAL(setDocument(const QString&)), |
61 | receiver, SLOT(setDocument(const QString&))); | 61 | receiver, SLOT(setDocument(const QString&))); |
62 | } | 62 | } |
63 | 63 | ||
64 | signals: | 64 | signals: |
65 | void setDocument(const QString&); | 65 | void setDocument(const QString&); |
66 | }; | 66 | }; |
67 | 67 | ||
68 | 68 | ||
69 | class StartingAppList : public QObject { | 69 | class StartingAppList : public QObject { |
70 | Q_OBJECT | 70 | Q_OBJECT |
71 | public: | 71 | public: |
72 | static void add( const QString& name ); | 72 | static void add( const QString& name ); |
73 | static bool isStarting( const QString name ); | 73 | static bool isStarting( const QString name ); |
74 | private slots: | 74 | private slots: |
75 | void handleNewChannel( const QString &); | 75 | void handleNewChannel( const QString &); |
76 | private: | 76 | private: |
77 | StartingAppList( QObject *parent=0, const char* name=0 ) ; | 77 | StartingAppList( QObject *parent=0, const char* name=0 ) ; |
78 | 78 | ||
79 | QDict<QTime> dict; | 79 | QDict<QTime> dict; |
80 | static StartingAppList *appl; | 80 | static StartingAppList *appl; |
81 | }; | 81 | }; |
82 | 82 | ||
83 | StartingAppList* StartingAppList::appl = 0; | 83 | StartingAppList* StartingAppList::appl = 0; |
84 | 84 | ||
85 | StartingAppList::StartingAppList( QObject *parent, const char* name ) | 85 | StartingAppList::StartingAppList( QObject *parent, const char* name ) |
86 | :QObject( parent, name ) | 86 | :QObject( parent, name ) |
87 | { | 87 | { |
88 | #if QT_VERSION >= 232 && !defined(QT_NO_COP) | 88 | #if QT_VERSION >= 232 && !defined(QT_NO_COP) |
89 | connect( qwsServer, SIGNAL( newChannel(const QString&)), | 89 | connect( qwsServer, SIGNAL( newChannel(const QString&)), |
90 | this, SLOT( handleNewChannel(const QString&)) ); | 90 | this, SLOT( handleNewChannel(const QString&)) ); |
91 | dict.setAutoDelete( TRUE ); | 91 | dict.setAutoDelete( TRUE ); |
92 | #endif | 92 | #endif |
93 | } | 93 | } |
94 | 94 | ||
95 | void StartingAppList::add( const QString& name ) | 95 | void StartingAppList::add( const QString& name ) |
96 | { | 96 | { |
97 | #if QT_VERSION >= 232 && !defined(QT_NO_COP) | 97 | #if QT_VERSION >= 232 && !defined(QT_NO_COP) |
98 | if ( !appl ) | 98 | if ( !appl ) |
99 | appl = new StartingAppList; | 99 | appl = new StartingAppList; |
100 | QTime *t = new QTime; | 100 | QTime *t = new QTime; |
101 | t->start(); | 101 | t->start(); |
102 | appl->dict.insert( "QPE/Application/" + name, t ); | 102 | appl->dict.insert( "QPE/Application/" + name, t ); |
103 | #endif | 103 | #endif |
104 | } | 104 | } |
105 | 105 | ||
106 | bool StartingAppList::isStarting( const QString name ) | 106 | bool StartingAppList::isStarting( const QString name ) |
107 | { | 107 | { |
108 | #if QT_VERSION >= 232 && !defined(QT_NO_COP) | 108 | #if QT_VERSION >= 232 && !defined(QT_NO_COP) |
109 | if ( appl ) { | 109 | if ( appl ) { |
110 | QTime *t = appl->dict.find( "QPE/Application/" + name ); | 110 | QTime *t = appl->dict.find( "QPE/Application/" + name ); |
111 | if ( !t ) | 111 | if ( !t ) |
112 | return FALSE; | 112 | return FALSE; |
113 | if ( t->elapsed() > 10000 ) { | 113 | if ( t->elapsed() > 10000 ) { |
114 | // timeout in case of crash or something | 114 | // timeout in case of crash or something |
115 | appl->dict.remove( "QPE/Application/" + name ); | 115 | appl->dict.remove( "QPE/Application/" + name ); |
116 | return FALSE; | 116 | return FALSE; |
117 | } | 117 | } |
118 | return TRUE; | 118 | return TRUE; |
119 | } | 119 | } |
120 | #endif | 120 | #endif |
121 | return FALSE; | 121 | return FALSE; |
122 | } | 122 | } |
123 | 123 | ||
124 | void StartingAppList::handleNewChannel( const QString & name ) | 124 | void StartingAppList::handleNewChannel( const QString & name ) |
125 | { | 125 | { |
126 | #if QT_VERSION >= 232 && !defined(QT_NO_COP) | 126 | #if QT_VERSION >= 232 && !defined(QT_NO_COP) |
127 | dict.remove( name ); | 127 | dict.remove( name ); |
128 | #endif | 128 | #endif |
129 | } | 129 | } |
130 | 130 | ||
131 | static bool docDirCreated = FALSE; | 131 | static bool docDirCreated = FALSE; |
132 | static QDawg* fixed_dawg = 0; | 132 | static QDawg* fixed_dawg = 0; |
133 | static QDict<QDawg> *named_dawg = 0; | 133 | static QDict<QDawg> *named_dawg = 0; |
134 | 134 | ||
135 | static QString qpeDir() | 135 | static QString qpeDir() |
136 | { | 136 | { |
137 | QString dir = getenv("QPEDIR"); | 137 | QString dir = getenv("OPIEDIR"); |
138 | if ( dir.isEmpty() ) dir = ".."; | 138 | if ( dir.isEmpty() ) dir = ".."; |
139 | return dir; | 139 | return dir; |
140 | } | 140 | } |
141 | 141 | ||
142 | static QString dictDir() | 142 | static QString dictDir() |
143 | { | 143 | { |
144 | return qpeDir() + "/etc/dict"; | 144 | return qpeDir() + "/etc/dict"; |
145 | } | 145 | } |
146 | 146 | ||
147 | /*! | 147 | /*! |
148 | \class Global global.h | 148 | \class Global global.h |
149 | \brief The Global class collects application-wide global functions. | 149 | \brief The Global class collects application-wide global functions. |
150 | */ | 150 | */ |
151 | 151 | ||
152 | /*! | 152 | /*! |
153 | \internal | 153 | \internal |
154 | */ | 154 | */ |
155 | Global::Global() | 155 | Global::Global() |
156 | { | 156 | { |
157 | } | 157 | } |
158 | 158 | ||
159 | /*! | 159 | /*! |
160 | Returns the unchangeable QDawg that contains general | 160 | Returns the unchangeable QDawg that contains general |
161 | words for the current locale. | 161 | words for the current locale. |
162 | 162 | ||
163 | \sa addedDawg() | 163 | \sa addedDawg() |
164 | */ | 164 | */ |
165 | const QDawg& Global::fixedDawg() | 165 | const QDawg& Global::fixedDawg() |
166 | { | 166 | { |
167 | if ( !fixed_dawg ) { | 167 | if ( !fixed_dawg ) { |
168 | if ( !docDirCreated ) | 168 | if ( !docDirCreated ) |
169 | createDocDir(); | 169 | createDocDir(); |
170 | 170 | ||
171 | fixed_dawg = new QDawg; | 171 | fixed_dawg = new QDawg; |
172 | QString dawgfilename = dictDir() + "/dawg"; | 172 | QString dawgfilename = dictDir() + "/dawg"; |
173 | QString lang = getenv( "LANG" ); | 173 | QString lang = getenv( "LANG" ); |
174 | QString dawgfilename_lang = dawgfilename + "." + lang; | 174 | QString dawgfilename_lang = dawgfilename + "." + lang; |
175 | QString words_lang = dictDir() + "/words." + lang; | 175 | QString words_lang = dictDir() + "/words." + lang; |
176 | if ( QFile::exists(dawgfilename_lang) || | 176 | if ( QFile::exists(dawgfilename_lang) || |
177 | QFile::exists(words_lang) ) | 177 | QFile::exists(words_lang) ) |
178 | dawgfilename = dawgfilename_lang; | 178 | dawgfilename = dawgfilename_lang; |
179 | QFile dawgfile(dawgfilename); | 179 | QFile dawgfile(dawgfilename); |
180 | 180 | ||
181 | if ( !dawgfile.exists() ) { | 181 | if ( !dawgfile.exists() ) { |
182 | QString fn = dictDir() + "/words"; | 182 | QString fn = dictDir() + "/words"; |
183 | if ( QFile::exists(words_lang) ) | 183 | if ( QFile::exists(words_lang) ) |
184 | fn = words_lang; | 184 | fn = words_lang; |
185 | QFile in(fn); | 185 | QFile in(fn); |
186 | if ( in.open(IO_ReadOnly) ) { | 186 | if ( in.open(IO_ReadOnly) ) { |
187 | fixed_dawg->createFromWords(&in); | 187 | fixed_dawg->createFromWords(&in); |
188 | dawgfile.open(IO_WriteOnly); | 188 | dawgfile.open(IO_WriteOnly); |
189 | fixed_dawg->write(&dawgfile); | 189 | fixed_dawg->write(&dawgfile); |
190 | dawgfile.close(); | 190 | dawgfile.close(); |
191 | } | 191 | } |
192 | } else { | 192 | } else { |
193 | fixed_dawg->readFile(dawgfilename); | 193 | fixed_dawg->readFile(dawgfilename); |
194 | } | 194 | } |
195 | } | 195 | } |
196 | 196 | ||
197 | return *fixed_dawg; | 197 | return *fixed_dawg; |
198 | } | 198 | } |
199 | 199 | ||
200 | /*! | 200 | /*! |
201 | Returns the changeable QDawg that contains general | 201 | Returns the changeable QDawg that contains general |
202 | words for the current locale. | 202 | words for the current locale. |
203 | 203 | ||
204 | \sa fixedDawg() | 204 | \sa fixedDawg() |
205 | */ | 205 | */ |
206 | const QDawg& Global::addedDawg() | 206 | const QDawg& Global::addedDawg() |
207 | { | 207 | { |
208 | return dawg("local"); | 208 | return dawg("local"); |
209 | } | 209 | } |
210 | 210 | ||
211 | /*! | 211 | /*! |
212 | Returns the QDawg with the given \a name. | 212 | Returns the QDawg with the given \a name. |
213 | This is an application-specific word list. | 213 | This is an application-specific word list. |
214 | 214 | ||
215 | \a name should not contain "/". | 215 | \a name should not contain "/". |
216 | */ | 216 | */ |
217 | const QDawg& Global::dawg(const QString& name) | 217 | const QDawg& Global::dawg(const QString& name) |
218 | { | 218 | { |
219 | createDocDir(); | 219 | createDocDir(); |
220 | if ( !named_dawg ) | 220 | if ( !named_dawg ) |
221 | named_dawg = new QDict<QDawg>; | 221 | named_dawg = new QDict<QDawg>; |
222 | QDawg* r = named_dawg->find(name); | 222 | QDawg* r = named_dawg->find(name); |
223 | if ( !r ) { | 223 | if ( !r ) { |
224 | r = new QDawg; | 224 | r = new QDawg; |
225 | named_dawg->insert(name,r); | 225 | named_dawg->insert(name,r); |
226 | QString dawgfilename = dictDir() + "/" + name + ".dawg"; | 226 | QString dawgfilename = dictDir() + "/" + name + ".dawg"; |
227 | QFile dawgfile(dawgfilename); | 227 | QFile dawgfile(dawgfilename); |
228 | if ( dawgfile.open(IO_ReadOnly) ) | 228 | if ( dawgfile.open(IO_ReadOnly) ) |
229 | r->readFile(dawgfilename); | 229 | r->readFile(dawgfilename); |
230 | } | 230 | } |
231 | return *r; | 231 | return *r; |
232 | } | 232 | } |
233 | 233 | ||
234 | /*! | 234 | /*! |
235 | Adds \a wordlist to the addedDawg(). | 235 | Adds \a wordlist to the addedDawg(). |
236 | */ | 236 | */ |
237 | void Global::addWords(const QStringList& wordlist) | 237 | void Global::addWords(const QStringList& wordlist) |
238 | { | 238 | { |
239 | addWords("local",wordlist); | 239 | addWords("local",wordlist); |
240 | } | 240 | } |
241 | 241 | ||
242 | /*! | 242 | /*! |
243 | Adds \a wordlist to the dawg() named \a dictname. | 243 | Adds \a wordlist to the dawg() named \a dictname. |
244 | */ | 244 | */ |
245 | void Global::addWords(const QString& dictname, const QStringList& wordlist) | 245 | void Global::addWords(const QString& dictname, const QStringList& wordlist) |
246 | { | 246 | { |
247 | QDawg& d = (QDawg&)dawg(dictname); | 247 | QDawg& d = (QDawg&)dawg(dictname); |
248 | QStringList all = d.allWords() + wordlist; | 248 | QStringList all = d.allWords() + wordlist; |
249 | d.createFromWords(all); | 249 | d.createFromWords(all); |
250 | 250 | ||
251 | QString dawgfilename = dictDir() + "/" + dictname + ".dawg"; | 251 | QString dawgfilename = dictDir() + "/" + dictname + ".dawg"; |
252 | QFile dawgfile(dawgfilename); | 252 | QFile dawgfile(dawgfilename); |
253 | if ( dawgfile.open(IO_WriteOnly) ) { | 253 | if ( dawgfile.open(IO_WriteOnly) ) { |
254 | d.write(&dawgfile); | 254 | d.write(&dawgfile); |
255 | dawgfile.close(); | 255 | dawgfile.close(); |
256 | } | 256 | } |
257 | 257 | ||
258 | // #### Re-read the dawg here if we use mmap(). | 258 | // #### Re-read the dawg here if we use mmap(). |
259 | 259 | ||
260 | // #### Signal other processes to re-read. | 260 | // #### Signal other processes to re-read. |
261 | } | 261 | } |
262 | 262 | ||
263 | 263 | ||
264 | /*! | 264 | /*! |
265 | Returns a full path for the application named \a appname, with the | 265 | Returns a full path for the application named \a appname, with the |
266 | given \a filename or QString::null if there was a problem creating | 266 | given \a filename or QString::null if there was a problem creating |
267 | the directory tree for \a appname. | 267 | the directory tree for \a appname. |
268 | If \a filename contains "/", it is the caller's responsibility to | 268 | If \a filename contains "/", it is the caller's responsibility to |
269 | ensure those directories exist. | 269 | ensure those directories exist. |
270 | */ | 270 | */ |
271 | QString Global::applicationFileName(const QString& appname, const QString& filename) | 271 | QString Global::applicationFileName(const QString& appname, const QString& filename) |
272 | { | 272 | { |
273 | QDir d; | 273 | QDir d; |
274 | QString r = getenv("HOME"); | 274 | QString r = getenv("HOME"); |
275 | r += "/Applications/"; | 275 | r += "/Applications/"; |
276 | if ( !QFile::exists( r ) ) | 276 | if ( !QFile::exists( r ) ) |
277 | if ( d.mkdir(r) == false ) | 277 | if ( d.mkdir(r) == false ) |
278 | return QString::null; | 278 | return QString::null; |
279 | r += appname; | 279 | r += appname; |
280 | if ( !QFile::exists( r ) ) | 280 | if ( !QFile::exists( r ) ) |
281 | if ( d.mkdir(r) == false ) | 281 | if ( d.mkdir(r) == false ) |
282 | return QString::null; | 282 | return QString::null; |
283 | r += "/"; r += filename; | 283 | r += "/"; r += filename; |
284 | return r; | 284 | return r; |
285 | } | 285 | } |
286 | 286 | ||
287 | /*! | 287 | /*! |
288 | \internal | 288 | \internal |
289 | */ | 289 | */ |
290 | void Global::createDocDir() | 290 | void Global::createDocDir() |
291 | { | 291 | { |
292 | if ( !docDirCreated ) { | 292 | if ( !docDirCreated ) { |
293 | docDirCreated = TRUE; | 293 | docDirCreated = TRUE; |
294 | mkdir( QPEApplication::documentDir().latin1(), 0755 ); | 294 | mkdir( QPEApplication::documentDir().latin1(), 0755 ); |
295 | } | 295 | } |
296 | } | 296 | } |
297 | 297 | ||
298 | 298 | ||
299 | /*! | 299 | /*! |
300 | Displays a status \a message to the user. This generally appears | 300 | Displays a status \a message to the user. This generally appears |
301 | in the taskbar for some amount of time, then disappears. | 301 | in the taskbar for some amount of time, then disappears. |
302 | */ | 302 | */ |
303 | void Global::statusMessage(const QString& message) | 303 | void Global::statusMessage(const QString& message) |
304 | { | 304 | { |
305 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 305 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
306 | QCopEnvelope e( "QPE/TaskBar", "message(QString)" ); | 306 | QCopEnvelope e( "QPE/TaskBar", "message(QString)" ); |
307 | e << message; | 307 | e << message; |
308 | #endif | 308 | #endif |
309 | } | 309 | } |
310 | 310 | ||
311 | /*! | 311 | /*! |
312 | \internal | 312 | \internal |
313 | */ | 313 | */ |
314 | void Global::applyStyle() | 314 | void Global::applyStyle() |
315 | { | 315 | { |
316 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 316 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
317 | QCopChannel::send( "QPE/System", "applyStyle()" ); | 317 | QCopChannel::send( "QPE/System", "applyStyle()" ); |
318 | #else | 318 | #else |
319 | ((QPEApplication *)qApp)->applyStyle(); // apply without needing QCop for floppy version | 319 | ((QPEApplication *)qApp)->applyStyle(); // apply without needing QCop for floppy version |
320 | #endif | 320 | #endif |
321 | } | 321 | } |
322 | 322 | ||
323 | /*! | 323 | /*! |
324 | \internal | 324 | \internal |
325 | */ | 325 | */ |
326 | QWidget *Global::shutdown( bool ) | 326 | QWidget *Global::shutdown( bool ) |
327 | { | 327 | { |
328 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 328 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
329 | QCopChannel::send( "QPE/System", "shutdown()" ); | 329 | QCopChannel::send( "QPE/System", "shutdown()" ); |