author | zecke <zecke> | 2002-04-22 16:57:17 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-04-22 16:57:17 (UTC) |
commit | cca7f8ae4f60ae9b6c704d200ab015233abdd4d7 (patch) (unidiff) | |
tree | c472d8d52bb27811f6400cb35a61f84e2387df71 /library | |
parent | ed0b3a5518e741c0991c659b6b9ec9984e1ff2a6 (diff) | |
download | opie-cca7f8ae4f60ae9b6c704d200ab015233abdd4d7.zip opie-cca7f8ae4f60ae9b6c704d200ab015233abdd4d7.tar.gz opie-cca7f8ae4f60ae9b6c704d200ab015233abdd4d7.tar.bz2 |
First fix for not finding files anymore.
I'm going to the movies and then I'll fix
the launcher case....
-rw-r--r-- | library/global.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/library/global.cpp b/library/global.cpp index 5a28595..4f1cc38 100644 --- a/library/global.cpp +++ b/library/global.cpp | |||
@@ -1,578 +1,578 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #define QTOPIA_INTERNAL_LANGLIST | 20 | #define QTOPIA_INTERNAL_LANGLIST |
21 | #include <qpe/qpedebug.h> | 21 | #include <qpe/qpedebug.h> |
22 | #include <qpe/global.h> | 22 | #include <qpe/global.h> |
23 | #include <qpe/qdawg.h> | 23 | #include <qpe/qdawg.h> |
24 | #include <qpe/qpeapplication.h> | 24 | #include <qpe/qpeapplication.h> |
25 | #include <qpe/resource.h> | 25 | #include <qpe/resource.h> |
26 | #include <qpe/storage.h> | 26 | #include <qpe/storage.h> |
27 | #include <qpe/applnk.h> | 27 | #include <qpe/applnk.h> |
28 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 28 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
29 | #include "qpe/qcopenvelope_qws.h" | 29 | #include "qpe/qcopenvelope_qws.h" |
30 | #endif | 30 | #endif |
31 | 31 | ||
32 | #include <qfile.h> | 32 | #include <qfile.h> |
33 | #include <qlabel.h> | 33 | #include <qlabel.h> |
34 | #include <qtimer.h> | 34 | #include <qtimer.h> |
35 | #include <qmap.h> | 35 | #include <qmap.h> |
36 | #include <qdict.h> | 36 | #include <qdict.h> |
37 | #include <qdir.h> | 37 | #include <qdir.h> |
38 | #include <qmessagebox.h> | 38 | #include <qmessagebox.h> |
39 | #include <qregexp.h> | 39 | #include <qregexp.h> |
40 | 40 | ||
41 | #include <stdlib.h> | 41 | #include <stdlib.h> |
42 | #include <sys/stat.h> | 42 | #include <sys/stat.h> |
43 | #include <sys/wait.h> | 43 | #include <sys/wait.h> |
44 | #include <sys/types.h> | 44 | #include <sys/types.h> |
45 | #include <fcntl.h> | 45 | #include <fcntl.h> |
46 | #include <unistd.h> | 46 | #include <unistd.h> |
47 | 47 | ||
48 | #include <qwindowsystem_qws.h> // for qwsServer | 48 | #include <qwindowsystem_qws.h> // for qwsServer |
49 | #include <qdatetime.h> | 49 | #include <qdatetime.h> |
50 | 50 | ||
51 | #include <qfile.h> | 51 | #include <qfile.h> |
52 | 52 | ||
53 | namespace { | 53 | namespace { |
54 | // checks if the storage should be searched | 54 | // checks if the storage should be searched |
55 | bool checkStorage(const QString &path ){ // this is a small Config replacement cause config is too limited -zecke | 55 | bool checkStorage(const QString &path ){ // this is a small Config replacement cause config is too limited -zecke |
56 | QFile file(path ); | 56 | QFile file(path ); |
57 | if(!file.open(IO_ReadOnly ) ) | 57 | if(!file.open(IO_ReadOnly ) ) |
58 | return true; | 58 | return true; |
59 | 59 | ||
60 | QByteArray array = file.readAll(); | 60 | QByteArray array = file.readAll(); |
61 | QStringList list = QStringList::split('\n', QString( array ) ); | 61 | QStringList list = QStringList::split('\n', QString( array ) ); |
62 | for(QStringList::Iterator it = list.begin(); it != list.end(); ++it ){ | 62 | for(QStringList::Iterator it = list.begin(); it != list.end(); ++it ){ |
63 | if( (*it).startsWith("autocheck = 0" ) ){ | 63 | if( (*it).startsWith("autocheck = 0" ) ){ |
64 | return true; | ||
65 | }else if( (*it).startsWith("autocheck = 1" ) ){ | ||
66 | return false; | 64 | return false; |
65 | }else if( (*it).startsWith("autocheck = 1" ) ){ | ||
66 | return true; | ||
67 | } | 67 | } |
68 | } | 68 | } |
69 | return true; | 69 | return true; |
70 | } | 70 | } |
71 | } | 71 | } |
72 | 72 | ||
73 | //#include "quickexec_p.h" | 73 | //#include "quickexec_p.h" |
74 | 74 | ||
75 | class Emitter : public QObject { | 75 | class Emitter : public QObject { |
76 | Q_OBJECT | 76 | Q_OBJECT |
77 | public: | 77 | public: |
78 | Emitter( QWidget* receiver, const QString& document ) | 78 | Emitter( QWidget* receiver, const QString& document ) |
79 | { | 79 | { |
80 | connect(this, SIGNAL(setDocument(const QString&)), | 80 | connect(this, SIGNAL(setDocument(const QString&)), |
81 | receiver, SLOT(setDocument(const QString&))); | 81 | receiver, SLOT(setDocument(const QString&))); |
82 | emit setDocument(document); | 82 | emit setDocument(document); |
83 | disconnect(this, SIGNAL(setDocument(const QString&)), | 83 | disconnect(this, SIGNAL(setDocument(const QString&)), |
84 | receiver, SLOT(setDocument(const QString&))); | 84 | receiver, SLOT(setDocument(const QString&))); |
85 | } | 85 | } |
86 | 86 | ||
87 | signals: | 87 | signals: |
88 | void setDocument(const QString&); | 88 | void setDocument(const QString&); |
89 | }; | 89 | }; |
90 | 90 | ||
91 | 91 | ||
92 | class StartingAppList : public QObject { | 92 | class StartingAppList : public QObject { |
93 | Q_OBJECT | 93 | Q_OBJECT |
94 | public: | 94 | public: |
95 | static void add( const QString& name ); | 95 | static void add( const QString& name ); |
96 | static bool isStarting( const QString name ); | 96 | static bool isStarting( const QString name ); |
97 | private slots: | 97 | private slots: |
98 | void handleNewChannel( const QString &); | 98 | void handleNewChannel( const QString &); |
99 | private: | 99 | private: |
100 | StartingAppList( QObject *parent=0, const char* name=0 ) ; | 100 | StartingAppList( QObject *parent=0, const char* name=0 ) ; |
101 | 101 | ||
102 | QDict<QTime> dict; | 102 | QDict<QTime> dict; |
103 | static StartingAppList *appl; | 103 | static StartingAppList *appl; |
104 | }; | 104 | }; |
105 | 105 | ||
106 | StartingAppList* StartingAppList::appl = 0; | 106 | StartingAppList* StartingAppList::appl = 0; |
107 | 107 | ||
108 | StartingAppList::StartingAppList( QObject *parent, const char* name ) | 108 | StartingAppList::StartingAppList( QObject *parent, const char* name ) |
109 | :QObject( parent, name ) | 109 | :QObject( parent, name ) |
110 | { | 110 | { |
111 | #if QT_VERSION >= 232 && !defined(QT_NO_COP) | 111 | #if QT_VERSION >= 232 && !defined(QT_NO_COP) |
112 | connect( qwsServer, SIGNAL( newChannel(const QString&)), | 112 | connect( qwsServer, SIGNAL( newChannel(const QString&)), |
113 | this, SLOT( handleNewChannel(const QString&)) ); | 113 | this, SLOT( handleNewChannel(const QString&)) ); |
114 | dict.setAutoDelete( TRUE ); | 114 | dict.setAutoDelete( TRUE ); |
115 | #endif | 115 | #endif |
116 | } | 116 | } |
117 | 117 | ||
118 | void StartingAppList::add( const QString& name ) | 118 | void StartingAppList::add( const QString& name ) |
119 | { | 119 | { |
120 | #if QT_VERSION >= 232 && !defined(QT_NO_COP) | 120 | #if QT_VERSION >= 232 && !defined(QT_NO_COP) |
121 | if ( !appl ) | 121 | if ( !appl ) |
122 | appl = new StartingAppList; | 122 | appl = new StartingAppList; |
123 | QTime *t = new QTime; | 123 | QTime *t = new QTime; |
124 | t->start(); | 124 | t->start(); |
125 | appl->dict.insert( "QPE/Application/" + name, t ); | 125 | appl->dict.insert( "QPE/Application/" + name, t ); |
126 | #endif | 126 | #endif |
127 | } | 127 | } |
128 | 128 | ||
129 | bool StartingAppList::isStarting( const QString name ) | 129 | bool StartingAppList::isStarting( const QString name ) |
130 | { | 130 | { |
131 | #if QT_VERSION >= 232 && !defined(QT_NO_COP) | 131 | #if QT_VERSION >= 232 && !defined(QT_NO_COP) |
132 | if ( appl ) { | 132 | if ( appl ) { |
133 | QTime *t = appl->dict.find( "QPE/Application/" + name ); | 133 | QTime *t = appl->dict.find( "QPE/Application/" + name ); |
134 | if ( !t ) | 134 | if ( !t ) |
135 | return FALSE; | 135 | return FALSE; |
136 | if ( t->elapsed() > 10000 ) { | 136 | if ( t->elapsed() > 10000 ) { |
137 | // timeout in case of crash or something | 137 | // timeout in case of crash or something |
138 | appl->dict.remove( "QPE/Application/" + name ); | 138 | appl->dict.remove( "QPE/Application/" + name ); |
139 | return FALSE; | 139 | return FALSE; |
140 | } | 140 | } |
141 | return TRUE; | 141 | return TRUE; |
142 | } | 142 | } |
143 | #endif | 143 | #endif |
144 | return FALSE; | 144 | return FALSE; |
145 | } | 145 | } |
146 | 146 | ||
147 | void StartingAppList::handleNewChannel( const QString & name ) | 147 | void StartingAppList::handleNewChannel( const QString & name ) |
148 | { | 148 | { |
149 | #if QT_VERSION >= 232 && !defined(QT_NO_COP) | 149 | #if QT_VERSION >= 232 && !defined(QT_NO_COP) |
150 | dict.remove( name ); | 150 | dict.remove( name ); |
151 | #endif | 151 | #endif |
152 | } | 152 | } |
153 | 153 | ||
154 | static bool docDirCreated = FALSE; | 154 | static bool docDirCreated = FALSE; |
155 | static QDawg* fixed_dawg = 0; | 155 | static QDawg* fixed_dawg = 0; |
156 | static QDict<QDawg> *named_dawg = 0; | 156 | static QDict<QDawg> *named_dawg = 0; |
157 | 157 | ||
158 | static QString qpeDir() | 158 | static QString qpeDir() |
159 | { | 159 | { |
160 | QString dir = getenv("OPIEDIR"); | 160 | QString dir = getenv("OPIEDIR"); |
161 | if ( dir.isEmpty() ) dir = ".."; | 161 | if ( dir.isEmpty() ) dir = ".."; |
162 | return dir; | 162 | return dir; |
163 | } | 163 | } |
164 | 164 | ||
165 | static QString dictDir() | 165 | static QString dictDir() |
166 | { | 166 | { |
167 | return qpeDir() + "/etc/dict"; | 167 | return qpeDir() + "/etc/dict"; |
168 | } | 168 | } |
169 | 169 | ||
170 | /*! | 170 | /*! |
171 | \class Global global.h | 171 | \class Global global.h |
172 | \brief The Global class collects application-wide global functions. | 172 | \brief The Global class collects application-wide global functions. |
173 | */ | 173 | */ |
174 | 174 | ||
175 | /*! | 175 | /*! |
176 | \internal | 176 | \internal |
177 | */ | 177 | */ |
178 | Global::Global() | 178 | Global::Global() |
179 | { | 179 | { |
180 | } | 180 | } |
181 | 181 | ||
182 | /*! | 182 | /*! |
183 | Returns the unchangeable QDawg that contains general | 183 | Returns the unchangeable QDawg that contains general |
184 | words for the current locale. | 184 | words for the current locale. |
185 | 185 | ||
186 | \sa addedDawg() | 186 | \sa addedDawg() |
187 | */ | 187 | */ |
188 | const QDawg& Global::fixedDawg() | 188 | const QDawg& Global::fixedDawg() |
189 | { | 189 | { |
190 | if ( !fixed_dawg ) { | 190 | if ( !fixed_dawg ) { |
191 | if ( !docDirCreated ) | 191 | if ( !docDirCreated ) |
192 | createDocDir(); | 192 | createDocDir(); |
193 | 193 | ||
194 | fixed_dawg = new QDawg; | 194 | fixed_dawg = new QDawg; |
195 | QString dawgfilename = dictDir() + "/dawg"; | 195 | QString dawgfilename = dictDir() + "/dawg"; |
196 | QString words_lang; | 196 | QString words_lang; |
197 | QStringList langs = Global::languageList(); | 197 | QStringList langs = Global::languageList(); |
198 | for (QStringList::ConstIterator it = langs.begin(); it!=langs.end(); ++it) { | 198 | for (QStringList::ConstIterator it = langs.begin(); it!=langs.end(); ++it) { |
199 | QString lang = *it; | 199 | QString lang = *it; |
200 | words_lang = dictDir() + "/words." + lang; | 200 | words_lang = dictDir() + "/words." + lang; |
201 | QString dawgfilename_lang = dawgfilename + "." + lang; | 201 | QString dawgfilename_lang = dawgfilename + "." + lang; |
202 | if ( QFile::exists(dawgfilename_lang) || | 202 | if ( QFile::exists(dawgfilename_lang) || |
203 | QFile::exists(words_lang) ) { | 203 | QFile::exists(words_lang) ) { |
204 | dawgfilename = dawgfilename_lang; | 204 | dawgfilename = dawgfilename_lang; |
205 | break; | 205 | break; |
206 | } | 206 | } |
207 | } | 207 | } |
208 | QFile dawgfile(dawgfilename); | 208 | QFile dawgfile(dawgfilename); |
209 | 209 | ||
210 | if ( !dawgfile.exists() ) { | 210 | if ( !dawgfile.exists() ) { |
211 | QString fn = dictDir() + "/words"; | 211 | QString fn = dictDir() + "/words"; |
212 | if ( QFile::exists(words_lang) ) | 212 | if ( QFile::exists(words_lang) ) |
213 | fn = words_lang; | 213 | fn = words_lang; |
214 | QFile in(fn); | 214 | QFile in(fn); |
215 | if ( in.open(IO_ReadOnly) ) { | 215 | if ( in.open(IO_ReadOnly) ) { |
216 | fixed_dawg->createFromWords(&in); | 216 | fixed_dawg->createFromWords(&in); |
217 | dawgfile.open(IO_WriteOnly); | 217 | dawgfile.open(IO_WriteOnly); |
218 | fixed_dawg->write(&dawgfile); | 218 | fixed_dawg->write(&dawgfile); |
219 | dawgfile.close(); | 219 | dawgfile.close(); |
220 | } | 220 | } |
221 | } else { | 221 | } else { |
222 | fixed_dawg->readFile(dawgfilename); | 222 | fixed_dawg->readFile(dawgfilename); |
223 | } | 223 | } |
224 | } | 224 | } |
225 | 225 | ||
226 | return *fixed_dawg; | 226 | return *fixed_dawg; |
227 | } | 227 | } |
228 | 228 | ||
229 | /*! | 229 | /*! |
230 | Returns the changeable QDawg that contains general | 230 | Returns the changeable QDawg that contains general |
231 | words for the current locale. | 231 | words for the current locale. |
232 | 232 | ||
233 | \sa fixedDawg() | 233 | \sa fixedDawg() |
234 | */ | 234 | */ |
235 | const QDawg& Global::addedDawg() | 235 | const QDawg& Global::addedDawg() |
236 | { | 236 | { |
237 | return dawg("local"); | 237 | return dawg("local"); |
238 | } | 238 | } |
239 | 239 | ||
240 | /*! | 240 | /*! |
241 | Returns the QDawg with the given \a name. | 241 | Returns the QDawg with the given \a name. |
242 | This is an application-specific word list. | 242 | This is an application-specific word list. |
243 | 243 | ||
244 | \a name should not contain "/". | 244 | \a name should not contain "/". |
245 | */ | 245 | */ |
246 | const QDawg& Global::dawg(const QString& name) | 246 | const QDawg& Global::dawg(const QString& name) |
247 | { | 247 | { |
248 | createDocDir(); | 248 | createDocDir(); |
249 | if ( !named_dawg ) | 249 | if ( !named_dawg ) |
250 | named_dawg = new QDict<QDawg>; | 250 | named_dawg = new QDict<QDawg>; |
251 | QDawg* r = named_dawg->find(name); | 251 | QDawg* r = named_dawg->find(name); |
252 | if ( !r ) { | 252 | if ( !r ) { |
253 | r = new QDawg; | 253 | r = new QDawg; |
254 | named_dawg->insert(name,r); | 254 | named_dawg->insert(name,r); |
255 | QString dawgfilename = dictDir() + "/" + name + ".dawg"; | 255 | QString dawgfilename = dictDir() + "/" + name + ".dawg"; |
256 | QFile dawgfile(dawgfilename); | 256 | QFile dawgfile(dawgfilename); |
257 | if ( dawgfile.open(IO_ReadOnly) ) | 257 | if ( dawgfile.open(IO_ReadOnly) ) |
258 | r->readFile(dawgfilename); | 258 | r->readFile(dawgfilename); |
259 | } | 259 | } |
260 | return *r; | 260 | return *r; |
261 | } | 261 | } |
262 | 262 | ||
263 | /*! | 263 | /*! |
264 | Adds \a wordlist to the addedDawg(). | 264 | Adds \a wordlist to the addedDawg(). |
265 | */ | 265 | */ |
266 | void Global::addWords(const QStringList& wordlist) | 266 | void Global::addWords(const QStringList& wordlist) |
267 | { | 267 | { |
268 | addWords("local",wordlist); | 268 | addWords("local",wordlist); |
269 | } | 269 | } |
270 | 270 | ||
271 | /*! | 271 | /*! |
272 | Adds \a wordlist to the dawg() named \a dictname. | 272 | Adds \a wordlist to the dawg() named \a dictname. |
273 | */ | 273 | */ |
274 | void Global::addWords(const QString& dictname, const QStringList& wordlist) | 274 | void Global::addWords(const QString& dictname, const QStringList& wordlist) |
275 | { | 275 | { |
276 | QDawg& d = (QDawg&)dawg(dictname); | 276 | QDawg& d = (QDawg&)dawg(dictname); |
277 | QStringList all = d.allWords() + wordlist; | 277 | QStringList all = d.allWords() + wordlist; |
278 | d.createFromWords(all); | 278 | d.createFromWords(all); |
279 | 279 | ||
280 | QString dawgfilename = dictDir() + "/" + dictname + ".dawg"; | 280 | QString dawgfilename = dictDir() + "/" + dictname + ".dawg"; |
281 | QFile dawgfile(dawgfilename); | 281 | QFile dawgfile(dawgfilename); |
282 | if ( dawgfile.open(IO_WriteOnly) ) { | 282 | if ( dawgfile.open(IO_WriteOnly) ) { |
283 | d.write(&dawgfile); | 283 | d.write(&dawgfile); |
284 | dawgfile.close(); | 284 | dawgfile.close(); |
285 | } | 285 | } |
286 | 286 | ||
287 | // #### Re-read the dawg here if we use mmap(). | 287 | // #### Re-read the dawg here if we use mmap(). |
288 | 288 | ||
289 | // #### Signal other processes to re-read. | 289 | // #### Signal other processes to re-read. |
290 | } | 290 | } |
291 | 291 | ||
292 | 292 | ||
293 | /*! | 293 | /*! |
294 | Returns a full path for the application named \a appname, with the | 294 | Returns a full path for the application named \a appname, with the |
295 | given \a filename or QString::null if there was a problem creating | 295 | given \a filename or QString::null if there was a problem creating |
296 | the directory tree for \a appname. | 296 | the directory tree for \a appname. |
297 | If \a filename contains "/", it is the caller's responsibility to | 297 | If \a filename contains "/", it is the caller's responsibility to |
298 | ensure those directories exist. | 298 | ensure those directories exist. |
299 | */ | 299 | */ |
300 | QString Global::applicationFileName(const QString& appname, const QString& filename) | 300 | QString Global::applicationFileName(const QString& appname, const QString& filename) |
301 | { | 301 | { |
302 | QDir d; | 302 | QDir d; |
303 | QString r = getenv("HOME"); | 303 | QString r = getenv("HOME"); |
304 | r += "/Applications/"; | 304 | r += "/Applications/"; |
305 | if ( !QFile::exists( r ) ) | 305 | if ( !QFile::exists( r ) ) |
306 | if ( d.mkdir(r) == false ) | 306 | if ( d.mkdir(r) == false ) |
307 | return QString::null; | 307 | return QString::null; |
308 | r += appname; | 308 | r += appname; |
309 | if ( !QFile::exists( r ) ) | 309 | if ( !QFile::exists( r ) ) |
310 | if ( d.mkdir(r) == false ) | 310 | if ( d.mkdir(r) == false ) |
311 | return QString::null; | 311 | return QString::null; |
312 | r += "/"; r += filename; | 312 | r += "/"; r += filename; |
313 | return r; | 313 | return r; |
314 | } | 314 | } |
315 | 315 | ||
316 | /*! | 316 | /*! |
317 | \internal | 317 | \internal |
318 | */ | 318 | */ |
319 | void Global::createDocDir() | 319 | void Global::createDocDir() |
320 | { | 320 | { |
321 | if ( !docDirCreated ) { | 321 | if ( !docDirCreated ) { |
322 | docDirCreated = TRUE; | 322 | docDirCreated = TRUE; |
323 | mkdir( QPEApplication::documentDir().latin1(), 0755 ); | 323 | mkdir( QPEApplication::documentDir().latin1(), 0755 ); |
324 | } | 324 | } |
325 | } | 325 | } |
326 | 326 | ||
327 | 327 | ||
328 | /*! | 328 | /*! |
329 | Displays a status \a message to the user. This generally appears | 329 | Displays a status \a message to the user. This generally appears |
330 | in the taskbar for some amount of time, then disappears. | 330 | in the taskbar for some amount of time, then disappears. |
331 | */ | 331 | */ |
332 | void Global::statusMessage(const QString& message) | 332 | void Global::statusMessage(const QString& message) |
333 | { | 333 | { |
334 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 334 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
335 | QCopEnvelope e( "QPE/TaskBar", "message(QString)" ); | 335 | QCopEnvelope e( "QPE/TaskBar", "message(QString)" ); |
336 | e << message; | 336 | e << message; |
337 | #endif | 337 | #endif |
338 | } | 338 | } |
339 | 339 | ||
340 | /*! | 340 | /*! |
341 | \internal | 341 | \internal |
342 | */ | 342 | */ |
343 | void Global::applyStyle() | 343 | void Global::applyStyle() |
344 | { | 344 | { |
345 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 345 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
346 | QCopChannel::send( "QPE/System", "applyStyle()" ); | 346 | QCopChannel::send( "QPE/System", "applyStyle()" ); |
347 | #else | 347 | #else |
348 | ((QPEApplication *)qApp)->applyStyle(); // apply without needing QCop for floppy version | 348 | ((QPEApplication *)qApp)->applyStyle(); // apply without needing QCop for floppy version |
349 | #endif | 349 | #endif |
350 | } | 350 | } |
351 | 351 | ||
352 | /*! | 352 | /*! |
353 | \internal | 353 | \internal |
354 | */ | 354 | */ |
355 | QWidget *Global::shutdown( bool ) | 355 | QWidget *Global::shutdown( bool ) |
356 | { | 356 | { |
357 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 357 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
358 | QCopChannel::send( "QPE/System", "shutdown()" ); | 358 | QCopChannel::send( "QPE/System", "shutdown()" ); |
359 | #endif | 359 | #endif |
360 | return 0; | 360 | return 0; |
361 | } | 361 | } |
362 | 362 | ||
363 | /*! | 363 | /*! |
364 | \internal | 364 | \internal |
365 | */ | 365 | */ |
366 | QWidget *Global::restart( bool ) | 366 | QWidget *Global::restart( bool ) |
367 | { | 367 | { |
368 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 368 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
369 | QCopChannel::send( "QPE/System", "restart()" ); | 369 | QCopChannel::send( "QPE/System", "restart()" ); |
370 | #endif | 370 | #endif |
371 | return 0; | 371 | return 0; |
372 | } | 372 | } |
373 | 373 | ||
374 | /*! | 374 | /*! |
375 | Explicitly show the current input method. | 375 | Explicitly show the current input method. |
376 | */ | 376 | */ |
377 | void Global::showInputMethod() | 377 | void Global::showInputMethod() |
378 | { | 378 | { |
379 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 379 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
380 | QCopChannel::send( "QPE/TaskBar", "showInputMethod()" ); | 380 | QCopChannel::send( "QPE/TaskBar", "showInputMethod()" ); |
381 | #endif | 381 | #endif |
382 | } | 382 | } |
383 | 383 | ||
384 | /*! | 384 | /*! |
385 | Explicitly hide the current input method. | 385 | Explicitly hide the current input method. |
386 | */ | 386 | */ |
387 | void Global::hideInputMethod() | 387 | void Global::hideInputMethod() |
388 | { | 388 | { |
389 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 389 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
390 | QCopChannel::send( "QPE/TaskBar", "hideInputMethod()" ); | 390 | QCopChannel::send( "QPE/TaskBar", "hideInputMethod()" ); |
391 | #endif | 391 | #endif |
392 | } | 392 | } |
393 | 393 | ||
394 | 394 | ||
395 | /*! | 395 | /*! |
396 | \internal | 396 | \internal |
397 | */ | 397 | */ |
398 | bool Global::isBuiltinCommand( const QString &name ) | 398 | bool Global::isBuiltinCommand( const QString &name ) |
399 | { | 399 | { |
400 | if(!builtin) | 400 | if(!builtin) |
401 | return FALSE; // yes, it can happen | 401 | return FALSE; // yes, it can happen |
402 | for (int i = 0; builtin[i].file; i++) { | 402 | for (int i = 0; builtin[i].file; i++) { |
403 | if ( builtin[i].file == name ) { | 403 | if ( builtin[i].file == name ) { |
404 | return TRUE; | 404 | return TRUE; |
405 | } | 405 | } |
406 | } | 406 | } |
407 | return FALSE; | 407 | return FALSE; |
408 | } | 408 | } |
409 | 409 | ||
410 | Global::Command* Global::builtin=0; | 410 | Global::Command* Global::builtin=0; |
411 | QGuardedPtr<QWidget> *Global::running=0; | 411 | QGuardedPtr<QWidget> *Global::running=0; |
412 | 412 | ||
413 | /*! | 413 | /*! |
414 | \class Global::Command | 414 | \class Global::Command |
415 | \brief The Global::Command class is internal. | 415 | \brief The Global::Command class is internal. |
416 | \internal | 416 | \internal |
417 | */ | 417 | */ |
418 | 418 | ||
419 | /*! | 419 | /*! |
420 | \internal | 420 | \internal |
421 | */ | 421 | */ |
422 | void Global::setBuiltinCommands( Command* list ) | 422 | void Global::setBuiltinCommands( Command* list ) |
423 | { | 423 | { |
424 | if ( running ) | 424 | if ( running ) |
425 | delete [] running; | 425 | delete [] running; |
426 | 426 | ||
427 | builtin = list; | 427 | builtin = list; |
428 | int count = 0; | 428 | int count = 0; |
429 | if (!builtin) | 429 | if (!builtin) |
430 | return; | 430 | return; |
431 | while ( builtin[count].file ) | 431 | while ( builtin[count].file ) |
432 | count++; | 432 | count++; |
433 | 433 | ||
434 | running = new QGuardedPtr<QWidget> [ count ]; | 434 | running = new QGuardedPtr<QWidget> [ count ]; |
435 | } | 435 | } |
436 | 436 | ||
437 | /*! | 437 | /*! |
438 | \internal | 438 | \internal |
439 | */ | 439 | */ |
440 | void Global::setDocument( QWidget* receiver, const QString& document ) | 440 | void Global::setDocument( QWidget* receiver, const QString& document ) |
441 | { | 441 | { |
442 | Emitter emitter(receiver,document); | 442 | Emitter emitter(receiver,document); |
443 | } | 443 | } |
444 | 444 | ||
445 | /*! | 445 | /*! |
446 | \internal | 446 | \internal |
447 | */ | 447 | */ |
448 | bool Global::terminateBuiltin( const QString& n ) | 448 | bool Global::terminateBuiltin( const QString& n ) |
449 | { | 449 | { |
450 | if (!builtin) | 450 | if (!builtin) |
451 | return FALSE; | 451 | return FALSE; |
452 | for (int i = 0; builtin[i].file; i++) { | 452 | for (int i = 0; builtin[i].file; i++) { |
453 | if ( builtin[i].file == n ) { | 453 | if ( builtin[i].file == n ) { |
454 | delete running[i]; | 454 | delete running[i]; |
455 | return TRUE; | 455 | return TRUE; |
456 | } | 456 | } |
457 | } | 457 | } |
458 | return FALSE; | 458 | return FALSE; |
459 | } | 459 | } |
460 | 460 | ||
461 | /*! | 461 | /*! |
462 | \internal | 462 | \internal |
463 | */ | 463 | */ |
464 | void Global::terminate( const AppLnk* app ) | 464 | void Global::terminate( const AppLnk* app ) |
465 | { | 465 | { |
466 | //if ( terminateBuiltin(app->exec()) ) return; // maybe? haven't tried this | 466 | //if ( terminateBuiltin(app->exec()) ) return; // maybe? haven't tried this |
467 | 467 | ||
468 | QCString channel = "QPE/Application/" + app->exec().utf8(); | 468 | QCString channel = "QPE/Application/" + app->exec().utf8(); |
469 | if ( QCopChannel::isRegistered(channel) ) { | 469 | if ( QCopChannel::isRegistered(channel) ) { |
470 | QCopEnvelope e(channel, "quit()"); | 470 | QCopEnvelope e(channel, "quit()"); |
471 | } | 471 | } |
472 | } | 472 | } |
473 | 473 | ||
474 | /*! | 474 | /*! |
475 | Low-level function to run command \a c. Not recommended. | 475 | Low-level function to run command \a c. Not recommended. |
476 | */ | 476 | */ |
477 | void Global::invoke(const QString &c) | 477 | void Global::invoke(const QString &c) |
478 | { | 478 | { |
479 | // Convert the command line in to a list of arguments | 479 | // Convert the command line in to a list of arguments |
480 | QStringList list = QStringList::split(QRegExp(" *"),c); | 480 | QStringList list = QStringList::split(QRegExp(" *"),c); |
481 | 481 | ||
482 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 482 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
483 | QString ap=list[0]; | 483 | QString ap=list[0]; |
484 | // see if the application is already running | 484 | // see if the application is already running |
485 | // XXX should lock file /tmp/qcop-msg-ap | 485 | // XXX should lock file /tmp/qcop-msg-ap |
486 | if ( QCopChannel::isRegistered( ("QPE/Application/" + ap).latin1() ) ) { | 486 | if ( QCopChannel::isRegistered( ("QPE/Application/" + ap).latin1() ) ) { |
487 | QCopEnvelope e("QPE/System", "notBusy(QString)" ); | 487 | QCopEnvelope e("QPE/System", "notBusy(QString)" ); |
488 | e << ap; | 488 | e << ap; |
489 | return; | 489 | return; |
490 | } | 490 | } |
491 | // XXX should unlock file /tmp/qcop-msg-ap | 491 | // XXX should unlock file /tmp/qcop-msg-ap |
492 | //see if it is being started | 492 | //see if it is being started |
493 | if ( StartingAppList::isStarting( ap ) ) { | 493 | if ( StartingAppList::isStarting( ap ) ) { |
494 | QCopEnvelope e("QPE/System", "notBusy(QString)" ); | 494 | QCopEnvelope e("QPE/System", "notBusy(QString)" ); |
495 | e << ap; | 495 | e << ap; |
496 | return; | 496 | return; |
497 | } | 497 | } |
498 | 498 | ||
499 | #endif | 499 | #endif |
500 | 500 | ||
501 | #ifdef QT_NO_QWS_MULTIPROCESS | 501 | #ifdef QT_NO_QWS_MULTIPROCESS |
502 | QMessageBox::warning( 0, "Error", "Could not find the application " + c, "Ok", 0, 0, 0, 1 ); | 502 | QMessageBox::warning( 0, "Error", "Could not find the application " + c, "Ok", 0, 0, 0, 1 ); |
503 | #else | 503 | #else |
504 | 504 | ||
505 | QStrList slist; | 505 | QStrList slist; |
506 | unsigned int j; | 506 | unsigned int j; |
507 | for ( j = 0; j < list.count(); j++ ) | 507 | for ( j = 0; j < list.count(); j++ ) |
508 | slist.append( list[j].utf8() ); | 508 | slist.append( list[j].utf8() ); |
509 | 509 | ||
510 | const char **args = new (const char *)[slist.count() + 1]; | 510 | const char **args = new (const char *)[slist.count() + 1]; |
511 | for ( j = 0; j < slist.count(); j++ ) | 511 | for ( j = 0; j < slist.count(); j++ ) |
512 | args[j] = slist.at(j); | 512 | args[j] = slist.at(j); |
513 | args[j] = NULL; | 513 | args[j] = NULL; |
514 | 514 | ||
515 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 515 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
516 | // an attempt to show a wait... | 516 | // an attempt to show a wait... |
517 | // more logic should be used, but this will be fine for the moment... | 517 | // more logic should be used, but this will be fine for the moment... |
518 | QCopEnvelope ( "QPE/System", "busy()" ); | 518 | QCopEnvelope ( "QPE/System", "busy()" ); |
519 | #endif | 519 | #endif |
520 | 520 | ||
521 | #ifdef HAVE_QUICKEXEC | 521 | #ifdef HAVE_QUICKEXEC |
522 | QString libexe = qpeDir()+"/binlib/lib"+args[0] + ".so"; | 522 | QString libexe = qpeDir()+"/binlib/lib"+args[0] + ".so"; |
523 | qDebug("libfile = %s", libexe.latin1() ); | 523 | qDebug("libfile = %s", libexe.latin1() ); |
524 | if ( QFile::exists( libexe ) ) { | 524 | if ( QFile::exists( libexe ) ) { |
525 | qDebug("calling quickexec %s", libexe.latin1() ); | 525 | qDebug("calling quickexec %s", libexe.latin1() ); |
526 | quickexecv( libexe.utf8().data(), (const char **)args ); | 526 | quickexecv( libexe.utf8().data(), (const char **)args ); |
527 | } else | 527 | } else |
528 | #endif | 528 | #endif |
529 | { | 529 | { |
530 | if ( !::vfork() ) { | 530 | if ( !::vfork() ) { |
531 | for ( int fd = 3; fd < 100; fd++ ) | 531 | for ( int fd = 3; fd < 100; fd++ ) |
532 | ::close( fd ); | 532 | ::close( fd ); |
533 | ::setpgid( ::getpid(), ::getppid() ); | 533 | ::setpgid( ::getpid(), ::getppid() ); |
534 | // Try bindir first, so that foo/bar works too | 534 | // Try bindir first, so that foo/bar works too |
535 | ::execv( qpeDir()+"/bin/"+args[0], (char * const *)args ); | 535 | ::execv( qpeDir()+"/bin/"+args[0], (char * const *)args ); |
536 | ::execvp( args[0], (char * const *)args ); | 536 | ::execvp( args[0], (char * const *)args ); |
537 | _exit( -1 ); | 537 | _exit( -1 ); |
538 | } | 538 | } |
539 | } | 539 | } |
540 | StartingAppList::add( list[0] ); | 540 | StartingAppList::add( list[0] ); |
541 | #endif //QT_NO_QWS_MULTIPROCESS | 541 | #endif //QT_NO_QWS_MULTIPROCESS |
542 | } | 542 | } |
543 | 543 | ||
544 | /*! | 544 | /*! |
545 | Executes application identfied by \a c, passing \a document. | 545 | Executes application identfied by \a c, passing \a document. |
546 | 546 | ||
547 | Note that you might be better off sending a QCop message to | 547 | Note that you might be better off sending a QCop message to |
548 | the application's QPE/Application/<i>appname</i> channel. | 548 | the application's QPE/Application/<i>appname</i> channel. |
549 | */ | 549 | */ |
550 | void Global::execute( const QString &c, const QString& document ) | 550 | void Global::execute( const QString &c, const QString& document ) |
551 | { | 551 | { |
552 | if ( qApp->type() != QApplication::GuiServer ) { | 552 | if ( qApp->type() != QApplication::GuiServer ) { |
553 | // ask the server to do the work | 553 | // ask the server to do the work |
554 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 554 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
555 | if ( document.isNull() ) { | 555 | if ( document.isNull() ) { |
556 | QCopEnvelope e( "QPE/System", "execute(QString)" ); | 556 | QCopEnvelope e( "QPE/System", "execute(QString)" ); |
557 | e << c; | 557 | e << c; |
558 | } else { | 558 | } else { |
559 | QCopEnvelope e( "QPE/System", "execute(QString,QString)" ); | 559 | QCopEnvelope e( "QPE/System", "execute(QString,QString)" ); |
560 | e << c << document; | 560 | e << c << document; |
561 | } | 561 | } |
562 | #endif | 562 | #endif |
563 | return; | 563 | return; |
564 | } | 564 | } |
565 | 565 | ||
566 | // Attempt to execute the app using a builtin class for the app first | 566 | // Attempt to execute the app using a builtin class for the app first |
567 | // else try and find it in the bin directory | 567 | // else try and find it in the bin directory |
568 | if (builtin) { | 568 | if (builtin) { |
569 | for (int i = 0; builtin[i].file; i++) { | 569 | for (int i = 0; builtin[i].file; i++) { |
570 | if ( builtin[i].file == c ) { | 570 | if ( builtin[i].file == c ) { |
571 | if ( running[i] ) { | 571 | if ( running[i] ) { |
572 | if ( !document.isNull() && builtin[i].documentary ) | 572 | if ( !document.isNull() && builtin[i].documentary ) |
573 | setDocument(running[i], document); | 573 | setDocument(running[i], document); |
574 | running[i]->raise(); | 574 | running[i]->raise(); |
575 | running[i]->show(); | 575 | running[i]->show(); |
576 | running[i]->setActiveWindow(); | 576 | running[i]->setActiveWindow(); |
577 | } else { | 577 | } else { |
578 | running[i] = builtin[i].func( builtin[i].maximized ); | 578 | running[i] = builtin[i].func( builtin[i].maximized ); |