summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiecore/oglobal.cpp152
-rw-r--r--libopie2/opiecore/oglobal.h47
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,305 +1,411 @@
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.
29*/ 28*/
30 29
31#include <opie2/oglobal.h> 30#include <opie2/oglobal.h>
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
36static const char Base64EncMap[64] = 42static const char Base64EncMap[64] =
37{ 43{
38 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 44 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
39 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 45 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50,
40 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 46 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
41 0x59, 0x5A, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 47 0x59, 0x5A, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
42 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 48 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E,
43 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 49 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76,
44 0x77, 0x78, 0x79, 0x7A, 0x30, 0x31, 0x32, 0x33, 50 0x77, 0x78, 0x79, 0x7A, 0x30, 0x31, 0x32, 0x33,
45 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x2B, 0x2F 51 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x2B, 0x2F
46}; 52};
47 53
48static char Base64DecMap[128] = 54static char Base64DecMap[128] =
49{ 55{
50 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 56 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
51 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 57 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
52 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 58 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
53 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 59 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
54 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 60 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
55 0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x3F, 61 0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x3F,
56 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 62 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B,
57 0x3C, 0x3D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 63 0x3C, 0x3D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
58 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 64 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
59 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 65 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E,
60 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 66 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16,
61 0x17, 0x18, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, 67 0x17, 0x18, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00,
62 0x00, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 68 0x00, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20,
63 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 69 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28,
64 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, 70 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30,
65 0x31, 0x32, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00 71 0x31, 0x32, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00
66}; 72};
67 73
68 74
69OConfig* OGlobal::_config = 0; 75OConfig* OGlobal::_config = 0;
76OConfig* OGlobal::_qpe_config = 0;
70 77
71OConfig* OGlobal::config() 78OConfig* OGlobal::config()
72{ 79{
73 if ( !OGlobal::_config ) 80 if ( !OGlobal::_config )
74 { 81 {
75 // odebug classes are reading config, so can't use them here! 82 // odebug classes are reading config, so can't use them here!
76 qDebug( "OGlobal::creating global configuration instance." ); 83 qDebug( "OGlobal::creating global configuration instance." );
77 OGlobal::_config = new OConfig( "global" ); 84 OGlobal::_config = new OConfig( "global" );
78 } 85 }
79 return OGlobal::_config; 86 return OGlobal::_config;
80} 87}
81 88
82 89
83/** 90/**
84 * Return the internal builtin Global::Command object 91 * Return the internal builtin Global::Command object
85 * 92 *
86 */ 93 */
87Global::Command* OGlobal::builtinCommands() { 94Global::Command* OGlobal::builtinCommands() {
88 return builtin; 95 return builtin;
89} 96}
90 97
91 98
92/** 99/**
93 * Return the internal builtin QGuardedPtr<QWidget> object 100 * Return the internal builtin QGuardedPtr<QWidget> object
94 */ 101 */
95QGuardedPtr<QWidget>* OGlobal::builtinRunning() { 102QGuardedPtr<QWidget>* OGlobal::builtinRunning() {
96 return running; 103 return running;
97} 104}
98 105
99 106
100/** 107/**
101 * \brief generate a new UUID as QString 108 * \brief generate a new UUID as QString
102 * Return a new UUID as QString. UUID are global unique 109 * Return a new UUID as QString. UUID are global unique
103 * 110 *
104 * 111 *
105 * @return the UUID or QString::null 112 * @return the UUID or QString::null
106 */ 113 */
107QString OGlobal::generateUuid() { 114QString OGlobal::generateUuid() {
108 QFile file( "/proc/sys/kernel/random/uuid" ); 115 QFile file( "/proc/sys/kernel/random/uuid" );
109 if (!file.open(IO_ReadOnly ) ) 116 if (!file.open(IO_ReadOnly ) )
110 return QString::null; 117 return QString::null;
111 118
112 QTextStream stream(&file); 119 QTextStream stream(&file);
113 120
114 return "{" + stream.read().stripWhiteSpace() + "}"; 121 return "{" + stream.read().stripWhiteSpace() + "}";
115} 122}
116 123
117 124
118/** 125/**
119 * \brief Encode a QByteArray in base64 126 * \brief Encode a QByteArray in base64
120 * 127 *
121 * An Implementation of the RF1521 base64 encoding. 128 * An Implementation of the RF1521 base64 encoding.
122 * 129 *
123 * The boolean argument determines if the encoded data is 130 * The boolean argument determines if the encoded data is
124 * going to be restricted to 76 characters or less per line 131 * going to be restricted to 76 characters or less per line
125 * as specified by RFC 2045. If @p insertLFs is true, then 132 * as specified by RFC 2045. If @p insertLFs is true, then
126 * there will be 76 characters or less per line. 133 * there will be 76 characters or less per line.
127 * 134 *
128 * If you use this to create a QCString remember that it is null terminated! 135 * If you use this to create a QCString remember that it is null terminated!
129 * \code 136 * \code
130 * QByteArray ar = OGlobal::encodeBase64(&array); 137 * QByteArray ar = OGlobal::encodeBase64(&array);
131 * QCString str(ar.data(),ar.size()+1); // the NUL at the end 138 * QCString str(ar.data(),ar.size()+1); // the NUL at the end
132 * 139 *
133 * \endcode 140 * \endcode
134 * 141 *
135 * @param in The QByteArray to encode 142 * @param in The QByteArray to encode
136 * @param insertLFs Limit number of characters per line 143 * @param insertLFs Limit number of characters per line
137 * @return The argument as base64 encoded or QByteArray() if in.isEmpty() 144 * @return The argument as base64 encoded or QByteArray() if in.isEmpty()
138 * @see QByteArray 145 * @see QByteArray
139 * @see QArray 146 * @see QArray
140 * @see QMemArray 147 * @see QMemArray
141 * @see QCString 148 * @see QCString
142 */ 149 */
143/* 150/*
144 * LGPL by Rik Hemsely of the KDE Project. taken from kmdcodec.cpp 151 * LGPL by Rik Hemsely of the KDE Project. taken from kmdcodec.cpp
145 */ 152 */
146QByteArray OGlobal::encodeBase64(const QByteArray& in, bool insertLFs ) { 153QByteArray OGlobal::encodeBase64(const QByteArray& in, bool insertLFs ) {
147 if ( in.isEmpty() ) 154 if ( in.isEmpty() )
148 return QByteArray(); 155 return QByteArray();
149 156
150 unsigned int sidx = 0; 157 unsigned int sidx = 0;
151 unsigned int didx = 0; 158 unsigned int didx = 0;
152 const char* data = in.data(); 159 const char* data = in.data();
153 const unsigned int len = in.size(); 160 const unsigned int len = in.size();
154 161
155 unsigned int out_len = ((len+2)/3)*4; 162 unsigned int out_len = ((len+2)/3)*4;
156 163
157 // Deal with the 76 characters or less per 164 // Deal with the 76 characters or less per
158 // line limit specified in RFC 2045 on a 165 // line limit specified in RFC 2045 on a
159 // pre request basis. 166 // pre request basis.
160 insertLFs = (insertLFs && out_len > 76); 167 insertLFs = (insertLFs && out_len > 76);
161 if ( insertLFs ) 168 if ( insertLFs )
162 out_len += ((out_len-1)/76); 169 out_len += ((out_len-1)/76);
163 170
164 int count = 0; 171 int count = 0;
165 QByteArray out( out_len ); 172 QByteArray out( out_len );
166 173
167 // 3-byte to 4-byte conversion + 0-63 to ascii printable conversion 174 // 3-byte to 4-byte conversion + 0-63 to ascii printable conversion
168 if ( len > 1 ) 175 if ( len > 1 )
169 { 176 {
170 while (sidx < len-2) 177 while (sidx < len-2)
171 { 178 {
172 if ( insertLFs ) 179 if ( insertLFs )
173 { 180 {
174 if ( count && (count%76) == 0 ) 181 if ( count && (count%76) == 0 )
175 out[didx++] = '\n'; 182 out[didx++] = '\n';
176 count += 4; 183 count += 4;
177 } 184 }
178 out[didx++] = Base64EncMap[(data[sidx] >> 2) & 077]; 185 out[didx++] = Base64EncMap[(data[sidx] >> 2) & 077];
179 out[didx++] = Base64EncMap[(data[sidx+1] >> 4) & 017 | 186 out[didx++] = Base64EncMap[(data[sidx+1] >> 4) & 017 |
180 (data[sidx] << 4) & 077]; 187 (data[sidx] << 4) & 077];
181 out[didx++] = Base64EncMap[(data[sidx+2] >> 6) & 003 | 188 out[didx++] = Base64EncMap[(data[sidx+2] >> 6) & 003 |
182 (data[sidx+1] << 2) & 077]; 189 (data[sidx+1] << 2) & 077];
183 out[didx++] = Base64EncMap[data[sidx+2] & 077]; 190 out[didx++] = Base64EncMap[data[sidx+2] & 077];
184 sidx += 3; 191 sidx += 3;
185 } 192 }
186 } 193 }
187 194
188 if (sidx < len) 195 if (sidx < len)
189 { 196 {
190 if ( insertLFs && (count > 0) && (count%76) == 0 ) 197 if ( insertLFs && (count > 0) && (count%76) == 0 )
191 out[didx++] = '\n'; 198 out[didx++] = '\n';
192 199
193 out[didx++] = Base64EncMap[(data[sidx] >> 2) & 077]; 200 out[didx++] = Base64EncMap[(data[sidx] >> 2) & 077];
194 if (sidx < len-1) 201 if (sidx < len-1)
195 { 202 {
196 out[didx++] = Base64EncMap[(data[sidx+1] >> 4) & 017 | 203 out[didx++] = Base64EncMap[(data[sidx+1] >> 4) & 017 |
197 (data[sidx] << 4) & 077]; 204 (data[sidx] << 4) & 077];
198 out[didx++] = Base64EncMap[(data[sidx+1] << 2) & 077]; 205 out[didx++] = Base64EncMap[(data[sidx+1] << 2) & 077];
199 } 206 }
200 else 207 else
201 { 208 {
202 out[didx++] = Base64EncMap[(data[sidx] << 4) & 077]; 209 out[didx++] = Base64EncMap[(data[sidx] << 4) & 077];
203 } 210 }
204 } 211 }
205 212
206 // Add padding 213 // Add padding
207 while (didx < out.size()) 214 while (didx < out.size())
208 { 215 {
209 out[didx] = '='; 216 out[didx] = '=';
210 didx++; 217 didx++;
211 } 218 }
212 219
213 return out; 220 return out;
214} 221}
215 222
216/** 223/**
217 * Decodes the given data that was encoded with the base64 224 * Decodes the given data that was encoded with the base64
218 * algorithm. 225 * algorithm.
219 * 226 *
220 * 227 *
221 * @param in the encoded data to be decoded. 228 * @param in the encoded data to be decoded.
222 * @return the decoded QByteArray or QByteArray() in case of failure 229 * @return the decoded QByteArray or QByteArray() in case of failure
223 * @see OGlobal::encodeBase64 230 * @see OGlobal::encodeBase64
224 */ 231 */
225QByteArray OGlobal::decodeBase64( const QByteArray& in) { 232QByteArray OGlobal::decodeBase64( const QByteArray& in) {
226 if ( in.isEmpty() ) 233 if ( in.isEmpty() )
227 return QByteArray(); 234 return QByteArray();
228 235
229 QByteArray out; 236 QByteArray out;
230 unsigned int count = 0; 237 unsigned int count = 0;
231 unsigned int len = in.size(), tail = len; 238 unsigned int len = in.size(), tail = len;
232 const char* data = in.data(); 239 const char* data = in.data();
233 240
234 // Deal with possible *nix "BEGIN" marker!! 241 // Deal with possible *nix "BEGIN" marker!!
235 while ( count < len && (data[count] == '\n' || data[count] == '\r' || 242 while ( count < len && (data[count] == '\n' || data[count] == '\r' ||
236 data[count] == '\t' || data[count] == ' ') ) 243 data[count] == '\t' || data[count] == ' ') )
237 count++; 244 count++;
238 245
239 if ( strncasecmp(data+count, "begin", 5) == 0 ) 246 if ( strncasecmp(data+count, "begin", 5) == 0 )
240 { 247 {
241 count += 5; 248 count += 5;
242 while ( count < len && data[count] != '\n' && data[count] != '\r' ) 249 while ( count < len && data[count] != '\n' && data[count] != '\r' )
243 count++; 250 count++;
244 251
245 while ( count < len && (data[count] == '\n' || data[count] == '\r') ) 252 while ( count < len && (data[count] == '\n' || data[count] == '\r') )
246 count ++; 253 count ++;
247 254
248 data += count; 255 data += count;
249 tail = (len -= count); 256 tail = (len -= count);
250 } 257 }
251 258
252 // Find the tail end of the actual encoded data even if 259 // Find the tail end of the actual encoded data even if
253 // there is/are trailing CR and/or LF. 260 // there is/are trailing CR and/or LF.
254 while ( data[tail-1] == '=' || data[tail-1] == '\n' || 261 while ( data[tail-1] == '=' || data[tail-1] == '\n' ||
255 data[tail-1] == '\r' ) 262 data[tail-1] == '\r' )
256 if ( data[--tail] != '=' ) len = tail; 263 if ( data[--tail] != '=' ) len = tail;
257 264
258 unsigned int outIdx = 0; 265 unsigned int outIdx = 0;
259 out.resize( (count=len) ); 266 out.resize( (count=len) );
260 for (unsigned int idx = 0; idx < count; idx++) 267 for (unsigned int idx = 0; idx < count; idx++)
261 { 268 {
262 // Adhere to RFC 2045 and ignore characters 269 // Adhere to RFC 2045 and ignore characters
263 // that are not part of the encoding table. 270 // that are not part of the encoding table.
264 unsigned char ch = data[idx]; 271 unsigned char ch = data[idx];
265 if ( (ch > 47 && ch < 58) || (ch > 64 && ch < 91 ) || 272 if ( (ch > 47 && ch < 58) || (ch > 64 && ch < 91 ) ||
266 (ch > 96 && ch < 123)|| ch == '+' || ch == '/' || ch == '=') 273 (ch > 96 && ch < 123)|| ch == '+' || ch == '/' || ch == '=')
267 { 274 {
268 out[outIdx++] = Base64DecMap[ch]; 275 out[outIdx++] = Base64DecMap[ch];
269 } 276 }
270 else 277 else
271 { 278 {
272 len--; 279 len--;
273 tail--; 280 tail--;
274 } 281 }
275 } 282 }
276 283
277 // kdDebug() << "Tail size = " << tail << ", Length size = " << len << endl; 284 // kdDebug() << "Tail size = " << tail << ", Length size = " << len << endl;
278 285
279 // 4-byte to 3-byte conversion 286 // 4-byte to 3-byte conversion
280 len = (tail>(len/4)) ? tail-(len/4) : 0; 287 len = (tail>(len/4)) ? tail-(len/4) : 0;
281 unsigned int sidx = 0, didx = 0; 288 unsigned int sidx = 0, didx = 0;
282 if ( len > 1 ) 289 if ( len > 1 )
283 { 290 {
284 while (didx < len-2) 291 while (didx < len-2)
285 { 292 {
286 out[didx] = (((out[sidx] << 2) & 255) | ((out[sidx+1] >> 4) & 003)); 293 out[didx] = (((out[sidx] << 2) & 255) | ((out[sidx+1] >> 4) & 003));
287 out[didx+1] = (((out[sidx+1] << 4) & 255) | ((out[sidx+2] >> 2) & 017)); 294 out[didx+1] = (((out[sidx+1] << 4) & 255) | ((out[sidx+2] >> 2) & 017));
288 out[didx+2] = (((out[sidx+2] << 6) & 255) | (out[sidx+3] & 077)); 295 out[didx+2] = (((out[sidx+2] << 6) & 255) | (out[sidx+3] & 077));
289 sidx += 4; 296 sidx += 4;
290 didx += 3; 297 didx += 3;
291 } 298 }
292 } 299 }
293 300
294 if (didx < len) 301 if (didx < len)
295 out[didx] = (((out[sidx] << 2) & 255) | ((out[sidx+1] >> 4) & 003)); 302 out[didx] = (((out[sidx] << 2) & 255) | ((out[sidx+1] >> 4) & 003));
296 303
297 if (++didx < len ) 304 if (++didx < len )
298 out[didx] = (((out[sidx+1] << 4) & 255) | ((out[sidx+2] >> 2) & 017)); 305 out[didx] = (((out[sidx+1] << 4) & 255) | ((out[sidx+2] >> 2) & 017));
299 306
300 // Resize the output buffer 307 // Resize the output buffer
301 if ( len == 0 || len < out.size() ) 308 if ( len == 0 || len < out.size() )
302 out.resize(len); 309 out.resize(len);
303 310
304 return out; 311 return out;
305} 312}
313
314bool 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 */
325bool 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
340QString 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
350QString OGlobal::homeDirPath()
351{
352 char * tmpp = getenv("HOME");
353 return (tmpp?tmpp:"/");
354}
355
356bool 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
364void 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
372bool 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
380void 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
388OConfig* OGlobal::qpe_config()
389{
390 if ( !OGlobal::_qpe_config ) {
391 OGlobal::_qpe_config = new OConfig( "qpe" );
392 }
393 return OGlobal::_qpe_config;
394}
395
396bool 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,140 +1,141 @@
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.
29*/ 28*/
30 29
31#ifndef OGLOBAL_H 30#ifndef OGLOBAL_H
32#define OGLOBAL_H 31#define OGLOBAL_H
33 32
34 33
35#include <opie2/oconfig.h> 34#include <opie2/oconfig.h>
36 35
37#ifndef private 36#ifndef private
38#define HACK_DEFINED 37#define HACK_DEFINED
39#define private protected 38#define private protected
40#endif 39#endif
41#include <qpe/global.h> 40#include <qpe/global.h>
42#ifdef HACK_DEFINED 41#ifdef HACK_DEFINED
43#undef private 42#undef private
44#endif 43#endif
45 44
46#include <sys/types.h> 45#include <sys/types.h>
47 46
48//FIXME Is it wise or even necessary to inherit OGlobal from Global? 47//FIXME Is it wise or even necessary to inherit OGlobal from Global?
49// once we totally skip libqpe it should ideally swallow Global -zecke 48// once we totally skip libqpe it should ideally swallow Global -zecke
50// You're right. I deleted global as the base class. -mickeyl 49// You're right. I deleted global as the base class. -mickeyl
51 50
52 51
53class QFile; 52class QFile;
54class QString; 53class QString;
55class DateFormat; 54class DateFormat;
56/** 55/**
57 *\brief OGlobal contains a list of generic functions 56 *\brief OGlobal contains a list of generic functions
58 * 57 *
59 * The class OGlobal contains small utility functions 58 * The class OGlobal contains small utility functions
60 * which might be useful for other applications to use. It features access 59 * which might be useful for other applications to use. It features access
61 * to the global device config and specialized functions to get information 60 * to the global device config and specialized functions to get information
62 * out of this config like Weekstart or Owner name. 61 * out of this config like Weekstart or Owner name.
63 * 62 *
64 * @todo ODP implement the things from Global which are good 63 * @todo ODP implement the things from Global which are good
65 * @author mickey,alwin,zecke 64 * @author mickey,alwin,zecke
66 * @version 0.1 65 * @version 0.1
67 */ 66 */
68class OGlobal : public Global 67class OGlobal : public Global
69{ 68{
70public: 69public:
71 70
72 // how do they relate to our Document Idea 71 // how do they relate to our Document Idea
73 /** @name Document System related functions 72 /** @name Document System related functions
74 * 73 *
75 */ 74 */
76 //@{ 75 //@{
77 static bool isAppLnkFileName( const QString& str ); 76 static bool isAppLnkFileName( const QString& str );
78 static bool isDocumentFileName( const QString& file ); 77 static bool isDocumentFileName( const QString& file );
79 //@} 78 //@}
80 79
81 /** @name File Operations 80 /** @name File Operations
82 * File operations provided by OGlobal 81 * File operations provided by OGlobal
83 */ 82 */
84 //@{ 83 //@{
85 static QString tempDirPath(); 84 static QString tempDirPath();
86 static QString homeDirPath(); 85 static QString homeDirPath();
87 static QString tempFileName( const QString& ); 86 static QString tempFileName( const QString& );
88 static bool renameFile( const QString& from, const QString& to ); 87 static bool renameFile( const QString& from, const QString& to );
89 static bool truncateFile( QFile &f, off_t size ); 88 static bool truncateFile( QFile &f, off_t size );
90 //@} 89 //@}
91 90
92 91
93 static QString generateUuid(); 92 static QString generateUuid();
94 93
95 /** @name Convert Content 94 /** @name Convert Content
96 * Convert Content of a QByteArray 95 * Convert Content of a QByteArray
97 */ 96 */
98 //@{ 97 //@{
99 static QByteArray encodeBase64(const QByteArray&, bool insertLF = false ); 98 static QByteArray encodeBase64(const QByteArray&, bool insertLF = false );
100 static QByteArray decodeBase64(const QByteArray& ); 99 static QByteArray decodeBase64(const QByteArray& );
101 //@} 100 //@}
102 101
103 //FIXME Do we want to put that into OApplication as in KApplication? -zecke 102 //FIXME Do we want to put that into OApplication as in KApplication? -zecke
104 // We already have a per-application config in OApplication 103 // We already have a per-application config in OApplication
105 // ( accessed through oApp->config() ), but this one is the global one! -mickeyl 104 // ( accessed through oApp->config() ), but this one is the global one! -mickeyl
106 /** @name Config and Owner related Information 105 /** @name Config and Owner related Information
107 * 106 *
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();
114#ifdef ODP 114#ifdef ODP
115#error "Fix dateFormat" 115#error "Fix dateFormat"
116 /** 116 /**
117 * For Qt3/Qt4 we can use QDate::toString(OGlobal::dateFormat) 117 * For Qt3/Qt4 we can use QDate::toString(OGlobal::dateFormat)
118 * See if we need to use the function with String in it 118 * See if we need to use the function with String in it
119 * Anyway this is the future 119 * Anyway this is the future
120 * for now still use TimeString! 120 * for now still use TimeString!
121 */ 121 */
122#endif 122#endif
123 static DateFormat dateFormat(); 123 static DateFormat dateFormat();
124 static void setDateFormat( const DateFormat& ); 124 static void setDateFormat( const DateFormat& );
125 125
126 126
127 static void setWeekStartsOnMonday( bool ); 127 static void setWeekStartsOnMonday( bool );
128 static void setUseAMPM( bool ); 128 static void setUseAMPM( bool );
129 //@} 129 //@}
130 130
131 //@{ 131 //@{
132 static Global::Command* builtinCommands(); 132 static Global::Command* builtinCommands();
133 static QGuardedPtr<QWidget>* builtinRunning(); 133 static QGuardedPtr<QWidget>* builtinRunning();
134 //@} 134 //@}
135 135
136private: 136private:
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