summaryrefslogtreecommitdiff
path: root/library/global.cpp
authorerik <erik>2007-01-19 01:18:01 (UTC)
committer erik <erik>2007-01-19 01:18:01 (UTC)
commit32343107b30904806d02672955c57ed53d39fe79 (patch) (unidiff)
tree9114a0ea170e3adc807a2445b49360f1bfde9626 /library/global.cpp
parentac0ce844e90a64247c0adb210e0a23021b011d57 (diff)
downloadopie-32343107b30904806d02672955c57ed53d39fe79.zip
opie-32343107b30904806d02672955c57ed53d39fe79.tar.gz
opie-32343107b30904806d02672955c57ed53d39fe79.tar.bz2
Every file in this commit has a change to check the return value of a call.
Diffstat (limited to 'library/global.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--library/global.cpp63
1 files changed, 31 insertions, 32 deletions
diff --git a/library/global.cpp b/library/global.cpp
index f7a0767..7bdd0b1 100644
--- a/library/global.cpp
+++ b/library/global.cpp
@@ -91,289 +91,288 @@ StartingAppList::StartingAppList( QObject *parent, const char* name )
91 this, SLOT( handleNewChannel(const QString&)) ); 91 this, SLOT( handleNewChannel(const QString&)) );
92#endif 92#endif
93 dict.setAutoDelete( TRUE ); 93 dict.setAutoDelete( TRUE );
94} 94}
95 95
96void StartingAppList::add( const QString& name ) 96void StartingAppList::add( const QString& name )
97{ 97{
98#if QT_VERSION >= 232 && !defined(QT_NO_COP) 98#if QT_VERSION >= 232 && !defined(QT_NO_COP)
99 if ( !appl ) 99 if ( !appl )
100 appl = new StartingAppList; 100 appl = new StartingAppList;
101 QTime *t = new QTime; 101 QTime *t = new QTime;
102 t->start(); 102 t->start();
103 appl->dict.insert( "QPE/Application/" + name, t ); 103 appl->dict.insert( "QPE/Application/" + name, t );
104#endif 104#endif
105} 105}
106 106
107bool StartingAppList::isStarting( const QString name ) 107bool StartingAppList::isStarting( const QString name )
108{ 108{
109#if QT_VERSION >= 232 && !defined(QT_NO_COP) 109#if QT_VERSION >= 232 && !defined(QT_NO_COP)
110 if ( appl ) { 110 if ( appl ) {
111 QTime *t = appl->dict.find( "QPE/Application/" + name ); 111 QTime *t = appl->dict.find( "QPE/Application/" + name );
112 if ( !t ) 112 if ( !t )
113 return FALSE; 113 return FALSE;
114 if ( t->elapsed() > 10000 ) { 114 if ( t->elapsed() > 10000 ) {
115 // timeout in case of crash or something 115 // timeout in case of crash or something
116 appl->dict.remove( "QPE/Application/" + name ); 116 appl->dict.remove( "QPE/Application/" + name );
117 return FALSE; 117 return FALSE;
118 } 118 }
119 return TRUE; 119 return TRUE;
120 } 120 }
121#endif 121#endif
122 return FALSE; 122 return FALSE;
123} 123}
124 124
125void StartingAppList::handleNewChannel( const QString & name ) 125void StartingAppList::handleNewChannel( const QString & name )
126{ 126{
127#if QT_VERSION >= 232 && !defined(QT_NO_COP) 127#if QT_VERSION >= 232 && !defined(QT_NO_COP)
128 dict.remove( name ); 128 dict.remove( name );
129#endif 129#endif
130} 130}
131 131
132static bool docDirCreated = FALSE; 132static bool docDirCreated = FALSE;
133static QDawg* fixed_dawg = 0; 133static QDawg* fixed_dawg = 0;
134static QDict<QDawg> *named_dawg = 0; 134static QDict<QDawg> *named_dawg = 0;
135 135
136static QString qpeDir() 136static QString qpeDir()
137{ 137{
138 QString dir = getenv("OPIEDIR"); 138 QString dir = getenv("OPIEDIR");
139 if ( dir.isEmpty() ) dir = ".."; 139 if ( dir.isEmpty() ) dir = "..";
140 return dir; 140 return dir;
141} 141}
142 142
143static QString dictDir() 143static QString dictDir()
144{ 144{
145 return qpeDir() + "/etc/dict"; 145 return qpeDir() + "/etc/dict";
146} 146}
147 147
148/*! 148/*!
149 \class Global global.h 149 \class Global global.h
150 \brief The Global class provides application-wide global functions. 150 \brief The Global class provides application-wide global functions.
151 151
152 The Global functions are grouped as follows: 152 The Global functions are grouped as follows:
153 \tableofcontents 153 \tableofcontents
154 154
155 \section1 User Interface 155 \section1 User Interface
156 156
157 The statusMessage() function provides short-duration messages to the 157 The statusMessage() function provides short-duration messages to the
158 user. The showInputMethod() function shows the current input method, 158 user. The showInputMethod() function shows the current input method,
159 and hideInputMethod() hides the input method. 159 and hideInputMethod() hides the input method.
160 160
161 \section1 Document related 161 \section1 Document related
162 162
163 The findDocuments() function creates a set of \link doclnk.html 163 The findDocuments() function creates a set of \link doclnk.html
164 DocLnk\endlink objects in a particular folder. 164 DocLnk\endlink objects in a particular folder.
165 165
166 \section1 Filesystem related 166 \section1 Filesystem related
167 167
168 Global provides an applicationFileName() function that returns the 168 Global provides an applicationFileName() function that returns the
169 full path of an application-specific file. 169 full path of an application-specific file.
170 170
171 The execute() function runs an application. 171 The execute() function runs an application.
172 172
173 \section1 Word list related 173 \section1 Word list related
174 174
175 A list of words relevant to the current locale is maintained by the 175 A list of words relevant to the current locale is maintained by the
176 system. The list is held in a \link qdawg.html DAWG\endlink 176 system. The list is held in a \link qdawg.html DAWG\endlink
177 (implemented by the QDawg class). This list is used, for example, by 177 (implemented by the QDawg class). This list is used, for example, by
178 the pickboard input method. 178 the pickboard input method.
179 179
180 The global QDawg is returned by fixedDawg(); this cannot be updated. 180 The global QDawg is returned by fixedDawg(); this cannot be updated.
181 An updatable copy of the global QDawg is returned by addedDawg(). 181 An updatable copy of the global QDawg is returned by addedDawg().
182 Applications may have their own word lists stored in \l{QDawg}s 182 Applications may have their own word lists stored in \l{QDawg}s
183 which are returned by dawg(). Use addWords() to add words to the 183 which are returned by dawg(). Use addWords() to add words to the
184 updateable copy of the global QDawg or to named application 184 updateable copy of the global QDawg or to named application
185 \l{QDawg}s. 185 \l{QDawg}s.
186 186
187 \section1 Quoting 187 \section1 Quoting
188 188
189 The shellQuote() function quotes a string suitable for passing to a 189 The shellQuote() function quotes a string suitable for passing to a
190 shell. The stringQuote() function backslash escapes '\' and '"' 190 shell. The stringQuote() function backslash escapes '\' and '"'
191 characters. 191 characters.
192 192
193 \section1 Hardware 193 \section1 Hardware
194 194
195 The implementation of the writeHWClock() function depends on the AlarmServer 195 The implementation of the writeHWClock() function depends on the AlarmServer
196 implementation. If the AlarmServer is using atd the clock will be synced to 196 implementation. If the AlarmServer is using atd the clock will be synced to
197 hardware. If opie-alarm is used the hardware clock will be synced before 197 hardware. If opie-alarm is used the hardware clock will be synced before
198 suspending the device. opie-alarm is used by iPAQ and Zaurii implementation 198 suspending the device. opie-alarm is used by iPAQ and Zaurii implementation
199 199
200 \ingroup qtopiaemb 200 \ingroup qtopiaemb
201*/ 201*/
202 202
203/*! 203/*!
204 \internal 204 \internal
205*/ 205*/
206Global::Global() 206Global::Global()
207{ 207{
208} 208}
209 209
210/*! 210/*!
211 Returns the unchangeable QDawg that contains general 211 Returns the unchangeable QDawg that contains general
212 words for the current locale. 212 words for the current locale.
213 213
214 \sa addedDawg() 214 \sa addedDawg()
215*/ 215*/
216const QDawg& Global::fixedDawg() 216const QDawg& Global::fixedDawg()
217{ 217{
218 if ( !fixed_dawg ) { 218 if ( !fixed_dawg ) {
219 if ( !docDirCreated ) 219 if ( !docDirCreated )
220 createDocDir(); 220 createDocDir();
221 221
222 fixed_dawg = new QDawg; 222 fixed_dawg = new QDawg;
223 QString dawgfilename = dictDir() + "/dawg"; 223 QString dawgfilename = dictDir() + "/dawg";
224 QString words_lang; 224 QString words_lang;
225 QStringList langs = Global::languageList(); 225 QStringList langs = Global::languageList();
226 for (QStringList::ConstIterator it = langs.begin(); it!=langs.end(); ++it) { 226 for (QStringList::ConstIterator it = langs.begin(); it!=langs.end(); ++it) {
227 QString lang = *it; 227 QString lang = *it;
228 words_lang = dictDir() + "/words." + lang; 228 words_lang = dictDir() + "/words." + lang;
229 QString dawgfilename_lang = dawgfilename + "." + lang; 229 QString dawgfilename_lang = dawgfilename + "." + lang;
230 if ( QFile::exists(dawgfilename_lang) || 230 if ( QFile::exists(dawgfilename_lang) ||
231 QFile::exists(words_lang) ) { 231 QFile::exists(words_lang) ) {
232 dawgfilename = dawgfilename_lang; 232 dawgfilename = dawgfilename_lang;
233 break; 233 break;
234 } 234 }
235 }
236 QFile dawgfile(dawgfilename);
237
238 if ( !dawgfile.exists() ) {
239 QString fn = dictDir() + "/words";
240 if ( QFile::exists(words_lang) )
241 fn = words_lang;
242 QFile in(fn);
243 if ( in.open(IO_ReadOnly) ) {
244 fixed_dawg->createFromWords(&in);
245 dawgfile.open(IO_WriteOnly);
246 fixed_dawg->write(&dawgfile);
247 dawgfile.close();
248 } 235 }
249 } else { 236 QFile dawgfile(dawgfilename);
250 fixed_dawg->readFile(dawgfilename); 237
251 } 238 if ( !dawgfile.exists() ) {
239 QString fn = dictDir() + "/words";
240 if ( QFile::exists(words_lang) )
241 fn = words_lang;
242 QFile in(fn);
243 if ( in.open(IO_ReadOnly) ) {
244 fixed_dawg->createFromWords(&in);
245 if (dawgfile.open(IO_WriteOnly))
246 fixed_dawg->write(&dawgfile);
247 dawgfile.close();
248 }
249 } else
250 fixed_dawg->readFile(dawgfilename);
252 } 251 }
253 252
254 return *fixed_dawg; 253 return *fixed_dawg;
255} 254}
256 255
257/*! 256/*!
258 Returns the changeable QDawg that contains general 257 Returns the changeable QDawg that contains general
259 words for the current locale. 258 words for the current locale.
260 259
261 \sa fixedDawg() 260 \sa fixedDawg()
262*/ 261*/
263const QDawg& Global::addedDawg() 262const QDawg& Global::addedDawg()
264{ 263{
265 return dawg("local"); 264 return dawg("local");
266} 265}
267 266
268/*! 267/*!
269 Returns the QDawg with the given \a name. 268 Returns the QDawg with the given \a name.
270 This is an application-specific word list. 269 This is an application-specific word list.
271 270
272 \a name should not contain "/". 271 \a name should not contain "/".
273*/ 272*/
274const QDawg& Global::dawg(const QString& name) 273const QDawg& Global::dawg(const QString& name)
275{ 274{
276 createDocDir(); 275 createDocDir();
277 if ( !named_dawg ) 276 if ( !named_dawg )
278 named_dawg = new QDict<QDawg>; 277 named_dawg = new QDict<QDawg>;
279 QDawg* r = named_dawg->find(name); 278 QDawg* r = named_dawg->find(name);
280 if ( !r ) { 279 if ( !r ) {
281 r = new QDawg; 280 r = new QDawg;
282 named_dawg->insert(name,r); 281 named_dawg->insert(name,r);
283 QString dawgfilename = applicationFileName("Dictionary", name ) + ".dawg"; 282 QString dawgfilename = applicationFileName("Dictionary", name ) + ".dawg";
284 QFile dawgfile(dawgfilename); 283 QFile dawgfile(dawgfilename);
285 if ( dawgfile.open(IO_ReadOnly) ) 284 if ( dawgfile.open(IO_ReadOnly) )
286 r->readFile(dawgfilename); 285 r->readFile(dawgfilename);
287 } 286 }
288 return *r; 287 return *r;
289} 288}
290 289
291/*! 290/*!
292 \overload 291 \overload
293 Adds \a wordlist to the addedDawg(). 292 Adds \a wordlist to the addedDawg().
294 293
295 Note that the addition of words persists between program executions 294 Note that the addition of words persists between program executions
296 (they are saved in the dictionary files), so you should confirm the 295 (they are saved in the dictionary files), so you should confirm the
297 words with the user before adding them. 296 words with the user before adding them.
298*/ 297*/
299void Global::addWords(const QStringList& wordlist) 298void Global::addWords(const QStringList& wordlist)
300{ 299{
301 addWords("local",wordlist); 300 addWords("local",wordlist);
302} 301}
303 302
304/*! 303/*!
305 \overload 304 \overload
306 Adds \a wordlist to the addedDawg(). 305 Adds \a wordlist to the addedDawg().
307 306
308 Note that the addition of words persists between program executions 307 Note that the addition of words persists between program executions
309 (they are saved in the dictionary files), so you should confirm the 308 (they are saved in the dictionary files), so you should confirm the
310 words with the user before adding them. 309 words with the user before adding them.
311*/ 310*/
312void Global::addWords(const QString& dictname, const QStringList& wordlist) 311void Global::addWords(const QString& dictname, const QStringList& wordlist)
313{ 312{
314 QDawg& d = (QDawg&)dawg(dictname); 313 QDawg& d = (QDawg&)dawg(dictname);
315 QStringList all = d.allWords() + wordlist; 314 QStringList all = d.allWords() + wordlist;
316 d.createFromWords(all); 315 d.createFromWords(all);
317 316
318 QString dawgfilename = applicationFileName("Dictionary", dictname) + ".dawg"; 317 QString dawgfilename = applicationFileName("Dictionary", dictname) + ".dawg";
319 QFile dawgfile(dawgfilename); 318 QFile dawgfile(dawgfilename);
320 if ( dawgfile.open(IO_WriteOnly) ) { 319 if ( dawgfile.open(IO_WriteOnly) ) {
321 d.write(&dawgfile); 320 d.write(&dawgfile);
322 dawgfile.close(); 321 dawgfile.close();
323 } 322 }
324 323
325 // #### Re-read the dawg here if we use mmap(). 324 // #### Re-read the dawg here if we use mmap().
326 325
327 // #### Signal other processes to re-read. 326 // #### Signal other processes to re-read.
328} 327}
329 328
330 329
331/*! 330/*!
332 Returns the full path for the application called \a appname, with the 331 Returns the full path for the application called \a appname, with the
333 given \a filename. Returns QString::null if there was a problem creating 332 given \a filename. Returns QString::null if there was a problem creating
334 the directory tree for \a appname. 333 the directory tree for \a appname.
335 If \a filename contains "/", it is the caller's responsibility to 334 If \a filename contains "/", it is the caller's responsibility to
336 ensure that those directories exist. 335 ensure that those directories exist.
337*/ 336*/
338QString Global::applicationFileName(const QString& appname, const QString& filename) 337QString Global::applicationFileName(const QString& appname, const QString& filename)
339{ 338{
340 QDir d; 339 QDir d;
341 QString r = getenv("HOME"); 340 QString r = getenv("HOME");
342 r += "/Applications/"; 341 r += "/Applications/";
343 if ( !QFile::exists( r ) ) 342 if ( !QFile::exists( r ) )
344 if ( d.mkdir(r) == false ) 343 if ( d.mkdir(r) == false )
345 return QString::null; 344 return QString::null;
346 r += appname; 345 r += appname;
347 if ( !QFile::exists( r ) ) 346 if ( !QFile::exists( r ) )
348 if ( d.mkdir(r) == false ) 347 if ( d.mkdir(r) == false )
349 return QString::null; 348 return QString::null;
350 r += "/"; r += filename; 349 r += "/"; r += filename;
351 return r; 350 return r;
352} 351}
353 352
354/*! 353/*!
355 \internal 354 \internal
356*/ 355*/
357void Global::createDocDir() 356void Global::createDocDir()
358{ 357{
359 if ( !docDirCreated ) { 358 if ( !docDirCreated ) {
360 docDirCreated = TRUE; 359 docDirCreated = TRUE;
361 mkdir( QPEApplication::documentDir().latin1(), 0755 ); 360 mkdir( QPEApplication::documentDir().latin1(), 0755 );
362 } 361 }
363} 362}
364 363
365 364
366/*! 365/*!
367 Displays a status \a message to the user. This usually appears 366 Displays a status \a message to the user. This usually appears
368 in the taskbar for a short amount of time, then disappears. 367 in the taskbar for a short amount of time, then disappears.
369*/ 368*/
370void Global::statusMessage(const QString& message) 369void Global::statusMessage(const QString& message)
371{ 370{
372#if !defined(QT_NO_COP) 371#if !defined(QT_NO_COP)
373 QCopEnvelope e( "QPE/TaskBar", "message(QString)" ); 372 QCopEnvelope e( "QPE/TaskBar", "message(QString)" );
374 e << message; 373 e << message;
375#endif 374#endif
376} 375}
377 376
378/*! 377/*!
379 \internal 378 \internal