summaryrefslogtreecommitdiff
path: root/libopie2
Unidiff
Diffstat (limited to 'libopie2') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiecore/odebug.cpp229
-rw-r--r--libopie2/opiecore/oglobal.cpp9
-rw-r--r--libopie2/opiecore/oglobal.h5
3 files changed, 132 insertions, 111 deletions
diff --git a/libopie2/opiecore/odebug.cpp b/libopie2/opiecore/odebug.cpp
index f258faa..3bffdd0 100644
--- a/libopie2/opiecore/odebug.cpp
+++ b/libopie2/opiecore/odebug.cpp
@@ -1,634 +1,645 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 (C) 2003 Michael 'Mickey' Lauer (mickey@tm.informatik.uni-frankfurt.de) 3 (C) 2003 Michael 'Mickey' Lauer (mickey@tm.informatik.uni-frankfurt.de)
4 (C) 2002 Holger Freyther (freyther@kde.org) 4 (C) 2002 Holger Freyther (freyther@kde.org)
5 (C) 1997 Matthias Kalle Dalheimer (kalle@kde.org) 5 (C) 1997 Matthias Kalle Dalheimer (kalle@kde.org)
6 =. 6 =.
7 .=l. 7 .=l.
8           .>+-= 8           .>+-=
9 _;:,     .>    :=|. This program is free software; you can 9 _;:,     .>    :=|. This program is free software; you can
10.> <`_,   >  .   <= redistribute it and/or modify it under 10.> <`_,   >  .   <= redistribute it and/or modify it under
11:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 11:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
12.="- .-=="i,     .._ License as published by the Free Software 12.="- .-=="i,     .._ License as published by the Free Software
13 - .   .-<_>     .<> Foundation; either version 2 of the License, 13 - .   .-<_>     .<> Foundation; either version 2 of the License,
14     ._= =}       : or (at your option) any later version. 14     ._= =}       : or (at your option) any later version.
15    .%`+i>       _;_. 15    .%`+i>       _;_.
16    .i_,=:_.      -<s. This program is distributed in the hope that 16    .i_,=:_.      -<s. This program is distributed in the hope that
17     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 17     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
18    : ..    .:,     . . . without even the implied warranty of 18    : ..    .:,     . . . without even the implied warranty of
19    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 19    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
20  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 20  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
21..}^=.=       =       ; Library General Public License for more 21..}^=.=       =       ; Library General Public License for more
22++=   -.     .`     .: details. 22++=   -.     .`     .: details.
23 :     =  ...= . :.=- 23 :     =  ...= . :.=-
24 -.   .:....=;==+<; You should have received a copy of the GNU 24 -.   .:....=;==+<; You should have received a copy of the GNU
25  -_. . .   )=.  = Library General Public License along with 25  -_. . .   )=.  = Library General Public License along with
26    --        :-=` this library; see the file COPYING.LIB. 26    --        :-=` this library; see the file COPYING.LIB.
27 If not, write to the Free Software Foundation, 27 If not, write to the Free Software Foundation,
28 Inc., 59 Temple Place - Suite 330, 28 Inc., 59 Temple Place - Suite 330,
29 Boston, MA 02111-1307, USA. 29 Boston, MA 02111-1307, USA.
30*/ 30*/
31 31
32// Include this header without OPIE_NO_DEBUG defined to avoid having the oDebugInfo 32// Include this header without OPIE_NO_DEBUG defined to avoid having the oDebugInfo
33// functions inlined to noops (which would then conflict with their definition here). 33// functions inlined to noops (which would then conflict with their definition here).
34 34
35#include <opie2/odebug.h> 35#include <opie2/odebug.h>
36 36
37#ifdef OPIE_NO_DEBUG 37#ifdef OPIE_NO_DEBUG
38#undef odDebug 38#undef odDebug
39#undef odBacktrace 39#undef odBacktrace
40#endif 40#endif
41 41
42/* OPIE */ 42/* OPIE */
43 43
44#include <opie2/oapplication.h> 44#include <opie2/oapplication.h>
45#include <opie2/oglobalsettings.h> 45#include <opie2/oglobalsettings.h>
46#include <opie2/oconfig.h> 46#include <opie2/oconfig.h>
47 47
48/* QT */ 48/* QT */
49 49
50#include <qfile.h> 50#include <qfile.h>
51#include <qmessagebox.h> 51#include <qmessagebox.h>
52#include <qsocketdevice.h> 52#include <qsocketdevice.h>
53 53
54/* UNIX */ 54/* UNIX */
55 55
56#include <stdlib.h> // abort 56#include <stdlib.h> // abort
57#include <unistd.h> // getpid 57#include <unistd.h> // getpid
58#include <stdarg.h> // vararg stuff 58#include <stdarg.h> // vararg stuff
59#include <ctype.h> // isprint 59#include <ctype.h> // isprint
60#include <syslog.h> 60#include <syslog.h>
61#include <errno.h> 61#include <errno.h>
62#include <string.h> 62#include <string.h>
63 63
64#ifndef OPIE_NO_BACKTRACE 64#ifndef OPIE_NO_BACKTRACE
65#include <execinfo.h> 65#include <execinfo.h>
66#endif 66#endif
67 67
68namespace Opie { 68namespace Opie {
69namespace Core { 69namespace Core {
70namespace Internal { 70namespace Internal {
71class DebugBackend {
72};
73
74static DebugBackend *backEnd = 0;
75}
76static void clean_up_routine() {
77 delete Internal::backEnd;
78}
79/*====================================================================================== 71/*======================================================================================
80 * debug levels 72 * debug levels
81 *======================================================================================*/ 73 *======================================================================================*/
82 74
83enum DebugLevels { 75enum DebugLevels {
84 ODEBUG_INFO = 0, 76 ODEBUG_INFO = 0,
85 ODEBUG_WARN = 1, 77 ODEBUG_WARN = 1,
86 ODEBUG_ERROR = 2, 78 ODEBUG_ERROR = 2,
87 ODEBUG_FATAL = 3 79 ODEBUG_FATAL = 3
88}; 80};
89 81
90/*====================================================================================== 82/*======================================================================================
91 * oDebug private data 83 * oDebug private data
92 *======================================================================================*/ 84 *======================================================================================*/
93 85
94/*====================================================================================== 86/*======================================================================================
95 * the main debug function 87 * the main debug function
96 *======================================================================================*/ 88 *======================================================================================*/
97 89
98static void oDebugBackend( unsigned short level, unsigned int area, const char *data) 90
99{ 91
92struct DebugBackend {
93 DebugBackend() : m_opened( false ), m_file( 0 ) ,m_port( -1 ),m_sock( 0 ) {
94 m_outp = OGlobalSettings::debugMode();
95 }
96 ~DebugBackend() {
97 delete m_file;
98 delete m_sock;
99 }
100 void debug( unsigned short level, unsigned int, const QString& data );
101
102private:
103 void debugFile( const QString&, const QString& data );
104 void debugMsgB( const QString&, const QString& data );
105 void debugShel( const QString&, const QString& data );
106 void debugSysl( int, const QString& );
107 void debugSock( const QString&, const QString& data );
108 QCString line( const QString&, const QString& data );
109 bool m_opened : 1;
110 QFile *m_file;
111 QHostAddress m_addr;
112 int m_port;
113 QSocketDevice *m_sock;
114 short m_outp;
115};
116
117void DebugBackend::debug(unsigned short level, unsigned int, const QString& data) {
100 //qDebug( "oDebugBackend: Level=%d, Area=%d, Data=%s", level, area, data ); 118 //qDebug( "oDebugBackend: Level=%d, Area=%d, Data=%s", level, area, data );
101 119
102 // ML: OPIE doesn't use areacodes at the moment. See the KDE debug classes for an 120 // ML: OPIE doesn't use areacodes at the moment. See the KDE debug classes for an
103 // ML: example use. I think it's not necessary to implement such a strategy here. 121 // ML: example use. I think it's not necessary to implement such a strategy here.
104 // ML: Comments? 122 // ML: Comments?
105 123
106 int priority = 0; 124 int priority = 0;
107 QString caption; 125 QString caption;
108 QString lev; 126 QString lev;
109 switch( level ) 127 switch( level )
110 { 128 {
111 case ODEBUG_INFO: lev = "(Info)"; caption = "Info"; priority = LOG_INFO; break; 129 case ODEBUG_INFO: lev = "(Info)"; caption = "Info"; priority = LOG_INFO; break;
112 case ODEBUG_WARN: lev = "(Warn)"; caption = "Warning"; priority = LOG_WARNING; break; 130 case ODEBUG_WARN: lev = "(Warn)"; caption = "Warning"; priority = LOG_WARNING; break;
113 case ODEBUG_FATAL: lev = "(Fatal)"; caption = "Fatal Error"; priority = LOG_CRIT; break; 131 case ODEBUG_FATAL: lev = "(Fatal)"; caption = "Fatal Error"; priority = LOG_CRIT; break;
114 default: qDebug( "oDebugBackend: Warning: Unknown debug level! - defaulting to ODEBUG_ERROR." ); 132 default: qDebug( "oDebugBackend: Warning: Unknown debug level! - defaulting to ODEBUG_ERROR." );
115 case ODEBUG_ERROR: lev = "(Error)"; caption = "Error"; priority = LOG_ERR; break; 133 case ODEBUG_ERROR: lev = "(Error)"; caption = "Error"; priority = LOG_ERR; break;
116 } 134 }
117 135
118 short output = OGlobalSettings::debugMode(); 136 if (!oApp && (m_outp == 1)) {
119 if (!oApp && (output == 1))
120 {
121 qDebug( "oDebugBackend: Warning: no oapplication object - can't use MsgBox" ); 137 qDebug( "oDebugBackend: Warning: no oapplication object - can't use MsgBox" );
122 output = 2; // need an application object to use MsgBox 138 m_outp = 2; // need an application object to use MsgBox
123 } 139 }
124 140
125 // gcc 2.9x is dumb and sucks... can you hear it? 141 // gcc 2.9x is dumb and sucks... can you hear it?
126 //QString areaName = (oApp) ? oApp->appName() : "<unknown>"; 142 //QString areaName = (oApp) ? oApp->appName() : "<unknown>";
127 QString areaName; 143 QString areaName;
128 if ( oApp ) areaName = oApp->appName(); 144 if ( oApp ) areaName = oApp->appName();
129 else areaName = "<unknown>"; 145 else areaName = "<unknown>";
130 146
131 // Output 147 switch( m_outp ) {
132 switch( output ) 148 case -1: // ignore
133 { 149 return;
134 case -1: // ignore 150 case 0: // File
135 { 151 return debugFile( areaName, data );
152 case 1: // Message Box
153 return debugMsgB( areaName, data );
154 case 2:
155 return debugShel( areaName,data );
156 case 3: // syslog
157 return debugSysl( priority, data );
158 case 4: // socket
159 return debugSock( areaName, data );
160 }
161}
162
163inline void DebugBackend::debugFile(const QString& area, const QString& data) {
164 /* something went wrong with the file don't bother.. */
165 if ( m_opened && !m_file )
166 return;
167 else if ( !m_opened ) {
168 m_opened = true;
169 m_file = new QFile( OGlobalSettings::debugOutput() );
170 if (!m_file->open( IO_WriteOnly | IO_Append ) ) {
171 delete m_file; m_file = 0;
172 qDebug( "ODebug: can't write to file '%s' (%s)", (const char*)OGlobalSettings::debugOutput(),
173 strerror(errno) );
136 return; 174 return;
137 } 175 }
138 case 0: // File 176 }
139 {
140 QString outputFilename = OGlobalSettings::debugOutput();
141
142 const int BUFSIZE = 4096;
143 char buf[BUFSIZE] = "";
144 buf[BUFSIZE-1] = '\0';
145 int nSize;
146
147 nSize = snprintf( buf, BUFSIZE-1, "%s: %s", (const char*) areaName, data);
148
149 QFile outputFile( outputFilename );
150 if ( outputFile.open( IO_WriteOnly | IO_Append ) )
151 {
152 if ( ( nSize == -1 ) || ( nSize >= BUFSIZE ) )
153 {
154 outputFile.writeBlock( buf, BUFSIZE-1 );
155 }
156 else
157 {
158 outputFile.writeBlock( buf, nSize );
159 }
160 }
161 else
162 {
163 qDebug( "ODebug: can't write to file '%s' (%s)", (const char*) outputFilename, strerror(errno) );
164 }
165 break;
166 } // automatic close of file here
167
168 case 1: // Message Box
169 {
170 // Since we are in opiecore here, we cannot use OMsgBox and use
171 // QMessageBox instead
172 177
173 caption += QString("(") + areaName + ")"; 178 /* go to end of file */
174 QMessageBox::warning( 0L, caption, data, ("&OK") ); // tr? 179 m_file->at( m_file->size() );
175 break; 180 QCString li = line( area, data );
176 } 181 m_file->writeBlock(li.data(), li.length() );
182}
177 183
178 case 2: // Shell 184void DebugBackend::debugMsgB( const QString& area, const QString& data ) {
179 { 185 QMessageBox::warning( 0l, "("+area+")", data, ("Ok") );
180 FILE *output = stderr; 186}
181 fprintf( output, "%s: ", (const char*) areaName );
182 fputs( data, output);
183 break;
184 }
185 187
186 case 3: // syslog 188void DebugBackend::debugShel( const QString& are, const QString& data ) {
187 { 189 FILE *output = stderr;
188 syslog( priority, "%s", data); 190 fprintf( output, "%s: %s", are.local8Bit().data(),
189 break; 191 data.local8Bit().data() );
190 } 192}
191 193
192 case 4: // socket 194void DebugBackend::debugSysl( int prio, const QString& data ) {
193 { 195 ::syslog( prio, "%s", data.local8Bit().data() );
194 QString destination = OGlobalSettings::debugOutput(); 196}
195 if ( destination && destination.find(":") != -1 ) 197
196 { 198void DebugBackend::debugSock( const QString& are, const QString& data ) {
197 QString host = destination.left( destination.find(":") ); 199 if ( m_opened && !m_sock )
198 QString port = destination.right( destination.length()-host.length()-1 ); 200 return;
199 QHostAddress addr; 201 else if ( !m_opened ){
200 addr.setAddress( host ); 202 m_opened = true;
201 // TODO: sanity check the address 203 QString destination = OGlobalSettings::debugOutput();
202 QString line; 204 if ( destination && destination.find(":") != -1 ) {
203 line.sprintf( "%s: %s", (const char*) areaName, (const char*) data ); 205 QString host = destination.left( destination.find(":") );
204 QSocketDevice s( QSocketDevice::Datagram ); 206 m_port = destination.right( destination.length()-host.length()-1 ).toInt();
205 int result = s.writeBlock( (const char*) line, line.length(), addr, port.toInt() ); 207 m_addr.setAddress( host );
206 if ( result == -1 ) 208 m_sock = new QSocketDevice( QSocketDevice::Datagram );
207 { 209 }else{
208 qDebug( "ODebug: can't send to address '%s:%d' (%s)", (const char*) host, port.toInt(), strerror(errno) ); 210 m_sock = 0;
209 } 211 return;
210 }
211 break;
212 } 212 }
213 } 213 }
214 214
215 // check if we should abort 215 QCString li = line( are, data );
216 216 int result = m_sock->writeBlock(li.data(), li.length(), m_addr, m_port );
217 /* 217 if ( result == -1 ) {
218 218 qDebug( "ODebug: can't send to address '"+ m_addr.toString() +":%d' (%s)",
219 if( ( nLevel == ODEBUG_FATAL ) 219 m_port, strerror(errno) );
220 && ( !oDebug_data->config || oDebug_data->config->readNumEntry( "AbortFatal", 1 ) ) ) 220 }
221 abort(); 221}
222 222
223 */ 223QCString DebugBackend::line( const QString& area, const QString& data ) {
224 QString str = area +":"+data;
225 return str.local8Bit();
224} 226}
225 227
228static DebugBackend *backEnd = 0;
229}
230static void clean_up_routine() {
231 qWarning( "Clean up Debug" );
232 delete Internal::backEnd;
233 Internal::backEnd = 0;
234}
226/*====================================================================================== 235/*======================================================================================
227 * odbgstream 236 * odbgstream
228 *======================================================================================*/ 237 *======================================================================================*/
229 238
230odbgstream& perror( odbgstream &s) 239odbgstream& perror( odbgstream &s)
231{ 240{
232 return s << QString::fromLocal8Bit(strerror(errno)); 241 return s << QString::fromLocal8Bit(strerror(errno));
233} 242}
234 243
235odbgstream odDebug(int area) 244odbgstream odDebug(int area)
236{ 245{
237 return odbgstream(area, ODEBUG_INFO); 246 return odbgstream(area, Internal::ODEBUG_INFO);
238} 247}
239odbgstream odDebug(bool cond, int area) 248odbgstream odDebug(bool cond, int area)
240{ 249{
241 if (cond) return odbgstream(area, ODEBUG_INFO); 250 if (cond) return odbgstream(area, Internal::ODEBUG_INFO);
242 else return odbgstream(0, 0, false); 251 else return odbgstream(0, 0, false);
243} 252}
244 253
245odbgstream odError(int area) 254odbgstream odError(int area)
246{ 255{
247 return odbgstream("ERROR: ", area, ODEBUG_ERROR); 256 return odbgstream("ERROR: ", area, Internal::ODEBUG_ERROR);
248} 257}
249 258
250odbgstream odError(bool cond, int area) 259odbgstream odError(bool cond, int area)
251{ 260{
252 if (cond) return odbgstream("ERROR: ", area, ODEBUG_ERROR); else return odbgstream(0,0,false); 261 if (cond) return odbgstream("ERROR: ", area, Internal::ODEBUG_ERROR); else return odbgstream(0,0,false);
253} 262}
254 263
255odbgstream odWarning(int area) 264odbgstream odWarning(int area)
256{ 265{
257 return odbgstream("WARNING: ", area, ODEBUG_WARN); 266 return odbgstream("WARNING: ", area, Internal::ODEBUG_WARN);
258} 267}
259 268
260odbgstream odWarning(bool cond, int area) 269odbgstream odWarning(bool cond, int area)
261{ 270{
262 if (cond) return odbgstream("WARNING: ", area, ODEBUG_WARN); else return odbgstream(0,0,false); 271 if (cond) return odbgstream("WARNING: ", area, Internal::ODEBUG_WARN); else return odbgstream(0,0,false);
263} 272}
264 273
265odbgstream odFatal(int area) 274odbgstream odFatal(int area)
266{ 275{
267 return odbgstream("FATAL: ", area, ODEBUG_FATAL); 276 return odbgstream("FATAL: ", area, Internal::ODEBUG_FATAL);
268} 277}
269 278
270odbgstream odFatal(bool cond, int area) 279odbgstream odFatal(bool cond, int area)
271{ 280{
272 if (cond) return odbgstream("FATAL: ", area, ODEBUG_FATAL); else return odbgstream(0,0,false); 281 if (cond) return odbgstream("FATAL: ", area, Internal::ODEBUG_FATAL); else return odbgstream(0,0,false);
273} 282}
274 283
275odbgstream::odbgstream(unsigned int _area, unsigned int _level, bool _print) 284odbgstream::odbgstream(unsigned int _area, unsigned int _level, bool _print)
276 :area(_area), level(_level), print(_print) 285 :area(_area), level(_level), print(_print)
277{ 286{
278} 287}
279 288
280 289
281odbgstream::odbgstream(const char * initialString, unsigned int _area, unsigned int _level, bool _print) 290odbgstream::odbgstream(const char * initialString, unsigned int _area, unsigned int _level, bool _print)
282 :output(QString::fromLatin1(initialString)), area(_area), level(_level), print(_print) 291 :output(QString::fromLatin1(initialString)), area(_area), level(_level), print(_print)
283{ 292{
284} 293}
285 294
286 295
287odbgstream::odbgstream(odbgstream &str) 296odbgstream::odbgstream(odbgstream &str)
288 :output(str.output), area(str.area), level(str.level), print(str.print) 297 :output(str.output), area(str.area), level(str.level), print(str.print)
289{ 298{
290 str.output.truncate(0); 299 str.output.truncate(0);
291} 300}
292 301
293 302
294odbgstream::odbgstream(const odbgstream &str) 303odbgstream::odbgstream(const odbgstream &str)
295 :output(str.output), area(str.area), level(str.level), print(str.print) 304 :output(str.output), area(str.area), level(str.level), print(str.print)
296{ 305{
297} 306}
298 307
299odbgstream& odbgstream::operator<<(bool i) 308odbgstream& odbgstream::operator<<(bool i)
300{ 309{
301 if (!print) return *this; 310 if (!print) return *this;
302 output += QString::fromLatin1(i ? "true" : "false"); 311 output += QString::fromLatin1(i ? "true" : "false");
303 return *this; 312 return *this;
304} 313}
305 314
306 315
307odbgstream& odbgstream::operator<<(short i) 316odbgstream& odbgstream::operator<<(short i)
308{ 317{
309 if (!print) return *this; 318 if (!print) return *this;
310 QString tmp; tmp.setNum(i); output += tmp; 319 QString tmp; tmp.setNum(i); output += tmp;
311 return *this; 320 return *this;
312} 321}
313 322
314 323
315odbgstream& odbgstream::operator<<(unsigned short i) 324odbgstream& odbgstream::operator<<(unsigned short i)
316{ 325{
317 if (!print) return *this; 326 if (!print) return *this;
318 QString tmp; tmp.setNum(i); output += tmp; 327 QString tmp; tmp.setNum(i); output += tmp;
319 return *this; 328 return *this;
320} 329}
321 330
322 331
323odbgstream& odbgstream::operator<<(unsigned char i) 332odbgstream& odbgstream::operator<<(unsigned char i)
324{ 333{
325 return operator<<( static_cast<char>( i ) ); 334 return operator<<( static_cast<char>( i ) );
326} 335}
327 336
328 337
329odbgstream& odbgstream::operator<<(int i) 338odbgstream& odbgstream::operator<<(int i)
330{ 339{
331 if (!print) return *this; 340 if (!print) return *this;
332 QString tmp; tmp.setNum(i); output += tmp; 341 QString tmp; tmp.setNum(i); output += tmp;
333 return *this; 342 return *this;
334} 343}
335 344
336 345
337odbgstream& odbgstream::operator<<(unsigned int i) 346odbgstream& odbgstream::operator<<(unsigned int i)
338{ 347{
339 if (!print) return *this; 348 if (!print) return *this;
340 QString tmp; tmp.setNum(i); output += tmp; 349 QString tmp; tmp.setNum(i); output += tmp;
341 return *this; 350 return *this;
342} 351}
343 352
344 353
345odbgstream& odbgstream::operator<<(long i) 354odbgstream& odbgstream::operator<<(long i)
346{ 355{
347 if (!print) return *this; 356 if (!print) return *this;
348 QString tmp; tmp.setNum(i); output += tmp; 357 QString tmp; tmp.setNum(i); output += tmp;
349 return *this; 358 return *this;
350} 359}
351 360
352 361
353odbgstream& odbgstream::operator<<(unsigned long i) 362odbgstream& odbgstream::operator<<(unsigned long i)
354{ 363{
355 if (!print) return *this; 364 if (!print) return *this;
356 QString tmp; tmp.setNum(i); output += tmp; 365 QString tmp; tmp.setNum(i); output += tmp;
357 return *this; 366 return *this;
358} 367}
359 368
360 369
361odbgstream& odbgstream::operator<<(const QString& string) 370odbgstream& odbgstream::operator<<(const QString& string)
362{ 371{
363 if (!print) return *this; 372 if (!print) return *this;
364 output += string; 373 output += string;
365 if (output.at(output.length() -1 ) == '\n') 374 if (output.at(output.length() -1 ) == '\n')
366 flush(); 375 flush();
367 return *this; 376 return *this;
368} 377}
369 378
370 379
371odbgstream& odbgstream::operator<<(const char *string) 380odbgstream& odbgstream::operator<<(const char *string)
372{ 381{
373 if (!print) return *this; 382 if (!print) return *this;
374 output += QString::fromUtf8(string); 383 output += QString::fromUtf8(string);
375 if (output.at(output.length() - 1) == '\n') 384 if (output.at(output.length() - 1) == '\n')
376 flush(); 385 flush();
377 return *this; 386 return *this;
378} 387}
379 388
380 389
381odbgstream& odbgstream::operator<<(const QCString& string) 390odbgstream& odbgstream::operator<<(const QCString& string)
382{ 391{
383 *this << string.data(); 392 *this << string.data();
384 return *this; 393 return *this;
385} 394}
386 395
387 396
388odbgstream& odbgstream::operator<<(const void * p) 397odbgstream& odbgstream::operator<<(const void * p)
389{ 398{
390 form("%p", p); 399 form("%p", p);
391 return *this; 400 return *this;
392} 401}
393 402
394odbgstream& odbgstream::operator<<(double d) 403odbgstream& odbgstream::operator<<(double d)
395{ 404{
396 QString tmp; tmp.setNum(d); output += tmp; 405 QString tmp; tmp.setNum(d); output += tmp;
397 return *this; 406 return *this;
398} 407}
399 408
400/* 409/*
401odbgstream::odbgstream &form(const char *format, ...) 410odbgstream::odbgstream &form(const char *format, ...)
402#ifdef __GNUC__ 411#ifdef __GNUC__
403 __attribute__ ( ( format ( printf, 2, 3 ) ) ) 412 __attribute__ ( ( format ( printf, 2, 3 ) ) )
404#endif 413#endif
405 ; 414 ;
406*/ 415*/
407 416
408void odbgstream::flush() 417void odbgstream::flush()
409{ 418{
410 if ( output.isEmpty() || !print ) 419 if ( output.isEmpty() || !print )
411 { 420 {
412 return; 421 return;
413 } 422 }
414 else 423 else
415 { 424 {
416 oDebugBackend( level, area, output.local8Bit().data() ); 425 if ( !Internal::backEnd ) {
426 Internal::backEnd = new Internal::DebugBackend;
427 qAddPostRoutine( clean_up_routine );
428 }
429 Internal::backEnd->debug( level, area, output );
417 output = QString::null; 430 output = QString::null;
418 } 431 }
419} 432}
420 433
421odbgstream& odbgstream::form(const char *format, ...) 434odbgstream& odbgstream::form(const char *format, ...)
422{ 435{
423 char buf[4096]; 436 char buf[4096];
424 va_list arguments; 437 va_list arguments;
425 va_start( arguments, format ); 438 va_start( arguments, format );
426 buf[sizeof(buf)-1] = '\0'; 439 buf[sizeof(buf)-1] = '\0';
427 vsnprintf( buf, sizeof(buf)-1, format, arguments ); 440 vsnprintf( buf, sizeof(buf)-1, format, arguments );
428 va_end(arguments); 441 va_end(arguments);
429 *this << buf; 442 *this << buf;
430 return *this; 443 return *this;
431} 444}
432 445
433odbgstream::~odbgstream() 446odbgstream::~odbgstream()
434{ 447{
435 if (!output.isEmpty()) 448 if (!output.isEmpty())
436 { 449 {
437 fprintf(stderr, "ASSERT: debug output not ended with \\n\n"); 450 fprintf(stderr, "ASSERT: debug output not ended with \\n\n");
438 *this << "\n"; 451 *this << "\n";
439 } 452 }
440} 453}
441 454
442odbgstream& odbgstream::operator<<(char ch) 455odbgstream& odbgstream::operator<<(char ch)
443{ 456{
444 if (!print) return *this; 457 if (!print) return *this;
445 if (!isprint(ch)) 458 if (!isprint(ch))
446 { 459 {
447 output += "\\x" + QString::number( static_cast<uint>( ch ) + 0x100, 16 ).right(2); 460 output += "\\x" + QString::number( static_cast<uint>( ch ) + 0x100, 16 ).right(2);
448 } 461 }
449 else 462 else
450 { 463 {
451 output += ch; 464 output += ch;
452 if (ch == '\n') flush(); 465 if (ch == '\n') flush();
453 } 466 }
454 return *this; 467 return *this;
455} 468}
456 469
457odbgstream& odbgstream::operator<<( QWidget* widget ) 470odbgstream& odbgstream::operator<<( QWidget* widget )
458{ 471{
459 QString string, temp; 472 QString string, temp;
460 // ----- 473 // -----
461 if(widget==0) 474 if(widget==0)
462 { 475 {
463 string=(QString)"[Null pointer]"; 476 string=(QString)"[Null pointer]";
464 } else 477 } else
465 { 478 {
466 temp.setNum((ulong)widget, 16); 479 temp.setNum((ulong)widget, 16);
467 string=(QString)"["+widget->className()+" pointer " + "(0x" + temp + ")"; 480 string=(QString)"["+widget->className()+" pointer " + "(0x" + temp + ")";
468 if(widget->name(0)==0) 481 if(widget->name(0)==0)
469 { 482 {
470 string += " to unnamed widget, "; 483 string += " to unnamed widget, ";
471 } else 484 } else
472 { 485 {
473 string += (QString)" to widget " + widget->name() + ", "; 486 string += (QString)" to widget " + widget->name() + ", ";
474 } 487 }
475 string += "geometry=" 488 string += "geometry="
476 + QString().setNum(widget->width()) 489 + QString().setNum(widget->width())
477 + "x"+QString().setNum(widget->height()) 490 + "x"+QString().setNum(widget->height())
478 + "+"+QString().setNum(widget->x()) 491 + "+"+QString().setNum(widget->x())
479 + "+"+QString().setNum(widget->y()) 492 + "+"+QString().setNum(widget->y())
480 + "]"; 493 + "]";
481 } 494 }
482 if (!print) return *this; 495 if (!print) return *this;
483 496
484 output += string; 497 output += string;
485 if (output.at(output.length()-1) == '\n') 498 if (output.at(output.length()-1) == '\n')
486 { 499 {
487 flush(); 500 flush();
488 } 501 }
489 return *this; 502 return *this;
490} 503}
491 504
492/* 505/*
493 * either use 'output' directly and do the flush if needed 506 * either use 'output' directly and do the flush if needed
494 * or use the QString operator which calls the char* operator 507 * or use the QString operator which calls the char* operator
495 * 508 *
496 */ 509 */
497odbgstream& odbgstream::operator<<( const QDateTime& time) 510odbgstream& odbgstream::operator<<( const QDateTime& time)
498{ 511{
499 *this << time.toString(); 512 *this << time.toString();
500 return *this; 513 return *this;
501} 514}
502 515
503 516
504odbgstream& odbgstream::operator<<( const QDate& date) 517odbgstream& odbgstream::operator<<( const QDate& date)
505{ 518{
506 *this << date.toString(); 519 *this << date.toString();
507 520
508 return *this; 521 return *this;
509} 522}
510 523
511 524
512odbgstream& odbgstream::operator<<( const QTime& time ) 525odbgstream& odbgstream::operator<<( const QTime& time )
513{ 526{
514 *this << time.toString(); 527 *this << time.toString();
515 return *this; 528 return *this;
516} 529}
517 530
518 531
519odbgstream& odbgstream::operator<<( const QPoint& p ) 532odbgstream& odbgstream::operator<<( const QPoint& p )
520{ 533{
521 *this << "(" << p.x() << ", " << p.y() << ")"; 534 *this << "(" << p.x() << ", " << p.y() << ")";
522 return *this; 535 return *this;
523} 536}
524 537
525 538
526odbgstream& odbgstream::operator<<( const QSize& s ) 539odbgstream& odbgstream::operator<<( const QSize& s )
527{ 540{
528 *this << "[" << s.width() << "x" << s.height() << "]"; 541 *this << "[" << s.width() << "x" << s.height() << "]";
529 return *this; 542 return *this;
530} 543}
531 544
532 545
533odbgstream& odbgstream::operator<<( const QRect& r ) 546odbgstream& odbgstream::operator<<( const QRect& r )
534{ 547{
535 *this << "[" << r.left() << ", " << r.top() << " - " << r.right() << ", " << r.bottom() << "]"; 548 *this << "[" << r.left() << ", " << r.top() << " - " << r.right() << ", " << r.bottom() << "]";
536 return *this; 549 return *this;
537} 550}
538 551
539 552
540odbgstream& odbgstream::operator<<( const QRegion& reg ) 553odbgstream& odbgstream::operator<<( const QRegion& reg )
541{ 554{
542 /* Qt2 doesn't have a QMemArray... :(
543 *this << "[ "; 555 *this << "[ ";
544 QMemArray<QRect>rs=reg.rects(); 556 QArray<QRect>rs=reg.rects();
545 for (uint i=0;i<rs.size();++i) 557 for (uint i=0;i<rs.size();++i)
546 *this << QString("[%1, %2 - %3, %4] ").arg(rs[i].left()).arg(rs[i].top()).arg(rs[i].right()).arg(rs[i].bottom() ) ; 558 *this << QString("[%1, %2 - %3, %4] ").arg(rs[i].left()).arg(rs[i].top()).arg(rs[i].right()).arg(rs[i].bottom() ) ;
547 *this <<"]"; 559 *this <<"]";
548 */
549 return *this; 560 return *this;
550} 561}
551 562
552 563
553odbgstream& odbgstream::operator<<( const QStringList& l ) 564odbgstream& odbgstream::operator<<( const QStringList& l )
554{ 565{
555 *this << "("; 566 *this << "(";
556 *this << l.join(","); 567 *this << l.join(",");
557 *this << ")"; 568 *this << ")";
558 569
559 return *this; 570 return *this;
560} 571}
561 572
562 573
563odbgstream& odbgstream::operator<<( const QColor& c ) 574odbgstream& odbgstream::operator<<( const QColor& c )
564{ 575{
565 if ( c.isValid() ) 576 if ( c.isValid() )
566 *this << c.name(); 577 *this << c.name();
567 else 578 else
568 *this << "(invalid/default)"; 579 *this << "(invalid/default)";
569 return *this; 580 return *this;
570} 581}
571 582
572 583
573odbgstream& odbgstream::operator<<( const QBrush& b) 584odbgstream& odbgstream::operator<<( const QBrush& b)
574{ 585{
575 static const char* const s_brushStyles[] = { 586 static const char* const s_brushStyles[] = {
576 "NoBrush", "SolidPattern", "Dense1Pattern", "Dense2Pattern", "Dense3Pattern", 587 "NoBrush", "SolidPattern", "Dense1Pattern", "Dense2Pattern", "Dense3Pattern",
577 "Dense4Pattern", "Dense5Pattern", "Dense6Pattern", "Dense7Pattern", 588 "Dense4Pattern", "Dense5Pattern", "Dense6Pattern", "Dense7Pattern",
578 "HorPattern", "VerPattern", "CrossPattern", "BDiagPattern", "FDiagPattern", 589 "HorPattern", "VerPattern", "CrossPattern", "BDiagPattern", "FDiagPattern",
579 "DiagCrossPattern" }; 590 "DiagCrossPattern" };
580 591
581 *this <<"[ style: "; 592 *this <<"[ style: ";
582 *this <<s_brushStyles[ b.style() ]; 593 *this <<s_brushStyles[ b.style() ];
583 *this <<" color: "; 594 *this <<" color: ";
584 // can't use operator<<(str, b.color()) because that terminates a odbgstream (flushes) 595 // can't use operator<<(str, b.color()) because that terminates a odbgstream (flushes)
585 if ( b.color().isValid() ) 596 if ( b.color().isValid() )
586 *this <<b.color().name() ; 597 *this <<b.color().name() ;
587 else 598 else
588 *this <<"(invalid/default)"; 599 *this <<"(invalid/default)";
589 if ( b.pixmap() ) 600 if ( b.pixmap() )
590 *this <<" has a pixmap"; 601 *this <<" has a pixmap";
591 *this <<" ]"; 602 *this <<" ]";
592 return *this; 603 return *this;
593} 604}
594 605
595 606
596 607
597QString odBacktrace( int levels ) 608QString odBacktrace( int levels )
598{ 609{
599 QString s; 610 QString s;
600#ifndef OPIE_NO_BACKTRACE 611#ifndef OPIE_NO_BACKTRACE
601 void* trace[256]; 612 void* trace[256];
602 int n = backtrace(trace, 256); 613 int n = backtrace(trace, 256);
603 char** strings = backtrace_symbols (trace, n); 614 char** strings = backtrace_symbols (trace, n);
604 615
605 if ( levels != -1 ) 616 if ( levels != -1 )
606 n = QMIN( n, levels ); 617 n = QMIN( n, levels );
607 s = "[\n"; 618 s = "[\n";
608 619
609 for (int i = 0; i < n; ++i) 620 for (int i = 0; i < n; ++i)
610 s += QString::number(i) + 621 s += QString::number(i) +
611 QString::fromLatin1(": ") + 622 QString::fromLatin1(": ") +
612 QString::fromLatin1(strings[i]) + QString::fromLatin1("\n"); 623 QString::fromLatin1(strings[i]) + QString::fromLatin1("\n");
613 s += "]\n"; 624 s += "]\n";
614 free (strings); 625 free (strings);
615#endif 626#endif
616 return s; 627 return s;
617} 628}
618 629
619void odClearDebugConfig() 630void odClearDebugConfig()
620{ 631{
621 /* 632 /*
622 delete oDebug_data->config; 633 delete oDebug_data->config;
623 oDebug_data->config = 0; 634 oDebug_data->config = 0;
624 */ 635 */
625} 636}
626 637
627 638
628#ifdef OPIE_NO_DEBUG 639#ifdef OPIE_NO_DEBUG
629#define odDebug ondDebug 640#define odDebug ondDebug
630#define odBacktrace ondBacktrace 641#define odBacktrace ondBacktrace
631#endif 642#endif
632 643
633} 644}
634} 645}
diff --git a/libopie2/opiecore/oglobal.cpp b/libopie2/opiecore/oglobal.cpp
index ea02058..2968a7d 100644
--- a/libopie2/opiecore/oglobal.cpp
+++ b/libopie2/opiecore/oglobal.cpp
@@ -1,179 +1,188 @@
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() {
80 qWarning( "Oglobal clean up" );
81 delete OGlobal::_config;
82 delete OGlobal::_qpe_config;
83 OGlobal::_config = 0;
84 OGlobal::_qpe_config = 0;
85}
86
79OConfig* OGlobal::config() 87OConfig* OGlobal::config()
80{ 88{
81 if ( !OGlobal::_config ) 89 if ( !OGlobal::_config )
82 { 90 {
83 // odebug classes are reading config, so can't use them here! 91 // odebug classes are reading config, so can't use them here!
92 qAddPostRoutine( OGlobal::clean_up );
84 qDebug( "OGlobal::creating global configuration instance." ); 93 qDebug( "OGlobal::creating global configuration instance." );
85 OGlobal::_config = new OConfig( "global" ); 94 OGlobal::_config = new OConfig( "global" );
86 } 95 }
87 return OGlobal::_config; 96 return OGlobal::_config;
88} 97}
89 98
90 99
91/** 100/**
92 * Return the internal builtin Global::Command object 101 * Return the internal builtin Global::Command object
93 * 102 *
94 */ 103 */
95Global::Command* OGlobal::builtinCommands() { 104Global::Command* OGlobal::builtinCommands() {
96 return builtin; 105 return builtin;
97} 106}
98 107
99 108
100/** 109/**
101 * Return the internal builtin QGuardedPtr<QWidget> object 110 * Return the internal builtin QGuardedPtr<QWidget> object
102 */ 111 */
103QGuardedPtr<QWidget>* OGlobal::builtinRunning() { 112QGuardedPtr<QWidget>* OGlobal::builtinRunning() {
104 return running; 113 return running;
105} 114}
106 115
107 116
108/** 117/**
109 * \brief generate a new UUID as QString 118 * \brief generate a new UUID as QString
110 * Return a new UUID as QString. UUID are global unique 119 * Return a new UUID as QString. UUID are global unique
111 * 120 *
112 * 121 *
113 * @return the UUID or QString::null 122 * @return the UUID or QString::null
114 */ 123 */
115QString OGlobal::generateUuid() { 124QString OGlobal::generateUuid() {
116 QFile file( "/proc/sys/kernel/random/uuid" ); 125 QFile file( "/proc/sys/kernel/random/uuid" );
117 if (!file.open(IO_ReadOnly ) ) 126 if (!file.open(IO_ReadOnly ) )
118 return QString::null; 127 return QString::null;
119 128
120 QTextStream stream(&file); 129 QTextStream stream(&file);
121 130
122 return "{" + stream.read().stripWhiteSpace() + "}"; 131 return "{" + stream.read().stripWhiteSpace() + "}";
123} 132}
124 133
125 134
126/** 135/**
127 * \brief Encode a QByteArray in base64 136 * \brief Encode a QByteArray in base64
128 * 137 *
129 * An Implementation of the RF1521 base64 encoding. 138 * An Implementation of the RF1521 base64 encoding.
130 * 139 *
131 * The boolean argument determines if the encoded data is 140 * The boolean argument determines if the encoded data is
132 * going to be restricted to 76 characters or less per line 141 * going to be restricted to 76 characters or less per line
133 * as specified by RFC 2045. If @p insertLFs is true, then 142 * as specified by RFC 2045. If @p insertLFs is true, then
134 * there will be 76 characters or less per line. 143 * there will be 76 characters or less per line.
135 * 144 *
136 * If you use this to create a QCString remember that it is null terminated! 145 * If you use this to create a QCString remember that it is null terminated!
137 * \code 146 * \code
138 * QByteArray ar = OGlobal::encodeBase64(&array); 147 * QByteArray ar = OGlobal::encodeBase64(&array);
139 * QCString str(ar.data(),ar.size()+1); // the NUL at the end 148 * QCString str(ar.data(),ar.size()+1); // the NUL at the end
140 * 149 *
141 * \endcode 150 * \endcode
142 * 151 *
143 * @param in The QByteArray to encode 152 * @param in The QByteArray to encode
144 * @param insertLFs Limit number of characters per line 153 * @param insertLFs Limit number of characters per line
145 * @return The argument as base64 encoded or QByteArray() if in.isEmpty() 154 * @return The argument as base64 encoded or QByteArray() if in.isEmpty()
146 * @see QByteArray 155 * @see QByteArray
147 * @see QArray 156 * @see QArray
148 * @see QMemArray 157 * @see QMemArray
149 * @see QCString 158 * @see QCString
150 */ 159 */
151/* 160/*
152 * LGPL by Rik Hemsely of the KDE Project. taken from kmdcodec.cpp 161 * LGPL by Rik Hemsely of the KDE Project. taken from kmdcodec.cpp
153 */ 162 */
154QByteArray OGlobal::encodeBase64(const QByteArray& in, bool insertLFs ) { 163QByteArray OGlobal::encodeBase64(const QByteArray& in, bool insertLFs ) {
155 if ( in.isEmpty() ) 164 if ( in.isEmpty() )
156 return QByteArray(); 165 return QByteArray();
157 166
158 unsigned int sidx = 0; 167 unsigned int sidx = 0;
159 unsigned int didx = 0; 168 unsigned int didx = 0;
160 const char* data = in.data(); 169 const char* data = in.data();
161 const unsigned int len = in.size(); 170 const unsigned int len = in.size();
162 171
163 unsigned int out_len = ((len+2)/3)*4; 172 unsigned int out_len = ((len+2)/3)*4;
164 173
165 // Deal with the 76 characters or less per 174 // Deal with the 76 characters or less per
166 // line limit specified in RFC 2045 on a 175 // line limit specified in RFC 2045 on a
167 // pre request basis. 176 // pre request basis.
168 insertLFs = (insertLFs && out_len > 76); 177 insertLFs = (insertLFs && out_len > 76);
169 if ( insertLFs ) 178 if ( insertLFs )
170 out_len += ((out_len-1)/76); 179 out_len += ((out_len-1)/76);
171 180
172 int count = 0; 181 int count = 0;
173 QByteArray out( out_len ); 182 QByteArray out( out_len );
174 183
175 // 3-byte to 4-byte conversion + 0-63 to ascii printable conversion 184 // 3-byte to 4-byte conversion + 0-63 to ascii printable conversion
176 if ( len > 1 ) 185 if ( len > 1 )
177 { 186 {
178 while (sidx < len-2) 187 while (sidx < len-2)
179 { 188 {
diff --git a/libopie2/opiecore/oglobal.h b/libopie2/opiecore/oglobal.h
index e6a6c46..d79a218 100644
--- a/libopie2/opiecore/oglobal.h
+++ b/libopie2/opiecore/oglobal.h
@@ -1,159 +1,160 @@
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#ifndef OGLOBAL_H 30#ifndef OGLOBAL_H
31#define OGLOBAL_H 31#define OGLOBAL_H
32 32
33 33
34#include <opie2/oconfig.h> 34#include <opie2/oconfig.h>
35 35
36#ifndef private 36#ifndef private
37#define HACK_DEFINED 37#define HACK_DEFINED
38#define private protected 38#define private protected
39#endif 39#endif
40#include <qpe/global.h> 40#include <qpe/global.h>
41#ifdef HACK_DEFINED 41#ifdef HACK_DEFINED
42#undef private 42#undef private
43#endif 43#endif
44 44
45#include <sys/types.h> 45#include <sys/types.h>
46 46
47//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?
48// once we totally skip libqpe it should ideally swallow Global -zecke 48// once we totally skip libqpe it should ideally swallow Global -zecke
49// You're right. I deleted global as the base class. -mickeyl 49// You're right. I deleted global as the base class. -mickeyl
50 50
51 51
52class QFile; 52class QFile;
53class QString; 53class QString;
54class DateFormat; 54class DateFormat;
55 55
56 56
57 57
58namespace Opie { 58namespace Opie {
59namespace Core { 59namespace Core {
60/** 60/**
61 *\brief OGlobal contains a list of generic functions 61 *\brief OGlobal contains a list of generic functions
62 * 62 *
63 * The class OGlobal contains small utility functions 63 * The class OGlobal contains small utility functions
64 * which might be useful for other applications to use. It features access 64 * which might be useful for other applications to use. It features access
65 * to the global device config and specialized functions to get information 65 * to the global device config and specialized functions to get information
66 * out of this config like Weekstart or Owner name. 66 * out of this config like Weekstart or Owner name.
67 * 67 *
68 * @todo ODP implement the things from Global which are good 68 * @todo ODP implement the things from Global which are good
69 * @author mickey,alwin,zecke 69 * @author mickey,alwin,zecke
70 * @version 0.1 70 * @version 0.1
71 */ 71 */
72class OGlobal : public Global 72class OGlobal : public Global
73{ 73{
74public: 74public:
75 75
76 // how do they relate to our Document Idea 76 // how do they relate to our Document Idea
77 /** @name Document System related functions 77 /** @name Document System related functions
78 * 78 *
79 */ 79 */
80 //@{ 80 //@{
81 static bool isAppLnkFileName( const QString& str ); 81 static bool isAppLnkFileName( const QString& str );
82 static bool isDocumentFileName( const QString& file ); 82 static bool isDocumentFileName( const QString& file );
83 //@} 83 //@}
84 84
85 /** @name File Operations 85 /** @name File Operations
86 * File operations provided by OGlobal 86 * File operations provided by OGlobal
87 */ 87 */
88 //@{ 88 //@{
89 /** the content of TEMP 89 /** the content of TEMP
90 * reads the environment variable TEMP and returns the content. 90 * reads the environment variable TEMP and returns the content.
91 * if not set returns "/tmp" 91 * if not set returns "/tmp"
92 * @return a string containing a dir without trailing slash! 92 * @return a string containing a dir without trailing slash!
93 */ 93 */
94 static QString tempDirPath(); 94 static QString tempDirPath();
95 /** the content of HOME 95 /** the content of HOME
96 * reads the environment variable HOME and returns the content. 96 * reads the environment variable HOME and returns the content.
97 * if not set returns "/" 97 * if not set returns "/"
98 * @return a string containing a dir without trailing slash! 98 * @return a string containing a dir without trailing slash!
99 */ 99 */
100 static QString homeDirPath(); 100 static QString homeDirPath();
101 static QString tempFileName( const QString& ); 101 static QString tempFileName( const QString& );
102 static bool renameFile( const QString& from, const QString& to ); 102 static bool renameFile( const QString& from, const QString& to );
103 static bool truncateFile( QFile &f, off_t size ); 103 static bool truncateFile( QFile &f, off_t size );
104 //@} 104 //@}
105 105
106 106
107 static QString generateUuid(); 107 static QString generateUuid();
108 108
109 /** @name Convert Content 109 /** @name Convert Content
110 * Convert Content of a QByteArray 110 * Convert Content of a QByteArray
111 */ 111 */
112 //@{ 112 //@{
113 static QByteArray encodeBase64(const QByteArray&, bool insertLF = false ); 113 static QByteArray encodeBase64(const QByteArray&, bool insertLF = false );
114 static QByteArray decodeBase64(const QByteArray& ); 114 static QByteArray decodeBase64(const QByteArray& );
115 //@} 115 //@}
116 116
117 //FIXME Do we want to put that into OApplication as in KApplication? -zecke 117 //FIXME Do we want to put that into OApplication as in KApplication? -zecke
118 // We already have a per-application config in OApplication 118 // We already have a per-application config in OApplication
119 // ( accessed through oApp->config() ), but this one is the global one! -mickeyl 119 // ( accessed through oApp->config() ), but this one is the global one! -mickeyl
120 /** @name Config and Owner related Information 120 /** @name Config and Owner related Information
121 * 121 *
122 */ 122 */
123 //@{ 123 //@{
124 static OConfig* config(); 124 static OConfig* config();
125 static OConfig* qpe_config(); 125 static OConfig* qpe_config();
126 static QString ownerName(); 126 static QString ownerName();
127 static bool weekStartsOnMonday(); 127 static bool weekStartsOnMonday();
128 static bool useAMPM(); 128 static bool useAMPM();
129#ifdef ODP 129#ifdef ODP
130#error "Fix dateFormat" 130#error "Fix dateFormat"
131 /** 131 /**
132 * For Qt3/Qt4 we can use QDate::toString(OGlobal::dateFormat) 132 * For Qt3/Qt4 we can use QDate::toString(OGlobal::dateFormat)
133 * See if we need to use the function with String in it 133 * See if we need to use the function with String in it
134 * Anyway this is the future 134 * Anyway this is the future
135 * for now still use TimeString! 135 * for now still use TimeString!
136 */ 136 */
137#endif 137#endif
138 static DateFormat dateFormat(); 138 static DateFormat dateFormat();
139 static void setDateFormat( const DateFormat& ); 139 static void setDateFormat( const DateFormat& );
140 140
141 141
142 static void setWeekStartsOnMonday( bool ); 142 static void setWeekStartsOnMonday( bool );
143 static void setUseAMPM( bool ); 143 static void setUseAMPM( bool );
144 //@} 144 //@}
145 145
146 //@{ 146 //@{
147 static Global::Command* builtinCommands(); 147 static Global::Command* builtinCommands();
148 static QGuardedPtr<QWidget>* builtinRunning(); 148 static QGuardedPtr<QWidget>* builtinRunning();
149 //@} 149 //@}
150 150
151private: 151private:
152 static void clean_up();
152 static OConfig* _config; 153 static OConfig* _config;
153 static OConfig* _qpe_config; 154 static OConfig* _qpe_config;
154 class Private; 155 class Private;
155 Private *d; 156 Private *d;
156}; 157};
157} 158}
158} 159}
159#endif // OGLOBAL_H 160#endif // OGLOBAL_H