-rw-r--r-- | libopie2/opiecore/oglobal.cpp | 152 | ||||
-rw-r--r-- | libopie2/opiecore/oglobal.h | 47 |
2 files changed, 153 insertions, 46 deletions
diff --git a/libopie2/opiecore/oglobal.cpp b/libopie2/opiecore/oglobal.cpp index 352151b..879e80f 100644 --- a/libopie2/opiecore/oglobal.cpp +++ b/libopie2/opiecore/oglobal.cpp | |||
@@ -1,28 +1,27 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@Vanille.de> | 3 | Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@Vanille.de> |
4 | Copyright (C) 2004 Holger 'zecke' Freyther <zecke@handhelds.org> | 4 | =. Copyright (C) 2004 Holger 'zecke' Freyther <zecke@handhelds.org> |
5 | =. | ||
6 | .=l. | 5 | .=l. |
7 | .>+-= | 6 | .>+-= |
8 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
9 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
10 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
11 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
12 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
13 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
14 | .%`+i> _;_. | 13 | .%`+i> _;_. |
15 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
16 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
17 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
18 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
19 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
20 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
21 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
22 | : = ...= . :.=- | 21 | : = ...= . :.=- |
23 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
24 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
25 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
26 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
27 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
28 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
@@ -32,6 +31,13 @@ | |||
32 | 31 | ||
33 | #include <qfile.h> | 32 | #include <qfile.h> |
34 | #include <qtextstream.h> | 33 | #include <qtextstream.h> |
34 | #include <qdir.h> | ||
35 | #include <qpe/mimetype.h> | ||
36 | #include <qpe/qpeapplication.h> | ||
37 | #include <qpe/storage.h> | ||
38 | |||
39 | #include <unistd.h> | ||
40 | #include <sys/types.h> | ||
35 | 41 | ||
36 | static const char Base64EncMap[64] = | 42 | static const char Base64EncMap[64] = |
37 | { | 43 | { |
@@ -67,6 +73,7 @@ static char Base64DecMap[128] = | |||
67 | 73 | ||
68 | 74 | ||
69 | OConfig* OGlobal::_config = 0; | 75 | OConfig* OGlobal::_config = 0; |
76 | OConfig* OGlobal::_qpe_config = 0; | ||
70 | 77 | ||
71 | OConfig* OGlobal::config() | 78 | OConfig* OGlobal::config() |
72 | { | 79 | { |
@@ -303,3 +310,102 @@ QByteArray OGlobal::decodeBase64( const QByteArray& in) { | |||
303 | 310 | ||
304 | return out; | 311 | return out; |
305 | } | 312 | } |
313 | |||
314 | bool OGlobal::isAppLnkFileName( const QString& str ) | ||
315 | { | ||
316 | if (str.length()==0||str.at(str.length()-1)==QDir::separator()) return false; | ||
317 | return str.startsWith(MimeType::appsFolderName()+QDir::separator()); | ||
318 | } | ||
319 | |||
320 | /* ToDo: | ||
321 | * This fun should check the document-path value for the mounted media | ||
322 | * which has to be implemented later. this moment we just check for a | ||
323 | * mounted media name. | ||
324 | */ | ||
325 | bool OGlobal::isDocumentFileName( const QString& file ) | ||
326 | { | ||
327 | if (file.length()==0||file.at(file.length()-1)==QDir::separator()) return false; | ||
328 | if (file.startsWith(QPEApplication::documentDir()+QDir::separator())) return true; | ||
329 | StorageInfo si; | ||
330 | QList< FileSystem > fl = si.fileSystems(); | ||
331 | FileSystem*fs; | ||
332 | for (fs = fl.first();fs!=0;fs=fl.next()) { | ||
333 | if (fs->isRemovable()&&file.startsWith(fs->name()+QDir::separator())) | ||
334 | return true; | ||
335 | } | ||
336 | if (file.startsWith(homeDirPath())+"/Documents/") return true; | ||
337 | return false; | ||
338 | } | ||
339 | |||
340 | QString OGlobal::tempDirPath() | ||
341 | { | ||
342 | static QString defstring="/tmp"; | ||
343 | char * tmpp = 0; | ||
344 | if ( (tmpp=getenv("TEMP"))) { | ||
345 | return tmpp; | ||
346 | } | ||
347 | return defstring; | ||
348 | } | ||
349 | |||
350 | QString OGlobal::homeDirPath() | ||
351 | { | ||
352 | char * tmpp = getenv("HOME"); | ||
353 | return (tmpp?tmpp:"/"); | ||
354 | } | ||
355 | |||
356 | bool OGlobal::weekStartsOnMonday() | ||
357 | { | ||
358 | OConfig*conf=OGlobal::qpe_config(); | ||
359 | if (!conf)return false; | ||
360 | conf->setGroup("Time"); | ||
361 | return conf->readBoolEntry("MONDAY",true); | ||
362 | } | ||
363 | |||
364 | void OGlobal::setWeekStartsOnMonday( bool what) | ||
365 | { | ||
366 | OConfig*conf=OGlobal::qpe_config(); | ||
367 | if (!conf)return; | ||
368 | conf->setGroup("Time"); | ||
369 | return conf->writeEntry("MONDAY",what); | ||
370 | } | ||
371 | |||
372 | bool OGlobal::useAMPM() | ||
373 | { | ||
374 | OConfig*conf=OGlobal::qpe_config(); | ||
375 | if (!conf)return false; | ||
376 | conf->setGroup("Time"); | ||
377 | return conf->readBoolEntry("AMPM",false); | ||
378 | } | ||
379 | |||
380 | void OGlobal::setUseAMPM( bool what) | ||
381 | { | ||
382 | OConfig*conf=OGlobal::qpe_config(); | ||
383 | if (!conf)return; | ||
384 | conf->setGroup("Time"); | ||
385 | return conf->writeEntry("AMPM",what); | ||
386 | } | ||
387 | |||
388 | OConfig* OGlobal::qpe_config() | ||
389 | { | ||
390 | if ( !OGlobal::_qpe_config ) { | ||
391 | OGlobal::_qpe_config = new OConfig( "qpe" ); | ||
392 | } | ||
393 | return OGlobal::_qpe_config; | ||
394 | } | ||
395 | |||
396 | bool OGlobal::truncateFile( QFile &f, off_t size ) | ||
397 | { | ||
398 | /* or should we let enlarge Files? then remove this | ||
399 | f.size()< part! - Alwin | ||
400 | */ | ||
401 | if (!f.exists()||f.size()<(unsigned)size) return false; | ||
402 | bool closeit=false; | ||
403 | if (!f.isOpen()) { | ||
404 | closeit=true; | ||
405 | f.open(IO_Raw | IO_ReadWrite | IO_Append); | ||
406 | } | ||
407 | if (!f.isOpen()) { return false; } | ||
408 | int r = ftruncate(f.handle(),size); | ||
409 | if (closeit) f.close(); | ||
410 | return r==0; | ||
411 | } | ||
diff --git a/libopie2/opiecore/oglobal.h b/libopie2/opiecore/oglobal.h index d09d73e..5b43f01 100644 --- a/libopie2/opiecore/oglobal.h +++ b/libopie2/opiecore/oglobal.h | |||
@@ -1,28 +1,27 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@Vanille.de> | 3 | Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@Vanille.de> |
4 | Copyright (C) 2004 Holger 'zecke' Freyther <zecke@handhelds.org> | 4 | =. Copyright (C) 2004 Holger 'zecke' Freyther <zecke@handhelds.org> |
5 | =. | ||
6 | .=l. | 5 | .=l. |
7 | .>+-= | 6 | .>+-= |
8 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
9 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
10 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
11 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
12 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
13 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
14 | .%`+i> _;_. | 13 | .%`+i> _;_. |
15 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
16 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
17 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
18 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
19 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
20 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
21 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
22 | : = ...= . :.=- | 21 | : = ...= . :.=- |
23 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
24 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
25 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
26 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
27 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
28 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
@@ -108,6 +107,7 @@ public: | |||
108 | */ | 107 | */ |
109 | //@{ | 108 | //@{ |
110 | static OConfig* config(); | 109 | static OConfig* config(); |
110 | static OConfig* qpe_config(); | ||
111 | static QString ownerName(); | 111 | static QString ownerName(); |
112 | static bool weekStartsOnMonday(); | 112 | static bool weekStartsOnMonday(); |
113 | static bool useAMPM(); | 113 | static bool useAMPM(); |
@@ -135,6 +135,7 @@ public: | |||
135 | 135 | ||
136 | private: | 136 | private: |
137 | static OConfig* _config; | 137 | static OConfig* _config; |
138 | static OConfig* _qpe_config; | ||
138 | }; | 139 | }; |
139 | 140 | ||
140 | #endif // OGLOBAL_H | 141 | #endif // OGLOBAL_H |