summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiecore/oglobal.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/libopie2/opiecore/oglobal.cpp b/libopie2/opiecore/oglobal.cpp
index 2968a7d..706ac6c 100644
--- a/libopie2/opiecore/oglobal.cpp
+++ b/libopie2/opiecore/oglobal.cpp
@@ -1,421 +1,422 @@
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 .=l. 5 .=l.
6 .>+-= 6 .>+-=
7 _;:, .> :=|. This program is free software; you can 7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under 8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software 10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License, 11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version. 12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_. 13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that 14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of 16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more 19..}^=.= = ; Library General Public License for more
20++= -. .` .: details. 20++= -. .` .: details.
21 : = ...= . :.=- 21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU 22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with 23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB. 24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28*/ 28*/
29 29
30#include <opie2/oglobal.h> 30#include <opie2/oglobal.h>
31 31
32#include <qtextstream.h> 32#include <qtextstream.h>
33#include <qdir.h> 33#include <qdir.h>
34#include <qpe/mimetype.h> 34#include <qpe/mimetype.h>
35#include <qpe/qpeapplication.h> 35#include <qpe/qpeapplication.h>
36#include <qpe/storage.h> 36#include <qpe/storage.h>
37 37
38#include <unistd.h> 38#include <unistd.h>
39#include <sys/types.h> 39#include <sys/types.h>
40 40
41using namespace Opie::Core; 41using namespace Opie::Core;
42 42
43static const char Base64EncMap[64] = 43static const char Base64EncMap[64] =
44{ 44{
45 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 45 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
46 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 46 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50,
47 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 47 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
48 0x59, 0x5A, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 48 0x59, 0x5A, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
49 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 49 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E,
50 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 50 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76,
51 0x77, 0x78, 0x79, 0x7A, 0x30, 0x31, 0x32, 0x33, 51 0x77, 0x78, 0x79, 0x7A, 0x30, 0x31, 0x32, 0x33,
52 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x2B, 0x2F 52 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x2B, 0x2F
53}; 53};
54 54
55static char Base64DecMap[128] = 55static char Base64DecMap[128] =
56{ 56{
57 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 57 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
58 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 58 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
59 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 59 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
60 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 60 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
61 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 61 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
62 0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x3F, 62 0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x3F,
63 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 63 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B,
64 0x3C, 0x3D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 64 0x3C, 0x3D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
65 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 65 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
66 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 66 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E,
67 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 67 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16,
68 0x17, 0x18, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, 68 0x17, 0x18, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00,
69 0x00, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 69 0x00, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20,
70 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 70 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28,
71 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, 71 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30,
72 0x31, 0x32, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00 72 0x31, 0x32, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00
73}; 73};
74 74
75 75
76OConfig* OGlobal::_config = 0; 76OConfig* OGlobal::_config = 0;
77OConfig* OGlobal::_qpe_config = 0; 77OConfig* OGlobal::_qpe_config = 0;
78 78
79void OGlobal::clean_up() { 79void OGlobal::clean_up()
80 qWarning( "Oglobal clean up" ); 80{
81 qDebug( "Oglobal clean up" );
81 delete OGlobal::_config; 82 delete OGlobal::_config;
82 delete OGlobal::_qpe_config; 83 delete OGlobal::_qpe_config;
83 OGlobal::_config = 0; 84 OGlobal::_config = 0;
84 OGlobal::_qpe_config = 0; 85 OGlobal::_qpe_config = 0;
85} 86}
86 87
87OConfig* OGlobal::config() 88OConfig* OGlobal::config()
88{ 89{
89 if ( !OGlobal::_config ) 90 if ( !OGlobal::_config )
90 { 91 {
91 // odebug classes are reading config, so can't use them here! 92 // odebug classes are reading config, so can't use them here!
92 qAddPostRoutine( OGlobal::clean_up ); 93 qAddPostRoutine( OGlobal::clean_up );
93 qDebug( "OGlobal::creating global configuration instance." ); 94 qDebug( "OGlobal::creating global configuration instance." );
94 OGlobal::_config = new OConfig( "global" ); 95 OGlobal::_config = new OConfig( "global" );
95 } 96 }
96 return OGlobal::_config; 97 return OGlobal::_config;
97} 98}
98 99
99 100
100/** 101/**
101 * Return the internal builtin Global::Command object 102 * Return the internal builtin Global::Command object
102 * 103 *
103 */ 104 */
104Global::Command* OGlobal::builtinCommands() { 105Global::Command* OGlobal::builtinCommands() {
105 return builtin; 106 return builtin;
106} 107}
107 108
108 109
109/** 110/**
110 * Return the internal builtin QGuardedPtr<QWidget> object 111 * Return the internal builtin QGuardedPtr<QWidget> object
111 */ 112 */
112QGuardedPtr<QWidget>* OGlobal::builtinRunning() { 113QGuardedPtr<QWidget>* OGlobal::builtinRunning() {
113 return running; 114 return running;
114} 115}
115 116
116 117
117/** 118/**
118 * \brief generate a new UUID as QString 119 * \brief generate a new UUID as QString
119 * Return a new UUID as QString. UUID are global unique 120 * Return a new UUID as QString. UUID are global unique
120 * 121 *
121 * 122 *
122 * @return the UUID or QString::null 123 * @return the UUID or QString::null
123 */ 124 */
124QString OGlobal::generateUuid() { 125QString OGlobal::generateUuid() {
125 QFile file( "/proc/sys/kernel/random/uuid" ); 126 QFile file( "/proc/sys/kernel/random/uuid" );
126 if (!file.open(IO_ReadOnly ) ) 127 if (!file.open(IO_ReadOnly ) )
127 return QString::null; 128 return QString::null;
128 129
129 QTextStream stream(&file); 130 QTextStream stream(&file);
130 131
131 return "{" + stream.read().stripWhiteSpace() + "}"; 132 return "{" + stream.read().stripWhiteSpace() + "}";
132} 133}
133 134
134 135
135/** 136/**
136 * \brief Encode a QByteArray in base64 137 * \brief Encode a QByteArray in base64
137 * 138 *
138 * An Implementation of the RF1521 base64 encoding. 139 * An Implementation of the RF1521 base64 encoding.
139 * 140 *
140 * The boolean argument determines if the encoded data is 141 * The boolean argument determines if the encoded data is
141 * going to be restricted to 76 characters or less per line 142 * going to be restricted to 76 characters or less per line
142 * as specified by RFC 2045. If @p insertLFs is true, then 143 * as specified by RFC 2045. If @p insertLFs is true, then
143 * there will be 76 characters or less per line. 144 * there will be 76 characters or less per line.
144 * 145 *
145 * If you use this to create a QCString remember that it is null terminated! 146 * If you use this to create a QCString remember that it is null terminated!
146 * \code 147 * \code
147 * QByteArray ar = OGlobal::encodeBase64(&array); 148 * QByteArray ar = OGlobal::encodeBase64(&array);
148 * QCString str(ar.data(),ar.size()+1); // the NUL at the end 149 * QCString str(ar.data(),ar.size()+1); // the NUL at the end
149 * 150 *
150 * \endcode 151 * \endcode
151 * 152 *
152 * @param in The QByteArray to encode 153 * @param in The QByteArray to encode
153 * @param insertLFs Limit number of characters per line 154 * @param insertLFs Limit number of characters per line
154 * @return The argument as base64 encoded or QByteArray() if in.isEmpty() 155 * @return The argument as base64 encoded or QByteArray() if in.isEmpty()
155 * @see QByteArray 156 * @see QByteArray
156 * @see QArray 157 * @see QArray
157 * @see QMemArray 158 * @see QMemArray
158 * @see QCString 159 * @see QCString
159 */ 160 */
160/* 161/*
161 * LGPL by Rik Hemsely of the KDE Project. taken from kmdcodec.cpp 162 * LGPL by Rik Hemsely of the KDE Project. taken from kmdcodec.cpp
162 */ 163 */
163QByteArray OGlobal::encodeBase64(const QByteArray& in, bool insertLFs ) { 164QByteArray OGlobal::encodeBase64(const QByteArray& in, bool insertLFs ) {
164 if ( in.isEmpty() ) 165 if ( in.isEmpty() )
165 return QByteArray(); 166 return QByteArray();
166 167
167 unsigned int sidx = 0; 168 unsigned int sidx = 0;
168 unsigned int didx = 0; 169 unsigned int didx = 0;
169 const char* data = in.data(); 170 const char* data = in.data();
170 const unsigned int len = in.size(); 171 const unsigned int len = in.size();
171 172
172 unsigned int out_len = ((len+2)/3)*4; 173 unsigned int out_len = ((len+2)/3)*4;
173 174
174 // Deal with the 76 characters or less per 175 // Deal with the 76 characters or less per
175 // line limit specified in RFC 2045 on a 176 // line limit specified in RFC 2045 on a
176 // pre request basis. 177 // pre request basis.
177 insertLFs = (insertLFs && out_len > 76); 178 insertLFs = (insertLFs && out_len > 76);
178 if ( insertLFs ) 179 if ( insertLFs )
179 out_len += ((out_len-1)/76); 180 out_len += ((out_len-1)/76);
180 181
181 int count = 0; 182 int count = 0;
182 QByteArray out( out_len ); 183 QByteArray out( out_len );
183 184
184 // 3-byte to 4-byte conversion + 0-63 to ascii printable conversion 185 // 3-byte to 4-byte conversion + 0-63 to ascii printable conversion
185 if ( len > 1 ) 186 if ( len > 1 )
186 { 187 {
187 while (sidx < len-2) 188 while (sidx < len-2)
188 { 189 {
189 if ( insertLFs ) 190 if ( insertLFs )
190 { 191 {
191 if ( count && (count%76) == 0 ) 192 if ( count && (count%76) == 0 )
192 out[didx++] = '\n'; 193 out[didx++] = '\n';
193 count += 4; 194 count += 4;
194 } 195 }
195 out[didx++] = Base64EncMap[(data[sidx] >> 2) & 077]; 196 out[didx++] = Base64EncMap[(data[sidx] >> 2) & 077];
196 out[didx++] = Base64EncMap[(data[sidx+1] >> 4) & 017 | 197 out[didx++] = Base64EncMap[(data[sidx+1] >> 4) & 017 |
197 (data[sidx] << 4) & 077]; 198 (data[sidx] << 4) & 077];
198 out[didx++] = Base64EncMap[(data[sidx+2] >> 6) & 003 | 199 out[didx++] = Base64EncMap[(data[sidx+2] >> 6) & 003 |
199 (data[sidx+1] << 2) & 077]; 200 (data[sidx+1] << 2) & 077];
200 out[didx++] = Base64EncMap[data[sidx+2] & 077]; 201 out[didx++] = Base64EncMap[data[sidx+2] & 077];
201 sidx += 3; 202 sidx += 3;
202 } 203 }
203 } 204 }
204 205
205 if (sidx < len) 206 if (sidx < len)
206 { 207 {
207 if ( insertLFs && (count > 0) && (count%76) == 0 ) 208 if ( insertLFs && (count > 0) && (count%76) == 0 )
208 out[didx++] = '\n'; 209 out[didx++] = '\n';
209 210
210 out[didx++] = Base64EncMap[(data[sidx] >> 2) & 077]; 211 out[didx++] = Base64EncMap[(data[sidx] >> 2) & 077];
211 if (sidx < len-1) 212 if (sidx < len-1)
212 { 213 {
213 out[didx++] = Base64EncMap[(data[sidx+1] >> 4) & 017 | 214 out[didx++] = Base64EncMap[(data[sidx+1] >> 4) & 017 |
214 (data[sidx] << 4) & 077]; 215 (data[sidx] << 4) & 077];
215 out[didx++] = Base64EncMap[(data[sidx+1] << 2) & 077]; 216 out[didx++] = Base64EncMap[(data[sidx+1] << 2) & 077];
216 } 217 }
217 else 218 else
218 { 219 {
219 out[didx++] = Base64EncMap[(data[sidx] << 4) & 077]; 220 out[didx++] = Base64EncMap[(data[sidx] << 4) & 077];
220 } 221 }
221 } 222 }
222 223
223 // Add padding 224 // Add padding
224 while (didx < out.size()) 225 while (didx < out.size())
225 { 226 {
226 out[didx] = '='; 227 out[didx] = '=';
227 didx++; 228 didx++;
228 } 229 }
229 230
230 return out; 231 return out;
231} 232}
232 233
233/** 234/**
234 * Decodes the given data that was encoded with the base64 235 * Decodes the given data that was encoded with the base64
235 * algorithm. 236 * algorithm.
236 * 237 *
237 * 238 *
238 * @param in the encoded data to be decoded. 239 * @param in the encoded data to be decoded.
239 * @return the decoded QByteArray or QByteArray() in case of failure 240 * @return the decoded QByteArray or QByteArray() in case of failure
240 * @see OGlobal::encodeBase64 241 * @see OGlobal::encodeBase64
241 */ 242 */
242QByteArray OGlobal::decodeBase64( const QByteArray& in) { 243QByteArray OGlobal::decodeBase64( const QByteArray& in) {
243 if ( in.isEmpty() ) 244 if ( in.isEmpty() )
244 return QByteArray(); 245 return QByteArray();
245 246
246 QByteArray out; 247 QByteArray out;
247 unsigned int count = 0; 248 unsigned int count = 0;
248 unsigned int len = in.size(), tail = len; 249 unsigned int len = in.size(), tail = len;
249 const char* data = in.data(); 250 const char* data = in.data();
250 251
251 // Deal with possible *nix "BEGIN" marker!! 252 // Deal with possible *nix "BEGIN" marker!!
252 while ( count < len && (data[count] == '\n' || data[count] == '\r' || 253 while ( count < len && (data[count] == '\n' || data[count] == '\r' ||
253 data[count] == '\t' || data[count] == ' ') ) 254 data[count] == '\t' || data[count] == ' ') )
254 count++; 255 count++;
255 256
256 if ( strncasecmp(data+count, "begin", 5) == 0 ) 257 if ( strncasecmp(data+count, "begin", 5) == 0 )
257 { 258 {
258 count += 5; 259 count += 5;
259 while ( count < len && data[count] != '\n' && data[count] != '\r' ) 260 while ( count < len && data[count] != '\n' && data[count] != '\r' )
260 count++; 261 count++;
261 262
262 while ( count < len && (data[count] == '\n' || data[count] == '\r') ) 263 while ( count < len && (data[count] == '\n' || data[count] == '\r') )
263 count ++; 264 count ++;
264 265
265 data += count; 266 data += count;
266 tail = (len -= count); 267 tail = (len -= count);
267 } 268 }
268 269
269 // Find the tail end of the actual encoded data even if 270 // Find the tail end of the actual encoded data even if
270 // there is/are trailing CR and/or LF. 271 // there is/are trailing CR and/or LF.
271 while ( data[tail-1] == '=' || data[tail-1] == '\n' || 272 while ( data[tail-1] == '=' || data[tail-1] == '\n' ||
272 data[tail-1] == '\r' ) 273 data[tail-1] == '\r' )
273 if ( data[--tail] != '=' ) len = tail; 274 if ( data[--tail] != '=' ) len = tail;
274 275
275 unsigned int outIdx = 0; 276 unsigned int outIdx = 0;
276 out.resize( (count=len) ); 277 out.resize( (count=len) );
277 for (unsigned int idx = 0; idx < count; idx++) 278 for (unsigned int idx = 0; idx < count; idx++)
278 { 279 {
279 // Adhere to RFC 2045 and ignore characters 280 // Adhere to RFC 2045 and ignore characters
280 // that are not part of the encoding table. 281 // that are not part of the encoding table.
281 unsigned char ch = data[idx]; 282 unsigned char ch = data[idx];
282 if ( (ch > 47 && ch < 58) || (ch > 64 && ch < 91 ) || 283 if ( (ch > 47 && ch < 58) || (ch > 64 && ch < 91 ) ||
283 (ch > 96 && ch < 123)|| ch == '+' || ch == '/' || ch == '=') 284 (ch > 96 && ch < 123)|| ch == '+' || ch == '/' || ch == '=')
284 { 285 {
285 out[outIdx++] = Base64DecMap[ch]; 286 out[outIdx++] = Base64DecMap[ch];
286 } 287 }
287 else 288 else
288 { 289 {
289 len--; 290 len--;
290 tail--; 291 tail--;
291 } 292 }
292 } 293 }
293 294
294 // kdDebug() << "Tail size = " << tail << ", Length size = " << len << endl; 295 // kdDebug() << "Tail size = " << tail << ", Length size = " << len << endl;
295 296
296 // 4-byte to 3-byte conversion 297 // 4-byte to 3-byte conversion
297 len = (tail>(len/4)) ? tail-(len/4) : 0; 298 len = (tail>(len/4)) ? tail-(len/4) : 0;
298 unsigned int sidx = 0, didx = 0; 299 unsigned int sidx = 0, didx = 0;
299 if ( len > 1 ) 300 if ( len > 1 )
300 { 301 {
301 while (didx < len-2) 302 while (didx < len-2)
302 { 303 {
303 out[didx] = (((out[sidx] << 2) & 255) | ((out[sidx+1] >> 4) & 003)); 304 out[didx] = (((out[sidx] << 2) & 255) | ((out[sidx+1] >> 4) & 003));
304 out[didx+1] = (((out[sidx+1] << 4) & 255) | ((out[sidx+2] >> 2) & 017)); 305 out[didx+1] = (((out[sidx+1] << 4) & 255) | ((out[sidx+2] >> 2) & 017));
305 out[didx+2] = (((out[sidx+2] << 6) & 255) | (out[sidx+3] & 077)); 306 out[didx+2] = (((out[sidx+2] << 6) & 255) | (out[sidx+3] & 077));
306 sidx += 4; 307 sidx += 4;
307 didx += 3; 308 didx += 3;
308 } 309 }
309 } 310 }
310 311
311 if (didx < len) 312 if (didx < len)
312 out[didx] = (((out[sidx] << 2) & 255) | ((out[sidx+1] >> 4) & 003)); 313 out[didx] = (((out[sidx] << 2) & 255) | ((out[sidx+1] >> 4) & 003));
313 314
314 if (++didx < len ) 315 if (++didx < len )
315 out[didx] = (((out[sidx+1] << 4) & 255) | ((out[sidx+2] >> 2) & 017)); 316 out[didx] = (((out[sidx+1] << 4) & 255) | ((out[sidx+2] >> 2) & 017));
316 317
317 // Resize the output buffer 318 // Resize the output buffer
318 if ( len == 0 || len < out.size() ) 319 if ( len == 0 || len < out.size() )
319 out.resize(len); 320 out.resize(len);
320 321
321 return out; 322 return out;
322} 323}
323 324
324bool OGlobal::isAppLnkFileName( const QString& str ) 325bool OGlobal::isAppLnkFileName( const QString& str )
325{ 326{
326 if (str.isEmpty()||str.at(str.length()-1)==QDir::separator()) return false; 327 if (str.isEmpty()||str.at(str.length()-1)==QDir::separator()) return false;
327 return str.startsWith(MimeType::appsFolderName()+QDir::separator()); 328 return str.startsWith(MimeType::appsFolderName()+QDir::separator());
328} 329}
329 330
330/* ToDo: 331/* ToDo:
331 * This fun should check the document-path value for the mounted media 332 * This fun should check the document-path value for the mounted media
332 * which has to be implemented later. this moment we just check for a 333 * which has to be implemented later. this moment we just check for a
333 * mounted media name. 334 * mounted media name.
334 */ 335 */
335bool OGlobal::isDocumentFileName( const QString& file ) 336bool OGlobal::isDocumentFileName( const QString& file )
336{ 337{
337 if (file.isEmpty()||file.at(file.length()-1)==QDir::separator()) return false; 338 if (file.isEmpty()||file.at(file.length()-1)==QDir::separator()) return false;
338 if (file.startsWith(QPEApplication::documentDir()+QDir::separator())) return true; 339 if (file.startsWith(QPEApplication::documentDir()+QDir::separator())) return true;
339 StorageInfo si; 340 StorageInfo si;
340 QList< FileSystem > fl = si.fileSystems(); 341 QList< FileSystem > fl = si.fileSystems();
341 FileSystem*fs; 342 FileSystem*fs;
342 for (fs = fl.first();fs!=0;fs=fl.next()) { 343 for (fs = fl.first();fs!=0;fs=fl.next()) {
343 if (fs->isRemovable()&&file.startsWith(fs->name()+QDir::separator())) 344 if (fs->isRemovable()&&file.startsWith(fs->name()+QDir::separator()))
344 return true; 345 return true;
345 } 346 }
346 if (file.startsWith(homeDirPath())+"/Documents/") return true; 347 if (file.startsWith(homeDirPath())+"/Documents/") return true;
347 return false; 348 return false;
348} 349}
349 350
350QString OGlobal::tempDirPath() 351QString OGlobal::tempDirPath()
351{ 352{
352 static QString defstring="/tmp"; 353 static QString defstring="/tmp";
353 char * tmpp = 0; 354 char * tmpp = 0;
354 if ( (tmpp=getenv("TEMP"))) { 355 if ( (tmpp=getenv("TEMP"))) {
355 return tmpp; 356 return tmpp;
356 } 357 }
357 return defstring; 358 return defstring;
358} 359}
359 360
360QString OGlobal::homeDirPath() 361QString OGlobal::homeDirPath()
361{ 362{
362 char * tmpp = getenv("HOME"); 363 char * tmpp = getenv("HOME");
363 return (tmpp?tmpp:"/"); 364 return (tmpp?tmpp:"/");
364} 365}
365 366
366bool OGlobal::weekStartsOnMonday() 367bool OGlobal::weekStartsOnMonday()
367{ 368{
368 OConfig*conf=OGlobal::qpe_config(); 369 OConfig*conf=OGlobal::qpe_config();
369 if (!conf)return false; 370 if (!conf)return false;
370 conf->setGroup("Time"); 371 conf->setGroup("Time");
371 return conf->readBoolEntry("MONDAY",true); 372 return conf->readBoolEntry("MONDAY",true);
372} 373}
373 374
374void OGlobal::setWeekStartsOnMonday( bool what) 375void OGlobal::setWeekStartsOnMonday( bool what)
375{ 376{
376 OConfig*conf=OGlobal::qpe_config(); 377 OConfig*conf=OGlobal::qpe_config();
377 if (!conf)return; 378 if (!conf)return;
378 conf->setGroup("Time"); 379 conf->setGroup("Time");
379 return conf->writeEntry("MONDAY",what); 380 return conf->writeEntry("MONDAY",what);
380} 381}
381 382
382bool OGlobal::useAMPM() 383bool OGlobal::useAMPM()
383{ 384{
384 OConfig*conf=OGlobal::qpe_config(); 385 OConfig*conf=OGlobal::qpe_config();
385 if (!conf)return false; 386 if (!conf)return false;
386 conf->setGroup("Time"); 387 conf->setGroup("Time");
387 return conf->readBoolEntry("AMPM",false); 388 return conf->readBoolEntry("AMPM",false);
388} 389}
389 390
390void OGlobal::setUseAMPM( bool what) 391void OGlobal::setUseAMPM( bool what)
391{ 392{
392 OConfig*conf=OGlobal::qpe_config(); 393 OConfig*conf=OGlobal::qpe_config();
393 if (!conf)return; 394 if (!conf)return;
394 conf->setGroup("Time"); 395 conf->setGroup("Time");
395 return conf->writeEntry("AMPM",what); 396 return conf->writeEntry("AMPM",what);
396} 397}
397 398
398OConfig* OGlobal::qpe_config() 399OConfig* OGlobal::qpe_config()
399{ 400{
400 if ( !OGlobal::_qpe_config ) { 401 if ( !OGlobal::_qpe_config ) {
401 OGlobal::_qpe_config = new OConfig( "qpe" ); 402 OGlobal::_qpe_config = new OConfig( "qpe" );
402 } 403 }
403 return OGlobal::_qpe_config; 404 return OGlobal::_qpe_config;
404} 405}
405 406
406bool OGlobal::truncateFile( QFile &f, off_t size ) 407bool OGlobal::truncateFile( QFile &f, off_t size )
407{ 408{
408 /* or should we let enlarge Files? then remove this 409 /* or should we let enlarge Files? then remove this
409 f.size()< part! - Alwin 410 f.size()< part! - Alwin
410 */ 411 */
411 if (!f.exists()||f.size()<(unsigned)size) return false; 412 if (!f.exists()||f.size()<(unsigned)size) return false;
412 bool closeit=false; 413 bool closeit=false;
413 if (!f.isOpen()) { 414 if (!f.isOpen()) {
414 closeit=true; 415 closeit=true;
415 f.open(IO_Raw | IO_ReadWrite | IO_Append); 416 f.open(IO_Raw | IO_ReadWrite | IO_Append);
416 } 417 }
417 if (!f.isOpen()) { return false; } 418 if (!f.isOpen()) { return false; }
418 int r = ftruncate(f.handle(),size); 419 int r = ftruncate(f.handle(),size);
419 if (closeit) f.close(); 420 if (closeit) f.close();
420 return r==0; 421 return r==0;
421} 422}