summaryrefslogtreecommitdiff
path: root/libopie2
Unidiff
Diffstat (limited to 'libopie2') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiecore/odebug.cpp11
-rw-r--r--libopie2/opiecore/oglobal.cpp1
-rw-r--r--libopie2/opiecore/oglobalsettings.cpp3
-rw-r--r--libopie2/opiecore/oprocctrl.cpp1
-rw-r--r--libopie2/opiecore/oprocess.cpp2
-rw-r--r--libopie2/opiedb/osqlbackendmanager.cpp1
-rw-r--r--libopie2/opiedb/osqlitedriver.cpp1
-rw-r--r--libopie2/opiedb/osqlmanager.cpp2
-rw-r--r--libopie2/opiedb/osqlresult.cpp1
-rw-r--r--libopie2/opiemm/osoundsystem.cpp1
-rw-r--r--libopie2/opienet/omanufacturerdb.cpp1
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp2
-rw-r--r--libopie2/opiepim/core/opimcontact.cpp4
-rw-r--r--libopie2/opiepim/core/opimcontactfields.cpp2
-rw-r--r--libopie2/opiepim/core/opimevent.cpp3
-rw-r--r--libopie2/opiepim/core/opimnotify.cpp1
-rw-r--r--libopie2/opiepim/core/opimrecord.cpp1
-rw-r--r--libopie2/opiepim/core/opimtodo.cpp3
-rw-r--r--libopie2/opieui/ofontselector.cpp1
-rw-r--r--libopie2/opieui/olistview.cpp3
-rw-r--r--libopie2/opieui/opopupmenu.cpp7
-rw-r--r--libopie2/opieui/oselector.cpp1
-rw-r--r--libopie2/opieui/oseparator.cpp1
-rw-r--r--libopie2/opieui/otimepicker.cpp3
-rw-r--r--libopie2/opieui/oversatileview.cpp11
25 files changed, 1 insertions, 67 deletions
diff --git a/libopie2/opiecore/odebug.cpp b/libopie2/opiecore/odebug.cpp
index 4505ce7..a40ef53 100644
--- a/libopie2/opiecore/odebug.cpp
+++ b/libopie2/opiecore/odebug.cpp
@@ -1,631 +1,620 @@
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 <qbrush.h>
51#include <qdatetime.h>
52#include <qfile.h> 50#include <qfile.h>
53#include <qhostaddress.h>
54#include <qmessagebox.h> 51#include <qmessagebox.h>
55#include <qintdict.h>
56#include <qpoint.h>
57#include <qrect.h>
58#include <qregion.h>
59#include <qsize.h>
60#include <qsocketdevice.h> 52#include <qsocketdevice.h>
61#include <qstring.h>
62#include <qstringlist.h>
63#include <qtextstream.h>
64 53
65/* UNIX */ 54/* UNIX */
66 55
67#include <stdlib.h> // abort 56#include <stdlib.h> // abort
68#include <unistd.h> // getpid 57#include <unistd.h> // getpid
69#include <stdarg.h> // vararg stuff 58#include <stdarg.h> // vararg stuff
70#include <ctype.h> // isprint 59#include <ctype.h> // isprint
71#include <syslog.h> 60#include <syslog.h>
72#include <errno.h> 61#include <errno.h>
73#include <string.h> 62#include <string.h>
74 63
75#ifndef OPIE_NO_BACKTRACE 64#ifndef OPIE_NO_BACKTRACE
76#include <execinfo.h> 65#include <execinfo.h>
77#endif 66#endif
78 67
79 68
80/*====================================================================================== 69/*======================================================================================
81 * debug levels 70 * debug levels
82 *======================================================================================*/ 71 *======================================================================================*/
83 72
84enum DebugLevels { 73enum DebugLevels {
85 ODEBUG_INFO = 0, 74 ODEBUG_INFO = 0,
86 ODEBUG_WARN = 1, 75 ODEBUG_WARN = 1,
87 ODEBUG_ERROR = 2, 76 ODEBUG_ERROR = 2,
88 ODEBUG_FATAL = 3 77 ODEBUG_FATAL = 3
89}; 78};
90 79
91/*====================================================================================== 80/*======================================================================================
92 * oDebug private data 81 * oDebug private data
93 *======================================================================================*/ 82 *======================================================================================*/
94 83
95/*====================================================================================== 84/*======================================================================================
96 * the main debug function 85 * the main debug function
97 *======================================================================================*/ 86 *======================================================================================*/
98 87
99static void oDebugBackend( unsigned short level, unsigned int area, const char *data) 88static void oDebugBackend( unsigned short level, unsigned int area, const char *data)
100{ 89{
101 //qDebug( "oDebugBackend: Level=%d, Area=%d, Data=%s", level, area, data ); 90 //qDebug( "oDebugBackend: Level=%d, Area=%d, Data=%s", level, area, data );
102 91
103 // ML: OPIE doesn't use areacodes at the moment. See the KDE debug classes for an 92 // ML: OPIE doesn't use areacodes at the moment. See the KDE debug classes for an
104 // ML: example use. I think it's not necessary to implement such a strategy here. 93 // ML: example use. I think it's not necessary to implement such a strategy here.
105 // ML: Comments? 94 // ML: Comments?
106 95
107 int priority = 0; 96 int priority = 0;
108 QString caption; 97 QString caption;
109 QString lev; 98 QString lev;
110 switch( level ) 99 switch( level )
111 { 100 {
112 case ODEBUG_INFO: lev = "(Info)"; caption = "Info"; priority = LOG_INFO; break; 101 case ODEBUG_INFO: lev = "(Info)"; caption = "Info"; priority = LOG_INFO; break;
113 case ODEBUG_WARN: lev = "(Warn)"; caption = "Warning"; priority = LOG_WARNING; break; 102 case ODEBUG_WARN: lev = "(Warn)"; caption = "Warning"; priority = LOG_WARNING; break;
114 case ODEBUG_FATAL: lev = "(Fatal)"; caption = "Fatal Error"; priority = LOG_CRIT; break; 103 case ODEBUG_FATAL: lev = "(Fatal)"; caption = "Fatal Error"; priority = LOG_CRIT; break;
115 default: qDebug( "oDebugBackend: Warning: Unknown debug level! - defaulting to ODEBUG_ERROR." ); 104 default: qDebug( "oDebugBackend: Warning: Unknown debug level! - defaulting to ODEBUG_ERROR." );
116 case ODEBUG_ERROR: lev = "(Error)"; caption = "Error"; priority = LOG_ERR; break; 105 case ODEBUG_ERROR: lev = "(Error)"; caption = "Error"; priority = LOG_ERR; break;
117 } 106 }
118 107
119 short output = OGlobalSettings::debugMode(); 108 short output = OGlobalSettings::debugMode();
120 if (!oApp && (output == 1)) 109 if (!oApp && (output == 1))
121 { 110 {
122 qDebug( "oDebugBackend: Warning: no oapplication object - can't use MsgBox" ); 111 qDebug( "oDebugBackend: Warning: no oapplication object - can't use MsgBox" );
123 output = 2; // need an application object to use MsgBox 112 output = 2; // need an application object to use MsgBox
124 } 113 }
125 114
126 // gcc 2.9x is dumb and sucks... can you hear it? 115 // gcc 2.9x is dumb and sucks... can you hear it?
127 //QString areaName = (oApp) ? oApp->appName() : "<unknown>"; 116 //QString areaName = (oApp) ? oApp->appName() : "<unknown>";
128 QString areaName; 117 QString areaName;
129 if ( oApp ) areaName = oApp->appName(); 118 if ( oApp ) areaName = oApp->appName();
130 else areaName = "<unknown>"; 119 else areaName = "<unknown>";
131 120
132 // Output 121 // Output
133 switch( output ) 122 switch( output )
134 { 123 {
135 case -1: // ignore 124 case -1: // ignore
136 { 125 {
137 return; 126 return;
138 } 127 }
139 case 0: // File 128 case 0: // File
140 { 129 {
141 QString outputFilename = OGlobalSettings::debugOutput(); 130 QString outputFilename = OGlobalSettings::debugOutput();
142 131
143 const int BUFSIZE = 4096; 132 const int BUFSIZE = 4096;
144 char buf[BUFSIZE] = ""; 133 char buf[BUFSIZE] = "";
145 buf[BUFSIZE-1] = '\0'; 134 buf[BUFSIZE-1] = '\0';
146 int nSize; 135 int nSize;
147 136
148 nSize = snprintf( buf, BUFSIZE-1, "%s: %s", (const char*) areaName, data); 137 nSize = snprintf( buf, BUFSIZE-1, "%s: %s", (const char*) areaName, data);
149 138
150 QFile outputFile( outputFilename ); 139 QFile outputFile( outputFilename );
151 if ( outputFile.open( IO_WriteOnly | IO_Append ) ) 140 if ( outputFile.open( IO_WriteOnly | IO_Append ) )
152 { 141 {
153 if ( ( nSize == -1 ) || ( nSize >= BUFSIZE ) ) 142 if ( ( nSize == -1 ) || ( nSize >= BUFSIZE ) )
154 { 143 {
155 outputFile.writeBlock( buf, BUFSIZE-1 ); 144 outputFile.writeBlock( buf, BUFSIZE-1 );
156 } 145 }
157 else 146 else
158 { 147 {
159 outputFile.writeBlock( buf, nSize ); 148 outputFile.writeBlock( buf, nSize );
160 } 149 }
161 } 150 }
162 else 151 else
163 { 152 {
164 qDebug( "ODebug: can't write to file '%s' (%s)", (const char*) outputFilename, strerror(errno) ); 153 qDebug( "ODebug: can't write to file '%s' (%s)", (const char*) outputFilename, strerror(errno) );
165 } 154 }
166 break; 155 break;
167 } // automatic close of file here 156 } // automatic close of file here
168 157
169 case 1: // Message Box 158 case 1: // Message Box
170 { 159 {
171 // Since we are in opiecore here, we cannot use OMsgBox and use 160 // Since we are in opiecore here, we cannot use OMsgBox and use
172 // QMessageBox instead 161 // QMessageBox instead
173 162
174 caption += QString("(") + areaName + ")"; 163 caption += QString("(") + areaName + ")";
175 QMessageBox::warning( 0L, caption, data, ("&OK") ); // tr? 164 QMessageBox::warning( 0L, caption, data, ("&OK") ); // tr?
176 break; 165 break;
177 } 166 }
178 167
179 case 2: // Shell 168 case 2: // Shell
180 { 169 {
181 FILE *output = stderr; 170 FILE *output = stderr;
182 fprintf( output, "%s: ", (const char*) areaName ); 171 fprintf( output, "%s: ", (const char*) areaName );
183 fputs( data, output); 172 fputs( data, output);
184 break; 173 break;
185 } 174 }
186 175
187 case 3: // syslog 176 case 3: // syslog
188 { 177 {
189 syslog( priority, "%s", data); 178 syslog( priority, "%s", data);
190 break; 179 break;
191 } 180 }
192 181
193 case 4: // socket 182 case 4: // socket
194 { 183 {
195 QString destination = OGlobalSettings::debugOutput(); 184 QString destination = OGlobalSettings::debugOutput();
196 if ( destination && destination.find(":") != -1 ) 185 if ( destination && destination.find(":") != -1 )
197 { 186 {
198 QString host = destination.left( destination.find(":") ); 187 QString host = destination.left( destination.find(":") );
199 QString port = destination.right( destination.length()-host.length()-1 ); 188 QString port = destination.right( destination.length()-host.length()-1 );
200 QHostAddress addr; 189 QHostAddress addr;
201 addr.setAddress( host ); 190 addr.setAddress( host );
202 // TODO: sanity check the address 191 // TODO: sanity check the address
203 QString line; 192 QString line;
204 line.sprintf( "%s: %s", (const char*) areaName, (const char*) data ); 193 line.sprintf( "%s: %s", (const char*) areaName, (const char*) data );
205 QSocketDevice s( QSocketDevice::Datagram ); 194 QSocketDevice s( QSocketDevice::Datagram );
206 int result = s.writeBlock( (const char*) line, line.length(), addr, port.toInt() ); 195 int result = s.writeBlock( (const char*) line, line.length(), addr, port.toInt() );
207 if ( result == -1 ) 196 if ( result == -1 )
208 { 197 {
209 qDebug( "ODebug: can't send to address '%s:%d' (%s)", (const char*) host, port.toInt(), strerror(errno) ); 198 qDebug( "ODebug: can't send to address '%s:%d' (%s)", (const char*) host, port.toInt(), strerror(errno) );
210 } 199 }
211 } 200 }
212 break; 201 break;
213 } 202 }
214 } 203 }
215 204
216 // check if we should abort 205 // check if we should abort
217 206
218 /* 207 /*
219 208
220 if( ( nLevel == ODEBUG_FATAL ) 209 if( ( nLevel == ODEBUG_FATAL )
221 && ( !oDebug_data->config || oDebug_data->config->readNumEntry( "AbortFatal", 1 ) ) ) 210 && ( !oDebug_data->config || oDebug_data->config->readNumEntry( "AbortFatal", 1 ) ) )
222 abort(); 211 abort();
223 212
224 */ 213 */
225} 214}
226 215
227/*====================================================================================== 216/*======================================================================================
228 * odbgstream 217 * odbgstream
229 *======================================================================================*/ 218 *======================================================================================*/
230 219
231odbgstream& perror( odbgstream &s) 220odbgstream& perror( odbgstream &s)
232{ 221{
233 return s << QString::fromLocal8Bit(strerror(errno)); 222 return s << QString::fromLocal8Bit(strerror(errno));
234} 223}
235 224
236odbgstream odDebug(int area) 225odbgstream odDebug(int area)
237{ 226{
238 return odbgstream(area, ODEBUG_INFO); 227 return odbgstream(area, ODEBUG_INFO);
239} 228}
240odbgstream odDebug(bool cond, int area) 229odbgstream odDebug(bool cond, int area)
241{ 230{
242 if (cond) return odbgstream(area, ODEBUG_INFO); 231 if (cond) return odbgstream(area, ODEBUG_INFO);
243 else return odbgstream(0, 0, false); 232 else return odbgstream(0, 0, false);
244} 233}
245 234
246odbgstream odError(int area) 235odbgstream odError(int area)
247{ 236{
248 return odbgstream("ERROR: ", area, ODEBUG_ERROR); 237 return odbgstream("ERROR: ", area, ODEBUG_ERROR);
249} 238}
250 239
251odbgstream odError(bool cond, int area) 240odbgstream odError(bool cond, int area)
252{ 241{
253 if (cond) return odbgstream("ERROR: ", area, ODEBUG_ERROR); else return odbgstream(0,0,false); 242 if (cond) return odbgstream("ERROR: ", area, ODEBUG_ERROR); else return odbgstream(0,0,false);
254} 243}
255 244
256odbgstream odWarning(int area) 245odbgstream odWarning(int area)
257{ 246{
258 return odbgstream("WARNING: ", area, ODEBUG_WARN); 247 return odbgstream("WARNING: ", area, ODEBUG_WARN);
259} 248}
260 249
261odbgstream odWarning(bool cond, int area) 250odbgstream odWarning(bool cond, int area)
262{ 251{
263 if (cond) return odbgstream("WARNING: ", area, ODEBUG_WARN); else return odbgstream(0,0,false); 252 if (cond) return odbgstream("WARNING: ", area, ODEBUG_WARN); else return odbgstream(0,0,false);
264} 253}
265 254
266odbgstream odFatal(int area) 255odbgstream odFatal(int area)
267{ 256{
268 return odbgstream("FATAL: ", area, ODEBUG_FATAL); 257 return odbgstream("FATAL: ", area, ODEBUG_FATAL);
269} 258}
270 259
271odbgstream odFatal(bool cond, int area) 260odbgstream odFatal(bool cond, int area)
272{ 261{
273 if (cond) return odbgstream("FATAL: ", area, ODEBUG_FATAL); else return odbgstream(0,0,false); 262 if (cond) return odbgstream("FATAL: ", area, ODEBUG_FATAL); else return odbgstream(0,0,false);
274} 263}
275 264
276odbgstream::odbgstream(unsigned int _area, unsigned int _level, bool _print) 265odbgstream::odbgstream(unsigned int _area, unsigned int _level, bool _print)
277 :area(_area), level(_level), print(_print) 266 :area(_area), level(_level), print(_print)
278{ 267{
279} 268}
280 269
281 270
282odbgstream::odbgstream(const char * initialString, unsigned int _area, unsigned int _level, bool _print) 271odbgstream::odbgstream(const char * initialString, unsigned int _area, unsigned int _level, bool _print)
283 :output(QString::fromLatin1(initialString)), area(_area), level(_level), print(_print) 272 :output(QString::fromLatin1(initialString)), area(_area), level(_level), print(_print)
284{ 273{
285} 274}
286 275
287 276
288odbgstream::odbgstream(odbgstream &str) 277odbgstream::odbgstream(odbgstream &str)
289 :output(str.output), area(str.area), level(str.level), print(str.print) 278 :output(str.output), area(str.area), level(str.level), print(str.print)
290{ 279{
291 str.output.truncate(0); 280 str.output.truncate(0);
292} 281}
293 282
294 283
295odbgstream::odbgstream(const odbgstream &str) 284odbgstream::odbgstream(const odbgstream &str)
296 :output(str.output), area(str.area), level(str.level), print(str.print) 285 :output(str.output), area(str.area), level(str.level), print(str.print)
297{ 286{
298} 287}
299 288
300odbgstream& odbgstream::operator<<(bool i) 289odbgstream& odbgstream::operator<<(bool i)
301{ 290{
302 if (!print) return *this; 291 if (!print) return *this;
303 output += QString::fromLatin1(i ? "true" : "false"); 292 output += QString::fromLatin1(i ? "true" : "false");
304 return *this; 293 return *this;
305} 294}
306 295
307 296
308odbgstream& odbgstream::operator<<(short i) 297odbgstream& odbgstream::operator<<(short i)
309{ 298{
310 if (!print) return *this; 299 if (!print) return *this;
311 QString tmp; tmp.setNum(i); output += tmp; 300 QString tmp; tmp.setNum(i); output += tmp;
312 return *this; 301 return *this;
313} 302}
314 303
315 304
316odbgstream& odbgstream::operator<<(unsigned short i) 305odbgstream& odbgstream::operator<<(unsigned short i)
317{ 306{
318 if (!print) return *this; 307 if (!print) return *this;
319 QString tmp; tmp.setNum(i); output += tmp; 308 QString tmp; tmp.setNum(i); output += tmp;
320 return *this; 309 return *this;
321} 310}
322 311
323 312
324odbgstream& odbgstream::operator<<(unsigned char i) 313odbgstream& odbgstream::operator<<(unsigned char i)
325{ 314{
326 return operator<<( static_cast<char>( i ) ); 315 return operator<<( static_cast<char>( i ) );
327} 316}
328 317
329 318
330odbgstream& odbgstream::operator<<(int i) 319odbgstream& odbgstream::operator<<(int i)
331{ 320{
332 if (!print) return *this; 321 if (!print) return *this;
333 QString tmp; tmp.setNum(i); output += tmp; 322 QString tmp; tmp.setNum(i); output += tmp;
334 return *this; 323 return *this;
335} 324}
336 325
337 326
338odbgstream& odbgstream::operator<<(unsigned int i) 327odbgstream& odbgstream::operator<<(unsigned int i)
339{ 328{
340 if (!print) return *this; 329 if (!print) return *this;
341 QString tmp; tmp.setNum(i); output += tmp; 330 QString tmp; tmp.setNum(i); output += tmp;
342 return *this; 331 return *this;
343} 332}
344 333
345 334
346odbgstream& odbgstream::operator<<(long i) 335odbgstream& odbgstream::operator<<(long i)
347{ 336{
348 if (!print) return *this; 337 if (!print) return *this;
349 QString tmp; tmp.setNum(i); output += tmp; 338 QString tmp; tmp.setNum(i); output += tmp;
350 return *this; 339 return *this;
351} 340}
352 341
353 342
354odbgstream& odbgstream::operator<<(unsigned long i) 343odbgstream& odbgstream::operator<<(unsigned long i)
355{ 344{
356 if (!print) return *this; 345 if (!print) return *this;
357 QString tmp; tmp.setNum(i); output += tmp; 346 QString tmp; tmp.setNum(i); output += tmp;
358 return *this; 347 return *this;
359} 348}
360 349
361 350
362odbgstream& odbgstream::operator<<(const QString& string) 351odbgstream& odbgstream::operator<<(const QString& string)
363{ 352{
364 if (!print) return *this; 353 if (!print) return *this;
365 output += string; 354 output += string;
366 if (output.at(output.length() -1 ) == '\n') 355 if (output.at(output.length() -1 ) == '\n')
367 flush(); 356 flush();
368 return *this; 357 return *this;
369} 358}
370 359
371 360
372odbgstream& odbgstream::operator<<(const char *string) 361odbgstream& odbgstream::operator<<(const char *string)
373{ 362{
374 if (!print) return *this; 363 if (!print) return *this;
375 output += QString::fromUtf8(string); 364 output += QString::fromUtf8(string);
376 if (output.at(output.length() - 1) == '\n') 365 if (output.at(output.length() - 1) == '\n')
377 flush(); 366 flush();
378 return *this; 367 return *this;
379} 368}
380 369
381 370
382odbgstream& odbgstream::operator<<(const QCString& string) 371odbgstream& odbgstream::operator<<(const QCString& string)
383{ 372{
384 *this << string.data(); 373 *this << string.data();
385 return *this; 374 return *this;
386} 375}
387 376
388 377
389odbgstream& odbgstream::operator<<(const void * p) 378odbgstream& odbgstream::operator<<(const void * p)
390{ 379{
391 form("%p", p); 380 form("%p", p);
392 return *this; 381 return *this;
393} 382}
394 383
395odbgstream& odbgstream::operator<<(double d) 384odbgstream& odbgstream::operator<<(double d)
396{ 385{
397 QString tmp; tmp.setNum(d); output += tmp; 386 QString tmp; tmp.setNum(d); output += tmp;
398 return *this; 387 return *this;
399} 388}
400 389
401/* 390/*
402odbgstream::odbgstream &form(const char *format, ...) 391odbgstream::odbgstream &form(const char *format, ...)
403#ifdef __GNUC__ 392#ifdef __GNUC__
404 __attribute__ ( ( format ( printf, 2, 3 ) ) ) 393 __attribute__ ( ( format ( printf, 2, 3 ) ) )
405#endif 394#endif
406 ; 395 ;
407*/ 396*/
408 397
409void odbgstream::flush() 398void odbgstream::flush()
410{ 399{
411 if ( output.isEmpty() || !print ) 400 if ( output.isEmpty() || !print )
412 { 401 {
413 return; 402 return;
414 } 403 }
415 else 404 else
416 { 405 {
417 oDebugBackend( level, area, output.local8Bit().data() ); 406 oDebugBackend( level, area, output.local8Bit().data() );
418 output = QString::null; 407 output = QString::null;
419 } 408 }
420} 409}
421 410
422odbgstream& odbgstream::form(const char *format, ...) 411odbgstream& odbgstream::form(const char *format, ...)
423{ 412{
424 char buf[4096]; 413 char buf[4096];
425 va_list arguments; 414 va_list arguments;
426 va_start( arguments, format ); 415 va_start( arguments, format );
427 buf[sizeof(buf)-1] = '\0'; 416 buf[sizeof(buf)-1] = '\0';
428 vsnprintf( buf, sizeof(buf)-1, format, arguments ); 417 vsnprintf( buf, sizeof(buf)-1, format, arguments );
429 va_end(arguments); 418 va_end(arguments);
430 *this << buf; 419 *this << buf;
431 return *this; 420 return *this;
432} 421}
433 422
434odbgstream::~odbgstream() 423odbgstream::~odbgstream()
435{ 424{
436 if (!output.isEmpty()) 425 if (!output.isEmpty())
437 { 426 {
438 fprintf(stderr, "ASSERT: debug output not ended with \\n\n"); 427 fprintf(stderr, "ASSERT: debug output not ended with \\n\n");
439 *this << "\n"; 428 *this << "\n";
440 } 429 }
441} 430}
442 431
443odbgstream& odbgstream::operator<<(char ch) 432odbgstream& odbgstream::operator<<(char ch)
444{ 433{
445 if (!print) return *this; 434 if (!print) return *this;
446 if (!isprint(ch)) 435 if (!isprint(ch))
447 { 436 {
448 output += "\\x" + QString::number( static_cast<uint>( ch ) + 0x100, 16 ).right(2); 437 output += "\\x" + QString::number( static_cast<uint>( ch ) + 0x100, 16 ).right(2);
449 } 438 }
450 else 439 else
451 { 440 {
452 output += ch; 441 output += ch;
453 if (ch == '\n') flush(); 442 if (ch == '\n') flush();
454 } 443 }
455 return *this; 444 return *this;
456} 445}
457 446
458odbgstream& odbgstream::operator<<( QWidget* widget ) 447odbgstream& odbgstream::operator<<( QWidget* widget )
459{ 448{
460 QString string, temp; 449 QString string, temp;
461 // ----- 450 // -----
462 if(widget==0) 451 if(widget==0)
463 { 452 {
464 string=(QString)"[Null pointer]"; 453 string=(QString)"[Null pointer]";
465 } else 454 } else
466 { 455 {
467 temp.setNum((ulong)widget, 16); 456 temp.setNum((ulong)widget, 16);
468 string=(QString)"["+widget->className()+" pointer " + "(0x" + temp + ")"; 457 string=(QString)"["+widget->className()+" pointer " + "(0x" + temp + ")";
469 if(widget->name(0)==0) 458 if(widget->name(0)==0)
470 { 459 {
471 string += " to unnamed widget, "; 460 string += " to unnamed widget, ";
472 } else 461 } else
473 { 462 {
474 string += (QString)" to widget " + widget->name() + ", "; 463 string += (QString)" to widget " + widget->name() + ", ";
475 } 464 }
476 string += "geometry=" 465 string += "geometry="
477 + QString().setNum(widget->width()) 466 + QString().setNum(widget->width())
478 + "x"+QString().setNum(widget->height()) 467 + "x"+QString().setNum(widget->height())
479 + "+"+QString().setNum(widget->x()) 468 + "+"+QString().setNum(widget->x())
480 + "+"+QString().setNum(widget->y()) 469 + "+"+QString().setNum(widget->y())
481 + "]"; 470 + "]";
482 } 471 }
483 if (!print) return *this; 472 if (!print) return *this;
484 473
485 output += string; 474 output += string;
486 if (output.at(output.length()-1) == '\n') 475 if (output.at(output.length()-1) == '\n')
487 { 476 {
488 flush(); 477 flush();
489 } 478 }
490 return *this; 479 return *this;
491} 480}
492 481
493/* 482/*
494 * either use 'output' directly and do the flush if needed 483 * either use 'output' directly and do the flush if needed
495 * or use the QString operator which calls the char* operator 484 * or use the QString operator which calls the char* operator
496 * 485 *
497 */ 486 */
498odbgstream& odbgstream::operator<<( const QDateTime& time) 487odbgstream& odbgstream::operator<<( const QDateTime& time)
499{ 488{
500 *this << time.toString(); 489 *this << time.toString();
501 return *this; 490 return *this;
502} 491}
503 492
504 493
505odbgstream& odbgstream::operator<<( const QDate& date) 494odbgstream& odbgstream::operator<<( const QDate& date)
506{ 495{
507 *this << date.toString(); 496 *this << date.toString();
508 497
509 return *this; 498 return *this;
510} 499}
511 500
512 501
513odbgstream& odbgstream::operator<<( const QTime& time ) 502odbgstream& odbgstream::operator<<( const QTime& time )
514{ 503{
515 *this << time.toString(); 504 *this << time.toString();
516 return *this; 505 return *this;
517} 506}
518 507
519 508
520odbgstream& odbgstream::operator<<( const QPoint& p ) 509odbgstream& odbgstream::operator<<( const QPoint& p )
521{ 510{
522 *this << "(" << p.x() << ", " << p.y() << ")"; 511 *this << "(" << p.x() << ", " << p.y() << ")";
523 return *this; 512 return *this;
524} 513}
525 514
526 515
527odbgstream& odbgstream::operator<<( const QSize& s ) 516odbgstream& odbgstream::operator<<( const QSize& s )
528{ 517{
529 *this << "[" << s.width() << "x" << s.height() << "]"; 518 *this << "[" << s.width() << "x" << s.height() << "]";
530 return *this; 519 return *this;
531} 520}
532 521
533 522
534odbgstream& odbgstream::operator<<( const QRect& r ) 523odbgstream& odbgstream::operator<<( const QRect& r )
535{ 524{
536 *this << "[" << r.left() << ", " << r.top() << " - " << r.right() << ", " << r.bottom() << "]"; 525 *this << "[" << r.left() << ", " << r.top() << " - " << r.right() << ", " << r.bottom() << "]";
537 return *this; 526 return *this;
538} 527}
539 528
540 529
541odbgstream& odbgstream::operator<<( const QRegion& reg ) 530odbgstream& odbgstream::operator<<( const QRegion& reg )
542{ 531{
543 /* Qt2 doesn't have a QMemArray... :( 532 /* Qt2 doesn't have a QMemArray... :(
544 *this << "[ "; 533 *this << "[ ";
545 QMemArray<QRect>rs=reg.rects(); 534 QMemArray<QRect>rs=reg.rects();
546 for (uint i=0;i<rs.size();++i) 535 for (uint i=0;i<rs.size();++i)
547 *this << QString("[%1, %2 - %3, %4] ").arg(rs[i].left()).arg(rs[i].top()).arg(rs[i].right()).arg(rs[i].bottom() ) ; 536 *this << QString("[%1, %2 - %3, %4] ").arg(rs[i].left()).arg(rs[i].top()).arg(rs[i].right()).arg(rs[i].bottom() ) ;
548 *this <<"]"; 537 *this <<"]";
549 */ 538 */
550 return *this; 539 return *this;
551} 540}
552 541
553 542
554odbgstream& odbgstream::operator<<( const QStringList& l ) 543odbgstream& odbgstream::operator<<( const QStringList& l )
555{ 544{
556 *this << "("; 545 *this << "(";
557 *this << l.join(","); 546 *this << l.join(",");
558 *this << ")"; 547 *this << ")";
559 548
560 return *this; 549 return *this;
561} 550}
562 551
563 552
564odbgstream& odbgstream::operator<<( const QColor& c ) 553odbgstream& odbgstream::operator<<( const QColor& c )
565{ 554{
566 if ( c.isValid() ) 555 if ( c.isValid() )
567 *this << c.name(); 556 *this << c.name();
568 else 557 else
569 *this << "(invalid/default)"; 558 *this << "(invalid/default)";
570 return *this; 559 return *this;
571} 560}
572 561
573 562
574odbgstream& odbgstream::operator<<( const QBrush& b) 563odbgstream& odbgstream::operator<<( const QBrush& b)
575{ 564{
576 static const char* const s_brushStyles[] = { 565 static const char* const s_brushStyles[] = {
577 "NoBrush", "SolidPattern", "Dense1Pattern", "Dense2Pattern", "Dense3Pattern", 566 "NoBrush", "SolidPattern", "Dense1Pattern", "Dense2Pattern", "Dense3Pattern",
578 "Dense4Pattern", "Dense5Pattern", "Dense6Pattern", "Dense7Pattern", 567 "Dense4Pattern", "Dense5Pattern", "Dense6Pattern", "Dense7Pattern",
579 "HorPattern", "VerPattern", "CrossPattern", "BDiagPattern", "FDiagPattern", 568 "HorPattern", "VerPattern", "CrossPattern", "BDiagPattern", "FDiagPattern",
580 "DiagCrossPattern" }; 569 "DiagCrossPattern" };
581 570
582 *this <<"[ style: "; 571 *this <<"[ style: ";
583 *this <<s_brushStyles[ b.style() ]; 572 *this <<s_brushStyles[ b.style() ];
584 *this <<" color: "; 573 *this <<" color: ";
585 // can't use operator<<(str, b.color()) because that terminates a odbgstream (flushes) 574 // can't use operator<<(str, b.color()) because that terminates a odbgstream (flushes)
586 if ( b.color().isValid() ) 575 if ( b.color().isValid() )
587 *this <<b.color().name() ; 576 *this <<b.color().name() ;
588 else 577 else
589 *this <<"(invalid/default)"; 578 *this <<"(invalid/default)";
590 if ( b.pixmap() ) 579 if ( b.pixmap() )
591 *this <<" has a pixmap"; 580 *this <<" has a pixmap";
592 *this <<" ]"; 581 *this <<" ]";
593 return *this; 582 return *this;
594} 583}
595 584
596 585
597 586
598QString odBacktrace( int levels ) 587QString odBacktrace( int levels )
599{ 588{
600 QString s; 589 QString s;
601#ifndef OPIE_NO_BACKTRACE 590#ifndef OPIE_NO_BACKTRACE
602 void* trace[256]; 591 void* trace[256];
603 int n = backtrace(trace, 256); 592 int n = backtrace(trace, 256);
604 char** strings = backtrace_symbols (trace, n); 593 char** strings = backtrace_symbols (trace, n);
605 594
606 if ( levels != -1 ) 595 if ( levels != -1 )
607 n = QMIN( n, levels ); 596 n = QMIN( n, levels );
608 s = "[\n"; 597 s = "[\n";
609 598
610 for (int i = 0; i < n; ++i) 599 for (int i = 0; i < n; ++i)
611 s += QString::number(i) + 600 s += QString::number(i) +
612 QString::fromLatin1(": ") + 601 QString::fromLatin1(": ") +
613 QString::fromLatin1(strings[i]) + QString::fromLatin1("\n"); 602 QString::fromLatin1(strings[i]) + QString::fromLatin1("\n");
614 s += "]\n"; 603 s += "]\n";
615 free (strings); 604 free (strings);
616#endif 605#endif
617 return s; 606 return s;
618} 607}
619 608
620void odClearDebugConfig() 609void odClearDebugConfig()
621{ 610{
622 /* 611 /*
623 delete oDebug_data->config; 612 delete oDebug_data->config;
624 oDebug_data->config = 0; 613 oDebug_data->config = 0;
625 */ 614 */
626} 615}
627 616
628#ifdef OPIE_NO_DEBUG 617#ifdef OPIE_NO_DEBUG
629#define odDebug ondDebug 618#define odDebug ondDebug
630#define odBacktrace ondBacktrace 619#define odBacktrace ondBacktrace
631#endif 620#endif
diff --git a/libopie2/opiecore/oglobal.cpp b/libopie2/opiecore/oglobal.cpp
index 879e80f..1aa206e 100644
--- a/libopie2/opiecore/oglobal.cpp
+++ b/libopie2/opiecore/oglobal.cpp
@@ -1,411 +1,410 @@
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 <qfile.h>
33#include <qtextstream.h> 32#include <qtextstream.h>
34#include <qdir.h> 33#include <qdir.h>
35#include <qpe/mimetype.h> 34#include <qpe/mimetype.h>
36#include <qpe/qpeapplication.h> 35#include <qpe/qpeapplication.h>
37#include <qpe/storage.h> 36#include <qpe/storage.h>
38 37
39#include <unistd.h> 38#include <unistd.h>
40#include <sys/types.h> 39#include <sys/types.h>
41 40
42static const char Base64EncMap[64] = 41static const char Base64EncMap[64] =
43{ 42{
44 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 43 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
45 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 44 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50,
46 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 45 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
47 0x59, 0x5A, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 46 0x59, 0x5A, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
48 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 47 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E,
49 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 48 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76,
50 0x77, 0x78, 0x79, 0x7A, 0x30, 0x31, 0x32, 0x33, 49 0x77, 0x78, 0x79, 0x7A, 0x30, 0x31, 0x32, 0x33,
51 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x2B, 0x2F 50 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x2B, 0x2F
52}; 51};
53 52
54static char Base64DecMap[128] = 53static char Base64DecMap[128] =
55{ 54{
56 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 55 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
57 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 56 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
58 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 57 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
59 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 58 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
60 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 59 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
61 0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x3F, 60 0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x3F,
62 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 61 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B,
63 0x3C, 0x3D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 62 0x3C, 0x3D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
64 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 63 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
65 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 64 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E,
66 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 65 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16,
67 0x17, 0x18, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, 66 0x17, 0x18, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00,
68 0x00, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 67 0x00, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20,
69 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 68 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28,
70 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, 69 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30,
71 0x31, 0x32, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00 70 0x31, 0x32, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00
72}; 71};
73 72
74 73
75OConfig* OGlobal::_config = 0; 74OConfig* OGlobal::_config = 0;
76OConfig* OGlobal::_qpe_config = 0; 75OConfig* OGlobal::_qpe_config = 0;
77 76
78OConfig* OGlobal::config() 77OConfig* OGlobal::config()
79{ 78{
80 if ( !OGlobal::_config ) 79 if ( !OGlobal::_config )
81 { 80 {
82 // odebug classes are reading config, so can't use them here! 81 // odebug classes are reading config, so can't use them here!
83 qDebug( "OGlobal::creating global configuration instance." ); 82 qDebug( "OGlobal::creating global configuration instance." );
84 OGlobal::_config = new OConfig( "global" ); 83 OGlobal::_config = new OConfig( "global" );
85 } 84 }
86 return OGlobal::_config; 85 return OGlobal::_config;
87} 86}
88 87
89 88
90/** 89/**
91 * Return the internal builtin Global::Command object 90 * Return the internal builtin Global::Command object
92 * 91 *
93 */ 92 */
94Global::Command* OGlobal::builtinCommands() { 93Global::Command* OGlobal::builtinCommands() {
95 return builtin; 94 return builtin;
96} 95}
97 96
98 97
99/** 98/**
100 * Return the internal builtin QGuardedPtr<QWidget> object 99 * Return the internal builtin QGuardedPtr<QWidget> object
101 */ 100 */
102QGuardedPtr<QWidget>* OGlobal::builtinRunning() { 101QGuardedPtr<QWidget>* OGlobal::builtinRunning() {
103 return running; 102 return running;
104} 103}
105 104
106 105
107/** 106/**
108 * \brief generate a new UUID as QString 107 * \brief generate a new UUID as QString
109 * Return a new UUID as QString. UUID are global unique 108 * Return a new UUID as QString. UUID are global unique
110 * 109 *
111 * 110 *
112 * @return the UUID or QString::null 111 * @return the UUID or QString::null
113 */ 112 */
114QString OGlobal::generateUuid() { 113QString OGlobal::generateUuid() {
115 QFile file( "/proc/sys/kernel/random/uuid" ); 114 QFile file( "/proc/sys/kernel/random/uuid" );
116 if (!file.open(IO_ReadOnly ) ) 115 if (!file.open(IO_ReadOnly ) )
117 return QString::null; 116 return QString::null;
118 117
119 QTextStream stream(&file); 118 QTextStream stream(&file);
120 119
121 return "{" + stream.read().stripWhiteSpace() + "}"; 120 return "{" + stream.read().stripWhiteSpace() + "}";
122} 121}
123 122
124 123
125/** 124/**
126 * \brief Encode a QByteArray in base64 125 * \brief Encode a QByteArray in base64
127 * 126 *
128 * An Implementation of the RF1521 base64 encoding. 127 * An Implementation of the RF1521 base64 encoding.
129 * 128 *
130 * The boolean argument determines if the encoded data is 129 * The boolean argument determines if the encoded data is
131 * going to be restricted to 76 characters or less per line 130 * going to be restricted to 76 characters or less per line
132 * as specified by RFC 2045. If @p insertLFs is true, then 131 * as specified by RFC 2045. If @p insertLFs is true, then
133 * there will be 76 characters or less per line. 132 * there will be 76 characters or less per line.
134 * 133 *
135 * If you use this to create a QCString remember that it is null terminated! 134 * If you use this to create a QCString remember that it is null terminated!
136 * \code 135 * \code
137 * QByteArray ar = OGlobal::encodeBase64(&array); 136 * QByteArray ar = OGlobal::encodeBase64(&array);
138 * QCString str(ar.data(),ar.size()+1); // the NUL at the end 137 * QCString str(ar.data(),ar.size()+1); // the NUL at the end
139 * 138 *
140 * \endcode 139 * \endcode
141 * 140 *
142 * @param in The QByteArray to encode 141 * @param in The QByteArray to encode
143 * @param insertLFs Limit number of characters per line 142 * @param insertLFs Limit number of characters per line
144 * @return The argument as base64 encoded or QByteArray() if in.isEmpty() 143 * @return The argument as base64 encoded or QByteArray() if in.isEmpty()
145 * @see QByteArray 144 * @see QByteArray
146 * @see QArray 145 * @see QArray
147 * @see QMemArray 146 * @see QMemArray
148 * @see QCString 147 * @see QCString
149 */ 148 */
150/* 149/*
151 * LGPL by Rik Hemsely of the KDE Project. taken from kmdcodec.cpp 150 * LGPL by Rik Hemsely of the KDE Project. taken from kmdcodec.cpp
152 */ 151 */
153QByteArray OGlobal::encodeBase64(const QByteArray& in, bool insertLFs ) { 152QByteArray OGlobal::encodeBase64(const QByteArray& in, bool insertLFs ) {
154 if ( in.isEmpty() ) 153 if ( in.isEmpty() )
155 return QByteArray(); 154 return QByteArray();
156 155
157 unsigned int sidx = 0; 156 unsigned int sidx = 0;
158 unsigned int didx = 0; 157 unsigned int didx = 0;
159 const char* data = in.data(); 158 const char* data = in.data();
160 const unsigned int len = in.size(); 159 const unsigned int len = in.size();
161 160
162 unsigned int out_len = ((len+2)/3)*4; 161 unsigned int out_len = ((len+2)/3)*4;
163 162
164 // Deal with the 76 characters or less per 163 // Deal with the 76 characters or less per
165 // line limit specified in RFC 2045 on a 164 // line limit specified in RFC 2045 on a
166 // pre request basis. 165 // pre request basis.
167 insertLFs = (insertLFs && out_len > 76); 166 insertLFs = (insertLFs && out_len > 76);
168 if ( insertLFs ) 167 if ( insertLFs )
169 out_len += ((out_len-1)/76); 168 out_len += ((out_len-1)/76);
170 169
171 int count = 0; 170 int count = 0;
172 QByteArray out( out_len ); 171 QByteArray out( out_len );
173 172
174 // 3-byte to 4-byte conversion + 0-63 to ascii printable conversion 173 // 3-byte to 4-byte conversion + 0-63 to ascii printable conversion
175 if ( len > 1 ) 174 if ( len > 1 )
176 { 175 {
177 while (sidx < len-2) 176 while (sidx < len-2)
178 { 177 {
179 if ( insertLFs ) 178 if ( insertLFs )
180 { 179 {
181 if ( count && (count%76) == 0 ) 180 if ( count && (count%76) == 0 )
182 out[didx++] = '\n'; 181 out[didx++] = '\n';
183 count += 4; 182 count += 4;
184 } 183 }
185 out[didx++] = Base64EncMap[(data[sidx] >> 2) & 077]; 184 out[didx++] = Base64EncMap[(data[sidx] >> 2) & 077];
186 out[didx++] = Base64EncMap[(data[sidx+1] >> 4) & 017 | 185 out[didx++] = Base64EncMap[(data[sidx+1] >> 4) & 017 |
187 (data[sidx] << 4) & 077]; 186 (data[sidx] << 4) & 077];
188 out[didx++] = Base64EncMap[(data[sidx+2] >> 6) & 003 | 187 out[didx++] = Base64EncMap[(data[sidx+2] >> 6) & 003 |
189 (data[sidx+1] << 2) & 077]; 188 (data[sidx+1] << 2) & 077];
190 out[didx++] = Base64EncMap[data[sidx+2] & 077]; 189 out[didx++] = Base64EncMap[data[sidx+2] & 077];
191 sidx += 3; 190 sidx += 3;
192 } 191 }
193 } 192 }
194 193
195 if (sidx < len) 194 if (sidx < len)
196 { 195 {
197 if ( insertLFs && (count > 0) && (count%76) == 0 ) 196 if ( insertLFs && (count > 0) && (count%76) == 0 )
198 out[didx++] = '\n'; 197 out[didx++] = '\n';
199 198
200 out[didx++] = Base64EncMap[(data[sidx] >> 2) & 077]; 199 out[didx++] = Base64EncMap[(data[sidx] >> 2) & 077];
201 if (sidx < len-1) 200 if (sidx < len-1)
202 { 201 {
203 out[didx++] = Base64EncMap[(data[sidx+1] >> 4) & 017 | 202 out[didx++] = Base64EncMap[(data[sidx+1] >> 4) & 017 |
204 (data[sidx] << 4) & 077]; 203 (data[sidx] << 4) & 077];
205 out[didx++] = Base64EncMap[(data[sidx+1] << 2) & 077]; 204 out[didx++] = Base64EncMap[(data[sidx+1] << 2) & 077];
206 } 205 }
207 else 206 else
208 { 207 {
209 out[didx++] = Base64EncMap[(data[sidx] << 4) & 077]; 208 out[didx++] = Base64EncMap[(data[sidx] << 4) & 077];
210 } 209 }
211 } 210 }
212 211
213 // Add padding 212 // Add padding
214 while (didx < out.size()) 213 while (didx < out.size())
215 { 214 {
216 out[didx] = '='; 215 out[didx] = '=';
217 didx++; 216 didx++;
218 } 217 }
219 218
220 return out; 219 return out;
221} 220}
222 221
223/** 222/**
224 * Decodes the given data that was encoded with the base64 223 * Decodes the given data that was encoded with the base64
225 * algorithm. 224 * algorithm.
226 * 225 *
227 * 226 *
228 * @param in the encoded data to be decoded. 227 * @param in the encoded data to be decoded.
229 * @return the decoded QByteArray or QByteArray() in case of failure 228 * @return the decoded QByteArray or QByteArray() in case of failure
230 * @see OGlobal::encodeBase64 229 * @see OGlobal::encodeBase64
231 */ 230 */
232QByteArray OGlobal::decodeBase64( const QByteArray& in) { 231QByteArray OGlobal::decodeBase64( const QByteArray& in) {
233 if ( in.isEmpty() ) 232 if ( in.isEmpty() )
234 return QByteArray(); 233 return QByteArray();
235 234
236 QByteArray out; 235 QByteArray out;
237 unsigned int count = 0; 236 unsigned int count = 0;
238 unsigned int len = in.size(), tail = len; 237 unsigned int len = in.size(), tail = len;
239 const char* data = in.data(); 238 const char* data = in.data();
240 239
241 // Deal with possible *nix "BEGIN" marker!! 240 // Deal with possible *nix "BEGIN" marker!!
242 while ( count < len && (data[count] == '\n' || data[count] == '\r' || 241 while ( count < len && (data[count] == '\n' || data[count] == '\r' ||
243 data[count] == '\t' || data[count] == ' ') ) 242 data[count] == '\t' || data[count] == ' ') )
244 count++; 243 count++;
245 244
246 if ( strncasecmp(data+count, "begin", 5) == 0 ) 245 if ( strncasecmp(data+count, "begin", 5) == 0 )
247 { 246 {
248 count += 5; 247 count += 5;
249 while ( count < len && data[count] != '\n' && data[count] != '\r' ) 248 while ( count < len && data[count] != '\n' && data[count] != '\r' )
250 count++; 249 count++;
251 250
252 while ( count < len && (data[count] == '\n' || data[count] == '\r') ) 251 while ( count < len && (data[count] == '\n' || data[count] == '\r') )
253 count ++; 252 count ++;
254 253
255 data += count; 254 data += count;
256 tail = (len -= count); 255 tail = (len -= count);
257 } 256 }
258 257
259 // Find the tail end of the actual encoded data even if 258 // Find the tail end of the actual encoded data even if
260 // there is/are trailing CR and/or LF. 259 // there is/are trailing CR and/or LF.
261 while ( data[tail-1] == '=' || data[tail-1] == '\n' || 260 while ( data[tail-1] == '=' || data[tail-1] == '\n' ||
262 data[tail-1] == '\r' ) 261 data[tail-1] == '\r' )
263 if ( data[--tail] != '=' ) len = tail; 262 if ( data[--tail] != '=' ) len = tail;
264 263
265 unsigned int outIdx = 0; 264 unsigned int outIdx = 0;
266 out.resize( (count=len) ); 265 out.resize( (count=len) );
267 for (unsigned int idx = 0; idx < count; idx++) 266 for (unsigned int idx = 0; idx < count; idx++)
268 { 267 {
269 // Adhere to RFC 2045 and ignore characters 268 // Adhere to RFC 2045 and ignore characters
270 // that are not part of the encoding table. 269 // that are not part of the encoding table.
271 unsigned char ch = data[idx]; 270 unsigned char ch = data[idx];
272 if ( (ch > 47 && ch < 58) || (ch > 64 && ch < 91 ) || 271 if ( (ch > 47 && ch < 58) || (ch > 64 && ch < 91 ) ||
273 (ch > 96 && ch < 123)|| ch == '+' || ch == '/' || ch == '=') 272 (ch > 96 && ch < 123)|| ch == '+' || ch == '/' || ch == '=')
274 { 273 {
275 out[outIdx++] = Base64DecMap[ch]; 274 out[outIdx++] = Base64DecMap[ch];
276 } 275 }
277 else 276 else
278 { 277 {
279 len--; 278 len--;
280 tail--; 279 tail--;
281 } 280 }
282 } 281 }
283 282
284 // kdDebug() << "Tail size = " << tail << ", Length size = " << len << endl; 283 // kdDebug() << "Tail size = " << tail << ", Length size = " << len << endl;
285 284
286 // 4-byte to 3-byte conversion 285 // 4-byte to 3-byte conversion
287 len = (tail>(len/4)) ? tail-(len/4) : 0; 286 len = (tail>(len/4)) ? tail-(len/4) : 0;
288 unsigned int sidx = 0, didx = 0; 287 unsigned int sidx = 0, didx = 0;
289 if ( len > 1 ) 288 if ( len > 1 )
290 { 289 {
291 while (didx < len-2) 290 while (didx < len-2)
292 { 291 {
293 out[didx] = (((out[sidx] << 2) & 255) | ((out[sidx+1] >> 4) & 003)); 292 out[didx] = (((out[sidx] << 2) & 255) | ((out[sidx+1] >> 4) & 003));
294 out[didx+1] = (((out[sidx+1] << 4) & 255) | ((out[sidx+2] >> 2) & 017)); 293 out[didx+1] = (((out[sidx+1] << 4) & 255) | ((out[sidx+2] >> 2) & 017));
295 out[didx+2] = (((out[sidx+2] << 6) & 255) | (out[sidx+3] & 077)); 294 out[didx+2] = (((out[sidx+2] << 6) & 255) | (out[sidx+3] & 077));
296 sidx += 4; 295 sidx += 4;
297 didx += 3; 296 didx += 3;
298 } 297 }
299 } 298 }
300 299
301 if (didx < len) 300 if (didx < len)
302 out[didx] = (((out[sidx] << 2) & 255) | ((out[sidx+1] >> 4) & 003)); 301 out[didx] = (((out[sidx] << 2) & 255) | ((out[sidx+1] >> 4) & 003));
303 302
304 if (++didx < len ) 303 if (++didx < len )
305 out[didx] = (((out[sidx+1] << 4) & 255) | ((out[sidx+2] >> 2) & 017)); 304 out[didx] = (((out[sidx+1] << 4) & 255) | ((out[sidx+2] >> 2) & 017));
306 305
307 // Resize the output buffer 306 // Resize the output buffer
308 if ( len == 0 || len < out.size() ) 307 if ( len == 0 || len < out.size() )
309 out.resize(len); 308 out.resize(len);
310 309
311 return out; 310 return out;
312} 311}
313 312
314bool OGlobal::isAppLnkFileName( const QString& str ) 313bool OGlobal::isAppLnkFileName( const QString& str )
315{ 314{
316 if (str.length()==0||str.at(str.length()-1)==QDir::separator()) return false; 315 if (str.length()==0||str.at(str.length()-1)==QDir::separator()) return false;
317 return str.startsWith(MimeType::appsFolderName()+QDir::separator()); 316 return str.startsWith(MimeType::appsFolderName()+QDir::separator());
318} 317}
319 318
320/* ToDo: 319/* ToDo:
321 * This fun should check the document-path value for the mounted media 320 * 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 321 * which has to be implemented later. this moment we just check for a
323 * mounted media name. 322 * mounted media name.
324 */ 323 */
325bool OGlobal::isDocumentFileName( const QString& file ) 324bool OGlobal::isDocumentFileName( const QString& file )
326{ 325{
327 if (file.length()==0||file.at(file.length()-1)==QDir::separator()) return false; 326 if (file.length()==0||file.at(file.length()-1)==QDir::separator()) return false;
328 if (file.startsWith(QPEApplication::documentDir()+QDir::separator())) return true; 327 if (file.startsWith(QPEApplication::documentDir()+QDir::separator())) return true;
329 StorageInfo si; 328 StorageInfo si;
330 QList< FileSystem > fl = si.fileSystems(); 329 QList< FileSystem > fl = si.fileSystems();
331 FileSystem*fs; 330 FileSystem*fs;
332 for (fs = fl.first();fs!=0;fs=fl.next()) { 331 for (fs = fl.first();fs!=0;fs=fl.next()) {
333 if (fs->isRemovable()&&file.startsWith(fs->name()+QDir::separator())) 332 if (fs->isRemovable()&&file.startsWith(fs->name()+QDir::separator()))
334 return true; 333 return true;
335 } 334 }
336 if (file.startsWith(homeDirPath())+"/Documents/") return true; 335 if (file.startsWith(homeDirPath())+"/Documents/") return true;
337 return false; 336 return false;
338} 337}
339 338
340QString OGlobal::tempDirPath() 339QString OGlobal::tempDirPath()
341{ 340{
342 static QString defstring="/tmp"; 341 static QString defstring="/tmp";
343 char * tmpp = 0; 342 char * tmpp = 0;
344 if ( (tmpp=getenv("TEMP"))) { 343 if ( (tmpp=getenv("TEMP"))) {
345 return tmpp; 344 return tmpp;
346 } 345 }
347 return defstring; 346 return defstring;
348} 347}
349 348
350QString OGlobal::homeDirPath() 349QString OGlobal::homeDirPath()
351{ 350{
352 char * tmpp = getenv("HOME"); 351 char * tmpp = getenv("HOME");
353 return (tmpp?tmpp:"/"); 352 return (tmpp?tmpp:"/");
354} 353}
355 354
356bool OGlobal::weekStartsOnMonday() 355bool OGlobal::weekStartsOnMonday()
357{ 356{
358 OConfig*conf=OGlobal::qpe_config(); 357 OConfig*conf=OGlobal::qpe_config();
359 if (!conf)return false; 358 if (!conf)return false;
360 conf->setGroup("Time"); 359 conf->setGroup("Time");
361 return conf->readBoolEntry("MONDAY",true); 360 return conf->readBoolEntry("MONDAY",true);
362} 361}
363 362
364void OGlobal::setWeekStartsOnMonday( bool what) 363void OGlobal::setWeekStartsOnMonday( bool what)
365{ 364{
366 OConfig*conf=OGlobal::qpe_config(); 365 OConfig*conf=OGlobal::qpe_config();
367 if (!conf)return; 366 if (!conf)return;
368 conf->setGroup("Time"); 367 conf->setGroup("Time");
369 return conf->writeEntry("MONDAY",what); 368 return conf->writeEntry("MONDAY",what);
370} 369}
371 370
372bool OGlobal::useAMPM() 371bool OGlobal::useAMPM()
373{ 372{
374 OConfig*conf=OGlobal::qpe_config(); 373 OConfig*conf=OGlobal::qpe_config();
375 if (!conf)return false; 374 if (!conf)return false;
376 conf->setGroup("Time"); 375 conf->setGroup("Time");
377 return conf->readBoolEntry("AMPM",false); 376 return conf->readBoolEntry("AMPM",false);
378} 377}
379 378
380void OGlobal::setUseAMPM( bool what) 379void OGlobal::setUseAMPM( bool what)
381{ 380{
382 OConfig*conf=OGlobal::qpe_config(); 381 OConfig*conf=OGlobal::qpe_config();
383 if (!conf)return; 382 if (!conf)return;
384 conf->setGroup("Time"); 383 conf->setGroup("Time");
385 return conf->writeEntry("AMPM",what); 384 return conf->writeEntry("AMPM",what);
386} 385}
387 386
388OConfig* OGlobal::qpe_config() 387OConfig* OGlobal::qpe_config()
389{ 388{
390 if ( !OGlobal::_qpe_config ) { 389 if ( !OGlobal::_qpe_config ) {
391 OGlobal::_qpe_config = new OConfig( "qpe" ); 390 OGlobal::_qpe_config = new OConfig( "qpe" );
392 } 391 }
393 return OGlobal::_qpe_config; 392 return OGlobal::_qpe_config;
394} 393}
395 394
396bool OGlobal::truncateFile( QFile &f, off_t size ) 395bool OGlobal::truncateFile( QFile &f, off_t size )
397{ 396{
398 /* or should we let enlarge Files? then remove this 397 /* or should we let enlarge Files? then remove this
399 f.size()< part! - Alwin 398 f.size()< part! - Alwin
400 */ 399 */
401 if (!f.exists()||f.size()<(unsigned)size) return false; 400 if (!f.exists()||f.size()<(unsigned)size) return false;
402 bool closeit=false; 401 bool closeit=false;
403 if (!f.isOpen()) { 402 if (!f.isOpen()) {
404 closeit=true; 403 closeit=true;
405 f.open(IO_Raw | IO_ReadWrite | IO_Append); 404 f.open(IO_Raw | IO_ReadWrite | IO_Append);
406 } 405 }
407 if (!f.isOpen()) { return false; } 406 if (!f.isOpen()) { return false; }
408 int r = ftruncate(f.handle(),size); 407 int r = ftruncate(f.handle(),size);
409 if (closeit) f.close(); 408 if (closeit) f.close();
410 return r==0; 409 return r==0;
411} 410}
diff --git a/libopie2/opiecore/oglobalsettings.cpp b/libopie2/opiecore/oglobalsettings.cpp
index 66adbd0..192e55b 100644
--- a/libopie2/opiecore/oglobalsettings.cpp
+++ b/libopie2/opiecore/oglobalsettings.cpp
@@ -1,548 +1,545 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3 3
4              Copyright (C) 2003 Michael Lauer <mickey@tm.informatik.uni-frankfurt.de> 4              Copyright (C) 2003 Michael Lauer <mickey@tm.informatik.uni-frankfurt.de>
5 Inspired by the KDE globalsettings which are 5 Inspired by the KDE globalsettings which are
6 Copyright (C) 2000 David Faure <faure@kde.org> 6 Copyright (C) 2000 David Faure <faure@kde.org>
7 =. 7 =.
8 .=l. 8 .=l.
9           .>+-= 9           .>+-=
10 _;:,     .>    :=|. This program is free software; you can 10 _;:,     .>    :=|. This program is free software; you can
11.> <`_,   >  .   <= redistribute it and/or modify it under 11.> <`_,   >  .   <= redistribute it and/or modify it under
12:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 12:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
13.="- .-=="i,     .._ License as published by the Free Software 13.="- .-=="i,     .._ License as published by the Free Software
14 - .   .-<_>     .<> Foundation; either version 2 of the License, 14 - .   .-<_>     .<> Foundation; either version 2 of the License,
15     ._= =}       : or (at your option) any later version. 15     ._= =}       : or (at your option) any later version.
16    .%`+i>       _;_. 16    .%`+i>       _;_.
17    .i_,=:_.      -<s. This program is distributed in the hope that 17    .i_,=:_.      -<s. This program is distributed in the hope that
18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
19    : ..    .:,     . . . without even the implied warranty of 19    : ..    .:,     . . . without even the implied warranty of
20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
22..}^=.=       =       ; Library General Public License for more 22..}^=.=       =       ; Library General Public License for more
23++=   -.     .`     .: details. 23++=   -.     .`     .: details.
24 :     =  ...= . :.=- 24 :     =  ...= . :.=-
25 -.   .:....=;==+<; You should have received a copy of the GNU 25 -.   .:....=;==+<; You should have received a copy of the GNU
26  -_. . .   )=.  = Library General Public License along with 26  -_. . .   )=.  = Library General Public License along with
27    --        :-=` this library; see the file COPYING.LIB. 27    --        :-=` this library; see the file COPYING.LIB.
28 If not, write to the Free Software Foundation, 28 If not, write to the Free Software Foundation,
29 Inc., 59 Temple Place - Suite 330, 29 Inc., 59 Temple Place - Suite 330,
30 Boston, MA 02111-1307, USA. 30 Boston, MA 02111-1307, USA.
31*/ 31*/
32 32
33/* OPIE */ 33/* OPIE */
34 34
35#include <opie2/oglobalsettings.h> 35#include <opie2/oglobalsettings.h>
36#include <opie2/oconfig.h> 36#include <opie2/oconfig.h>
37#include <opie2/oglobal.h> 37#include <opie2/oglobal.h>
38 38
39/* QT */ 39/* QT */
40 40
41#include <qobject.h>
42#include <qdir.h> 41#include <qdir.h>
43#include <qpixmap.h>
44#include <qfontinfo.h>
45 42
46/* UNIX */ 43/* UNIX */
47 44
48#include <stdlib.h> 45#include <stdlib.h>
49 46
50QString* OGlobalSettings::s_desktopPath = 0; 47QString* OGlobalSettings::s_desktopPath = 0;
51QString* OGlobalSettings::s_autostartPath = 0; 48QString* OGlobalSettings::s_autostartPath = 0;
52QString* OGlobalSettings::s_trashPath = 0; 49QString* OGlobalSettings::s_trashPath = 0;
53QString* OGlobalSettings::s_documentPath = 0; 50QString* OGlobalSettings::s_documentPath = 0;
54QFont *OGlobalSettings::_generalFont = 0; 51QFont *OGlobalSettings::_generalFont = 0;
55QFont *OGlobalSettings::_fixedFont = 0; 52QFont *OGlobalSettings::_fixedFont = 0;
56QFont *OGlobalSettings::_toolBarFont = 0; 53QFont *OGlobalSettings::_toolBarFont = 0;
57QFont *OGlobalSettings::_menuFont = 0; 54QFont *OGlobalSettings::_menuFont = 0;
58QFont *OGlobalSettings::_windowTitleFont = 0; 55QFont *OGlobalSettings::_windowTitleFont = 0;
59QFont *OGlobalSettings::_taskbarFont = 0; 56QFont *OGlobalSettings::_taskbarFont = 0;
60 57
61QColor *OGlobalSettings::OpieGray = 0; 58QColor *OGlobalSettings::OpieGray = 0;
62QColor *OGlobalSettings::OpieHighlight = 0; 59QColor *OGlobalSettings::OpieHighlight = 0;
63QColor *OGlobalSettings::OpieAlternate = 0; 60QColor *OGlobalSettings::OpieAlternate = 0;
64 61
65OGlobalSettings::OMouseSettings *OGlobalSettings::s_mouseSettings = 0; 62OGlobalSettings::OMouseSettings *OGlobalSettings::s_mouseSettings = 0;
66 63
67//FIXME: Add manipulators to the accessors 64//FIXME: Add manipulators to the accessors
68 65
69int OGlobalSettings::dndEventDelay() 66int OGlobalSettings::dndEventDelay()
70{ 67{
71 OConfig *c = OGlobal::config(); 68 OConfig *c = OGlobal::config();
72 OConfigGroupSaver cgs( c, "General" ); 69 OConfigGroupSaver cgs( c, "General" );
73 return c->readNumEntry("DndDelay", 2); 70 return c->readNumEntry("DndDelay", 2);
74} 71}
75 72
76bool OGlobalSettings::singleClick() 73bool OGlobalSettings::singleClick()
77{ 74{
78 OConfig *c = OGlobal::config(); 75 OConfig *c = OGlobal::config();
79 OConfigGroupSaver cgs( c, "OPIE" ); 76 OConfigGroupSaver cgs( c, "OPIE" );
80 return c->readBoolEntry("SingleClick", OPIE_DEFAULT_SINGLECLICK); 77 return c->readBoolEntry("SingleClick", OPIE_DEFAULT_SINGLECLICK);
81} 78}
82 79
83bool OGlobalSettings::insertTearOffHandle() 80bool OGlobalSettings::insertTearOffHandle()
84{ 81{
85 OConfig *c = OGlobal::config(); 82 OConfig *c = OGlobal::config();
86 OConfigGroupSaver cgs( c, "OPIE" ); 83 OConfigGroupSaver cgs( c, "OPIE" );
87 return c->readBoolEntry("InsertTearOffHandle", OPIE_DEFAULT_INSERTTEAROFFHANDLES); 84 return c->readBoolEntry("InsertTearOffHandle", OPIE_DEFAULT_INSERTTEAROFFHANDLES);
88} 85}
89 86
90bool OGlobalSettings::changeCursorOverIcon() 87bool OGlobalSettings::changeCursorOverIcon()
91{ 88{
92 OConfig *c = OGlobal::config(); 89 OConfig *c = OGlobal::config();
93 OConfigGroupSaver cgs( c, "OPIE" ); 90 OConfigGroupSaver cgs( c, "OPIE" );
94 return c->readBoolEntry("ChangeCursor", OPIE_DEFAULT_CHANGECURSOR); 91 return c->readBoolEntry("ChangeCursor", OPIE_DEFAULT_CHANGECURSOR);
95} 92}
96 93
97bool OGlobalSettings::visualActivate() 94bool OGlobalSettings::visualActivate()
98{ 95{
99 OConfig *c = OGlobal::config(); 96 OConfig *c = OGlobal::config();
100 OConfigGroupSaver cgs( c, "OPIE" ); 97 OConfigGroupSaver cgs( c, "OPIE" );
101 return c->readBoolEntry("VisualActivate", OPIE_DEFAULT_VISUAL_ACTIVATE); 98 return c->readBoolEntry("VisualActivate", OPIE_DEFAULT_VISUAL_ACTIVATE);
102} 99}
103 100
104unsigned int OGlobalSettings::visualActivateSpeed() 101unsigned int OGlobalSettings::visualActivateSpeed()
105{ 102{
106 OConfig *c = OGlobal::config(); 103 OConfig *c = OGlobal::config();
107 OConfigGroupSaver cgs( c, "OPIE" ); 104 OConfigGroupSaver cgs( c, "OPIE" );
108 return 105 return
109 c->readNumEntry( 106 c->readNumEntry(
110 "VisualActivateSpeed", 107 "VisualActivateSpeed",
111 OPIE_DEFAULT_VISUAL_ACTIVATE_SPEED 108 OPIE_DEFAULT_VISUAL_ACTIVATE_SPEED
112 ); 109 );
113} 110}
114 111
115int OGlobalSettings::autoSelectDelay() 112int OGlobalSettings::autoSelectDelay()
116{ 113{
117 OConfig *c = OGlobal::config(); 114 OConfig *c = OGlobal::config();
118 OConfigGroupSaver cgs( c, "OPIE" ); 115 OConfigGroupSaver cgs( c, "OPIE" );
119 return c->readNumEntry("AutoSelectDelay", OPIE_DEFAULT_AUTOSELECTDELAY); 116 return c->readNumEntry("AutoSelectDelay", OPIE_DEFAULT_AUTOSELECTDELAY);
120} 117}
121 118
122OGlobalSettings::Completion OGlobalSettings::completionMode() 119OGlobalSettings::Completion OGlobalSettings::completionMode()
123{ 120{
124 int completion; 121 int completion;
125 OConfig *c = OGlobal::config(); 122 OConfig *c = OGlobal::config();
126 OConfigGroupSaver cgs( c, "General" ); 123 OConfigGroupSaver cgs( c, "General" );
127 completion = c->readNumEntry("completionMode", -1); 124 completion = c->readNumEntry("completionMode", -1);
128 if ((completion < (int) CompletionNone) || 125 if ((completion < (int) CompletionNone) ||
129 (completion > (int) CompletionPopupAuto)) 126 (completion > (int) CompletionPopupAuto))
130 { 127 {
131 completion = (int) CompletionPopup; // Default 128 completion = (int) CompletionPopup; // Default
132 } 129 }
133 return (Completion) completion; 130 return (Completion) completion;
134} 131}
135 132
136 133
137bool OGlobalSettings::showContextMenusOnPress () 134bool OGlobalSettings::showContextMenusOnPress ()
138{ 135{
139 OConfig *c = OGlobal::config(); 136 OConfig *c = OGlobal::config();
140 OConfigGroupSaver cgs (c, "ContextMenus"); 137 OConfigGroupSaver cgs (c, "ContextMenus");
141 138
142 return cgs.config()->readBoolEntry("ShowOnPress", true); 139 return cgs.config()->readBoolEntry("ShowOnPress", true);
143} 140}
144 141
145 142
146int OGlobalSettings::contextMenuKey () 143int OGlobalSettings::contextMenuKey ()
147{ 144{
148 OConfig *c = OGlobal::config(); 145 OConfig *c = OGlobal::config();
149 OConfigGroupSaver cgs (c, "Shortcuts"); 146 OConfigGroupSaver cgs (c, "Shortcuts");
150 147
151 //OShortcut cut (cgs.config()->readEntry ("PopupMenuContext", "Menu")); 148 //OShortcut cut (cgs.config()->readEntry ("PopupMenuContext", "Menu"));
152 //return cut.keyCodeQt(); 149 //return cut.keyCodeQt();
153 150
154 return 0; // FIXME 151 return 0; // FIXME
155} 152}
156 153
157 154
158OGlobalSettings::Debug OGlobalSettings::debugMode() 155OGlobalSettings::Debug OGlobalSettings::debugMode()
159{ 156{
160 OConfig *c = OGlobal::config(); 157 OConfig *c = OGlobal::config();
161 OConfigGroupSaver cgs( c, "General" ); 158 OConfigGroupSaver cgs( c, "General" );
162 int debug = c->readNumEntry( "debugMode", -1 ); 159 int debug = c->readNumEntry( "debugMode", -1 );
163 if ( (debug < (int) DebugNone) || (debug > (int) DebugSocket) ) 160 if ( (debug < (int) DebugNone) || (debug > (int) DebugSocket) )
164 { 161 {
165 debug = (int) DebugStdErr; // Default 162 debug = (int) DebugStdErr; // Default
166 } 163 }
167 return (Debug) debug; 164 return (Debug) debug;
168} 165}
169 166
170 167
171QString OGlobalSettings::debugOutput() 168QString OGlobalSettings::debugOutput()
172{ 169{
173 OConfig *c = OGlobal::config(); 170 OConfig *c = OGlobal::config();
174 OConfigGroupSaver cgs( c, "General" ); 171 OConfigGroupSaver cgs( c, "General" );
175 QString deflt = QString::null; 172 QString deflt = QString::null;
176 switch( debugMode() ) 173 switch( debugMode() )
177 { 174 {
178 case DebugNone: break; // no additional information needed 175 case DebugNone: break; // no additional information needed
179 case DebugFiles: deflt = "/var/log/opiedebug.log"; break; // file to save output in 176 case DebugFiles: deflt = "/var/log/opiedebug.log"; break; // file to save output in
180 case DebugMsgBox: break; // no additional information needed 177 case DebugMsgBox: break; // no additional information needed
181 case DebugStdErr: break; // no additional information needed 178 case DebugStdErr: break; // no additional information needed
182 case DebugSysLog: break; // no additional information needed 179 case DebugSysLog: break; // no additional information needed
183 case DebugSocket: deflt = "127.0.0.1:8913"; break; // address to send packets to 180 case DebugSocket: deflt = "127.0.0.1:8913"; break; // address to send packets to
184 } 181 }
185 182
186 return c->readEntry( "debugOutput"+ QString::number(debugMode()), deflt ); 183 return c->readEntry( "debugOutput"+ QString::number(debugMode()), deflt );
187} 184}
188 185
189 186
190QColor OGlobalSettings::toolBarHighlightColor() 187QColor OGlobalSettings::toolBarHighlightColor()
191{ 188{
192 initColors(); 189 initColors();
193 OConfig *c = OGlobal::config(); 190 OConfig *c = OGlobal::config();
194 OConfigGroupSaver cgs( c, QString::fromLatin1("Toolbar style") ); 191 OConfigGroupSaver cgs( c, QString::fromLatin1("Toolbar style") );
195 return c->readColorEntry("HighlightColor", OpieHighlight); 192 return c->readColorEntry("HighlightColor", OpieHighlight);
196} 193}
197 194
198QColor OGlobalSettings::inactiveTitleColor() 195QColor OGlobalSettings::inactiveTitleColor()
199{ 196{
200 if (!OpieGray) OpieGray = new QColor(220, 220, 220); 197 if (!OpieGray) OpieGray = new QColor(220, 220, 220);
201 OConfig *c = OGlobal::config(); 198 OConfig *c = OGlobal::config();
202 OConfigGroupSaver cgs( c, QString::fromLatin1("WM") ); 199 OConfigGroupSaver cgs( c, QString::fromLatin1("WM") );
203 return c->readColorEntry( "inactiveBackground", OpieGray ); 200 return c->readColorEntry( "inactiveBackground", OpieGray );
204} 201}
205 202
206QColor OGlobalSettings::inactiveTextColor() 203QColor OGlobalSettings::inactiveTextColor()
207{ 204{
208 OConfig *c = OGlobal::config(); 205 OConfig *c = OGlobal::config();
209 OConfigGroupSaver cgs( c, QString::fromLatin1("WM") ); 206 OConfigGroupSaver cgs( c, QString::fromLatin1("WM") );
210 return c->readColorEntry( "inactiveForeground", &Qt::darkGray ); 207 return c->readColorEntry( "inactiveForeground", &Qt::darkGray );
211} 208}
212 209
213QColor OGlobalSettings::activeTitleColor() 210QColor OGlobalSettings::activeTitleColor()
214{ 211{
215 initColors(); 212 initColors();
216 OConfig *c = OGlobal::config(); 213 OConfig *c = OGlobal::config();
217 OConfigGroupSaver cgs( c, QString::fromLatin1("WM") ); 214 OConfigGroupSaver cgs( c, QString::fromLatin1("WM") );
218 return c->readColorEntry( "activeBackground", OpieHighlight); 215 return c->readColorEntry( "activeBackground", OpieHighlight);
219} 216}
220 217
221QColor OGlobalSettings::activeTextColor() 218QColor OGlobalSettings::activeTextColor()
222{ 219{
223 OConfig *c = OGlobal::config(); 220 OConfig *c = OGlobal::config();
224 OConfigGroupSaver cgs( c, QString::fromLatin1("WM") ); 221 OConfigGroupSaver cgs( c, QString::fromLatin1("WM") );
225 return c->readColorEntry( "activeForeground", &Qt::white ); 222 return c->readColorEntry( "activeForeground", &Qt::white );
226} 223}
227 224
228int OGlobalSettings::contrast() 225int OGlobalSettings::contrast()
229{ 226{
230 OConfig *c = OGlobal::config(); 227 OConfig *c = OGlobal::config();
231 OConfigGroupSaver cgs( c, QString::fromLatin1("OPIE") ); 228 OConfigGroupSaver cgs( c, QString::fromLatin1("OPIE") );
232 return c->readNumEntry( "contrast", 7 ); 229 return c->readNumEntry( "contrast", 7 );
233} 230}
234 231
235// following functions should work in OPIE - how to sync with appearance changes? 232// following functions should work in OPIE - how to sync with appearance changes?
236 233
237QColor OGlobalSettings::baseColor() 234QColor OGlobalSettings::baseColor()
238{ 235{
239 OConfig *c = OGlobal::config(); 236 OConfig *c = OGlobal::config();
240 OConfigGroupSaver cgs( c, QString::fromLatin1("Appearance") ); 237 OConfigGroupSaver cgs( c, QString::fromLatin1("Appearance") );
241 return c->readColorEntry( "Base", &Qt::white ); 238 return c->readColorEntry( "Base", &Qt::white );
242} 239}
243 240
244QColor OGlobalSettings::textColor() 241QColor OGlobalSettings::textColor()
245{ 242{
246 OConfig *c = OGlobal::config(); 243 OConfig *c = OGlobal::config();
247 OConfigGroupSaver cgs( c, QString::fromLatin1("Appearance") ); 244 OConfigGroupSaver cgs( c, QString::fromLatin1("Appearance") );
248 return c->readColorEntry( "Text", &Qt::black ); 245 return c->readColorEntry( "Text", &Qt::black );
249} 246}
250 247
251QColor OGlobalSettings::highlightedTextColor() 248QColor OGlobalSettings::highlightedTextColor()
252{ 249{
253 OConfig *c = OGlobal::config(); 250 OConfig *c = OGlobal::config();
254 OConfigGroupSaver cgs( c, QString::fromLatin1("Appearance") ); 251 OConfigGroupSaver cgs( c, QString::fromLatin1("Appearance") );
255 return c->readColorEntry( "HighlightedText", &Qt::white ); 252 return c->readColorEntry( "HighlightedText", &Qt::white );
256} 253}
257 254
258QColor OGlobalSettings::highlightColor() 255QColor OGlobalSettings::highlightColor()
259{ 256{
260 initColors(); 257 initColors();
261 OConfig *c = OGlobal::config(); 258 OConfig *c = OGlobal::config();
262 OConfigGroupSaver cgs( c, QString::fromLatin1("Appearance") ); 259 OConfigGroupSaver cgs( c, QString::fromLatin1("Appearance") );
263 return c->readColorEntry( "Highlight", OpieHighlight ); 260 return c->readColorEntry( "Highlight", OpieHighlight );
264} 261}
265 262
266QColor OGlobalSettings::alternateBackgroundColor() 263QColor OGlobalSettings::alternateBackgroundColor()
267{ 264{
268 initColors(); 265 initColors();
269 OConfig *c = OGlobal::config(); 266 OConfig *c = OGlobal::config();
270 OConfigGroupSaver cgs( c, QString::fromLatin1("Appearance") ); 267 OConfigGroupSaver cgs( c, QString::fromLatin1("Appearance") );
271 *OpieAlternate = calculateAlternateBackgroundColor( baseColor() ); 268 *OpieAlternate = calculateAlternateBackgroundColor( baseColor() );
272 return c->readColorEntry( "alternateBackground", OpieAlternate ); 269 return c->readColorEntry( "alternateBackground", OpieAlternate );
273} 270}
274 271
275QColor OGlobalSettings::calculateAlternateBackgroundColor(const QColor& base) 272QColor OGlobalSettings::calculateAlternateBackgroundColor(const QColor& base)
276{ 273{
277 if (base == Qt::white) 274 if (base == Qt::white)
278 return QColor(238,246,255); 275 return QColor(238,246,255);
279 else 276 else
280 { 277 {
281 int h, s, v; 278 int h, s, v;
282 base.hsv( &h, &s, &v ); 279 base.hsv( &h, &s, &v );
283 if (v > 128) 280 if (v > 128)
284 return base.dark(106); 281 return base.dark(106);
285 else if (base != Qt::black) 282 else if (base != Qt::black)
286 return base.light(110); 283 return base.light(110);
287 284
288 return QColor(32,32,32); 285 return QColor(32,32,32);
289 } 286 }
290} 287}
291 288
292QColor OGlobalSettings::linkColor() 289QColor OGlobalSettings::linkColor()
293{ 290{
294 initColors(); 291 initColors();
295 OConfig *c = OGlobal::config(); 292 OConfig *c = OGlobal::config();
296 OConfigGroupSaver cgs( c, QString::fromLatin1("Appearance") ); 293 OConfigGroupSaver cgs( c, QString::fromLatin1("Appearance") );
297 return c->readColorEntry( "linkColor", OpieGray ); 294 return c->readColorEntry( "linkColor", OpieGray );
298} 295}
299 296
300QColor OGlobalSettings::visitedLinkColor() 297QColor OGlobalSettings::visitedLinkColor()
301{ 298{
302 OConfig *c = OGlobal::config(); 299 OConfig *c = OGlobal::config();
303 OConfigGroupSaver cgs( c, QString::fromLatin1("Appearance") ); 300 OConfigGroupSaver cgs( c, QString::fromLatin1("Appearance") );
304 return c->readColorEntry( "visitedLinkColor", &Qt::magenta ); 301 return c->readColorEntry( "visitedLinkColor", &Qt::magenta );
305} 302}
306 303
307// FIXME: font stuff currently uses a different format in OPIE, so the 304// FIXME: font stuff currently uses a different format in OPIE, so the
308// functions below are not yet applicable. The whole font stuff for OPIE 305// functions below are not yet applicable. The whole font stuff for OPIE
309// has to be revised anyway 306// has to be revised anyway
310 307
311QFont OGlobalSettings::generalFont() 308QFont OGlobalSettings::generalFont()
312{ 309{
313 if (_generalFont) 310 if (_generalFont)
314 return *_generalFont; 311 return *_generalFont;
315 312
316 _generalFont = new QFont("helvetica", 10); 313 _generalFont = new QFont("helvetica", 10);
317 _generalFont->setPixelSize(10); 314 _generalFont->setPixelSize(10);
318 _generalFont->setStyleHint(QFont::SansSerif); 315 _generalFont->setStyleHint(QFont::SansSerif);
319 316
320 OConfig *c = OGlobal::config(); 317 OConfig *c = OGlobal::config();
321 OConfigGroupSaver cgs( c, QString::fromLatin1("Appearance") ); 318 OConfigGroupSaver cgs( c, QString::fromLatin1("Appearance") );
322 *_generalFont = c->readFontEntry("font", _generalFont); 319 *_generalFont = c->readFontEntry("font", _generalFont);
323 320
324 return *_generalFont; 321 return *_generalFont;
325} 322}
326 323
327QFont OGlobalSettings::fixedFont() 324QFont OGlobalSettings::fixedFont()
328{ 325{
329 if (_fixedFont) 326 if (_fixedFont)
330 return *_fixedFont; 327 return *_fixedFont;
331 328
332 _fixedFont = new QFont("courier", 12); 329 _fixedFont = new QFont("courier", 12);
333 _fixedFont->setPixelSize(12); 330 _fixedFont->setPixelSize(12);
334 _fixedFont->setStyleHint(QFont::TypeWriter); 331 _fixedFont->setStyleHint(QFont::TypeWriter);
335 332
336 OConfig *c = OGlobal::config(); 333 OConfig *c = OGlobal::config();
337 OConfigGroupSaver cgs( c, QString::fromLatin1("General") ); 334 OConfigGroupSaver cgs( c, QString::fromLatin1("General") );
338 *_fixedFont = c->readFontEntry("fixed", _fixedFont); 335 *_fixedFont = c->readFontEntry("fixed", _fixedFont);
339 336
340 return *_fixedFont; 337 return *_fixedFont;
341} 338}
342 339
343QFont OGlobalSettings::toolBarFont() 340QFont OGlobalSettings::toolBarFont()
344{ 341{
345 if(_toolBarFont) 342 if(_toolBarFont)
346 return *_toolBarFont; 343 return *_toolBarFont;
347 344
348 _toolBarFont = new QFont("helvetica", 10); 345 _toolBarFont = new QFont("helvetica", 10);
349 _toolBarFont->setPixelSize(10); 346 _toolBarFont->setPixelSize(10);
350 _toolBarFont->setStyleHint(QFont::SansSerif); 347 _toolBarFont->setStyleHint(QFont::SansSerif);
351 348
352 OConfig *c = OGlobal::config(); 349 OConfig *c = OGlobal::config();
353 OConfigGroupSaver cgs( c, QString::fromLatin1("General") ); 350 OConfigGroupSaver cgs( c, QString::fromLatin1("General") );
354 *_toolBarFont = c->readFontEntry("toolBarFont", _toolBarFont); 351 *_toolBarFont = c->readFontEntry("toolBarFont", _toolBarFont);
355 352
356 return *_toolBarFont; 353 return *_toolBarFont;
357} 354}
358 355
359QFont OGlobalSettings::menuFont() 356QFont OGlobalSettings::menuFont()
360{ 357{
361 if(_menuFont) 358 if(_menuFont)
362 return *_menuFont; 359 return *_menuFont;
363 360
364 _menuFont = new QFont("helvetica", 12); 361 _menuFont = new QFont("helvetica", 12);
365 _menuFont->setPixelSize(12); 362 _menuFont->setPixelSize(12);
366 _menuFont->setStyleHint(QFont::SansSerif); 363 _menuFont->setStyleHint(QFont::SansSerif);
367 364
368 OConfig *c = OGlobal::config(); 365 OConfig *c = OGlobal::config();
369 OConfigGroupSaver cgs( c, QString::fromLatin1("General") ); 366 OConfigGroupSaver cgs( c, QString::fromLatin1("General") );
370 *_menuFont = c->readFontEntry("menuFont", _menuFont); 367 *_menuFont = c->readFontEntry("menuFont", _menuFont);
371 368
372 return *_menuFont; 369 return *_menuFont;
373} 370}
374 371
375QFont OGlobalSettings::windowTitleFont() 372QFont OGlobalSettings::windowTitleFont()
376{ 373{
377 if(_windowTitleFont) 374 if(_windowTitleFont)
378 return *_windowTitleFont; 375 return *_windowTitleFont;
379 376
380 _windowTitleFont = new QFont("helvetica", 12, QFont::Bold); 377 _windowTitleFont = new QFont("helvetica", 12, QFont::Bold);
381 _windowTitleFont->setPixelSize(12); 378 _windowTitleFont->setPixelSize(12);
382 _windowTitleFont->setStyleHint(QFont::SansSerif); 379 _windowTitleFont->setStyleHint(QFont::SansSerif);
383 380
384 OConfig *c = OGlobal::config(); 381 OConfig *c = OGlobal::config();
385 OConfigGroupSaver cgs( c, QString::fromLatin1("WM") ); 382 OConfigGroupSaver cgs( c, QString::fromLatin1("WM") );
386 *_windowTitleFont = c->readFontEntry("activeFont", _windowTitleFont); // inconsistency 383 *_windowTitleFont = c->readFontEntry("activeFont", _windowTitleFont); // inconsistency
387 384
388 return *_windowTitleFont; 385 return *_windowTitleFont;
389} 386}
390 387
391QFont OGlobalSettings::taskbarFont() 388QFont OGlobalSettings::taskbarFont()
392{ 389{
393 if(_taskbarFont) 390 if(_taskbarFont)
394 return *_taskbarFont; 391 return *_taskbarFont;
395 392
396 _taskbarFont = new QFont("helvetica", 8); 393 _taskbarFont = new QFont("helvetica", 8);
397 _taskbarFont->setPixelSize(8); 394 _taskbarFont->setPixelSize(8);
398 _taskbarFont->setStyleHint(QFont::SansSerif); 395 _taskbarFont->setStyleHint(QFont::SansSerif);
399 396
400 OConfig *c = OGlobal::config(); 397 OConfig *c = OGlobal::config();
401 OConfigGroupSaver cgs( c, QString::fromLatin1("General") ); 398 OConfigGroupSaver cgs( c, QString::fromLatin1("General") );
402 *_taskbarFont = c->readFontEntry("taskbarFont", _taskbarFont); 399 *_taskbarFont = c->readFontEntry("taskbarFont", _taskbarFont);
403 400
404 return *_taskbarFont; 401 return *_taskbarFont;
405} 402}
406 403
407// FIXME: the whole path stuff has to be revised for OPIE 404// FIXME: the whole path stuff has to be revised for OPIE
408 405
409void OGlobalSettings::initStatic() // should be called initPaths(). Don't put anything else here. 406void OGlobalSettings::initStatic() // should be called initPaths(). Don't put anything else here.
410{ 407{
411 if ( s_desktopPath != 0 ) 408 if ( s_desktopPath != 0 )
412 return; 409 return;
413 410
414 s_desktopPath = new QString(); 411 s_desktopPath = new QString();
415 s_autostartPath = new QString(); 412 s_autostartPath = new QString();
416 s_trashPath = new QString(); 413 s_trashPath = new QString();
417 s_documentPath = new QString(); 414 s_documentPath = new QString();
418 415
419 OConfig *config = OGlobal::config(); 416 OConfig *config = OGlobal::config();
420 //bool dollarExpansion = config->isDollarExpansion(); 417 //bool dollarExpansion = config->isDollarExpansion();
421 //config->setDollarExpansion(true); 418 //config->setDollarExpansion(true);
422 OConfigGroupSaver cgs( config, "Paths" ); 419 OConfigGroupSaver cgs( config, "Paths" );
423 420
424 // Desktop Path 421 // Desktop Path
425 *s_desktopPath = QDir::homeDirPath() + "/" + "Desktop" + "/"; 422 *s_desktopPath = QDir::homeDirPath() + "/" + "Desktop" + "/";
426 *s_desktopPath = config->readEntry( "Desktop", *s_desktopPath); 423 *s_desktopPath = config->readEntry( "Desktop", *s_desktopPath);
427 if ( (*s_desktopPath)[0] != '/' ) 424 if ( (*s_desktopPath)[0] != '/' )
428 s_desktopPath->prepend( QDir::homeDirPath() + "/" ); 425 s_desktopPath->prepend( QDir::homeDirPath() + "/" );
429 *s_desktopPath = QDir::cleanDirPath( *s_desktopPath ); 426 *s_desktopPath = QDir::cleanDirPath( *s_desktopPath );
430 if ( s_desktopPath->right(1) != "/") 427 if ( s_desktopPath->right(1) != "/")
431 *s_desktopPath += "/"; 428 *s_desktopPath += "/";
432 429
433 // Trash Path 430 // Trash Path
434 *s_trashPath = *s_desktopPath + QObject::tr("Trash") + "/"; 431 *s_trashPath = *s_desktopPath + QObject::tr("Trash") + "/";
435 *s_trashPath = config->readEntry( "Trash" , *s_trashPath); 432 *s_trashPath = config->readEntry( "Trash" , *s_trashPath);
436 if ( (*s_trashPath)[0] != '/' ) 433 if ( (*s_trashPath)[0] != '/' )
437 s_trashPath->prepend( QDir::homeDirPath() + "/" ); 434 s_trashPath->prepend( QDir::homeDirPath() + "/" );
438 *s_trashPath = QDir::cleanDirPath( *s_trashPath ); 435 *s_trashPath = QDir::cleanDirPath( *s_trashPath );
439 if ( s_trashPath->right(1) != "/") 436 if ( s_trashPath->right(1) != "/")
440 *s_trashPath += "/"; 437 *s_trashPath += "/";
441 // We need to save it in any case, in case the language changes later on, 438 // We need to save it in any case, in case the language changes later on,
442 if ( !config->hasKey( "Trash" ) ) 439 if ( !config->hasKey( "Trash" ) )
443 { 440 {
444 //config->writePathEntry( "Trash", *s_trashPath, true, true ); 441 //config->writePathEntry( "Trash", *s_trashPath, true, true );
445 config->writeEntry( "Trash", *s_trashPath ); 442 config->writeEntry( "Trash", *s_trashPath );
446 //config->sync(); 443 //config->sync();
447 } 444 }
448 445
449/* // Autostart Path 446/* // Autostart Path
450 *s_autostartPath = OGlobal::dirs()->localkdedir() + "Autostart" + "/"; 447 *s_autostartPath = OGlobal::dirs()->localkdedir() + "Autostart" + "/";
451 *s_autostartPath = config->readEntry( "Autostart" , *s_autostartPath); 448 *s_autostartPath = config->readEntry( "Autostart" , *s_autostartPath);
452 if ( (*s_autostartPath)[0] != '/' ) 449 if ( (*s_autostartPath)[0] != '/' )
453 s_autostartPath->prepend( QDir::homeDirPath() + "/" ); 450 s_autostartPath->prepend( QDir::homeDirPath() + "/" );
454 *s_autostartPath = QDir::cleanDirPath( *s_autostartPath ); 451 *s_autostartPath = QDir::cleanDirPath( *s_autostartPath );
455 if ( s_autostartPath->right(1) != "/") 452 if ( s_autostartPath->right(1) != "/")
456 *s_autostartPath += "/"; 453 *s_autostartPath += "/";
457*/ 454*/
458 // Document Path 455 // Document Path
459 *s_documentPath = QString::null; 456 *s_documentPath = QString::null;
460 *s_documentPath = config->readEntry( "Documents" , *s_documentPath); 457 *s_documentPath = config->readEntry( "Documents" , *s_documentPath);
461 if ( (*s_documentPath)[0] != '/' ) 458 if ( (*s_documentPath)[0] != '/' )
462 s_documentPath->prepend( QDir::homeDirPath() + "/" ); 459 s_documentPath->prepend( QDir::homeDirPath() + "/" );
463 *s_documentPath = QDir::cleanDirPath( *s_documentPath ); 460 *s_documentPath = QDir::cleanDirPath( *s_documentPath );
464 if ( s_documentPath->right(1) != "/") 461 if ( s_documentPath->right(1) != "/")
465 *s_documentPath += "/"; 462 *s_documentPath += "/";
466 463
467 //config->setDollarExpansion(dollarExpansion); 464 //config->setDollarExpansion(dollarExpansion);
468 465
469 // Make sure this app gets the notifications about those paths 466 // Make sure this app gets the notifications about those paths
470 //if (kapp) 467 //if (kapp)
471 //kapp->addKipcEventMask(KIPC::SettingsChanged); 468 //kapp->addKipcEventMask(KIPC::SettingsChanged);
472} 469}
473 470
474void OGlobalSettings::initColors() 471void OGlobalSettings::initColors()
475{ 472{
476 if ( !OpieHighlight ) OpieHighlight = new QColor( 156, 118, 32 ); 473 if ( !OpieHighlight ) OpieHighlight = new QColor( 156, 118, 32 );
477 if ( !OpieAlternate ) OpieAlternate = new QColor( 238, 246, 255 ); 474 if ( !OpieAlternate ) OpieAlternate = new QColor( 238, 246, 255 );
478 if ( !OpieGray ) OpieGray = new QColor( 220, 210, 215 ); 475 if ( !OpieGray ) OpieGray = new QColor( 220, 210, 215 );
479} 476}
480 477
481void OGlobalSettings::rereadFontSettings() 478void OGlobalSettings::rereadFontSettings()
482{ 479{
483 delete _generalFont; 480 delete _generalFont;
484 _generalFont = 0L; 481 _generalFont = 0L;
485 delete _fixedFont; 482 delete _fixedFont;
486 _fixedFont = 0L; 483 _fixedFont = 0L;
487 delete _menuFont; 484 delete _menuFont;
488 _menuFont = 0L; 485 _menuFont = 0L;
489 delete _toolBarFont; 486 delete _toolBarFont;
490 _toolBarFont = 0L; 487 _toolBarFont = 0L;
491 delete _windowTitleFont; 488 delete _windowTitleFont;
492 _windowTitleFont = 0L; 489 _windowTitleFont = 0L;
493 delete _taskbarFont; 490 delete _taskbarFont;
494 _taskbarFont = 0L; 491 _taskbarFont = 0L;
495} 492}
496 493
497void OGlobalSettings::rereadPathSettings() 494void OGlobalSettings::rereadPathSettings()
498{ 495{
499 qDebug( "OGlobalSettings::rereadPathSettings" ); 496 qDebug( "OGlobalSettings::rereadPathSettings" );
500 delete s_autostartPath; 497 delete s_autostartPath;
501 s_autostartPath = 0L; 498 s_autostartPath = 0L;
502 delete s_trashPath; 499 delete s_trashPath;
503 s_trashPath = 0L; 500 s_trashPath = 0L;
504 delete s_desktopPath; 501 delete s_desktopPath;
505 s_desktopPath = 0L; 502 s_desktopPath = 0L;
506 delete s_documentPath; 503 delete s_documentPath;
507 s_documentPath = 0L; 504 s_documentPath = 0L;
508} 505}
509 506
510OGlobalSettings::OMouseSettings & OGlobalSettings::mouseSettings() 507OGlobalSettings::OMouseSettings & OGlobalSettings::mouseSettings()
511{ 508{
512 if ( ! s_mouseSettings ) 509 if ( ! s_mouseSettings )
513 { 510 {
514 s_mouseSettings = new OMouseSettings; 511 s_mouseSettings = new OMouseSettings;
515 OMouseSettings & s = *s_mouseSettings; // for convenience 512 OMouseSettings & s = *s_mouseSettings; // for convenience
516 513
517 OConfigGroupSaver cgs( OGlobal::config(), "Mouse" ); 514 OConfigGroupSaver cgs( OGlobal::config(), "Mouse" );
518 QString setting = OGlobal::config()->readEntry("MouseButtonMapping"); 515 QString setting = OGlobal::config()->readEntry("MouseButtonMapping");
519 if (setting == "RightHanded") 516 if (setting == "RightHanded")
520 s.handed = OMouseSettings::RightHanded; 517 s.handed = OMouseSettings::RightHanded;
521 else if (setting == "LeftHanded") 518 else if (setting == "LeftHanded")
522 s.handed = OMouseSettings::LeftHanded; 519 s.handed = OMouseSettings::LeftHanded;
523 else 520 else
524 { 521 {
525 522
526 // FIXME: Implement for Opie / Qt Embedded 523 // FIXME: Implement for Opie / Qt Embedded
527 524
528 } 525 }
529 } 526 }
530 return *s_mouseSettings; 527 return *s_mouseSettings;
531} 528}
532 529
533void OGlobalSettings::rereadMouseSettings() 530void OGlobalSettings::rereadMouseSettings()
534{ 531{
535 delete s_mouseSettings; 532 delete s_mouseSettings;
536 s_mouseSettings = 0L; 533 s_mouseSettings = 0L;
537} 534}
538 535
539// FIXME: This won't be necessary, or will it? :-D 536// FIXME: This won't be necessary, or will it? :-D
540 537
541bool OGlobalSettings::isMultiHead() 538bool OGlobalSettings::isMultiHead()
542{ 539{
543 QCString multiHead = getenv("OPIE_MULTIHEAD"); 540 QCString multiHead = getenv("OPIE_MULTIHEAD");
544 if (!multiHead.isEmpty()) { 541 if (!multiHead.isEmpty()) {
545 return (multiHead.lower() == "true"); 542 return (multiHead.lower() == "true");
546 } 543 }
547 return false; 544 return false;
548} 545}
diff --git a/libopie2/opiecore/oprocctrl.cpp b/libopie2/opiecore/oprocctrl.cpp
index b3d57c8..0403526 100644
--- a/libopie2/opiecore/oprocctrl.cpp
+++ b/libopie2/opiecore/oprocctrl.cpp
@@ -1,284 +1,283 @@
1/* This file is part of the KDE libraries 1/* This file is part of the KDE libraries
2 Copyright (C) 1997 Christian Czezakte (e9025461@student.tuwien.ac.at) 2 Copyright (C) 1997 Christian Czezakte (e9025461@student.tuwien.ac.at)
3 3
4 This library is free software; you can redistribute it and/or 4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public 5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either 6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version. 7 version 2 of the License, or (at your option) any later version.
8 8
9 This library is distributed in the hope that it will be useful, 9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of 10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details. 12 Library General Public License for more details.
13 13
14 You should have received a copy of the GNU Library General Public License 14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to 15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 16 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. 17 Boston, MA 02111-1307, USA.
18*/ 18*/
19// 19//
20// KPROCESSCONTROLLER -- A helper class for KProcess 20// KPROCESSCONTROLLER -- A helper class for KProcess
21// 21//
22// version 0.3.1, Jan, 8th 1997 22// version 0.3.1, Jan, 8th 1997
23// 23//
24// (C) Christian Czezatke 24// (C) Christian Czezatke
25// e9025461@student.tuwien.ac.at 25// e9025461@student.tuwien.ac.at
26// Ported by Holger Freyther 26// Ported by Holger Freyther
27// 27//
28 28
29//#include <config.h> 29//#include <config.h>
30 30
31#include <sys/types.h> 31#include <sys/types.h>
32#include <sys/socket.h> 32#include <sys/socket.h>
33 33
34#include <errno.h> 34#include <errno.h>
35#include <fcntl.h> 35#include <fcntl.h>
36#include <stdio.h> 36#include <stdio.h>
37#include <string.h> 37#include <string.h>
38#include <unistd.h> 38#include <unistd.h>
39#include <assert.h> 39#include <assert.h>
40 40
41#include <qsocketnotifier.h> 41#include <qsocketnotifier.h>
42#include "oprocess.h"
43#include "oprocctrl.h" 42#include "oprocctrl.h"
44 43
45OProcessController *OProcessController::theOProcessController = 0; 44OProcessController *OProcessController::theOProcessController = 0;
46 45
47struct sigaction OProcessController::oldChildHandlerData; 46struct sigaction OProcessController::oldChildHandlerData;
48bool OProcessController::handlerSet = false; 47bool OProcessController::handlerSet = false;
49 48
50OProcessController::OProcessController() 49OProcessController::OProcessController()
51{ 50{
52 assert( theOProcessController == 0 ); 51 assert( theOProcessController == 0 );
53 52
54 if (0 > pipe(fd)) 53 if (0 > pipe(fd))
55 printf(strerror(errno)); 54 printf(strerror(errno));
56 55
57 notifier = new QSocketNotifier(fd[0], QSocketNotifier::Read); 56 notifier = new QSocketNotifier(fd[0], QSocketNotifier::Read);
58 notifier->setEnabled(true); 57 notifier->setEnabled(true);
59 QObject::connect(notifier, SIGNAL(activated(int)), 58 QObject::connect(notifier, SIGNAL(activated(int)),
60 this, SLOT(slotDoHousekeeping(int))); 59 this, SLOT(slotDoHousekeeping(int)));
61 connect( &delayedChildrenCleanupTimer, SIGNAL( timeout()), 60 connect( &delayedChildrenCleanupTimer, SIGNAL( timeout()),
62 SLOT( delayedChildrenCleanup())); 61 SLOT( delayedChildrenCleanup()));
63 62
64 theOProcessController = this; 63 theOProcessController = this;
65 64
66 setupHandlers(); 65 setupHandlers();
67} 66}
68 67
69 68
70void OProcessController::setupHandlers() 69void OProcessController::setupHandlers()
71{ 70{
72 if( handlerSet ) 71 if( handlerSet )
73 return; 72 return;
74 struct sigaction act; 73 struct sigaction act;
75 act.sa_handler=theSigCHLDHandler; 74 act.sa_handler=theSigCHLDHandler;
76 sigemptyset(&(act.sa_mask)); 75 sigemptyset(&(act.sa_mask));
77 sigaddset(&(act.sa_mask), SIGCHLD); 76 sigaddset(&(act.sa_mask), SIGCHLD);
78 // Make sure we don't block this signal. gdb tends to do that :-( 77 // Make sure we don't block this signal. gdb tends to do that :-(
79 sigprocmask(SIG_UNBLOCK, &(act.sa_mask), 0); 78 sigprocmask(SIG_UNBLOCK, &(act.sa_mask), 0);
80 79
81 act.sa_flags = SA_NOCLDSTOP; 80 act.sa_flags = SA_NOCLDSTOP;
82 81
83 // CC: take care of SunOS which automatically restarts interrupted system 82 // CC: take care of SunOS which automatically restarts interrupted system
84 // calls (and thus does not have SA_RESTART) 83 // calls (and thus does not have SA_RESTART)
85 84
86#ifdef SA_RESTART 85#ifdef SA_RESTART
87 act.sa_flags |= SA_RESTART; 86 act.sa_flags |= SA_RESTART;
88#endif 87#endif
89 88
90 sigaction( SIGCHLD, &act, &oldChildHandlerData ); 89 sigaction( SIGCHLD, &act, &oldChildHandlerData );
91 90
92 act.sa_handler=SIG_IGN; 91 act.sa_handler=SIG_IGN;
93 sigemptyset(&(act.sa_mask)); 92 sigemptyset(&(act.sa_mask));
94 sigaddset(&(act.sa_mask), SIGPIPE); 93 sigaddset(&(act.sa_mask), SIGPIPE);
95 act.sa_flags = 0; 94 act.sa_flags = 0;
96 sigaction( SIGPIPE, &act, 0L); 95 sigaction( SIGPIPE, &act, 0L);
97 handlerSet = true; 96 handlerSet = true;
98} 97}
99 98
100void OProcessController::resetHandlers() 99void OProcessController::resetHandlers()
101{ 100{
102 if( !handlerSet ) 101 if( !handlerSet )
103 return; 102 return;
104 sigaction( SIGCHLD, &oldChildHandlerData, 0 ); 103 sigaction( SIGCHLD, &oldChildHandlerData, 0 );
105 // there should be no problem with SIGPIPE staying SIG_IGN 104 // there should be no problem with SIGPIPE staying SIG_IGN
106 handlerSet = false; 105 handlerSet = false;
107} 106}
108 107
109// block SIGCHLD handler, because it accesses processList 108// block SIGCHLD handler, because it accesses processList
110void OProcessController::addOProcess( OProcess* p ) 109void OProcessController::addOProcess( OProcess* p )
111{ 110{
112 sigset_t newset, oldset; 111 sigset_t newset, oldset;
113 sigemptyset( &newset ); 112 sigemptyset( &newset );
114 sigaddset( &newset, SIGCHLD ); 113 sigaddset( &newset, SIGCHLD );
115 sigprocmask( SIG_BLOCK, &newset, &oldset ); 114 sigprocmask( SIG_BLOCK, &newset, &oldset );
116 processList.append( p ); 115 processList.append( p );
117 sigprocmask( SIG_SETMASK, &oldset, 0 ); 116 sigprocmask( SIG_SETMASK, &oldset, 0 );
118} 117}
119 118
120void OProcessController::removeOProcess( OProcess* p ) 119void OProcessController::removeOProcess( OProcess* p )
121{ 120{
122 sigset_t newset, oldset; 121 sigset_t newset, oldset;
123 sigemptyset( &newset ); 122 sigemptyset( &newset );
124 sigaddset( &newset, SIGCHLD ); 123 sigaddset( &newset, SIGCHLD );
125 sigprocmask( SIG_BLOCK, &newset, &oldset ); 124 sigprocmask( SIG_BLOCK, &newset, &oldset );
126 processList.remove( p ); 125 processList.remove( p );
127 sigprocmask( SIG_SETMASK, &oldset, 0 ); 126 sigprocmask( SIG_SETMASK, &oldset, 0 );
128} 127}
129 128
130//using a struct which contains both the pid and the status makes it easier to write 129//using a struct which contains both the pid and the status makes it easier to write
131//and read the data into the pipe 130//and read the data into the pipe
132//especially this solves a problem which appeared on my box where slotDoHouseKeeping() received 131//especially this solves a problem which appeared on my box where slotDoHouseKeeping() received
133//only 4 bytes (with some debug output around the write()'s it received all 8 bytes) 132//only 4 bytes (with some debug output around the write()'s it received all 8 bytes)
134//don't know why this happened, but when writing all 8 bytes at once it works here, aleXXX 133//don't know why this happened, but when writing all 8 bytes at once it works here, aleXXX
135struct waitdata 134struct waitdata
136{ 135{
137 pid_t pid; 136 pid_t pid;
138 int status; 137 int status;
139}; 138};
140 139
141void OProcessController::theSigCHLDHandler(int arg) 140void OProcessController::theSigCHLDHandler(int arg)
142{ 141{
143 struct waitdata wd; 142 struct waitdata wd;
144 // int status; 143 // int status;
145 // pid_t this_pid; 144 // pid_t this_pid;
146 int saved_errno; 145 int saved_errno;
147 146
148 saved_errno = errno; 147 saved_errno = errno;
149 // since waitpid and write change errno, we have to save it and restore it 148 // since waitpid and write change errno, we have to save it and restore it
150 // (Richard Stevens, Advanced programming in the Unix Environment) 149 // (Richard Stevens, Advanced programming in the Unix Environment)
151 150
152 bool found = false; 151 bool found = false;
153 if( theOProcessController != 0 ) 152 if( theOProcessController != 0 )
154 { 153 {
155 // iterating the list doesn't perform any system call 154 // iterating the list doesn't perform any system call
156 for( QValueList<OProcess*>::ConstIterator it = theOProcessController->processList.begin(); 155 for( QValueList<OProcess*>::ConstIterator it = theOProcessController->processList.begin();
157 it != theOProcessController->processList.end(); 156 it != theOProcessController->processList.end();
158 ++it ) 157 ++it )
159 { 158 {
160 if( !(*it)->isRunning()) 159 if( !(*it)->isRunning())
161 continue; 160 continue;
162 wd.pid = waitpid( (*it)->pid(), &wd.status, WNOHANG ); 161 wd.pid = waitpid( (*it)->pid(), &wd.status, WNOHANG );
163 if ( wd.pid > 0 ) 162 if ( wd.pid > 0 )
164 { 163 {
165 ::write(theOProcessController->fd[1], &wd, sizeof(wd)); 164 ::write(theOProcessController->fd[1], &wd, sizeof(wd));
166 found = true; 165 found = true;
167 } 166 }
168 } 167 }
169 } 168 }
170 if( !found && oldChildHandlerData.sa_handler != SIG_IGN 169 if( !found && oldChildHandlerData.sa_handler != SIG_IGN
171 && oldChildHandlerData.sa_handler != SIG_DFL ) 170 && oldChildHandlerData.sa_handler != SIG_DFL )
172 oldChildHandlerData.sa_handler( arg ); // call the old handler 171 oldChildHandlerData.sa_handler( arg ); // call the old handler
173 // handle the rest 172 // handle the rest
174 if( theOProcessController != 0 ) 173 if( theOProcessController != 0 )
175 { 174 {
176 static const struct waitdata dwd = { 0, 0 } 175 static const struct waitdata dwd = { 0, 0 }
177 ; // delayed waitpid() 176 ; // delayed waitpid()
178 ::write(theOProcessController->fd[1], &dwd, sizeof(dwd)); 177 ::write(theOProcessController->fd[1], &dwd, sizeof(dwd));
179 } 178 }
180 else 179 else
181 { 180 {
182 int dummy; 181 int dummy;
183 while( waitpid( -1, &dummy, WNOHANG ) > 0 ) 182 while( waitpid( -1, &dummy, WNOHANG ) > 0 )
184 ; 183 ;
185 } 184 }
186 185
187 errno = saved_errno; 186 errno = saved_errno;
188} 187}
189 188
190 189
191 190
192void OProcessController::slotDoHousekeeping(int ) 191void OProcessController::slotDoHousekeeping(int )
193{ 192{
194 unsigned int bytes_read = 0; 193 unsigned int bytes_read = 0;
195 unsigned int errcnt=0; 194 unsigned int errcnt=0;
196 // read pid and status from the pipe. 195 // read pid and status from the pipe.
197 struct waitdata wd; 196 struct waitdata wd;
198 while ((bytes_read < sizeof(wd)) && (errcnt < 50)) 197 while ((bytes_read < sizeof(wd)) && (errcnt < 50))
199 { 198 {
200 int r = ::read(fd[0], ((char *)&wd) + bytes_read, sizeof(wd) - bytes_read); 199 int r = ::read(fd[0], ((char *)&wd) + bytes_read, sizeof(wd) - bytes_read);
201 if (r > 0) bytes_read += r; 200 if (r > 0) bytes_read += r;
202 else if (r < 0) errcnt++; 201 else if (r < 0) errcnt++;
203 } 202 }
204 if (errcnt >= 50) 203 if (errcnt >= 50)
205 { 204 {
206 fprintf(stderr, 205 fprintf(stderr,
207 "Error: Max. error count for pipe read " 206 "Error: Max. error count for pipe read "
208 "exceeded in OProcessController::slotDoHousekeeping\n"); 207 "exceeded in OProcessController::slotDoHousekeeping\n");
209 return; // it makes no sense to continue here! 208 return; // it makes no sense to continue here!
210 } 209 }
211 if (bytes_read != sizeof(wd)) 210 if (bytes_read != sizeof(wd))
212 { 211 {
213 fprintf(stderr, 212 fprintf(stderr,
214 "Error: Could not read info from signal handler %d <> %d!\n", 213 "Error: Could not read info from signal handler %d <> %d!\n",
215 bytes_read, sizeof(wd)); 214 bytes_read, sizeof(wd));
216 return; // it makes no sense to continue here! 215 return; // it makes no sense to continue here!
217 } 216 }
218 if (wd.pid==0) 217 if (wd.pid==0)
219 { // special case, see delayedChildrenCleanup() 218 { // special case, see delayedChildrenCleanup()
220 delayedChildrenCleanupTimer.start( 1000, true ); 219 delayedChildrenCleanupTimer.start( 1000, true );
221 return; 220 return;
222 } 221 }
223 222
224 for( QValueList<OProcess*>::ConstIterator it = processList.begin(); 223 for( QValueList<OProcess*>::ConstIterator it = processList.begin();
225 it != processList.end(); 224 it != processList.end();
226 ++it ) 225 ++it )
227 { 226 {
228 OProcess* proc = *it; 227 OProcess* proc = *it;
229 if (proc->pid() == wd.pid) 228 if (proc->pid() == wd.pid)
230 { 229 {
231 // process has exited, so do emit the respective events 230 // process has exited, so do emit the respective events
232 if (proc->run_mode == OProcess::Block) 231 if (proc->run_mode == OProcess::Block)
233 { 232 {
234 // If the reads are done blocking then set the status in proc 233 // If the reads are done blocking then set the status in proc
235 // but do nothing else because OProcess will perform the other 234 // but do nothing else because OProcess will perform the other
236 // actions of processHasExited. 235 // actions of processHasExited.
237 proc->status = wd.status; 236 proc->status = wd.status;
238 proc->runs = false; 237 proc->runs = false;
239 } 238 }
240 else 239 else
241 { 240 {
242 proc->processHasExited(wd.status); 241 proc->processHasExited(wd.status);
243 } 242 }
244 return; 243 return;
245 } 244 }
246 } 245 }
247} 246}
248 247
249// this is needed e.g. for popen(), which calls waitpid() checking 248// this is needed e.g. for popen(), which calls waitpid() checking
250// for its forked child, if we did waitpid() directly in the SIGCHLD 249// for its forked child, if we did waitpid() directly in the SIGCHLD
251// handler, popen()'s waitpid() call would fail 250// handler, popen()'s waitpid() call would fail
252void OProcessController::delayedChildrenCleanup() 251void OProcessController::delayedChildrenCleanup()
253{ 252{
254 struct waitdata wd; 253 struct waitdata wd;
255 while(( wd.pid = waitpid( -1, &wd.status, WNOHANG ) ) > 0 ) 254 while(( wd.pid = waitpid( -1, &wd.status, WNOHANG ) ) > 0 )
256 { 255 {
257 for( QValueList<OProcess*>::ConstIterator it = processList.begin(); 256 for( QValueList<OProcess*>::ConstIterator it = processList.begin();
258 it != processList.end(); 257 it != processList.end();
259 ++it ) 258 ++it )
260 { 259 {
261 if( !(*it)->isRunning() || (*it)->pid() != wd.pid ) 260 if( !(*it)->isRunning() || (*it)->pid() != wd.pid )
262 continue; 261 continue;
263 // it's OProcess, handle it 262 // it's OProcess, handle it
264 ::write(fd[1], &wd, sizeof(wd)); 263 ::write(fd[1], &wd, sizeof(wd));
265 break; 264 break;
266 } 265 }
267 } 266 }
268} 267}
269 268
270OProcessController::~OProcessController() 269OProcessController::~OProcessController()
271{ 270{
272 assert( theOProcessController == this ); 271 assert( theOProcessController == this );
273 resetHandlers(); 272 resetHandlers();
274 273
275 notifier->setEnabled(false); 274 notifier->setEnabled(false);
276 275
277 close(fd[0]); 276 close(fd[0]);
278 close(fd[1]); 277 close(fd[1]);
279 278
280 delete notifier; 279 delete notifier;
281 theOProcessController = 0; 280 theOProcessController = 0;
282} 281}
283 282
284//#include "kprocctrl.moc" 283//#include "kprocctrl.moc"
diff --git a/libopie2/opiecore/oprocess.cpp b/libopie2/opiecore/oprocess.cpp
index 83677aa..0a361a1 100644
--- a/libopie2/opiecore/oprocess.cpp
+++ b/libopie2/opiecore/oprocess.cpp
@@ -1,945 +1,943 @@
1/* 1/*
2                This file is part of the Opie Project 2                This file is part of the Opie Project
3             Copyright (C) 2002-2004 Holger Freyther <zecke@handhelds.org> 3             Copyright (C) 2002-2004 Holger Freyther <zecke@handhelds.org>
4 and The Opie Team <opie-devel@handhelds.org> 4 and The Opie Team <opie-devel@handhelds.org>
5 =. Based on KProcess (C) 1997 Christian Czezatke (e9025461@student.tuwien.ac.at) 5 =. Based on KProcess (C) 1997 Christian Czezatke (e9025461@student.tuwien.ac.at)
6 .=l. 6 .=l.
7          .>+-= 7          .>+-=
8_;:,     .>    :=|. This program is free software; you can 8_;:,     .>    :=|. This program is free software; you can
9.> <`_,   >  .   <= redistribute it and/or modify it under 9.> <`_,   >  .   <= redistribute it and/or modify it under
10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
11.="- .-=="i,     .._ License as published by the Free Software 11.="- .-=="i,     .._ License as published by the Free Software
12- .   .-<_>     .<> Foundation; either version 2 of the License, 12- .   .-<_>     .<> Foundation; either version 2 of the License,
13    ._= =}       : or (at your option) any later version. 13    ._= =}       : or (at your option) any later version.
14   .%`+i>       _;_. 14   .%`+i>       _;_.
15   .i_,=:_.      -<s. This program is distributed in the hope that 15   .i_,=:_.      -<s. This program is distributed in the hope that
16    +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 16    +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
17   : ..    .:,     . . . without even the implied warranty of 17   : ..    .:,     . . . without even the implied warranty of
18   =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 18   =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
19 _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 19 _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
20..}^=.=       =       ; Library General Public License for more 20..}^=.=       =       ; Library General Public License for more
21++=   -.     .`     .: details. 21++=   -.     .`     .: details.
22:     =  ...= . :.=- 22:     =  ...= . :.=-
23-.   .:....=;==+<; You should have received a copy of the GNU 23-.   .:....=;==+<; You should have received a copy of the GNU
24 -_. . .   )=.  = Library General Public License along with 24 -_. . .   )=.  = Library General Public License along with
25   --        :-=` this library; see the file COPYING.LIB. 25   --        :-=` this library; see the file COPYING.LIB.
26 If not, write to the Free Software Foundation, 26 If not, write to the Free Software Foundation,
27 Inc., 59 Temple Place - Suite 330, 27 Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. 28 Boston, MA 02111-1307, USA.
29*/ 29*/
30 30
31#include "oprocctrl.h" 31#include "oprocctrl.h"
32 32
33/* OPIE */ 33/* OPIE */
34#include <opie2/oprocess.h> 34#include <opie2/oprocess.h>
35 35
36/* QT */ 36/* QT */
37 37
38#include <qapplication.h> 38#include <qapplication.h>
39#include <qdir.h> 39#include <qdir.h>
40#include <qfile.h>
41#include <qmap.h> 40#include <qmap.h>
42#include <qregexp.h>
43#include <qsocketnotifier.h> 41#include <qsocketnotifier.h>
44#include <qtextstream.h> 42#include <qtextstream.h>
45 43
46/* STD */ 44/* STD */
47#include <errno.h> 45#include <errno.h>
48#include <fcntl.h> 46#include <fcntl.h>
49#include <pwd.h> 47#include <pwd.h>
50#include <stdlib.h> 48#include <stdlib.h>
51#include <signal.h> 49#include <signal.h>
52#include <stdio.h> 50#include <stdio.h>
53#include <string.h> 51#include <string.h>
54#include <sys/time.h> 52#include <sys/time.h>
55#include <sys/types.h> 53#include <sys/types.h>
56#include <sys/stat.h> 54#include <sys/stat.h>
57#include <sys/socket.h> 55#include <sys/socket.h>
58#include <unistd.h> 56#include <unistd.h>
59#ifdef HAVE_SYS_SELECT_H 57#ifdef HAVE_SYS_SELECT_H
60#include <sys/select.h> 58#include <sys/select.h>
61#endif 59#endif
62#ifdef HAVE_INITGROUPS 60#ifdef HAVE_INITGROUPS
63#include <grp.h> 61#include <grp.h>
64#endif 62#endif
65 63
66class OProcessPrivate 64class OProcessPrivate
67{ 65{
68public: 66public:
69 OProcessPrivate() : useShell( false ) 67 OProcessPrivate() : useShell( false )
70 { } 68 { }
71 69
72 bool useShell; 70 bool useShell;
73 QMap<QString, QString> env; 71 QMap<QString, QString> env;
74 QString wd; 72 QString wd;
75 QCString shell; 73 QCString shell;
76}; 74};
77 75
78 76
79OProcess::OProcess( QObject *parent, const char *name ) 77OProcess::OProcess( QObject *parent, const char *name )
80 : QObject( parent, name ) 78 : QObject( parent, name )
81{ 79{
82 init ( ); 80 init ( );
83} 81}
84 82
85OProcess::OProcess( const QString &arg0, QObject *parent, const char *name ) 83OProcess::OProcess( const QString &arg0, QObject *parent, const char *name )
86 : QObject( parent, name ) 84 : QObject( parent, name )
87{ 85{
88 init ( ); 86 init ( );
89 *this << arg0; 87 *this << arg0;
90} 88}
91 89
92OProcess::OProcess( const QStringList &args, QObject *parent, const char *name ) 90OProcess::OProcess( const QStringList &args, QObject *parent, const char *name )
93 : QObject( parent, name ) 91 : QObject( parent, name )
94{ 92{
95 init ( ); 93 init ( );
96 *this << args; 94 *this << args;
97} 95}
98 96
99void OProcess::init ( ) 97void OProcess::init ( )
100{ 98{
101 run_mode = NotifyOnExit; 99 run_mode = NotifyOnExit;
102 runs = false; 100 runs = false;
103 pid_ = 0; 101 pid_ = 0;
104 status = 0; 102 status = 0;
105 keepPrivs = false; 103 keepPrivs = false;
106 innot = 0; 104 innot = 0;
107 outnot = 0; 105 outnot = 0;
108 errnot = 0; 106 errnot = 0;
109 communication = NoCommunication; 107 communication = NoCommunication;
110 input_data = 0; 108 input_data = 0;
111 input_sent = 0; 109 input_sent = 0;
112 input_total = 0; 110 input_total = 0;
113 d = 0; 111 d = 0;
114 112
115 if ( 0 == OProcessController::theOProcessController ) 113 if ( 0 == OProcessController::theOProcessController )
116 { 114 {
117 ( void ) new OProcessController(); 115 ( void ) new OProcessController();
118 CHECK_PTR( OProcessController::theOProcessController ); 116 CHECK_PTR( OProcessController::theOProcessController );
119 } 117 }
120 118
121 OProcessController::theOProcessController->addOProcess( this ); 119 OProcessController::theOProcessController->addOProcess( this );
122 out[ 0 ] = out[ 1 ] = -1; 120 out[ 0 ] = out[ 1 ] = -1;
123 in[ 0 ] = in[ 1 ] = -1; 121 in[ 0 ] = in[ 1 ] = -1;
124 err[ 0 ] = err[ 1 ] = -1; 122 err[ 0 ] = err[ 1 ] = -1;
125} 123}
126 124
127void OProcess::setEnvironment( const QString &name, const QString &value ) 125void OProcess::setEnvironment( const QString &name, const QString &value )
128{ 126{
129 if ( !d ) 127 if ( !d )
130 d = new OProcessPrivate; 128 d = new OProcessPrivate;
131 d->env.insert( name, value ); 129 d->env.insert( name, value );
132} 130}
133 131
134void OProcess::setWorkingDirectory( const QString &dir ) 132void OProcess::setWorkingDirectory( const QString &dir )
135{ 133{
136 if ( !d ) 134 if ( !d )
137 d = new OProcessPrivate; 135 d = new OProcessPrivate;
138 d->wd = dir; 136 d->wd = dir;
139} 137}
140 138
141void OProcess::setupEnvironment() 139void OProcess::setupEnvironment()
142{ 140{
143 if ( d ) 141 if ( d )
144 { 142 {
145 QMap<QString, QString>::Iterator it; 143 QMap<QString, QString>::Iterator it;
146 for ( it = d->env.begin(); it != d->env.end(); ++it ) 144 for ( it = d->env.begin(); it != d->env.end(); ++it )
147 setenv( QFile::encodeName( it.key() ).data(), 145 setenv( QFile::encodeName( it.key() ).data(),
148 QFile::encodeName( it.data() ).data(), 1 ); 146 QFile::encodeName( it.data() ).data(), 1 );
149 if ( !d->wd.isEmpty() ) 147 if ( !d->wd.isEmpty() )
150 chdir( QFile::encodeName( d->wd ).data() ); 148 chdir( QFile::encodeName( d->wd ).data() );
151 } 149 }
152} 150}
153 151
154void OProcess::setRunPrivileged( bool keepPrivileges ) 152void OProcess::setRunPrivileged( bool keepPrivileges )
155{ 153{
156 keepPrivs = keepPrivileges; 154 keepPrivs = keepPrivileges;
157} 155}
158 156
159bool OProcess::runPrivileged() const 157bool OProcess::runPrivileged() const
160{ 158{
161 return keepPrivs; 159 return keepPrivs;
162} 160}
163 161
164OProcess::~OProcess() 162OProcess::~OProcess()
165{ 163{
166 // destroying the OProcess instance sends a SIGKILL to the 164 // destroying the OProcess instance sends a SIGKILL to the
167 // child process (if it is running) after removing it from the 165 // child process (if it is running) after removing it from the
168 // list of valid processes (if the process is not started as 166 // list of valid processes (if the process is not started as
169 // "DontCare") 167 // "DontCare")
170 168
171 OProcessController::theOProcessController->removeOProcess( this ); 169 OProcessController::theOProcessController->removeOProcess( this );
172 // this must happen before we kill the child 170 // this must happen before we kill the child
173 // TODO: block the signal while removing the current process from the process list 171 // TODO: block the signal while removing the current process from the process list
174 172
175 if ( runs && ( run_mode != DontCare ) ) 173 if ( runs && ( run_mode != DontCare ) )
176 kill( SIGKILL ); 174 kill( SIGKILL );
177 175
178 // Clean up open fd's and socket notifiers. 176 // Clean up open fd's and socket notifiers.
179 closeStdin(); 177 closeStdin();
180 closeStdout(); 178 closeStdout();
181 closeStderr(); 179 closeStderr();
182 180
183 // TODO: restore SIGCHLD and SIGPIPE handler if this is the last OProcess 181 // TODO: restore SIGCHLD and SIGPIPE handler if this is the last OProcess
184 delete d; 182 delete d;
185} 183}
186 184
187void OProcess::detach() 185void OProcess::detach()
188{ 186{
189 OProcessController::theOProcessController->removeOProcess( this ); 187 OProcessController::theOProcessController->removeOProcess( this );
190 188
191 runs = false; 189 runs = false;
192 pid_ = 0; 190 pid_ = 0;
193 191
194 // Clean up open fd's and socket notifiers. 192 // Clean up open fd's and socket notifiers.
195 closeStdin(); 193 closeStdin();
196 closeStdout(); 194 closeStdout();
197 closeStderr(); 195 closeStderr();
198} 196}
199 197
200bool OProcess::setExecutable( const QString& proc ) 198bool OProcess::setExecutable( const QString& proc )
201{ 199{
202 if ( runs ) 200 if ( runs )
203 return false; 201 return false;
204 202
205 if ( proc.isEmpty() ) 203 if ( proc.isEmpty() )
206 return false; 204 return false;
207 205
208 if ( !arguments.isEmpty() ) 206 if ( !arguments.isEmpty() )
209 arguments.remove( arguments.begin() ); 207 arguments.remove( arguments.begin() );
210 arguments.prepend( QFile::encodeName( proc ) ); 208 arguments.prepend( QFile::encodeName( proc ) );
211 209
212 return true; 210 return true;
213} 211}
214 212
215OProcess &OProcess::operator<<( const QStringList& args ) 213OProcess &OProcess::operator<<( const QStringList& args )
216{ 214{
217 QStringList::ConstIterator it = args.begin(); 215 QStringList::ConstIterator it = args.begin();
218 for ( ; it != args.end() ; ++it ) 216 for ( ; it != args.end() ; ++it )
219 arguments.append( QFile::encodeName( *it ) ); 217 arguments.append( QFile::encodeName( *it ) );
220 return *this; 218 return *this;
221} 219}
222 220
223OProcess &OProcess::operator<<( const QCString& arg ) 221OProcess &OProcess::operator<<( const QCString& arg )
224{ 222{
225 return operator<< ( arg.data() ); 223 return operator<< ( arg.data() );
226} 224}
227 225
228OProcess &OProcess::operator<<( const char* arg ) 226OProcess &OProcess::operator<<( const char* arg )
229{ 227{
230 arguments.append( arg ); 228 arguments.append( arg );
231 return *this; 229 return *this;
232} 230}
233 231
234OProcess &OProcess::operator<<( const QString& arg ) 232OProcess &OProcess::operator<<( const QString& arg )
235{ 233{
236 arguments.append( QFile::encodeName( arg ) ); 234 arguments.append( QFile::encodeName( arg ) );
237 return *this; 235 return *this;
238} 236}
239 237
240void OProcess::clearArguments() 238void OProcess::clearArguments()
241{ 239{
242 arguments.clear(); 240 arguments.clear();
243} 241}
244 242
245bool OProcess::start( RunMode runmode, Communication comm ) 243bool OProcess::start( RunMode runmode, Communication comm )
246{ 244{
247 uint i; 245 uint i;
248 uint n = arguments.count(); 246 uint n = arguments.count();
249 char **arglist; 247 char **arglist;
250 248
251 if ( runs || ( 0 == n ) ) 249 if ( runs || ( 0 == n ) )
252 { 250 {
253 return false; // cannot start a process that is already running 251 return false; // cannot start a process that is already running
254 // or if no executable has been assigned 252 // or if no executable has been assigned
255 } 253 }
256 run_mode = runmode; 254 run_mode = runmode;
257 status = 0; 255 status = 0;
258 256
259 QCString shellCmd; 257 QCString shellCmd;
260 if ( d && d->useShell ) 258 if ( d && d->useShell )
261 { 259 {
262 if ( d->shell.isEmpty() ) 260 if ( d->shell.isEmpty() )
263 { 261 {
264 qWarning( "Could not find a valid shell" ); 262 qWarning( "Could not find a valid shell" );
265 return false; 263 return false;
266 } 264 }
267 265
268 arglist = static_cast<char **>( malloc( ( 4 ) * sizeof( char * ) ) ); 266 arglist = static_cast<char **>( malloc( ( 4 ) * sizeof( char * ) ) );
269 for ( i = 0; i < n; i++ ) 267 for ( i = 0; i < n; i++ )
270 { 268 {
271 shellCmd += arguments[ i ]; 269 shellCmd += arguments[ i ];
272 shellCmd += " "; // CC: to separate the arguments 270 shellCmd += " "; // CC: to separate the arguments
273 } 271 }
274 272
275 arglist[ 0 ] = d->shell.data(); 273 arglist[ 0 ] = d->shell.data();
276 arglist[ 1 ] = ( char * ) "-c"; 274 arglist[ 1 ] = ( char * ) "-c";
277 arglist[ 2 ] = shellCmd.data(); 275 arglist[ 2 ] = shellCmd.data();
278 arglist[ 3 ] = 0; 276 arglist[ 3 ] = 0;
279 } 277 }
280 else 278 else
281 { 279 {
282 arglist = static_cast<char **>( malloc( ( n + 1 ) * sizeof( char * ) ) ); 280 arglist = static_cast<char **>( malloc( ( n + 1 ) * sizeof( char * ) ) );
283 for ( i = 0; i < n; i++ ) 281 for ( i = 0; i < n; i++ )
284 arglist[ i ] = arguments[ i ].data(); 282 arglist[ i ] = arguments[ i ].data();
285 arglist[ n ] = 0; 283 arglist[ n ] = 0;
286 } 284 }
287 285
288 if ( !setupCommunication( comm ) ) 286 if ( !setupCommunication( comm ) )
289 qWarning( "Could not setup Communication!" ); 287 qWarning( "Could not setup Communication!" );
290 288
291 // We do this in the parent because if we do it in the child process 289 // We do this in the parent because if we do it in the child process
292 // gdb gets confused when the application runs from gdb. 290 // gdb gets confused when the application runs from gdb.
293 uid_t uid = getuid(); 291 uid_t uid = getuid();
294 gid_t gid = getgid(); 292 gid_t gid = getgid();
295#ifdef HAVE_INITGROUPS 293#ifdef HAVE_INITGROUPS
296 294
297 struct passwd *pw = getpwuid( uid ); 295 struct passwd *pw = getpwuid( uid );
298#endif 296#endif
299 297
300 int fd[ 2 ]; 298 int fd[ 2 ];
301 if ( 0 > pipe( fd ) ) 299 if ( 0 > pipe( fd ) )
302 { 300 {
303 fd[ 0 ] = fd[ 1 ] = 0; // Pipe failed.. continue 301 fd[ 0 ] = fd[ 1 ] = 0; // Pipe failed.. continue
304 } 302 }
305 303
306 runs = true; 304 runs = true;
307 305
308 QApplication::flushX(); 306 QApplication::flushX();
309 307
310 // WABA: Note that we use fork() and not vfork() because 308 // WABA: Note that we use fork() and not vfork() because
311 // vfork() has unclear semantics and is not standardized. 309 // vfork() has unclear semantics and is not standardized.
312 pid_ = fork(); 310 pid_ = fork();
313 311
314 if ( 0 == pid_ ) 312 if ( 0 == pid_ )
315 { 313 {
316 if ( fd[ 0 ] ) 314 if ( fd[ 0 ] )
317 close( fd[ 0 ] ); 315 close( fd[ 0 ] );
318 if ( !runPrivileged() ) 316 if ( !runPrivileged() )
319 { 317 {
320 setgid( gid ); 318 setgid( gid );
321#if defined( HAVE_INITGROUPS) 319#if defined( HAVE_INITGROUPS)
322 320
323 if ( pw ) 321 if ( pw )
324 initgroups( pw->pw_name, pw->pw_gid ); 322 initgroups( pw->pw_name, pw->pw_gid );
325#endif 323#endif
326 324
327 setuid( uid ); 325 setuid( uid );
328 } 326 }
329 // The child process 327 // The child process
330 if ( !commSetupDoneC() ) 328 if ( !commSetupDoneC() )
331 qWarning( "Could not finish comm setup in child!" ); 329 qWarning( "Could not finish comm setup in child!" );
332 330
333 setupEnvironment(); 331 setupEnvironment();
334 332
335 // Matthias 333 // Matthias
336 if ( run_mode == DontCare ) 334 if ( run_mode == DontCare )
337 setpgid( 0, 0 ); 335 setpgid( 0, 0 );
338 // restore default SIGPIPE handler (Harri) 336 // restore default SIGPIPE handler (Harri)
339 struct sigaction act; 337 struct sigaction act;
340 sigemptyset( &( act.sa_mask ) ); 338 sigemptyset( &( act.sa_mask ) );
341 sigaddset( &( act.sa_mask ), SIGPIPE ); 339 sigaddset( &( act.sa_mask ), SIGPIPE );
342 act.sa_handler = SIG_DFL; 340 act.sa_handler = SIG_DFL;
343 act.sa_flags = 0; 341 act.sa_flags = 0;
344 sigaction( SIGPIPE, &act, 0L ); 342 sigaction( SIGPIPE, &act, 0L );
345 343
346 // We set the close on exec flag. 344 // We set the close on exec flag.
347 // Closing of fd[1] indicates that the execvp succeeded! 345 // Closing of fd[1] indicates that the execvp succeeded!
348 if ( fd[ 1 ] ) 346 if ( fd[ 1 ] )
349 fcntl( fd[ 1 ], F_SETFD, FD_CLOEXEC ); 347 fcntl( fd[ 1 ], F_SETFD, FD_CLOEXEC );
350 execvp( arglist[ 0 ], arglist ); 348 execvp( arglist[ 0 ], arglist );
351 char resultByte = 1; 349 char resultByte = 1;
352 if ( fd[ 1 ] ) 350 if ( fd[ 1 ] )
353 write( fd[ 1 ], &resultByte, 1 ); 351 write( fd[ 1 ], &resultByte, 1 );
354 _exit( -1 ); 352 _exit( -1 );
355 } 353 }
356 else if ( -1 == pid_ ) 354 else if ( -1 == pid_ )
357 { 355 {
358 // forking failed 356 // forking failed
359 357
360 runs = false; 358 runs = false;
361 free( arglist ); 359 free( arglist );
362 return false; 360 return false;
363 } 361 }
364 else 362 else
365 { 363 {
366 if ( fd[ 1 ] ) 364 if ( fd[ 1 ] )
367 close( fd[ 1 ] ); 365 close( fd[ 1 ] );
368 // the parent continues here 366 // the parent continues here
369 367
370 // Discard any data for stdin that might still be there 368 // Discard any data for stdin that might still be there
371 input_data = 0; 369 input_data = 0;
372 370
373 // Check whether client could be started. 371 // Check whether client could be started.
374 if ( fd[ 0 ] ) 372 if ( fd[ 0 ] )
375 for ( ;; ) 373 for ( ;; )
376 { 374 {
377 char resultByte; 375 char resultByte;
378 int n = ::read( fd[ 0 ], &resultByte, 1 ); 376 int n = ::read( fd[ 0 ], &resultByte, 1 );
379 if ( n == 1 ) 377 if ( n == 1 )
380 { 378 {
381 // Error 379 // Error
382 runs = false; 380 runs = false;
383 close( fd[ 0 ] ); 381 close( fd[ 0 ] );
384 free( arglist ); 382 free( arglist );
385 pid_ = 0; 383 pid_ = 0;
386 return false; 384 return false;
387 } 385 }
388 if ( n == -1 ) 386 if ( n == -1 )
389 { 387 {
390 if ( ( errno == ECHILD ) || ( errno == EINTR ) ) 388 if ( ( errno == ECHILD ) || ( errno == EINTR ) )
391 continue; // Ignore 389 continue; // Ignore
392 } 390 }
393 break; // success 391 break; // success
394 } 392 }
395 if ( fd[ 0 ] ) 393 if ( fd[ 0 ] )
396 close( fd[ 0 ] ); 394 close( fd[ 0 ] );
397 395
398 if ( !commSetupDoneP() ) // finish communication socket setup for the parent 396 if ( !commSetupDoneP() ) // finish communication socket setup for the parent
399 qWarning( "Could not finish comm setup in parent!" ); 397 qWarning( "Could not finish comm setup in parent!" );
400 398
401 if ( run_mode == Block ) 399 if ( run_mode == Block )
402 { 400 {
403 commClose(); 401 commClose();
404 402
405 // The SIGCHLD handler of the process controller will catch 403 // The SIGCHLD handler of the process controller will catch
406 // the exit and set the status 404 // the exit and set the status
407 while ( runs ) 405 while ( runs )
408 { 406 {
409 OProcessController::theOProcessController-> 407 OProcessController::theOProcessController->
410 slotDoHousekeeping( 0 ); 408 slotDoHousekeeping( 0 );
411 } 409 }
412 runs = FALSE; 410 runs = FALSE;
413 emit processExited( this ); 411 emit processExited( this );
414 } 412 }
415 } 413 }
416 free( arglist ); 414 free( arglist );
417 return true; 415 return true;
418} 416}
419 417
420 418
421 419
422bool OProcess::kill( int signo ) 420bool OProcess::kill( int signo )
423{ 421{
424 bool rv = false; 422 bool rv = false;
425 423
426 if ( 0 != pid_ ) 424 if ( 0 != pid_ )
427 rv = ( -1 != ::kill( pid_, signo ) ); 425 rv = ( -1 != ::kill( pid_, signo ) );
428 // probably store errno somewhere... 426 // probably store errno somewhere...
429 return rv; 427 return rv;
430} 428}
431 429
432bool OProcess::isRunning() const 430bool OProcess::isRunning() const
433{ 431{
434 return runs; 432 return runs;
435} 433}
436 434
437pid_t OProcess::pid() const 435pid_t OProcess::pid() const
438{ 436{
439 return pid_; 437 return pid_;
440} 438}
441 439
442bool OProcess::normalExit() const 440bool OProcess::normalExit() const
443{ 441{
444 int _status = status; 442 int _status = status;
445 return ( pid_ != 0 ) && ( !runs ) && ( WIFEXITED( ( _status ) ) ); 443 return ( pid_ != 0 ) && ( !runs ) && ( WIFEXITED( ( _status ) ) );
446} 444}
447 445
448int OProcess::exitStatus() const 446int OProcess::exitStatus() const
449{ 447{
450 int _status = status; 448 int _status = status;
451 return WEXITSTATUS( ( _status ) ); 449 return WEXITSTATUS( ( _status ) );
452} 450}
453 451
454bool OProcess::writeStdin( const char *buffer, int buflen ) 452bool OProcess::writeStdin( const char *buffer, int buflen )
455{ 453{
456 bool rv; 454 bool rv;
457 455
458 // if there is still data pending, writing new data 456 // if there is still data pending, writing new data
459 // to stdout is not allowed (since it could also confuse 457 // to stdout is not allowed (since it could also confuse
460 // kprocess... 458 // kprocess...
461 if ( 0 != input_data ) 459 if ( 0 != input_data )
462 return false; 460 return false;
463 461
464 if ( runs && ( communication & Stdin ) ) 462 if ( runs && ( communication & Stdin ) )
465 { 463 {
466 input_data = buffer; 464 input_data = buffer;
467 input_sent = 0; 465 input_sent = 0;
468 input_total = buflen; 466 input_total = buflen;
469 slotSendData( 0 ); 467 slotSendData( 0 );
470 innot->setEnabled( true ); 468 innot->setEnabled( true );
471 rv = true; 469 rv = true;
472 } 470 }
473 else 471 else
474 rv = false; 472 rv = false;
475 return rv; 473 return rv;
476} 474}
477 475
478void OProcess::flushStdin ( ) 476void OProcess::flushStdin ( )
479{ 477{
480 if ( !input_data || ( input_sent == input_total ) ) 478 if ( !input_data || ( input_sent == input_total ) )
481 return ; 479 return ;
482 480
483 int d1, d2; 481 int d1, d2;
484 482
485 do 483 do
486 { 484 {
487 d1 = input_total - input_sent; 485 d1 = input_total - input_sent;
488 slotSendData ( 0 ); 486 slotSendData ( 0 );
489 d2 = input_total - input_sent; 487 d2 = input_total - input_sent;
490 } 488 }
491 while ( d2 <= d1 ); 489 while ( d2 <= d1 );
492} 490}
493 491
494void OProcess::suspend() 492void OProcess::suspend()
495{ 493{
496 if ( ( communication & Stdout ) && outnot ) 494 if ( ( communication & Stdout ) && outnot )
497 outnot->setEnabled( false ); 495 outnot->setEnabled( false );
498} 496}
499 497
500void OProcess::resume() 498void OProcess::resume()
501{ 499{
502 if ( ( communication & Stdout ) && outnot ) 500 if ( ( communication & Stdout ) && outnot )
503 outnot->setEnabled( true ); 501 outnot->setEnabled( true );
504} 502}
505 503
506bool OProcess::closeStdin() 504bool OProcess::closeStdin()
507{ 505{
508 bool rv; 506 bool rv;
509 507
510 if ( communication & Stdin ) 508 if ( communication & Stdin )
511 { 509 {
512 communication = ( Communication ) ( communication & ~Stdin ); 510 communication = ( Communication ) ( communication & ~Stdin );
513 delete innot; 511 delete innot;
514 innot = 0; 512 innot = 0;
515 close( in[ 1 ] ); 513 close( in[ 1 ] );
516 rv = true; 514 rv = true;
517 } 515 }
518 else 516 else
519 rv = false; 517 rv = false;
520 return rv; 518 return rv;
521} 519}
522 520
523bool OProcess::closeStdout() 521bool OProcess::closeStdout()
524{ 522{
525 bool rv; 523 bool rv;
526 524
527 if ( communication & Stdout ) 525 if ( communication & Stdout )
528 { 526 {
529 communication = ( Communication ) ( communication & ~Stdout ); 527 communication = ( Communication ) ( communication & ~Stdout );
530 delete outnot; 528 delete outnot;
531 outnot = 0; 529 outnot = 0;
532 close( out[ 0 ] ); 530 close( out[ 0 ] );
533 rv = true; 531 rv = true;
534 } 532 }
535 else 533 else
536 rv = false; 534 rv = false;
537 return rv; 535 return rv;
538} 536}
539 537
540bool OProcess::closeStderr() 538bool OProcess::closeStderr()
541{ 539{
542 bool rv; 540 bool rv;
543 541
544 if ( communication & Stderr ) 542 if ( communication & Stderr )
545 { 543 {
546 communication = static_cast<Communication>( communication & ~Stderr ); 544 communication = static_cast<Communication>( communication & ~Stderr );
547 delete errnot; 545 delete errnot;
548 errnot = 0; 546 errnot = 0;
549 close( err[ 0 ] ); 547 close( err[ 0 ] );
550 rv = true; 548 rv = true;
551 } 549 }
552 else 550 else
553 rv = false; 551 rv = false;
554 return rv; 552 return rv;
555} 553}
556 554
557void OProcess::slotChildOutput( int fdno ) 555void OProcess::slotChildOutput( int fdno )
558{ 556{
559 if ( !childOutput( fdno ) ) 557 if ( !childOutput( fdno ) )
560 closeStdout(); 558 closeStdout();
561} 559}
562 560
563void OProcess::slotChildError( int fdno ) 561void OProcess::slotChildError( int fdno )
564{ 562{
565 if ( !childError( fdno ) ) 563 if ( !childError( fdno ) )
566 closeStderr(); 564 closeStderr();
567} 565}
568 566
569void OProcess::slotSendData( int ) 567void OProcess::slotSendData( int )
570{ 568{
571 if ( input_sent == input_total ) 569 if ( input_sent == input_total )
572 { 570 {
573 innot->setEnabled( false ); 571 innot->setEnabled( false );
574 input_data = 0; 572 input_data = 0;
575 emit wroteStdin( this ); 573 emit wroteStdin( this );
576 } 574 }
577 else 575 else
578 input_sent += ::write( in[ 1 ], input_data + input_sent, input_total - input_sent ); 576 input_sent += ::write( in[ 1 ], input_data + input_sent, input_total - input_sent );
579} 577}
580 578
581void OProcess::processHasExited( int state ) 579void OProcess::processHasExited( int state )
582{ 580{
583 if ( runs ) 581 if ( runs )
584 { 582 {
585 runs = false; 583 runs = false;
586 status = state; 584 status = state;
587 585
588 commClose(); // cleanup communication sockets 586 commClose(); // cleanup communication sockets
589 587
590 // also emit a signal if the process was run Blocking 588 // also emit a signal if the process was run Blocking
591 if ( DontCare != run_mode ) 589 if ( DontCare != run_mode )
592 { 590 {
593 emit processExited( this ); 591 emit processExited( this );
594 } 592 }
595 } 593 }
596} 594}
597 595
598int OProcess::childOutput( int fdno ) 596int OProcess::childOutput( int fdno )
599{ 597{
600 if ( communication & NoRead ) 598 if ( communication & NoRead )
601 { 599 {
602 int len = -1; 600 int len = -1;
603 emit receivedStdout( fdno, len ); 601 emit receivedStdout( fdno, len );
604 errno = 0; // Make sure errno doesn't read "EAGAIN" 602 errno = 0; // Make sure errno doesn't read "EAGAIN"
605 return len; 603 return len;
606 } 604 }
607 else 605 else
608 { 606 {
609 char buffer[ 1024 ]; 607 char buffer[ 1024 ];
610 int len; 608 int len;
611 609
612 len = ::read( fdno, buffer, 1024 ); 610 len = ::read( fdno, buffer, 1024 );
613 611
614 if ( 0 < len ) 612 if ( 0 < len )
615 { 613 {
616 emit receivedStdout( this, buffer, len ); 614 emit receivedStdout( this, buffer, len );
617 } 615 }
618 return len; 616 return len;
619 } 617 }
620} 618}
621 619
622int OProcess::childError( int fdno ) 620int OProcess::childError( int fdno )
623{ 621{
624 char buffer[ 1024 ]; 622 char buffer[ 1024 ];
625 int len; 623 int len;
626 624
627 len = ::read( fdno, buffer, 1024 ); 625 len = ::read( fdno, buffer, 1024 );
628 626
629 if ( 0 < len ) 627 if ( 0 < len )
630 emit receivedStderr( this, buffer, len ); 628 emit receivedStderr( this, buffer, len );
631 return len; 629 return len;
632} 630}
633 631
634int OProcess::setupCommunication( Communication comm ) 632int OProcess::setupCommunication( Communication comm )
635{ 633{
636 int ok; 634 int ok;
637 635
638 communication = comm; 636 communication = comm;
639 637
640 ok = 1; 638 ok = 1;
641 if ( comm & Stdin ) 639 if ( comm & Stdin )
642 ok &= socketpair( AF_UNIX, SOCK_STREAM, 0, in ) >= 0; 640 ok &= socketpair( AF_UNIX, SOCK_STREAM, 0, in ) >= 0;
643 641
644 if ( comm & Stdout ) 642 if ( comm & Stdout )
645 ok &= socketpair( AF_UNIX, SOCK_STREAM, 0, out ) >= 0; 643 ok &= socketpair( AF_UNIX, SOCK_STREAM, 0, out ) >= 0;
646 644
647 if ( comm & Stderr ) 645 if ( comm & Stderr )
648 ok &= socketpair( AF_UNIX, SOCK_STREAM, 0, err ) >= 0; 646 ok &= socketpair( AF_UNIX, SOCK_STREAM, 0, err ) >= 0;
649 647
650 return ok; 648 return ok;
651} 649}
652 650
653int OProcess::commSetupDoneP() 651int OProcess::commSetupDoneP()
654{ 652{
655 int ok = 1; 653 int ok = 1;
656 654
657 if ( communication != NoCommunication ) 655 if ( communication != NoCommunication )
658 { 656 {
659 if ( communication & Stdin ) 657 if ( communication & Stdin )
660 close( in[ 0 ] ); 658 close( in[ 0 ] );
661 if ( communication & Stdout ) 659 if ( communication & Stdout )
662 close( out[ 1 ] ); 660 close( out[ 1 ] );
663 if ( communication & Stderr ) 661 if ( communication & Stderr )
664 close( err[ 1 ] ); 662 close( err[ 1 ] );
665 663
666 // Don't create socket notifiers and set the sockets non-blocking if 664 // Don't create socket notifiers and set the sockets non-blocking if
667 // blocking is requested. 665 // blocking is requested.
668 if ( run_mode == Block ) 666 if ( run_mode == Block )
669 return ok; 667 return ok;
670 668
671 if ( communication & Stdin ) 669 if ( communication & Stdin )
672 { 670 {
673 // ok &= (-1 != fcntl(in[1], F_SETFL, O_NONBLOCK)); 671 // ok &= (-1 != fcntl(in[1], F_SETFL, O_NONBLOCK));
674 innot = new QSocketNotifier( in[ 1 ], QSocketNotifier::Write, this ); 672 innot = new QSocketNotifier( in[ 1 ], QSocketNotifier::Write, this );
675 CHECK_PTR( innot ); 673 CHECK_PTR( innot );
676 innot->setEnabled( false ); // will be enabled when data has to be sent 674 innot->setEnabled( false ); // will be enabled when data has to be sent
677 QObject::connect( innot, SIGNAL( activated( int ) ), 675 QObject::connect( innot, SIGNAL( activated( int ) ),
678 this, SLOT( slotSendData( int ) ) ); 676 this, SLOT( slotSendData( int ) ) );
679 } 677 }
680 678
681 if ( communication & Stdout ) 679 if ( communication & Stdout )
682 { 680 {
683 // ok &= (-1 != fcntl(out[0], F_SETFL, O_NONBLOCK)); 681 // ok &= (-1 != fcntl(out[0], F_SETFL, O_NONBLOCK));
684 outnot = new QSocketNotifier( out[ 0 ], QSocketNotifier::Read, this ); 682 outnot = new QSocketNotifier( out[ 0 ], QSocketNotifier::Read, this );
685 CHECK_PTR( outnot ); 683 CHECK_PTR( outnot );
686 QObject::connect( outnot, SIGNAL( activated( int ) ), 684 QObject::connect( outnot, SIGNAL( activated( int ) ),
687 this, SLOT( slotChildOutput( int ) ) ); 685 this, SLOT( slotChildOutput( int ) ) );
688 if ( communication & NoRead ) 686 if ( communication & NoRead )
689 suspend(); 687 suspend();
690 } 688 }
691 689
692 if ( communication & Stderr ) 690 if ( communication & Stderr )
693 { 691 {
694 // ok &= (-1 != fcntl(err[0], F_SETFL, O_NONBLOCK)); 692 // ok &= (-1 != fcntl(err[0], F_SETFL, O_NONBLOCK));
695 errnot = new QSocketNotifier( err[ 0 ], QSocketNotifier::Read, this ); 693 errnot = new QSocketNotifier( err[ 0 ], QSocketNotifier::Read, this );
696 CHECK_PTR( errnot ); 694 CHECK_PTR( errnot );
697 QObject::connect( errnot, SIGNAL( activated( int ) ), 695 QObject::connect( errnot, SIGNAL( activated( int ) ),
698 this, SLOT( slotChildError( int ) ) ); 696 this, SLOT( slotChildError( int ) ) );
699 } 697 }
700 } 698 }
701 return ok; 699 return ok;
702} 700}
703 701
704int OProcess::commSetupDoneC() 702int OProcess::commSetupDoneC()
705{ 703{
706 int ok = 1; 704 int ok = 1;
707 struct linger so; 705 struct linger so;
708 memset( &so, 0, sizeof( so ) ); 706 memset( &so, 0, sizeof( so ) );
709 707
710 if ( communication & Stdin ) 708 if ( communication & Stdin )
711 close( in[ 1 ] ); 709 close( in[ 1 ] );
712 if ( communication & Stdout ) 710 if ( communication & Stdout )
713 close( out[ 0 ] ); 711 close( out[ 0 ] );
714 if ( communication & Stderr ) 712 if ( communication & Stderr )
715 close( err[ 0 ] ); 713 close( err[ 0 ] );
716 714
717 if ( communication & Stdin ) 715 if ( communication & Stdin )
718 ok &= dup2( in[ 0 ], STDIN_FILENO ) != -1; 716 ok &= dup2( in[ 0 ], STDIN_FILENO ) != -1;
719 else 717 else
720 { 718 {
721 int null_fd = open( "/dev/null", O_RDONLY ); 719 int null_fd = open( "/dev/null", O_RDONLY );
722 ok &= dup2( null_fd, STDIN_FILENO ) != -1; 720 ok &= dup2( null_fd, STDIN_FILENO ) != -1;
723 close( null_fd ); 721 close( null_fd );
724 } 722 }
725 if ( communication & Stdout ) 723 if ( communication & Stdout )
726 { 724 {
727 ok &= dup2( out[ 1 ], STDOUT_FILENO ) != -1; 725 ok &= dup2( out[ 1 ], STDOUT_FILENO ) != -1;
728 ok &= !setsockopt( out[ 1 ], SOL_SOCKET, SO_LINGER, ( char* ) & so, sizeof( so ) ); 726 ok &= !setsockopt( out[ 1 ], SOL_SOCKET, SO_LINGER, ( char* ) & so, sizeof( so ) );
729 } 727 }
730 else 728 else
731 { 729 {
732 int null_fd = open( "/dev/null", O_WRONLY ); 730 int null_fd = open( "/dev/null", O_WRONLY );
733 ok &= dup2( null_fd, STDOUT_FILENO ) != -1; 731 ok &= dup2( null_fd, STDOUT_FILENO ) != -1;
734 close( null_fd ); 732 close( null_fd );
735 } 733 }
736 if ( communication & Stderr ) 734 if ( communication & Stderr )
737 { 735 {
738 ok &= dup2( err[ 1 ], STDERR_FILENO ) != -1; 736 ok &= dup2( err[ 1 ], STDERR_FILENO ) != -1;
739 ok &= !setsockopt( err[ 1 ], SOL_SOCKET, SO_LINGER, reinterpret_cast<char *>( &so ), sizeof( so ) ); 737 ok &= !setsockopt( err[ 1 ], SOL_SOCKET, SO_LINGER, reinterpret_cast<char *>( &so ), sizeof( so ) );
740 } 738 }
741 else 739 else
742 { 740 {
743 int null_fd = open( "/dev/null", O_WRONLY ); 741 int null_fd = open( "/dev/null", O_WRONLY );
744 ok &= dup2( null_fd, STDERR_FILENO ) != -1; 742 ok &= dup2( null_fd, STDERR_FILENO ) != -1;
745 close( null_fd ); 743 close( null_fd );
746 } 744 }
747 return ok; 745 return ok;
748} 746}
749 747
750void OProcess::commClose() 748void OProcess::commClose()
751{ 749{
752 if ( NoCommunication != communication ) 750 if ( NoCommunication != communication )
753 { 751 {
754 bool b_in = ( communication & Stdin ); 752 bool b_in = ( communication & Stdin );
755 bool b_out = ( communication & Stdout ); 753 bool b_out = ( communication & Stdout );
756 bool b_err = ( communication & Stderr ); 754 bool b_err = ( communication & Stderr );
757 if ( b_in ) 755 if ( b_in )
758 delete innot; 756 delete innot;
759 757
760 if ( b_out || b_err ) 758 if ( b_out || b_err )
761 { 759 {
762 // If both channels are being read we need to make sure that one socket buffer 760 // If both channels are being read we need to make sure that one socket buffer
763 // doesn't fill up whilst we are waiting for data on the other (causing a deadlock). 761 // doesn't fill up whilst we are waiting for data on the other (causing a deadlock).
764 // Hence we need to use select. 762 // Hence we need to use select.
765 763
766 // Once one or other of the channels has reached EOF (or given an error) go back 764 // Once one or other of the channels has reached EOF (or given an error) go back
767 // to the usual mechanism. 765 // to the usual mechanism.
768 766
769 int fds_ready = 1; 767 int fds_ready = 1;
770 fd_set rfds; 768 fd_set rfds;
771 769
772 int max_fd = 0; 770 int max_fd = 0;
773 if ( b_out ) 771 if ( b_out )
774 { 772 {
775 fcntl( out[ 0 ], F_SETFL, O_NONBLOCK ); 773 fcntl( out[ 0 ], F_SETFL, O_NONBLOCK );
776 if ( out[ 0 ] > max_fd ) 774 if ( out[ 0 ] > max_fd )
777 max_fd = out[ 0 ]; 775 max_fd = out[ 0 ];
778 delete outnot; 776 delete outnot;
779 outnot = 0; 777 outnot = 0;
780 } 778 }
781 if ( b_err ) 779 if ( b_err )
782 { 780 {
783 fcntl( err[ 0 ], F_SETFL, O_NONBLOCK ); 781 fcntl( err[ 0 ], F_SETFL, O_NONBLOCK );
784 if ( err[ 0 ] > max_fd ) 782 if ( err[ 0 ] > max_fd )
785 max_fd = err[ 0 ]; 783 max_fd = err[ 0 ];
786 delete errnot; 784 delete errnot;
787 errnot = 0; 785 errnot = 0;
788 } 786 }
789 787
790 788
791 while ( b_out || b_err ) 789 while ( b_out || b_err )
792 { 790 {
793 // * If the process is still running we block until we 791 // * If the process is still running we block until we
794 // receive data. (p_timeout = 0, no timeout) 792 // receive data. (p_timeout = 0, no timeout)
795 // * If the process has already exited, we only check 793 // * If the process has already exited, we only check
796 // the available data, we don't wait for more. 794 // the available data, we don't wait for more.
797 // (p_timeout = &timeout, timeout immediately) 795 // (p_timeout = &timeout, timeout immediately)
798 struct timeval timeout; 796 struct timeval timeout;
799 timeout.tv_sec = 0; 797 timeout.tv_sec = 0;
800 timeout.tv_usec = 0; 798 timeout.tv_usec = 0;
801 struct timeval *p_timeout = runs ? 0 : &timeout; 799 struct timeval *p_timeout = runs ? 0 : &timeout;
802 800
803 FD_ZERO( &rfds ); 801 FD_ZERO( &rfds );
804 if ( b_out ) 802 if ( b_out )
805 FD_SET( out[ 0 ], &rfds ); 803 FD_SET( out[ 0 ], &rfds );
806 804
807 if ( b_err ) 805 if ( b_err )
808 FD_SET( err[ 0 ], &rfds ); 806 FD_SET( err[ 0 ], &rfds );
809 807
810 fds_ready = select( max_fd + 1, &rfds, 0, 0, p_timeout ); 808 fds_ready = select( max_fd + 1, &rfds, 0, 0, p_timeout );
811 if ( fds_ready <= 0 ) 809 if ( fds_ready <= 0 )
812 break; 810 break;
813 811
814 if ( b_out && FD_ISSET( out[ 0 ], &rfds ) ) 812 if ( b_out && FD_ISSET( out[ 0 ], &rfds ) )
815 { 813 {
816 int ret = 1; 814 int ret = 1;
817 while ( ret > 0 ) 815 while ( ret > 0 )
818 ret = childOutput( out[ 0 ] ); 816 ret = childOutput( out[ 0 ] );
819 if ( ( ret == -1 && errno != EAGAIN ) || ret == 0 ) 817 if ( ( ret == -1 && errno != EAGAIN ) || ret == 0 )
820 b_out = false; 818 b_out = false;
821 } 819 }
822 820
823 if ( b_err && FD_ISSET( err[ 0 ], &rfds ) ) 821 if ( b_err && FD_ISSET( err[ 0 ], &rfds ) )
824 { 822 {
825 int ret = 1; 823 int ret = 1;
826 while ( ret > 0 ) 824 while ( ret > 0 )
827 ret = childError( err[ 0 ] ); 825 ret = childError( err[ 0 ] );
828 if ( ( ret == -1 && errno != EAGAIN ) || ret == 0 ) 826 if ( ( ret == -1 && errno != EAGAIN ) || ret == 0 )
829 b_err = false; 827 b_err = false;
830 } 828 }
831 } 829 }
832 } 830 }
833 831
834 if ( b_in ) 832 if ( b_in )
835 { 833 {
836 communication = ( Communication ) ( communication & ~Stdin ); 834 communication = ( Communication ) ( communication & ~Stdin );
837 close( in[ 1 ] ); 835 close( in[ 1 ] );
838 } 836 }
839 if ( b_out ) 837 if ( b_out )
840 { 838 {
841 communication = ( Communication ) ( communication & ~Stdout ); 839 communication = ( Communication ) ( communication & ~Stdout );
842 close( out[ 0 ] ); 840 close( out[ 0 ] );
843 } 841 }
844 if ( b_err ) 842 if ( b_err )
845 { 843 {
846 communication = ( Communication ) ( communication & ~Stderr ); 844 communication = ( Communication ) ( communication & ~Stderr );
847 close( err[ 0 ] ); 845 close( err[ 0 ] );
848 } 846 }
849 } 847 }
850} 848}
851 849
852void OProcess::setUseShell( bool useShell, const char *shell ) 850void OProcess::setUseShell( bool useShell, const char *shell )
853{ 851{
854 if ( !d ) 852 if ( !d )
855 d = new OProcessPrivate; 853 d = new OProcessPrivate;
856 d->useShell = useShell; 854 d->useShell = useShell;
857 d->shell = shell; 855 d->shell = shell;
858 if ( d->shell.isEmpty() ) 856 if ( d->shell.isEmpty() )
859 d->shell = searchShell(); 857 d->shell = searchShell();
860} 858}
861 859
862QString OProcess::quote( const QString &arg ) 860QString OProcess::quote( const QString &arg )
863{ 861{
864 QString res = arg; 862 QString res = arg;
865 res.replace( QRegExp( QString::fromLatin1( "\'" ) ), 863 res.replace( QRegExp( QString::fromLatin1( "\'" ) ),
866 QString::fromLatin1( "'\"'\"'" ) ); 864 QString::fromLatin1( "'\"'\"'" ) );
867 res.prepend( '\'' ); 865 res.prepend( '\'' );
868 res.append( '\'' ); 866 res.append( '\'' );
869 return res; 867 return res;
870} 868}
871 869
872QCString OProcess::searchShell() 870QCString OProcess::searchShell()
873{ 871{
874 QCString tmpShell = QCString( getenv( "SHELL" ) ).stripWhiteSpace(); 872 QCString tmpShell = QCString( getenv( "SHELL" ) ).stripWhiteSpace();
875 if ( !isExecutable( tmpShell ) ) 873 if ( !isExecutable( tmpShell ) )
876 { 874 {
877 tmpShell = "/bin/sh"; 875 tmpShell = "/bin/sh";
878 } 876 }
879 877
880 return tmpShell; 878 return tmpShell;
881} 879}
882 880
883bool OProcess::isExecutable( const QCString &filename ) 881bool OProcess::isExecutable( const QCString &filename )
884{ 882{
885 struct stat fileinfo; 883 struct stat fileinfo;
886 884
887 if ( filename.isEmpty() ) 885 if ( filename.isEmpty() )
888 return false; 886 return false;
889 887
890 // CC: we've got a valid filename, now let's see whether we can execute that file 888 // CC: we've got a valid filename, now let's see whether we can execute that file
891 889
892 if ( -1 == stat( filename.data(), &fileinfo ) ) 890 if ( -1 == stat( filename.data(), &fileinfo ) )
893 return false; 891 return false;
894 // CC: return false if the file does not exist 892 // CC: return false if the file does not exist
895 893
896 // CC: anyway, we cannot execute directories, block/character devices, fifos or sockets 894 // CC: anyway, we cannot execute directories, block/character devices, fifos or sockets
897 if ( ( S_ISDIR( fileinfo.st_mode ) ) || 895 if ( ( S_ISDIR( fileinfo.st_mode ) ) ||
898 ( S_ISCHR( fileinfo.st_mode ) ) || 896 ( S_ISCHR( fileinfo.st_mode ) ) ||
899 ( S_ISBLK( fileinfo.st_mode ) ) || 897 ( S_ISBLK( fileinfo.st_mode ) ) ||
900#ifdef S_ISSOCK 898#ifdef S_ISSOCK
901 // CC: SYSVR4 systems don't have that macro 899 // CC: SYSVR4 systems don't have that macro
902 ( S_ISSOCK( fileinfo.st_mode ) ) || 900 ( S_ISSOCK( fileinfo.st_mode ) ) ||
903#endif 901#endif
904 ( S_ISFIFO( fileinfo.st_mode ) ) || 902 ( S_ISFIFO( fileinfo.st_mode ) ) ||
905 ( S_ISDIR( fileinfo.st_mode ) ) ) 903 ( S_ISDIR( fileinfo.st_mode ) ) )
906 { 904 {
907 return false; 905 return false;
908 } 906 }
909 907
910 // CC: now check for permission to execute the file 908 // CC: now check for permission to execute the file
911 if ( access( filename.data(), X_OK ) != 0 ) 909 if ( access( filename.data(), X_OK ) != 0 )
912 return false; 910 return false;
913 911
914 // CC: we've passed all the tests... 912 // CC: we've passed all the tests...
915 return true; 913 return true;
916} 914}
917 915
918int OProcess::processPID( const QString& process ) 916int OProcess::processPID( const QString& process )
919{ 917{
920 QString line; 918 QString line;
921 QDir d = QDir( "/proc" ); 919 QDir d = QDir( "/proc" );
922 QStringList dirs = d.entryList( QDir::Dirs ); 920 QStringList dirs = d.entryList( QDir::Dirs );
923 QStringList::Iterator it; 921 QStringList::Iterator it;
924 for ( it = dirs.begin(); it != dirs.end(); ++it ) 922 for ( it = dirs.begin(); it != dirs.end(); ++it )
925 { 923 {
926 //qDebug( "next entry: %s", (const char*) *it ); 924 //qDebug( "next entry: %s", (const char*) *it );
927 QFile file( "/proc/"+*it+"/cmdline" ); 925 QFile file( "/proc/"+*it+"/cmdline" );
928 file.open( IO_ReadOnly ); 926 file.open( IO_ReadOnly );
929 if ( !file.isOpen() ) continue; 927 if ( !file.isOpen() ) continue;
930 QTextStream t( &file ); 928 QTextStream t( &file );
931 line = t.readLine(); 929 line = t.readLine();
932 //qDebug( "cmdline = %s", (const char*) line ); 930 //qDebug( "cmdline = %s", (const char*) line );
933 if ( line.contains( process ) ) break; //FIXME: That may find also other process, if the name is not long enough ;) 931 if ( line.contains( process ) ) break; //FIXME: That may find also other process, if the name is not long enough ;)
934 } 932 }
935 if ( line.contains( process ) ) 933 if ( line.contains( process ) )
936 { 934 {
937 //qDebug( "found process id #%d", (*it).toInt() ); 935 //qDebug( "found process id #%d", (*it).toInt() );
938 return (*it).toInt(); 936 return (*it).toInt();
939 } 937 }
940 else 938 else
941 { 939 {
942 //qDebug( "process '%s' not found", (const char*) process ); 940 //qDebug( "process '%s' not found", (const char*) process );
943 return 0; 941 return 0;
944 } 942 }
945} 943}
diff --git a/libopie2/opiedb/osqlbackendmanager.cpp b/libopie2/opiedb/osqlbackendmanager.cpp
index 0f261b9..95ed77b 100644
--- a/libopie2/opiedb/osqlbackendmanager.cpp
+++ b/libopie2/opiedb/osqlbackendmanager.cpp
@@ -1,99 +1,98 @@
1#include <qdir.h> 1#include <qdir.h>
2#include <qfile.h>
3#include <qmap.h> 2#include <qmap.h>
4 3
5#include "osqlbackendmanager.h" 4#include "osqlbackendmanager.h"
6 5
7namespace { 6namespace {
8 class Config { 7 class Config {
9 typedef QMap<QString, QString> List; 8 typedef QMap<QString, QString> List;
10 public: 9 public:
11 Config( const QString& fileName ); 10 Config( const QString& fileName );
12 /** 11 /**
13 * Quite simple layout in nature 12 * Quite simple layout in nature
14 * BeginFile 13 * BeginFile
15 * Key = Value 14 * Key = Value
16 */ 15 */
17 bool load(); 16 bool load();
18 QString value( const QString& key ); 17 QString value( const QString& key );
19 private: 18 private:
20 List m_list; 19 List m_list;
21 QString m_fileName; 20 QString m_fileName;
22 }; 21 };
23 Config::Config( const QString& fileName ) 22 Config::Config( const QString& fileName )
24 : m_fileName( fileName ) { 23 : m_fileName( fileName ) {
25 } 24 }
26 25
27 bool Config::load() { 26 bool Config::load() {
28 if (!QFile::exists( m_fileName ) ) 27 if (!QFile::exists( m_fileName ) )
29 return false; 28 return false;
30 QFile file( m_fileName ); 29 QFile file( m_fileName );
31 if (!file.open(IO_ReadOnly ) ) 30 if (!file.open(IO_ReadOnly ) )
32 return false; 31 return false;
33 QStringList list = QStringList::split( '\n', file.readAll() ); 32 QStringList list = QStringList::split( '\n', file.readAll() );
34 QStringList::Iterator it; 33 QStringList::Iterator it;
35 QString line; 34 QString line;
36 for (it = list.begin(); it != list.end(); ++it ) { 35 for (it = list.begin(); it != list.end(); ++it ) {
37 line = (*it).stripWhiteSpace(); 36 line = (*it).stripWhiteSpace();
38 qWarning("Anonymous::Config:" + line ); 37 qWarning("Anonymous::Config:" + line );
39 QStringList test = QStringList::split(' ', line ); 38 QStringList test = QStringList::split(' ', line );
40 m_list.insert( test[0], test[2] ); 39 m_list.insert( test[0], test[2] );
41 } 40 }
42 return true; 41 return true;
43 } 42 }
44 QString Config::value( const QString& key ) { 43 QString Config::value( const QString& key ) {
45 return m_list[key]; 44 return m_list[key];
46 } 45 }
47}; 46};
48OSQLBackEndManager::OSQLBackEndManager( const QStringList& path ) 47OSQLBackEndManager::OSQLBackEndManager( const QStringList& path )
49 :m_path( path ) 48 :m_path( path )
50{ 49{
51} 50}
52OSQLBackEndManager::~OSQLBackEndManager() { 51OSQLBackEndManager::~OSQLBackEndManager() {
53} 52}
54/** 53/**
55 * scan dirs 54 * scan dirs
56 */ 55 */
57OSQLBackEnd::ValueList OSQLBackEndManager::scan() { 56OSQLBackEnd::ValueList OSQLBackEndManager::scan() {
58 OSQLBackEnd::ValueList list; 57 OSQLBackEnd::ValueList list;
59 if (!m_path.isEmpty() ) { 58 if (!m_path.isEmpty() ) {
60 QStringList::Iterator it; 59 QStringList::Iterator it;
61 for ( it = m_path.begin(); it != m_path.end(); ++it ) { 60 for ( it = m_path.begin(); it != m_path.end(); ++it ) {
62 list += scanDir( (*it) ); 61 list += scanDir( (*it) );
63 } 62 }
64 } 63 }
65 return list; 64 return list;
66} 65}
67/** 66/**
68 * scan a specified dir for *.osql 67 * scan a specified dir for *.osql
69 */ 68 */
70OSQLBackEnd::ValueList OSQLBackEndManager::scanDir( const QString& dirName ) { 69OSQLBackEnd::ValueList OSQLBackEndManager::scanDir( const QString& dirName ) {
71 OSQLBackEnd::ValueList list; 70 OSQLBackEnd::ValueList list;
72 QDir dir( dirName ); 71 QDir dir( dirName );
73 if (dir.exists() ) { 72 if (dir.exists() ) {
74 QStringList files = dir.entryList( "*.osql" ); 73 QStringList files = dir.entryList( "*.osql" );
75 QStringList::Iterator it; 74 QStringList::Iterator it;
76 for ( it = files.begin(); it != files.end(); ++it ) { 75 for ( it = files.begin(); it != files.end(); ++it ) {
77 list.append( file2backend( (*it) ) ); 76 list.append( file2backend( (*it) ) );
78 } 77 }
79 } 78 }
80 return list; 79 return list;
81} 80}
82 81
83/** 82/**
84 * read a config file and convert it to a OSQLBackEnd 83 * read a config file and convert it to a OSQLBackEnd
85 */ 84 */
86OSQLBackEnd OSQLBackEndManager::file2backend( const QString& file ) { 85OSQLBackEnd OSQLBackEndManager::file2backend( const QString& file ) {
87 OSQLBackEnd end; 86 OSQLBackEnd end;
88 qWarning("fileName: " + file ); 87 qWarning("fileName: " + file );
89 Config cfg( file ); 88 Config cfg( file );
90 if (cfg.load() ) { 89 if (cfg.load() ) {
91 end.setName( cfg.value( "Name") ); 90 end.setName( cfg.value( "Name") );
92 end.setVendor( cfg.value("Vendor") ); 91 end.setVendor( cfg.value("Vendor") );
93 end.setLicense( cfg.value("License") ); 92 end.setLicense( cfg.value("License") );
94 end.setLibrary( cfg.value("Library").local8Bit() ); 93 end.setLibrary( cfg.value("Library").local8Bit() );
95 end.setDefault( cfg.value("Default").toInt() ); 94 end.setDefault( cfg.value("Default").toInt() );
96 end.setPreference( cfg.value("Preference").toInt() ); 95 end.setPreference( cfg.value("Preference").toInt() );
97 } 96 }
98 return end; 97 return end;
99} 98}
diff --git a/libopie2/opiedb/osqlitedriver.cpp b/libopie2/opiedb/osqlitedriver.cpp
index b857534..6141504 100644
--- a/libopie2/opiedb/osqlitedriver.cpp
+++ b/libopie2/opiedb/osqlitedriver.cpp
@@ -1,189 +1,188 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3 3
4 =. 4 =.
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 30
31#include "osqlresult.h"
32#include "osqlquery.h" 31#include "osqlquery.h"
33#include "osqlitedriver.h" 32#include "osqlitedriver.h"
34 33
35#include <opie2/odebug.h> 34#include <opie2/odebug.h>
36 35
37#include <stdlib.h> 36#include <stdlib.h>
38 37
39// fromLocal8Bit() does not work as expected. Thus it 38// fromLocal8Bit() does not work as expected. Thus it
40// is replaced by fromLatin1() (eilers) 39// is replaced by fromLatin1() (eilers)
41#define __BUGGY_LOCAL8BIT_ 40#define __BUGGY_LOCAL8BIT_
42 41
43 42
44namespace { 43namespace {
45 struct Query { 44 struct Query {
46 OSQLError::ValueList errors; 45 OSQLError::ValueList errors;
47 OSQLResultItem::ValueList items; 46 OSQLResultItem::ValueList items;
48 OSQLiteDriver *driver; 47 OSQLiteDriver *driver;
49 }; 48 };
50} 49}
51 50
52 51
53OSQLiteDriver::OSQLiteDriver( QLibrary *lib ) 52OSQLiteDriver::OSQLiteDriver( QLibrary *lib )
54 : OSQLDriver( lib ) 53 : OSQLDriver( lib )
55{ 54{
56 m_sqlite = 0l; 55 m_sqlite = 0l;
57} 56}
58 57
59 58
60OSQLiteDriver::~OSQLiteDriver() { 59OSQLiteDriver::~OSQLiteDriver() {
61 close(); 60 close();
62} 61}
63 62
64 63
65QString OSQLiteDriver::id()const { 64QString OSQLiteDriver::id()const {
66 return QString::fromLatin1("SQLite"); 65 return QString::fromLatin1("SQLite");
67} 66}
68 67
69void OSQLiteDriver::setUserName( const QString& ) {} 68void OSQLiteDriver::setUserName( const QString& ) {}
70 69
71 70
72void OSQLiteDriver::setPassword( const QString& ) {} 71void OSQLiteDriver::setPassword( const QString& ) {}
73 72
74 73
75void OSQLiteDriver::setUrl( const QString& url ) { 74void OSQLiteDriver::setUrl( const QString& url ) {
76 m_url = url; 75 m_url = url;
77} 76}
78 77
79 78
80void OSQLiteDriver::setOptions( const QStringList& ) { 79void OSQLiteDriver::setOptions( const QStringList& ) {
81} 80}
82 81
83 82
84/* 83/*
85 * try to open a db specified via setUrl 84 * try to open a db specified via setUrl
86 * and options 85 * and options
87 */ 86 */
88bool OSQLiteDriver::open() { 87bool OSQLiteDriver::open() {
89 char *error; 88 char *error;
90 odebug << "OSQLiteDriver::open: about to open" << oendl; 89 odebug << "OSQLiteDriver::open: about to open" << oendl;
91 m_sqlite = sqlite_open(m_url.local8Bit(), 90 m_sqlite = sqlite_open(m_url.local8Bit(),
92 0, 91 0,
93 &error ); 92 &error );
94 93
95 /* failed to open */ 94 /* failed to open */
96 if (m_sqlite == 0l ) { 95 if (m_sqlite == 0l ) {
97 // FIXME set the last error 96 // FIXME set the last error
98 owarn << "OSQLiteDriver::open: " << error << oendl; 97 owarn << "OSQLiteDriver::open: " << error << oendl;
99 free( error ); 98 free( error );
100 return false; 99 return false;
101 } 100 }
102 return true; 101 return true;
103} 102}
104 103
105 104
106/* close the db 105/* close the db
107 * sqlite closes them without 106 * sqlite closes them without
108 * telling failure or success 107 * telling failure or success
109 */ 108 */
110bool OSQLiteDriver::close() { 109bool OSQLiteDriver::close() {
111 if (m_sqlite ) 110 if (m_sqlite )
112 sqlite_close( m_sqlite ), m_sqlite=0l; 111 sqlite_close( m_sqlite ), m_sqlite=0l;
113 112
114 return true; 113 return true;
115} 114}
116 115
117 116
118/* Query */ 117/* Query */
119OSQLResult OSQLiteDriver::query( OSQLQuery* qu) { 118OSQLResult OSQLiteDriver::query( OSQLQuery* qu) {
120 if ( !m_sqlite ) { 119 if ( !m_sqlite ) {
121 // FIXME set error code 120 // FIXME set error code
122 OSQLResult result( OSQLResult::Failure ); 121 OSQLResult result( OSQLResult::Failure );
123 return result; 122 return result;
124 } 123 }
125 Query query; 124 Query query;
126 query.driver = this; 125 query.driver = this;
127 char *err; 126 char *err;
128 /* SQLITE_OK 0 if return code > 0 == failure */ 127 /* SQLITE_OK 0 if return code > 0 == failure */
129 if ( sqlite_exec(m_sqlite, qu->query(),&call_back, &query, &err) > 0 ) { 128 if ( sqlite_exec(m_sqlite, qu->query(),&call_back, &query, &err) > 0 ) {
130 owarn << "OSQLiteDriver::query: Error while executing" << oendl; 129 owarn << "OSQLiteDriver::query: Error while executing" << oendl;
131 free(err ); 130 free(err );
132 // FixMe Errors 131 // FixMe Errors
133 } 132 }
134 133
135 OSQLResult result(OSQLResult::Success, 134 OSQLResult result(OSQLResult::Success,
136 query.items, 135 query.items,
137 query.errors ); 136 query.errors );
138 return result; 137 return result;
139} 138}
140 139
141 140
142OSQLTable::ValueList OSQLiteDriver::tables() const { 141OSQLTable::ValueList OSQLiteDriver::tables() const {
143 142
144} 143}
145 144
146 145
147OSQLError OSQLiteDriver::lastError() { 146OSQLError OSQLiteDriver::lastError() {
148 OSQLError error; 147 OSQLError error;
149 return error; 148 return error;
150}; 149};
151 150
152 151
153/* handle a callback add the row to the global 152/* handle a callback add the row to the global
154 * OSQLResultItem 153 * OSQLResultItem
155 */ 154 */
156int OSQLiteDriver::handleCallBack( int, char**, char** ) { 155int OSQLiteDriver::handleCallBack( int, char**, char** ) {
157 return 0; 156 return 0;
158} 157}
159 158
160 159
161/* callback_handler add the values to the list*/ 160/* callback_handler add the values to the list*/
162int OSQLiteDriver::call_back( void* voi, int argc, 161int OSQLiteDriver::call_back( void* voi, int argc,
163 char** argv, char** columns) { 162 char** argv, char** columns) {
164 Query* qu = (Query*)voi; 163 Query* qu = (Query*)voi;
165 164
166 //copy them over to a OSQLResultItem 165 //copy them over to a OSQLResultItem
167 QMap<QString, QString> tableString; 166 QMap<QString, QString> tableString;
168 QMap<int, QString> tableInt; 167 QMap<int, QString> tableInt;
169 for (int i = 0; i < argc; i++ ) { 168 for (int i = 0; i < argc; i++ ) {
170 169
171#ifdef __BUGGY_LOCAL8BIT_ 170#ifdef __BUGGY_LOCAL8BIT_
172 tableInt.insert( i, QString::fromLatin1( argv[i] ) ); 171 tableInt.insert( i, QString::fromLatin1( argv[i] ) );
173 tableString.insert( QString::fromLatin1( columns[i] ), 172 tableString.insert( QString::fromLatin1( columns[i] ),
174 QString::fromLatin1( argv[i] ) ); 173 QString::fromLatin1( argv[i] ) );
175#else 174#else
176 tableInt.insert( i, QString::fromLocal8Bit( argv[i] ) ); 175 tableInt.insert( i, QString::fromLocal8Bit( argv[i] ) );
177 tableString.insert( QString::fromLocal8Bit( columns[i] ), 176 tableString.insert( QString::fromLocal8Bit( columns[i] ),
178 QString::fromLocal8Bit( argv[i] ) ); 177 QString::fromLocal8Bit( argv[i] ) );
179#endif 178#endif
180 } 179 }
181 OSQLResultItem item( tableString, tableInt ); 180 OSQLResultItem item( tableString, tableInt );
182 qu->items.append( item ); 181 qu->items.append( item );
183 182
184 return ((Query*)voi)->driver->handleCallBack( argc, 183 return ((Query*)voi)->driver->handleCallBack( argc,
185 argv, 184 argv,
186 columns ); 185 columns );
187 186
188 187
189} 188}
diff --git a/libopie2/opiedb/osqlmanager.cpp b/libopie2/opiedb/osqlmanager.cpp
index b0fea04..766ebe1 100644
--- a/libopie2/opiedb/osqlmanager.cpp
+++ b/libopie2/opiedb/osqlmanager.cpp
@@ -1,83 +1,81 @@
1 1
2#include <stdlib.h> 2#include <stdlib.h>
3 3
4#include "osqlbackend.h"
5#include "osqldriver.h"
6#include "osqlmanager.h" 4#include "osqlmanager.h"
7#include "osqlbackendmanager.h" 5#include "osqlbackendmanager.h"
8#include "osqlitedriver.h" 6#include "osqlitedriver.h"
9 7
10OSQLManager::OSQLManager() { 8OSQLManager::OSQLManager() {
11} 9}
12OSQLBackEnd::ValueList OSQLManager::queryBackEnd() { 10OSQLBackEnd::ValueList OSQLManager::queryBackEnd() {
13 m_list.clear(); 11 m_list.clear();
14 QString opie = QString::fromLatin1( getenv("OPIEDIR") ); 12 QString opie = QString::fromLatin1( getenv("OPIEDIR") );
15 QString qpe = QString::fromLatin1( getenv("QPEDIR") ); 13 QString qpe = QString::fromLatin1( getenv("QPEDIR") );
16 14
17 if ( !m_path.contains(opie) && !opie.isEmpty() ) 15 if ( !m_path.contains(opie) && !opie.isEmpty() )
18 m_path << opie; 16 m_path << opie;
19 if ( !m_path.contains(qpe) && !qpe.isEmpty() ) 17 if ( !m_path.contains(qpe) && !qpe.isEmpty() )
20 m_path << qpe; 18 m_path << qpe;
21 19
22 OSQLBackEndManager mng( m_path ); 20 OSQLBackEndManager mng( m_path );
23 m_list = mng.scan(); 21 m_list = mng.scan();
24 m_list += builtIn(); 22 m_list += builtIn();
25 23
26 return m_list; 24 return m_list;
27} 25}
28/* 26/*
29 * loading dso's is currently not enabled due problems with QLibrary 27 * loading dso's is currently not enabled due problems with QLibrary
30 * beeing in libqpe and not libqte 28 * beeing in libqpe and not libqte
31 */ 29 */
32OSQLDriver* OSQLManager::load( const QString& name ) { 30OSQLDriver* OSQLManager::load( const QString& name ) {
33 OSQLDriver* driver = 0l; 31 OSQLDriver* driver = 0l;
34 32
35 if ( name == "SQLite" ) { 33 if ( name == "SQLite" ) {
36 driver = new OSQLiteDriver(); 34 driver = new OSQLiteDriver();
37 } 35 }
38 return driver; 36 return driver;
39} 37}
40/* 38/*
41 * same as above 39 * same as above
42 */ 40 */
43OSQLDriver* OSQLManager::load( const OSQLBackEnd& end) { 41OSQLDriver* OSQLManager::load( const OSQLBackEnd& end) {
44 OSQLDriver *driver = 0l; 42 OSQLDriver *driver = 0l;
45 if ( end.library() == "builtin" && 43 if ( end.library() == "builtin" &&
46 end.name() == "SQLite" ) 44 end.name() == "SQLite" )
47 driver = new OSQLiteDriver(); 45 driver = new OSQLiteDriver();
48 46
49 return driver; 47 return driver;
50} 48}
51/* 49/*
52 * let's find the a default with the highes preference 50 * let's find the a default with the highes preference
53 */ 51 */
54OSQLDriver* OSQLManager::standard() { 52OSQLDriver* OSQLManager::standard() {
55 OSQLDriver* driver =0l; 53 OSQLDriver* driver =0l;
56 if ( m_list.isEmpty() ) queryBackEnd(); 54 if ( m_list.isEmpty() ) queryBackEnd();
57 OSQLBackEnd::ValueList::Iterator it; 55 OSQLBackEnd::ValueList::Iterator it;
58 OSQLBackEnd back; 56 OSQLBackEnd back;
59 for ( it = m_list.begin(); it != m_list.end(); ++it ) { 57 for ( it = m_list.begin(); it != m_list.end(); ++it ) {
60 if ( (*it).isDefault() && 58 if ( (*it).isDefault() &&
61 back.preference() < (*it).preference() ) { 59 back.preference() < (*it).preference() ) {
62 back = (*it); 60 back = (*it);
63 } 61 }
64 } 62 }
65 driver = load( back ); 63 driver = load( back );
66 return driver; 64 return driver;
67} 65}
68void OSQLManager::registerPath( const QString& path ) { 66void OSQLManager::registerPath( const QString& path ) {
69 m_path << path; 67 m_path << path;
70} 68}
71bool OSQLManager::unregisterPath( const QString& path ) { 69bool OSQLManager::unregisterPath( const QString& path ) {
72 m_path.remove( path ); 70 m_path.remove( path );
73 return true; 71 return true;
74} 72}
75OSQLBackEnd::ValueList OSQLManager::builtIn()const { 73OSQLBackEnd::ValueList OSQLManager::builtIn()const {
76 OSQLBackEnd::ValueList list; 74 OSQLBackEnd::ValueList list;
77 // create the OSQLiteBackend 75 // create the OSQLiteBackend
78 OSQLBackEnd back("SQLite","Opie e.V.","GPL", "builtin" ); 76 OSQLBackEnd back("SQLite","Opie e.V.","GPL", "builtin" );
79 back.setDefault( true ); 77 back.setDefault( true );
80 back.setPreference( 50 ); 78 back.setPreference( 50 );
81 list.append( back ); 79 list.append( back );
82 return list; 80 return list;
83} 81}
diff --git a/libopie2/opiedb/osqlresult.cpp b/libopie2/opiedb/osqlresult.cpp
index 490fb45..42da356 100644
--- a/libopie2/opiedb/osqlresult.cpp
+++ b/libopie2/opiedb/osqlresult.cpp
@@ -1,127 +1,126 @@
1 1
2#include "osqlquery.h"
3#include "osqlresult.h" 2#include "osqlresult.h"
4 3
5OSQLResultItem::OSQLResultItem( const TableString& string, 4OSQLResultItem::OSQLResultItem( const TableString& string,
6 const TableInt& Int) 5 const TableInt& Int)
7 : m_string( string ), m_int( Int ) 6 : m_string( string ), m_int( Int )
8{ 7{
9 8
10} 9}
11OSQLResultItem::~OSQLResultItem() { 10OSQLResultItem::~OSQLResultItem() {
12} 11}
13OSQLResultItem::OSQLResultItem( const OSQLResultItem& item) { 12OSQLResultItem::OSQLResultItem( const OSQLResultItem& item) {
14 *this = item; 13 *this = item;
15} 14}
16OSQLResultItem &OSQLResultItem::operator=( const OSQLResultItem& other) { 15OSQLResultItem &OSQLResultItem::operator=( const OSQLResultItem& other) {
17 m_string = other.m_string; 16 m_string = other.m_string;
18 m_int = other.m_int; 17 m_int = other.m_int;
19 return *this; 18 return *this;
20} 19}
21OSQLResultItem::TableString OSQLResultItem::tableString()const{ 20OSQLResultItem::TableString OSQLResultItem::tableString()const{
22 return m_string; 21 return m_string;
23} 22}
24OSQLResultItem::TableInt OSQLResultItem::tableInt()const { 23OSQLResultItem::TableInt OSQLResultItem::tableInt()const {
25 return m_int; 24 return m_int;
26} 25}
27QString OSQLResultItem::data( const QString& columnName, bool *ok ) { 26QString OSQLResultItem::data( const QString& columnName, bool *ok ) {
28 TableString::Iterator it = m_string.find( columnName ); 27 TableString::Iterator it = m_string.find( columnName );
29 28
30 /* if found */ 29 /* if found */
31 if ( it != m_string.end() ) { 30 if ( it != m_string.end() ) {
32 if ( ok ) *ok = true; 31 if ( ok ) *ok = true;
33 return it.data(); 32 return it.data();
34 }else{ 33 }else{
35 if ( ok ) *ok = false; 34 if ( ok ) *ok = false;
36 return QString::null; 35 return QString::null;
37 } 36 }
38 37
39} 38}
40QString OSQLResultItem::data( int column, bool *ok ) { 39QString OSQLResultItem::data( int column, bool *ok ) {
41 TableInt::Iterator it = m_int.find( column ); 40 TableInt::Iterator it = m_int.find( column );
42 41
43 /* if found */ 42 /* if found */
44 if ( it != m_int.end() ) { 43 if ( it != m_int.end() ) {
45 if ( ok ) *ok = true; 44 if ( ok ) *ok = true;
46 return it.data(); 45 return it.data();
47 }else{ 46 }else{
48 if ( ok ) *ok = false; 47 if ( ok ) *ok = false;
49 return QString::null; 48 return QString::null;
50 } 49 }
51} 50}
52/* 51/*
53 * DateFormat is 'YYYY-MM-DD' 52 * DateFormat is 'YYYY-MM-DD'
54 */ 53 */
55QDate OSQLResultItem::dataToDate( const QString& column, bool *ok ) { 54QDate OSQLResultItem::dataToDate( const QString& column, bool *ok ) {
56 QDate date = QDate::currentDate(); 55 QDate date = QDate::currentDate();
57 QString str = data( column, ok ); 56 QString str = data( column, ok );
58 if (!str.isEmpty() ) { 57 if (!str.isEmpty() ) {
59 ;// convert 58 ;// convert
60 } 59 }
61 return date; 60 return date;
62} 61}
63QDate OSQLResultItem::dataToDate( int column, bool *ok ) { 62QDate OSQLResultItem::dataToDate( int column, bool *ok ) {
64 QDate date = QDate::currentDate(); 63 QDate date = QDate::currentDate();
65 QString str = data( column, ok ); 64 QString str = data( column, ok );
66 if (!str.isEmpty() ) { 65 if (!str.isEmpty() ) {
67 ;// convert 66 ;// convert
68 } 67 }
69 return date; 68 return date;
70 69
71} 70}
72QDateTime OSQLResultItem::dataToDateTime( const QString& column, bool *ok ) { 71QDateTime OSQLResultItem::dataToDateTime( const QString& column, bool *ok ) {
73 QDateTime time = QDateTime::currentDateTime(); 72 QDateTime time = QDateTime::currentDateTime();
74 return time; 73 return time;
75} 74}
76QDateTime OSQLResultItem::dataToDateTime( int column, bool *ok ) { 75QDateTime OSQLResultItem::dataToDateTime( int column, bool *ok ) {
77 QDateTime time = QDateTime::currentDateTime(); 76 QDateTime time = QDateTime::currentDateTime();
78 return time; 77 return time;
79} 78}
80 79
81OSQLResult::OSQLResult( enum State state, 80OSQLResult::OSQLResult( enum State state,
82 const OSQLResultItem::ValueList& list, 81 const OSQLResultItem::ValueList& list,
83 const OSQLError::ValueList& error ) 82 const OSQLError::ValueList& error )
84 : m_state( state ), m_list( list ), m_error( error ) 83 : m_state( state ), m_list( list ), m_error( error )
85{ 84{
86 85
87} 86}
88OSQLResult::~OSQLResult() { 87OSQLResult::~OSQLResult() {
89 88
90} 89}
91OSQLResult::State OSQLResult::state()const { 90OSQLResult::State OSQLResult::state()const {
92 return m_state; 91 return m_state;
93} 92}
94void OSQLResult::setState( OSQLResult::State state ) { 93void OSQLResult::setState( OSQLResult::State state ) {
95 m_state = state; 94 m_state = state;
96} 95}
97OSQLError::ValueList OSQLResult::errors()const { 96OSQLError::ValueList OSQLResult::errors()const {
98 return m_error; 97 return m_error;
99} 98}
100void OSQLResult::setErrors( const OSQLError::ValueList& err ) { 99void OSQLResult::setErrors( const OSQLError::ValueList& err ) {
101 m_error = err; 100 m_error = err;
102} 101}
103OSQLResultItem::ValueList OSQLResult::results()const { 102OSQLResultItem::ValueList OSQLResult::results()const {
104 return m_list; 103 return m_list;
105} 104}
106void OSQLResult::setResults( const OSQLResultItem::ValueList& result ) { 105void OSQLResult::setResults( const OSQLResultItem::ValueList& result ) {
107 m_list = result; 106 m_list = result;
108} 107}
109OSQLResultItem OSQLResult::first() { 108OSQLResultItem OSQLResult::first() {
110 it = m_list.begin(); 109 it = m_list.begin();
111 return (*it); 110 return (*it);
112} 111}
113OSQLResultItem OSQLResult::next(){ 112OSQLResultItem OSQLResult::next(){
114 ++it; 113 ++it;
115 return (*it); 114 return (*it);
116} 115}
117bool OSQLResult::atEnd(){ 116bool OSQLResult::atEnd(){
118 if ( it == m_list.end() ) 117 if ( it == m_list.end() )
119 return true; 118 return true;
120 119
121 return false; 120 return false;
122} 121}
123OSQLResultItem::ValueList::ConstIterator OSQLResult::iterator()const { 122OSQLResultItem::ValueList::ConstIterator OSQLResult::iterator()const {
124 OSQLResultItem::ValueList::ConstIterator it; 123 OSQLResultItem::ValueList::ConstIterator it;
125 it = m_list.begin(); 124 it = m_list.begin();
126 return it; 125 return it;
127} 126}
diff --git a/libopie2/opiemm/osoundsystem.cpp b/libopie2/opiemm/osoundsystem.cpp
index ca63389..51e088c 100644
--- a/libopie2/opiemm/osoundsystem.cpp
+++ b/libopie2/opiemm/osoundsystem.cpp
@@ -1,314 +1,313 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3 3
4              (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 4              (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
5 =. 5 =.
6 .=l. 6 .=l.
7           .>+-= 7           .>+-=
8 _;:,     .>    :=|. This program is free software; you can 8 _;:,     .>    :=|. This program is free software; you can
9.> <`_,   >  .   <= redistribute it and/or modify it under 9.> <`_,   >  .   <= redistribute it and/or modify it under
10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
11.="- .-=="i,     .._ License as published by the Free Software 11.="- .-=="i,     .._ License as published by the Free Software
12 - .   .-<_>     .<> Foundation; either version 2 of the License, 12 - .   .-<_>     .<> Foundation; either version 2 of the License,
13     ._= =}       : or (at your option) any later version. 13     ._= =}       : or (at your option) any later version.
14    .%`+i>       _;_. 14    .%`+i>       _;_.
15    .i_,=:_.      -<s. This program is distributed in the hope that 15    .i_,=:_.      -<s. This program is distributed in the hope that
16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
17    : ..    .:,     . . . without even the implied warranty of 17    : ..    .:,     . . . without even the implied warranty of
18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
20..}^=.=       =       ; Library General Public License for more 20..}^=.=       =       ; Library General Public License for more
21++=   -.     .`     .: details. 21++=   -.     .`     .: details.
22 :     =  ...= . :.=- 22 :     =  ...= . :.=-
23 -.   .:....=;==+<; You should have received a copy of the GNU 23 -.   .:....=;==+<; You should have received a copy of the GNU
24  -_. . .   )=.  = Library General Public License along with 24  -_. . .   )=.  = Library General Public License along with
25    --        :-=` this library; see the file COPYING.LIB. 25    --        :-=` this library; see the file COPYING.LIB.
26 If not, write to the Free Software Foundation, 26 If not, write to the Free Software Foundation,
27 Inc., 59 Temple Place - Suite 330, 27 Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. 28 Boston, MA 02111-1307, USA.
29 29
30*/ 30*/
31 31
32#include <opie2/osoundsystem.h> 32#include <opie2/osoundsystem.h>
33#include <opie2/odebug.h> 33#include <opie2/odebug.h>
34 34
35#include <errno.h> 35#include <errno.h>
36#include <fcntl.h> 36#include <fcntl.h>
37#include <string.h> 37#include <string.h>
38#include <sys/ioctl.h> 38#include <sys/ioctl.h>
39#include <sys/types.h> 39#include <sys/types.h>
40#include <sys/soundcard.h> 40#include <sys/soundcard.h>
41#include <sys/stat.h> 41#include <sys/stat.h>
42 42
43#include <qstringlist.h>
44 43
45/*====================================================================================== 44/*======================================================================================
46 * OSoundSystem 45 * OSoundSystem
47 *======================================================================================*/ 46 *======================================================================================*/
48 47
49OSoundSystem* OSoundSystem::_instance = 0; 48OSoundSystem* OSoundSystem::_instance = 0;
50 49
51OSoundSystem::OSoundSystem() 50OSoundSystem::OSoundSystem()
52{ 51{
53 odebug << "OSoundSystem::OSoundSystem()" << oendl; 52 odebug << "OSoundSystem::OSoundSystem()" << oendl;
54 synchronize(); 53 synchronize();
55} 54}
56 55
57void OSoundSystem::synchronize() 56void OSoundSystem::synchronize()
58{ 57{
59 // gather available interfaces by inspecting /dev 58 // gather available interfaces by inspecting /dev
60 //FIXME: we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices 59 //FIXME: we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices
61 //FIXME: Use SIOCGIFCONF anway, because we can disable listing of aliased devices 60 //FIXME: Use SIOCGIFCONF anway, because we can disable listing of aliased devices
62 61
63 _interfaces.clear(); 62 _interfaces.clear();
64 _interfaces.insert( "soundcard", new OSoundCard( this, "soundcard" ) ); 63 _interfaces.insert( "soundcard", new OSoundCard( this, "soundcard" ) );
65 64
66 65
67 /* 66 /*
68 67
69 QString str; 68 QString str;
70 QFile f( "/dev/sound" ); 69 QFile f( "/dev/sound" );
71 bool hasFile = f.open( IO_ReadOnly ); 70 bool hasFile = f.open( IO_ReadOnly );
72 if ( !hasFile ) 71 if ( !hasFile )
73 { 72 {
74 odebug << "OSoundSystem: /dev/sound not existing. No sound devices available" << oendl; 73 odebug << "OSoundSystem: /dev/sound not existing. No sound devices available" << oendl;
75 return; 74 return;
76 } 75 }
77 QTextStream s( &f ); 76 QTextStream s( &f );
78 s.readLine(); 77 s.readLine();
79 s.readLine(); 78 s.readLine();
80 while ( !s.atEnd() ) 79 while ( !s.atEnd() )
81 { 80 {
82 s >> str; 81 s >> str;
83 str.truncate( str.find( ':' ) ); 82 str.truncate( str.find( ':' ) );
84 qDebug( "OSoundSystem: found interface '%s'", (const char*) str ); 83 qDebug( "OSoundSystem: found interface '%s'", (const char*) str );
85 OAudioInterface* iface; 84 OAudioInterface* iface;
86 iface = new OAudioInterface( this, (const char*) str ); 85 iface = new OAudioInterface( this, (const char*) str );
87 86
88 _interfaces.insert( str, iface ); 87 _interfaces.insert( str, iface );
89 s.readLine(); 88 s.readLine();
90 } 89 }
91*/ 90*/
92} 91}
93 92
94 93
95int OSoundSystem::count() const 94int OSoundSystem::count() const
96{ 95{
97 return _interfaces.count(); 96 return _interfaces.count();
98} 97}
99 98
100 99
101OSoundCard* OSoundSystem::card( const QString& iface ) const 100OSoundCard* OSoundSystem::card( const QString& iface ) const
102{ 101{
103 return _interfaces[iface]; 102 return _interfaces[iface];
104} 103}
105 104
106 105
107OSoundSystem* OSoundSystem::instance() 106OSoundSystem* OSoundSystem::instance()
108{ 107{
109 if ( !_instance ) _instance = new OSoundSystem(); 108 if ( !_instance ) _instance = new OSoundSystem();
110 return _instance; 109 return _instance;
111} 110}
112 111
113 112
114OSoundSystem::CardIterator OSoundSystem::iterator() const 113OSoundSystem::CardIterator OSoundSystem::iterator() const
115{ 114{
116 return OSoundSystem::CardIterator( _interfaces ); 115 return OSoundSystem::CardIterator( _interfaces );
117} 116}
118 117
119 118
120/*====================================================================================== 119/*======================================================================================
121 * OSoundCard 120 * OSoundCard
122 *======================================================================================*/ 121 *======================================================================================*/
123 122
124OSoundCard::OSoundCard( QObject* parent, const char* name ) 123OSoundCard::OSoundCard( QObject* parent, const char* name )
125 :QObject( parent, name ), _audio( 0 ), _mixer( 0 ) 124 :QObject( parent, name ), _audio( 0 ), _mixer( 0 )
126{ 125{
127 odebug << "OSoundCard::OSoundCard()" << oendl; 126 odebug << "OSoundCard::OSoundCard()" << oendl;
128 init(); 127 init();
129} 128}
130 129
131 130
132OSoundCard::~OSoundCard() 131OSoundCard::~OSoundCard()
133{ 132{
134} 133}
135 134
136 135
137void OSoundCard::init() 136void OSoundCard::init()
138{ 137{
139 _audio = new OAudioInterface( this, "/dev/dsp" ); 138 _audio = new OAudioInterface( this, "/dev/dsp" );
140 _mixer = new OMixerInterface( this, "/dev/mixer" ); 139 _mixer = new OMixerInterface( this, "/dev/mixer" );
141} 140}
142 141
143 142
144/*====================================================================================== 143/*======================================================================================
145 * OAudioInterface 144 * OAudioInterface
146 *======================================================================================*/ 145 *======================================================================================*/
147 146
148OAudioInterface::OAudioInterface( QObject* parent, const char* name ) 147OAudioInterface::OAudioInterface( QObject* parent, const char* name )
149 :QObject( parent, name ) 148 :QObject( parent, name )
150{ 149{
151 odebug << "OAudioInterface::OAudioInterface()" << oendl; 150 odebug << "OAudioInterface::OAudioInterface()" << oendl;
152 init(); 151 init();
153} 152}
154 153
155 154
156OAudioInterface::~OAudioInterface() 155OAudioInterface::~OAudioInterface()
157{ 156{
158} 157}
159 158
160 159
161void OAudioInterface::init() 160void OAudioInterface::init()
162{ 161{
163 162
164 163
165} 164}
166 165
167 166
168/*====================================================================================== 167/*======================================================================================
169 * OMixerInterface 168 * OMixerInterface
170 *======================================================================================*/ 169 *======================================================================================*/
171 170
172OMixerInterface::OMixerInterface( QObject* parent, const char* name ) 171OMixerInterface::OMixerInterface( QObject* parent, const char* name )
173 :QObject( parent, name ) 172 :QObject( parent, name )
174{ 173{
175 odebug << "OMixerInterface::OMixerInterface()" << oendl; 174 odebug << "OMixerInterface::OMixerInterface()" << oendl;
176 init(); 175 init();
177} 176}
178 177
179 178
180OMixerInterface::~OMixerInterface() 179OMixerInterface::~OMixerInterface()
181{ 180{
182} 181}
183 182
184 183
185void OMixerInterface::init() 184void OMixerInterface::init()
186{ 185{
187 // open the device 186 // open the device
188 _fd = ::open( name(), O_RDWR ); 187 _fd = ::open( name(), O_RDWR );
189 if ( _fd == -1 ) 188 if ( _fd == -1 )
190 { 189 {
191 owarn << "OMixerInterface::init(): Can't open mixer." << oendl; 190 owarn << "OMixerInterface::init(): Can't open mixer." << oendl;
192 return; 191 return;
193 } 192 }
194 193
195 // construct the device capabilities 194 // construct the device capabilities
196 int devmask = 0; 195 int devmask = 0;
197 if ( ioctl( _fd, SOUND_MIXER_READ_DEVMASK, &devmask ) != -1 ) 196 if ( ioctl( _fd, SOUND_MIXER_READ_DEVMASK, &devmask ) != -1 )
198 { 197 {
199 if ( devmask & ( 1 << SOUND_MIXER_VOLUME ) ) _channels.insert( "PlayVolume", SOUND_MIXER_VOLUME ); 198 if ( devmask & ( 1 << SOUND_MIXER_VOLUME ) ) _channels.insert( "PlayVolume", SOUND_MIXER_VOLUME );
200 if ( devmask & ( 1 << SOUND_MIXER_BASS ) ) _channels.insert( "PlayBass", SOUND_MIXER_BASS ); 199 if ( devmask & ( 1 << SOUND_MIXER_BASS ) ) _channels.insert( "PlayBass", SOUND_MIXER_BASS );
201 if ( devmask & ( 1 << SOUND_MIXER_TREBLE ) ) _channels.insert( "PlayTreble", SOUND_MIXER_TREBLE ); 200 if ( devmask & ( 1 << SOUND_MIXER_TREBLE ) ) _channels.insert( "PlayTreble", SOUND_MIXER_TREBLE );
202 if ( devmask & ( 1 << SOUND_MIXER_SYNTH ) ) _channels.insert( "PlaySynth", SOUND_MIXER_SYNTH ); 201 if ( devmask & ( 1 << SOUND_MIXER_SYNTH ) ) _channels.insert( "PlaySynth", SOUND_MIXER_SYNTH );
203 if ( devmask & ( 1 << SOUND_MIXER_PCM ) ) _channels.insert( "PlayPCM", SOUND_MIXER_PCM ); 202 if ( devmask & ( 1 << SOUND_MIXER_PCM ) ) _channels.insert( "PlayPCM", SOUND_MIXER_PCM );
204 if ( devmask & ( 1 << SOUND_MIXER_SPEAKER ) ) _channels.insert( "PlaySpeaker", SOUND_MIXER_SPEAKER ); 203 if ( devmask & ( 1 << SOUND_MIXER_SPEAKER ) ) _channels.insert( "PlaySpeaker", SOUND_MIXER_SPEAKER );
205 if ( devmask & ( 1 << SOUND_MIXER_LINE ) ) _channels.insert( "PlayLine", SOUND_MIXER_LINE ); 204 if ( devmask & ( 1 << SOUND_MIXER_LINE ) ) _channels.insert( "PlayLine", SOUND_MIXER_LINE );
206 if ( devmask & ( 1 << SOUND_MIXER_MIC ) ) _channels.insert( "PlayMic", SOUND_MIXER_MIC ); 205 if ( devmask & ( 1 << SOUND_MIXER_MIC ) ) _channels.insert( "PlayMic", SOUND_MIXER_MIC );
207 if ( devmask & ( 1 << SOUND_MIXER_CD ) ) _channels.insert( "PlayCD", SOUND_MIXER_CD ); 206 if ( devmask & ( 1 << SOUND_MIXER_CD ) ) _channels.insert( "PlayCD", SOUND_MIXER_CD );
208 if ( devmask & ( 1 << SOUND_MIXER_IMIX ) ) _channels.insert( "PlayInputMix", SOUND_MIXER_IMIX ); 207 if ( devmask & ( 1 << SOUND_MIXER_IMIX ) ) _channels.insert( "PlayInputMix", SOUND_MIXER_IMIX );
209 if ( devmask & ( 1 << SOUND_MIXER_ALTPCM ) ) _channels.insert( "PlayAltPCM", SOUND_MIXER_ALTPCM ); 208 if ( devmask & ( 1 << SOUND_MIXER_ALTPCM ) ) _channels.insert( "PlayAltPCM", SOUND_MIXER_ALTPCM );
210 if ( devmask & ( 1 << SOUND_MIXER_RECLEV ) ) _channels.insert( "PlayRecord", SOUND_MIXER_RECLEV ); 209 if ( devmask & ( 1 << SOUND_MIXER_RECLEV ) ) _channels.insert( "PlayRecord", SOUND_MIXER_RECLEV );
211 if ( devmask & ( 1 << SOUND_MIXER_IGAIN ) ) _channels.insert( "PlayInputGain", SOUND_MIXER_IGAIN ); 210 if ( devmask & ( 1 << SOUND_MIXER_IGAIN ) ) _channels.insert( "PlayInputGain", SOUND_MIXER_IGAIN );
212 if ( devmask & ( 1 << SOUND_MIXER_OGAIN ) ) _channels.insert( "PlayOutputGain", SOUND_MIXER_OGAIN ); 211 if ( devmask & ( 1 << SOUND_MIXER_OGAIN ) ) _channels.insert( "PlayOutputGain", SOUND_MIXER_OGAIN );
213 //odebug << "devmask available and constructed." << oendl; 212 //odebug << "devmask available and constructed." << oendl;
214 } 213 }
215 214
216 devmask = 0; 215 devmask = 0;
217 if ( ioctl( _fd, SOUND_MIXER_READ_RECMASK, &devmask ) != -1 ) 216 if ( ioctl( _fd, SOUND_MIXER_READ_RECMASK, &devmask ) != -1 )
218 { 217 {
219 if ( devmask & ( 1 << SOUND_MIXER_VOLUME ) ) _channels.insert( "RecVolume", SOUND_MIXER_VOLUME ); 218 if ( devmask & ( 1 << SOUND_MIXER_VOLUME ) ) _channels.insert( "RecVolume", SOUND_MIXER_VOLUME );
220 if ( devmask & ( 1 << SOUND_MIXER_BASS ) ) _channels.insert( "RecBass", SOUND_MIXER_BASS ); 219 if ( devmask & ( 1 << SOUND_MIXER_BASS ) ) _channels.insert( "RecBass", SOUND_MIXER_BASS );
221 if ( devmask & ( 1 << SOUND_MIXER_TREBLE ) ) _channels.insert( "RecTreble", SOUND_MIXER_TREBLE ); 220 if ( devmask & ( 1 << SOUND_MIXER_TREBLE ) ) _channels.insert( "RecTreble", SOUND_MIXER_TREBLE );
222 if ( devmask & ( 1 << SOUND_MIXER_SYNTH ) ) _channels.insert( "RecSynth", SOUND_MIXER_SYNTH ); 221 if ( devmask & ( 1 << SOUND_MIXER_SYNTH ) ) _channels.insert( "RecSynth", SOUND_MIXER_SYNTH );
223 if ( devmask & ( 1 << SOUND_MIXER_PCM ) ) _channels.insert( "RecPCM", SOUND_MIXER_PCM ); 222 if ( devmask & ( 1 << SOUND_MIXER_PCM ) ) _channels.insert( "RecPCM", SOUND_MIXER_PCM );
224 if ( devmask & ( 1 << SOUND_MIXER_SPEAKER ) ) _channels.insert( "RecSpeaker", SOUND_MIXER_SPEAKER ); 223 if ( devmask & ( 1 << SOUND_MIXER_SPEAKER ) ) _channels.insert( "RecSpeaker", SOUND_MIXER_SPEAKER );
225 if ( devmask & ( 1 << SOUND_MIXER_LINE ) ) _channels.insert( "RecLine", SOUND_MIXER_LINE ); 224 if ( devmask & ( 1 << SOUND_MIXER_LINE ) ) _channels.insert( "RecLine", SOUND_MIXER_LINE );
226 if ( devmask & ( 1 << SOUND_MIXER_MIC ) ) _channels.insert( "RecMic", SOUND_MIXER_MIC ); 225 if ( devmask & ( 1 << SOUND_MIXER_MIC ) ) _channels.insert( "RecMic", SOUND_MIXER_MIC );
227 if ( devmask & ( 1 << SOUND_MIXER_CD ) ) _channels.insert( "RecCD", SOUND_MIXER_CD ); 226 if ( devmask & ( 1 << SOUND_MIXER_CD ) ) _channels.insert( "RecCD", SOUND_MIXER_CD );
228 if ( devmask & ( 1 << SOUND_MIXER_IMIX ) ) _channels.insert( "RecInputMix", SOUND_MIXER_IMIX ); 227 if ( devmask & ( 1 << SOUND_MIXER_IMIX ) ) _channels.insert( "RecInputMix", SOUND_MIXER_IMIX );
229 if ( devmask & ( 1 << SOUND_MIXER_ALTPCM ) ) _channels.insert( "RecAltPCM", SOUND_MIXER_ALTPCM ); 228 if ( devmask & ( 1 << SOUND_MIXER_ALTPCM ) ) _channels.insert( "RecAltPCM", SOUND_MIXER_ALTPCM );
230 if ( devmask & ( 1 << SOUND_MIXER_RECLEV ) ) _channels.insert( "RecRecord", SOUND_MIXER_RECLEV ); 229 if ( devmask & ( 1 << SOUND_MIXER_RECLEV ) ) _channels.insert( "RecRecord", SOUND_MIXER_RECLEV );
231 if ( devmask & ( 1 << SOUND_MIXER_IGAIN ) ) _channels.insert( "RecInputGain", SOUND_MIXER_IGAIN ); 230 if ( devmask & ( 1 << SOUND_MIXER_IGAIN ) ) _channels.insert( "RecInputGain", SOUND_MIXER_IGAIN );
232 if ( devmask & ( 1 << SOUND_MIXER_OGAIN ) ) _channels.insert( "RecOutputGain", SOUND_MIXER_OGAIN ); 231 if ( devmask & ( 1 << SOUND_MIXER_OGAIN ) ) _channels.insert( "RecOutputGain", SOUND_MIXER_OGAIN );
233 //odebug << "recmask available and constructed." << oendl; 232 //odebug << "recmask available and constructed." << oendl;
234 } 233 }
235 234
236/* ChannelIterator it; 235/* ChannelIterator it;
237 for ( it = _channels.begin(); it != _channels.end(); ++it ) 236 for ( it = _channels.begin(); it != _channels.end(); ++it )
238 { 237 {
239 qDebug( "Channel %s available (bit %d)", (const char*) it.key(), it.data() ); 238 qDebug( "Channel %s available (bit %d)", (const char*) it.key(), it.data() );
240 qDebug( " +--- Volume: %02d | %02d", volume( it.key() ) & 0xff, volume( it.key() ) >> 8 ); 239 qDebug( " +--- Volume: %02d | %02d", volume( it.key() ) & 0xff, volume( it.key() ) >> 8 );
241 } 240 }
242*/ 241*/
243} 242}
244 243
245QStringList OMixerInterface::allChannels() const 244QStringList OMixerInterface::allChannels() const
246{ 245{
247 ChannelIterator it = _channels.begin(); 246 ChannelIterator it = _channels.begin();
248 QStringList channels; 247 QStringList channels;
249 while ( it != _channels.end() ) 248 while ( it != _channels.end() )
250 { 249 {
251 channels += it.key(); 250 channels += it.key();
252 it++; 251 it++;
253 } 252 }
254 return channels; 253 return channels;
255} 254}
256 255
257 256
258QStringList OMixerInterface::recChannels() const 257QStringList OMixerInterface::recChannels() const
259{ 258{
260 owarn << "NYI" << oendl; 259 owarn << "NYI" << oendl;
261} 260}
262 261
263 262
264QStringList OMixerInterface::playChannels() const 263QStringList OMixerInterface::playChannels() const
265{ 264{
266 owarn << "NYI" << oendl; 265 owarn << "NYI" << oendl;
267} 266}
268 267
269 268
270bool OMixerInterface::hasChannel( const QString& channel ) 269bool OMixerInterface::hasChannel( const QString& channel )
271{ 270{
272 return _channels.contains( channel ); 271 return _channels.contains( channel );
273} 272}
274 273
275 274
276void OMixerInterface::setVolume( const QString& channel, int left, int right ) 275void OMixerInterface::setVolume( const QString& channel, int left, int right )
277{ 276{
278 int volume = left; 277 int volume = left;
279 volume |= ( right == -1 ) ? left << 8 : right << 8; 278 volume |= ( right == -1 ) ? left << 8 : right << 8;
280 279
281 if ( _channels.contains( channel ) ) 280 if ( _channels.contains( channel ) )
282 { 281 {
283 int result = ioctl( _fd, MIXER_WRITE( _channels[channel] ), &volume ); 282 int result = ioctl( _fd, MIXER_WRITE( _channels[channel] ), &volume );
284 if ( result == -1 ) 283 if ( result == -1 )
285 { 284 {
286 owarn << "Can't set volume: " << strerror( errno ) << oendl; 285 owarn << "Can't set volume: " << strerror( errno ) << oendl;
287 } 286 }
288 else 287 else
289 { 288 {
290 if ( result & 0xff != left ) 289 if ( result & 0xff != left )
291 { 290 {
292 owarn << "Device adjusted volume from " << left << " to " << (result & 0xff) << oendl; 291 owarn << "Device adjusted volume from " << left << " to " << (result & 0xff) << oendl;
293 } 292 }
294 } 293 }
295 } 294 }
296} 295}
297 296
298 297
299int OMixerInterface::volume( const QString& channel ) const 298int OMixerInterface::volume( const QString& channel ) const
300{ 299{
301 int volume; 300 int volume;
302 301
303 if ( _channels.contains( channel ) ) 302 if ( _channels.contains( channel ) )
304 { 303 {
305 if ( ioctl( _fd, MIXER_READ( _channels[channel] ), &volume ) == -1 ) 304 if ( ioctl( _fd, MIXER_READ( _channels[channel] ), &volume ) == -1 )
306 { 305 {
307 owarn << "Can't get volume: " << strerror( errno ) << oendl; 306 owarn << "Can't get volume: " << strerror( errno ) << oendl;
308 } 307 }
309 else return volume; 308 else return volume;
310 } 309 }
311 return -1; 310 return -1;
312} 311}
313 312
314 313
diff --git a/libopie2/opienet/omanufacturerdb.cpp b/libopie2/opienet/omanufacturerdb.cpp
index 2da549c..b93b752 100644
--- a/libopie2/opienet/omanufacturerdb.cpp
+++ b/libopie2/opienet/omanufacturerdb.cpp
@@ -1,136 +1,135 @@
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@Vanille.de> 3              (C) 2003 Michael 'Mickey' Lauer <mickey@Vanille.de>
4 =. 4 =.
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 30
31#include "omanufacturerdb.h" 31#include "omanufacturerdb.h"
32 32
33#define OPIE_IMPROVE_GUI_LATENCY 1 33#define OPIE_IMPROVE_GUI_LATENCY 1
34 34
35/* OPIE */ 35/* OPIE */
36#include <opie2/odebug.h> 36#include <opie2/odebug.h>
37#ifdef OPIE_IMPROVE_GUI_LATENCY 37#ifdef OPIE_IMPROVE_GUI_LATENCY
38#include <qpe/global.h> 38#include <qpe/global.h>
39#endif 39#endif
40 40
41/* QT */ 41/* QT */
42#include <qapplication.h> 42#include <qapplication.h>
43#include <qstring.h>
44#include <qfile.h> 43#include <qfile.h>
45#include <qtextstream.h> 44#include <qtextstream.h>
46 45
47OManufacturerDB* OManufacturerDB::_instance = 0; 46OManufacturerDB* OManufacturerDB::_instance = 0;
48 47
49OManufacturerDB* OManufacturerDB::instance() 48OManufacturerDB* OManufacturerDB::instance()
50{ 49{
51 if ( !OManufacturerDB::_instance ) 50 if ( !OManufacturerDB::_instance )
52 { 51 {
53 odebug << "OManufacturerDB::instance(): creating OManufacturerDB..." << oendl; 52 odebug << "OManufacturerDB::instance(): creating OManufacturerDB..." << oendl;
54 _instance = new OManufacturerDB(); 53 _instance = new OManufacturerDB();
55 } 54 }
56 return _instance; 55 return _instance;
57} 56}
58 57
59 58
60OManufacturerDB::OManufacturerDB() 59OManufacturerDB::OManufacturerDB()
61{ 60{
62 #ifdef OPIE_IMPROVE_GUI_LATENCY 61 #ifdef OPIE_IMPROVE_GUI_LATENCY
63 Global::statusMessage( "Reading Manufacturers..." ); 62 Global::statusMessage( "Reading Manufacturers..." );
64 #endif 63 #endif
65 QString filename( "/etc/manufacturers" ); 64 QString filename( "/etc/manufacturers" );
66 odebug << "OManufacturerDB: trying to read " << filename << oendl; 65 odebug << "OManufacturerDB: trying to read " << filename << oendl;
67 if ( !QFile::exists( filename ) ) 66 if ( !QFile::exists( filename ) )
68 { 67 {
69 filename = "/opt/QtPalmtop/etc/manufacturers"; 68 filename = "/opt/QtPalmtop/etc/manufacturers";
70 odebug << "OManufacturerDB: trying to read " << filename << oendl; 69 odebug << "OManufacturerDB: trying to read " << filename << oendl;
71 if ( !QFile::exists( filename ) ) 70 if ( !QFile::exists( filename ) )
72 { 71 {
73 filename = "/usr/share/wellenreiter/manufacturers"; 72 filename = "/usr/share/wellenreiter/manufacturers";
74 odebug << "OManufacturerDB: trying to read " << filename << oendl; 73 odebug << "OManufacturerDB: trying to read " << filename << oendl;
75 } 74 }
76 } 75 }
77 76
78 QFile file( filename ); 77 QFile file( filename );
79 bool hasFile = file.open( IO_ReadOnly ); 78 bool hasFile = file.open( IO_ReadOnly );
80 if (!hasFile) 79 if (!hasFile)
81 { 80 {
82 owarn << "OManufacturerDB: no valid manufacturer list found." << oendl; 81 owarn << "OManufacturerDB: no valid manufacturer list found." << oendl;
83 } 82 }
84 else 83 else
85 { 84 {
86 odebug << "OManufacturerDB: found manufacturer list in " << filename << oendl; 85 odebug << "OManufacturerDB: found manufacturer list in " << filename << oendl;
87 QTextStream s( &file ); 86 QTextStream s( &file );
88 QString addr; 87 QString addr;
89 QString manu; 88 QString manu;
90 QString extManu; 89 QString extManu;
91 #ifdef OPIE_IMPROVE_GUI_LATENCY 90 #ifdef OPIE_IMPROVE_GUI_LATENCY
92 int counter = 0; 91 int counter = 0;
93 #endif 92 #endif
94 while (!s.atEnd()) 93 while (!s.atEnd())
95 { 94 {
96 s >> addr; 95 s >> addr;
97 s >> manu; 96 s >> manu;
98 s >> extManu; 97 s >> extManu;
99 98
100 manufacturers.insert( addr, manu ); 99 manufacturers.insert( addr, manu );
101 manufacturersExt.insert( addr, extManu ); 100 manufacturersExt.insert( addr, extManu );
102 // odebug << "OmanufacturerDB: parse '" << addr << "' as '" << manu << "' (" << extManu << ")" << oendl; 101 // odebug << "OmanufacturerDB: parse '" << addr << "' as '" << manu << "' (" << extManu << ")" << oendl;
103 #ifdef OPIE_IMPROVE_GUI_LATENCY 102 #ifdef OPIE_IMPROVE_GUI_LATENCY
104 counter++; 103 counter++;
105 if ( counter == 50 ) 104 if ( counter == 50 )
106 { 105 {
107 qApp->processEvents(); 106 qApp->processEvents();
108 counter = 0; 107 counter = 0;
109 } 108 }
110 #endif 109 #endif
111 } 110 }
112 odebug << "OManufacturerDB: manufacturer list completed." << oendl; 111 odebug << "OManufacturerDB: manufacturer list completed." << oendl;
113 #ifdef OPIE_IMPROVE_GUI_LATENCY 112 #ifdef OPIE_IMPROVE_GUI_LATENCY
114 Global::statusMessage( "Manufacturers Complete..." ); 113 Global::statusMessage( "Manufacturers Complete..." );
115 #endif 114 #endif
116 } 115 }
117} 116}
118 117
119 118
120OManufacturerDB::~OManufacturerDB() 119OManufacturerDB::~OManufacturerDB()
121{ 120{
122} 121}
123 122
124 123
125const QString& OManufacturerDB::lookup( const QString& macaddr ) const 124const QString& OManufacturerDB::lookup( const QString& macaddr ) const
126{ 125{
127 return manufacturers[macaddr.upper().left(8)]; 126 return manufacturers[macaddr.upper().left(8)];
128} 127}
129 128
130 129
131const QString& OManufacturerDB::lookupExt( const QString& macaddr ) const 130const QString& OManufacturerDB::lookupExt( const QString& macaddr ) const
132{ 131{
133 QMap<QString,QString>::ConstIterator it = manufacturersExt.find( macaddr.upper().left(8) ); 132 QMap<QString,QString>::ConstIterator it = manufacturersExt.find( macaddr.upper().left(8) );
134 return it == manufacturersExt.end() ? lookup( macaddr ) : *it; 133 return it == manufacturersExt.end() ? lookup( macaddr ) : *it;
135} 134}
136 135
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp
index 0adba68..5d92b8f 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp
+++ b/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp
@@ -1,751 +1,749 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de) 3 Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de)
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 4 =. Copyright (C) The Opie Team <opie-devel@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 * XML Backend for the OPIE-Contact Database. 30 * XML Backend for the OPIE-Contact Database.
31 */ 31 */
32 32
33#include <opie2/ocontactaccessbackend_xml.h> 33#include <opie2/ocontactaccessbackend_xml.h>
34 34
35#include <qasciidict.h> 35#include <qasciidict.h>
36#include <qdatetime.h>
37#include <qfile.h> 36#include <qfile.h>
38#include <qfileinfo.h> 37#include <qfileinfo.h>
39#include <qregexp.h> 38#include <qregexp.h>
40#include <qarray.h> 39#include <qarray.h>
41#include <qmap.h> 40#include <qmap.h>
42#include <qdatetime.h>
43 41
44#include <qpe/global.h> 42#include <qpe/global.h>
45 43
46#include <opie2/xmltree.h> 44#include <opie2/xmltree.h>
47#include <opie2/ocontactaccessbackend.h> 45#include <opie2/ocontactaccessbackend.h>
48#include <opie2/ocontactaccess.h> 46#include <opie2/ocontactaccess.h>
49 47
50#include <stdlib.h> 48#include <stdlib.h>
51#include <errno.h> 49#include <errno.h>
52 50
53using namespace Opie; 51using namespace Opie;
54 52
55 53
56namespace Opie { 54namespace Opie {
57OPimContactAccessBackend_XML::OPimContactAccessBackend_XML ( const QString& appname, const QString& filename ): 55OPimContactAccessBackend_XML::OPimContactAccessBackend_XML ( const QString& appname, const QString& filename ):
58 m_changed( false ) 56 m_changed( false )
59{ 57{
60 // Just m_contactlist should call delete if an entry 58 // Just m_contactlist should call delete if an entry
61 // is removed. 59 // is removed.
62 m_contactList.setAutoDelete( true ); 60 m_contactList.setAutoDelete( true );
63 m_uidToContact.setAutoDelete( false ); 61 m_uidToContact.setAutoDelete( false );
64 62
65 m_appName = appname; 63 m_appName = appname;
66 64
67 /* Set journalfile name ... */ 65 /* Set journalfile name ... */
68 m_journalName = getenv("HOME"); 66 m_journalName = getenv("HOME");
69 m_journalName +="/.abjournal" + appname; 67 m_journalName +="/.abjournal" + appname;
70 68
71 /* Expecting to access the default filename if nothing else is set */ 69 /* Expecting to access the default filename if nothing else is set */
72 if ( filename.isEmpty() ){ 70 if ( filename.isEmpty() ){
73 m_fileName = Global::applicationFileName( "addressbook","addressbook.xml" ); 71 m_fileName = Global::applicationFileName( "addressbook","addressbook.xml" );
74 } else 72 } else
75 m_fileName = filename; 73 m_fileName = filename;
76 74
77 /* Load Database now */ 75 /* Load Database now */
78 load (); 76 load ();
79} 77}
80 78
81bool OPimContactAccessBackend_XML::save() 79bool OPimContactAccessBackend_XML::save()
82{ 80{
83 81
84 if ( !m_changed ) 82 if ( !m_changed )
85 return true; 83 return true;
86 84
87 QString strNewFile = m_fileName + ".new"; 85 QString strNewFile = m_fileName + ".new";
88 QFile f( strNewFile ); 86 QFile f( strNewFile );
89 if ( !f.open( IO_WriteOnly|IO_Raw ) ) 87 if ( !f.open( IO_WriteOnly|IO_Raw ) )
90 return false; 88 return false;
91 89
92 int total_written; 90 int total_written;
93 int idx_offset = 0; 91 int idx_offset = 0;
94 QString out; 92 QString out;
95 93
96 // Write Header 94 // Write Header
97 out = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>\n" 95 out = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>\n"
98 " <Groups>\n" 96 " <Groups>\n"
99 " </Groups>\n" 97 " </Groups>\n"
100 " <Contacts>\n"; 98 " <Contacts>\n";
101 QCString cstr = out.utf8(); 99 QCString cstr = out.utf8();
102 f.writeBlock( cstr.data(), cstr.length() ); 100 f.writeBlock( cstr.data(), cstr.length() );
103 idx_offset += cstr.length(); 101 idx_offset += cstr.length();
104 out = ""; 102 out = "";
105 103
106 // Write all contacts 104 // Write all contacts
107 QListIterator<OPimContact> it( m_contactList ); 105 QListIterator<OPimContact> it( m_contactList );
108 for ( ; it.current(); ++it ) { 106 for ( ; it.current(); ++it ) {
109 // qWarning(" Uid %d at Offset: %x", (*it)->uid(), idx_offset ); 107 // qWarning(" Uid %d at Offset: %x", (*it)->uid(), idx_offset );
110 out += "<Contact "; 108 out += "<Contact ";
111 (*it)->save( out ); 109 (*it)->save( out );
112 out += "/>\n"; 110 out += "/>\n";
113 cstr = out.utf8(); 111 cstr = out.utf8();
114 total_written = f.writeBlock( cstr.data(), cstr.length() ); 112 total_written = f.writeBlock( cstr.data(), cstr.length() );
115 idx_offset += cstr.length(); 113 idx_offset += cstr.length();
116 if ( total_written != int(cstr.length()) ) { 114 if ( total_written != int(cstr.length()) ) {
117 f.close(); 115 f.close();
118 QFile::remove( strNewFile ); 116 QFile::remove( strNewFile );
119 return false; 117 return false;
120 } 118 }
121 out = ""; 119 out = "";
122 } 120 }
123 out += " </Contacts>\n</AddressBook>\n"; 121 out += " </Contacts>\n</AddressBook>\n";
124 122
125 // Write Footer 123 // Write Footer
126 cstr = out.utf8(); 124 cstr = out.utf8();
127 total_written = f.writeBlock( cstr.data(), cstr.length() ); 125 total_written = f.writeBlock( cstr.data(), cstr.length() );
128 if ( total_written != int( cstr.length() ) ) { 126 if ( total_written != int( cstr.length() ) ) {
129 f.close(); 127 f.close();
130 QFile::remove( strNewFile ); 128 QFile::remove( strNewFile );
131 return false; 129 return false;
132 } 130 }
133 f.close(); 131 f.close();
134 132
135 // move the file over, I'm just going to use the system call 133 // move the file over, I'm just going to use the system call
136 // because, I don't feel like using QDir. 134 // because, I don't feel like using QDir.
137 if ( ::rename( strNewFile.latin1(), m_fileName.latin1() ) < 0 ) { 135 if ( ::rename( strNewFile.latin1(), m_fileName.latin1() ) < 0 ) {
138 qWarning( "problem renaming file %s to %s, errno: %d", 136 qWarning( "problem renaming file %s to %s, errno: %d",
139 strNewFile.latin1(), m_journalName.latin1(), errno ); 137 strNewFile.latin1(), m_journalName.latin1(), errno );
140 // remove the tmp file... 138 // remove the tmp file...
141 QFile::remove( strNewFile ); 139 QFile::remove( strNewFile );
142 } 140 }
143 141
144 /* The journalfile should be removed now... */ 142 /* The journalfile should be removed now... */
145 removeJournal(); 143 removeJournal();
146 144
147 m_changed = false; 145 m_changed = false;
148 return true; 146 return true;
149} 147}
150 148
151bool OPimContactAccessBackend_XML::load () 149bool OPimContactAccessBackend_XML::load ()
152{ 150{
153 m_contactList.clear(); 151 m_contactList.clear();
154 m_uidToContact.clear(); 152 m_uidToContact.clear();
155 153
156 /* Load XML-File and journal if it exists */ 154 /* Load XML-File and journal if it exists */
157 if ( !load ( m_fileName, false ) ) 155 if ( !load ( m_fileName, false ) )
158 return false; 156 return false;
159 /* The returncode of the journalfile is ignored due to the 157 /* The returncode of the journalfile is ignored due to the
160 * fact that it does not exist when this class is instantiated ! 158 * fact that it does not exist when this class is instantiated !
161 * But there may such a file exist, if the application crashed. 159 * But there may such a file exist, if the application crashed.
162 * Therefore we try to load it to get the changes before the # 160 * Therefore we try to load it to get the changes before the #
163 * crash happened... 161 * crash happened...
164 */ 162 */
165 load (m_journalName, true); 163 load (m_journalName, true);
166 164
167 return true; 165 return true;
168} 166}
169 167
170void OPimContactAccessBackend_XML::clear () 168void OPimContactAccessBackend_XML::clear ()
171{ 169{
172 m_contactList.clear(); 170 m_contactList.clear();
173 m_uidToContact.clear(); 171 m_uidToContact.clear();
174 172
175 m_changed = false; 173 m_changed = false;
176} 174}
177 175
178bool OPimContactAccessBackend_XML::wasChangedExternally() 176bool OPimContactAccessBackend_XML::wasChangedExternally()
179{ 177{
180 QFileInfo fi( m_fileName ); 178 QFileInfo fi( m_fileName );
181 179
182 QDateTime lastmod = fi.lastModified (); 180 QDateTime lastmod = fi.lastModified ();
183 181
184 return (lastmod != m_readtime); 182 return (lastmod != m_readtime);
185} 183}
186 184
187QArray<int> OPimContactAccessBackend_XML::allRecords() const 185QArray<int> OPimContactAccessBackend_XML::allRecords() const
188{ 186{
189 QArray<int> uid_list( m_contactList.count() ); 187 QArray<int> uid_list( m_contactList.count() );
190 188
191 uint counter = 0; 189 uint counter = 0;
192 QListIterator<OPimContact> it( m_contactList ); 190 QListIterator<OPimContact> it( m_contactList );
193 for( ; it.current(); ++it ){ 191 for( ; it.current(); ++it ){
194 uid_list[counter++] = (*it)->uid(); 192 uid_list[counter++] = (*it)->uid();
195 } 193 }
196 194
197 return ( uid_list ); 195 return ( uid_list );
198} 196}
199 197
200OPimContact OPimContactAccessBackend_XML::find ( int uid ) const 198OPimContact OPimContactAccessBackend_XML::find ( int uid ) const
201{ 199{
202 OPimContact foundContact; //Create empty contact 200 OPimContact foundContact; //Create empty contact
203 201
204 OPimContact* found = m_uidToContact.find( QString().setNum( uid ) ); 202 OPimContact* found = m_uidToContact.find( QString().setNum( uid ) );
205 203
206 if ( found ){ 204 if ( found ){
207 foundContact = *found; 205 foundContact = *found;
208 } 206 }
209 207
210 return ( foundContact ); 208 return ( foundContact );
211} 209}
212 210
213QArray<int> OPimContactAccessBackend_XML::queryByExample ( const OPimContact &query, int settings, 211QArray<int> OPimContactAccessBackend_XML::queryByExample ( const OPimContact &query, int settings,
214 const QDateTime& d ) 212 const QDateTime& d )
215{ 213{
216 214
217 QArray<int> m_currentQuery( m_contactList.count() ); 215 QArray<int> m_currentQuery( m_contactList.count() );
218 QListIterator<OPimContact> it( m_contactList ); 216 QListIterator<OPimContact> it( m_contactList );
219 uint arraycounter = 0; 217 uint arraycounter = 0;
220 218
221 for( ; it.current(); ++it ){ 219 for( ; it.current(); ++it ){
222 /* Search all fields and compare them with query object. Store them into list 220 /* Search all fields and compare them with query object. Store them into list
223 * if all fields matches. 221 * if all fields matches.
224 */ 222 */
225 QDate* queryDate = 0l; 223 QDate* queryDate = 0l;
226 QDate* checkDate = 0l; 224 QDate* checkDate = 0l;
227 bool allcorrect = true; 225 bool allcorrect = true;
228 for ( int i = 0; i < Qtopia::Groups; i++ ) { 226 for ( int i = 0; i < Qtopia::Groups; i++ ) {
229 // Birthday and anniversary are special nonstring fields and should 227 // Birthday and anniversary are special nonstring fields and should
230 // be handled specially 228 // be handled specially
231 switch ( i ){ 229 switch ( i ){
232 case Qtopia::Birthday: 230 case Qtopia::Birthday:
233 queryDate = new QDate( query.birthday() ); 231 queryDate = new QDate( query.birthday() );
234 checkDate = new QDate( (*it)->birthday() ); 232 checkDate = new QDate( (*it)->birthday() );
235 case Qtopia::Anniversary: 233 case Qtopia::Anniversary:
236 if ( queryDate == 0l ){ 234 if ( queryDate == 0l ){
237 queryDate = new QDate( query.anniversary() ); 235 queryDate = new QDate( query.anniversary() );
238 checkDate = new QDate( (*it)->anniversary() ); 236 checkDate = new QDate( (*it)->anniversary() );
239 } 237 }
240 238
241 if ( queryDate->isValid() ){ 239 if ( queryDate->isValid() ){
242 if( checkDate->isValid() ){ 240 if( checkDate->isValid() ){
243 if ( settings & OPimContactAccess::DateYear ){ 241 if ( settings & OPimContactAccess::DateYear ){
244 if ( queryDate->year() != checkDate->year() ) 242 if ( queryDate->year() != checkDate->year() )
245 allcorrect = false; 243 allcorrect = false;
246 } 244 }
247 if ( settings & OPimContactAccess::DateMonth ){ 245 if ( settings & OPimContactAccess::DateMonth ){
248 if ( queryDate->month() != checkDate->month() ) 246 if ( queryDate->month() != checkDate->month() )
249 allcorrect = false; 247 allcorrect = false;
250 } 248 }
251 if ( settings & OPimContactAccess::DateDay ){ 249 if ( settings & OPimContactAccess::DateDay ){
252 if ( queryDate->day() != checkDate->day() ) 250 if ( queryDate->day() != checkDate->day() )
253 allcorrect = false; 251 allcorrect = false;
254 } 252 }
255 if ( settings & OPimContactAccess::DateDiff ) { 253 if ( settings & OPimContactAccess::DateDiff ) {
256 QDate current; 254 QDate current;
257 // If we get an additional date, we 255 // If we get an additional date, we
258 // will take this date instead of 256 // will take this date instead of
259 // the current one.. 257 // the current one..
260 if ( !d.date().isValid() ) 258 if ( !d.date().isValid() )
261 current = QDate::currentDate(); 259 current = QDate::currentDate();
262 else 260 else
263 current = d.date(); 261 current = d.date();
264 262
265 // We have to equalize the year, otherwise 263 // We have to equalize the year, otherwise
266 // the search will fail.. 264 // the search will fail..
267 checkDate->setYMD( current.year(), 265 checkDate->setYMD( current.year(),
268 checkDate->month(), 266 checkDate->month(),
269 checkDate->day() ); 267 checkDate->day() );
270 if ( *checkDate < current ) 268 if ( *checkDate < current )
271 checkDate->setYMD( current.year()+1, 269 checkDate->setYMD( current.year()+1,
272 checkDate->month(), 270 checkDate->month(),
273 checkDate->day() ); 271 checkDate->day() );
274 272
275 // Check whether the birthday/anniversary date is between 273 // Check whether the birthday/anniversary date is between
276 // the current/given date and the maximum date 274 // the current/given date and the maximum date
277 // ( maximum time range ) ! 275 // ( maximum time range ) !
278 qWarning("Checking if %s is between %s and %s ! ", 276 qWarning("Checking if %s is between %s and %s ! ",
279 checkDate->toString().latin1(), 277 checkDate->toString().latin1(),
280 current.toString().latin1(), 278 current.toString().latin1(),
281 queryDate->toString().latin1() ); 279 queryDate->toString().latin1() );
282 if ( current.daysTo( *queryDate ) >= 0 ){ 280 if ( current.daysTo( *queryDate ) >= 0 ){
283 if ( !( ( *checkDate >= current ) && 281 if ( !( ( *checkDate >= current ) &&
284 ( *checkDate <= *queryDate ) ) ){ 282 ( *checkDate <= *queryDate ) ) ){
285 allcorrect = false; 283 allcorrect = false;
286 qWarning (" Nope!.."); 284 qWarning (" Nope!..");
287 } 285 }
288 } 286 }
289 } 287 }
290 } else{ 288 } else{
291 // checkDate is invalid. Therefore this entry is always rejected 289 // checkDate is invalid. Therefore this entry is always rejected
292 allcorrect = false; 290 allcorrect = false;
293 } 291 }
294 } 292 }
295 293
296 delete queryDate; 294 delete queryDate;
297 queryDate = 0l; 295 queryDate = 0l;
298 delete checkDate; 296 delete checkDate;
299 checkDate = 0l; 297 checkDate = 0l;
300 break; 298 break;
301 default: 299 default:
302 /* Just compare fields which are not empty in the query object */ 300 /* Just compare fields which are not empty in the query object */
303 if ( !query.field(i).isEmpty() ){ 301 if ( !query.field(i).isEmpty() ){
304 switch ( settings & ~( OPimContactAccess::IgnoreCase 302 switch ( settings & ~( OPimContactAccess::IgnoreCase
305 | OPimContactAccess::DateDiff 303 | OPimContactAccess::DateDiff
306 | OPimContactAccess::DateYear 304 | OPimContactAccess::DateYear
307 | OPimContactAccess::DateMonth 305 | OPimContactAccess::DateMonth
308 | OPimContactAccess::DateDay 306 | OPimContactAccess::DateDay
309 | OPimContactAccess::MatchOne 307 | OPimContactAccess::MatchOne
310 ) ){ 308 ) ){
311 309
312 case OPimContactAccess::RegExp:{ 310 case OPimContactAccess::RegExp:{
313 QRegExp expr ( query.field(i), 311 QRegExp expr ( query.field(i),
314 !(settings & OPimContactAccess::IgnoreCase), 312 !(settings & OPimContactAccess::IgnoreCase),
315 false ); 313 false );
316 if ( expr.find ( (*it)->field(i), 0 ) == -1 ) 314 if ( expr.find ( (*it)->field(i), 0 ) == -1 )
317 allcorrect = false; 315 allcorrect = false;
318 } 316 }
319 break; 317 break;
320 case OPimContactAccess::WildCards:{ 318 case OPimContactAccess::WildCards:{
321 QRegExp expr ( query.field(i), 319 QRegExp expr ( query.field(i),
322 !(settings & OPimContactAccess::IgnoreCase), 320 !(settings & OPimContactAccess::IgnoreCase),
323 true ); 321 true );
324 if ( expr.find ( (*it)->field(i), 0 ) == -1 ) 322 if ( expr.find ( (*it)->field(i), 0 ) == -1 )
325 allcorrect = false; 323 allcorrect = false;
326 } 324 }
327 break; 325 break;
328 case OPimContactAccess::ExactMatch:{ 326 case OPimContactAccess::ExactMatch:{
329 if (settings & OPimContactAccess::IgnoreCase){ 327 if (settings & OPimContactAccess::IgnoreCase){
330 if ( query.field(i).upper() != 328 if ( query.field(i).upper() !=
331 (*it)->field(i).upper() ) 329 (*it)->field(i).upper() )
332 allcorrect = false; 330 allcorrect = false;
333 }else{ 331 }else{
334 if ( query.field(i) != (*it)->field(i) ) 332 if ( query.field(i) != (*it)->field(i) )
335 allcorrect = false; 333 allcorrect = false;
336 } 334 }
337 } 335 }
338 break; 336 break;
339 } 337 }
340 } 338 }
341 } 339 }
342 } 340 }
343 if ( allcorrect ){ 341 if ( allcorrect ){
344 m_currentQuery[arraycounter++] = (*it)->uid(); 342 m_currentQuery[arraycounter++] = (*it)->uid();
345 } 343 }
346 } 344 }
347 345
348 // Shrink to fit.. 346 // Shrink to fit..
349 m_currentQuery.resize(arraycounter); 347 m_currentQuery.resize(arraycounter);
350 348
351 return m_currentQuery; 349 return m_currentQuery;
352} 350}
353 351
354QArray<int> OPimContactAccessBackend_XML::matchRegexp( const QRegExp &r ) const 352QArray<int> OPimContactAccessBackend_XML::matchRegexp( const QRegExp &r ) const
355{ 353{
356 QArray<int> m_currentQuery( m_contactList.count() ); 354 QArray<int> m_currentQuery( m_contactList.count() );
357 QListIterator<OPimContact> it( m_contactList ); 355 QListIterator<OPimContact> it( m_contactList );
358 uint arraycounter = 0; 356 uint arraycounter = 0;
359 357
360 for( ; it.current(); ++it ){ 358 for( ; it.current(); ++it ){
361 if ( (*it)->match( r ) ){ 359 if ( (*it)->match( r ) ){
362 m_currentQuery[arraycounter++] = (*it)->uid(); 360 m_currentQuery[arraycounter++] = (*it)->uid();
363 } 361 }
364 362
365 } 363 }
366 // Shrink to fit.. 364 // Shrink to fit..
367 m_currentQuery.resize(arraycounter); 365 m_currentQuery.resize(arraycounter);
368 366
369 return m_currentQuery; 367 return m_currentQuery;
370} 368}
371 369
372const uint OPimContactAccessBackend_XML::querySettings() 370const uint OPimContactAccessBackend_XML::querySettings()
373{ 371{
374 return ( OPimContactAccess::WildCards 372 return ( OPimContactAccess::WildCards
375 | OPimContactAccess::IgnoreCase 373 | OPimContactAccess::IgnoreCase
376 | OPimContactAccess::RegExp 374 | OPimContactAccess::RegExp
377 | OPimContactAccess::ExactMatch 375 | OPimContactAccess::ExactMatch
378 | OPimContactAccess::DateDiff 376 | OPimContactAccess::DateDiff
379 | OPimContactAccess::DateYear 377 | OPimContactAccess::DateYear
380 | OPimContactAccess::DateMonth 378 | OPimContactAccess::DateMonth
381 | OPimContactAccess::DateDay 379 | OPimContactAccess::DateDay
382 ); 380 );
383} 381}
384 382
385bool OPimContactAccessBackend_XML::hasQuerySettings (uint querySettings) const 383bool OPimContactAccessBackend_XML::hasQuerySettings (uint querySettings) const
386{ 384{
387 /* OPimContactAccess::IgnoreCase, DateDiff, DateYear, DateMonth, DateDay 385 /* OPimContactAccess::IgnoreCase, DateDiff, DateYear, DateMonth, DateDay
388 * may be added with any of the other settings. IgnoreCase should never used alone. 386 * may be added with any of the other settings. IgnoreCase should never used alone.
389 * Wildcards, RegExp, ExactMatch should never used at the same time... 387 * Wildcards, RegExp, ExactMatch should never used at the same time...
390 */ 388 */
391 389
392 // Step 1: Check whether the given settings are supported by this backend 390 // Step 1: Check whether the given settings are supported by this backend
393 if ( ( querySettings & ( 391 if ( ( querySettings & (
394 OPimContactAccess::IgnoreCase 392 OPimContactAccess::IgnoreCase
395 | OPimContactAccess::WildCards 393 | OPimContactAccess::WildCards
396 | OPimContactAccess::DateDiff 394 | OPimContactAccess::DateDiff
397 | OPimContactAccess::DateYear 395 | OPimContactAccess::DateYear
398 | OPimContactAccess::DateMonth 396 | OPimContactAccess::DateMonth
399 | OPimContactAccess::DateDay 397 | OPimContactAccess::DateDay
400 | OPimContactAccess::RegExp 398 | OPimContactAccess::RegExp
401 | OPimContactAccess::ExactMatch 399 | OPimContactAccess::ExactMatch
402 ) ) != querySettings ) 400 ) ) != querySettings )
403 return false; 401 return false;
404 402
405 // Step 2: Check whether the given combinations are ok.. 403 // Step 2: Check whether the given combinations are ok..
406 404
407 // IngoreCase alone is invalid 405 // IngoreCase alone is invalid
408 if ( querySettings == OPimContactAccess::IgnoreCase ) 406 if ( querySettings == OPimContactAccess::IgnoreCase )
409 return false; 407 return false;
410 408
411 // WildCards, RegExp and ExactMatch should never used at the same time 409 // WildCards, RegExp and ExactMatch should never used at the same time
412 switch ( querySettings & ~( OPimContactAccess::IgnoreCase 410 switch ( querySettings & ~( OPimContactAccess::IgnoreCase
413 | OPimContactAccess::DateDiff 411 | OPimContactAccess::DateDiff
414 | OPimContactAccess::DateYear 412 | OPimContactAccess::DateYear
415 | OPimContactAccess::DateMonth 413 | OPimContactAccess::DateMonth
416 | OPimContactAccess::DateDay 414 | OPimContactAccess::DateDay
417 ) 415 )
418 ){ 416 ){
419 case OPimContactAccess::RegExp: 417 case OPimContactAccess::RegExp:
420 return ( true ); 418 return ( true );
421 case OPimContactAccess::WildCards: 419 case OPimContactAccess::WildCards:
422 return ( true ); 420 return ( true );
423 case OPimContactAccess::ExactMatch: 421 case OPimContactAccess::ExactMatch:
424 return ( true ); 422 return ( true );
425 case 0: // one of the upper removed bits were set.. 423 case 0: // one of the upper removed bits were set..
426 return ( true ); 424 return ( true );
427 default: 425 default:
428 return ( false ); 426 return ( false );
429 } 427 }
430} 428}
431 429
432// Currently only asc implemented.. 430// Currently only asc implemented..
433QArray<int> OPimContactAccessBackend_XML::sorted( bool asc, int , int , int ) 431QArray<int> OPimContactAccessBackend_XML::sorted( bool asc, int , int , int )
434{ 432{
435 QMap<QString, int> nameToUid; 433 QMap<QString, int> nameToUid;
436 QStringList names; 434 QStringList names;
437 QArray<int> m_currentQuery( m_contactList.count() ); 435 QArray<int> m_currentQuery( m_contactList.count() );
438 436
439 // First fill map and StringList with all Names 437 // First fill map and StringList with all Names
440 // Afterwards sort namelist and use map to fill array to return.. 438 // Afterwards sort namelist and use map to fill array to return..
441 QListIterator<OPimContact> it( m_contactList ); 439 QListIterator<OPimContact> it( m_contactList );
442 for( ; it.current(); ++it ){ 440 for( ; it.current(); ++it ){
443 names.append( (*it)->fileAs() + QString::number( (*it)->uid() ) ); 441 names.append( (*it)->fileAs() + QString::number( (*it)->uid() ) );
444 nameToUid.insert( (*it)->fileAs() + QString::number( (*it)->uid() ), (*it)->uid() ); 442 nameToUid.insert( (*it)->fileAs() + QString::number( (*it)->uid() ), (*it)->uid() );
445 } 443 }
446 names.sort(); 444 names.sort();
447 445
448 int i = 0; 446 int i = 0;
449 if ( asc ){ 447 if ( asc ){
450 for ( QStringList::Iterator it = names.begin(); it != names.end(); ++it ) 448 for ( QStringList::Iterator it = names.begin(); it != names.end(); ++it )
451 m_currentQuery[i++] = nameToUid[ (*it) ]; 449 m_currentQuery[i++] = nameToUid[ (*it) ];
452 }else{ 450 }else{
453 for ( QStringList::Iterator it = names.end(); it != names.begin(); --it ) 451 for ( QStringList::Iterator it = names.end(); it != names.begin(); --it )
454 m_currentQuery[i++] = nameToUid[ (*it) ]; 452 m_currentQuery[i++] = nameToUid[ (*it) ];
455 } 453 }
456 454
457 return m_currentQuery; 455 return m_currentQuery;
458 456
459} 457}
460 458
461bool OPimContactAccessBackend_XML::add ( const OPimContact &newcontact ) 459bool OPimContactAccessBackend_XML::add ( const OPimContact &newcontact )
462{ 460{
463 //qWarning("odefaultbackend: ACTION::ADD"); 461 //qWarning("odefaultbackend: ACTION::ADD");
464 updateJournal (newcontact, ACTION_ADD); 462 updateJournal (newcontact, ACTION_ADD);
465 addContact_p( newcontact ); 463 addContact_p( newcontact );
466 464
467 m_changed = true; 465 m_changed = true;
468 466
469 return true; 467 return true;
470} 468}
471 469
472bool OPimContactAccessBackend_XML::replace ( const OPimContact &contact ) 470bool OPimContactAccessBackend_XML::replace ( const OPimContact &contact )
473{ 471{
474 m_changed = true; 472 m_changed = true;
475 473
476 OPimContact* found = m_uidToContact.find ( QString().setNum( contact.uid() ) ); 474 OPimContact* found = m_uidToContact.find ( QString().setNum( contact.uid() ) );
477 475
478 if ( found ) { 476 if ( found ) {
479 OPimContact* newCont = new OPimContact( contact ); 477 OPimContact* newCont = new OPimContact( contact );
480 478
481 updateJournal ( *newCont, ACTION_REPLACE); 479 updateJournal ( *newCont, ACTION_REPLACE);
482 m_contactList.removeRef ( found ); 480 m_contactList.removeRef ( found );
483 m_contactList.append ( newCont ); 481 m_contactList.append ( newCont );
484 m_uidToContact.remove( QString().setNum( contact.uid() ) ); 482 m_uidToContact.remove( QString().setNum( contact.uid() ) );
485 m_uidToContact.insert( QString().setNum( newCont->uid() ), newCont ); 483 m_uidToContact.insert( QString().setNum( newCont->uid() ), newCont );
486 484
487 qWarning("Nur zur Sicherheit: %d == %d ?",contact.uid(), newCont->uid()); 485 qWarning("Nur zur Sicherheit: %d == %d ?",contact.uid(), newCont->uid());
488 486
489 return true; 487 return true;
490 } else 488 } else
491 return false; 489 return false;
492} 490}
493 491
494bool OPimContactAccessBackend_XML::remove ( int uid ) 492bool OPimContactAccessBackend_XML::remove ( int uid )
495{ 493{
496 m_changed = true; 494 m_changed = true;
497 495
498 OPimContact* found = m_uidToContact.find ( QString().setNum( uid ) ); 496 OPimContact* found = m_uidToContact.find ( QString().setNum( uid ) );
499 497
500 if ( found ) { 498 if ( found ) {
501 updateJournal ( *found, ACTION_REMOVE); 499 updateJournal ( *found, ACTION_REMOVE);
502 m_contactList.removeRef ( found ); 500 m_contactList.removeRef ( found );
503 m_uidToContact.remove( QString().setNum( uid ) ); 501 m_uidToContact.remove( QString().setNum( uid ) );
504 502
505 return true; 503 return true;
506 } else 504 } else
507 return false; 505 return false;
508} 506}
509 507
510bool OPimContactAccessBackend_XML::reload(){ 508bool OPimContactAccessBackend_XML::reload(){
511 /* Reload is the same as load in this implementation */ 509 /* Reload is the same as load in this implementation */
512 return ( load() ); 510 return ( load() );
513} 511}
514 512
515void OPimContactAccessBackend_XML::addContact_p( const OPimContact &newcontact ) 513void OPimContactAccessBackend_XML::addContact_p( const OPimContact &newcontact )
516{ 514{
517 OPimContact* contRef = new OPimContact( newcontact ); 515 OPimContact* contRef = new OPimContact( newcontact );
518 516
519 m_contactList.append ( contRef ); 517 m_contactList.append ( contRef );
520 m_uidToContact.insert( QString().setNum( newcontact.uid() ), contRef ); 518 m_uidToContact.insert( QString().setNum( newcontact.uid() ), contRef );
521} 519}
522 520
523/* This function loads the xml-database and the journalfile */ 521/* This function loads the xml-database and the journalfile */
524bool OPimContactAccessBackend_XML::load( const QString filename, bool isJournal ) 522bool OPimContactAccessBackend_XML::load( const QString filename, bool isJournal )
525{ 523{
526 524
527 /* We use the time of the last read to check if the file was 525 /* We use the time of the last read to check if the file was
528 * changed externally. 526 * changed externally.
529 */ 527 */
530 if ( !isJournal ){ 528 if ( !isJournal ){
531 QFileInfo fi( filename ); 529 QFileInfo fi( filename );
532 m_readtime = fi.lastModified (); 530 m_readtime = fi.lastModified ();
533 } 531 }
534 532
535 const int JOURNALACTION = Qtopia::Notes + 1; 533 const int JOURNALACTION = Qtopia::Notes + 1;
536 const int JOURNALROW = JOURNALACTION + 1; 534 const int JOURNALROW = JOURNALACTION + 1;
537 535
538 bool foundAction = false; 536 bool foundAction = false;
539 journal_action action = ACTION_ADD; 537 journal_action action = ACTION_ADD;
540 int journalKey = 0; 538 int journalKey = 0;
541 QMap<int, QString> contactMap; 539 QMap<int, QString> contactMap;
542 QMap<QString, QString> customMap; 540 QMap<QString, QString> customMap;
543 QMap<QString, QString>::Iterator customIt; 541 QMap<QString, QString>::Iterator customIt;
544 QAsciiDict<int> dict( 47 ); 542 QAsciiDict<int> dict( 47 );
545 543
546 dict.setAutoDelete( TRUE ); 544 dict.setAutoDelete( TRUE );
547 dict.insert( "Uid", new int(Qtopia::AddressUid) ); 545 dict.insert( "Uid", new int(Qtopia::AddressUid) );
548 dict.insert( "Title", new int(Qtopia::Title) ); 546 dict.insert( "Title", new int(Qtopia::Title) );
549 dict.insert( "FirstName", new int(Qtopia::FirstName) ); 547 dict.insert( "FirstName", new int(Qtopia::FirstName) );
550 dict.insert( "MiddleName", new int(Qtopia::MiddleName) ); 548 dict.insert( "MiddleName", new int(Qtopia::MiddleName) );
551 dict.insert( "LastName", new int(Qtopia::LastName) ); 549 dict.insert( "LastName", new int(Qtopia::LastName) );
552 dict.insert( "Suffix", new int(Qtopia::Suffix) ); 550 dict.insert( "Suffix", new int(Qtopia::Suffix) );
553 dict.insert( "FileAs", new int(Qtopia::FileAs) ); 551 dict.insert( "FileAs", new int(Qtopia::FileAs) );
554 dict.insert( "Categories", new int(Qtopia::AddressCategory) ); 552 dict.insert( "Categories", new int(Qtopia::AddressCategory) );
555 dict.insert( "DefaultEmail", new int(Qtopia::DefaultEmail) ); 553 dict.insert( "DefaultEmail", new int(Qtopia::DefaultEmail) );
556 dict.insert( "Emails", new int(Qtopia::Emails) ); 554 dict.insert( "Emails", new int(Qtopia::Emails) );
557 dict.insert( "HomeStreet", new int(Qtopia::HomeStreet) ); 555 dict.insert( "HomeStreet", new int(Qtopia::HomeStreet) );
558 dict.insert( "HomeCity", new int(Qtopia::HomeCity) ); 556 dict.insert( "HomeCity", new int(Qtopia::HomeCity) );
559 dict.insert( "HomeState", new int(Qtopia::HomeState) ); 557 dict.insert( "HomeState", new int(Qtopia::HomeState) );
560 dict.insert( "HomeZip", new int(Qtopia::HomeZip) ); 558 dict.insert( "HomeZip", new int(Qtopia::HomeZip) );
561 dict.insert( "HomeCountry", new int(Qtopia::HomeCountry) ); 559 dict.insert( "HomeCountry", new int(Qtopia::HomeCountry) );
562 dict.insert( "HomePhone", new int(Qtopia::HomePhone) ); 560 dict.insert( "HomePhone", new int(Qtopia::HomePhone) );
563 dict.insert( "HomeFax", new int(Qtopia::HomeFax) ); 561 dict.insert( "HomeFax", new int(Qtopia::HomeFax) );
564 dict.insert( "HomeMobile", new int(Qtopia::HomeMobile) ); 562 dict.insert( "HomeMobile", new int(Qtopia::HomeMobile) );
565 dict.insert( "HomeWebPage", new int(Qtopia::HomeWebPage) ); 563 dict.insert( "HomeWebPage", new int(Qtopia::HomeWebPage) );
566 dict.insert( "Company", new int(Qtopia::Company) ); 564 dict.insert( "Company", new int(Qtopia::Company) );
567 dict.insert( "BusinessStreet", new int(Qtopia::BusinessStreet) ); 565 dict.insert( "BusinessStreet", new int(Qtopia::BusinessStreet) );
568 dict.insert( "BusinessCity", new int(Qtopia::BusinessCity) ); 566 dict.insert( "BusinessCity", new int(Qtopia::BusinessCity) );
569 dict.insert( "BusinessState", new int(Qtopia::BusinessState) ); 567 dict.insert( "BusinessState", new int(Qtopia::BusinessState) );
570 dict.insert( "BusinessZip", new int(Qtopia::BusinessZip) ); 568 dict.insert( "BusinessZip", new int(Qtopia::BusinessZip) );
571 dict.insert( "BusinessCountry", new int(Qtopia::BusinessCountry) ); 569 dict.insert( "BusinessCountry", new int(Qtopia::BusinessCountry) );
572 dict.insert( "BusinessWebPage", new int(Qtopia::BusinessWebPage) ); 570 dict.insert( "BusinessWebPage", new int(Qtopia::BusinessWebPage) );
573 dict.insert( "JobTitle", new int(Qtopia::JobTitle) ); 571 dict.insert( "JobTitle", new int(Qtopia::JobTitle) );
574 dict.insert( "Department", new int(Qtopia::Department) ); 572 dict.insert( "Department", new int(Qtopia::Department) );
575 dict.insert( "Office", new int(Qtopia::Office) ); 573 dict.insert( "Office", new int(Qtopia::Office) );
576 dict.insert( "BusinessPhone", new int(Qtopia::BusinessPhone) ); 574 dict.insert( "BusinessPhone", new int(Qtopia::BusinessPhone) );
577 dict.insert( "BusinessFax", new int(Qtopia::BusinessFax) ); 575 dict.insert( "BusinessFax", new int(Qtopia::BusinessFax) );
578 dict.insert( "BusinessMobile", new int(Qtopia::BusinessMobile) ); 576 dict.insert( "BusinessMobile", new int(Qtopia::BusinessMobile) );
579 dict.insert( "BusinessPager", new int(Qtopia::BusinessPager) ); 577 dict.insert( "BusinessPager", new int(Qtopia::BusinessPager) );
580 dict.insert( "Profession", new int(Qtopia::Profession) ); 578 dict.insert( "Profession", new int(Qtopia::Profession) );
581 dict.insert( "Assistant", new int(Qtopia::Assistant) ); 579 dict.insert( "Assistant", new int(Qtopia::Assistant) );
582 dict.insert( "Manager", new int(Qtopia::Manager) ); 580 dict.insert( "Manager", new int(Qtopia::Manager) );
583 dict.insert( "Spouse", new int(Qtopia::Spouse) ); 581 dict.insert( "Spouse", new int(Qtopia::Spouse) );
584 dict.insert( "Children", new int(Qtopia::Children) ); 582 dict.insert( "Children", new int(Qtopia::Children) );
585 dict.insert( "Gender", new int(Qtopia::Gender) ); 583 dict.insert( "Gender", new int(Qtopia::Gender) );
586 dict.insert( "Birthday", new int(Qtopia::Birthday) ); 584 dict.insert( "Birthday", new int(Qtopia::Birthday) );
587 dict.insert( "Anniversary", new int(Qtopia::Anniversary) ); 585 dict.insert( "Anniversary", new int(Qtopia::Anniversary) );
588 dict.insert( "Nickname", new int(Qtopia::Nickname) ); 586 dict.insert( "Nickname", new int(Qtopia::Nickname) );
589 dict.insert( "Notes", new int(Qtopia::Notes) ); 587 dict.insert( "Notes", new int(Qtopia::Notes) );
590 dict.insert( "action", new int(JOURNALACTION) ); 588 dict.insert( "action", new int(JOURNALACTION) );
591 dict.insert( "actionrow", new int(JOURNALROW) ); 589 dict.insert( "actionrow", new int(JOURNALROW) );
592 590
593 //qWarning( "OPimContactDefaultBackEnd::loading %s", filename.latin1() ); 591 //qWarning( "OPimContactDefaultBackEnd::loading %s", filename.latin1() );
594 592
595 XMLElement *root = XMLElement::load( filename ); 593 XMLElement *root = XMLElement::load( filename );
596 if(root != 0l ){ // start parsing 594 if(root != 0l ){ // start parsing
597 /* Parse all XML-Elements and put the data into the 595 /* Parse all XML-Elements and put the data into the
598 * Contact-Class 596 * Contact-Class
599 */ 597 */
600 XMLElement *element = root->firstChild(); 598 XMLElement *element = root->firstChild();
601 //qWarning("OPimContactAccess::load tagName(): %s", root->tagName().latin1() ); 599 //qWarning("OPimContactAccess::load tagName(): %s", root->tagName().latin1() );
602 element = element->firstChild(); 600 element = element->firstChild();
603 601
604 /* Search Tag "Contacts" which is the parent of all Contacts */ 602 /* Search Tag "Contacts" which is the parent of all Contacts */
605 while( element && !isJournal ){ 603 while( element && !isJournal ){
606 if( element->tagName() != QString::fromLatin1("Contacts") ){ 604 if( element->tagName() != QString::fromLatin1("Contacts") ){
607 //qWarning ("OPimContactDefBack::Searching for Tag \"Contacts\"! Found: %s", 605 //qWarning ("OPimContactDefBack::Searching for Tag \"Contacts\"! Found: %s",
608 // element->tagName().latin1()); 606 // element->tagName().latin1());
609 element = element->nextChild(); 607 element = element->nextChild();
610 } else { 608 } else {
611 element = element->firstChild(); 609 element = element->firstChild();
612 break; 610 break;
613 } 611 }
614 } 612 }
615 /* Parse all Contacts and ignore unknown tags */ 613 /* Parse all Contacts and ignore unknown tags */
616 while( element ){ 614 while( element ){
617 if( element->tagName() != QString::fromLatin1("Contact") ){ 615 if( element->tagName() != QString::fromLatin1("Contact") ){
618 //qWarning ("OPimContactDefBack::Searching for Tag \"Contact\"! Found: %s", 616 //qWarning ("OPimContactDefBack::Searching for Tag \"Contact\"! Found: %s",
619 // element->tagName().latin1()); 617 // element->tagName().latin1());
620 element = element->nextChild(); 618 element = element->nextChild();
621 continue; 619 continue;
622 } 620 }
623 /* Found alement with tagname "contact", now parse and store all 621 /* Found alement with tagname "contact", now parse and store all
624 * attributes contained 622 * attributes contained
625 */ 623 */
626 //qWarning("OPimContactDefBack::load element tagName() : %s", 624 //qWarning("OPimContactDefBack::load element tagName() : %s",
627 // element->tagName().latin1() ); 625 // element->tagName().latin1() );
628 QString dummy; 626 QString dummy;
629 foundAction = false; 627 foundAction = false;
630 628
631 XMLElement::AttributeMap aMap = element->attributes(); 629 XMLElement::AttributeMap aMap = element->attributes();
632 XMLElement::AttributeMap::Iterator it; 630 XMLElement::AttributeMap::Iterator it;
633 contactMap.clear(); 631 contactMap.clear();
634 customMap.clear(); 632 customMap.clear();
635 for( it = aMap.begin(); it != aMap.end(); ++it ){ 633 for( it = aMap.begin(); it != aMap.end(); ++it ){
636 // qWarning ("Read Attribute: %s=%s", it.key().latin1(),it.data().latin1()); 634 // qWarning ("Read Attribute: %s=%s", it.key().latin1(),it.data().latin1());
637 635
638 int *find = dict[ it.key() ]; 636 int *find = dict[ it.key() ];
639 /* Unknown attributes will be stored as "Custom" elements */ 637 /* Unknown attributes will be stored as "Custom" elements */
640 if ( !find ) { 638 if ( !find ) {
641 // qWarning("Attribute %s not known.", it.key().latin1()); 639 // qWarning("Attribute %s not known.", it.key().latin1());
642 //contact.setCustomField(it.key(), it.data()); 640 //contact.setCustomField(it.key(), it.data());
643 customMap.insert( it.key(), it.data() ); 641 customMap.insert( it.key(), it.data() );
644 continue; 642 continue;
645 } 643 }
646 644
647 /* Check if special conversion is needed and add attribute 645 /* Check if special conversion is needed and add attribute
648 * into Contact class 646 * into Contact class
649 */ 647 */
650 switch( *find ) { 648 switch( *find ) {
651 /* 649 /*
652 case Qtopia::AddressUid: 650 case Qtopia::AddressUid:
653 contact.setUid( it.data().toInt() ); 651 contact.setUid( it.data().toInt() );
654 break; 652 break;
655 case Qtopia::AddressCategory: 653 case Qtopia::AddressCategory:
656 contact.setCategories( Qtopia::Record::idsFromString( it.data( ))); 654 contact.setCategories( Qtopia::Record::idsFromString( it.data( )));
657 break; 655 break;
658 */ 656 */
659 case JOURNALACTION: 657 case JOURNALACTION:
660 action = journal_action(it.data().toInt()); 658 action = journal_action(it.data().toInt());
661 foundAction = true; 659 foundAction = true;
662 qWarning ("ODefBack(journal)::ACTION found: %d", action); 660 qWarning ("ODefBack(journal)::ACTION found: %d", action);
663 break; 661 break;
664 case JOURNALROW: 662 case JOURNALROW:
665 journalKey = it.data().toInt(); 663 journalKey = it.data().toInt();
666 break; 664 break;
667 default: // no conversion needed add them to the map 665 default: // no conversion needed add them to the map
668 contactMap.insert( *find, it.data() ); 666 contactMap.insert( *find, it.data() );
669 break; 667 break;
670 } 668 }
671 } 669 }
672 /* now generate the Contact contact */ 670 /* now generate the Contact contact */
673 OPimContact contact( contactMap ); 671 OPimContact contact( contactMap );
674 672
675 for (customIt = customMap.begin(); customIt != customMap.end(); ++customIt ) { 673 for (customIt = customMap.begin(); customIt != customMap.end(); ++customIt ) {
676 contact.setCustomField( customIt.key(), customIt.data() ); 674 contact.setCustomField( customIt.key(), customIt.data() );
677 } 675 }
678 676
679 if (foundAction){ 677 if (foundAction){
680 foundAction = false; 678 foundAction = false;
681 switch ( action ) { 679 switch ( action ) {
682 case ACTION_ADD: 680 case ACTION_ADD:
683 addContact_p (contact); 681 addContact_p (contact);
684 break; 682 break;
685 case ACTION_REMOVE: 683 case ACTION_REMOVE:
686 if ( !remove (contact.uid()) ) 684 if ( !remove (contact.uid()) )
687 qWarning ("ODefBack(journal)::Unable to remove uid: %d", 685 qWarning ("ODefBack(journal)::Unable to remove uid: %d",
688 contact.uid() ); 686 contact.uid() );
689 break; 687 break;
690 case ACTION_REPLACE: 688 case ACTION_REPLACE:
691 if ( !replace ( contact ) ) 689 if ( !replace ( contact ) )
692 qWarning ("ODefBack(journal)::Unable to replace uid: %d", 690 qWarning ("ODefBack(journal)::Unable to replace uid: %d",
693 contact.uid() ); 691 contact.uid() );
694 break; 692 break;
695 default: 693 default:
696 qWarning ("Unknown action: ignored !"); 694 qWarning ("Unknown action: ignored !");
697 break; 695 break;
698 } 696 }
699 }else{ 697 }else{
700 /* Add contact to list */ 698 /* Add contact to list */
701 addContact_p (contact); 699 addContact_p (contact);
702 } 700 }
703 701
704 /* Move to next element */ 702 /* Move to next element */
705 element = element->nextChild(); 703 element = element->nextChild();
706 } 704 }
707 }else { 705 }else {
708 qWarning("ODefBack::could not load"); 706 qWarning("ODefBack::could not load");
709 } 707 }
710 delete root; 708 delete root;
711 qWarning("returning from loading" ); 709 qWarning("returning from loading" );
712 return true; 710 return true;
713} 711}
714 712
715 713
716void OPimContactAccessBackend_XML::updateJournal( const OPimContact& cnt, 714void OPimContactAccessBackend_XML::updateJournal( const OPimContact& cnt,
717 journal_action action ) 715 journal_action action )
718{ 716{
719 QFile f( m_journalName ); 717 QFile f( m_journalName );
720 bool created = !f.exists(); 718 bool created = !f.exists();
721 if ( !f.open(IO_WriteOnly|IO_Append) ) 719 if ( !f.open(IO_WriteOnly|IO_Append) )
722 return; 720 return;
723 721
724 QString buf; 722 QString buf;
725 QCString str; 723 QCString str;
726 724
727 // if the file was created, we have to set the Tag "<CONTACTS>" to 725 // if the file was created, we have to set the Tag "<CONTACTS>" to
728 // get a XML-File which is readable by our parser. 726 // get a XML-File which is readable by our parser.
729 // This is just a cheat, but better than rewrite the parser. 727 // This is just a cheat, but better than rewrite the parser.
730 if ( created ){ 728 if ( created ){
731 buf = "<Contacts>"; 729 buf = "<Contacts>";
732 QCString cstr = buf.utf8(); 730 QCString cstr = buf.utf8();
733 f.writeBlock( cstr.data(), cstr.length() ); 731 f.writeBlock( cstr.data(), cstr.length() );
734 } 732 }
735 733
736 buf = "<Contact "; 734 buf = "<Contact ";
737 cnt.save( buf ); 735 cnt.save( buf );
738 buf += " action=\"" + QString::number( (int)action ) + "\" "; 736 buf += " action=\"" + QString::number( (int)action ) + "\" ";
739 buf += "/>\n"; 737 buf += "/>\n";
740 QCString cstr = buf.utf8(); 738 QCString cstr = buf.utf8();
741 f.writeBlock( cstr.data(), cstr.length() ); 739 f.writeBlock( cstr.data(), cstr.length() );
742} 740}
743 741
744void OPimContactAccessBackend_XML::removeJournal() 742void OPimContactAccessBackend_XML::removeJournal()
745{ 743{
746 QFile f ( m_journalName ); 744 QFile f ( m_journalName );
747 if ( f.exists() ) 745 if ( f.exists() )
748 f.remove(); 746 f.remove();
749} 747}
750 748
751} 749}
diff --git a/libopie2/opiepim/core/opimcontact.cpp b/libopie2/opiepim/core/opimcontact.cpp
index a5df597..4a774e8 100644
--- a/libopie2/opiepim/core/opimcontact.cpp
+++ b/libopie2/opiepim/core/opimcontact.cpp
@@ -1,1293 +1,1289 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) Stefan Eilers <eilers.stefan@epost.de> 3 Copyright (C) Stefan Eilers <eilers.stefan@epost.de>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 4 =. Copyright (C) The Opie Team <opie-devel@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#define QTOPIA_INTERNAL_CONTACT_MRE 30#define QTOPIA_INTERNAL_CONTACT_MRE
31 31
32#include "opimcontact.h" 32#include "opimcontact.h"
33 33
34/* OPIE */ 34/* OPIE */
35#include <opie2/opimresolver.h> 35#include <opie2/opimresolver.h>
36#include <opie2/opimdateconversion.h> 36#include <opie2/opimdateconversion.h>
37#include <qpe/stringutil.h> 37#include <qpe/stringutil.h>
38#include <qpe/timestring.h> 38#include <qpe/timestring.h>
39#include <qpe/config.h> 39#include <qpe/config.h>
40 40
41/* QT */ 41/* QT */
42#include <qobject.h>
43#include <qregexp.h>
44#include <qstylesheet.h> 42#include <qstylesheet.h>
45#include <qfileinfo.h>
46#include <qmap.h>
47 43
48/* STD */ 44/* STD */
49#include <stdio.h> 45#include <stdio.h>
50 46
51/*! 47/*!
52 \class Contact contact.h 48 \class Contact contact.h
53 \brief The Contact class holds the data of an address book entry. 49 \brief The Contact class holds the data of an address book entry.
54 50
55 This data includes information the name of the person, contact 51 This data includes information the name of the person, contact
56 information, and business information such as deparment and job title. 52 information, and business information such as deparment and job title.
57 53
58 \ingroup qtopiaemb 54 \ingroup qtopiaemb
59 \ingroup qtopiadesktop 55 \ingroup qtopiadesktop
60*/ 56*/
61 57
62 58
63namespace Opie 59namespace Opie
64{ 60{
65/*! 61/*!
66 Creates a new, empty contact. 62 Creates a new, empty contact.
67*/ 63*/
68OPimContact::OPimContact():OPimRecord(), mMap(), d( 0 ) 64OPimContact::OPimContact():OPimRecord(), mMap(), d( 0 )
69{} 65{}
70 66
71/*! 67/*!
72 \internal 68 \internal
73 Creates a new contact. The properties of the contact are 69 Creates a new contact. The properties of the contact are
74 set from \a fromMap. 70 set from \a fromMap.
75*/ 71*/
76OPimContact::OPimContact( const QMap<int, QString> &fromMap ):OPimRecord(), mMap( fromMap ), d( 0 ) 72OPimContact::OPimContact( const QMap<int, QString> &fromMap ):OPimRecord(), mMap( fromMap ), d( 0 )
77{ 73{
78 QString cats = mMap[ Qtopia::AddressCategory ]; 74 QString cats = mMap[ Qtopia::AddressCategory ];
79 if ( !cats.isEmpty() ) 75 if ( !cats.isEmpty() )
80 setCategories( idsFromString( cats ) ); 76 setCategories( idsFromString( cats ) );
81 77
82 QString uidStr = find( Qtopia::AddressUid ); 78 QString uidStr = find( Qtopia::AddressUid );
83 79
84 if ( uidStr.isEmpty() || ( uidStr.toInt() == 0 ) ) 80 if ( uidStr.isEmpty() || ( uidStr.toInt() == 0 ) )
85 { 81 {
86 qWarning( "Invalid UID found. Generate new one.." ); 82 qWarning( "Invalid UID found. Generate new one.." );
87 setUid( uidGen().generate() ); 83 setUid( uidGen().generate() );
88 } 84 }
89 else 85 else
90 setUid( uidStr.toInt() ); 86 setUid( uidStr.toInt() );
91 87
92 // if ( !uidStr.isEmpty() ) 88 // if ( !uidStr.isEmpty() )
93 // setUid( uidStr.toInt() ); 89 // setUid( uidStr.toInt() );
94} 90}
95 91
96/*! 92/*!
97 Destroys a contact. 93 Destroys a contact.
98*/ 94*/
99OPimContact::~OPimContact() 95OPimContact::~OPimContact()
100{} 96{}
101 97
102/*! \fn void OPimContact::setTitle( const QString &str ) 98/*! \fn void OPimContact::setTitle( const QString &str )
103 Sets the title of the contact to \a str. 99 Sets the title of the contact to \a str.
104*/ 100*/
105 101
106/*! \fn void OPimContact::setFirstName( const QString &str ) 102/*! \fn void OPimContact::setFirstName( const QString &str )
107 Sets the first name of the contact to \a str. 103 Sets the first name of the contact to \a str.
108*/ 104*/
109 105
110/*! \fn void OPimContact::setMiddleName( const QString &str ) 106/*! \fn void OPimContact::setMiddleName( const QString &str )
111 Sets the middle name of the contact to \a str. 107 Sets the middle name of the contact to \a str.
112*/ 108*/
113 109
114/*! \fn void OPimContact::setLastName( const QString &str ) 110/*! \fn void OPimContact::setLastName( const QString &str )
115 Sets the last name of the contact to \a str. 111 Sets the last name of the contact to \a str.
116*/ 112*/
117 113
118/*! \fn void OPimContact::setSuffix( const QString &str ) 114/*! \fn void OPimContact::setSuffix( const QString &str )
119 Sets the suffix of the contact to \a str. 115 Sets the suffix of the contact to \a str.
120*/ 116*/
121 117
122/*! \fn void OPimContact::setFileAs( const QString &str ) 118/*! \fn void OPimContact::setFileAs( const QString &str )
123 Sets the contact to filed as \a str. 119 Sets the contact to filed as \a str.
124*/ 120*/
125 121
126/*! \fn void OPimContact::setDefaultEmail( const QString &str ) 122/*! \fn void OPimContact::setDefaultEmail( const QString &str )
127 Sets the default email of the contact to \a str. 123 Sets the default email of the contact to \a str.
128*/ 124*/
129 125
130/*! \fn void OPimContact::setHomeStreet( const QString &str ) 126/*! \fn void OPimContact::setHomeStreet( const QString &str )
131 Sets the home street address of the contact to \a str. 127 Sets the home street address of the contact to \a str.
132*/ 128*/
133 129
134/*! \fn void OPimContact::setHomeCity( const QString &str ) 130/*! \fn void OPimContact::setHomeCity( const QString &str )
135 Sets the home city of the contact to \a str. 131 Sets the home city of the contact to \a str.
136*/ 132*/
137 133
138/*! \fn void OPimContact::setHomeState( const QString &str ) 134/*! \fn void OPimContact::setHomeState( const QString &str )
139 Sets the home state of the contact to \a str. 135 Sets the home state of the contact to \a str.
140*/ 136*/
141 137
142/*! \fn void OPimContact::setHomeZip( const QString &str ) 138/*! \fn void OPimContact::setHomeZip( const QString &str )
143 Sets the home zip code of the contact to \a str. 139 Sets the home zip code of the contact to \a str.
144*/ 140*/
145 141
146/*! \fn void OPimContact::setHomeCountry( const QString &str ) 142/*! \fn void OPimContact::setHomeCountry( const QString &str )
147 Sets the home country of the contact to \a str. 143 Sets the home country of the contact to \a str.
148*/ 144*/
149 145
150/*! \fn void OPimContact::setHomePhone( const QString &str ) 146/*! \fn void OPimContact::setHomePhone( const QString &str )
151 Sets the home phone number of the contact to \a str. 147 Sets the home phone number of the contact to \a str.
152*/ 148*/
153 149
154/*! \fn void OPimContact::setHomeFax( const QString &str ) 150/*! \fn void OPimContact::setHomeFax( const QString &str )
155 Sets the home fax number of the contact to \a str. 151 Sets the home fax number of the contact to \a str.
156*/ 152*/
157 153
158/*! \fn void OPimContact::setHomeMobile( const QString &str ) 154/*! \fn void OPimContact::setHomeMobile( const QString &str )
159 Sets the home mobile phone number of the contact to \a str. 155 Sets the home mobile phone number of the contact to \a str.
160*/ 156*/
161 157
162/*! \fn void OPimContact::setHomeWebpage( const QString &str ) 158/*! \fn void OPimContact::setHomeWebpage( const QString &str )
163 Sets the home webpage of the contact to \a str. 159 Sets the home webpage of the contact to \a str.
164*/ 160*/
165 161
166/*! \fn void OPimContact::setCompany( const QString &str ) 162/*! \fn void OPimContact::setCompany( const QString &str )
167 Sets the company for contact to \a str. 163 Sets the company for contact to \a str.
168*/ 164*/
169 165
170/*! \fn void OPimContact::setJobTitle( const QString &str ) 166/*! \fn void OPimContact::setJobTitle( const QString &str )
171 Sets the job title of the contact to \a str. 167 Sets the job title of the contact to \a str.
172*/ 168*/
173 169
174/*! \fn void OPimContact::setDepartment( const QString &str ) 170/*! \fn void OPimContact::setDepartment( const QString &str )
175 Sets the department for contact to \a str. 171 Sets the department for contact to \a str.
176*/ 172*/
177 173
178/*! \fn void OPimContact::setOffice( const QString &str ) 174/*! \fn void OPimContact::setOffice( const QString &str )
179 Sets the office for contact to \a str. 175 Sets the office for contact to \a str.
180*/ 176*/
181 177
182/*! \fn void OPimContact::setBusinessStreet( const QString &str ) 178/*! \fn void OPimContact::setBusinessStreet( const QString &str )
183 Sets the business street address of the contact to \a str. 179 Sets the business street address of the contact to \a str.
184*/ 180*/
185 181
186/*! \fn void OPimContact::setBusinessCity( const QString &str ) 182/*! \fn void OPimContact::setBusinessCity( const QString &str )
187 Sets the business city of the contact to \a str. 183 Sets the business city of the contact to \a str.
188*/ 184*/
189 185
190/*! \fn void OPimContact::setBusinessState( const QString &str ) 186/*! \fn void OPimContact::setBusinessState( const QString &str )
191 Sets the business state of the contact to \a str. 187 Sets the business state of the contact to \a str.
192*/ 188*/
193 189
194/*! \fn void OPimContact::setBusinessZip( const QString &str ) 190/*! \fn void OPimContact::setBusinessZip( const QString &str )
195 Sets the business zip code of the contact to \a str. 191 Sets the business zip code of the contact to \a str.
196*/ 192*/
197 193
198/*! \fn void OPimContact::setBusinessCountry( const QString &str ) 194/*! \fn void OPimContact::setBusinessCountry( const QString &str )
199 Sets the business country of the contact to \a str. 195 Sets the business country of the contact to \a str.
200*/ 196*/
201 197
202/*! \fn void OPimContact::setBusinessPhone( const QString &str ) 198/*! \fn void OPimContact::setBusinessPhone( const QString &str )
203 Sets the business phone number of the contact to \a str. 199 Sets the business phone number of the contact to \a str.
204*/ 200*/
205 201
206/*! \fn void OPimContact::setBusinessFax( const QString &str ) 202/*! \fn void OPimContact::setBusinessFax( const QString &str )
207 Sets the business fax number of the contact to \a str. 203 Sets the business fax number of the contact to \a str.
208*/ 204*/
209 205
210/*! \fn void OPimContact::setBusinessMobile( const QString &str ) 206/*! \fn void OPimContact::setBusinessMobile( const QString &str )
211 Sets the business mobile phone number of the contact to \a str. 207 Sets the business mobile phone number of the contact to \a str.
212*/ 208*/
213 209
214/*! \fn void OPimContact::setBusinessPager( const QString &str ) 210/*! \fn void OPimContact::setBusinessPager( const QString &str )
215 Sets the business pager number of the contact to \a str. 211 Sets the business pager number of the contact to \a str.
216*/ 212*/
217 213
218/*! \fn void OPimContact::setBusinessWebpage( const QString &str ) 214/*! \fn void OPimContact::setBusinessWebpage( const QString &str )
219 Sets the business webpage of the contact to \a str. 215 Sets the business webpage of the contact to \a str.
220*/ 216*/
221 217
222/*! \fn void OPimContact::setProfession( const QString &str ) 218/*! \fn void OPimContact::setProfession( const QString &str )
223 Sets the profession of the contact to \a str. 219 Sets the profession of the contact to \a str.
224*/ 220*/
225 221
226/*! \fn void OPimContact::setAssistant( const QString &str ) 222/*! \fn void OPimContact::setAssistant( const QString &str )
227 Sets the assistant of the contact to \a str. 223 Sets the assistant of the contact to \a str.
228*/ 224*/
229 225
230/*! \fn void OPimContact::setManager( const QString &str ) 226/*! \fn void OPimContact::setManager( const QString &str )
231 Sets the manager of the contact to \a str. 227 Sets the manager of the contact to \a str.
232*/ 228*/
233 229
234/*! \fn void OPimContact::setSpouse( const QString &str ) 230/*! \fn void OPimContact::setSpouse( const QString &str )
235 Sets the spouse of the contact to \a str. 231 Sets the spouse of the contact to \a str.
236*/ 232*/
237 233
238/*! \fn void OPimContact::setGender( const QString &str ) 234/*! \fn void OPimContact::setGender( const QString &str )
239 Sets the gender of the contact to \a str. 235 Sets the gender of the contact to \a str.
240*/ 236*/
241 237
242/*! \fn void OPimContact::setNickname( const QString &str ) 238/*! \fn void OPimContact::setNickname( const QString &str )
243 Sets the nickname of the contact to \a str. 239 Sets the nickname of the contact to \a str.
244*/ 240*/
245 241
246/*! \fn void OPimContact::setNotes( const QString &str ) 242/*! \fn void OPimContact::setNotes( const QString &str )
247 Sets the notes about the contact to \a str. 243 Sets the notes about the contact to \a str.
248*/ 244*/
249 245
250/*! \fn QString OPimContact::title() const 246/*! \fn QString OPimContact::title() const
251 Returns the title of the contact. 247 Returns the title of the contact.
252*/ 248*/
253 249
254/*! \fn QString OPimContact::firstName() const 250/*! \fn QString OPimContact::firstName() const
255 Returns the first name of the contact. 251 Returns the first name of the contact.
256*/ 252*/
257 253
258/*! \fn QString OPimContact::middleName() const 254/*! \fn QString OPimContact::middleName() const
259 Returns the middle name of the contact. 255 Returns the middle name of the contact.
260*/ 256*/
261 257
262/*! \fn QString OPimContact::lastName() const 258/*! \fn QString OPimContact::lastName() const
263 Returns the last name of the contact. 259 Returns the last name of the contact.
264*/ 260*/
265 261
266/*! \fn QString OPimContact::suffix() const 262/*! \fn QString OPimContact::suffix() const
267 Returns the suffix of the contact. 263 Returns the suffix of the contact.
268*/ 264*/
269 265
270/*! \fn QString OPimContact::fileAs() const 266/*! \fn QString OPimContact::fileAs() const
271 Returns the string the contact is filed as. 267 Returns the string the contact is filed as.
272*/ 268*/
273 269
274/*! \fn QString OPimContact::defaultEmail() const 270/*! \fn QString OPimContact::defaultEmail() const
275 Returns the default email address of the contact. 271 Returns the default email address of the contact.
276*/ 272*/
277 273
278/*! \fn QString OPimContact::emails() const 274/*! \fn QString OPimContact::emails() const
279 Returns the list of email address for a contact separated by ';'s in a single 275 Returns the list of email address for a contact separated by ';'s in a single
280 string. 276 string.
281*/ 277*/
282 278
283/*! \fn QString OPimContact::homeStreet() const 279/*! \fn QString OPimContact::homeStreet() const
284 Returns the home street address of the contact. 280 Returns the home street address of the contact.
285*/ 281*/
286 282
287/*! \fn QString OPimContact::homeCity() const 283/*! \fn QString OPimContact::homeCity() const
288 Returns the home city of the contact. 284 Returns the home city of the contact.
289*/ 285*/
290 286
291/*! \fn QString OPimContact::homeState() const 287/*! \fn QString OPimContact::homeState() const
292 Returns the home state of the contact. 288 Returns the home state of the contact.
293*/ 289*/
294 290
295/*! \fn QString OPimContact::homeZip() const 291/*! \fn QString OPimContact::homeZip() const
296 Returns the home zip of the contact. 292 Returns the home zip of the contact.
297*/ 293*/
298 294
299/*! \fn QString OPimContact::homeCountry() const 295/*! \fn QString OPimContact::homeCountry() const
300 Returns the home country of the contact. 296 Returns the home country of the contact.
301*/ 297*/
302 298
303/*! \fn QString OPimContact::homePhone() const 299/*! \fn QString OPimContact::homePhone() const
304 Returns the home phone number of the contact. 300 Returns the home phone number of the contact.
305*/ 301*/
306 302
307/*! \fn QString OPimContact::homeFax() const 303/*! \fn QString OPimContact::homeFax() const
308 Returns the home fax number of the contact. 304 Returns the home fax number of the contact.
309*/ 305*/
310 306
311/*! \fn QString OPimContact::homeMobile() const 307/*! \fn QString OPimContact::homeMobile() const
312 Returns the home mobile number of the contact. 308 Returns the home mobile number of the contact.
313*/ 309*/
314 310
315/*! \fn QString OPimContact::homeWebpage() const 311/*! \fn QString OPimContact::homeWebpage() const
316 Returns the home webpage of the contact. 312 Returns the home webpage of the contact.
317*/ 313*/
318 314
319/*! \fn QString OPimContact::company() const 315/*! \fn QString OPimContact::company() const
320 Returns the company for the contact. 316 Returns the company for the contact.
321*/ 317*/
322 318
323/*! \fn QString OPimContact::department() const 319/*! \fn QString OPimContact::department() const
324 Returns the department for the contact. 320 Returns the department for the contact.
325*/ 321*/
326 322
327/*! \fn QString OPimContact::office() const 323/*! \fn QString OPimContact::office() const
328 Returns the office for the contact. 324 Returns the office for the contact.
329*/ 325*/
330 326
331/*! \fn QString OPimContact::jobTitle() const 327/*! \fn QString OPimContact::jobTitle() const
332 Returns the job title of the contact. 328 Returns the job title of the contact.
333*/ 329*/
334 330
335/*! \fn QString OPimContact::profession() const 331/*! \fn QString OPimContact::profession() const
336 Returns the profession of the contact. 332 Returns the profession of the contact.
337*/ 333*/
338 334
339/*! \fn QString OPimContact::assistant() const 335/*! \fn QString OPimContact::assistant() const
340 Returns the assistant of the contact. 336 Returns the assistant of the contact.
341*/ 337*/
342 338
343/*! \fn QString OPimContact::manager() const 339/*! \fn QString OPimContact::manager() const
344 Returns the manager of the contact. 340 Returns the manager of the contact.
345*/ 341*/
346 342
347/*! \fn QString OPimContact::businessStreet() const 343/*! \fn QString OPimContact::businessStreet() const
348 Returns the business street address of the contact. 344 Returns the business street address of the contact.
349*/ 345*/
350 346
351/*! \fn QString OPimContact::businessCity() const 347/*! \fn QString OPimContact::businessCity() const
352 Returns the business city of the contact. 348 Returns the business city of the contact.
353*/ 349*/
354 350
355/*! \fn QString OPimContact::businessState() const 351/*! \fn QString OPimContact::businessState() const
356 Returns the business state of the contact. 352 Returns the business state of the contact.
357*/ 353*/
358 354
359/*! \fn QString OPimContact::businessZip() const 355/*! \fn QString OPimContact::businessZip() const
360 Returns the business zip of the contact. 356 Returns the business zip of the contact.
361*/ 357*/
362 358
363/*! \fn QString OPimContact::businessCountry() const 359/*! \fn QString OPimContact::businessCountry() const
364 Returns the business country of the contact. 360 Returns the business country of the contact.
365*/ 361*/
366 362
367/*! \fn QString OPimContact::businessPhone() const 363/*! \fn QString OPimContact::businessPhone() const
368 Returns the business phone number of the contact. 364 Returns the business phone number of the contact.
369*/ 365*/
370 366
371/*! \fn QString OPimContact::businessFax() const 367/*! \fn QString OPimContact::businessFax() const
372 Returns the business fax number of the contact. 368 Returns the business fax number of the contact.
373*/ 369*/
374 370
375/*! \fn QString OPimContact::businessMobile() const 371/*! \fn QString OPimContact::businessMobile() const
376 Returns the business mobile number of the contact. 372 Returns the business mobile number of the contact.
377*/ 373*/
378 374
379/*! \fn QString OPimContact::businessPager() const 375/*! \fn QString OPimContact::businessPager() const
380 Returns the business pager number of the contact. 376 Returns the business pager number of the contact.
381*/ 377*/
382 378
383/*! \fn QString OPimContact::businessWebpage() const 379/*! \fn QString OPimContact::businessWebpage() const
384 Returns the business webpage of the contact. 380 Returns the business webpage of the contact.
385*/ 381*/
386 382
387/*! \fn QString OPimContact::spouse() const 383/*! \fn QString OPimContact::spouse() const
388 Returns the spouse of the contact. 384 Returns the spouse of the contact.
389*/ 385*/
390 386
391/*! \fn QString OPimContact::gender() const 387/*! \fn QString OPimContact::gender() const
392 Returns the gender of the contact. 388 Returns the gender of the contact.
393*/ 389*/
394 390
395/*! \fn QString OPimContact::nickname() const 391/*! \fn QString OPimContact::nickname() const
396 Returns the nickname of the contact. 392 Returns the nickname of the contact.
397*/ 393*/
398 394
399/*! \fn QString OPimContact::children() const 395/*! \fn QString OPimContact::children() const
400 Returns the children of the contact. 396 Returns the children of the contact.
401*/ 397*/
402 398
403/*! \fn QString OPimContact::notes() const 399/*! \fn QString OPimContact::notes() const
404 Returns the notes relating to the the contact. 400 Returns the notes relating to the the contact.
405*/ 401*/
406 402
407/*! \fn QString OPimContact::groups() const 403/*! \fn QString OPimContact::groups() const
408 \internal 404 \internal
409 Returns the groups for the contact. 405 Returns the groups for the contact.
410*/ 406*/
411 407
412/*! \fn QStringList OPimContact::groupList() const 408/*! \fn QStringList OPimContact::groupList() const
413 \internal 409 \internal
414*/ 410*/
415 411
416/*! \fn QString OPimContact::field(int) const 412/*! \fn QString OPimContact::field(int) const
417 \internal 413 \internal
418*/ 414*/
419 415
420/*! \fn void OPimContact::saveJournal( journal_action, const QString & = QString::null ) 416/*! \fn void OPimContact::saveJournal( journal_action, const QString & = QString::null )
421 \internal 417 \internal
422*/ 418*/
423 419
424/*! \fn void OPimContact::setUid( int id ) 420/*! \fn void OPimContact::setUid( int id )
425 \internal 421 \internal
426 Sets the uid for this record to \a id. 422 Sets the uid for this record to \a id.
427*/ 423*/
428 424
429/*! \enum OPimContact::journal_action 425/*! \enum OPimContact::journal_action
430 \internal 426 \internal
431*/ 427*/
432 428
433/*! 429/*!
434 \internal 430 \internal
435*/ 431*/
436QMap<int, QString> OPimContact::toMap() const 432QMap<int, QString> OPimContact::toMap() const
437{ 433{
438 QMap<int, QString> map = mMap; 434 QMap<int, QString> map = mMap;
439 QString cats = idsToString( categories() ); 435 QString cats = idsToString( categories() );
440 if ( !cats.isEmpty() ) 436 if ( !cats.isEmpty() )
441 map.insert( Qtopia::AddressCategory, cats ); 437 map.insert( Qtopia::AddressCategory, cats );
442 return map; 438 return map;
443} 439}
444 440
445/*! 441/*!
446 Returns a rich text formatted QString representing the contents the contact. 442 Returns a rich text formatted QString representing the contents the contact.
447*/ 443*/
448QString OPimContact::toRichText() const 444QString OPimContact::toRichText() const
449{ 445{
450 QString text; 446 QString text;
451 QString value, comp, state; 447 QString value, comp, state;
452 QString str; 448 QString str;
453 bool marker = false; 449 bool marker = false;
454 450
455 Config cfg( "qpe" ); 451 Config cfg( "qpe" );
456 cfg.setGroup( "Appearance" ); 452 cfg.setGroup( "Appearance" );
457 int addressformat = cfg.readNumEntry( "AddressFormat", Zip_City_State ); 453 int addressformat = cfg.readNumEntry( "AddressFormat", Zip_City_State );
458 454
459 // name, jobtitle and company 455 // name, jobtitle and company
460 if ( !( value = fullName() ).isEmpty() ) 456 if ( !( value = fullName() ).isEmpty() )
461 text += "<b><h3><img src=\"addressbook/AddressBook\"> " + Qtopia::escapeString( value ) + "</h3></b>"; 457 text += "<b><h3><img src=\"addressbook/AddressBook\"> " + Qtopia::escapeString( value ) + "</h3></b>";
462 458
463 if ( !( value = jobTitle() ).isEmpty() ) 459 if ( !( value = jobTitle() ).isEmpty() )
464 text += Qtopia::escapeString( value ) + " "; 460 text += Qtopia::escapeString( value ) + " ";
465 461
466 comp = company(); 462 comp = company();
467 if ( !( value = department() ).isEmpty() ) 463 if ( !( value = department() ).isEmpty() )
468 { 464 {
469 text += Qtopia::escapeString( value ); 465 text += Qtopia::escapeString( value );
470 if ( comp ) 466 if ( comp )
471 text += ", " + Qtopia::escapeString( comp ); 467 text += ", " + Qtopia::escapeString( comp );
472 } 468 }
473 else if ( comp ) 469 else if ( comp )
474 text += "<br>" + Qtopia::escapeString( comp ); 470 text += "<br>" + Qtopia::escapeString( comp );
475 text += "<br><hr>"; 471 text += "<br><hr>";
476 472
477 // defailt email 473 // defailt email
478 QString defEmail = defaultEmail(); 474 QString defEmail = defaultEmail();
479 if ( !defEmail.isEmpty() ) 475 if ( !defEmail.isEmpty() )
480 { 476 {
481 text += "<b><img src=\"addressbook/email\"> " + QObject::tr( "Default Email: " ) + "</b>" 477 text += "<b><img src=\"addressbook/email\"> " + QObject::tr( "Default Email: " ) + "</b>"
482 + Qtopia::escapeString( defEmail ); 478 + Qtopia::escapeString( defEmail );
483 marker = true; 479 marker = true;
484 } 480 }
485 481
486 // business address 482 // business address
487 if ( !businessStreet().isEmpty() || !businessCity().isEmpty() || 483 if ( !businessStreet().isEmpty() || !businessCity().isEmpty() ||
488 !businessZip().isEmpty() || !businessCountry().isEmpty() ) 484 !businessZip().isEmpty() || !businessCountry().isEmpty() )
489 { 485 {
490 text += QObject::tr( "<br><b>Work Address:</b>" ); 486 text += QObject::tr( "<br><b>Work Address:</b>" );
491 marker = true; 487 marker = true;
492 } 488 }
493 489
494 if ( !( value = businessStreet() ).isEmpty() ) 490 if ( !( value = businessStreet() ).isEmpty() )
495 { 491 {
496 text += "<br>" + Qtopia::escapeString( value ); 492 text += "<br>" + Qtopia::escapeString( value );
497 marker = true; 493 marker = true;
498 } 494 }
499 495
500 switch ( addressformat ) 496 switch ( addressformat )
501 { 497 {
502 case Zip_City_State: 498 case Zip_City_State:
503 { // Zip_Code City, State 499 { // Zip_Code City, State
504 state = businessState(); 500 state = businessState();
505 if ( !( value = businessZip() ).isEmpty() ) 501 if ( !( value = businessZip() ).isEmpty() )
506 { 502 {
507 text += "<br>" + Qtopia::escapeString( value ) + " "; 503 text += "<br>" + Qtopia::escapeString( value ) + " ";
508 marker = true; 504 marker = true;
509 505
510 } 506 }
511 if ( !( value = businessCity() ).isEmpty() ) 507 if ( !( value = businessCity() ).isEmpty() )
512 { 508 {
513 marker = true; 509 marker = true;
514 if ( businessZip().isEmpty() && !businessStreet().isEmpty() ) 510 if ( businessZip().isEmpty() && !businessStreet().isEmpty() )
515 text += "<br>"; 511 text += "<br>";
516 text += Qtopia::escapeString( value ); 512 text += Qtopia::escapeString( value );
517 if ( state ) 513 if ( state )
518 text += ", " + Qtopia::escapeString( state ); 514 text += ", " + Qtopia::escapeString( state );
519 } 515 }
520 else if ( !state.isEmpty() ) 516 else if ( !state.isEmpty() )
521 { 517 {
522 text += "<br>" + Qtopia::escapeString( state ); 518 text += "<br>" + Qtopia::escapeString( state );
523 marker = true; 519 marker = true;
524 } 520 }
525 break; 521 break;
526 } 522 }
527 case City_State_Zip: 523 case City_State_Zip:
528 { // City, State Zip_Code 524 { // City, State Zip_Code
529 state = businessState(); 525 state = businessState();
530 if ( !( value = businessCity() ).isEmpty() ) 526 if ( !( value = businessCity() ).isEmpty() )
531 { 527 {
532 marker = true; 528 marker = true;
533 text += "<br>" + Qtopia::escapeString( value ); 529 text += "<br>" + Qtopia::escapeString( value );
534 if ( state ) 530 if ( state )
535 text += ", " + Qtopia::escapeString( state ); 531 text += ", " + Qtopia::escapeString( state );
536 } 532 }
537 else if ( !state.isEmpty() ) 533 else if ( !state.isEmpty() )
538 { 534 {
539 text += "<br>" + Qtopia::escapeString( state ); 535 text += "<br>" + Qtopia::escapeString( state );
540 marker = true; 536 marker = true;
541 } 537 }
542 if ( !( value = businessZip() ).isEmpty() ) 538 if ( !( value = businessZip() ).isEmpty() )
543 { 539 {
544 text += " " + Qtopia::escapeString( value ); 540 text += " " + Qtopia::escapeString( value );
545 marker = true; 541 marker = true;
546 } 542 }
547 break; 543 break;
548 } 544 }
549 } 545 }
550 546
551 if ( !( value = businessCountry() ).isEmpty() ) 547 if ( !( value = businessCountry() ).isEmpty() )
552 { 548 {
553 text += "<br>" + Qtopia::escapeString( value ); 549 text += "<br>" + Qtopia::escapeString( value );
554 marker = true; 550 marker = true;
555 } 551 }
556 552
557 // rest of Business data 553 // rest of Business data
558 str = office(); 554 str = office();
559 if ( !str.isEmpty() ) 555 if ( !str.isEmpty() )
560 { 556 {
561 text += "<br><b>" + QObject::tr( "Office: " ) + "</b>" 557 text += "<br><b>" + QObject::tr( "Office: " ) + "</b>"
562 + Qtopia::escapeString( str ); 558 + Qtopia::escapeString( str );
563 marker = true; 559 marker = true;
564 } 560 }
565 str = businessWebpage(); 561 str = businessWebpage();
566 if ( !str.isEmpty() ) 562 if ( !str.isEmpty() )
567 { 563 {
568 text += "<br><b><img src=\"addressbook/webpagework\"> " + QObject::tr( "Business Web Page: " ) + "</b>" 564 text += "<br><b><img src=\"addressbook/webpagework\"> " + QObject::tr( "Business Web Page: " ) + "</b>"
569 + Qtopia::escapeString( str ); 565 + Qtopia::escapeString( str );
570 marker = true; 566 marker = true;
571 } 567 }
572 str = businessPhone(); 568 str = businessPhone();
573 if ( !str.isEmpty() ) 569 if ( !str.isEmpty() )
574 { 570 {
575 text += "<br><b><img src=\"addressbook/phonework\"> " + QObject::tr( "Business Phone: " ) + "</b>" 571 text += "<br><b><img src=\"addressbook/phonework\"> " + QObject::tr( "Business Phone: " ) + "</b>"
576 + Qtopia::escapeString( str ); 572 + Qtopia::escapeString( str );
577 marker = true; 573 marker = true;
578 } 574 }
579 str = businessFax(); 575 str = businessFax();
580 if ( !str.isEmpty() ) 576 if ( !str.isEmpty() )
581 { 577 {
582 text += "<br><b><img src=\"addressbook/faxwork\"> " + QObject::tr( "Business Fax: " ) + "</b>" 578 text += "<br><b><img src=\"addressbook/faxwork\"> " + QObject::tr( "Business Fax: " ) + "</b>"
583 + Qtopia::escapeString( str ); 579 + Qtopia::escapeString( str );
584 marker = true; 580 marker = true;
585 } 581 }
586 str = businessMobile(); 582 str = businessMobile();
587 if ( !str.isEmpty() ) 583 if ( !str.isEmpty() )
588 { 584 {
589 text += "<br><b><img src=\"addressbook/mobilework\"> " + QObject::tr( "Business Mobile: " ) + "</b>" 585 text += "<br><b><img src=\"addressbook/mobilework\"> " + QObject::tr( "Business Mobile: " ) + "</b>"
590 + Qtopia::escapeString( str ); 586 + Qtopia::escapeString( str );
591 marker = true; 587 marker = true;
592 } 588 }
593 str = businessPager(); 589 str = businessPager();
594 if ( !str.isEmpty() ) 590 if ( !str.isEmpty() )
595 { 591 {
596 text += "<br><b>" + QObject::tr( "Business Pager: " ) + "</b>" 592 text += "<br><b>" + QObject::tr( "Business Pager: " ) + "</b>"
597 + Qtopia::escapeString( str ); 593 + Qtopia::escapeString( str );
598 marker = true; 594 marker = true;
599 } 595 }
600 596
601 // text += "<br>"; 597 // text += "<br>";
602 598
603 // home address 599 // home address
604 if ( !homeStreet().isEmpty() || !homeCity().isEmpty() || 600 if ( !homeStreet().isEmpty() || !homeCity().isEmpty() ||
605 !homeZip().isEmpty() || !homeCountry().isEmpty() ) 601 !homeZip().isEmpty() || !homeCountry().isEmpty() )
606 { 602 {
607 text += QObject::tr( "<br><b>Home Address:</b>" ); 603 text += QObject::tr( "<br><b>Home Address:</b>" );
608 marker = true; 604 marker = true;
609 } 605 }
610 606
611 if ( !( value = homeStreet() ).isEmpty() ) 607 if ( !( value = homeStreet() ).isEmpty() )
612 { 608 {
613 text += "<br>" + Qtopia::escapeString( value ); 609 text += "<br>" + Qtopia::escapeString( value );
614 marker = true; 610 marker = true;
615 } 611 }
616 612
617 switch ( addressformat ) 613 switch ( addressformat )
618 { 614 {
619 case Zip_City_State: 615 case Zip_City_State:
620 { // Zip_Code City, State 616 { // Zip_Code City, State
621 state = homeState(); 617 state = homeState();
622 if ( !( value = homeZip() ).isEmpty() ) 618 if ( !( value = homeZip() ).isEmpty() )
623 { 619 {
624 text += "<br>" + Qtopia::escapeString( value ) + " "; 620 text += "<br>" + Qtopia::escapeString( value ) + " ";
625 marker = true; 621 marker = true;
626 } 622 }
627 if ( !( value = homeCity() ).isEmpty() ) 623 if ( !( value = homeCity() ).isEmpty() )
628 { 624 {
629 marker = true; 625 marker = true;
630 if ( homeZip().isEmpty() && !homeStreet().isEmpty() ) 626 if ( homeZip().isEmpty() && !homeStreet().isEmpty() )
631 text += "<br>"; 627 text += "<br>";
632 text += Qtopia::escapeString( value ); 628 text += Qtopia::escapeString( value );
633 if ( !state.isEmpty() ) 629 if ( !state.isEmpty() )
634 text += ", " + Qtopia::escapeString( state ); 630 text += ", " + Qtopia::escapeString( state );
635 } 631 }
636 else if ( !state.isEmpty() ) 632 else if ( !state.isEmpty() )
637 { 633 {
638 text += "<br>" + Qtopia::escapeString( state ); 634 text += "<br>" + Qtopia::escapeString( state );
639 marker = true; 635 marker = true;
640 } 636 }
641 break; 637 break;
642 } 638 }
643 case City_State_Zip: 639 case City_State_Zip:
644 { // City, State Zip_Code 640 { // City, State Zip_Code
645 state = homeState(); 641 state = homeState();
646 if ( !( value = homeCity() ).isEmpty() ) 642 if ( !( value = homeCity() ).isEmpty() )
647 { 643 {
648 marker = true; 644 marker = true;
649 text += "<br>" + Qtopia::escapeString( value ); 645 text += "<br>" + Qtopia::escapeString( value );
650 if ( state ) 646 if ( state )
651 text += ", " + Qtopia::escapeString( state ); 647 text += ", " + Qtopia::escapeString( state );
652 } 648 }
653 else if ( !state.isEmpty() ) 649 else if ( !state.isEmpty() )
654 { 650 {
655 text += "<br>" + Qtopia::escapeString( state ); 651 text += "<br>" + Qtopia::escapeString( state );
656 marker = true; 652 marker = true;
657 } 653 }
658 if ( !( value = homeZip() ).isEmpty() ) 654 if ( !( value = homeZip() ).isEmpty() )
659 { 655 {
660 text += " " + Qtopia::escapeString( value ); 656 text += " " + Qtopia::escapeString( value );
661 marker = true; 657 marker = true;
662 } 658 }
663 break; 659 break;
664 } 660 }
665 } 661 }
666 662
667 if ( !( value = homeCountry() ).isEmpty() ) 663 if ( !( value = homeCountry() ).isEmpty() )
668 { 664 {
669 text += "<br>" + Qtopia::escapeString( value ); 665 text += "<br>" + Qtopia::escapeString( value );
670 marker = true; 666 marker = true;
671 } 667 }
672 668
673 // rest of Home data 669 // rest of Home data
674 str = homeWebpage(); 670 str = homeWebpage();
675 if ( !str.isEmpty() ) 671 if ( !str.isEmpty() )
676 { 672 {
677 text += "<br><b><img src=\"addressbook/webpagehome\"> " + QObject::tr( "Home Web Page: " ) + "</b>" 673 text += "<br><b><img src=\"addressbook/webpagehome\"> " + QObject::tr( "Home Web Page: " ) + "</b>"
678 + Qtopia::escapeString( str ); 674 + Qtopia::escapeString( str );
679 marker = true; 675 marker = true;
680 } 676 }
681 str = homePhone(); 677 str = homePhone();
682 if ( !str.isEmpty() ) 678 if ( !str.isEmpty() )
683 { 679 {
684 text += "<br><b><img src=\"addressbook/phonehome\"> " + QObject::tr( "Home Phone: " ) + "</b>" 680 text += "<br><b><img src=\"addressbook/phonehome\"> " + QObject::tr( "Home Phone: " ) + "</b>"
685 + Qtopia::escapeString( str ); 681 + Qtopia::escapeString( str );
686 marker = true; 682 marker = true;
687 } 683 }
688 str = homeFax(); 684 str = homeFax();
689 if ( !str.isEmpty() ) 685 if ( !str.isEmpty() )
690 { 686 {
691 text += "<br><b><img src=\"addressbook/faxhome\"> " + QObject::tr( "Home Fax: " ) + "</b>" 687 text += "<br><b><img src=\"addressbook/faxhome\"> " + QObject::tr( "Home Fax: " ) + "</b>"
692 + Qtopia::escapeString( str ); 688 + Qtopia::escapeString( str );
693 marker = true; 689 marker = true;
694 } 690 }
695 str = homeMobile(); 691 str = homeMobile();
696 if ( !str.isEmpty() ) 692 if ( !str.isEmpty() )
697 { 693 {
698 text += "<br><b><img src=\"addressbook/mobilehome\"> " + QObject::tr( "Home Mobile: " ) + "</b>" 694 text += "<br><b><img src=\"addressbook/mobilehome\"> " + QObject::tr( "Home Mobile: " ) + "</b>"
699 + Qtopia::escapeString( str ); 695 + Qtopia::escapeString( str );
700 marker = true; 696 marker = true;
701 } 697 }
702 698
703 if ( marker ) 699 if ( marker )
704 text += "<br><hr>"; 700 text += "<br><hr>";
705 701
706 // the rest... 702 // the rest...
707 str = emails(); 703 str = emails();
708 if ( !str.isEmpty() && ( str != defEmail ) ) 704 if ( !str.isEmpty() && ( str != defEmail ) )
709 text += "<br><b>" + QObject::tr( "All Emails: " ) + "</b>" 705 text += "<br><b>" + QObject::tr( "All Emails: " ) + "</b>"
710 + Qtopia::escapeString( str ); 706 + Qtopia::escapeString( str );
711 str = profession(); 707 str = profession();
712 if ( !str.isEmpty() ) 708 if ( !str.isEmpty() )
713 text += "<br><b>" + QObject::tr( "Profession: " ) + "</b>" 709 text += "<br><b>" + QObject::tr( "Profession: " ) + "</b>"
714 + Qtopia::escapeString( str ); 710 + Qtopia::escapeString( str );
715 str = assistant(); 711 str = assistant();
716 if ( !str.isEmpty() ) 712 if ( !str.isEmpty() )
717 text += "<br><b>" + QObject::tr( "Assistant: " ) + "</b>" 713 text += "<br><b>" + QObject::tr( "Assistant: " ) + "</b>"
718 + Qtopia::escapeString( str ); 714 + Qtopia::escapeString( str );
719 str = manager(); 715 str = manager();
720 if ( !str.isEmpty() ) 716 if ( !str.isEmpty() )
721 text += "<br><b>" + QObject::tr( "Manager: " ) + "</b>" 717 text += "<br><b>" + QObject::tr( "Manager: " ) + "</b>"
722 + Qtopia::escapeString( str ); 718 + Qtopia::escapeString( str );
723 str = gender(); 719 str = gender();
724 if ( !str.isEmpty() && str.toInt() != 0 ) 720 if ( !str.isEmpty() && str.toInt() != 0 )
725 { 721 {
726 text += "<br>"; 722 text += "<br>";
727 if ( str.toInt() == 1 ) 723 if ( str.toInt() == 1 )
728 str = QObject::tr( "Male" ); 724 str = QObject::tr( "Male" );
729 else if ( str.toInt() == 2 ) 725 else if ( str.toInt() == 2 )
730 str = QObject::tr( "Female" ); 726 str = QObject::tr( "Female" );
731 text += "<b>" + QObject::tr( "Gender: " ) + "</b>" + str; 727 text += "<b>" + QObject::tr( "Gender: " ) + "</b>" + str;
732 } 728 }
733 str = spouse(); 729 str = spouse();
734 if ( !str.isEmpty() ) 730 if ( !str.isEmpty() )
735 text += "<br><b>" + QObject::tr( "Spouse: " ) + "</b>" 731 text += "<br><b>" + QObject::tr( "Spouse: " ) + "</b>"
736 + Qtopia::escapeString( str ); 732 + Qtopia::escapeString( str );
737 if ( birthday().isValid() ) 733 if ( birthday().isValid() )
738 { 734 {
739 str = TimeString::numberDateString( birthday() ); 735 str = TimeString::numberDateString( birthday() );
740 text += "<br><b>" + QObject::tr( "Birthday: " ) + "</b>" 736 text += "<br><b>" + QObject::tr( "Birthday: " ) + "</b>"
741 + Qtopia::escapeString( str ); 737 + Qtopia::escapeString( str );
742 } 738 }
743 if ( anniversary().isValid() ) 739 if ( anniversary().isValid() )
744 { 740 {
745 str = TimeString::numberDateString( anniversary() ); 741 str = TimeString::numberDateString( anniversary() );
746 text += "<br><b>" + QObject::tr( "Anniversary: " ) + "</b>" 742 text += "<br><b>" + QObject::tr( "Anniversary: " ) + "</b>"
747 + Qtopia::escapeString( str ); 743 + Qtopia::escapeString( str );
748 } 744 }
749 str = children(); 745 str = children();
750 if ( !str.isEmpty() ) 746 if ( !str.isEmpty() )
751 text += "<br><b>" + QObject::tr( "Children: " ) + "</b>" 747 text += "<br><b>" + QObject::tr( "Children: " ) + "</b>"
752 + Qtopia::escapeString( str ); 748 + Qtopia::escapeString( str );
753 749
754 str = nickname(); 750 str = nickname();
755 if ( !str.isEmpty() ) 751 if ( !str.isEmpty() )
756 text += "<br><b>" + QObject::tr( "Nickname: " ) + "</b>" 752 text += "<br><b>" + QObject::tr( "Nickname: " ) + "</b>"
757 + Qtopia::escapeString( str ); 753 + Qtopia::escapeString( str );
758 754
759 // categories 755 // categories
760 if ( categoryNames( "Contacts" ).count() ) 756 if ( categoryNames( "Contacts" ).count() )
761 { 757 {
762 text += "<br><b>" + QObject::tr( "Category:" ) + "</b> "; 758 text += "<br><b>" + QObject::tr( "Category:" ) + "</b> ";
763 text += categoryNames( "Contacts" ).join( ", " ); 759 text += categoryNames( "Contacts" ).join( ", " );
764 } 760 }
765 761
766 // notes last 762 // notes last
767 if ( !( value = notes() ).isEmpty() ) 763 if ( !( value = notes() ).isEmpty() )
768 { 764 {
769 text += "<br><hr><b>" + QObject::tr( "Notes:" ) + "</b> "; 765 text += "<br><hr><b>" + QObject::tr( "Notes:" ) + "</b> ";
770 QRegExp reg( "\n" ); 766 QRegExp reg( "\n" );
771 767
772 //QString tmp = Qtopia::escapeString(value); 768 //QString tmp = Qtopia::escapeString(value);
773 QString tmp = QStyleSheet::convertFromPlainText( value ); 769 QString tmp = QStyleSheet::convertFromPlainText( value );
774 //tmp.replace( reg, "<br>" ); 770 //tmp.replace( reg, "<br>" );
775 text += "<br>" + tmp + "<br>"; 771 text += "<br>" + tmp + "<br>";
776 } 772 }
777 return text; 773 return text;
778} 774}
779 775
780/*! 776/*!
781 \internal 777 \internal
782*/ 778*/
783void OPimContact::insert( int key, const QString &v ) 779void OPimContact::insert( int key, const QString &v )
784{ 780{
785 QString value = v.stripWhiteSpace(); 781 QString value = v.stripWhiteSpace();
786 if ( value.isEmpty() ) 782 if ( value.isEmpty() )
787 mMap.remove( key ); 783 mMap.remove( key );
788 else 784 else
789 mMap.insert( key, value ); 785 mMap.insert( key, value );
790} 786}
791 787
792/*! 788/*!
793 \internal 789 \internal
794*/ 790*/
795void OPimContact::replace( int key, const QString & v ) 791void OPimContact::replace( int key, const QString & v )
796{ 792{
797 QString value = v.stripWhiteSpace(); 793 QString value = v.stripWhiteSpace();
798 if ( value.isEmpty() ) 794 if ( value.isEmpty() )
799 mMap.remove( key ); 795 mMap.remove( key );
800 else 796 else
801 mMap.replace( key, value ); 797 mMap.replace( key, value );
802} 798}
803 799
804/*! 800/*!
805 \internal 801 \internal
806*/ 802*/
807QString OPimContact::find( int key ) const 803QString OPimContact::find( int key ) const
808{ 804{
809 return mMap[ key ]; 805 return mMap[ key ];
810} 806}
811 807
812/*! 808/*!
813 \internal 809 \internal
814*/ 810*/
815QString OPimContact::displayAddress( const QString &street, 811QString OPimContact::displayAddress( const QString &street,
816 const QString &city, 812 const QString &city,
817 const QString &state, 813 const QString &state,
818 const QString &zip, 814 const QString &zip,
819 const QString &country ) const 815 const QString &country ) const
820{ 816{
821 QString s = street; 817 QString s = street;
822 if ( !street.isEmpty() ) 818 if ( !street.isEmpty() )
823 s += "\n"; 819 s += "\n";
824 s += city; 820 s += city;
825 if ( !city.isEmpty() && !state.isEmpty() ) 821 if ( !city.isEmpty() && !state.isEmpty() )
826 s += ", "; 822 s += ", ";
827 s += state; 823 s += state;
828 if ( !state.isEmpty() && !zip.isEmpty() ) 824 if ( !state.isEmpty() && !zip.isEmpty() )
829 s += " "; 825 s += " ";
830 s += zip; 826 s += zip;
831 if ( !country.isEmpty() && !s.isEmpty() ) 827 if ( !country.isEmpty() && !s.isEmpty() )
832 s += "\n"; 828 s += "\n";
833 s += country; 829 s += country;
834 return s; 830 return s;
835} 831}
836 832
837/*! 833/*!
838 \internal 834 \internal
839*/ 835*/
840QString OPimContact::displayBusinessAddress() const 836QString OPimContact::displayBusinessAddress() const
841{ 837{
842 return displayAddress( businessStreet(), businessCity(), 838 return displayAddress( businessStreet(), businessCity(),
843 businessState(), businessZip(), 839 businessState(), businessZip(),
844 businessCountry() ); 840 businessCountry() );
845} 841}
846 842
847/*! 843/*!
848 \internal 844 \internal
849*/ 845*/
850QString OPimContact::displayHomeAddress() const 846QString OPimContact::displayHomeAddress() const
851{ 847{
852 return displayAddress( homeStreet(), homeCity(), 848 return displayAddress( homeStreet(), homeCity(),
853 homeState(), homeZip(), 849 homeState(), homeZip(),
854 homeCountry() ); 850 homeCountry() );
855} 851}
856 852
857/*! 853/*!
858 Returns the full name of the contact 854 Returns the full name of the contact
859*/ 855*/
860QString OPimContact::fullName() const 856QString OPimContact::fullName() const
861{ 857{
862 QString title = find( Qtopia::Title ); 858 QString title = find( Qtopia::Title );
863 QString firstName = find( Qtopia::FirstName ); 859 QString firstName = find( Qtopia::FirstName );
864 QString middleName = find( Qtopia::MiddleName ); 860 QString middleName = find( Qtopia::MiddleName );
865 QString lastName = find( Qtopia::LastName ); 861 QString lastName = find( Qtopia::LastName );
866 QString suffix = find( Qtopia::Suffix ); 862 QString suffix = find( Qtopia::Suffix );
867 863
868 QString name = title; 864 QString name = title;
869 if ( !firstName.isEmpty() ) 865 if ( !firstName.isEmpty() )
870 { 866 {
871 if ( !name.isEmpty() ) 867 if ( !name.isEmpty() )
872 name += " "; 868 name += " ";
873 name += firstName; 869 name += firstName;
874 } 870 }
875 if ( !middleName.isEmpty() ) 871 if ( !middleName.isEmpty() )
876 { 872 {
877 if ( !name.isEmpty() ) 873 if ( !name.isEmpty() )
878 name += " "; 874 name += " ";
879 name += middleName; 875 name += middleName;
880 } 876 }
881 if ( !lastName.isEmpty() ) 877 if ( !lastName.isEmpty() )
882 { 878 {
883 if ( !name.isEmpty() ) 879 if ( !name.isEmpty() )
884 name += " "; 880 name += " ";
885 name += lastName; 881 name += lastName;
886 } 882 }
887 if ( !suffix.isEmpty() ) 883 if ( !suffix.isEmpty() )
888 { 884 {
889 if ( !name.isEmpty() ) 885 if ( !name.isEmpty() )
890 name += " "; 886 name += " ";
891 name += suffix; 887 name += suffix;
892 } 888 }
893 return name.simplifyWhiteSpace(); 889 return name.simplifyWhiteSpace();
894} 890}
895 891
896/*! 892/*!
897 Returns a list of the names of the children of the contact. 893 Returns a list of the names of the children of the contact.
898*/ 894*/
899QStringList OPimContact::childrenList() const 895QStringList OPimContact::childrenList() const
900{ 896{
901 return QStringList::split( " ", find( Qtopia::Children ) ); 897 return QStringList::split( " ", find( Qtopia::Children ) );
902} 898}
903 899
904/*! \fn void OPimContact::insertEmail( const QString &email ) 900/*! \fn void OPimContact::insertEmail( const QString &email )
905 901
906 Insert \a email into the email list. Ensures \a email can only be added 902 Insert \a email into the email list. Ensures \a email can only be added
907 once. If there is no default email address set, it sets it to the \a email. 903 once. If there is no default email address set, it sets it to the \a email.
908*/ 904*/
909 905
910/*! \fn void OPimContact::removeEmail( const QString &email ) 906/*! \fn void OPimContact::removeEmail( const QString &email )
911 907
912 Removes the \a email from the email list. If the default email was \a email, 908 Removes the \a email from the email list. If the default email was \a email,
913 then the default email address is assigned to the first email in the 909 then the default email address is assigned to the first email in the
914 email list 910 email list
915*/ 911*/
916 912
917/*! \fn void OPimContact::clearEmails() 913/*! \fn void OPimContact::clearEmails()
918 914
919 Clears the email list. 915 Clears the email list.
920 */ 916 */
921 917
922/*! \fn void OPimContact::insertEmails( const QStringList &emailList ) 918/*! \fn void OPimContact::insertEmails( const QStringList &emailList )
923 919
924 Appends the \a emailList to the exiting email list 920 Appends the \a emailList to the exiting email list
925 */ 921 */
926 922
927/*! 923/*!
928 Returns a list of email addresses belonging to the contact, including 924 Returns a list of email addresses belonging to the contact, including
929 the default email address. 925 the default email address.
930*/ 926*/
931QStringList OPimContact::emailList() const 927QStringList OPimContact::emailList() const
932{ 928{
933 QString emailStr = emails(); 929 QString emailStr = emails();
934 930
935 QStringList r; 931 QStringList r;
936 if ( !emailStr.isEmpty() ) 932 if ( !emailStr.isEmpty() )
937 { 933 {
938 qDebug( " emailstr " ); 934 qDebug( " emailstr " );
939 QStringList l = QStringList::split( emailSeparator(), emailStr ); 935 QStringList l = QStringList::split( emailSeparator(), emailStr );
940 for ( QStringList::ConstIterator it = l.begin();it != l.end();++it ) 936 for ( QStringList::ConstIterator it = l.begin();it != l.end();++it )
941 r += ( *it ).simplifyWhiteSpace(); 937 r += ( *it ).simplifyWhiteSpace();
942 } 938 }
943 939
944 return r; 940 return r;
945} 941}
946 942
947/*! 943/*!
948 \overload 944 \overload
949 945
950 Generates the string for the contact to be filed as from the first, 946 Generates the string for the contact to be filed as from the first,
951 middle and last name of the contact. 947 middle and last name of the contact.
952*/ 948*/
953void OPimContact::setFileAs() 949void OPimContact::setFileAs()
954{ 950{
955 QString lastName, firstName, middleName, fileas; 951 QString lastName, firstName, middleName, fileas;
956 952
957 lastName = find( Qtopia::LastName ); 953 lastName = find( Qtopia::LastName );
958 firstName = find( Qtopia::FirstName ); 954 firstName = find( Qtopia::FirstName );
959 middleName = find( Qtopia::MiddleName ); 955 middleName = find( Qtopia::MiddleName );
960 if ( !lastName.isEmpty() && !firstName.isEmpty() 956 if ( !lastName.isEmpty() && !firstName.isEmpty()
961 && !middleName.isEmpty() ) 957 && !middleName.isEmpty() )
962 fileas = lastName + ", " + firstName + " " + middleName; 958 fileas = lastName + ", " + firstName + " " + middleName;
963 else if ( !lastName.isEmpty() && !firstName.isEmpty() ) 959 else if ( !lastName.isEmpty() && !firstName.isEmpty() )
964 fileas = lastName + ", " + firstName; 960 fileas = lastName + ", " + firstName;
965 else if ( !lastName.isEmpty() || !firstName.isEmpty() || 961 else if ( !lastName.isEmpty() || !firstName.isEmpty() ||
966 !middleName.isEmpty() ) 962 !middleName.isEmpty() )
967 fileas = firstName + ( firstName.isEmpty() ? "" : " " ) 963 fileas = firstName + ( firstName.isEmpty() ? "" : " " )
968 + middleName + ( middleName.isEmpty() ? "" : " " ) 964 + middleName + ( middleName.isEmpty() ? "" : " " )
969 + lastName; 965 + lastName;
970 966
971 replace( Qtopia::FileAs, fileas ); 967 replace( Qtopia::FileAs, fileas );
972} 968}
973 969
974/*! 970/*!
975 \internal 971 \internal
976 Appends the contact information to \a buf. 972 Appends the contact information to \a buf.
977*/ 973*/
978void OPimContact::save( QString &buf ) const 974void OPimContact::save( QString &buf ) const
979{ 975{
980 static const QStringList SLFIELDS = fields(); 976 static const QStringList SLFIELDS = fields();
981 // I'm expecting "<Contact " in front of this... 977 // I'm expecting "<Contact " in front of this...
982 for ( QMap<int, QString>::ConstIterator it = mMap.begin(); 978 for ( QMap<int, QString>::ConstIterator it = mMap.begin();
983 it != mMap.end(); ++it ) 979 it != mMap.end(); ++it )
984 { 980 {
985 const QString &value = it.data(); 981 const QString &value = it.data();
986 int key = it.key(); 982 int key = it.key();
987 if ( !value.isEmpty() ) 983 if ( !value.isEmpty() )
988 { 984 {
989 if ( key == Qtopia::AddressCategory || key == Qtopia::AddressUid ) 985 if ( key == Qtopia::AddressCategory || key == Qtopia::AddressUid )
990 continue; 986 continue;
991 987
992 key -= Qtopia::AddressCategory + 1; 988 key -= Qtopia::AddressCategory + 1;
993 buf += SLFIELDS[ key ]; 989 buf += SLFIELDS[ key ];
994 buf += "=\"" + Qtopia::escapeString( value ) + "\" "; 990 buf += "=\"" + Qtopia::escapeString( value ) + "\" ";
995 } 991 }
996 } 992 }
997 buf += customToXml(); 993 buf += customToXml();
998 if ( categories().count() > 0 ) 994 if ( categories().count() > 0 )
999 buf += "Categories=\"" + idsToString( categories() ) + "\" "; 995 buf += "Categories=\"" + idsToString( categories() ) + "\" ";
1000 buf += "Uid=\"" + QString::number( uid() ) + "\" "; 996 buf += "Uid=\"" + QString::number( uid() ) + "\" ";
1001 // You need to close this yourself 997 // You need to close this yourself
1002} 998}
1003 999
1004 1000
1005/*! 1001/*!
1006 \internal 1002 \internal
1007 Returns the list of fields belonging to a contact 1003 Returns the list of fields belonging to a contact
1008 Never change order of this list ! It has to be regarding 1004 Never change order of this list ! It has to be regarding
1009 enum AddressBookFields !! 1005 enum AddressBookFields !!
1010*/ 1006*/
1011QStringList OPimContact::fields() 1007QStringList OPimContact::fields()
1012{ 1008{
1013 QStringList list; 1009 QStringList list;
1014 1010
1015 list.append( "Title" ); // Not Used! 1011 list.append( "Title" ); // Not Used!
1016 list.append( "FirstName" ); 1012 list.append( "FirstName" );
1017 list.append( "MiddleName" ); 1013 list.append( "MiddleName" );
1018 list.append( "LastName" ); 1014 list.append( "LastName" );
1019 list.append( "Suffix" ); 1015 list.append( "Suffix" );
1020 list.append( "FileAs" ); 1016 list.append( "FileAs" );
1021 1017
1022 list.append( "JobTitle" ); 1018 list.append( "JobTitle" );
1023 list.append( "Department" ); 1019 list.append( "Department" );
1024 list.append( "Company" ); 1020 list.append( "Company" );
1025 list.append( "BusinessPhone" ); 1021 list.append( "BusinessPhone" );
1026 list.append( "BusinessFax" ); 1022 list.append( "BusinessFax" );
1027 list.append( "BusinessMobile" ); 1023 list.append( "BusinessMobile" );
1028 1024
1029 list.append( "DefaultEmail" ); 1025 list.append( "DefaultEmail" );
1030 list.append( "Emails" ); 1026 list.append( "Emails" );
1031 1027
1032 list.append( "HomePhone" ); 1028 list.append( "HomePhone" );
1033 list.append( "HomeFax" ); 1029 list.append( "HomeFax" );
1034 list.append( "HomeMobile" ); 1030 list.append( "HomeMobile" );
1035 1031
1036 list.append( "BusinessStreet" ); 1032 list.append( "BusinessStreet" );
1037 list.append( "BusinessCity" ); 1033 list.append( "BusinessCity" );
1038 list.append( "BusinessState" ); 1034 list.append( "BusinessState" );
1039 list.append( "BusinessZip" ); 1035 list.append( "BusinessZip" );
1040 list.append( "BusinessCountry" ); 1036 list.append( "BusinessCountry" );
1041 list.append( "BusinessPager" ); 1037 list.append( "BusinessPager" );
1042 list.append( "BusinessWebPage" ); 1038 list.append( "BusinessWebPage" );
1043 1039
1044 list.append( "Office" ); 1040 list.append( "Office" );
1045 list.append( "Profession" ); 1041 list.append( "Profession" );
1046 list.append( "Assistant" ); 1042 list.append( "Assistant" );
1047 list.append( "Manager" ); 1043 list.append( "Manager" );
1048 1044
1049 list.append( "HomeStreet" ); 1045 list.append( "HomeStreet" );
1050 list.append( "HomeCity" ); 1046 list.append( "HomeCity" );
1051 list.append( "HomeState" ); 1047 list.append( "HomeState" );
1052 list.append( "HomeZip" ); 1048 list.append( "HomeZip" );
1053 list.append( "HomeCountry" ); 1049 list.append( "HomeCountry" );
1054 list.append( "HomeWebPage" ); 1050 list.append( "HomeWebPage" );
1055 1051
1056 list.append( "Spouse" ); 1052 list.append( "Spouse" );
1057 list.append( "Gender" ); 1053 list.append( "Gender" );
1058 list.append( "Birthday" ); 1054 list.append( "Birthday" );
1059 list.append( "Anniversary" ); 1055 list.append( "Anniversary" );
1060 list.append( "Nickname" ); 1056 list.append( "Nickname" );
1061 list.append( "Children" ); 1057 list.append( "Children" );
1062 1058
1063 list.append( "Notes" ); 1059 list.append( "Notes" );
1064 list.append( "Groups" ); 1060 list.append( "Groups" );
1065 1061
1066 return list; 1062 return list;
1067} 1063}
1068 1064
1069 1065
1070/*! 1066/*!
1071 Sets the list of email address for contact to those contained in \a str. 1067 Sets the list of email address for contact to those contained in \a str.
1072 Email address should be separated by ';'s. 1068 Email address should be separated by ';'s.
1073*/ 1069*/
1074void OPimContact::setEmails( const QString &str ) 1070void OPimContact::setEmails( const QString &str )
1075{ 1071{
1076 replace( Qtopia::Emails, str ); 1072 replace( Qtopia::Emails, str );
1077 if ( str.isEmpty() ) 1073 if ( str.isEmpty() )
1078 setDefaultEmail( QString::null ); 1074 setDefaultEmail( QString::null );
1079} 1075}
1080 1076
1081/*! 1077/*!
1082 Sets the list of children for the contact to those contained in \a str. 1078 Sets the list of children for the contact to those contained in \a str.
1083*/ 1079*/
1084void OPimContact::setChildren( const QString &str ) 1080void OPimContact::setChildren( const QString &str )
1085{ 1081{
1086 replace( Qtopia::Children, str ); 1082 replace( Qtopia::Children, str );
1087} 1083}
1088 1084
1089/*! 1085/*!
1090 \overload 1086 \overload
1091 Returns TRUE if the contact matches the regular expression \a regexp. 1087 Returns TRUE if the contact matches the regular expression \a regexp.
1092 Otherwise returns FALSE. 1088 Otherwise returns FALSE.
1093*/ 1089*/
1094bool OPimContact::match( const QRegExp &r ) const 1090bool OPimContact::match( const QRegExp &r ) const
1095{ 1091{
1096 setLastHitField( -1 ); 1092 setLastHitField( -1 );
1097 bool match; 1093 bool match;
1098 match = false; 1094 match = false;
1099 QMap<int, QString>::ConstIterator it; 1095 QMap<int, QString>::ConstIterator it;
1100 for ( it = mMap.begin(); it != mMap.end(); ++it ) 1096 for ( it = mMap.begin(); it != mMap.end(); ++it )
1101 { 1097 {
1102 if ( ( *it ).find( r ) > -1 ) 1098 if ( ( *it ).find( r ) > -1 )
1103 { 1099 {
1104 setLastHitField( it.key() ); 1100 setLastHitField( it.key() );
1105 match = true; 1101 match = true;
1106 break; 1102 break;
1107 } 1103 }
1108 } 1104 }
1109 return match; 1105 return match;
1110} 1106}
1111 1107
1112 1108
1113QString OPimContact::toShortText() const 1109QString OPimContact::toShortText() const
1114{ 1110{
1115 return ( fullName() ); 1111 return ( fullName() );
1116} 1112}
1117 1113
1118 1114
1119QString OPimContact::type() const 1115QString OPimContact::type() const
1120{ 1116{
1121 return QString::fromLatin1( "OPimContact" ); 1117 return QString::fromLatin1( "OPimContact" );
1122} 1118}
1123 1119
1124 1120
1125class QString OPimContact::recordField( int pos ) const 1121class QString OPimContact::recordField( int pos ) const
1126{ 1122{
1127 QStringList SLFIELDS = fields(); // ?? why this ? (se) 1123 QStringList SLFIELDS = fields(); // ?? why this ? (se)
1128 return SLFIELDS[ pos ]; 1124 return SLFIELDS[ pos ];
1129} 1125}
1130 1126
1131// In future releases, we should store birthday and anniversary 1127// In future releases, we should store birthday and anniversary
1132// internally as QDate instead of QString ! 1128// internally as QDate instead of QString !
1133// QString is always too complicate to interprete (DD.MM.YY, DD/MM/YY, MM/DD/YY, etc..)(se) 1129// QString is always too complicate to interprete (DD.MM.YY, DD/MM/YY, MM/DD/YY, etc..)(se)
1134 1130
1135/*! \fn void OPimContact::setBirthday( const QDate& date ) 1131/*! \fn void OPimContact::setBirthday( const QDate& date )
1136 Sets the birthday for the contact to \a date. If date is null 1132 Sets the birthday for the contact to \a date. If date is null
1137 the current stored date will be removed. 1133 the current stored date will be removed.
1138*/ 1134*/
1139void OPimContact::setBirthday( const QDate &v ) 1135void OPimContact::setBirthday( const QDate &v )
1140{ 1136{
1141 if ( v.isNull() ) 1137 if ( v.isNull() )
1142 { 1138 {
1143 qWarning( "Remove Birthday" ); 1139 qWarning( "Remove Birthday" );
1144 replace( Qtopia::Birthday, QString::null ); 1140 replace( Qtopia::Birthday, QString::null );
1145 return ; 1141 return ;
1146 } 1142 }
1147 1143
1148 if ( v.isValid() ) 1144 if ( v.isValid() )
1149 replace( Qtopia::Birthday, OPimDateConversion::dateToString( v ) ); 1145 replace( Qtopia::Birthday, OPimDateConversion::dateToString( v ) );
1150 1146
1151} 1147}
1152 1148
1153 1149
1154/*! \fn void OPimContact::setAnniversary( const QDate &date ) 1150/*! \fn void OPimContact::setAnniversary( const QDate &date )
1155 Sets the anniversary of the contact to \a date. If date is 1151 Sets the anniversary of the contact to \a date. If date is
1156 null, the current stored date will be removed. 1152 null, the current stored date will be removed.
1157*/ 1153*/
1158void OPimContact::setAnniversary( const QDate &v ) 1154void OPimContact::setAnniversary( const QDate &v )
1159{ 1155{
1160 if ( v.isNull() ) 1156 if ( v.isNull() )
1161 { 1157 {
1162 qWarning( "Remove Anniversary" ); 1158 qWarning( "Remove Anniversary" );
1163 replace( Qtopia::Anniversary, QString::null ); 1159 replace( Qtopia::Anniversary, QString::null );
1164 return ; 1160 return ;
1165 } 1161 }
1166 1162
1167 if ( v.isValid() ) 1163 if ( v.isValid() )
1168 replace( Qtopia::Anniversary, OPimDateConversion::dateToString( v ) ); 1164 replace( Qtopia::Anniversary, OPimDateConversion::dateToString( v ) );
1169} 1165}
1170 1166
1171 1167
1172/*! \fn QDate OPimContact::birthday() const 1168/*! \fn QDate OPimContact::birthday() const
1173 Returns the birthday of the contact. 1169 Returns the birthday of the contact.
1174*/ 1170*/
1175QDate OPimContact::birthday() const 1171QDate OPimContact::birthday() const
1176{ 1172{
1177 QString str = find( Qtopia::Birthday ); 1173 QString str = find( Qtopia::Birthday );
1178 // qWarning ("Birthday %s", str.latin1() ); 1174 // qWarning ("Birthday %s", str.latin1() );
1179 if ( !str.isEmpty() ) 1175 if ( !str.isEmpty() )
1180 return OPimDateConversion::dateFromString ( str ); 1176 return OPimDateConversion::dateFromString ( str );
1181 else 1177 else
1182 return QDate(); 1178 return QDate();
1183} 1179}
1184 1180
1185 1181
1186/*! \fn QDate OPimContact::anniversary() const 1182/*! \fn QDate OPimContact::anniversary() const
1187 Returns the anniversary of the contact. 1183 Returns the anniversary of the contact.
1188*/ 1184*/
1189QDate OPimContact::anniversary() const 1185QDate OPimContact::anniversary() const
1190{ 1186{
1191 QDate empty; 1187 QDate empty;
1192 QString str = find( Qtopia::Anniversary ); 1188 QString str = find( Qtopia::Anniversary );
1193 // qWarning ("Anniversary %s", str.latin1() ); 1189 // qWarning ("Anniversary %s", str.latin1() );
1194 if ( !str.isEmpty() ) 1190 if ( !str.isEmpty() )
1195 return OPimDateConversion::dateFromString ( str ); 1191 return OPimDateConversion::dateFromString ( str );
1196 else 1192 else
1197 return empty; 1193 return empty;
1198} 1194}
1199 1195
1200 1196
1201void OPimContact::insertEmail( const QString &v ) 1197void OPimContact::insertEmail( const QString &v )
1202{ 1198{
1203 //qDebug("insertEmail %s", v.latin1()); 1199 //qDebug("insertEmail %s", v.latin1());
1204 QString e = v.simplifyWhiteSpace(); 1200 QString e = v.simplifyWhiteSpace();
1205 QString def = defaultEmail(); 1201 QString def = defaultEmail();
1206 1202
1207 // if no default, set it as the default email and don't insert 1203 // if no default, set it as the default email and don't insert
1208 if ( def.isEmpty() ) 1204 if ( def.isEmpty() )
1209 { 1205 {
1210 setDefaultEmail( e ); // will insert into the list for us 1206 setDefaultEmail( e ); // will insert into the list for us
1211 return ; 1207 return ;
1212 } 1208 }
1213 1209
1214 // otherwise, insert assuming doesn't already exist 1210 // otherwise, insert assuming doesn't already exist
1215 QString emailsStr = find( Qtopia::Emails ); 1211 QString emailsStr = find( Qtopia::Emails );
1216 if ( emailsStr.contains( e ) ) 1212 if ( emailsStr.contains( e ) )
1217 return ; 1213 return ;
1218 if ( !emailsStr.isEmpty() ) 1214 if ( !emailsStr.isEmpty() )
1219 emailsStr += emailSeparator(); 1215 emailsStr += emailSeparator();
1220 emailsStr += e; 1216 emailsStr += e;
1221 replace( Qtopia::Emails, emailsStr ); 1217 replace( Qtopia::Emails, emailsStr );
1222} 1218}
1223 1219
1224 1220
1225 void OPimContact::removeEmail( const QString &v ) 1221 void OPimContact::removeEmail( const QString &v )
1226{ 1222{
1227 QString e = v.simplifyWhiteSpace(); 1223 QString e = v.simplifyWhiteSpace();
1228 QString def = defaultEmail(); 1224 QString def = defaultEmail();
1229 QString emailsStr = find( Qtopia::Emails ); 1225 QString emailsStr = find( Qtopia::Emails );
1230 QStringList emails = emailList(); 1226 QStringList emails = emailList();
1231 1227
1232 // otherwise, must first contain it 1228 // otherwise, must first contain it
1233 if ( !emailsStr.contains( e ) ) 1229 if ( !emailsStr.contains( e ) )
1234 return ; 1230 return ;
1235 1231
1236 // remove it 1232 // remove it
1237 //qDebug(" removing email from list %s", e.latin1()); 1233 //qDebug(" removing email from list %s", e.latin1());
1238 emails.remove( e ); 1234 emails.remove( e );
1239 // reset the string 1235 // reset the string
1240 emailsStr = emails.join( emailSeparator() ); // Sharp's brain dead separator 1236 emailsStr = emails.join( emailSeparator() ); // Sharp's brain dead separator
1241 replace( Qtopia::Emails, emailsStr ); 1237 replace( Qtopia::Emails, emailsStr );
1242 1238
1243 // if default, then replace the default email with the first one 1239 // if default, then replace the default email with the first one
1244 if ( def == e ) 1240 if ( def == e )
1245 { 1241 {
1246 //qDebug("removeEmail is default; setting new default"); 1242 //qDebug("removeEmail is default; setting new default");
1247 if ( !emails.count() ) 1243 if ( !emails.count() )
1248 clearEmails(); 1244 clearEmails();
1249 else // setDefaultEmail will remove e from the list 1245 else // setDefaultEmail will remove e from the list
1250 setDefaultEmail( emails.first() ); 1246 setDefaultEmail( emails.first() );
1251 } 1247 }
1252} 1248}
1253 1249
1254 1250
1255void OPimContact::clearEmails() 1251void OPimContact::clearEmails()
1256{ 1252{
1257 mMap.remove( Qtopia::DefaultEmail ); 1253 mMap.remove( Qtopia::DefaultEmail );
1258 mMap.remove( Qtopia::Emails ); 1254 mMap.remove( Qtopia::Emails );
1259} 1255}
1260 1256
1261 1257
1262void OPimContact::setDefaultEmail( const QString &v ) 1258void OPimContact::setDefaultEmail( const QString &v )
1263{ 1259{
1264 QString e = v.simplifyWhiteSpace(); 1260 QString e = v.simplifyWhiteSpace();
1265 1261
1266 //qDebug("OPimContact::setDefaultEmail %s", e.latin1()); 1262 //qDebug("OPimContact::setDefaultEmail %s", e.latin1());
1267 replace( Qtopia::DefaultEmail, e ); 1263 replace( Qtopia::DefaultEmail, e );
1268 1264
1269 if ( !e.isEmpty() ) 1265 if ( !e.isEmpty() )
1270 insertEmail( e ); 1266 insertEmail( e );
1271 1267
1272} 1268}
1273 1269
1274 1270
1275void OPimContact::insertEmails( const QStringList &v ) 1271void OPimContact::insertEmails( const QStringList &v )
1276{ 1272{
1277 for ( QStringList::ConstIterator it = v.begin(); it != v.end(); ++it ) 1273 for ( QStringList::ConstIterator it = v.begin(); it != v.end(); ++it )
1278 insertEmail( *it ); 1274 insertEmail( *it );
1279} 1275}
1280 1276
1281 1277
1282int OPimContact::rtti() 1278int OPimContact::rtti()
1283{ 1279{
1284 return OPimResolver::AddressBook; 1280 return OPimResolver::AddressBook;
1285} 1281}
1286 1282
1287 1283
1288void OPimContact::setUid( int i ) 1284void OPimContact::setUid( int i )
1289{ 1285{
1290 OPimRecord::setUid( i ); 1286 OPimRecord::setUid( i );
1291 replace( Qtopia::AddressUid , QString::number( i ) ); 1287 replace( Qtopia::AddressUid , QString::number( i ) );
1292} 1288}
1293} 1289}
diff --git a/libopie2/opiepim/core/opimcontactfields.cpp b/libopie2/opiepim/core/opimcontactfields.cpp
index 4b0ba3b..120beb6 100644
--- a/libopie2/opiepim/core/opimcontactfields.cpp
+++ b/libopie2/opiepim/core/opimcontactfields.cpp
@@ -1,518 +1,516 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) Stefan Eilers <eilers.stefan@epost.de> 3 Copyright (C) Stefan Eilers <eilers.stefan@epost.de>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 4 =. Copyright (C) The Opie Team <opie-devel@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 "opimcontactfields.h" 30#include "opimcontactfields.h"
31 31
32/* OPIE */ 32/* OPIE */
33#include <opie2/opimcontact.h> 33#include <opie2/opimcontact.h>
34#include <qpe/recordfields.h> // We should use our own enum in the future ..
35#include <qpe/config.h> 34#include <qpe/config.h>
36 35
37/* QT */ 36/* QT */
38#include <qobject.h> 37#include <qobject.h>
39#include <qstringlist.h>
40 38
41 39
42namespace Opie 40namespace Opie
43{ 41{
44/*! 42/*!
45 \internal 43 \internal
46 Returns a list of personal field names for a contact. 44 Returns a list of personal field names for a contact.
47*/ 45*/
48QStringList OPimContactFields::personalfields( bool sorted, bool translated ) 46QStringList OPimContactFields::personalfields( bool sorted, bool translated )
49{ 47{
50 QStringList list; 48 QStringList list;
51 QMap<int, QString> mapIdToStr; 49 QMap<int, QString> mapIdToStr;
52 if ( translated ) 50 if ( translated )
53 mapIdToStr = idToTrFields(); 51 mapIdToStr = idToTrFields();
54 else 52 else
55 mapIdToStr = idToUntrFields(); 53 mapIdToStr = idToUntrFields();
56 54
57 list.append( mapIdToStr[ Qtopia::AddressUid ] ); 55 list.append( mapIdToStr[ Qtopia::AddressUid ] );
58 list.append( mapIdToStr[ Qtopia::AddressCategory ] ); 56 list.append( mapIdToStr[ Qtopia::AddressCategory ] );
59 57
60 list.append( mapIdToStr[ Qtopia::Title ] ); 58 list.append( mapIdToStr[ Qtopia::Title ] );
61 list.append( mapIdToStr[ Qtopia::FirstName ] ); 59 list.append( mapIdToStr[ Qtopia::FirstName ] );
62 list.append( mapIdToStr[ Qtopia::MiddleName ] ); 60 list.append( mapIdToStr[ Qtopia::MiddleName ] );
63 list.append( mapIdToStr[ Qtopia::LastName ] ); 61 list.append( mapIdToStr[ Qtopia::LastName ] );
64 list.append( mapIdToStr[ Qtopia::Suffix ] ); 62 list.append( mapIdToStr[ Qtopia::Suffix ] );
65 list.append( mapIdToStr[ Qtopia::FileAs ] ); 63 list.append( mapIdToStr[ Qtopia::FileAs ] );
66 64
67 list.append( mapIdToStr[ Qtopia::JobTitle ] ); 65 list.append( mapIdToStr[ Qtopia::JobTitle ] );
68 list.append( mapIdToStr[ Qtopia::Department ] ); 66 list.append( mapIdToStr[ Qtopia::Department ] );
69 list.append( mapIdToStr[ Qtopia::Company ] ); 67 list.append( mapIdToStr[ Qtopia::Company ] );
70 68
71 list.append( mapIdToStr[ Qtopia::Notes ] ); 69 list.append( mapIdToStr[ Qtopia::Notes ] );
72 list.append( mapIdToStr[ Qtopia::Groups ] ); 70 list.append( mapIdToStr[ Qtopia::Groups ] );
73 71
74 if ( sorted ) list.sort(); 72 if ( sorted ) list.sort();
75 return list; 73 return list;
76} 74}
77 75
78/*! 76/*!
79 \internal 77 \internal
80 Returns a list of details field names for a contact. 78 Returns a list of details field names for a contact.
81*/ 79*/
82QStringList OPimContactFields::detailsfields( bool sorted, bool translated ) 80QStringList OPimContactFields::detailsfields( bool sorted, bool translated )
83{ 81{
84 QStringList list; 82 QStringList list;
85 QMap<int, QString> mapIdToStr; 83 QMap<int, QString> mapIdToStr;
86 if ( translated ) 84 if ( translated )
87 mapIdToStr = idToTrFields(); 85 mapIdToStr = idToTrFields();
88 else 86 else
89 mapIdToStr = idToUntrFields(); 87 mapIdToStr = idToUntrFields();
90 88
91 list.append( mapIdToStr[ Qtopia::Office ] ); 89 list.append( mapIdToStr[ Qtopia::Office ] );
92 list.append( mapIdToStr[ Qtopia::Profession ] ); 90 list.append( mapIdToStr[ Qtopia::Profession ] );
93 list.append( mapIdToStr[ Qtopia::Assistant ] ); 91 list.append( mapIdToStr[ Qtopia::Assistant ] );
94 list.append( mapIdToStr[ Qtopia::Manager ] ); 92 list.append( mapIdToStr[ Qtopia::Manager ] );
95 93
96 list.append( mapIdToStr[ Qtopia::Spouse ] ); 94 list.append( mapIdToStr[ Qtopia::Spouse ] );
97 list.append( mapIdToStr[ Qtopia::Gender ] ); 95 list.append( mapIdToStr[ Qtopia::Gender ] );
98 list.append( mapIdToStr[ Qtopia::Birthday ] ); 96 list.append( mapIdToStr[ Qtopia::Birthday ] );
99 list.append( mapIdToStr[ Qtopia::Anniversary ] ); 97 list.append( mapIdToStr[ Qtopia::Anniversary ] );
100 list.append( mapIdToStr[ Qtopia::Nickname ] ); 98 list.append( mapIdToStr[ Qtopia::Nickname ] );
101 list.append( mapIdToStr[ Qtopia::Children ] ); 99 list.append( mapIdToStr[ Qtopia::Children ] );
102 100
103 if ( sorted ) list.sort(); 101 if ( sorted ) list.sort();
104 return list; 102 return list;
105} 103}
106 104
107/*! 105/*!
108 \internal 106 \internal
109 Returns a list of phone field names for a contact. 107 Returns a list of phone field names for a contact.
110*/ 108*/
111QStringList OPimContactFields::phonefields( bool sorted, bool translated ) 109QStringList OPimContactFields::phonefields( bool sorted, bool translated )
112{ 110{
113 QStringList list; 111 QStringList list;
114 QMap<int, QString> mapIdToStr; 112 QMap<int, QString> mapIdToStr;
115 if ( translated ) 113 if ( translated )
116 mapIdToStr = idToTrFields(); 114 mapIdToStr = idToTrFields();
117 else 115 else
118 mapIdToStr = idToUntrFields(); 116 mapIdToStr = idToUntrFields();
119 117
120 list.append( mapIdToStr[ Qtopia::BusinessPhone ] ); 118 list.append( mapIdToStr[ Qtopia::BusinessPhone ] );
121 list.append( mapIdToStr[ Qtopia::BusinessFax ] ); 119 list.append( mapIdToStr[ Qtopia::BusinessFax ] );
122 list.append( mapIdToStr[ Qtopia::BusinessMobile ] ); 120 list.append( mapIdToStr[ Qtopia::BusinessMobile ] );
123 list.append( mapIdToStr[ Qtopia::BusinessPager ] ); 121 list.append( mapIdToStr[ Qtopia::BusinessPager ] );
124 list.append( mapIdToStr[ Qtopia::BusinessWebPage ] ); 122 list.append( mapIdToStr[ Qtopia::BusinessWebPage ] );
125 123
126 list.append( mapIdToStr[ Qtopia::DefaultEmail ] ); 124 list.append( mapIdToStr[ Qtopia::DefaultEmail ] );
127 list.append( mapIdToStr[ Qtopia::Emails ] ); 125 list.append( mapIdToStr[ Qtopia::Emails ] );
128 126
129 list.append( mapIdToStr[ Qtopia::HomePhone ] ); 127 list.append( mapIdToStr[ Qtopia::HomePhone ] );
130 list.append( mapIdToStr[ Qtopia::HomeFax ] ); 128 list.append( mapIdToStr[ Qtopia::HomeFax ] );
131 list.append( mapIdToStr[ Qtopia::HomeMobile ] ); 129 list.append( mapIdToStr[ Qtopia::HomeMobile ] );
132 // list.append( mapIdToStr[Qtopia::HomePager] ); 130 // list.append( mapIdToStr[Qtopia::HomePager] );
133 list.append( mapIdToStr[ Qtopia::HomeWebPage ] ); 131 list.append( mapIdToStr[ Qtopia::HomeWebPage ] );
134 132
135 if ( sorted ) list.sort(); 133 if ( sorted ) list.sort();
136 134
137 return list; 135 return list;
138} 136}
139 137
140/*! 138/*!
141 \internal 139 \internal
142 Returns a list of field names for a contact. 140 Returns a list of field names for a contact.
143*/ 141*/
144QStringList OPimContactFields::fields( bool sorted, bool translated ) 142QStringList OPimContactFields::fields( bool sorted, bool translated )
145{ 143{
146 QStringList list; 144 QStringList list;
147 QMap<int, QString> mapIdToStr; 145 QMap<int, QString> mapIdToStr;
148 if ( translated ) 146 if ( translated )
149 mapIdToStr = idToTrFields(); 147 mapIdToStr = idToTrFields();
150 else 148 else
151 mapIdToStr = idToUntrFields(); 149 mapIdToStr = idToUntrFields();
152 150
153 list += personalfields( sorted, translated ); 151 list += personalfields( sorted, translated );
154 152
155 list += phonefields( sorted, translated ); 153 list += phonefields( sorted, translated );
156 154
157 list.append( mapIdToStr[ Qtopia::BusinessStreet ] ); 155 list.append( mapIdToStr[ Qtopia::BusinessStreet ] );
158 list.append( mapIdToStr[ Qtopia::BusinessCity ] ); 156 list.append( mapIdToStr[ Qtopia::BusinessCity ] );
159 list.append( mapIdToStr[ Qtopia::BusinessState ] ); 157 list.append( mapIdToStr[ Qtopia::BusinessState ] );
160 list.append( mapIdToStr[ Qtopia::BusinessZip ] ); 158 list.append( mapIdToStr[ Qtopia::BusinessZip ] );
161 list.append( mapIdToStr[ Qtopia::BusinessCountry ] ); 159 list.append( mapIdToStr[ Qtopia::BusinessCountry ] );
162 160
163 list.append( mapIdToStr[ Qtopia::HomeStreet ] ); 161 list.append( mapIdToStr[ Qtopia::HomeStreet ] );
164 list.append( mapIdToStr[ Qtopia::HomeCity ] ); 162 list.append( mapIdToStr[ Qtopia::HomeCity ] );
165 list.append( mapIdToStr[ Qtopia::HomeState ] ); 163 list.append( mapIdToStr[ Qtopia::HomeState ] );
166 list.append( mapIdToStr[ Qtopia::HomeZip ] ); 164 list.append( mapIdToStr[ Qtopia::HomeZip ] );
167 list.append( mapIdToStr[ Qtopia::HomeCountry ] ); 165 list.append( mapIdToStr[ Qtopia::HomeCountry ] );
168 166
169 list += detailsfields( sorted, translated ); 167 list += detailsfields( sorted, translated );
170 168
171 if ( sorted ) list.sort(); 169 if ( sorted ) list.sort();
172 170
173 return list; 171 return list;
174} 172}
175 173
176 174
177/*! 175/*!
178 \internal 176 \internal
179 Returns an untranslated list of personal field names for a contact. 177 Returns an untranslated list of personal field names for a contact.
180*/ 178*/
181QStringList OPimContactFields::untrpersonalfields( bool sorted ) 179QStringList OPimContactFields::untrpersonalfields( bool sorted )
182{ 180{
183 return personalfields( sorted, false ); 181 return personalfields( sorted, false );
184} 182}
185 183
186 184
187/*! 185/*!
188 \internal 186 \internal
189 Returns a translated list of personal field names for a contact. 187 Returns a translated list of personal field names for a contact.
190*/ 188*/
191QStringList OPimContactFields::trpersonalfields( bool sorted ) 189QStringList OPimContactFields::trpersonalfields( bool sorted )
192{ 190{
193 return personalfields( sorted, true ); 191 return personalfields( sorted, true );
194} 192}
195 193
196 194
197/*! 195/*!
198 \internal 196 \internal
199 Returns an untranslated list of details field names for a contact. 197 Returns an untranslated list of details field names for a contact.
200*/ 198*/
201QStringList OPimContactFields::untrdetailsfields( bool sorted ) 199QStringList OPimContactFields::untrdetailsfields( bool sorted )
202{ 200{
203 return detailsfields( sorted, false ); 201 return detailsfields( sorted, false );
204} 202}
205 203
206 204
207/*! 205/*!
208 \internal 206 \internal
209 Returns a translated list of details field names for a contact. 207 Returns a translated list of details field names for a contact.
210*/ 208*/
211QStringList OPimContactFields::trdetailsfields( bool sorted ) 209QStringList OPimContactFields::trdetailsfields( bool sorted )
212{ 210{
213 return detailsfields( sorted, true ); 211 return detailsfields( sorted, true );
214} 212}
215 213
216 214
217/*! 215/*!
218 \internal 216 \internal
219 Returns a translated list of phone field names for a contact. 217 Returns a translated list of phone field names for a contact.
220*/ 218*/
221QStringList OPimContactFields::trphonefields( bool sorted ) 219QStringList OPimContactFields::trphonefields( bool sorted )
222{ 220{
223 return phonefields( sorted, true ); 221 return phonefields( sorted, true );
224} 222}
225 223
226/*! 224/*!
227 \internal 225 \internal
228 Returns an untranslated list of phone field names for a contact. 226 Returns an untranslated list of phone field names for a contact.
229*/ 227*/
230QStringList OPimContactFields::untrphonefields( bool sorted ) 228QStringList OPimContactFields::untrphonefields( bool sorted )
231{ 229{
232 return phonefields( sorted, false ); 230 return phonefields( sorted, false );
233} 231}
234 232
235 233
236/*! 234/*!
237 \internal 235 \internal
238 Returns a translated list of field names for a contact. 236 Returns a translated list of field names for a contact.
239*/ 237*/
240QStringList OPimContactFields::trfields( bool sorted ) 238QStringList OPimContactFields::trfields( bool sorted )
241{ 239{
242 return fields( sorted, true ); 240 return fields( sorted, true );
243} 241}
244 242
245/*! 243/*!
246 \internal 244 \internal
247 Returns an untranslated list of field names for a contact. 245 Returns an untranslated list of field names for a contact.
248*/ 246*/
249QStringList OPimContactFields::untrfields( bool sorted ) 247QStringList OPimContactFields::untrfields( bool sorted )
250{ 248{
251 return fields( sorted, false ); 249 return fields( sorted, false );
252} 250}
253 251
254QMap<int, QString> OPimContactFields::idToTrFields() 252QMap<int, QString> OPimContactFields::idToTrFields()
255{ 253{
256 QMap<int, QString> ret_map; 254 QMap<int, QString> ret_map;
257 255
258 ret_map.insert( Qtopia::AddressUid, QObject::tr( "User Id" ) ); 256 ret_map.insert( Qtopia::AddressUid, QObject::tr( "User Id" ) );
259 ret_map.insert( Qtopia::AddressCategory, QObject::tr( "Categories" ) ); 257 ret_map.insert( Qtopia::AddressCategory, QObject::tr( "Categories" ) );
260 258
261 ret_map.insert( Qtopia::Title, QObject::tr( "Name Title" ) ); 259 ret_map.insert( Qtopia::Title, QObject::tr( "Name Title" ) );
262 ret_map.insert( Qtopia::FirstName, QObject::tr( "First Name" ) ); 260 ret_map.insert( Qtopia::FirstName, QObject::tr( "First Name" ) );
263 ret_map.insert( Qtopia::MiddleName, QObject::tr( "Middle Name" ) ); 261 ret_map.insert( Qtopia::MiddleName, QObject::tr( "Middle Name" ) );
264 ret_map.insert( Qtopia::LastName, QObject::tr( "Last Name" ) ); 262 ret_map.insert( Qtopia::LastName, QObject::tr( "Last Name" ) );
265 ret_map.insert( Qtopia::Suffix, QObject::tr( "Suffix" ) ); 263 ret_map.insert( Qtopia::Suffix, QObject::tr( "Suffix" ) );
266 ret_map.insert( Qtopia::FileAs, QObject::tr( "File As" ) ); 264 ret_map.insert( Qtopia::FileAs, QObject::tr( "File As" ) );
267 265
268 ret_map.insert( Qtopia::JobTitle, QObject::tr( "Job Title" ) ); 266 ret_map.insert( Qtopia::JobTitle, QObject::tr( "Job Title" ) );
269 ret_map.insert( Qtopia::Department, QObject::tr( "Department" ) ); 267 ret_map.insert( Qtopia::Department, QObject::tr( "Department" ) );
270 ret_map.insert( Qtopia::Company, QObject::tr( "Company" ) ); 268 ret_map.insert( Qtopia::Company, QObject::tr( "Company" ) );
271 ret_map.insert( Qtopia::BusinessPhone, QObject::tr( "Business Phone" ) ); 269 ret_map.insert( Qtopia::BusinessPhone, QObject::tr( "Business Phone" ) );
272 ret_map.insert( Qtopia::BusinessFax, QObject::tr( "Business Fax" ) ); 270 ret_map.insert( Qtopia::BusinessFax, QObject::tr( "Business Fax" ) );
273 ret_map.insert( Qtopia::BusinessMobile, QObject::tr( "Business Mobile" ) ); 271 ret_map.insert( Qtopia::BusinessMobile, QObject::tr( "Business Mobile" ) );
274 272
275 // email 273 // email
276 ret_map.insert( Qtopia::DefaultEmail, QObject::tr( "Default Email" ) ); 274 ret_map.insert( Qtopia::DefaultEmail, QObject::tr( "Default Email" ) );
277 ret_map.insert( Qtopia::Emails, QObject::tr( "Emails" ) ); 275 ret_map.insert( Qtopia::Emails, QObject::tr( "Emails" ) );
278 276
279 ret_map.insert( Qtopia::HomePhone, QObject::tr( "Home Phone" ) ); 277 ret_map.insert( Qtopia::HomePhone, QObject::tr( "Home Phone" ) );
280 ret_map.insert( Qtopia::HomeFax, QObject::tr( "Home Fax" ) ); 278 ret_map.insert( Qtopia::HomeFax, QObject::tr( "Home Fax" ) );
281 ret_map.insert( Qtopia::HomeMobile, QObject::tr( "Home Mobile" ) ); 279 ret_map.insert( Qtopia::HomeMobile, QObject::tr( "Home Mobile" ) );
282 280
283 // business 281 // business
284 ret_map.insert( Qtopia::BusinessStreet, QObject::tr( "Business Street" ) ); 282 ret_map.insert( Qtopia::BusinessStreet, QObject::tr( "Business Street" ) );
285 ret_map.insert( Qtopia::BusinessCity, QObject::tr( "Business City" ) ); 283 ret_map.insert( Qtopia::BusinessCity, QObject::tr( "Business City" ) );
286 ret_map.insert( Qtopia::BusinessState, QObject::tr( "Business State" ) ); 284 ret_map.insert( Qtopia::BusinessState, QObject::tr( "Business State" ) );
287 ret_map.insert( Qtopia::BusinessZip, QObject::tr( "Business Zip" ) ); 285 ret_map.insert( Qtopia::BusinessZip, QObject::tr( "Business Zip" ) );
288 ret_map.insert( Qtopia::BusinessCountry, QObject::tr( "Business Country" ) ); 286 ret_map.insert( Qtopia::BusinessCountry, QObject::tr( "Business Country" ) );
289 ret_map.insert( Qtopia::BusinessPager, QObject::tr( "Business Pager" ) ); 287 ret_map.insert( Qtopia::BusinessPager, QObject::tr( "Business Pager" ) );
290 ret_map.insert( Qtopia::BusinessWebPage, QObject::tr( "Business WebPage" ) ); 288 ret_map.insert( Qtopia::BusinessWebPage, QObject::tr( "Business WebPage" ) );
291 289
292 ret_map.insert( Qtopia::Office, QObject::tr( "Office" ) ); 290 ret_map.insert( Qtopia::Office, QObject::tr( "Office" ) );
293 ret_map.insert( Qtopia::Profession, QObject::tr( "Profession" ) ); 291 ret_map.insert( Qtopia::Profession, QObject::tr( "Profession" ) );
294 ret_map.insert( Qtopia::Assistant, QObject::tr( "Assistant" ) ); 292 ret_map.insert( Qtopia::Assistant, QObject::tr( "Assistant" ) );
295 ret_map.insert( Qtopia::Manager, QObject::tr( "Manager" ) ); 293 ret_map.insert( Qtopia::Manager, QObject::tr( "Manager" ) );
296 294
297 // home 295 // home
298 ret_map.insert( Qtopia::HomeStreet, QObject::tr( "Home Street" ) ); 296 ret_map.insert( Qtopia::HomeStreet, QObject::tr( "Home Street" ) );
299 ret_map.insert( Qtopia::HomeCity, QObject::tr( "Home City" ) ); 297 ret_map.insert( Qtopia::HomeCity, QObject::tr( "Home City" ) );
300 ret_map.insert( Qtopia::HomeState, QObject::tr( "Home State" ) ); 298 ret_map.insert( Qtopia::HomeState, QObject::tr( "Home State" ) );
301 ret_map.insert( Qtopia::HomeZip, QObject::tr( "Home Zip" ) ); 299 ret_map.insert( Qtopia::HomeZip, QObject::tr( "Home Zip" ) );
302 ret_map.insert( Qtopia::HomeCountry, QObject::tr( "Home Country" ) ); 300 ret_map.insert( Qtopia::HomeCountry, QObject::tr( "Home Country" ) );
303 ret_map.insert( Qtopia::HomeWebPage, QObject::tr( "Home Web Page" ) ); 301 ret_map.insert( Qtopia::HomeWebPage, QObject::tr( "Home Web Page" ) );
304 302
305 //personal 303 //personal
306 ret_map.insert( Qtopia::Spouse, QObject::tr( "Spouse" ) ); 304 ret_map.insert( Qtopia::Spouse, QObject::tr( "Spouse" ) );
307 ret_map.insert( Qtopia::Gender, QObject::tr( "Gender" ) ); 305 ret_map.insert( Qtopia::Gender, QObject::tr( "Gender" ) );
308 ret_map.insert( Qtopia::Birthday, QObject::tr( "Birthday" ) ); 306 ret_map.insert( Qtopia::Birthday, QObject::tr( "Birthday" ) );
309 ret_map.insert( Qtopia::Anniversary, QObject::tr( "Anniversary" ) ); 307 ret_map.insert( Qtopia::Anniversary, QObject::tr( "Anniversary" ) );
310 ret_map.insert( Qtopia::Nickname, QObject::tr( "Nickname" ) ); 308 ret_map.insert( Qtopia::Nickname, QObject::tr( "Nickname" ) );
311 ret_map.insert( Qtopia::Children, QObject::tr( "Children" ) ); 309 ret_map.insert( Qtopia::Children, QObject::tr( "Children" ) );
312 310
313 // other 311 // other
314 ret_map.insert( Qtopia::Notes, QObject::tr( "Notes" ) ); 312 ret_map.insert( Qtopia::Notes, QObject::tr( "Notes" ) );
315 313
316 314
317 return ret_map; 315 return ret_map;
318} 316}
319 317
320QMap<int, QString> OPimContactFields::idToUntrFields() 318QMap<int, QString> OPimContactFields::idToUntrFields()
321{ 319{
322 QMap<int, QString> ret_map; 320 QMap<int, QString> ret_map;
323 321
324 ret_map.insert( Qtopia::AddressUid, "User Id" ); 322 ret_map.insert( Qtopia::AddressUid, "User Id" );
325 ret_map.insert( Qtopia::AddressCategory, "Categories" ); 323 ret_map.insert( Qtopia::AddressCategory, "Categories" );
326 324
327 ret_map.insert( Qtopia::Title, "Name Title" ); 325 ret_map.insert( Qtopia::Title, "Name Title" );
328 ret_map.insert( Qtopia::FirstName, "First Name" ); 326 ret_map.insert( Qtopia::FirstName, "First Name" );
329 ret_map.insert( Qtopia::MiddleName, "Middle Name" ); 327 ret_map.insert( Qtopia::MiddleName, "Middle Name" );
330 ret_map.insert( Qtopia::LastName, "Last Name" ); 328 ret_map.insert( Qtopia::LastName, "Last Name" );
331 ret_map.insert( Qtopia::Suffix, "Suffix" ); 329 ret_map.insert( Qtopia::Suffix, "Suffix" );
332 ret_map.insert( Qtopia::FileAs, "File As" ); 330 ret_map.insert( Qtopia::FileAs, "File As" );
333 331
334 ret_map.insert( Qtopia::JobTitle, "Job Title" ); 332 ret_map.insert( Qtopia::JobTitle, "Job Title" );
335 ret_map.insert( Qtopia::Department, "Department" ); 333 ret_map.insert( Qtopia::Department, "Department" );
336 ret_map.insert( Qtopia::Company, "Company" ); 334 ret_map.insert( Qtopia::Company, "Company" );
337 ret_map.insert( Qtopia::BusinessPhone, "Business Phone" ); 335 ret_map.insert( Qtopia::BusinessPhone, "Business Phone" );
338 ret_map.insert( Qtopia::BusinessFax, "Business Fax" ); 336 ret_map.insert( Qtopia::BusinessFax, "Business Fax" );
339 ret_map.insert( Qtopia::BusinessMobile, "Business Mobile" ); 337 ret_map.insert( Qtopia::BusinessMobile, "Business Mobile" );
340 338
341 // email 339 // email
342 ret_map.insert( Qtopia::DefaultEmail, "Default Email" ); 340 ret_map.insert( Qtopia::DefaultEmail, "Default Email" );
343 ret_map.insert( Qtopia::Emails, "Emails" ); 341 ret_map.insert( Qtopia::Emails, "Emails" );
344 342
345 ret_map.insert( Qtopia::HomePhone, "Home Phone" ); 343 ret_map.insert( Qtopia::HomePhone, "Home Phone" );
346 ret_map.insert( Qtopia::HomeFax, "Home Fax" ); 344 ret_map.insert( Qtopia::HomeFax, "Home Fax" );
347 ret_map.insert( Qtopia::HomeMobile, "Home Mobile" ); 345 ret_map.insert( Qtopia::HomeMobile, "Home Mobile" );
348 346
349 // business 347 // business
350 ret_map.insert( Qtopia::BusinessStreet, "Business Street" ); 348 ret_map.insert( Qtopia::BusinessStreet, "Business Street" );
351 ret_map.insert( Qtopia::BusinessCity, "Business City" ); 349 ret_map.insert( Qtopia::BusinessCity, "Business City" );
352 ret_map.insert( Qtopia::BusinessState, "Business State" ); 350 ret_map.insert( Qtopia::BusinessState, "Business State" );
353 ret_map.insert( Qtopia::BusinessZip, "Business Zip" ); 351 ret_map.insert( Qtopia::BusinessZip, "Business Zip" );
354 ret_map.insert( Qtopia::BusinessCountry, "Business Country" ); 352 ret_map.insert( Qtopia::BusinessCountry, "Business Country" );
355 ret_map.insert( Qtopia::BusinessPager, "Business Pager" ); 353 ret_map.insert( Qtopia::BusinessPager, "Business Pager" );
356 ret_map.insert( Qtopia::BusinessWebPage, "Business WebPage" ); 354 ret_map.insert( Qtopia::BusinessWebPage, "Business WebPage" );
357 355
358 ret_map.insert( Qtopia::Office, "Office" ); 356 ret_map.insert( Qtopia::Office, "Office" );
359 ret_map.insert( Qtopia::Profession, "Profession" ); 357 ret_map.insert( Qtopia::Profession, "Profession" );
360 ret_map.insert( Qtopia::Assistant, "Assistant" ); 358 ret_map.insert( Qtopia::Assistant, "Assistant" );
361 ret_map.insert( Qtopia::Manager, "Manager" ); 359 ret_map.insert( Qtopia::Manager, "Manager" );
362 360
363 // home 361 // home
364 ret_map.insert( Qtopia::HomeStreet, "Home Street" ); 362 ret_map.insert( Qtopia::HomeStreet, "Home Street" );
365 ret_map.insert( Qtopia::HomeCity, "Home City" ); 363 ret_map.insert( Qtopia::HomeCity, "Home City" );
366 ret_map.insert( Qtopia::HomeState, "Home State" ); 364 ret_map.insert( Qtopia::HomeState, "Home State" );
367 ret_map.insert( Qtopia::HomeZip, "Home Zip" ); 365 ret_map.insert( Qtopia::HomeZip, "Home Zip" );
368 ret_map.insert( Qtopia::HomeCountry, "Home Country" ); 366 ret_map.insert( Qtopia::HomeCountry, "Home Country" );
369 ret_map.insert( Qtopia::HomeWebPage, "Home Web Page" ); 367 ret_map.insert( Qtopia::HomeWebPage, "Home Web Page" );
370 368
371 //personal 369 //personal
372 ret_map.insert( Qtopia::Spouse, "Spouse" ); 370 ret_map.insert( Qtopia::Spouse, "Spouse" );
373 ret_map.insert( Qtopia::Gender, "Gender" ); 371 ret_map.insert( Qtopia::Gender, "Gender" );
374 ret_map.insert( Qtopia::Birthday, "Birthday" ); 372 ret_map.insert( Qtopia::Birthday, "Birthday" );
375 ret_map.insert( Qtopia::Anniversary, "Anniversary" ); 373 ret_map.insert( Qtopia::Anniversary, "Anniversary" );
376 ret_map.insert( Qtopia::Nickname, "Nickname" ); 374 ret_map.insert( Qtopia::Nickname, "Nickname" );
377 ret_map.insert( Qtopia::Children, "Children" ); 375 ret_map.insert( Qtopia::Children, "Children" );
378 376
379 // other 377 // other
380 ret_map.insert( Qtopia::Notes, "Notes" ); 378 ret_map.insert( Qtopia::Notes, "Notes" );
381 ret_map.insert( Qtopia::Groups, "Groups" ); 379 ret_map.insert( Qtopia::Groups, "Groups" );
382 380
383 381
384 return ret_map; 382 return ret_map;
385} 383}
386 384
387QMap<QString, int> OPimContactFields::trFieldsToId() 385QMap<QString, int> OPimContactFields::trFieldsToId()
388{ 386{
389 QMap<int, QString> idtostr = idToTrFields(); 387 QMap<int, QString> idtostr = idToTrFields();
390 QMap<QString, int> ret_map; 388 QMap<QString, int> ret_map;
391 389
392 390
393 QMap<int, QString>::Iterator it; 391 QMap<int, QString>::Iterator it;
394 for ( it = idtostr.begin(); it != idtostr.end(); ++it ) 392 for ( it = idtostr.begin(); it != idtostr.end(); ++it )
395 ret_map.insert( *it, it.key() ); 393 ret_map.insert( *it, it.key() );
396 394
397 395
398 return ret_map; 396 return ret_map;
399} 397}
400 398
401/* ======================================================================= */ 399/* ======================================================================= */
402 400
403QMap<QString, int> OPimContactFields::untrFieldsToId() 401QMap<QString, int> OPimContactFields::untrFieldsToId()
404{ 402{
405 QMap<int, QString> idtostr = idToUntrFields(); 403 QMap<int, QString> idtostr = idToUntrFields();
406 QMap<QString, int> ret_map; 404 QMap<QString, int> ret_map;
407 405
408 406
409 QMap<int, QString>::Iterator it; 407 QMap<int, QString>::Iterator it;
410 for ( it = idtostr.begin(); it != idtostr.end(); ++it ) 408 for ( it = idtostr.begin(); it != idtostr.end(); ++it )
411 ret_map.insert( *it, it.key() ); 409 ret_map.insert( *it, it.key() );
412 410
413 411
414 return ret_map; 412 return ret_map;
415} 413}
416 414
417 415
418OPimContactFields::OPimContactFields() : 416OPimContactFields::OPimContactFields() :
419 fieldOrder( DEFAULT_FIELD_ORDER ), 417 fieldOrder( DEFAULT_FIELD_ORDER ),
420 changedFieldOrder( false ) 418 changedFieldOrder( false )
421{ 419{
422 // Get the global field order from the config file and 420 // Get the global field order from the config file and
423 // use it as a start pattern 421 // use it as a start pattern
424 Config cfg ( "AddressBook" ); 422 Config cfg ( "AddressBook" );
425 cfg.setGroup( "ContactFieldOrder" ); 423 cfg.setGroup( "ContactFieldOrder" );
426 globalFieldOrder = cfg.readEntry( "General", DEFAULT_FIELD_ORDER ); 424 globalFieldOrder = cfg.readEntry( "General", DEFAULT_FIELD_ORDER );
427} 425}
428 426
429OPimContactFields::~OPimContactFields() 427OPimContactFields::~OPimContactFields()
430{ 428{
431 429
432 // We will store the fieldorder into the config file 430 // We will store the fieldorder into the config file
433 // to reuse it for the future.. 431 // to reuse it for the future..
434 if ( changedFieldOrder ) 432 if ( changedFieldOrder )
435 { 433 {
436 Config cfg ( "AddressBook" ); 434 Config cfg ( "AddressBook" );
437 cfg.setGroup( "ContactFieldOrder" ); 435 cfg.setGroup( "ContactFieldOrder" );
438 cfg.writeEntry( "General", globalFieldOrder ); 436 cfg.writeEntry( "General", globalFieldOrder );
439 } 437 }
440} 438}
441 439
442 440
443 441
444void OPimContactFields::saveToRecord( OPimContact &cnt ) 442void OPimContactFields::saveToRecord( OPimContact &cnt )
445{ 443{
446 444
447 qDebug( "ocontactfields saveToRecord: >%s<", fieldOrder.latin1() ); 445 qDebug( "ocontactfields saveToRecord: >%s<", fieldOrder.latin1() );
448 446
449 // Store fieldorder into this contact. 447 // Store fieldorder into this contact.
450 cnt.setCustomField( CONTACT_FIELD_ORDER_NAME, fieldOrder ); 448 cnt.setCustomField( CONTACT_FIELD_ORDER_NAME, fieldOrder );
451 449
452 globalFieldOrder = fieldOrder; 450 globalFieldOrder = fieldOrder;
453 changedFieldOrder = true; 451 changedFieldOrder = true;
454 452
455} 453}
456 454
457void OPimContactFields::loadFromRecord( const OPimContact &cnt ) 455void OPimContactFields::loadFromRecord( const OPimContact &cnt )
458{ 456{
459 qDebug( "ocontactfields loadFromRecord" ); 457 qDebug( "ocontactfields loadFromRecord" );
460 qDebug( "loading >%s<", cnt.fullName().latin1() ); 458 qDebug( "loading >%s<", cnt.fullName().latin1() );
461 459
462 // Get fieldorder for this contact. If none is defined, 460 // Get fieldorder for this contact. If none is defined,
463 // we will use the global one from the config file.. 461 // we will use the global one from the config file..
464 462
465 fieldOrder = cnt.customField( CONTACT_FIELD_ORDER_NAME ); 463 fieldOrder = cnt.customField( CONTACT_FIELD_ORDER_NAME );
466 464
467 qDebug( "fieldOrder from contact>%s<", fieldOrder.latin1() ); 465 qDebug( "fieldOrder from contact>%s<", fieldOrder.latin1() );
468 466
469 if ( fieldOrder.isEmpty() ) 467 if ( fieldOrder.isEmpty() )
470 { 468 {
471 fieldOrder = globalFieldOrder; 469 fieldOrder = globalFieldOrder;
472 } 470 }
473 471
474 472
475 qDebug( "effective fieldOrder in loadFromRecord >%s<", fieldOrder.latin1() ); 473 qDebug( "effective fieldOrder in loadFromRecord >%s<", fieldOrder.latin1() );
476} 474}
477 475
478void OPimContactFields::setFieldOrder( int num, int index ) 476void OPimContactFields::setFieldOrder( int num, int index )
479{ 477{
480 qDebug( "qcontactfields setfieldorder pos %i -> %i", num, index ); 478 qDebug( "qcontactfields setfieldorder pos %i -> %i", num, index );
481 479
482 fieldOrder[ num ] = QString::number( index, 16 ) [ 0 ]; 480 fieldOrder[ num ] = QString::number( index, 16 ) [ 0 ];
483 481
484 // We will store this new fieldorder globally to 482 // We will store this new fieldorder globally to
485 // remember it for contacts which have none 483 // remember it for contacts which have none
486 globalFieldOrder = fieldOrder; 484 globalFieldOrder = fieldOrder;
487 changedFieldOrder = true; 485 changedFieldOrder = true;
488 486
489 qDebug( "fieldOrder >%s<", fieldOrder.latin1() ); 487 qDebug( "fieldOrder >%s<", fieldOrder.latin1() );
490} 488}
491 489
492int OPimContactFields::getFieldOrder( int num, int defIndex ) 490int OPimContactFields::getFieldOrder( int num, int defIndex )
493{ 491{
494 qDebug( "ocontactfields getFieldOrder" ); 492 qDebug( "ocontactfields getFieldOrder" );
495 qDebug( "fieldOrder >%s<", fieldOrder.latin1() ); 493 qDebug( "fieldOrder >%s<", fieldOrder.latin1() );
496 494
497 // Get index of combo as char.. 495 // Get index of combo as char..
498 QChar poschar = fieldOrder[ num ]; 496 QChar poschar = fieldOrder[ num ];
499 497
500 bool ok; 498 bool ok;
501 int ret = 0; 499 int ret = 0;
502 // Convert char to number.. 500 // Convert char to number..
503 if ( !( poschar == QChar::null ) ) 501 if ( !( poschar == QChar::null ) )
504 ret = QString( poschar ).toInt( &ok, 16 ); 502 ret = QString( poschar ).toInt( &ok, 16 );
505 else 503 else
506 ok = false; 504 ok = false;
507 505
508 // Return default value if index for 506 // Return default value if index for
509 // num was not set or if anything else happened.. 507 // num was not set or if anything else happened..
510 if ( !ok ) ret = defIndex; 508 if ( !ok ) ret = defIndex;
511 509
512 qDebug( "returning >%i<", ret ); 510 qDebug( "returning >%i<", ret );
513 511
514 return ret; 512 return ret;
515 513
516} 514}
517 515
518} 516}
diff --git a/libopie2/opiepim/core/opimevent.cpp b/libopie2/opiepim/core/opimevent.cpp
index 3ddbf85..77730e9 100644
--- a/libopie2/opiepim/core/opimevent.cpp
+++ b/libopie2/opiepim/core/opimevent.cpp
@@ -1,1025 +1,1022 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) Stefan Eilers <Eilers.Stefan@epost.de> 3 Copyright (C) Stefan Eilers <Eilers.Stefan@epost.de>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 4 =. Copyright (C) The Opie Team <opie-devel@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 "opimevent.h" 30#include "opimevent.h"
31 31
32/* OPIE */ 32/* OPIE */
33#include <opie2/opimrecurrence.h> 33#include <opie2/opimrecurrence.h>
34#include <opie2/opimresolver.h> 34#include <opie2/opimresolver.h>
35#include <opie2/opimnotifymanager.h> 35#include <opie2/opimnotifymanager.h>
36#include <qpe/categories.h> 36#include <qpe/categories.h>
37#include <qpe/palmtopuidgen.h>
38#include <qpe/stringutil.h> 37#include <qpe/stringutil.h>
39 38
40/* QT */ 39/* QT */
41#include <qshared.h>
42#include <qarray.h>
43 40
44namespace Opie 41namespace Opie
45{ 42{
46 43
47int OCalendarHelper::week( const QDate& date ) 44int OCalendarHelper::week( const QDate& date )
48{ 45{
49 // Calculates the week this date is in within that 46 // Calculates the week this date is in within that
50 // month. Equals the "row" is is in in the month view 47 // month. Equals the "row" is is in in the month view
51 int week = 1; 48 int week = 1;
52 QDate tmp( date.year(), date.month(), 1 ); 49 QDate tmp( date.year(), date.month(), 1 );
53 if ( date.dayOfWeek() < tmp.dayOfWeek() ) 50 if ( date.dayOfWeek() < tmp.dayOfWeek() )
54 ++week; 51 ++week;
55 52
56 week += ( date.day() - 1 ) / 7; 53 week += ( date.day() - 1 ) / 7;
57 54
58 return week; 55 return week;
59} 56}
60 57
61 58
62int OCalendarHelper::ocurrence( const QDate& date ) 59int OCalendarHelper::ocurrence( const QDate& date )
63{ 60{
64 // calculates the number of occurrances of this day of the 61 // calculates the number of occurrances of this day of the
65 // week till the given date (e.g 3rd Wednesday of the month) 62 // week till the given date (e.g 3rd Wednesday of the month)
66 return ( date.day() - 1 ) / 7 + 1; 63 return ( date.day() - 1 ) / 7 + 1;
67} 64}
68 65
69 66
70int OCalendarHelper::dayOfWeek( char day ) 67int OCalendarHelper::dayOfWeek( char day )
71{ 68{
72 int dayOfWeek = 1; 69 int dayOfWeek = 1;
73 char i = OPimRecurrence::MON; 70 char i = OPimRecurrence::MON;
74 while ( !( i & day ) && i <= OPimRecurrence::SUN ) 71 while ( !( i & day ) && i <= OPimRecurrence::SUN )
75 { 72 {
76 i <<= 1; 73 i <<= 1;
77 ++dayOfWeek; 74 ++dayOfWeek;
78 } 75 }
79 return dayOfWeek; 76 return dayOfWeek;
80} 77}
81 78
82 79
83int OCalendarHelper::monthDiff( const QDate& first, const QDate& second ) 80int OCalendarHelper::monthDiff( const QDate& first, const QDate& second )
84{ 81{
85 return ( second.year() - first.year() ) * 12 + 82 return ( second.year() - first.year() ) * 12 +
86 second.month() - first.month(); 83 second.month() - first.month();
87} 84}
88 85
89 86
90struct OPimEvent::Data : public QShared 87struct OPimEvent::Data : public QShared
91{ 88{
92 Data() : QShared() 89 Data() : QShared()
93 { 90 {
94 child = 0; 91 child = 0;
95 recur = 0; 92 recur = 0;
96 manager = 0; 93 manager = 0;
97 isAllDay = false; 94 isAllDay = false;
98 parent = 0; 95 parent = 0;
99 } 96 }
100 ~Data() 97 ~Data()
101 { 98 {
102 delete manager; 99 delete manager;
103 delete recur; 100 delete recur;
104 } 101 }
105 QString description; 102 QString description;
106 QString location; 103 QString location;
107 OPimNotifyManager* manager; 104 OPimNotifyManager* manager;
108 OPimRecurrence* recur; 105 OPimRecurrence* recur;
109 QString note; 106 QString note;
110 QDateTime created; 107 QDateTime created;
111 QDateTime start; 108 QDateTime start;
112 QDateTime end; 109 QDateTime end;
113bool isAllDay : 1; 110bool isAllDay : 1;
114 QString timezone; 111 QString timezone;
115 QArray<int>* child; 112 QArray<int>* child;
116 int parent; 113 int parent;
117}; 114};
118 115
119 116
120OPimEvent::OPimEvent( int uid ) 117OPimEvent::OPimEvent( int uid )
121 : OPimRecord( uid ) 118 : OPimRecord( uid )
122{ 119{
123 data = new Data; 120 data = new Data;
124} 121}
125 122
126 123
127OPimEvent::OPimEvent( const OPimEvent& ev ) 124OPimEvent::OPimEvent( const OPimEvent& ev )
128 : OPimRecord( ev ), data( ev.data ) 125 : OPimRecord( ev ), data( ev.data )
129{ 126{
130 data->ref(); 127 data->ref();
131} 128}
132 129
133 130
134OPimEvent::OPimEvent( const QMap<int, QString> map ) 131OPimEvent::OPimEvent( const QMap<int, QString> map )
135 : OPimRecord( 0 ) 132 : OPimRecord( 0 )
136{ 133{
137 data = new Data; 134 data = new Data;
138 135
139 fromMap( map ); 136 fromMap( map );
140} 137}
141 138
142 139
143OPimEvent::~OPimEvent() 140OPimEvent::~OPimEvent()
144{ 141{
145 if ( data->deref() ) 142 if ( data->deref() )
146 { 143 {
147 delete data; 144 delete data;
148 data = 0; 145 data = 0;
149 } 146 }
150} 147}
151 148
152 149
153OPimEvent& OPimEvent::operator=( const OPimEvent& ev ) 150OPimEvent& OPimEvent::operator=( const OPimEvent& ev )
154{ 151{
155 if ( this == &ev ) return * this; 152 if ( this == &ev ) return * this;
156 153
157 OPimRecord::operator=( ev ); 154 OPimRecord::operator=( ev );
158 ev.data->ref(); 155 ev.data->ref();
159 deref(); 156 deref();
160 data = ev.data; 157 data = ev.data;
161 158
162 159
163 return *this; 160 return *this;
164} 161}
165 162
166 163
167QString OPimEvent::description() const 164QString OPimEvent::description() const
168{ 165{
169 return data->description; 166 return data->description;
170} 167}
171 168
172 169
173void OPimEvent::setDescription( const QString& description ) 170void OPimEvent::setDescription( const QString& description )
174{ 171{
175 changeOrModify(); 172 changeOrModify();
176 data->description = description; 173 data->description = description;
177} 174}
178 175
179 176
180void OPimEvent::setLocation( const QString& loc ) 177void OPimEvent::setLocation( const QString& loc )
181{ 178{
182 changeOrModify(); 179 changeOrModify();
183 data->location = loc; 180 data->location = loc;
184} 181}
185 182
186 183
187QString OPimEvent::location() const 184QString OPimEvent::location() const
188{ 185{
189 return data->location; 186 return data->location;
190} 187}
191 188
192 189
193OPimNotifyManager &OPimEvent::notifiers() const 190OPimNotifyManager &OPimEvent::notifiers() const
194{ 191{
195 // I hope we can skip the changeOrModify here 192 // I hope we can skip the changeOrModify here
196 // the notifier should take care of it 193 // the notifier should take care of it
197 // and OPimNotify is shared too 194 // and OPimNotify is shared too
198 if ( !data->manager ) 195 if ( !data->manager )
199 data->manager = new OPimNotifyManager; 196 data->manager = new OPimNotifyManager;
200 197
201 return *data->manager; 198 return *data->manager;
202} 199}
203 200
204 201
205bool OPimEvent::hasNotifiers() const 202bool OPimEvent::hasNotifiers() const
206{ 203{
207 if ( !data->manager ) 204 if ( !data->manager )
208 return false; 205 return false;
209 if ( data->manager->reminders().isEmpty() && 206 if ( data->manager->reminders().isEmpty() &&
210 data->manager->alarms().isEmpty() ) 207 data->manager->alarms().isEmpty() )
211 return false; 208 return false;
212 209
213 return true; 210 return true;
214} 211}
215 212
216 213
217OPimRecurrence OPimEvent::recurrence() const 214OPimRecurrence OPimEvent::recurrence() const
218{ 215{
219 if ( !data->recur ) 216 if ( !data->recur )
220 data->recur = new OPimRecurrence; 217 data->recur = new OPimRecurrence;
221 218
222 return *data->recur; 219 return *data->recur;
223} 220}
224 221
225 222
226void OPimEvent::setRecurrence( const OPimRecurrence& rec ) 223void OPimEvent::setRecurrence( const OPimRecurrence& rec )
227{ 224{
228 changeOrModify(); 225 changeOrModify();
229 if ( data->recur ) 226 if ( data->recur )
230 ( *data->recur ) = rec; 227 ( *data->recur ) = rec;
231 else 228 else
232 data->recur = new OPimRecurrence( rec ); 229 data->recur = new OPimRecurrence( rec );
233} 230}
234 231
235 232
236bool OPimEvent::hasRecurrence() const 233bool OPimEvent::hasRecurrence() const
237{ 234{
238 if ( !data->recur ) return false; 235 if ( !data->recur ) return false;
239 return data->recur->doesRecur(); 236 return data->recur->doesRecur();
240} 237}
241 238
242 239
243QString OPimEvent::note() const 240QString OPimEvent::note() const
244{ 241{
245 return data->note; 242 return data->note;
246} 243}
247 244
248 245
249void OPimEvent::setNote( const QString& note ) 246void OPimEvent::setNote( const QString& note )
250{ 247{
251 changeOrModify(); 248 changeOrModify();
252 data->note = note; 249 data->note = note;
253} 250}
254 251
255 252
256QDateTime OPimEvent::createdDateTime() const 253QDateTime OPimEvent::createdDateTime() const
257{ 254{
258 return data->created; 255 return data->created;
259} 256}
260 257
261 258
262void OPimEvent::setCreatedDateTime( const QDateTime& time ) 259void OPimEvent::setCreatedDateTime( const QDateTime& time )
263{ 260{
264 changeOrModify(); 261 changeOrModify();
265 data->created = time; 262 data->created = time;
266} 263}
267 264
268 265
269QDateTime OPimEvent::startDateTime() const 266QDateTime OPimEvent::startDateTime() const
270{ 267{
271 if ( data->isAllDay ) 268 if ( data->isAllDay )
272 return QDateTime( data->start.date(), QTime( 0, 0, 0 ) ); 269 return QDateTime( data->start.date(), QTime( 0, 0, 0 ) );
273 return data->start; 270 return data->start;
274} 271}
275 272
276 273
277QDateTime OPimEvent::startDateTimeInZone() const 274QDateTime OPimEvent::startDateTimeInZone() const
278{ 275{
279 /* if no timezone, or all day event or if the current and this timeZone match... */ 276 /* if no timezone, or all day event or if the current and this timeZone match... */
280 if ( data->timezone.isEmpty() || data->isAllDay || data->timezone == OPimTimeZone::current().timeZone() ) return startDateTime(); 277 if ( data->timezone.isEmpty() || data->isAllDay || data->timezone == OPimTimeZone::current().timeZone() ) return startDateTime();
281 278
282 OPimTimeZone zone( data->timezone ); 279 OPimTimeZone zone( data->timezone );
283 return zone.toDateTime( data->start, OPimTimeZone::current() ); 280 return zone.toDateTime( data->start, OPimTimeZone::current() );
284} 281}
285 282
286 283
287void OPimEvent::setStartDateTime( const QDateTime& dt ) 284void OPimEvent::setStartDateTime( const QDateTime& dt )
288{ 285{
289 changeOrModify(); 286 changeOrModify();
290 data->start = dt; 287 data->start = dt;
291} 288}
292 289
293 290
294QDateTime OPimEvent::endDateTime() const 291QDateTime OPimEvent::endDateTime() const
295{ 292{
296 /* 293 /*
297 * if all Day event the end time needs 294 * if all Day event the end time needs
298 * to be on the same day as the start 295 * to be on the same day as the start
299 */ 296 */
300 if ( data->isAllDay ) 297 if ( data->isAllDay )
301 return QDateTime( data->start.date(), QTime( 23, 59, 59 ) ); 298 return QDateTime( data->start.date(), QTime( 23, 59, 59 ) );
302 return data->end; 299 return data->end;
303} 300}
304 301
305 302
306QDateTime OPimEvent::endDateTimeInZone() const 303QDateTime OPimEvent::endDateTimeInZone() const
307{ 304{
308 /* if no timezone, or all day event or if the current and this timeZone match... */ 305 /* if no timezone, or all day event or if the current and this timeZone match... */
309 if ( data->timezone.isEmpty() || data->isAllDay || data->timezone == OPimTimeZone::current().timeZone() ) return endDateTime(); 306 if ( data->timezone.isEmpty() || data->isAllDay || data->timezone == OPimTimeZone::current().timeZone() ) return endDateTime();
310 307
311 OPimTimeZone zone( data->timezone ); 308 OPimTimeZone zone( data->timezone );
312 return zone.toDateTime( data->end, OPimTimeZone::current() ); 309 return zone.toDateTime( data->end, OPimTimeZone::current() );
313} 310}
314 311
315 312
316void OPimEvent::setEndDateTime( const QDateTime& dt ) 313void OPimEvent::setEndDateTime( const QDateTime& dt )
317{ 314{
318 changeOrModify(); 315 changeOrModify();
319 data->end = dt; 316 data->end = dt;
320} 317}
321 318
322 319
323bool OPimEvent::isMultipleDay() const 320bool OPimEvent::isMultipleDay() const
324{ 321{
325 return data->end.date().day() - data->start.date().day(); 322 return data->end.date().day() - data->start.date().day();
326} 323}
327 324
328 325
329bool OPimEvent::isAllDay() const 326bool OPimEvent::isAllDay() const
330{ 327{
331 return data->isAllDay; 328 return data->isAllDay;
332} 329}
333 330
334 331
335void OPimEvent::setAllDay( bool allDay ) 332void OPimEvent::setAllDay( bool allDay )
336{ 333{
337 changeOrModify(); 334 changeOrModify();
338 data->isAllDay = allDay; 335 data->isAllDay = allDay;
339 if ( allDay ) data->timezone = "UTC"; 336 if ( allDay ) data->timezone = "UTC";
340} 337}
341 338
342 339
343void OPimEvent::setTimeZone( const QString& tz ) 340void OPimEvent::setTimeZone( const QString& tz )
344{ 341{
345 changeOrModify(); 342 changeOrModify();
346 data->timezone = tz; 343 data->timezone = tz;
347} 344}
348 345
349 346
350QString OPimEvent::timeZone() const 347QString OPimEvent::timeZone() const
351{ 348{
352 if ( data->isAllDay ) return QString::fromLatin1( "UTC" ); 349 if ( data->isAllDay ) return QString::fromLatin1( "UTC" );
353 return data->timezone; 350 return data->timezone;
354} 351}
355 352
356 353
357bool OPimEvent::match( const QRegExp& re ) const 354bool OPimEvent::match( const QRegExp& re ) const
358{ 355{
359 if ( re.match( data->description ) != -1 ) 356 if ( re.match( data->description ) != -1 )
360 { 357 {
361 setLastHitField( Qtopia::DatebookDescription ); 358 setLastHitField( Qtopia::DatebookDescription );
362 return true; 359 return true;
363 } 360 }
364 if ( re.match( data->note ) != -1 ) 361 if ( re.match( data->note ) != -1 )
365 { 362 {
366 setLastHitField( Qtopia::Note ); 363 setLastHitField( Qtopia::Note );
367 return true; 364 return true;
368 } 365 }
369 if ( re.match( data->location ) != -1 ) 366 if ( re.match( data->location ) != -1 )
370 { 367 {
371 setLastHitField( Qtopia::Location ); 368 setLastHitField( Qtopia::Location );
372 return true; 369 return true;
373 } 370 }
374 if ( re.match( data->start.toString() ) != -1 ) 371 if ( re.match( data->start.toString() ) != -1 )
375 { 372 {
376 setLastHitField( Qtopia::StartDateTime ); 373 setLastHitField( Qtopia::StartDateTime );
377 return true; 374 return true;
378 } 375 }
379 if ( re.match( data->end.toString() ) != -1 ) 376 if ( re.match( data->end.toString() ) != -1 )
380 { 377 {
381 setLastHitField( Qtopia::EndDateTime ); 378 setLastHitField( Qtopia::EndDateTime );
382 return true; 379 return true;
383 } 380 }
384 return false; 381 return false;
385} 382}
386 383
387 384
388QString OPimEvent::toRichText() const 385QString OPimEvent::toRichText() const
389{ 386{
390 QString text, value; 387 QString text, value;
391 388
392 // description 389 // description
393 text += "<b><h3><img src=\"datebook/DateBook\">"; 390 text += "<b><h3><img src=\"datebook/DateBook\">";
394 if ( !description().isEmpty() ) 391 if ( !description().isEmpty() )
395 { 392 {
396 text += Qtopia::escapeString( description() ).replace( QRegExp( "[\n]" ), "" ); 393 text += Qtopia::escapeString( description() ).replace( QRegExp( "[\n]" ), "" );
397 } 394 }
398 text += "</h3></b><br><hr><br>"; 395 text += "</h3></b><br><hr><br>";
399 396
400 // location 397 // location
401 if ( !( value = location() ).isEmpty() ) 398 if ( !( value = location() ).isEmpty() )
402 { 399 {
403 text += "<b>" + QObject::tr( "Location:" ) + "</b> "; 400 text += "<b>" + QObject::tr( "Location:" ) + "</b> ";
404 text += Qtopia::escapeString( value ) + "<br>"; 401 text += Qtopia::escapeString( value ) + "<br>";
405 } 402 }
406 403
407 // all day event 404 // all day event
408 if ( isAllDay() ) 405 if ( isAllDay() )
409 { 406 {
410 text += "<b><i>" + QObject::tr( "This is an all day event" ) + "</i></b><br>"; 407 text += "<b><i>" + QObject::tr( "This is an all day event" ) + "</i></b><br>";
411 } 408 }
412 // multiple day event 409 // multiple day event
413 else if ( isMultipleDay () ) 410 else if ( isMultipleDay () )
414 { 411 {
415 text += "<b><i>" + QObject::tr( "This is a multiple day event" ) + "</i></b><br>"; 412 text += "<b><i>" + QObject::tr( "This is a multiple day event" ) + "</i></b><br>";
416 } 413 }
417 // start & end times 414 // start & end times
418 else 415 else
419 { 416 {
420 // start time 417 // start time
421 if ( startDateTime().isValid() ) 418 if ( startDateTime().isValid() )
422 { 419 {
423 text += "<b>" + QObject::tr( "Start:" ) + "</b> "; 420 text += "<b>" + QObject::tr( "Start:" ) + "</b> ";
424 text += Qtopia::escapeString( startDateTime().toString() ). 421 text += Qtopia::escapeString( startDateTime().toString() ).
425 replace( QRegExp( "[\n]" ), "<br>" ) + "<br>"; 422 replace( QRegExp( "[\n]" ), "<br>" ) + "<br>";
426 } 423 }
427 424
428 // end time 425 // end time
429 if ( endDateTime().isValid() ) 426 if ( endDateTime().isValid() )
430 { 427 {
431 text += "<b>" + QObject::tr( "End:" ) + "</b> "; 428 text += "<b>" + QObject::tr( "End:" ) + "</b> ";
432 text += Qtopia::escapeString( endDateTime().toString() ). 429 text += Qtopia::escapeString( endDateTime().toString() ).
433 replace( QRegExp( "[\n]" ), "<br>" ) + "<br>"; 430 replace( QRegExp( "[\n]" ), "<br>" ) + "<br>";
434 } 431 }
435 } 432 }
436 433
437 // categories 434 // categories
438 if ( categoryNames( "Calendar" ).count() ) 435 if ( categoryNames( "Calendar" ).count() )
439 { 436 {
440 text += "<b>" + QObject::tr( "Category:" ) + "</b> "; 437 text += "<b>" + QObject::tr( "Category:" ) + "</b> ";
441 text += categoryNames( "Calendar" ).join( ", " ); 438 text += categoryNames( "Calendar" ).join( ", " );
442 text += "<br>"; 439 text += "<br>";
443 } 440 }
444 441
445 //notes 442 //notes
446 if ( !note().isEmpty() ) 443 if ( !note().isEmpty() )
447 { 444 {
448 text += "<b>" + QObject::tr( "Note:" ) + "</b><br>"; 445 text += "<b>" + QObject::tr( "Note:" ) + "</b><br>";
449 text += note(); 446 text += note();
450 // text += Qtopia::escapeString(note() ). 447 // text += Qtopia::escapeString(note() ).
451 // replace(QRegExp( "[\n]"), "<br>" ) + "<br>"; 448 // replace(QRegExp( "[\n]"), "<br>" ) + "<br>";
452 } 449 }
453 return text; 450 return text;
454} 451}
455 452
456 453
457QString OPimEvent::toShortText() const 454QString OPimEvent::toShortText() const
458{ 455{
459 QString text; 456 QString text;
460 text += QString::number( startDateTime().date().day() ); 457 text += QString::number( startDateTime().date().day() );
461 text += "."; 458 text += ".";
462 text += QString::number( startDateTime().date().month() ); 459 text += QString::number( startDateTime().date().month() );
463 text += "."; 460 text += ".";
464 text += QString::number( startDateTime().date().year() ); 461 text += QString::number( startDateTime().date().year() );
465 text += " "; 462 text += " ";
466 text += QString::number( startDateTime().time().hour() ); 463 text += QString::number( startDateTime().time().hour() );
467 text += ":"; 464 text += ":";
468 text += QString::number( startDateTime().time().minute() ); 465 text += QString::number( startDateTime().time().minute() );
469 text += " - "; 466 text += " - ";
470 text += description(); 467 text += description();
471 return text; 468 return text;
472} 469}
473 470
474 471
475QString OPimEvent::type() const 472QString OPimEvent::type() const
476{ 473{
477 return QString::fromLatin1( "OPimEvent" ); 474 return QString::fromLatin1( "OPimEvent" );
478} 475}
479 476
480 477
481QString OPimEvent::recordField( int /*id */ ) const 478QString OPimEvent::recordField( int /*id */ ) const
482{ 479{
483 return QString::null; 480 return QString::null;
484} 481}
485 482
486 483
487int OPimEvent::rtti() 484int OPimEvent::rtti()
488{ 485{
489 return OPimResolver::DateBook; 486 return OPimResolver::DateBook;
490} 487}
491 488
492 489
493bool OPimEvent::loadFromStream( QDataStream& ) 490bool OPimEvent::loadFromStream( QDataStream& )
494{ 491{
495 return true; 492 return true;
496} 493}
497 494
498 495
499bool OPimEvent::saveToStream( QDataStream& ) const 496bool OPimEvent::saveToStream( QDataStream& ) const
500{ 497{
501 return true; 498 return true;
502} 499}
503 500
504 501
505void OPimEvent::changeOrModify() 502void OPimEvent::changeOrModify()
506{ 503{
507 if ( data->count != 1 ) 504 if ( data->count != 1 )
508 { 505 {
509 data->deref(); 506 data->deref();
510 Data* d2 = new Data; 507 Data* d2 = new Data;
511 d2->description = data->description; 508 d2->description = data->description;
512 d2->location = data->location; 509 d2->location = data->location;
513 510
514 if ( data->manager ) 511 if ( data->manager )
515 d2->manager = new OPimNotifyManager( *data->manager ); 512 d2->manager = new OPimNotifyManager( *data->manager );
516 513
517 if ( data->recur ) 514 if ( data->recur )
518 d2->recur = new OPimRecurrence( *data->recur ); 515 d2->recur = new OPimRecurrence( *data->recur );
519 516
520 d2->note = data->note; 517 d2->note = data->note;
521 d2->created = data->created; 518 d2->created = data->created;
522 d2->start = data->start; 519 d2->start = data->start;
523 d2->end = data->end; 520 d2->end = data->end;
524 d2->isAllDay = data->isAllDay; 521 d2->isAllDay = data->isAllDay;
525 d2->timezone = data->timezone; 522 d2->timezone = data->timezone;
526 d2->parent = data->parent; 523 d2->parent = data->parent;
527 524
528 if ( data->child ) 525 if ( data->child )
529 { 526 {
530 d2->child = new QArray<int>( *data->child ); 527 d2->child = new QArray<int>( *data->child );
531 d2->child->detach(); 528 d2->child->detach();
532 } 529 }
533 530
534 data = d2; 531 data = d2;
535 } 532 }
536} 533}
537 534
538 535
539void OPimEvent::deref() 536void OPimEvent::deref()
540{ 537{
541 if ( data->deref() ) 538 if ( data->deref() )
542 { 539 {
543 delete data; 540 delete data;
544 data = 0; 541 data = 0;
545 } 542 }
546} 543}
547// Exporting Event data to map. Using the same 544// Exporting Event data to map. Using the same
548// encoding as ODateBookAccessBackend_xml does.. 545// encoding as ODateBookAccessBackend_xml does..
549// Thus, we could remove the stuff there and use this 546// Thus, we could remove the stuff there and use this
550// for it and for all other places.. 547// for it and for all other places..
551// Encoding should happen at one place, only ! (eilers) 548// Encoding should happen at one place, only ! (eilers)
552QMap<int, QString> OPimEvent::toMap() const 549QMap<int, QString> OPimEvent::toMap() const
553{ 550{
554 QMap<int, QString> retMap; 551 QMap<int, QString> retMap;
555 552
556 retMap.insert( OPimEvent::FUid, QString::number( uid() ) ); 553 retMap.insert( OPimEvent::FUid, QString::number( uid() ) );
557 retMap.insert( OPimEvent::FCategories, Qtopia::escapeString( Qtopia::Record::idsToString( categories() ) ) ); 554 retMap.insert( OPimEvent::FCategories, Qtopia::escapeString( Qtopia::Record::idsToString( categories() ) ) );
558 retMap.insert( OPimEvent::FDescription, Qtopia::escapeString( description() ) ); 555 retMap.insert( OPimEvent::FDescription, Qtopia::escapeString( description() ) );
559 retMap.insert( OPimEvent::FLocation, Qtopia::escapeString( location() ) ); 556 retMap.insert( OPimEvent::FLocation, Qtopia::escapeString( location() ) );
560 retMap.insert( OPimEvent::FType, isAllDay() ? "AllDay" : "" ); 557 retMap.insert( OPimEvent::FType, isAllDay() ? "AllDay" : "" );
561 OPimAlarm alarm = notifiers().alarms() [ 0 ]; 558 OPimAlarm alarm = notifiers().alarms() [ 0 ];
562 retMap.insert( OPimEvent::FAlarm, QString::number( alarm.dateTime().secsTo( startDateTime() ) / 60 ) ); 559 retMap.insert( OPimEvent::FAlarm, QString::number( alarm.dateTime().secsTo( startDateTime() ) / 60 ) );
563 retMap.insert( OPimEvent::FSound, ( alarm.sound() == OPimAlarm::Loud ) ? "loud" : "silent" ); 560 retMap.insert( OPimEvent::FSound, ( alarm.sound() == OPimAlarm::Loud ) ? "loud" : "silent" );
564 561
565 OPimTimeZone zone( timeZone().isEmpty() ? OPimTimeZone::current() : timeZone() ); 562 OPimTimeZone zone( timeZone().isEmpty() ? OPimTimeZone::current() : timeZone() );
566 retMap.insert( OPimEvent::FStart, QString::number( zone.fromUTCDateTime( zone.toDateTime( startDateTime(), OPimTimeZone::utc() ) ) ) ); 563 retMap.insert( OPimEvent::FStart, QString::number( zone.fromUTCDateTime( zone.toDateTime( startDateTime(), OPimTimeZone::utc() ) ) ) );
567 retMap.insert( OPimEvent::FEnd, QString::number( zone.fromUTCDateTime( zone.toDateTime( endDateTime(), OPimTimeZone::utc() ) ) ) ); 564 retMap.insert( OPimEvent::FEnd, QString::number( zone.fromUTCDateTime( zone.toDateTime( endDateTime(), OPimTimeZone::utc() ) ) ) );
568 retMap.insert( OPimEvent::FNote, Qtopia::escapeString( note() ) ); 565 retMap.insert( OPimEvent::FNote, Qtopia::escapeString( note() ) );
569 retMap.insert( OPimEvent::FTimeZone, timeZone().isEmpty() ? QString( "None" ) : timeZone() ); 566 retMap.insert( OPimEvent::FTimeZone, timeZone().isEmpty() ? QString( "None" ) : timeZone() );
570 if ( parent() ) 567 if ( parent() )
571 retMap.insert( OPimEvent::FRecParent, QString::number( parent() ) ); 568 retMap.insert( OPimEvent::FRecParent, QString::number( parent() ) );
572 if ( children().count() ) 569 if ( children().count() )
573 { 570 {
574 QArray<int> childr = children(); 571 QArray<int> childr = children();
575 QString buf; 572 QString buf;
576 for ( uint i = 0; i < childr.count(); i++ ) 573 for ( uint i = 0; i < childr.count(); i++ )
577 { 574 {
578 if ( i != 0 ) buf += " "; 575 if ( i != 0 ) buf += " ";
579 buf += QString::number( childr[ i ] ); 576 buf += QString::number( childr[ i ] );
580 } 577 }
581 retMap.insert( OPimEvent::FRecChildren, buf ); 578 retMap.insert( OPimEvent::FRecChildren, buf );
582 } 579 }
583 580
584 // Add recurrence stuff 581 // Add recurrence stuff
585 if ( hasRecurrence() ) 582 if ( hasRecurrence() )
586 { 583 {
587 OPimRecurrence recur = recurrence(); 584 OPimRecurrence recur = recurrence();
588 QMap<int, QString> recFields = recur.toMap(); 585 QMap<int, QString> recFields = recur.toMap();
589 retMap.insert( OPimEvent::FRType, recFields[ OPimRecurrence::RType ] ); 586 retMap.insert( OPimEvent::FRType, recFields[ OPimRecurrence::RType ] );
590 retMap.insert( OPimEvent::FRWeekdays, recFields[ OPimRecurrence::RWeekdays ] ); 587 retMap.insert( OPimEvent::FRWeekdays, recFields[ OPimRecurrence::RWeekdays ] );
591 retMap.insert( OPimEvent::FRPosition, recFields[ OPimRecurrence::RPosition ] ); 588 retMap.insert( OPimEvent::FRPosition, recFields[ OPimRecurrence::RPosition ] );
592 retMap.insert( OPimEvent::FRFreq, recFields[ OPimRecurrence::RFreq ] ); 589 retMap.insert( OPimEvent::FRFreq, recFields[ OPimRecurrence::RFreq ] );
593 retMap.insert( OPimEvent::FRHasEndDate, recFields[ OPimRecurrence::RHasEndDate ] ); 590 retMap.insert( OPimEvent::FRHasEndDate, recFields[ OPimRecurrence::RHasEndDate ] );
594 retMap.insert( OPimEvent::FREndDate, recFields[ OPimRecurrence::EndDate ] ); 591 retMap.insert( OPimEvent::FREndDate, recFields[ OPimRecurrence::EndDate ] );
595 retMap.insert( OPimEvent::FRCreated, recFields[ OPimRecurrence::Created ] ); 592 retMap.insert( OPimEvent::FRCreated, recFields[ OPimRecurrence::Created ] );
596 retMap.insert( OPimEvent::FRExceptions, recFields[ OPimRecurrence::Exceptions ] ); 593 retMap.insert( OPimEvent::FRExceptions, recFields[ OPimRecurrence::Exceptions ] );
597 } 594 }
598 else 595 else
599 { 596 {
600 OPimRecurrence recur = recurrence(); 597 OPimRecurrence recur = recurrence();
601 QMap<int, QString> recFields = recur.toMap(); 598 QMap<int, QString> recFields = recur.toMap();
602 retMap.insert( OPimEvent::FRType, recFields[ OPimRecurrence::RType ] ); 599 retMap.insert( OPimEvent::FRType, recFields[ OPimRecurrence::RType ] );
603 } 600 }
604 601
605 return retMap; 602 return retMap;
606} 603}
607 604
608 605
609void OPimEvent::fromMap( const QMap<int, QString>& map ) 606void OPimEvent::fromMap( const QMap<int, QString>& map )
610{ 607{
611 608
612 // We just want to set the UID if it is really stored. 609 // We just want to set the UID if it is really stored.
613 if ( !map[ OPimEvent::FUid ].isEmpty() ) 610 if ( !map[ OPimEvent::FUid ].isEmpty() )
614 setUid( map[ OPimEvent::FUid ].toInt() ); 611 setUid( map[ OPimEvent::FUid ].toInt() );
615 612
616 setCategories( idsFromString( map[ OPimEvent::FCategories ] ) ); 613 setCategories( idsFromString( map[ OPimEvent::FCategories ] ) );
617 setDescription( map[ OPimEvent::FDescription ] ); 614 setDescription( map[ OPimEvent::FDescription ] );
618 setLocation( map[ OPimEvent::FLocation ] ); 615 setLocation( map[ OPimEvent::FLocation ] );
619 616
620 if ( map[ OPimEvent::FType ] == "AllDay" ) 617 if ( map[ OPimEvent::FType ] == "AllDay" )
621 setAllDay( true ); 618 setAllDay( true );
622 else 619 else
623 setAllDay( false ); 620 setAllDay( false );
624 621
625 int alarmTime = -1; 622 int alarmTime = -1;
626 if ( !map[ OPimEvent::FAlarm ].isEmpty() ) 623 if ( !map[ OPimEvent::FAlarm ].isEmpty() )
627 alarmTime = map[ OPimEvent::FAlarm ].toInt(); 624 alarmTime = map[ OPimEvent::FAlarm ].toInt();
628 625
629 int sound = ( ( map[ OPimEvent::FSound ] == "loud" ) ? OPimAlarm::Loud : OPimAlarm::Silent ); 626 int sound = ( ( map[ OPimEvent::FSound ] == "loud" ) ? OPimAlarm::Loud : OPimAlarm::Silent );
630 if ( ( alarmTime != -1 ) ) 627 if ( ( alarmTime != -1 ) )
631 { 628 {
632 QDateTime dt = startDateTime().addSecs( -1 * alarmTime * 60 ); 629 QDateTime dt = startDateTime().addSecs( -1 * alarmTime * 60 );
633 OPimAlarm al( sound , dt ); 630 OPimAlarm al( sound , dt );
634 notifiers().add( al ); 631 notifiers().add( al );
635 } 632 }
636 if ( !map[ OPimEvent::FTimeZone ].isEmpty() && ( map[ OPimEvent::FTimeZone ] != "None" ) ) 633 if ( !map[ OPimEvent::FTimeZone ].isEmpty() && ( map[ OPimEvent::FTimeZone ] != "None" ) )
637 { 634 {
638 setTimeZone( map[ OPimEvent::FTimeZone ] ); 635 setTimeZone( map[ OPimEvent::FTimeZone ] );
639 } 636 }
640 637
641 time_t start = ( time_t ) map[ OPimEvent::FStart ].toLong(); 638 time_t start = ( time_t ) map[ OPimEvent::FStart ].toLong();
642 time_t end = ( time_t ) map[ OPimEvent::FEnd ].toLong(); 639 time_t end = ( time_t ) map[ OPimEvent::FEnd ].toLong();
643 640
644 /* AllDay is always in UTC */ 641 /* AllDay is always in UTC */
645 if ( isAllDay() ) 642 if ( isAllDay() )
646 { 643 {
647 OPimTimeZone utc = OPimTimeZone::utc(); 644 OPimTimeZone utc = OPimTimeZone::utc();
648 setStartDateTime( utc.fromUTCDateTime( start ) ); 645 setStartDateTime( utc.fromUTCDateTime( start ) );
649 setEndDateTime ( utc.fromUTCDateTime( end ) ); 646 setEndDateTime ( utc.fromUTCDateTime( end ) );
650 setTimeZone( "UTC" ); // make sure it is really utc 647 setTimeZone( "UTC" ); // make sure it is really utc
651 } 648 }
652 else 649 else
653 { 650 {
654 /* to current date time */ 651 /* to current date time */
655 // qWarning(" Start is %d", start ); 652 // qWarning(" Start is %d", start );
656 OPimTimeZone zone( timeZone().isEmpty() ? OPimTimeZone::current() : timeZone() ); 653 OPimTimeZone zone( timeZone().isEmpty() ? OPimTimeZone::current() : timeZone() );
657 QDateTime date = zone.toDateTime( start ); 654 QDateTime date = zone.toDateTime( start );
658 qWarning( " Start is %s", date.toString().latin1() ); 655 qWarning( " Start is %s", date.toString().latin1() );
659 setStartDateTime( zone.toDateTime( date, OPimTimeZone::current() ) ); 656 setStartDateTime( zone.toDateTime( date, OPimTimeZone::current() ) );
660 657
661 date = zone.toDateTime( end ); 658 date = zone.toDateTime( end );
662 setEndDateTime ( zone.toDateTime( date, OPimTimeZone::current() ) ); 659 setEndDateTime ( zone.toDateTime( date, OPimTimeZone::current() ) );
663 } 660 }
664 661
665 if ( !map[ OPimEvent::FRecParent ].isEmpty() ) 662 if ( !map[ OPimEvent::FRecParent ].isEmpty() )
666 setParent( map[ OPimEvent::FRecParent ].toInt() ); 663 setParent( map[ OPimEvent::FRecParent ].toInt() );
667 664
668 if ( !map[ OPimEvent::FRecChildren ].isEmpty() ) 665 if ( !map[ OPimEvent::FRecChildren ].isEmpty() )
669 { 666 {
670 QStringList list = QStringList::split( ' ', map[ OPimEvent::FRecChildren ] ); 667 QStringList list = QStringList::split( ' ', map[ OPimEvent::FRecChildren ] );
671 for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) 668 for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it )
672 { 669 {
673 addChild( ( *it ).toInt() ); 670 addChild( ( *it ).toInt() );
674 } 671 }
675 } 672 }
676 673
677 // Fill recurrence stuff and put it directly into the OPimRecurrence-Object using fromMap.. 674 // Fill recurrence stuff and put it directly into the OPimRecurrence-Object using fromMap..
678 if ( !map[ OPimEvent::FRType ].isEmpty() ) 675 if ( !map[ OPimEvent::FRType ].isEmpty() )
679 { 676 {
680 QMap<int, QString> recFields; 677 QMap<int, QString> recFields;
681 recFields.insert( OPimRecurrence::RType, map[ OPimEvent::FRType ] ); 678 recFields.insert( OPimRecurrence::RType, map[ OPimEvent::FRType ] );
682 recFields.insert( OPimRecurrence::RWeekdays, map[ OPimEvent::FRWeekdays ] ); 679 recFields.insert( OPimRecurrence::RWeekdays, map[ OPimEvent::FRWeekdays ] );
683 recFields.insert( OPimRecurrence::RPosition, map[ OPimEvent::FRPosition ] ); 680 recFields.insert( OPimRecurrence::RPosition, map[ OPimEvent::FRPosition ] );
684 recFields.insert( OPimRecurrence::RFreq, map[ OPimEvent::FRFreq ] ); 681 recFields.insert( OPimRecurrence::RFreq, map[ OPimEvent::FRFreq ] );
685 recFields.insert( OPimRecurrence::RHasEndDate, map[ OPimEvent::FRHasEndDate ] ); 682 recFields.insert( OPimRecurrence::RHasEndDate, map[ OPimEvent::FRHasEndDate ] );
686 recFields.insert( OPimRecurrence::EndDate, map[ OPimEvent::FREndDate ] ); 683 recFields.insert( OPimRecurrence::EndDate, map[ OPimEvent::FREndDate ] );
687 recFields.insert( OPimRecurrence::Created, map[ OPimEvent::FRCreated ] ); 684 recFields.insert( OPimRecurrence::Created, map[ OPimEvent::FRCreated ] );
688 recFields.insert( OPimRecurrence::Exceptions, map[ OPimEvent::FRExceptions ] ); 685 recFields.insert( OPimRecurrence::Exceptions, map[ OPimEvent::FRExceptions ] );
689 OPimRecurrence recur( recFields ); 686 OPimRecurrence recur( recFields );
690 setRecurrence( recur ); 687 setRecurrence( recur );
691 } 688 }
692 689
693} 690}
694 691
695 692
696int OPimEvent::parent() const 693int OPimEvent::parent() const
697{ 694{
698 return data->parent; 695 return data->parent;
699} 696}
700 697
701 698
702void OPimEvent::setParent( int uid ) 699void OPimEvent::setParent( int uid )
703{ 700{
704 changeOrModify(); 701 changeOrModify();
705 data->parent = uid; 702 data->parent = uid;
706} 703}
707 704
708 705
709QArray<int> OPimEvent::children() const 706QArray<int> OPimEvent::children() const
710{ 707{
711 if ( !data->child ) return QArray<int>(); 708 if ( !data->child ) return QArray<int>();
712 else 709 else
713 return data->child->copy(); 710 return data->child->copy();
714} 711}
715 712
716 713
717void OPimEvent::setChildren( const QArray<int>& arr ) 714void OPimEvent::setChildren( const QArray<int>& arr )
718{ 715{
719 changeOrModify(); 716 changeOrModify();
720 if ( data->child ) delete data->child; 717 if ( data->child ) delete data->child;
721 718
722 data->child = new QArray<int>( arr ); 719 data->child = new QArray<int>( arr );
723 data->child->detach(); 720 data->child->detach();
724} 721}
725 722
726 723
727void OPimEvent::addChild( int uid ) 724void OPimEvent::addChild( int uid )
728{ 725{
729 changeOrModify(); 726 changeOrModify();
730 if ( !data->child ) 727 if ( !data->child )
731 { 728 {
732 data->child = new QArray<int>( 1 ); 729 data->child = new QArray<int>( 1 );
733 ( *data->child ) [ 0 ] = uid; 730 ( *data->child ) [ 0 ] = uid;
734 } 731 }
735 else 732 else
736 { 733 {
737 int count = data->child->count(); 734 int count = data->child->count();
738 data->child->resize( count + 1 ); 735 data->child->resize( count + 1 );
739 ( *data->child ) [ count ] = uid; 736 ( *data->child ) [ count ] = uid;
740 } 737 }
741} 738}
742 739
743 740
744void OPimEvent::removeChild( int uid ) 741void OPimEvent::removeChild( int uid )
745{ 742{
746 if ( !data->child || !data->child->contains( uid ) ) return ; 743 if ( !data->child || !data->child->contains( uid ) ) return ;
747 changeOrModify(); 744 changeOrModify();
748 QArray<int> newAr( data->child->count() - 1 ); 745 QArray<int> newAr( data->child->count() - 1 );
749 int j = 0; 746 int j = 0;
750 uint count = data->child->count(); 747 uint count = data->child->count();
751 for ( uint i = 0; i < count; i++ ) 748 for ( uint i = 0; i < count; i++ )
752 { 749 {
753 if ( ( *data->child ) [ i ] != uid ) 750 if ( ( *data->child ) [ i ] != uid )
754 { 751 {
755 newAr[ j ] = ( *data->child ) [ i ]; 752 newAr[ j ] = ( *data->child ) [ i ];
756 j++; 753 j++;
757 } 754 }
758 } 755 }
759 ( *data->child ) = newAr; 756 ( *data->child ) = newAr;
760} 757}
761 758
762 759
763struct OEffectiveEvent::Data : public QShared 760struct OEffectiveEvent::Data : public QShared
764{ 761{
765 Data() : QShared() 762 Data() : QShared()
766 {} 763 {}
767 OPimEvent event; 764 OPimEvent event;
768 QDate date; 765 QDate date;
769 QTime start, end; 766 QTime start, end;
770 QDate startDate, endDate; 767 QDate startDate, endDate;
771bool dates : 1; 768bool dates : 1;
772}; 769};
773 770
774 771
775OEffectiveEvent::OEffectiveEvent() 772OEffectiveEvent::OEffectiveEvent()
776{ 773{
777 data = new Data; 774 data = new Data;
778 data->date = QDate::currentDate(); 775 data->date = QDate::currentDate();
779 data->start = data->end = QTime::currentTime(); 776 data->start = data->end = QTime::currentTime();
780 data->dates = false; 777 data->dates = false;
781} 778}
782 779
783 780
784OEffectiveEvent::OEffectiveEvent( const OPimEvent& ev, const QDate& startDate, 781OEffectiveEvent::OEffectiveEvent( const OPimEvent& ev, const QDate& startDate,
785 Position pos ) 782 Position pos )
786{ 783{
787 data = new Data; 784 data = new Data;
788 data->event = ev; 785 data->event = ev;
789 data->date = startDate; 786 data->date = startDate;
790 if ( pos & Start ) 787 if ( pos & Start )
791 data->start = ev.startDateTime().time(); 788 data->start = ev.startDateTime().time();
792 else 789 else
793 data->start = QTime( 0, 0, 0 ); 790 data->start = QTime( 0, 0, 0 );
794 791
795 if ( pos & End ) 792 if ( pos & End )
796 data->end = ev.endDateTime().time(); 793 data->end = ev.endDateTime().time();
797 else 794 else
798 data->end = QTime( 23, 59, 59 ); 795 data->end = QTime( 23, 59, 59 );
799 796
800 data->dates = false; 797 data->dates = false;
801} 798}
802 799
803 800
804OEffectiveEvent::OEffectiveEvent( const OEffectiveEvent& ev ) 801OEffectiveEvent::OEffectiveEvent( const OEffectiveEvent& ev )
805{ 802{
806 data = ev.data; 803 data = ev.data;
807 data->ref(); 804 data->ref();
808} 805}
809 806
810 807
811OEffectiveEvent::~OEffectiveEvent() 808OEffectiveEvent::~OEffectiveEvent()
812{ 809{
813 if ( data->deref() ) 810 if ( data->deref() )
814 { 811 {
815 delete data; 812 delete data;
816 data = 0; 813 data = 0;
817 } 814 }
818} 815}
819 816
820 817
821OEffectiveEvent& OEffectiveEvent::operator=( const OEffectiveEvent& ev ) 818OEffectiveEvent& OEffectiveEvent::operator=( const OEffectiveEvent& ev )
822{ 819{
823 if ( *this == ev ) return * this; 820 if ( *this == ev ) return * this;
824 821
825 ev.data->ref(); 822 ev.data->ref();
826 deref(); 823 deref();
827 data = ev.data; 824 data = ev.data;
828 825
829 return *this; 826 return *this;
830} 827}
831 828
832 829
833void OEffectiveEvent::setStartTime( const QTime& ti ) 830void OEffectiveEvent::setStartTime( const QTime& ti )
834{ 831{
835 changeOrModify(); 832 changeOrModify();
836 data->start = ti; 833 data->start = ti;
837} 834}
838 835
839 836
840void OEffectiveEvent::setEndTime( const QTime& en ) 837void OEffectiveEvent::setEndTime( const QTime& en )
841{ 838{
842 changeOrModify(); 839 changeOrModify();
843 data->end = en; 840 data->end = en;
844} 841}
845 842
846 843
847void OEffectiveEvent::setEvent( const OPimEvent& ev ) 844void OEffectiveEvent::setEvent( const OPimEvent& ev )
848{ 845{
849 changeOrModify(); 846 changeOrModify();
850 data->event = ev; 847 data->event = ev;
851} 848}
852 849
853 850
854void OEffectiveEvent::setDate( const QDate& da ) 851void OEffectiveEvent::setDate( const QDate& da )
855{ 852{
856 changeOrModify(); 853 changeOrModify();
857 data->date = da; 854 data->date = da;
858} 855}
859 856
860 857
861void OEffectiveEvent::setEffectiveDates( const QDate& from, 858void OEffectiveEvent::setEffectiveDates( const QDate& from,
862 const QDate& to ) 859 const QDate& to )
863{ 860{
864 if ( !from.isValid() ) 861 if ( !from.isValid() )
865 { 862 {
866 data->dates = false; 863 data->dates = false;
867 return ; 864 return ;
868 } 865 }
869 866
870 data->startDate = from; 867 data->startDate = from;
871 data->endDate = to; 868 data->endDate = to;
872} 869}
873 870
874 871
875QString OEffectiveEvent::description() const 872QString OEffectiveEvent::description() const
876{ 873{
877 return data->event.description(); 874 return data->event.description();
878} 875}
879 876
880 877
881QString OEffectiveEvent::location() const 878QString OEffectiveEvent::location() const
882{ 879{
883 return data->event.location(); 880 return data->event.location();
884} 881}
885 882
886 883
887QString OEffectiveEvent::note() const 884QString OEffectiveEvent::note() const
888{ 885{
889 return data->event.note(); 886 return data->event.note();
890} 887}
891 888
892 889
893OPimEvent OEffectiveEvent::event() const 890OPimEvent OEffectiveEvent::event() const
894{ 891{
895 return data->event; 892 return data->event;
896} 893}
897 894
898 895
899QTime OEffectiveEvent::startTime() const 896QTime OEffectiveEvent::startTime() const
900{ 897{
901 return data->start; 898 return data->start;
902} 899}
903 900
904 901
905QTime OEffectiveEvent::endTime() const 902QTime OEffectiveEvent::endTime() const
906{ 903{
907 return data->end; 904 return data->end;
908} 905}
909 906
910 907
911QDate OEffectiveEvent::date() const 908QDate OEffectiveEvent::date() const
912{ 909{
913 return data->date; 910 return data->date;
914} 911}
915 912
916 913
917int OEffectiveEvent::length() const 914int OEffectiveEvent::length() const
918{ 915{
919 return ( data->end.hour() * 60 - data->start.hour() * 60 ) 916 return ( data->end.hour() * 60 - data->start.hour() * 60 )
920 + QABS( data->start.minute() - data->end.minute() ); 917 + QABS( data->start.minute() - data->end.minute() );
921} 918}
922 919
923 920
924int OEffectiveEvent::size() const 921int OEffectiveEvent::size() const
925{ 922{
926 return ( data->end.hour() - data->start.hour() ) * 3600 923 return ( data->end.hour() - data->start.hour() ) * 3600
927 + ( data->end.minute() - data->start.minute() * 60 924 + ( data->end.minute() - data->start.minute() * 60
928 + data->end.second() - data->start.second() ); 925 + data->end.second() - data->start.second() );
929} 926}
930 927
931 928
932QDate OEffectiveEvent::startDate() const 929QDate OEffectiveEvent::startDate() const
933{ 930{
934 if ( data->dates ) 931 if ( data->dates )
935 return data->startDate; 932 return data->startDate;
936 else if ( data->event.hasRecurrence() ) // single day, since multi-day should have a d pointer 933 else if ( data->event.hasRecurrence() ) // single day, since multi-day should have a d pointer
937 return data->date; 934 return data->date;
938 else 935 else
939 return data->event.startDateTime().date(); 936 return data->event.startDateTime().date();
940} 937}
941 938
942 939
943QDate OEffectiveEvent::endDate() const 940QDate OEffectiveEvent::endDate() const
944{ 941{
945 if ( data->dates ) 942 if ( data->dates )
946 return data->endDate; 943 return data->endDate;
947 else if ( data->event.hasRecurrence() ) 944 else if ( data->event.hasRecurrence() )
948 return data->date; 945 return data->date;
949 else 946 else
950 return data->event.endDateTime().date(); 947 return data->event.endDateTime().date();
951} 948}
952 949
953 950
954void OEffectiveEvent::deref() 951void OEffectiveEvent::deref()
955{ 952{
956 if ( data->deref() ) 953 if ( data->deref() )
957 { 954 {
958 delete data; 955 delete data;
959 data = 0; 956 data = 0;
960 } 957 }
961} 958}
962 959
963 960
964void OEffectiveEvent::changeOrModify() 961void OEffectiveEvent::changeOrModify()
965{ 962{
966 if ( data->count != 1 ) 963 if ( data->count != 1 )
967 { 964 {
968 data->deref(); 965 data->deref();
969 Data* d2 = new Data; 966 Data* d2 = new Data;
970 d2->event = data->event; 967 d2->event = data->event;
971 d2->date = data->date; 968 d2->date = data->date;
972 d2->start = data->start; 969 d2->start = data->start;
973 d2->end = data->end; 970 d2->end = data->end;
974 d2->startDate = data->startDate; 971 d2->startDate = data->startDate;
975 d2->endDate = data->endDate; 972 d2->endDate = data->endDate;
976 d2->dates = data->dates; 973 d2->dates = data->dates;
977 data = d2; 974 data = d2;
978 } 975 }
979} 976}
980 977
981 978
982bool OEffectiveEvent::operator<( const OEffectiveEvent &e ) const 979bool OEffectiveEvent::operator<( const OEffectiveEvent &e ) const
983{ 980{
984 if ( data->date < e.date() ) 981 if ( data->date < e.date() )
985 return TRUE; 982 return TRUE;
986 if ( data->date == e.date() ) 983 if ( data->date == e.date() )
987 return ( startTime() < e.startTime() ); 984 return ( startTime() < e.startTime() );
988 else 985 else
989 return FALSE; 986 return FALSE;
990} 987}
991 988
992 989
993bool OEffectiveEvent::operator<=( const OEffectiveEvent &e ) const 990bool OEffectiveEvent::operator<=( const OEffectiveEvent &e ) const
994{ 991{
995 return ( data->date <= e.date() ); 992 return ( data->date <= e.date() );
996} 993}
997 994
998 995
999bool OEffectiveEvent::operator==( const OEffectiveEvent &e ) const 996bool OEffectiveEvent::operator==( const OEffectiveEvent &e ) const
1000{ 997{
1001 return ( date() == e.date() 998 return ( date() == e.date()
1002 && startTime() == e.startTime() 999 && startTime() == e.startTime()
1003 && endTime() == e.endTime() 1000 && endTime() == e.endTime()
1004 && event() == e.event() ); 1001 && event() == e.event() );
1005} 1002}
1006 1003
1007 1004
1008bool OEffectiveEvent::operator!=( const OEffectiveEvent &e ) const 1005bool OEffectiveEvent::operator!=( const OEffectiveEvent &e ) const
1009{ 1006{
1010 return !( *this == e ); 1007 return !( *this == e );
1011} 1008}
1012 1009
1013 1010
1014bool OEffectiveEvent::operator>( const OEffectiveEvent &e ) const 1011bool OEffectiveEvent::operator>( const OEffectiveEvent &e ) const
1015{ 1012{
1016 return !( *this <= e ); 1013 return !( *this <= e );
1017} 1014}
1018 1015
1019 1016
1020bool OEffectiveEvent::operator>= ( const OEffectiveEvent &e ) const 1017bool OEffectiveEvent::operator>= ( const OEffectiveEvent &e ) const
1021{ 1018{
1022 return !( *this < e ); 1019 return !( *this < e );
1023} 1020}
1024 1021
1025} 1022}
diff --git a/libopie2/opiepim/core/opimnotify.cpp b/libopie2/opiepim/core/opimnotify.cpp
index 43858f0..417b0b9 100644
--- a/libopie2/opiepim/core/opimnotify.cpp
+++ b/libopie2/opiepim/core/opimnotify.cpp
@@ -1,379 +1,378 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) The Main Author <main-author@whereever.org> 3 Copyright (C) The Main Author <main-author@whereever.org>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 4 =. Copyright (C) The Opie Team <opie-devel@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 "opimnotify.h" 30#include "opimnotify.h"
31 31
32/* QT */ 32/* QT */
33#include <qshared.h>
34 33
35namespace Opie 34namespace Opie
36{ 35{
37 36
38struct OPimNotify::Data : public QShared 37struct OPimNotify::Data : public QShared
39{ 38{
40 Data() : QShared(), dur( -1 ), parent( 0 ) 39 Data() : QShared(), dur( -1 ), parent( 0 )
41 { 40 {
42 } 41 }
43 QDateTime start; 42 QDateTime start;
44 int dur; 43 int dur;
45 QString application; 44 QString application;
46 int parent; 45 int parent;
47}; 46};
48 47
49OPimNotify::OPimNotify( const QDateTime& start, int duration, int parent ) 48OPimNotify::OPimNotify( const QDateTime& start, int duration, int parent )
50{ 49{
51 data = new Data; 50 data = new Data;
52 data->start = start; 51 data->start = start;
53 data->dur = duration; 52 data->dur = duration;
54 data->parent = parent; 53 data->parent = parent;
55} 54}
56 55
57 56
58OPimNotify::OPimNotify( const OPimNotify& noti ) 57OPimNotify::OPimNotify( const OPimNotify& noti )
59 : data( noti.data ) 58 : data( noti.data )
60{ 59{
61 data->ref(); 60 data->ref();
62} 61}
63 62
64 63
65OPimNotify::~OPimNotify() 64OPimNotify::~OPimNotify()
66{ 65{
67 if ( data->deref() ) 66 if ( data->deref() )
68 { 67 {
69 delete data; 68 delete data;
70 data = 0l; 69 data = 0l;
71 } 70 }
72} 71}
73 72
74 73
75OPimNotify &OPimNotify::operator=( const OPimNotify& noti ) 74OPimNotify &OPimNotify::operator=( const OPimNotify& noti )
76{ 75{
77 noti.data->ref(); 76 noti.data->ref();
78 deref(); 77 deref();
79 data = noti.data; 78 data = noti.data;
80 79
81 return *this; 80 return *this;
82} 81}
83 82
84 83
85bool OPimNotify::operator==( const OPimNotify& noti ) 84bool OPimNotify::operator==( const OPimNotify& noti )
86{ 85{
87 if ( data == noti.data ) return true; 86 if ( data == noti.data ) return true;
88 if ( data->dur != noti.data->dur ) return false; 87 if ( data->dur != noti.data->dur ) return false;
89 if ( data->parent != noti.data->parent ) return false; 88 if ( data->parent != noti.data->parent ) return false;
90 if ( data->application != noti.data->application ) return false; 89 if ( data->application != noti.data->application ) return false;
91 if ( data->start != noti.data->start ) return false; 90 if ( data->start != noti.data->start ) return false;
92 91
93 return true; 92 return true;
94} 93}
95 94
96 95
97QDateTime OPimNotify::dateTime() const 96QDateTime OPimNotify::dateTime() const
98{ 97{
99 return data->start; 98 return data->start;
100} 99}
101 100
102 101
103QString OPimNotify::service() const 102QString OPimNotify::service() const
104{ 103{
105 return data->application; 104 return data->application;
106} 105}
107 106
108 107
109int OPimNotify::parent() const 108int OPimNotify::parent() const
110{ 109{
111 return data->parent; 110 return data->parent;
112} 111}
113 112
114 113
115int OPimNotify::duration() const 114int OPimNotify::duration() const
116{ 115{
117 return data->dur; 116 return data->dur;
118} 117}
119 118
120 119
121QDateTime OPimNotify::endTime() const 120QDateTime OPimNotify::endTime() const
122{ 121{
123 return QDateTime( data->start.date(), data->start.time().addSecs( data->dur ) ); 122 return QDateTime( data->start.date(), data->start.time().addSecs( data->dur ) );
124} 123}
125 124
126 125
127void OPimNotify::setDateTime( const QDateTime& time ) 126void OPimNotify::setDateTime( const QDateTime& time )
128{ 127{
129 copyIntern(); 128 copyIntern();
130 data->start = time; 129 data->start = time;
131} 130}
132 131
133 132
134void OPimNotify::setDuration( int dur ) 133void OPimNotify::setDuration( int dur )
135{ 134{
136 copyIntern(); 135 copyIntern();
137 data->dur = dur; 136 data->dur = dur;
138} 137}
139 138
140 139
141void OPimNotify::setParent( int uid ) 140void OPimNotify::setParent( int uid )
142{ 141{
143 copyIntern(); 142 copyIntern();
144 data->parent = uid; 143 data->parent = uid;
145} 144}
146 145
147 146
148void OPimNotify::setService( const QString& str ) 147void OPimNotify::setService( const QString& str )
149{ 148{
150 copyIntern(); 149 copyIntern();
151 data->application = str; 150 data->application = str;
152} 151}
153 152
154 153
155void OPimNotify::copyIntern() 154void OPimNotify::copyIntern()
156{ 155{
157 if ( data->count != 1 ) 156 if ( data->count != 1 )
158 { 157 {
159 data->deref(); 158 data->deref();
160 Data* dat = new Data; 159 Data* dat = new Data;
161 dat->start = data->start; 160 dat->start = data->start;
162 dat->dur = data->dur; 161 dat->dur = data->dur;
163 dat->application = data->application; 162 dat->application = data->application;
164 dat->parent = data->parent; 163 dat->parent = data->parent;
165 data = dat; 164 data = dat;
166 } 165 }
167} 166}
168 167
169 168
170void OPimNotify::deref() 169void OPimNotify::deref()
171{ 170{
172 if ( data->deref() ) 171 if ( data->deref() )
173 { 172 {
174 delete data; 173 delete data;
175 data = 0; 174 data = 0;
176 } 175 }
177} 176}
178 177
179 178
180/***********************************************************/ 179/***********************************************************/
181struct OPimAlarm::Data : public QShared 180struct OPimAlarm::Data : public QShared
182{ 181{
183 Data() : QShared() 182 Data() : QShared()
184 { 183 {
185 sound = 1; 184 sound = 1;
186 } 185 }
187 int sound; 186 int sound;
188 QString file; 187 QString file;
189}; 188};
190 189
191 190
192OPimAlarm::OPimAlarm( int sound, const QDateTime& start, int duration, int parent ) 191OPimAlarm::OPimAlarm( int sound, const QDateTime& start, int duration, int parent )
193 : OPimNotify( start, duration, parent ) 192 : OPimNotify( start, duration, parent )
194{ 193{
195 data = new Data; 194 data = new Data;
196 data->sound = sound; 195 data->sound = sound;
197} 196}
198 197
199 198
200OPimAlarm::OPimAlarm( const OPimAlarm& al ) 199OPimAlarm::OPimAlarm( const OPimAlarm& al )
201 : OPimNotify( al ), data( al.data ) 200 : OPimNotify( al ), data( al.data )
202{ 201{
203 data->ref(); 202 data->ref();
204} 203}
205 204
206 205
207OPimAlarm::~OPimAlarm() 206OPimAlarm::~OPimAlarm()
208{ 207{
209 if ( data->deref() ) 208 if ( data->deref() )
210 { 209 {
211 delete data; 210 delete data;
212 data = 0l; 211 data = 0l;
213 } 212 }
214} 213}
215 214
216 215
217OPimAlarm &OPimAlarm::operator=( const OPimAlarm& al ) 216OPimAlarm &OPimAlarm::operator=( const OPimAlarm& al )
218{ 217{
219 OPimNotify::operator=( al ); 218 OPimNotify::operator=( al );
220 deref(); 219 deref();
221 al.data->ref(); 220 al.data->ref();
222 221
223 data = al.data; 222 data = al.data;
224 223
225 224
226 return *this; 225 return *this;
227} 226}
228 227
229 228
230bool OPimAlarm::operator==( const OPimAlarm& al ) 229bool OPimAlarm::operator==( const OPimAlarm& al )
231{ 230{
232 if ( data->sound != al.data->sound ) return false; 231 if ( data->sound != al.data->sound ) return false;
233 else if ( data->sound == Custom && data->file != al.data->file ) 232 else if ( data->sound == Custom && data->file != al.data->file )
234 return false; 233 return false;
235 234
236 return OPimNotify::operator==( al ); 235 return OPimNotify::operator==( al );
237} 236}
238 237
239 238
240QString OPimAlarm::type() const 239QString OPimAlarm::type() const
241{ 240{
242 return QString::fromLatin1( "OPimAlarm" ); 241 return QString::fromLatin1( "OPimAlarm" );
243} 242}
244 243
245 244
246int OPimAlarm::sound() const 245int OPimAlarm::sound() const
247{ 246{
248 return data->sound; 247 return data->sound;
249} 248}
250 249
251 250
252QString OPimAlarm::file() const 251QString OPimAlarm::file() const
253{ 252{
254 return data->file; 253 return data->file;
255} 254}
256 255
257 256
258void OPimAlarm::setSound( int snd ) 257void OPimAlarm::setSound( int snd )
259{ 258{
260 copyIntern(); 259 copyIntern();
261 data->sound = snd; 260 data->sound = snd;
262} 261}
263 262
264 263
265void OPimAlarm::setFile( const QString& sound ) 264void OPimAlarm::setFile( const QString& sound )
266{ 265{
267 copyIntern(); 266 copyIntern();
268 data->file = sound; 267 data->file = sound;
269} 268}
270 269
271 270
272void OPimAlarm::deref() 271void OPimAlarm::deref()
273{ 272{
274 if ( data->deref() ) 273 if ( data->deref() )
275 { 274 {
276 delete data; 275 delete data;
277 data = 0l; 276 data = 0l;
278 } 277 }
279} 278}
280 279
281 280
282void OPimAlarm::copyIntern() 281void OPimAlarm::copyIntern()
283{ 282{
284 if ( data->count != 1 ) 283 if ( data->count != 1 )
285 { 284 {
286 data->deref(); 285 data->deref();
287 Data *newDat = new Data; 286 Data *newDat = new Data;
288 newDat->sound = data->sound; 287 newDat->sound = data->sound;
289 newDat->file = data->file; 288 newDat->file = data->file;
290 data = newDat; 289 data = newDat;
291 } 290 }
292} 291}
293 292
294 293
295/************************/ 294/************************/
296struct OPimReminder::Data : public QShared 295struct OPimReminder::Data : public QShared
297{ 296{
298 Data() : QShared(), record( 0 ) 297 Data() : QShared(), record( 0 )
299 {} 298 {}
300 int record; 299 int record;
301 300
302}; 301};
303 302
304 303
305OPimReminder::OPimReminder( int uid, const QDateTime& start, int dur, int parent ) 304OPimReminder::OPimReminder( int uid, const QDateTime& start, int dur, int parent )
306 : OPimNotify( start, dur, parent ) 305 : OPimNotify( start, dur, parent )
307{ 306{
308 data = new Data; 307 data = new Data;
309 data->record = uid; 308 data->record = uid;
310} 309}
311 310
312 311
313OPimReminder::OPimReminder( const OPimReminder& rem ) 312OPimReminder::OPimReminder( const OPimReminder& rem )
314 : OPimNotify( rem ), data( rem.data ) 313 : OPimNotify( rem ), data( rem.data )
315{ 314{
316 data->ref(); 315 data->ref();
317} 316}
318 317
319 318
320OPimReminder& OPimReminder::operator=( const OPimReminder& rem ) 319OPimReminder& OPimReminder::operator=( const OPimReminder& rem )
321{ 320{
322 OPimNotify::operator=( rem ); 321 OPimNotify::operator=( rem );
323 322
324 deref(); 323 deref();
325 rem.data->ref(); 324 rem.data->ref();
326 data = rem.data; 325 data = rem.data;
327 326
328 return *this; 327 return *this;
329} 328}
330 329
331 330
332bool OPimReminder::operator==( const OPimReminder& rem ) 331bool OPimReminder::operator==( const OPimReminder& rem )
333{ 332{
334 if ( data->record != rem.data->record ) return false; 333 if ( data->record != rem.data->record ) return false;
335 334
336 return OPimNotify::operator==( rem ); 335 return OPimNotify::operator==( rem );
337} 336}
338 337
339 338
340QString OPimReminder::type() const 339QString OPimReminder::type() const
341{ 340{
342 return QString::fromLatin1( "OPimReminder" ); 341 return QString::fromLatin1( "OPimReminder" );
343} 342}
344 343
345 344
346int OPimReminder::recordUid() const 345int OPimReminder::recordUid() const
347{ 346{
348 return data->record; 347 return data->record;
349} 348}
350 349
351 350
352void OPimReminder::setRecordUid( int uid ) 351void OPimReminder::setRecordUid( int uid )
353{ 352{
354 copyIntern(); 353 copyIntern();
355 data->record = uid; 354 data->record = uid;
356} 355}
357 356
358 357
359void OPimReminder::deref() 358void OPimReminder::deref()
360{ 359{
361 if ( data->deref() ) 360 if ( data->deref() )
362 { 361 {
363 delete data; 362 delete data;
364 data = 0l; 363 data = 0l;
365 } 364 }
366} 365}
367 366
368 367
369void OPimReminder::copyIntern() 368void OPimReminder::copyIntern()
370{ 369{
371 if ( data->count != 1 ) 370 if ( data->count != 1 )
372 { 371 {
373 Data * da = new Data; 372 Data * da = new Data;
374 da->record = data->record; 373 da->record = data->record;
375 data = da; 374 data = da;
376 } 375 }
377} 376}
378 377
379} 378}
diff --git a/libopie2/opiepim/core/opimrecord.cpp b/libopie2/opiepim/core/opimrecord.cpp
index c603f44..67eed41 100644
--- a/libopie2/opiepim/core/opimrecord.cpp
+++ b/libopie2/opiepim/core/opimrecord.cpp
@@ -1,274 +1,273 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) The Main Author <main-author@whereever.org> 3 Copyright (C) The Main Author <main-author@whereever.org>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 4 =. Copyright (C) The Opie Team <opie-devel@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 "opimrecord.h" 30#include "opimrecord.h"
31 31
32/* OPIE */ 32/* OPIE */
33#include <qpe/categories.h> 33#include <qpe/categories.h>
34#include <qpe/categoryselect.h> 34#include <qpe/categoryselect.h>
35 35
36/* QT */ 36/* QT */
37#include <qarray.h>
38 37
39namespace Opie 38namespace Opie
40{ 39{
41Qtopia::UidGen OPimRecord::m_uidGen( Qtopia::UidGen::Qtopia ); 40Qtopia::UidGen OPimRecord::m_uidGen( Qtopia::UidGen::Qtopia );
42 41
43 42
44OPimRecord::OPimRecord( int uid ) 43OPimRecord::OPimRecord( int uid )
45 : Qtopia::Record() 44 : Qtopia::Record()
46{ 45{
47 46
48 m_lastHit = -1; 47 m_lastHit = -1;
49 setUid( uid ); 48 setUid( uid );
50} 49}
51 50
52 51
53OPimRecord::~OPimRecord() 52OPimRecord::~OPimRecord()
54{} 53{}
55 54
56 55
57OPimRecord::OPimRecord( const OPimRecord& rec ) 56OPimRecord::OPimRecord( const OPimRecord& rec )
58 : Qtopia::Record( rec ) 57 : Qtopia::Record( rec )
59{ 58{
60 ( *this ) = rec; 59 ( *this ) = rec;
61} 60}
62 61
63 62
64OPimRecord &OPimRecord::operator=( const OPimRecord& rec ) 63OPimRecord &OPimRecord::operator=( const OPimRecord& rec )
65{ 64{
66 if ( this == &rec ) return * this; 65 if ( this == &rec ) return * this;
67 66
68 Qtopia::Record::operator=( rec ); 67 Qtopia::Record::operator=( rec );
69 m_xrefman = rec.m_xrefman; 68 m_xrefman = rec.m_xrefman;
70 m_lastHit = rec.m_lastHit; 69 m_lastHit = rec.m_lastHit;
71 70
72 return *this; 71 return *this;
73} 72}
74 73
75 74
76/* 75/*
77 * category names 76 * category names
78 */ 77 */
79QStringList OPimRecord::categoryNames( const QString& appname ) const 78QStringList OPimRecord::categoryNames( const QString& appname ) const
80{ 79{
81 QStringList list; 80 QStringList list;
82 QArray<int> cats = categories(); 81 QArray<int> cats = categories();
83 Categories catDB; 82 Categories catDB;
84 catDB.load( categoryFileName() ); 83 catDB.load( categoryFileName() );
85 84
86 for ( uint i = 0; i < cats.count(); i++ ) 85 for ( uint i = 0; i < cats.count(); i++ )
87 { 86 {
88 list << catDB.label( appname, cats[ i ] ); 87 list << catDB.label( appname, cats[ i ] );
89 } 88 }
90 89
91 return list; 90 return list;
92} 91}
93 92
94 93
95void OPimRecord::setCategoryNames( const QStringList& ) 94void OPimRecord::setCategoryNames( const QStringList& )
96{ 95{
97} 96}
98 97
99 98
100void OPimRecord::addCategoryName( const QString& ) 99void OPimRecord::addCategoryName( const QString& )
101{ 100{
102 Categories catDB; 101 Categories catDB;
103 catDB.load( categoryFileName() ); 102 catDB.load( categoryFileName() );
104 103
105 104
106} 105}
107 106
108 107
109bool OPimRecord::isEmpty() const 108bool OPimRecord::isEmpty() const
110{ 109{
111 return ( uid() == 0 ); 110 return ( uid() == 0 );
112} 111}
113 112
114 113
115/*QString OPimRecord::crossToString()const { 114/*QString OPimRecord::crossToString()const {
116 QString str; 115 QString str;
117 QMap<QString, QArray<int> >::ConstIterator it; 116 QMap<QString, QArray<int> >::ConstIterator it;
118 for (it = m_relations.begin(); it != m_relations.end(); ++it ) { 117 for (it = m_relations.begin(); it != m_relations.end(); ++it ) {
119 QArray<int> id = it.data(); 118 QArray<int> id = it.data();
120 for ( uint i = 0; i < id.size(); ++i ) { 119 for ( uint i = 0; i < id.size(); ++i ) {
121 str += it.key() + "," + QString::number( i ) + ";"; 120 str += it.key() + "," + QString::number( i ) + ";";
122 } 121 }
123 } 122 }
124 str = str.remove( str.length()-1, 1); // strip the ; 123 str = str.remove( str.length()-1, 1); // strip the ;
125 //qWarning("IDS " + str ); 124 //qWarning("IDS " + str );
126 125
127 return str; 126 return str;
128 }*/ 127 }*/
129/* if uid = 1 assign a new one */ 128/* if uid = 1 assign a new one */
130void OPimRecord::setUid( int uid ) 129void OPimRecord::setUid( int uid )
131{ 130{
132 if ( uid == 1 ) 131 if ( uid == 1 )
133 uid = uidGen().generate(); 132 uid = uidGen().generate();
134 133
135 Qtopia::Record::setUid( uid ); 134 Qtopia::Record::setUid( uid );
136}; 135};
137 136
138 137
139Qtopia::UidGen &OPimRecord::uidGen() 138Qtopia::UidGen &OPimRecord::uidGen()
140{ 139{
141 return m_uidGen; 140 return m_uidGen;
142} 141}
143 142
144 143
145OPimXRefManager &OPimRecord::xrefmanager() 144OPimXRefManager &OPimRecord::xrefmanager()
146{ 145{
147 return m_xrefman; 146 return m_xrefman;
148} 147}
149 148
150 149
151int OPimRecord::rtti() 150int OPimRecord::rtti()
152{ 151{
153 return 0; 152 return 0;
154} 153}
155 154
156/** 155/**
157 * now let's put our data into the stream 156 * now let's put our data into the stream
158 */ 157 */
159/* 158/*
160 * First read UID 159 * First read UID
161 * Categories 160 * Categories
162 * XRef 161 * XRef
163 */ 162 */
164bool OPimRecord::loadFromStream( QDataStream& stream ) 163bool OPimRecord::loadFromStream( QDataStream& stream )
165{ 164{
166 int Int; 165 int Int;
167 uint UInt; 166 uint UInt;
168 stream >> Int; 167 stream >> Int;
169 setUid( Int ); 168 setUid( Int );
170 169
171 /** Categories */ 170 /** Categories */
172 stream >> UInt; 171 stream >> UInt;
173 QArray<int> array( UInt ); 172 QArray<int> array( UInt );
174 for ( uint i = 0; i < UInt; i++ ) 173 for ( uint i = 0; i < UInt; i++ )
175 { 174 {
176 stream >> array[ i ]; 175 stream >> array[ i ];
177 } 176 }
178 setCategories( array ); 177 setCategories( array );
179 178
180 /* 179 /*
181 * now we do the X-Ref stuff 180 * now we do the X-Ref stuff
182 */ 181 */
183 OPimXRef xref; 182 OPimXRef xref;
184 stream >> UInt; 183 stream >> UInt;
185 for ( uint i = 0; i < UInt; i++ ) 184 for ( uint i = 0; i < UInt; i++ )
186 { 185 {
187 xref.setPartner( OPimXRef::One, partner( stream ) ); 186 xref.setPartner( OPimXRef::One, partner( stream ) );
188 xref.setPartner( OPimXRef::Two, partner( stream ) ); 187 xref.setPartner( OPimXRef::Two, partner( stream ) );
189 m_xrefman.add( xref ); 188 m_xrefman.add( xref );
190 } 189 }
191 190
192 return true; 191 return true;
193} 192}
194 193
195 194
196bool OPimRecord::saveToStream( QDataStream& stream ) const 195bool OPimRecord::saveToStream( QDataStream& stream ) const
197{ 196{
198 /** UIDs */ 197 /** UIDs */
199 198
200 stream << uid(); 199 stream << uid();
201 200
202 /** Categories */ 201 /** Categories */
203 stream << categories().count(); 202 stream << categories().count();
204 for ( uint i = 0; i < categories().count(); i++ ) 203 for ( uint i = 0; i < categories().count(); i++ )
205 { 204 {
206 stream << categories() [ i ]; 205 stream << categories() [ i ];
207 } 206 }
208 207
209 /* 208 /*
210 * first the XRef count 209 * first the XRef count
211 * then the xrefs 210 * then the xrefs
212 */ 211 */
213 stream << m_xrefman.list().count(); 212 stream << m_xrefman.list().count();
214 for ( OPimXRef::ValueList::ConstIterator it = m_xrefman.list().begin(); 213 for ( OPimXRef::ValueList::ConstIterator it = m_xrefman.list().begin();
215 it != m_xrefman.list().end(); ++it ) 214 it != m_xrefman.list().end(); ++it )
216 { 215 {
217 flush( ( *it ).partner( OPimXRef::One ), stream ); 216 flush( ( *it ).partner( OPimXRef::One ), stream );
218 flush( ( *it ).partner( OPimXRef::Two ), stream ); 217 flush( ( *it ).partner( OPimXRef::Two ), stream );
219 } 218 }
220 return true; 219 return true;
221} 220}
222 221
223 222
224void OPimRecord::flush( const OPimXRefPartner& par, QDataStream& str ) const 223void OPimRecord::flush( const OPimXRefPartner& par, QDataStream& str ) const
225{ 224{
226 str << par.service(); 225 str << par.service();
227 str << par.uid(); 226 str << par.uid();
228 str << par.field(); 227 str << par.field();
229} 228}
230 229
231 230
232OPimXRefPartner OPimRecord::partner( QDataStream& stream ) 231OPimXRefPartner OPimRecord::partner( QDataStream& stream )
233{ 232{
234 OPimXRefPartner par; 233 OPimXRefPartner par;
235 QString str; 234 QString str;
236 int i; 235 int i;
237 236
238 stream >> str; 237 stream >> str;
239 par.setService( str ); 238 par.setService( str );
240 239
241 stream >> i; 240 stream >> i;
242 par.setUid( i ); 241 par.setUid( i );
243 242
244 stream >> i ; 243 stream >> i ;
245 par.setField( i ); 244 par.setField( i );
246 245
247 return par; 246 return par;
248} 247}
249 248
250 249
251void OPimRecord::setLastHitField( int lastHit ) const 250void OPimRecord::setLastHitField( int lastHit ) const
252{ 251{
253 m_lastHit = lastHit; 252 m_lastHit = lastHit;
254} 253}
255 254
256 255
257int OPimRecord::lastHitField() const 256int OPimRecord::lastHitField() const
258{ 257{
259 return m_lastHit; 258 return m_lastHit;
260} 259}
261 260
262 261
263QMap<QString, QString> OPimRecord::toExtraMap() const 262QMap<QString, QString> OPimRecord::toExtraMap() const
264{ 263{
265 return customMap; 264 return customMap;
266} 265}
267 266
268 267
269void OPimRecord::setExtraMap( const QMap<QString, QString>& map ) 268void OPimRecord::setExtraMap( const QMap<QString, QString>& map )
270{ 269{
271 customMap = map; 270 customMap = map;
272} 271}
273 272
274} 273}
diff --git a/libopie2/opiepim/core/opimtodo.cpp b/libopie2/opiepim/core/opimtodo.cpp
index 34df807..f246bfd 100644
--- a/libopie2/opiepim/core/opimtodo.cpp
+++ b/libopie2/opiepim/core/opimtodo.cpp
@@ -1,712 +1,711 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) The Main Author <main-author@whereever.org> 3 Copyright (C) The Main Author <main-author@whereever.org>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 4 =. Copyright (C) The Opie Team <opie-devel@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 "opimtodo.h" 30#include "opimtodo.h"
31 31
32/* OPIE */ 32/* OPIE */
33#include <opie2/opimstate.h> 33#include <opie2/opimstate.h>
34#include <opie2/opimrecurrence.h> 34#include <opie2/opimrecurrence.h>
35#include <opie2/opimmaintainer.h> 35#include <opie2/opimmaintainer.h>
36#include <opie2/opimnotifymanager.h> 36#include <opie2/opimnotifymanager.h>
37#include <opie2/opimresolver.h> 37#include <opie2/opimresolver.h>
38#include <qpe/palmtopuidgen.h> 38#include <qpe/palmtopuidgen.h>
39#include <qpe/stringutil.h>
40#include <qpe/palmtoprecord.h> 39#include <qpe/palmtoprecord.h>
41#include <qpe/stringutil.h>
42#include <qpe/categories.h> 40#include <qpe/categories.h>
43#include <qpe/categoryselect.h> 41#include <qpe/categoryselect.h>
42#include <qpe/stringutil.h>
44 43
45/* QT */ 44/* QT */
46#include <qobject.h> 45#include <qobject.h>
47#include <qshared.h> 46#include <qshared.h>
48 47
49namespace Opie 48namespace Opie
50{ 49{
51 50
52struct OPimTodo::OPimTodoData : public QShared 51struct OPimTodo::OPimTodoData : public QShared
53{ 52{
54 OPimTodoData() : QShared() 53 OPimTodoData() : QShared()
55 { 54 {
56 recur = 0; 55 recur = 0;
57 state = 0; 56 state = 0;
58 maintainer = 0; 57 maintainer = 0;
59 notifiers = 0; 58 notifiers = 0;
60 }; 59 };
61 ~OPimTodoData() 60 ~OPimTodoData()
62 { 61 {
63 delete recur; 62 delete recur;
64 delete maintainer; 63 delete maintainer;
65 delete notifiers; 64 delete notifiers;
66 } 65 }
67 66
68 QDate date; 67 QDate date;
69 bool isCompleted: 1; 68 bool isCompleted: 1;
70 bool hasDate: 1; 69 bool hasDate: 1;
71 int priority; 70 int priority;
72 QString desc; 71 QString desc;
73 QString sum; 72 QString sum;
74 QMap<QString, QString> extra; 73 QMap<QString, QString> extra;
75 ushort prog; 74 ushort prog;
76 OPimState *state; 75 OPimState *state;
77 OPimRecurrence *recur; 76 OPimRecurrence *recur;
78 OPimMaintainer *maintainer; 77 OPimMaintainer *maintainer;
79 QDate start; 78 QDate start;
80 QDate completed; 79 QDate completed;
81 OPimNotifyManager *notifiers; 80 OPimNotifyManager *notifiers;
82}; 81};
83 82
84 83
85OPimTodo::OPimTodo( const OPimTodo &event ) 84OPimTodo::OPimTodo( const OPimTodo &event )
86 : OPimRecord( event ), data( event.data ) 85 : OPimRecord( event ), data( event.data )
87{ 86{
88 data->ref(); 87 data->ref();
89 // qWarning("ref up"); 88 // qWarning("ref up");
90} 89}
91 90
92 91
93OPimTodo::~OPimTodo() 92OPimTodo::~OPimTodo()
94{ 93{
95 94
96 // qWarning("~OPimTodo " ); 95 // qWarning("~OPimTodo " );
97 if ( data->deref() ) 96 if ( data->deref() )
98 { 97 {
99 // qWarning("OPimTodo::dereffing"); 98 // qWarning("OPimTodo::dereffing");
100 delete data; 99 delete data;
101 data = 0l; 100 data = 0l;
102 } 101 }
103} 102}
104 103
105 104
106OPimTodo::OPimTodo( bool completed, int priority, 105OPimTodo::OPimTodo( bool completed, int priority,
107 const QArray<int> &category, 106 const QArray<int> &category,
108 const QString& summary, 107 const QString& summary,
109 const QString &description, 108 const QString &description,
110 ushort progress, 109 ushort progress,
111 bool hasDate, QDate date, int uid ) 110 bool hasDate, QDate date, int uid )
112 : OPimRecord( uid ) 111 : OPimRecord( uid )
113{ 112{
114 // qWarning("OPimTodoData " + summary); 113 // qWarning("OPimTodoData " + summary);
115 setCategories( category ); 114 setCategories( category );
116 115
117 data = new OPimTodoData; 116 data = new OPimTodoData;
118 117
119 data->date = date; 118 data->date = date;
120 data->isCompleted = completed; 119 data->isCompleted = completed;
121 data->hasDate = hasDate; 120 data->hasDate = hasDate;
122 data->priority = priority; 121 data->priority = priority;
123 data->sum = summary; 122 data->sum = summary;
124 data->prog = progress; 123 data->prog = progress;
125 data->desc = Qtopia::simplifyMultiLineSpace( description ); 124 data->desc = Qtopia::simplifyMultiLineSpace( description );
126} 125}
127 126
128 127
129OPimTodo::OPimTodo( bool completed, int priority, 128OPimTodo::OPimTodo( bool completed, int priority,
130 const QStringList &category, 129 const QStringList &category,
131 const QString& summary, 130 const QString& summary,
132 const QString &description, 131 const QString &description,
133 ushort progress, 132 ushort progress,
134 bool hasDate, QDate date, int uid ) 133 bool hasDate, QDate date, int uid )
135 : OPimRecord( uid ) 134 : OPimRecord( uid )
136{ 135{
137 // qWarning("OPimTodoData" + summary); 136 // qWarning("OPimTodoData" + summary);
138 setCategories( idsFromString( category.join( ";" ) ) ); 137 setCategories( idsFromString( category.join( ";" ) ) );
139 138
140 data = new OPimTodoData; 139 data = new OPimTodoData;
141 140
142 data->date = date; 141 data->date = date;
143 data->isCompleted = completed; 142 data->isCompleted = completed;
144 data->hasDate = hasDate; 143 data->hasDate = hasDate;
145 data->priority = priority; 144 data->priority = priority;
146 data->sum = summary; 145 data->sum = summary;
147 data->prog = progress; 146 data->prog = progress;
148 data->desc = Qtopia::simplifyMultiLineSpace( description ); 147 data->desc = Qtopia::simplifyMultiLineSpace( description );
149} 148}
150 149
151 150
152bool OPimTodo::match( const QRegExp &regExp ) const 151bool OPimTodo::match( const QRegExp &regExp ) const
153{ 152{
154 if ( QString::number( data->priority ).find( regExp ) != -1 ) 153 if ( QString::number( data->priority ).find( regExp ) != -1 )
155 { 154 {
156 setLastHitField( Priority ); 155 setLastHitField( Priority );
157 return true; 156 return true;
158 } 157 }
159 else if ( data->hasDate && data->date.toString().find( regExp ) != -1 ) 158 else if ( data->hasDate && data->date.toString().find( regExp ) != -1 )
160 { 159 {
161 setLastHitField( HasDate ); 160 setLastHitField( HasDate );
162 return true; 161 return true;
163 } 162 }
164 else if ( data->desc.find( regExp ) != -1 ) 163 else if ( data->desc.find( regExp ) != -1 )
165 { 164 {
166 setLastHitField( Description ); 165 setLastHitField( Description );
167 return true; 166 return true;
168 } 167 }
169 else if ( data->sum.find( regExp ) != -1 ) 168 else if ( data->sum.find( regExp ) != -1 )
170 { 169 {
171 setLastHitField( Summary ); 170 setLastHitField( Summary );
172 return true; 171 return true;
173 } 172 }
174 return false; 173 return false;
175} 174}
176 175
177 176
178bool OPimTodo::isCompleted() const 177bool OPimTodo::isCompleted() const
179{ 178{
180 return data->isCompleted; 179 return data->isCompleted;
181} 180}
182 181
183 182
184bool OPimTodo::hasDueDate() const 183bool OPimTodo::hasDueDate() const
185{ 184{
186 return data->hasDate; 185 return data->hasDate;
187} 186}
188 187
189 188
190bool OPimTodo::hasStartDate() const 189bool OPimTodo::hasStartDate() const
191{ 190{
192 return data->start.isValid(); 191 return data->start.isValid();
193} 192}
194 193
195 194
196bool OPimTodo::hasCompletedDate() const 195bool OPimTodo::hasCompletedDate() const
197{ 196{
198 return data->completed.isValid(); 197 return data->completed.isValid();
199} 198}
200 199
201 200
202int OPimTodo::priority() const 201int OPimTodo::priority() const
203{ 202{
204 return data->priority; 203 return data->priority;
205} 204}
206 205
207 206
208QString OPimTodo::summary() const 207QString OPimTodo::summary() const
209{ 208{
210 return data->sum; 209 return data->sum;
211} 210}
212 211
213 212
214ushort OPimTodo::progress() const 213ushort OPimTodo::progress() const
215{ 214{
216 return data->prog; 215 return data->prog;
217} 216}
218 217
219 218
220QDate OPimTodo::dueDate() const 219QDate OPimTodo::dueDate() const
221{ 220{
222 return data->date; 221 return data->date;
223} 222}
224 223
225 224
226QDate OPimTodo::startDate() const 225QDate OPimTodo::startDate() const
227{ 226{
228 return data->start; 227 return data->start;
229} 228}
230 229
231 230
232QDate OPimTodo::completedDate() const 231QDate OPimTodo::completedDate() const
233{ 232{
234 return data->completed; 233 return data->completed;
235} 234}
236 235
237 236
238QString OPimTodo::description() const 237QString OPimTodo::description() const
239{ 238{
240 return data->desc; 239 return data->desc;
241} 240}
242 241
243 242
244bool OPimTodo::hasState() const 243bool OPimTodo::hasState() const
245{ 244{
246 if ( !data->state ) return false; 245 if ( !data->state ) return false;
247 return ( data->state->state() != OPimState::Undefined ); 246 return ( data->state->state() != OPimState::Undefined );
248} 247}
249 248
250 249
251OPimState OPimTodo::state() const 250OPimState OPimTodo::state() const
252{ 251{
253 if ( !data->state ) 252 if ( !data->state )
254 { 253 {
255 OPimState state; 254 OPimState state;
256 return state; 255 return state;
257 } 256 }
258 257
259 return ( *data->state ); 258 return ( *data->state );
260} 259}
261 260
262 261
263bool OPimTodo::hasRecurrence() const 262bool OPimTodo::hasRecurrence() const
264{ 263{
265 if ( !data->recur ) return false; 264 if ( !data->recur ) return false;
266 return data->recur->doesRecur(); 265 return data->recur->doesRecur();
267} 266}
268 267
269 268
270OPimRecurrence OPimTodo::recurrence() const 269OPimRecurrence OPimTodo::recurrence() const
271{ 270{
272 if ( !data->recur ) return OPimRecurrence(); 271 if ( !data->recur ) return OPimRecurrence();
273 272
274 return ( *data->recur ); 273 return ( *data->recur );
275} 274}
276 275
277 276
278bool OPimTodo::hasMaintainer() const 277bool OPimTodo::hasMaintainer() const
279{ 278{
280 if ( !data->maintainer ) return false; 279 if ( !data->maintainer ) return false;
281 280
282 return ( data->maintainer->mode() != OPimMaintainer::Undefined ); 281 return ( data->maintainer->mode() != OPimMaintainer::Undefined );
283} 282}
284 283
285 284
286OPimMaintainer OPimTodo::maintainer() const 285OPimMaintainer OPimTodo::maintainer() const
287{ 286{
288 if ( !data->maintainer ) return OPimMaintainer(); 287 if ( !data->maintainer ) return OPimMaintainer();
289 288
290 return ( *data->maintainer ); 289 return ( *data->maintainer );
291} 290}
292 291
293 292
294void OPimTodo::setCompleted( bool completed ) 293void OPimTodo::setCompleted( bool completed )
295{ 294{
296 changeOrModify(); 295 changeOrModify();
297 data->isCompleted = completed; 296 data->isCompleted = completed;
298} 297}
299 298
300 299
301void OPimTodo::setHasDueDate( bool hasDate ) 300void OPimTodo::setHasDueDate( bool hasDate )
302{ 301{
303 changeOrModify(); 302 changeOrModify();
304 data->hasDate = hasDate; 303 data->hasDate = hasDate;
305} 304}
306 305
307 306
308void OPimTodo::setDescription( const QString &desc ) 307void OPimTodo::setDescription( const QString &desc )
309{ 308{
310 // qWarning( "desc " + desc ); 309 // qWarning( "desc " + desc );
311 changeOrModify(); 310 changeOrModify();
312 data->desc = Qtopia::simplifyMultiLineSpace( desc ); 311 data->desc = Qtopia::simplifyMultiLineSpace( desc );
313} 312}
314 313
315 314
316void OPimTodo::setSummary( const QString& sum ) 315void OPimTodo::setSummary( const QString& sum )
317{ 316{
318 changeOrModify(); 317 changeOrModify();
319 data->sum = sum; 318 data->sum = sum;
320} 319}
321 320
322 321
323void OPimTodo::setPriority( int prio ) 322void OPimTodo::setPriority( int prio )
324{ 323{
325 changeOrModify(); 324 changeOrModify();
326 data->priority = prio; 325 data->priority = prio;
327} 326}
328 327
329 328
330void OPimTodo::setDueDate( const QDate& date ) 329void OPimTodo::setDueDate( const QDate& date )
331{ 330{
332 changeOrModify(); 331 changeOrModify();
333 data->date = date; 332 data->date = date;
334} 333}
335 334
336 335
337void OPimTodo::setStartDate( const QDate& date ) 336void OPimTodo::setStartDate( const QDate& date )
338{ 337{
339 changeOrModify(); 338 changeOrModify();
340 data->start = date; 339 data->start = date;
341} 340}
342 341
343 342
344void OPimTodo::setCompletedDate( const QDate& date ) 343void OPimTodo::setCompletedDate( const QDate& date )
345{ 344{
346 changeOrModify(); 345 changeOrModify();
347 data->completed = date; 346 data->completed = date;
348} 347}
349 348
350 349
351void OPimTodo::setState( const OPimState& state ) 350void OPimTodo::setState( const OPimState& state )
352{ 351{
353 changeOrModify(); 352 changeOrModify();
354 if ( data->state ) 353 if ( data->state )
355 ( *data->state ) = state; 354 ( *data->state ) = state;
356 else 355 else
357 data->state = new OPimState( state ); 356 data->state = new OPimState( state );
358} 357}
359 358
360 359
361void OPimTodo::setRecurrence( const OPimRecurrence& rec ) 360void OPimTodo::setRecurrence( const OPimRecurrence& rec )
362{ 361{
363 changeOrModify(); 362 changeOrModify();
364 if ( data->recur ) 363 if ( data->recur )
365 ( *data->recur ) = rec; 364 ( *data->recur ) = rec;
366 else 365 else
367 data->recur = new OPimRecurrence( rec ); 366 data->recur = new OPimRecurrence( rec );
368} 367}
369 368
370 369
371void OPimTodo::setMaintainer( const OPimMaintainer& pim ) 370void OPimTodo::setMaintainer( const OPimMaintainer& pim )
372{ 371{
373 changeOrModify(); 372 changeOrModify();
374 373
375 if ( data->maintainer ) 374 if ( data->maintainer )
376 ( *data->maintainer ) = pim; 375 ( *data->maintainer ) = pim;
377 else 376 else
378 data->maintainer = new OPimMaintainer( pim ); 377 data->maintainer = new OPimMaintainer( pim );
379} 378}
380 379
381 380
382bool OPimTodo::isOverdue( ) 381bool OPimTodo::isOverdue( )
383{ 382{
384 if ( data->hasDate && !data->isCompleted ) 383 if ( data->hasDate && !data->isCompleted )
385 return QDate::currentDate() > data->date; 384 return QDate::currentDate() > data->date;
386 return false; 385 return false;
387} 386}
388 387
389 388
390void OPimTodo::setProgress( ushort progress ) 389void OPimTodo::setProgress( ushort progress )
391{ 390{
392 changeOrModify(); 391 changeOrModify();
393 data->prog = progress; 392 data->prog = progress;
394} 393}
395 394
396 395
397QString OPimTodo::toShortText() const 396QString OPimTodo::toShortText() const
398{ 397{
399 return summary(); 398 return summary();
400} 399}
401 400
402 401
403/*! 402/*!
404 Returns a richt text string 403 Returns a richt text string
405*/ 404*/
406QString OPimTodo::toRichText() const 405QString OPimTodo::toRichText() const
407{ 406{
408 QString text; 407 QString text;
409 QStringList catlist; 408 QStringList catlist;
410 409
411 // summary 410 // summary
412 text += "<b><h3><img src=\"todo/TodoList\"> "; 411 text += "<b><h3><img src=\"todo/TodoList\"> ";
413 if ( !summary().isEmpty() ) 412 if ( !summary().isEmpty() )
414 { 413 {
415 text += Qtopia::escapeString( summary() ).replace( QRegExp( "[\n]" ), "" ); 414 text += Qtopia::escapeString( summary() ).replace( QRegExp( "[\n]" ), "" );
416 } 415 }
417 text += "</h3></b><br><hr><br>"; 416 text += "</h3></b><br><hr><br>";
418 417
419 // description 418 // description
420 if ( !description().isEmpty() ) 419 if ( !description().isEmpty() )
421 { 420 {
422 text += "<b>" + QObject::tr( "Description:" ) + "</b><br>"; 421 text += "<b>" + QObject::tr( "Description:" ) + "</b><br>";
423 text += Qtopia::escapeString( description() ).replace( QRegExp( "[\n]" ), "<br>" ) + "<br>"; 422 text += Qtopia::escapeString( description() ).replace( QRegExp( "[\n]" ), "<br>" ) + "<br>";
424 } 423 }
425 424
426 // priority 425 // priority
427 int priorityval = priority(); 426 int priorityval = priority();
428 text += "<b>" + QObject::tr( "Priority:" ) + " </b><img src=\"todo/priority" + 427 text += "<b>" + QObject::tr( "Priority:" ) + " </b><img src=\"todo/priority" +
429 QString::number( priorityval ) + "\"> "; 428 QString::number( priorityval ) + "\"> ";
430 429
431 switch ( priorityval ) 430 switch ( priorityval )
432 { 431 {
433 case 1 : text += QObject::tr( "Very high" ); 432 case 1 : text += QObject::tr( "Very high" );
434 break; 433 break;
435 case 2 : text += QObject::tr( "High" ); 434 case 2 : text += QObject::tr( "High" );
436 break; 435 break;
437 case 3 : text += QObject::tr( "Normal" ); 436 case 3 : text += QObject::tr( "Normal" );
438 break; 437 break;
439 case 4 : text += QObject::tr( "Low" ); 438 case 4 : text += QObject::tr( "Low" );
440 break; 439 break;
441 case 5 : text += QObject::tr( "Very low" ); 440 case 5 : text += QObject::tr( "Very low" );
442 break; 441 break;
443 }; 442 };
444 text += "<br>"; 443 text += "<br>";
445 444
446 // progress 445 // progress
447 text += "<b>" + QObject::tr( "Progress:" ) + " </b>" 446 text += "<b>" + QObject::tr( "Progress:" ) + " </b>"
448 + QString::number( progress() ) + " %<br>"; 447 + QString::number( progress() ) + " %<br>";
449 448
450 // due date 449 // due date
451 if ( hasDueDate() ) 450 if ( hasDueDate() )
452 { 451 {
453 QDate dd = dueDate(); 452 QDate dd = dueDate();
454 int off = QDate::currentDate().daysTo( dd ); 453 int off = QDate::currentDate().daysTo( dd );
455 454
456 text += "<b>" + QObject::tr( "Deadline:" ) + " </b><font color=\""; 455 text += "<b>" + QObject::tr( "Deadline:" ) + " </b><font color=\"";
457 if ( off < 0 ) 456 if ( off < 0 )
458 text += "#FF0000"; 457 text += "#FF0000";
459 else if ( off == 0 ) 458 else if ( off == 0 )
460 text += "#FFFF00"; 459 text += "#FFFF00";
461 else if ( off > 0 ) 460 else if ( off > 0 )
462 text += "#00FF00"; 461 text += "#00FF00";
463 462
464 text += "\">" + dd.toString() + "</font><br>"; 463 text += "\">" + dd.toString() + "</font><br>";
465 } 464 }
466 465
467 // categories 466 // categories
468 text += "<b>" + QObject::tr( "Category:" ) + "</b> "; 467 text += "<b>" + QObject::tr( "Category:" ) + "</b> ";
469 text += categoryNames( "Todo List" ).join( ", " ); 468 text += categoryNames( "Todo List" ).join( ", " );
470 text += "<br>"; 469 text += "<br>";
471 470
472 return text; 471 return text;
473} 472}
474 473
475 474
476bool OPimTodo::hasNotifiers() const 475bool OPimTodo::hasNotifiers() const
477{ 476{
478 if ( !data->notifiers ) return false; 477 if ( !data->notifiers ) return false;
479 return !data->notifiers->isEmpty(); 478 return !data->notifiers->isEmpty();
480} 479}
481 480
482 481
483OPimNotifyManager& OPimTodo::notifiers() 482OPimNotifyManager& OPimTodo::notifiers()
484{ 483{
485 if ( !data->notifiers ) 484 if ( !data->notifiers )
486 data->notifiers = new OPimNotifyManager; 485 data->notifiers = new OPimNotifyManager;
487 return ( *data->notifiers ); 486 return ( *data->notifiers );
488} 487}
489 488
490 489
491const OPimNotifyManager& OPimTodo::notifiers() const 490const OPimNotifyManager& OPimTodo::notifiers() const
492{ 491{
493 if ( !data->notifiers ) 492 if ( !data->notifiers )
494 data->notifiers = new OPimNotifyManager; 493 data->notifiers = new OPimNotifyManager;
495 494
496 return ( *data->notifiers ); 495 return ( *data->notifiers );
497} 496}
498 497
499 498
500bool OPimTodo::operator<( const OPimTodo &toDoEvent ) const 499bool OPimTodo::operator<( const OPimTodo &toDoEvent ) const
501{ 500{
502 if ( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; 501 if ( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
503 if ( !hasDueDate() && toDoEvent.hasDueDate() ) return false; 502 if ( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
504 if ( hasDueDate() && toDoEvent.hasDueDate() ) 503 if ( hasDueDate() && toDoEvent.hasDueDate() )
505 { 504 {
506 if ( dueDate() == toDoEvent.dueDate() ) 505 if ( dueDate() == toDoEvent.dueDate() )
507 { // let's the priority decide 506 { // let's the priority decide
508 return priority() < toDoEvent.priority(); 507 return priority() < toDoEvent.priority();
509 } 508 }
510 else 509 else
511 { 510 {
512 return dueDate() < toDoEvent.dueDate(); 511 return dueDate() < toDoEvent.dueDate();
513 } 512 }
514 } 513 }
515 return false; 514 return false;
516} 515}
517 516
518 517
519bool OPimTodo::operator<=( const OPimTodo &toDoEvent ) const 518bool OPimTodo::operator<=( const OPimTodo &toDoEvent ) const
520{ 519{
521 if ( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; 520 if ( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
522 if ( !hasDueDate() && toDoEvent.hasDueDate() ) return true; 521 if ( !hasDueDate() && toDoEvent.hasDueDate() ) return true;
523 if ( hasDueDate() && toDoEvent.hasDueDate() ) 522 if ( hasDueDate() && toDoEvent.hasDueDate() )
524 { 523 {
525 if ( dueDate() == toDoEvent.dueDate() ) 524 if ( dueDate() == toDoEvent.dueDate() )
526 { // let's the priority decide 525 { // let's the priority decide
527 return priority() <= toDoEvent.priority(); 526 return priority() <= toDoEvent.priority();
528 } 527 }
529 else 528 else
530 { 529 {
531 return dueDate() <= toDoEvent.dueDate(); 530 return dueDate() <= toDoEvent.dueDate();
532 } 531 }
533 } 532 }
534 return true; 533 return true;
535} 534}
536 535
537 536
538bool OPimTodo::operator>( const OPimTodo &toDoEvent ) const 537bool OPimTodo::operator>( const OPimTodo &toDoEvent ) const
539{ 538{
540 if ( !hasDueDate() && !toDoEvent.hasDueDate() ) return false; 539 if ( !hasDueDate() && !toDoEvent.hasDueDate() ) return false;
541 if ( !hasDueDate() && toDoEvent.hasDueDate() ) return false; 540 if ( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
542 if ( hasDueDate() && toDoEvent.hasDueDate() ) 541 if ( hasDueDate() && toDoEvent.hasDueDate() )
543 { 542 {
544 if ( dueDate() == toDoEvent.dueDate() ) 543 if ( dueDate() == toDoEvent.dueDate() )
545 { // let's the priority decide 544 { // let's the priority decide
546 return priority() > toDoEvent.priority(); 545 return priority() > toDoEvent.priority();
547 } 546 }
548 else 547 else
549 { 548 {
550 return dueDate() > toDoEvent.dueDate(); 549 return dueDate() > toDoEvent.dueDate();
551 } 550 }
552 } 551 }
553 return false; 552 return false;
554} 553}
555 554
556 555
557bool OPimTodo::operator>=( const OPimTodo &toDoEvent ) const 556bool OPimTodo::operator>=( const OPimTodo &toDoEvent ) const
558{ 557{
559 if ( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; 558 if ( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
560 if ( !hasDueDate() && toDoEvent.hasDueDate() ) return false; 559 if ( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
561 if ( hasDueDate() && toDoEvent.hasDueDate() ) 560 if ( hasDueDate() && toDoEvent.hasDueDate() )
562 { 561 {
563 if ( dueDate() == toDoEvent.dueDate() ) 562 if ( dueDate() == toDoEvent.dueDate() )
564 { // let's the priority decide 563 { // let's the priority decide
565 return priority() > toDoEvent.priority(); 564 return priority() > toDoEvent.priority();
566 } 565 }
567 else 566 else
568 { 567 {
569 return dueDate() > toDoEvent.dueDate(); 568 return dueDate() > toDoEvent.dueDate();
570 } 569 }
571 } 570 }
572 return true; 571 return true;
573} 572}
574 573
575 574
576bool OPimTodo::operator==( const OPimTodo &toDoEvent ) const 575bool OPimTodo::operator==( const OPimTodo &toDoEvent ) const
577{ 576{
578 if ( data->priority != toDoEvent.data->priority ) return false; 577 if ( data->priority != toDoEvent.data->priority ) return false;
579 if ( data->priority != toDoEvent.data->prog ) return false; 578 if ( data->priority != toDoEvent.data->prog ) return false;
580 if ( data->isCompleted != toDoEvent.data->isCompleted ) return false; 579 if ( data->isCompleted != toDoEvent.data->isCompleted ) return false;
581 if ( data->hasDate != toDoEvent.data->hasDate ) return false; 580 if ( data->hasDate != toDoEvent.data->hasDate ) return false;
582 if ( data->date != toDoEvent.data->date ) return false; 581 if ( data->date != toDoEvent.data->date ) return false;
583 if ( data->sum != toDoEvent.data->sum ) return false; 582 if ( data->sum != toDoEvent.data->sum ) return false;
584 if ( data->desc != toDoEvent.data->desc ) return false; 583 if ( data->desc != toDoEvent.data->desc ) return false;
585 if ( data->maintainer != toDoEvent.data->maintainer ) 584 if ( data->maintainer != toDoEvent.data->maintainer )
586 return false; 585 return false;
587 586
588 return OPimRecord::operator==( toDoEvent ); 587 return OPimRecord::operator==( toDoEvent );
589} 588}
590 589
591 590
592void OPimTodo::deref() 591void OPimTodo::deref()
593{ 592{
594 593
595 // qWarning("deref in ToDoEvent"); 594 // qWarning("deref in ToDoEvent");
596 if ( data->deref() ) 595 if ( data->deref() )
597 { 596 {
598 // qWarning("deleting"); 597 // qWarning("deleting");
599 delete data; 598 delete data;
600 data = 0; 599 data = 0;
601 } 600 }
602} 601}
603 602
604 603
605OPimTodo &OPimTodo::operator=( const OPimTodo &item ) 604OPimTodo &OPimTodo::operator=( const OPimTodo &item )
606{ 605{
607 if ( this == &item ) return * this; 606 if ( this == &item ) return * this;
608 607
609 OPimRecord::operator=( item ); 608 OPimRecord::operator=( item );
610 //qWarning("operator= ref "); 609 //qWarning("operator= ref ");
611 item.data->ref(); 610 item.data->ref();
612 deref(); 611 deref();
613 data = item.data; 612 data = item.data;
614 613
615 return *this; 614 return *this;
616} 615}
617 616
618 617
619QMap<int, QString> OPimTodo::toMap() const 618QMap<int, QString> OPimTodo::toMap() const
620{ 619{
621 QMap<int, QString> map; 620 QMap<int, QString> map;
622 621
623 map.insert( Uid, QString::number( uid() ) ); 622 map.insert( Uid, QString::number( uid() ) );
624 map.insert( Category, idsToString( categories() ) ); 623 map.insert( Category, idsToString( categories() ) );
625 map.insert( HasDate, QString::number( data->hasDate ) ); 624 map.insert( HasDate, QString::number( data->hasDate ) );
626 map.insert( Completed, QString::number( data->isCompleted ) ); 625 map.insert( Completed, QString::number( data->isCompleted ) );
627 map.insert( Description, data->desc ); 626 map.insert( Description, data->desc );
628 map.insert( Summary, data->sum ); 627 map.insert( Summary, data->sum );
629 map.insert( Priority, QString::number( data->priority ) ); 628 map.insert( Priority, QString::number( data->priority ) );
630 map.insert( DateDay, QString::number( data->date.day() ) ); 629 map.insert( DateDay, QString::number( data->date.day() ) );
631 map.insert( DateMonth, QString::number( data->date.month() ) ); 630 map.insert( DateMonth, QString::number( data->date.month() ) );
632 map.insert( DateYear, QString::number( data->date.year() ) ); 631 map.insert( DateYear, QString::number( data->date.year() ) );
633 map.insert( Progress, QString::number( data->prog ) ); 632 map.insert( Progress, QString::number( data->prog ) );
634 // map.insert( CrossReference, crossToString() ); 633 // map.insert( CrossReference, crossToString() );
635 /* FIXME!!! map.insert( State, ); 634 /* FIXME!!! map.insert( State, );
636 map.insert( Recurrence, ); 635 map.insert( Recurrence, );
637 map.insert( Reminders, ); 636 map.insert( Reminders, );
638 map. 637 map.
639 */ 638 */
640 return map; 639 return map;
641} 640}
642 641
643 642
644/** 643/**
645 * change or modify looks at the ref count and either 644 * change or modify looks at the ref count and either
646 * creates a new QShared Object or it can modify it 645 * creates a new QShared Object or it can modify it
647 * right in place 646 * right in place
648 */ 647 */
649void OPimTodo::changeOrModify() 648void OPimTodo::changeOrModify()
650{ 649{
651 if ( data->count != 1 ) 650 if ( data->count != 1 )
652 { 651 {
653 qWarning( "changeOrModify" ); 652 qWarning( "changeOrModify" );
654 data->deref(); 653 data->deref();
655 OPimTodoData* d2 = new OPimTodoData(); 654 OPimTodoData* d2 = new OPimTodoData();
656 copy( data, d2 ); 655 copy( data, d2 );
657 data = d2; 656 data = d2;
658 } 657 }
659} 658}
660 659
661 660
662// WATCHOUT 661// WATCHOUT
663/* 662/*
664 * if you add something to the Data struct 663 * if you add something to the Data struct
665 * be sure to copy it here 664 * be sure to copy it here
666 */ 665 */
667void OPimTodo::copy( OPimTodoData* src, OPimTodoData* dest ) 666void OPimTodo::copy( OPimTodoData* src, OPimTodoData* dest )
668{ 667{
669 dest->date = src->date; 668 dest->date = src->date;
670 dest->isCompleted = src->isCompleted; 669 dest->isCompleted = src->isCompleted;
671 dest->hasDate = src->hasDate; 670 dest->hasDate = src->hasDate;
672 dest->priority = src->priority; 671 dest->priority = src->priority;
673 dest->desc = src->desc; 672 dest->desc = src->desc;
674 dest->sum = src->sum; 673 dest->sum = src->sum;
675 dest->extra = src->extra; 674 dest->extra = src->extra;
676 dest->prog = src->prog; 675 dest->prog = src->prog;
677 676
678 if ( src->state ) 677 if ( src->state )
679 dest->state = new OPimState( *src->state ); 678 dest->state = new OPimState( *src->state );
680 679
681 if ( src->recur ) 680 if ( src->recur )
682 dest->recur = new OPimRecurrence( *src->recur ); 681 dest->recur = new OPimRecurrence( *src->recur );
683 682
684 if ( src->maintainer ) 683 if ( src->maintainer )
685 dest->maintainer = new OPimMaintainer( *src->maintainer ) 684 dest->maintainer = new OPimMaintainer( *src->maintainer )
686 ; 685 ;
687 dest->start = src->start; 686 dest->start = src->start;
688 dest->completed = src->completed; 687 dest->completed = src->completed;
689 688
690 if ( src->notifiers ) 689 if ( src->notifiers )
691 dest->notifiers = new OPimNotifyManager( *src->notifiers ); 690 dest->notifiers = new OPimNotifyManager( *src->notifiers );
692} 691}
693 692
694 693
695QString OPimTodo::type() const 694QString OPimTodo::type() const
696{ 695{
697 return QString::fromLatin1( "OPimTodo" ); 696 return QString::fromLatin1( "OPimTodo" );
698} 697}
699 698
700 699
701QString OPimTodo::recordField( int /*id*/ ) const 700QString OPimTodo::recordField( int /*id*/ ) const
702{ 701{
703 return QString::null; 702 return QString::null;
704} 703}
705 704
706 705
707int OPimTodo::rtti() 706int OPimTodo::rtti()
708{ 707{
709 return OPimResolver::TodoList; 708 return OPimResolver::TodoList;
710} 709}
711 710
712} 711}
diff --git a/libopie2/opieui/ofontselector.cpp b/libopie2/opieui/ofontselector.cpp
index 49628c9..49ddeb6 100644
--- a/libopie2/opieui/ofontselector.cpp
+++ b/libopie2/opieui/ofontselector.cpp
@@ -1,429 +1,428 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) Robert Griebl <sandman@handhelds.org> 3 Copyright (C) Robert Griebl <sandman@handhelds.org>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 4 =. Copyright (C) The Opie Team <opie-devel@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/* OPIE */ 30/* OPIE */
31#include <opie2/ofontselector.h> 31#include <opie2/ofontselector.h>
32#include <qpe/fontdatabase.h> 32#include <qpe/fontdatabase.h>
33 33
34/* QT */ 34/* QT */
35#include <qlayout.h> 35#include <qlayout.h>
36#include <qlistbox.h> 36#include <qlistbox.h>
37#include <qcombobox.h> 37#include <qcombobox.h>
38#include <qlabel.h> 38#include <qlabel.h>
39#include <qfont.h>
40#include <qmultilineedit.h> 39#include <qmultilineedit.h>
41 40
42using namespace Opie; 41using namespace Opie;
43 42
44namespace Opie 43namespace Opie
45{ 44{
46 45
47class OFontSelectorPrivate 46class OFontSelectorPrivate
48{ 47{
49public: 48public:
50 QListBox * m_font_family_list; 49 QListBox * m_font_family_list;
51 QComboBox * m_font_style_list; 50 QComboBox * m_font_style_list;
52 QComboBox * m_font_size_list; 51 QComboBox * m_font_size_list;
53 QMultiLineEdit *m_preview; 52 QMultiLineEdit *m_preview;
54 53
55 bool m_pointbug : 1; 54 bool m_pointbug : 1;
56 55
57 FontDatabase m_fdb; 56 FontDatabase m_fdb;
58}; 57};
59 58
60}; 59};
61 60
62namespace 61namespace
63{ 62{
64 63
65class FontListItem : public QListBoxText 64class FontListItem : public QListBoxText
66{ 65{
67public: 66public:
68 FontListItem ( const QString &t, const QStringList &styles, const QValueList<int> &sizes ) : QListBoxText() 67 FontListItem ( const QString &t, const QStringList &styles, const QValueList<int> &sizes ) : QListBoxText()
69 { 68 {
70 m_name = t; 69 m_name = t;
71 m_styles = styles; 70 m_styles = styles;
72 m_sizes = sizes; 71 m_sizes = sizes;
73 72
74 QString str = t; 73 QString str = t;
75 str [0] = str [0]. upper(); 74 str [0] = str [0]. upper();
76 setText ( str ); 75 setText ( str );
77 } 76 }
78 77
79 QString family() const 78 QString family() const
80 { 79 {
81 return m_name; 80 return m_name;
82 } 81 }
83 82
84 const QStringList &styles() const 83 const QStringList &styles() const
85 { 84 {
86 return m_styles; 85 return m_styles;
87 } 86 }
88 87
89 const QValueList<int> &sizes() const 88 const QValueList<int> &sizes() const
90 { 89 {
91 return m_sizes; 90 return m_sizes;
92 } 91 }
93 92
94private: 93private:
95 QStringList m_styles; 94 QStringList m_styles;
96 QValueList<int> m_sizes; 95 QValueList<int> m_sizes;
97 QString m_name; 96 QString m_name;
98}; 97};
99 98
100 99
101static int findItemCB( QComboBox *box, const QString &str ) 100static int findItemCB( QComboBox *box, const QString &str )
102{ 101{
103 for ( int i = 0; i < box->count(); i++ ) 102 for ( int i = 0; i < box->count(); i++ )
104 { 103 {
105 if ( box->text ( i ) == str ) 104 if ( box->text ( i ) == str )
106 return i; 105 return i;
107 } 106 }
108 return -1; 107 return -1;
109} 108}
110 109
111} 110}
112/* static same as anon. namespace */ 111/* static same as anon. namespace */
113static int qt_version() 112static int qt_version()
114{ 113{
115 const char *qver = qVersion(); 114 const char *qver = qVersion();
116 115
117 return ( qver [0] - '0' ) * 100 + ( qver [2] - '0' ) * 10 + ( qver [4] - '0' ); 116 return ( qver [0] - '0' ) * 100 + ( qver [2] - '0' ) * 10 + ( qver [4] - '0' );
118} 117}
119 118
120/** 119/**
121 * Constructs the Selector object 120 * Constructs the Selector object
122 * @param withpreview If a font preview should be given 121 * @param withpreview If a font preview should be given
123 * @param parent The parent of the Font Selector 122 * @param parent The parent of the Font Selector
124 * @param name The name of the object 123 * @param name The name of the object
125 * @param fl WidgetFlags 124 * @param fl WidgetFlags
126 */ 125 */
127OFontSelector::OFontSelector( bool withpreview, QWidget *parent, const char *name, WFlags fl ) : QWidget ( parent, name, fl ) 126OFontSelector::OFontSelector( bool withpreview, QWidget *parent, const char *name, WFlags fl ) : QWidget ( parent, name, fl )
128{ 127{
129 d = new OFontSelectorPrivate(); 128 d = new OFontSelectorPrivate();
130 129
131 QGridLayout *gridLayout = new QGridLayout( this, 0, 0, 4, 4 ); 130 QGridLayout *gridLayout = new QGridLayout( this, 0, 0, 4, 4 );
132 gridLayout->setRowStretch( 4, 10 ); 131 gridLayout->setRowStretch( 4, 10 );
133 132
134 d->m_font_family_list = new QListBox( this, "FontListBox" ); 133 d->m_font_family_list = new QListBox( this, "FontListBox" );
135 gridLayout->addMultiCellWidget( d->m_font_family_list, 0, 4, 0, 0 ); 134 gridLayout->addMultiCellWidget( d->m_font_family_list, 0, 4, 0, 0 );
136 connect( d->m_font_family_list, SIGNAL( highlighted( int ) ), this, SLOT( fontFamilyClicked( int ) ) ); 135 connect( d->m_font_family_list, SIGNAL( highlighted( int ) ), this, SLOT( fontFamilyClicked( int ) ) );
137 136
138 QLabel *label = new QLabel( tr( "Style" ), this ); 137 QLabel *label = new QLabel( tr( "Style" ), this );
139 gridLayout->addWidget( label, 0, 1 ); 138 gridLayout->addWidget( label, 0, 1 );
140 139
141 d->m_font_style_list = new QComboBox( this, "StyleListBox" ); 140 d->m_font_style_list = new QComboBox( this, "StyleListBox" );
142 connect( d->m_font_style_list, SIGNAL( activated( int ) ), this, SLOT( fontStyleClicked( int ) ) ); 141 connect( d->m_font_style_list, SIGNAL( activated( int ) ), this, SLOT( fontStyleClicked( int ) ) );
143 gridLayout->addWidget( d->m_font_style_list, 1, 1 ); 142 gridLayout->addWidget( d->m_font_style_list, 1, 1 );
144 143
145 label = new QLabel( tr( "Size" ), this ); 144 label = new QLabel( tr( "Size" ), this );
146 gridLayout->addWidget( label, 2, 1 ); 145 gridLayout->addWidget( label, 2, 1 );
147 146
148 d->m_font_size_list = new QComboBox( this, "SizeListBox" ); 147 d->m_font_size_list = new QComboBox( this, "SizeListBox" );
149 connect( d->m_font_size_list, SIGNAL( activated( int ) ), 148 connect( d->m_font_size_list, SIGNAL( activated( int ) ),
150 this, SLOT( fontSizeClicked( int ) ) ); 149 this, SLOT( fontSizeClicked( int ) ) );
151 gridLayout->addWidget( d->m_font_size_list, 3, 1 ); 150 gridLayout->addWidget( d->m_font_size_list, 3, 1 );
152 151
153 d->m_pointbug = ( qt_version() <= 233 ); 152 d->m_pointbug = ( qt_version() <= 233 );
154 153
155 if ( withpreview ) 154 if ( withpreview )
156 { 155 {
157 d->m_preview = new QMultiLineEdit ( this, "Preview" ); 156 d->m_preview = new QMultiLineEdit ( this, "Preview" );
158 d->m_preview->setAlignment ( AlignCenter ); 157 d->m_preview->setAlignment ( AlignCenter );
159 d->m_preview->setWordWrap ( QMultiLineEdit::WidgetWidth ); 158 d->m_preview->setWordWrap ( QMultiLineEdit::WidgetWidth );
160 d->m_preview->setMargin ( 3 ); 159 d->m_preview->setMargin ( 3 );
161 d->m_preview->setText ( tr( "The Quick Brown Fox Jumps Over The Lazy Dog" )); 160 d->m_preview->setText ( tr( "The Quick Brown Fox Jumps Over The Lazy Dog" ));
162 gridLayout->addRowSpacing ( 5, 4 ); 161 gridLayout->addRowSpacing ( 5, 4 );
163 gridLayout->addMultiCellWidget ( d->m_preview, 6, 6, 0, 1 ); 162 gridLayout->addMultiCellWidget ( d->m_preview, 6, 6, 0, 1 );
164 gridLayout->setRowStretch ( 6, 5 ); 163 gridLayout->setRowStretch ( 6, 5 );
165 } 164 }
166 else 165 else
167 d->m_preview = 0; 166 d->m_preview = 0;
168 167
169 loadFonts ( d->m_font_family_list ); 168 loadFonts ( d->m_font_family_list );
170} 169}
171 170
172OFontSelector::~OFontSelector() 171OFontSelector::~OFontSelector()
173{ 172{
174 delete d; 173 delete d;
175} 174}
176 175
177/** 176/**
178 * This methods tries to set the font 177 * This methods tries to set the font
179 * @param f The wishes font 178 * @param f The wishes font
180 * @return success or failure 179 * @return success or failure
181 */ 180 */
182bool OFontSelector::setSelectedFont ( const QFont &f ) 181bool OFontSelector::setSelectedFont ( const QFont &f )
183{ 182{
184 return setSelectedFont ( f. family(), d->m_fdb. styleString ( f ), f. pointSize(), QFont::encodingName ( f. charSet())); 183 return setSelectedFont ( f. family(), d->m_fdb. styleString ( f ), f. pointSize(), QFont::encodingName ( f. charSet()));
185} 184}
186 185
187 186
188/** 187/**
189 * This is an overloaded method @see setSelectedFont 188 * This is an overloaded method @see setSelectedFont
190 * @param familyStr The family of the font 189 * @param familyStr The family of the font
191 * @param styleStr The style of the font 190 * @param styleStr The style of the font
192 * @param sizeVal The size of font 191 * @param sizeVal The size of font
193 * @param charset The charset to be used. Will be deprecated by QT3 192 * @param charset The charset to be used. Will be deprecated by QT3
194 */ 193 */
195bool OFontSelector::setSelectedFont( const QString &familyStr, const QString &styleStr, int sizeVal, const QString & charset ) 194bool OFontSelector::setSelectedFont( const QString &familyStr, const QString &styleStr, int sizeVal, const QString & charset )
196{ 195{
197 QString sizeStr = QString::number ( sizeVal ); 196 QString sizeStr = QString::number ( sizeVal );
198 197
199 QListBoxItem *family = d->m_font_family_list->findItem ( familyStr ); 198 QListBoxItem *family = d->m_font_family_list->findItem ( familyStr );
200 if ( !family ) 199 if ( !family )
201 family = d->m_font_family_list->findItem ( "Helvetica" ); 200 family = d->m_font_family_list->findItem ( "Helvetica" );
202 if ( !family ) 201 if ( !family )
203 family = d->m_font_family_list->firstItem(); 202 family = d->m_font_family_list->firstItem();
204 d->m_font_family_list->setCurrentItem ( family ); 203 d->m_font_family_list->setCurrentItem ( family );
205 fontFamilyClicked ( d->m_font_family_list->index ( family )); 204 fontFamilyClicked ( d->m_font_family_list->index ( family ));
206 205
207 int style = findItemCB ( d->m_font_style_list, styleStr ); 206 int style = findItemCB ( d->m_font_style_list, styleStr );
208 if ( style < 0 ) 207 if ( style < 0 )
209 style = findItemCB ( d->m_font_style_list, "Regular" ); 208 style = findItemCB ( d->m_font_style_list, "Regular" );
210 if ( style < 0 && d->m_font_style_list->count() > 0 ) 209 if ( style < 0 && d->m_font_style_list->count() > 0 )
211 style = 0; 210 style = 0;
212 d->m_font_style_list->setCurrentItem ( style ); 211 d->m_font_style_list->setCurrentItem ( style );
213 fontStyleClicked ( style ); 212 fontStyleClicked ( style );
214 213
215 int size = findItemCB ( d->m_font_size_list, sizeStr ); 214 int size = findItemCB ( d->m_font_size_list, sizeStr );
216 if ( size < 0 ) 215 if ( size < 0 )
217 size = findItemCB ( d->m_font_size_list, "10" ); 216 size = findItemCB ( d->m_font_size_list, "10" );
218 if ( size < 0 && d->m_font_size_list->count() > 0 ) 217 if ( size < 0 && d->m_font_size_list->count() > 0 )
219 size = 0; 218 size = 0;
220 d->m_font_size_list->setCurrentItem ( size ); 219 d->m_font_size_list->setCurrentItem ( size );
221 fontSizeClicked ( size ); 220 fontSizeClicked ( size );
222 221
223 return (( family ) && ( style >= 0 ) && ( size >= 0 )); 222 return (( family ) && ( style >= 0 ) && ( size >= 0 ));
224} 223}
225 224
226/** 225/**
227 * This method returns the name, style and size of the currently selected 226 * This method returns the name, style and size of the currently selected
228 * font or false if no font is selected 227 * font or false if no font is selected
229 * @param family The font family will be written there 228 * @param family The font family will be written there
230 * @param style The style will be written there 229 * @param style The style will be written there
231 * @param size The size will be written there 230 * @param size The size will be written there
232 * @return success or failure 231 * @return success or failure
233 */ 232 */
234bool OFontSelector::selectedFont ( QString &family, QString &style, int &size ) 233bool OFontSelector::selectedFont ( QString &family, QString &style, int &size )
235{ 234{
236 QString dummy; 235 QString dummy;
237 return selectedFont ( family, style, size, dummy ); 236 return selectedFont ( family, style, size, dummy );
238} 237}
239 238
240 239
241/** 240/**
242 * This method does return the font family or QString::null if there is 241 * This method does return the font family or QString::null if there is
243 * no font item selected 242 * no font item selected
244 * @return the font family 243 * @return the font family
245 */ 244 */
246QString OFontSelector::fontFamily() const 245QString OFontSelector::fontFamily() const
247{ 246{
248 FontListItem *fli = (FontListItem *) d->m_font_family_list->item ( d->m_font_family_list->currentItem()); 247 FontListItem *fli = (FontListItem *) d->m_font_family_list->item ( d->m_font_family_list->currentItem());
249 248
250 return fli ? fli->family() : QString::null; 249 return fli ? fli->family() : QString::null;
251} 250}
252 251
253/** 252/**
254 * This method will return the style of the font or QString::null 253 * This method will return the style of the font or QString::null
255 * @return the style of the font 254 * @return the style of the font
256 */ 255 */
257QString OFontSelector::fontStyle() const 256QString OFontSelector::fontStyle() const
258{ 257{
259 FontListItem *fli = (FontListItem *) d->m_font_family_list->item ( d->m_font_family_list->currentItem()); 258 FontListItem *fli = (FontListItem *) d->m_font_family_list->item ( d->m_font_family_list->currentItem());
260 int fst = d->m_font_style_list->currentItem(); 259 int fst = d->m_font_style_list->currentItem();
261 260
262 return ( fli && fst >= 0 ) ? fli->styles() [fst] : QString::null; 261 return ( fli && fst >= 0 ) ? fli->styles() [fst] : QString::null;
263} 262}
264 263
265/** 264/**
266 * This method will return the font size or 10 if no font size is available 265 * This method will return the font size or 10 if no font size is available
267 */ 266 */
268int OFontSelector::fontSize() const 267int OFontSelector::fontSize() const
269{ 268{
270 FontListItem *fli = (FontListItem *) d->m_font_family_list->item ( d->m_font_family_list->currentItem()); 269 FontListItem *fli = (FontListItem *) d->m_font_family_list->item ( d->m_font_family_list->currentItem());
271 int fsi = d->m_font_size_list->currentItem(); 270 int fsi = d->m_font_size_list->currentItem();
272 271
273 return ( fli && fsi >= 0 ) ? fli->sizes() [fsi] : 10; 272 return ( fli && fsi >= 0 ) ? fli->sizes() [fsi] : 10;
274} 273}
275 274
276/** 275/**
277 * returns the charset of the font or QString::null 276 * returns the charset of the font or QString::null
278 */ 277 */
279QString OFontSelector::fontCharSet() const 278QString OFontSelector::fontCharSet() const
280{ 279{
281 FontListItem *fli = (FontListItem *) d->m_font_family_list->item ( d->m_font_family_list->currentItem()); 280 FontListItem *fli = (FontListItem *) d->m_font_family_list->item ( d->m_font_family_list->currentItem());
282 281
283 return fli ? d->m_fdb. charSets ( fli->family()) [0] : QString::null; 282 return fli ? d->m_fdb. charSets ( fli->family()) [0] : QString::null;
284} 283}
285 284
286/** 285/**
287 * Overloaded member function see above 286 * Overloaded member function see above
288 * @see selectedFont 287 * @see selectedFont
289 */ 288 */
290bool OFontSelector::selectedFont ( QString &family, QString &style, int &size, QString &charset ) 289bool OFontSelector::selectedFont ( QString &family, QString &style, int &size, QString &charset )
291{ 290{
292 int ffa = d->m_font_family_list->currentItem(); 291 int ffa = d->m_font_family_list->currentItem();
293 int fst = d->m_font_style_list->currentItem(); 292 int fst = d->m_font_style_list->currentItem();
294 int fsi = d->m_font_size_list->currentItem(); 293 int fsi = d->m_font_size_list->currentItem();
295 294
296 FontListItem *fli = (FontListItem *) d->m_font_family_list->item ( ffa ); 295 FontListItem *fli = (FontListItem *) d->m_font_family_list->item ( ffa );
297 296
298 if ( fli ) 297 if ( fli )
299 { 298 {
300 family = fli->family(); 299 family = fli->family();
301 style = fst >= 0 ? fli->styles() [fst] : QString::null; 300 style = fst >= 0 ? fli->styles() [fst] : QString::null;
302 size = fsi >= 0 ? fli->sizes() [fsi] : 10; 301 size = fsi >= 0 ? fli->sizes() [fsi] : 10;
303 charset = d->m_fdb. charSets ( fli->family()) [0]; 302 charset = d->m_fdb. charSets ( fli->family()) [0];
304 303
305 return true; 304 return true;
306 } 305 }
307 else 306 else
308 return false; 307 return false;
309} 308}
310 309
311void OFontSelector::loadFonts ( QListBox *list ) 310void OFontSelector::loadFonts ( QListBox *list )
312{ 311{
313 QStringList f = d->m_fdb. families(); 312 QStringList f = d->m_fdb. families();
314 313
315 for ( QStringList::ConstIterator it = f. begin(); it != f. end(); ++it ) 314 for ( QStringList::ConstIterator it = f. begin(); it != f. end(); ++it )
316 { 315 {
317 QValueList <int> ps = d->m_fdb. pointSizes ( *it ); 316 QValueList <int> ps = d->m_fdb. pointSizes ( *it );
318 317
319 if ( d->m_pointbug ) 318 if ( d->m_pointbug )
320 { 319 {
321 for ( QValueList <int>::Iterator it = ps. begin(); it != ps. end(); it++ ) 320 for ( QValueList <int>::Iterator it = ps. begin(); it != ps. end(); it++ )
322 *it /= 10; 321 *it /= 10;
323 } 322 }
324 323
325 list->insertItem ( new FontListItem ( *it, d->m_fdb. styles ( *it ), ps )); 324 list->insertItem ( new FontListItem ( *it, d->m_fdb. styles ( *it ), ps ));
326 } 325 }
327} 326}
328 327
329void OFontSelector::fontFamilyClicked ( int index ) 328void OFontSelector::fontFamilyClicked ( int index )
330{ 329{
331 QString oldstyle = d->m_font_style_list->currentText(); 330 QString oldstyle = d->m_font_style_list->currentText();
332 QString oldsize = d->m_font_size_list->currentText(); 331 QString oldsize = d->m_font_size_list->currentText();
333 332
334 FontListItem *fli = (FontListItem *) d->m_font_family_list->item ( index ); 333 FontListItem *fli = (FontListItem *) d->m_font_family_list->item ( index );
335 334
336 d->m_font_style_list->clear(); 335 d->m_font_style_list->clear();
337 d->m_font_style_list->insertStringList ( fli->styles()); 336 d->m_font_style_list->insertStringList ( fli->styles());
338 d->m_font_style_list->setEnabled ( !fli->styles(). isEmpty()); 337 d->m_font_style_list->setEnabled ( !fli->styles(). isEmpty());
339 338
340 int i; 339 int i;
341 340
342 i = findItemCB ( d->m_font_style_list, oldstyle ); 341 i = findItemCB ( d->m_font_style_list, oldstyle );
343 if ( i < 0 ) 342 if ( i < 0 )
344 i = findItemCB ( d->m_font_style_list, "Regular" ); 343 i = findItemCB ( d->m_font_style_list, "Regular" );
345 if (( i < 0 ) && ( d->m_font_style_list->count() > 0 )) 344 if (( i < 0 ) && ( d->m_font_style_list->count() > 0 ))
346 i = 0; 345 i = 0;
347 346
348 if ( i >= 0 ) 347 if ( i >= 0 )
349 { 348 {
350 d->m_font_style_list->setCurrentItem ( i ); 349 d->m_font_style_list->setCurrentItem ( i );
351 fontStyleClicked ( i ); 350 fontStyleClicked ( i );
352 } 351 }
353 352
354 d->m_font_size_list->clear(); 353 d->m_font_size_list->clear();
355 QValueList<int> sl = fli->sizes(); 354 QValueList<int> sl = fli->sizes();
356 355
357 for ( QValueList<int>::Iterator it = sl. begin(); it != sl. end(); ++it ) 356 for ( QValueList<int>::Iterator it = sl. begin(); it != sl. end(); ++it )
358 d->m_font_size_list->insertItem ( QString::number ( *it )); 357 d->m_font_size_list->insertItem ( QString::number ( *it ));
359 358
360 i = findItemCB ( d->m_font_size_list, oldsize ); 359 i = findItemCB ( d->m_font_size_list, oldsize );
361 if ( i < 0 ) 360 if ( i < 0 )
362 i = findItemCB ( d->m_font_size_list, "10" ); 361 i = findItemCB ( d->m_font_size_list, "10" );
363 if (( i < 0 ) && ( d->m_font_size_list->count() > 0 )) 362 if (( i < 0 ) && ( d->m_font_size_list->count() > 0 ))
364 i = 0; 363 i = 0;
365 364
366 if ( i >= 0 ) 365 if ( i >= 0 )
367 { 366 {
368 d->m_font_size_list->setCurrentItem ( i ); 367 d->m_font_size_list->setCurrentItem ( i );
369 fontSizeClicked ( i ); 368 fontSizeClicked ( i );
370 } 369 }
371 changeFont(); 370 changeFont();
372} 371}
373 372
374void OFontSelector::fontStyleClicked ( int /*index*/ ) 373void OFontSelector::fontStyleClicked ( int /*index*/ )
375{ 374{
376 changeFont(); 375 changeFont();
377} 376}
378 377
379void OFontSelector::fontSizeClicked ( int /*index*/ ) 378void OFontSelector::fontSizeClicked ( int /*index*/ )
380{ 379{
381 changeFont(); 380 changeFont();
382} 381}
383 382
384void OFontSelector::changeFont() 383void OFontSelector::changeFont()
385{ 384{
386 QFont f = selectedFont(); 385 QFont f = selectedFont();
387 386
388 if ( d->m_preview ) 387 if ( d->m_preview )
389 d->m_preview->setFont ( f ); 388 d->m_preview->setFont ( f );
390 389
391 emit fontSelected ( f ); 390 emit fontSelected ( f );
392} 391}
393 392
394/** 393/**
395 * Return the selected font 394 * Return the selected font
396 */ 395 */
397QFont OFontSelector::selectedFont() 396QFont OFontSelector::selectedFont()
398{ 397{
399 int ffa = d->m_font_family_list->currentItem(); 398 int ffa = d->m_font_family_list->currentItem();
400 int fst = d->m_font_style_list->currentItem(); 399 int fst = d->m_font_style_list->currentItem();
401 int fsi = d->m_font_size_list->currentItem(); 400 int fsi = d->m_font_size_list->currentItem();
402 401
403 FontListItem *fli = (FontListItem *) d->m_font_family_list->item ( ffa ); 402 FontListItem *fli = (FontListItem *) d->m_font_family_list->item ( ffa );
404 403
405 if ( fli ) 404 if ( fli )
406 { 405 {
407 return d->m_fdb. font ( fli->family(), \ 406 return d->m_fdb. font ( fli->family(), \
408 fst >= 0 ? fli->styles() [fst] : QString::null, \ 407 fst >= 0 ? fli->styles() [fst] : QString::null, \
409 fsi >= 0 ? fli->sizes() [fsi] : 10, \ 408 fsi >= 0 ? fli->sizes() [fsi] : 10, \
410 d->m_fdb. charSets ( fli->family()) [0] ); 409 d->m_fdb. charSets ( fli->family()) [0] );
411 } 410 }
412 else 411 else
413 return QFont(); 412 return QFont();
414} 413}
415 414
416void OFontSelector::resizeEvent ( QResizeEvent *re ) 415void OFontSelector::resizeEvent ( QResizeEvent *re )
417{ 416{
418 if ( d->m_preview ) 417 if ( d->m_preview )
419 { 418 {
420 d->m_preview->setMinimumHeight ( 1 ); 419 d->m_preview->setMinimumHeight ( 1 );
421 d->m_preview->setMaximumHeight ( 32767 ); 420 d->m_preview->setMaximumHeight ( 32767 );
422 } 421 }
423 422
424 QWidget::resizeEvent ( re ); 423 QWidget::resizeEvent ( re );
425 424
426 if ( d->m_preview ) 425 if ( d->m_preview )
427 d->m_preview->setFixedHeight ( d->m_preview->height()); 426 d->m_preview->setFixedHeight ( d->m_preview->height());
428 427
429} 428}
diff --git a/libopie2/opieui/olistview.cpp b/libopie2/opieui/olistview.cpp
index 38f3fe2..84617f8 100644
--- a/libopie2/opieui/olistview.cpp
+++ b/libopie2/opieui/olistview.cpp
@@ -1,613 +1,610 @@
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@Vanille.de> 3 =. (C) 2003 Michael 'Mickey' Lauer <mickey@Vanille.de>
4 .=l. 4 .=l.
5           .>+-= 5           .>+-=
6 _;:,     .>    :=|. This program is free software; you can 6 _;:,     .>    :=|. This program is free software; you can
7.> <`_,   >  .   <= redistribute it and/or modify it under 7.> <`_,   >  .   <= redistribute it and/or modify it under
8:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 8:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
9.="- .-=="i,     .._ License as published by the Free Software 9.="- .-=="i,     .._ License as published by the Free Software
10 - .   .-<_>     .<> Foundation; either version 2 of the License, 10 - .   .-<_>     .<> Foundation; either version 2 of the License,
11     ._= =}       : or (at your option) any later version. 11     ._= =}       : or (at your option) any later version.
12    .%`+i>       _;_. 12    .%`+i>       _;_.
13    .i_,=:_.      -<s. This program is distributed in the hope that 13    .i_,=:_.      -<s. This program is distributed in the hope that
14     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 14     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
15    : ..    .:,     . . . without even the implied warranty of 15    : ..    .:,     . . . without even the implied warranty of
16    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 16    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
17  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 17  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
18..}^=.=       =       ; Library General Public License for more 18..}^=.=       =       ; Library General Public License for more
19++=   -.     .`     .: details. 19++=   -.     .`     .: details.
20 :     =  ...= . :.=- 20 :     =  ...= . :.=-
21 -.   .:....=;==+<; You should have received a copy of the GNU 21 -.   .:....=;==+<; You should have received a copy of the GNU
22  -_. . .   )=.  = Library General Public License along with 22  -_. . .   )=.  = Library General Public License along with
23    --        :-=` this library; see the file COPYING.LIB. 23    --        :-=` this library; see the file COPYING.LIB.
24 If not, write to the Free Software Foundation, 24 If not, write to the Free Software Foundation,
25 Inc., 59 Temple Place - Suite 330, 25 Inc., 59 Temple Place - Suite 330,
26 Boston, MA 02111-1307, USA. 26 Boston, MA 02111-1307, USA.
27 27
28*/ 28*/
29 29
30/* QT */ 30/* QT */
31 31
32#include <qcolor.h>
33#include <qheader.h>
34#include <qpainter.h>
35#include <qpixmap.h> 32#include <qpixmap.h>
36 33
37/* OPIE */ 34/* OPIE */
38 35
39#include <opie2/odebug.h> 36#include <opie2/odebug.h>
40#include <opie2/olistview.h> 37#include <opie2/olistview.h>
41 38
42/*====================================================================================== 39/*======================================================================================
43 * OListView 40 * OListView
44 *======================================================================================*/ 41 *======================================================================================*/
45 42
46OListView::OListView( QWidget *parent, const char *name ) 43OListView::OListView( QWidget *parent, const char *name )
47 :QListView( parent, name ) 44 :QListView( parent, name )
48{ 45{
49 //FIXME: get from global settings and calculate ==> see oglobalsettings.* 46 //FIXME: get from global settings and calculate ==> see oglobalsettings.*
50 47
51 m_alternateBackground = QColor( 238, 246, 255 ); 48 m_alternateBackground = QColor( 238, 246, 255 );
52 m_columnSeparator = QPen( QColor( 150, 160, 170 ), 0, DotLine ); 49 m_columnSeparator = QPen( QColor( 150, 160, 170 ), 0, DotLine );
53 m_fullWidth = true; 50 m_fullWidth = true;
54 connect( this, SIGNAL(expanded(QListViewItem*)), SLOT(expand(QListViewItem*))); 51 connect( this, SIGNAL(expanded(QListViewItem*)), SLOT(expand(QListViewItem*)));
55} 52}
56 53
57OListView::~OListView() 54OListView::~OListView()
58{ 55{
59} 56}
60 57
61void OListView::setFullWidth( bool fullWidth ) 58void OListView::setFullWidth( bool fullWidth )
62{ 59{
63 m_fullWidth = m_fullWidth; 60 m_fullWidth = m_fullWidth;
64 #if QT_VERSION > 290 61 #if QT_VERSION > 290
65 header()->setStretchEnabled( fullWidth, columns()-1 ); 62 header()->setStretchEnabled( fullWidth, columns()-1 );
66 #endif 63 #endif
67} 64}
68 65
69bool OListView::fullWidth() const 66bool OListView::fullWidth() const
70{ 67{
71 return m_fullWidth; 68 return m_fullWidth;
72} 69}
73 70
74int OListView::addColumn( const QString& label, int width ) 71int OListView::addColumn( const QString& label, int width )
75{ 72{
76 int result = QListView::addColumn( label, width ); 73 int result = QListView::addColumn( label, width );
77 #if QT_VERSION > 290 74 #if QT_VERSION > 290
78 if (m_fullWidth) { 75 if (m_fullWidth) {
79 header()->setStretchEnabled( false, columns()-2 ); 76 header()->setStretchEnabled( false, columns()-2 );
80 header()->setStretchEnabled( true, columns()-1 ); 77 header()->setStretchEnabled( true, columns()-1 );
81 } 78 }
82 #endif 79 #endif
83 return result; 80 return result;
84} 81}
85 82
86int OListView::addColumn( const QIconSet& iconset, const QString& label, int width ) 83int OListView::addColumn( const QIconSet& iconset, const QString& label, int width )
87{ 84{
88 int result = QListView::addColumn( iconset, label, width ); 85 int result = QListView::addColumn( iconset, label, width );
89 #if QT_VERSION > 290 86 #if QT_VERSION > 290
90 if (m_fullWidth) { 87 if (m_fullWidth) {
91 header()->setStretchEnabled( false, columns()-2 ); 88 header()->setStretchEnabled( false, columns()-2 );
92 header()->setStretchEnabled( true, columns()-1 ); 89 header()->setStretchEnabled( true, columns()-1 );
93 } 90 }
94 #endif 91 #endif
95 return result; 92 return result;
96} 93}
97 94
98void OListView::removeColumn( int index ) 95void OListView::removeColumn( int index )
99{ 96{
100 QListView::removeColumn(index); 97 QListView::removeColumn(index);
101 #if QT_VERSION > 290 98 #if QT_VERSION > 290
102 if ( m_fullWidth && index == columns() ) 99 if ( m_fullWidth && index == columns() )
103 { 100 {
104 header()->setStretchEnabled( true, columns()-1 ); 101 header()->setStretchEnabled( true, columns()-1 );
105 } 102 }
106 #endif 103 #endif
107} 104}
108 105
109const QColor& OListView::alternateBackground() const 106const QColor& OListView::alternateBackground() const
110{ 107{
111 return m_alternateBackground; 108 return m_alternateBackground;
112} 109}
113 110
114void OListView::setAlternateBackground( const QColor &c ) 111void OListView::setAlternateBackground( const QColor &c )
115{ 112{
116 m_alternateBackground = c; 113 m_alternateBackground = c;
117 repaint(); 114 repaint();
118} 115}
119 116
120const QPen& OListView::columnSeparator() const 117const QPen& OListView::columnSeparator() const
121{ 118{
122 return m_columnSeparator; 119 return m_columnSeparator;
123} 120}
124 121
125void OListView::setColumnSeparator( const QPen& p ) 122void OListView::setColumnSeparator( const QPen& p )
126{ 123{
127 m_columnSeparator = p; 124 m_columnSeparator = p;
128 repaint(); 125 repaint();
129} 126}
130 127
131void OListView::expand(QListViewItem *item) 128void OListView::expand(QListViewItem *item)
132{ 129{
133 ((OListViewItem*)item)->expand(); 130 ((OListViewItem*)item)->expand();
134} 131}
135 132
136OListViewItem* OListView::childFactory() 133OListViewItem* OListView::childFactory()
137{ 134{
138 return new OListViewItem( this ); 135 return new OListViewItem( this );
139} 136}
140 137
141#ifndef QT_NO_DATASTREAM 138#ifndef QT_NO_DATASTREAM
142void OListView::serializeTo( QDataStream& s ) const 139void OListView::serializeTo( QDataStream& s ) const
143{ 140{
144 #warning Caution... the binary format is still under construction... 141 #warning Caution... the binary format is still under construction...
145 odebug << "storing OListView..." << oendl; 142 odebug << "storing OListView..." << oendl;
146 143
147 // store number of columns and the labels 144 // store number of columns and the labels
148 s << columns(); 145 s << columns();
149 for ( int i = 0; i < columns(); ++i ) 146 for ( int i = 0; i < columns(); ++i )
150 s << columnText( i ); 147 s << columnText( i );
151 148
152 // calculate the number of top-level items to serialize 149 // calculate the number of top-level items to serialize
153 int items = 0; 150 int items = 0;
154 QListViewItem* item = firstChild(); 151 QListViewItem* item = firstChild();
155 while ( item ) 152 while ( item )
156 { 153 {
157 item = item->nextSibling(); 154 item = item->nextSibling();
158 items++; 155 items++;
159 } 156 }
160 157
161 // store number of items and the items itself 158 // store number of items and the items itself
162 s << items; 159 s << items;
163 item = firstChild(); 160 item = firstChild();
164 for ( int i = 0; i < items; ++i ) 161 for ( int i = 0; i < items; ++i )
165 { 162 {
166 s << *static_cast<OListViewItem*>( item ); 163 s << *static_cast<OListViewItem*>( item );
167 item = item->nextSibling(); 164 item = item->nextSibling();
168 } 165 }
169 166
170 odebug << "OListview stored." << oendl; 167 odebug << "OListview stored." << oendl;
171} 168}
172 169
173void OListView::serializeFrom( QDataStream& s ) 170void OListView::serializeFrom( QDataStream& s )
174{ 171{
175 #warning Caution... the binary format is still under construction... 172 #warning Caution... the binary format is still under construction...
176 odebug << "loading OListView..." << oendl; 173 odebug << "loading OListView..." << oendl;
177 174
178 int cols; 175 int cols;
179 s >> cols; 176 s >> cols;
180 qDebug( "read number of columns = %d", cols ); 177 qDebug( "read number of columns = %d", cols );
181 178
182 while ( columns() < cols ) addColumn( QString::null ); 179 while ( columns() < cols ) addColumn( QString::null );
183 180
184 for ( int i = 0; i < cols; ++i ) 181 for ( int i = 0; i < cols; ++i )
185 { 182 {
186 QString coltext; 183 QString coltext;
187 s >> coltext; 184 s >> coltext;
188 qDebug( "read text '%s' for column %d", (const char*) coltext, i ); 185 qDebug( "read text '%s' for column %d", (const char*) coltext, i );
189 setColumnText( i, coltext ); 186 setColumnText( i, coltext );
190 } 187 }
191 188
192 int items; 189 int items;
193 s >> items; 190 s >> items;
194 qDebug( "read number of items = %d", items ); 191 qDebug( "read number of items = %d", items );
195 192
196 for ( int i = 0; i < items; ++i ) 193 for ( int i = 0; i < items; ++i )
197 { 194 {
198 OListViewItem* item = childFactory(); 195 OListViewItem* item = childFactory();
199 s >> *item; 196 s >> *item;
200 } 197 }
201 198
202 odebug << "OListView loaded." << oendl; 199 odebug << "OListView loaded." << oendl;
203 200
204} 201}
205 202
206QDataStream& operator<<( QDataStream& s, const OListView& lv ) 203QDataStream& operator<<( QDataStream& s, const OListView& lv )
207{ 204{
208 lv.serializeTo( s ); 205 lv.serializeTo( s );
209} 206}
210 207
211QDataStream& operator>>( QDataStream& s, OListView& lv ) 208QDataStream& operator>>( QDataStream& s, OListView& lv )
212{ 209{
213 lv.serializeFrom( s ); 210 lv.serializeFrom( s );
214} 211}
215#endif // QT_NO_DATASTREAM 212#endif // QT_NO_DATASTREAM
216 213
217/*====================================================================================== 214/*======================================================================================
218 * OListViewItem 215 * OListViewItem
219 *======================================================================================*/ 216 *======================================================================================*/
220 217
221OListViewItem::OListViewItem(QListView *parent) 218OListViewItem::OListViewItem(QListView *parent)
222 : QListViewItem(parent) 219 : QListViewItem(parent)
223{ 220{
224 init(); 221 init();
225} 222}
226 223
227 224
228OListViewItem::OListViewItem(QListViewItem *parent) 225OListViewItem::OListViewItem(QListViewItem *parent)
229 : QListViewItem(parent) 226 : QListViewItem(parent)
230{ 227{
231 init(); 228 init();
232} 229}
233 230
234 231
235OListViewItem::OListViewItem(QListView *parent, QListViewItem *after) 232OListViewItem::OListViewItem(QListView *parent, QListViewItem *after)
236 : QListViewItem(parent, after) 233 : QListViewItem(parent, after)
237{ 234{
238 init(); 235 init();
239} 236}
240 237
241 238
242OListViewItem::OListViewItem(QListViewItem *parent, QListViewItem *after) 239OListViewItem::OListViewItem(QListViewItem *parent, QListViewItem *after)
243 : QListViewItem(parent, after) 240 : QListViewItem(parent, after)
244{ 241{
245 init(); 242 init();
246} 243}
247 244
248 245
249OListViewItem::OListViewItem(QListView *parent, 246OListViewItem::OListViewItem(QListView *parent,
250 QString label1, QString label2, QString label3, QString label4, 247 QString label1, QString label2, QString label3, QString label4,
251 QString label5, QString label6, QString label7, QString label8) 248 QString label5, QString label6, QString label7, QString label8)
252 : QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8) 249 : QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8)
253{ 250{
254 init(); 251 init();
255} 252}
256 253
257 254
258OListViewItem::OListViewItem(QListViewItem *parent, 255OListViewItem::OListViewItem(QListViewItem *parent,
259 QString label1, QString label2, QString label3, QString label4, 256 QString label1, QString label2, QString label3, QString label4,
260 QString label5, QString label6, QString label7, QString label8) 257 QString label5, QString label6, QString label7, QString label8)
261 : QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8) 258 : QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8)
262{ 259{
263 init(); 260 init();
264} 261}
265 262
266 263
267OListViewItem::OListViewItem(QListView *parent, QListViewItem *after, 264OListViewItem::OListViewItem(QListView *parent, QListViewItem *after,
268 QString label1, QString label2, QString label3, QString label4, 265 QString label1, QString label2, QString label3, QString label4,
269 QString label5, QString label6, QString label7, QString label8) 266 QString label5, QString label6, QString label7, QString label8)
270 : QListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8) 267 : QListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8)
271{ 268{
272 init(); 269 init();
273} 270}
274 271
275 272
276OListViewItem::OListViewItem(QListViewItem *parent, QListViewItem *after, 273OListViewItem::OListViewItem(QListViewItem *parent, QListViewItem *after,
277 QString label1, QString label2, QString label3, QString label4, 274 QString label1, QString label2, QString label3, QString label4,
278 QString label5, QString label6, QString label7, QString label8) 275 QString label5, QString label6, QString label7, QString label8)
279 : QListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8) 276 : QListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8)
280{ 277{
281 init(); 278 init();
282} 279}
283 280
284 281
285OListViewItem::~OListViewItem() 282OListViewItem::~OListViewItem()
286{ 283{
287} 284}
288 285
289 286
290void OListViewItem::init() 287void OListViewItem::init()
291{ 288{
292 m_known = false; 289 m_known = false;
293} 290}
294 291
295 292
296const QColor &OListViewItem::backgroundColor() 293const QColor &OListViewItem::backgroundColor()
297{ 294{
298 return isAlternate() ? static_cast<OListView*>(listView())->alternateBackground() : 295 return isAlternate() ? static_cast<OListView*>(listView())->alternateBackground() :
299 listView()->viewport()->colorGroup().base(); 296 listView()->viewport()->colorGroup().base();
300} 297}
301 298
302 299
303bool OListViewItem::isAlternate() 300bool OListViewItem::isAlternate()
304{ 301{
305 OListView *lv = static_cast<OListView*>( listView() ); 302 OListView *lv = static_cast<OListView*>( listView() );
306 303
307 // check if the item above is an OListViewItem 304 // check if the item above is an OListViewItem
308 OListViewItem *above = static_cast<OListViewItem*>( itemAbove() ); 305 OListViewItem *above = static_cast<OListViewItem*>( itemAbove() );
309 /*if (! itemAbove()->inherits( "OListViewItem" )) return false;*/ 306 /*if (! itemAbove()->inherits( "OListViewItem" )) return false;*/
310 307
311 // check if we have a valid alternate background color 308 // check if we have a valid alternate background color
312 if (!(lv && lv->alternateBackground().isValid())) return false; 309 if (!(lv && lv->alternateBackground().isValid())) return false;
313 310
314 m_known = above ? above->m_known : true; 311 m_known = above ? above->m_known : true;
315 if (m_known) 312 if (m_known)
316 { 313 {
317 m_odd = above ? !above->m_odd : false; 314 m_odd = above ? !above->m_odd : false;
318 } 315 }
319 else 316 else
320 { 317 {
321 OListViewItem *item; 318 OListViewItem *item;
322 bool previous = true; 319 bool previous = true;
323 if (parent()) 320 if (parent())
324 { 321 {
325 item = static_cast<OListViewItem *>(parent()); 322 item = static_cast<OListViewItem *>(parent());
326 if ( item /*&& item->inherits( "OListViewItem" )*/ ) previous = item->m_odd; 323 if ( item /*&& item->inherits( "OListViewItem" )*/ ) previous = item->m_odd;
327 item = static_cast<OListViewItem *>(parent()->firstChild()); 324 item = static_cast<OListViewItem *>(parent()->firstChild());
328 /* if ( !item.inherits( "OListViewItem" ) item = 0; */ 325 /* if ( !item.inherits( "OListViewItem" ) item = 0; */
329 } 326 }
330 else 327 else
331 { 328 {
332 item = static_cast<OListViewItem *>(lv->firstChild()); 329 item = static_cast<OListViewItem *>(lv->firstChild());
333 } 330 }
334 331
335 while(item) 332 while(item)
336 { 333 {
337 item->m_odd = previous = !previous; 334 item->m_odd = previous = !previous;
338 item->m_known = true; 335 item->m_known = true;
339 item = static_cast<OListViewItem *>(item->nextSibling()); 336 item = static_cast<OListViewItem *>(item->nextSibling());
340 /* if (!item.inherits( "OListViewItem" ) ) break; */ 337 /* if (!item.inherits( "OListViewItem" ) ) break; */
341 } 338 }
342 } 339 }
343 return m_odd; 340 return m_odd;
344} 341}
345 342
346 343
347void OListViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment) 344void OListViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment)
348{ 345{
349 QColorGroup _cg = cg; 346 QColorGroup _cg = cg;
350 const QPixmap *pm = listView()->viewport()->backgroundPixmap(); 347 const QPixmap *pm = listView()->viewport()->backgroundPixmap();
351 if (pm && !pm->isNull()) 348 if (pm && !pm->isNull())
352 { 349 {
353 _cg.setBrush( QColorGroup::Base, QBrush(backgroundColor(), *pm) ); 350 _cg.setBrush( QColorGroup::Base, QBrush(backgroundColor(), *pm) );
354 p->setBrushOrigin( -listView()->contentsX(), -listView()->contentsY() ); 351 p->setBrushOrigin( -listView()->contentsX(), -listView()->contentsY() );
355 } 352 }
356 else if ( isAlternate() ) 353 else if ( isAlternate() )
357 { 354 {
358 _cg.setColor( QColorGroup::Base, static_cast<OListView*>( listView() )->alternateBackground() ); 355 _cg.setColor( QColorGroup::Base, static_cast<OListView*>( listView() )->alternateBackground() );
359 } 356 }
360 QListViewItem::paintCell( p, _cg, column, width, alignment ); 357 QListViewItem::paintCell( p, _cg, column, width, alignment );
361 358
362 //FIXME: Use styling here! 359 //FIXME: Use styling here!
363 360
364 const QPen& pen = static_cast<OListView*>( listView() )->columnSeparator(); 361 const QPen& pen = static_cast<OListView*>( listView() )->columnSeparator();
365 p->setPen( pen ); 362 p->setPen( pen );
366 p->drawLine( width-1, 0, width-1, height() ); 363 p->drawLine( width-1, 0, width-1, height() );
367} 364}
368 365
369 366
370OListViewItem* OListViewItem::childFactory() 367OListViewItem* OListViewItem::childFactory()
371{ 368{
372 return new OListViewItem( this ); 369 return new OListViewItem( this );
373} 370}
374 371
375 372
376#ifndef QT_NO_DATASTREAM 373#ifndef QT_NO_DATASTREAM
377void OListViewItem::serializeTo( QDataStream& s ) const 374void OListViewItem::serializeTo( QDataStream& s ) const
378{ 375{
379 #warning Caution... the binary format is still under construction... 376 #warning Caution... the binary format is still under construction...
380 odebug << "storing OListViewItem..." << oendl; 377 odebug << "storing OListViewItem..." << oendl;
381 378
382 // store item text 379 // store item text
383 for ( int i = 0; i < listView()->columns(); ++i ) 380 for ( int i = 0; i < listView()->columns(); ++i )
384 { 381 {
385 s << text( i ); 382 s << text( i );
386 } 383 }
387 384
388 // calculate the number of children to serialize 385 // calculate the number of children to serialize
389 int items = 0; 386 int items = 0;
390 QListViewItem* item = firstChild(); 387 QListViewItem* item = firstChild();
391 while ( item ) 388 while ( item )
392 { 389 {
393 item = item->nextSibling(); 390 item = item->nextSibling();
394 items++; 391 items++;
395 } 392 }
396 393
397 // store number of items and the items itself 394 // store number of items and the items itself
398 s << items; 395 s << items;
399 item = firstChild(); 396 item = firstChild();
400 for ( int i = 0; i < items; ++i ) 397 for ( int i = 0; i < items; ++i )
401 { 398 {
402 s << *static_cast<OListViewItem*>( item ); 399 s << *static_cast<OListViewItem*>( item );
403 item = item->nextSibling(); 400 item = item->nextSibling();
404 } 401 }
405 402
406 odebug << "OListviewItem stored." << oendl; 403 odebug << "OListviewItem stored." << oendl;
407} 404}
408 405
409 406
410void OListViewItem::serializeFrom( QDataStream& s ) 407void OListViewItem::serializeFrom( QDataStream& s )
411{ 408{
412 #warning Caution... the binary format is still under construction... 409 #warning Caution... the binary format is still under construction...
413 odebug << "loading OListViewItem..." << oendl; 410 odebug << "loading OListViewItem..." << oendl;
414 411
415 for ( int i = 0; i < listView()->columns(); ++i ) 412 for ( int i = 0; i < listView()->columns(); ++i )
416 { 413 {
417 QString coltext; 414 QString coltext;
418 s >> coltext; 415 s >> coltext;
419 qDebug( "read text '%s' for column %d", (const char*) coltext, i ); 416 qDebug( "read text '%s' for column %d", (const char*) coltext, i );
420 setText( i, coltext ); 417 setText( i, coltext );
421 } 418 }
422 419
423 int items; 420 int items;
424 s >> items; 421 s >> items;
425 qDebug( "read number of items = %d", items ); 422 qDebug( "read number of items = %d", items );
426 423
427 for ( int i = 0; i < items; ++i ) 424 for ( int i = 0; i < items; ++i )
428 { 425 {
429 OListViewItem* item = childFactory(); 426 OListViewItem* item = childFactory();
430 s >> (*item); 427 s >> (*item);
431 } 428 }
432 429
433 odebug << "OListViewItem loaded." << oendl; 430 odebug << "OListViewItem loaded." << oendl;
434} 431}
435 432
436 433
437QDataStream& operator<<( QDataStream& s, const OListViewItem& lvi ) 434QDataStream& operator<<( QDataStream& s, const OListViewItem& lvi )
438{ 435{
439 lvi.serializeTo( s ); 436 lvi.serializeTo( s );
440} 437}
441 438
442 439
443QDataStream& operator>>( QDataStream& s, OListViewItem& lvi ) 440QDataStream& operator>>( QDataStream& s, OListViewItem& lvi )
444{ 441{
445 lvi.serializeFrom( s ); 442 lvi.serializeFrom( s );
446} 443}
447#endif // QT_NO_DATASTREAM 444#endif // QT_NO_DATASTREAM
448 445
449 446
450/*====================================================================================== 447/*======================================================================================
451 * ONamedListView 448 * ONamedListView
452 *======================================================================================*/ 449 *======================================================================================*/
453 450
454ONamedListView::ONamedListView( QWidget *parent, const char *name ) 451ONamedListView::ONamedListView( QWidget *parent, const char *name )
455 :OListView( parent, name ) 452 :OListView( parent, name )
456{ 453{
457} 454}
458 455
459 456
460ONamedListView::~ONamedListView() 457ONamedListView::~ONamedListView()
461{ 458{
462} 459}
463 460
464 461
465void ONamedListView::addColumns( const QStringList& columns ) 462void ONamedListView::addColumns( const QStringList& columns )
466{ 463{
467 for ( QStringList::ConstIterator it = columns.begin(); it != columns.end(); ++it ) 464 for ( QStringList::ConstIterator it = columns.begin(); it != columns.end(); ++it )
468 { 465 {
469 qDebug( "adding column %s", (const char*) *it ); 466 qDebug( "adding column %s", (const char*) *it );
470 addColumn( *it ); 467 addColumn( *it );
471 } 468 }
472} 469}
473 470
474 471
475int ONamedListView::findColumn( const QString& text ) const 472int ONamedListView::findColumn( const QString& text ) const
476{ 473{
477 //FIXME: If used excessively, this will slow down performance of updates 474 //FIXME: If used excessively, this will slow down performance of updates
478 //FIXME: because of the linear search over all column texts. 475 //FIXME: because of the linear search over all column texts.
479 //FIXME: I will optimize later by using a hash map. 476 //FIXME: I will optimize later by using a hash map.
480 for ( int i = 0; i < columns(); ++i ) 477 for ( int i = 0; i < columns(); ++i )
481 if ( columnText( i ) == text ) 478 if ( columnText( i ) == text )
482 return i; 479 return i;
483 return -1; 480 return -1;
484} 481}
485 482
486 483
487ONamedListViewItem* ONamedListView::find( int column, const QString& text, int recurse ) const 484ONamedListViewItem* ONamedListView::find( int column, const QString& text, int recurse ) const
488{ 485{
489 return find( (ONamedListViewItem*) firstChild(), column, text, recurse ); 486 return find( (ONamedListViewItem*) firstChild(), column, text, recurse );
490} 487}
491 488
492 489
493ONamedListViewItem* ONamedListView::find( ONamedListViewItem* item, int column, const QString& text, int recurse ) const 490ONamedListViewItem* ONamedListView::find( ONamedListViewItem* item, int column, const QString& text, int recurse ) const
494{ 491{
495 ONamedListViewItem* result; 492 ONamedListViewItem* result;
496 while ( item && item->text( column ) != text ) 493 while ( item && item->text( column ) != text )
497 { 494 {
498 qDebug( "checked %s", (const char*) item->text( column ) ); 495 qDebug( "checked %s", (const char*) item->text( column ) );
499 496
500 if ( recurse < 0 || recurse > 0 ) 497 if ( recurse < 0 || recurse > 0 )
501 { 498 {
502 qDebug( "recursion is %d - recursing into...", recurse ); 499 qDebug( "recursion is %d - recursing into...", recurse );
503 result = find( (ONamedListViewItem*) item->firstChild(), column, text, recurse-1 ); 500 result = find( (ONamedListViewItem*) item->firstChild(), column, text, recurse-1 );
504 if ( result ) return result; 501 if ( result ) return result;
505 } 502 }
506 503
507 504
508 item = (ONamedListViewItem*) item->itemBelow(); 505 item = (ONamedListViewItem*) item->itemBelow();
509 } 506 }
510 if ( item && item->text( column ) == text ) 507 if ( item && item->text( column ) == text )
511 return item; 508 return item;
512 else 509 else
513 return 0; 510 return 0;
514} 511}
515 512
516 513
517ONamedListViewItem* ONamedListView::find( const QString& column, const QString& text, int recurse ) const 514ONamedListViewItem* ONamedListView::find( const QString& column, const QString& text, int recurse ) const
518{ 515{
519 int col = findColumn( column ); 516 int col = findColumn( column );
520 if ( col != -1 ) 517 if ( col != -1 )
521 return find( (ONamedListViewItem*) firstChild(), col, text, recurse ); 518 return find( (ONamedListViewItem*) firstChild(), col, text, recurse );
522 else 519 else
523 return 0; 520 return 0;
524} 521}
525 522
526 523
527ONamedListViewItem* ONamedListView::find( ONamedListViewItem* item, const QString& column, const QString& text, int recurse ) const 524ONamedListViewItem* ONamedListView::find( ONamedListViewItem* item, const QString& column, const QString& text, int recurse ) const
528{ 525{
529 int col = findColumn( column ); 526 int col = findColumn( column );
530 if ( col != -1 ) 527 if ( col != -1 )
531 return find( item, col, text, recurse ); 528 return find( item, col, text, recurse );
532 else 529 else
533 return 0; 530 return 0;
534} 531}
535 532
536 533
537/*====================================================================================== 534/*======================================================================================
538 * ONamedListViewItem 535 * ONamedListViewItem
539 *======================================================================================*/ 536 *======================================================================================*/
540 537
541ONamedListViewItem::ONamedListViewItem( QListView* parent, const QStringList& texts ) 538ONamedListViewItem::ONamedListViewItem( QListView* parent, const QStringList& texts )
542 :OListViewItem( parent ) 539 :OListViewItem( parent )
543{ 540{
544 setText( texts ); 541 setText( texts );
545} 542}
546 543
547 544
548ONamedListViewItem::ONamedListViewItem( QListViewItem* parent, const QStringList& texts ) 545ONamedListViewItem::ONamedListViewItem( QListViewItem* parent, const QStringList& texts )
549 :OListViewItem( parent ) 546 :OListViewItem( parent )
550{ 547{
551 setText( texts ); 548 setText( texts );
552} 549}
553 550
554 551
555ONamedListViewItem::ONamedListViewItem( QListView* parent, QListViewItem* after, const QStringList& texts ) 552ONamedListViewItem::ONamedListViewItem( QListView* parent, QListViewItem* after, const QStringList& texts )
556 :OListViewItem( parent, after ) 553 :OListViewItem( parent, after )
557{ 554{
558 setText( texts ); 555 setText( texts );
559} 556}
560 557
561 558
562ONamedListViewItem::ONamedListViewItem( QListViewItem* parent, QListViewItem* after, const QStringList& texts ) 559ONamedListViewItem::ONamedListViewItem( QListViewItem* parent, QListViewItem* after, const QStringList& texts )
563 :OListViewItem( parent, after ) 560 :OListViewItem( parent, after )
564{ 561{
565 setText( texts ); 562 setText( texts );
566} 563}
567 564
568 565
569ONamedListViewItem::~ONamedListViewItem() 566ONamedListViewItem::~ONamedListViewItem()
570{ 567{
571} 568}
572 569
573 570
574void ONamedListViewItem::setText( const QStringList& texts ) 571void ONamedListViewItem::setText( const QStringList& texts )
575{ 572{
576 int col = 0; 573 int col = 0;
577 for ( QStringList::ConstIterator it = texts.begin(); it != texts.end(); ++it ) 574 for ( QStringList::ConstIterator it = texts.begin(); it != texts.end(); ++it )
578 { 575 {
579 qDebug( "setting column %d = text %s", col, (const char*) *it ); 576 qDebug( "setting column %d = text %s", col, (const char*) *it );
580 OListViewItem::setText( col++, *it ); 577 OListViewItem::setText( col++, *it );
581 } 578 }
582 579
583} 580}
584 581
585 582
586void ONamedListViewItem::setText( const QString& column, const QString& text ) 583void ONamedListViewItem::setText( const QString& column, const QString& text )
587{ 584{
588 //FIXME: If used excessively, this will slow down performance of updates 585 //FIXME: If used excessively, this will slow down performance of updates
589 //FIXME: because of the linear search over all column texts. 586 //FIXME: because of the linear search over all column texts.
590 //FIXME: I will optimize later by using a hash map. 587 //FIXME: I will optimize later by using a hash map.
591 int col = ( (ONamedListView*) listView() )->findColumn( column ); 588 int col = ( (ONamedListView*) listView() )->findColumn( column );
592 if ( col != -1 ) 589 if ( col != -1 )
593 OListViewItem::setText( col, text ); 590 OListViewItem::setText( col, text );
594 else 591 else
595 qWarning( "ONamedListViewItem::setText(): Warning! Columntext '%s' not found.", (const char*) column ); 592 qWarning( "ONamedListViewItem::setText(): Warning! Columntext '%s' not found.", (const char*) column );
596} 593}
597 594
598 595
599ONamedListViewItem* ONamedListViewItem::find( int column, const QString& text, int recurse ) const 596ONamedListViewItem* ONamedListViewItem::find( int column, const QString& text, int recurse ) const
600{ 597{
601 return ( (ONamedListView*) listView() )->find( (ONamedListViewItem*) firstChild(), column, text, recurse ); 598 return ( (ONamedListView*) listView() )->find( (ONamedListViewItem*) firstChild(), column, text, recurse );
602} 599}
603 600
604 601
605ONamedListViewItem* ONamedListViewItem::find( const QString& column, const QString& text, int recurse ) const 602ONamedListViewItem* ONamedListViewItem::find( const QString& column, const QString& text, int recurse ) const
606{ 603{
607 int col = ( (ONamedListView*) listView() )->findColumn( column ); 604 int col = ( (ONamedListView*) listView() )->findColumn( column );
608 if ( col != -1 ) 605 if ( col != -1 )
609 return ( (ONamedListView*) listView() )->find( (ONamedListViewItem*) firstChild(), col, text, recurse ); 606 return ( (ONamedListView*) listView() )->find( (ONamedListViewItem*) firstChild(), col, text, recurse );
610 else 607 else
611 return 0; 608 return 0;
612} 609}
613 610
diff --git a/libopie2/opieui/opopupmenu.cpp b/libopie2/opieui/opopupmenu.cpp
index ac73188..d5cc575 100644
--- a/libopie2/opieui/opopupmenu.cpp
+++ b/libopie2/opieui/opopupmenu.cpp
@@ -1,604 +1,597 @@
1/* This file is part of the KDE libraries 1/* This file is part of the KDE libraries
2 Copyright (C) 2000 Daniel M. Duley <mosfet@kde.org> 2 Copyright (C) 2000 Daniel M. Duley <mosfet@kde.org>
3 Copyright (C) 2002 Hamish Rodda <meddie@yoyo.its.monash.edu.au> 3 Copyright (C) 2002 Hamish Rodda <meddie@yoyo.its.monash.edu.au>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License version 2 as published by the Free Software Foundation. 7 License version 2 as published by the Free Software Foundation.
8 8
9 This library is distributed in the hope that it will be useful, 9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of 10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details. 12 Library General Public License for more details.
13 13
14 You should have received a copy of the GNU Library General Public License 14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to 15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 16 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. 17 Boston, MA 02111-1307, USA.
18*/ 18*/
19 19
20/* QT */ 20/* QT */
21 21
22#include <qapplication.h>
23#include <qcursor.h>
24#include <qpainter.h>
25#include <qdrawutil.h> 22#include <qdrawutil.h>
26#include <qtimer.h> 23#include <qtimer.h>
27#include <qfont.h>
28#include <qfontmetrics.h>
29#include <qregexp.h>
30#include <qstyle.h>
31 24
32/* OPIE */ 25/* OPIE */
33 26
34#include <opie2/opopupmenu.h> 27#include <opie2/opopupmenu.h>
35#include <opie2/oconfig.h> 28#include <opie2/oconfig.h>
36 29
37OPopupTitle::OPopupTitle(QWidget *parent, const char *name) 30OPopupTitle::OPopupTitle(QWidget *parent, const char *name)
38 : QWidget(parent, name) 31 : QWidget(parent, name)
39{ 32{
40 setMinimumSize(16, fontMetrics().height()+8); 33 setMinimumSize(16, fontMetrics().height()+8);
41} 34}
42 35
43OPopupTitle::OPopupTitle(OPixmapEffect::GradientType /* gradient */, 36OPopupTitle::OPopupTitle(OPixmapEffect::GradientType /* gradient */,
44 const QColor &/* color */, const QColor &/* textColor */, 37 const QColor &/* color */, const QColor &/* textColor */,
45 QWidget *parent, const char *name) 38 QWidget *parent, const char *name)
46 : QWidget(parent, name) 39 : QWidget(parent, name)
47{ 40{
48 setMinimumSize(16, fontMetrics().height()+8); 41 setMinimumSize(16, fontMetrics().height()+8);
49} 42}
50 43
51OPopupTitle::OPopupTitle(const OPixmap & /* background */, const QColor &/* color */, 44OPopupTitle::OPopupTitle(const OPixmap & /* background */, const QColor &/* color */,
52 const QColor &/* textColor */, QWidget *parent, 45 const QColor &/* textColor */, QWidget *parent,
53 const char *name) 46 const char *name)
54 : QWidget(parent, name) 47 : QWidget(parent, name)
55{ 48{
56 setMinimumSize(16, fontMetrics().height()+8); 49 setMinimumSize(16, fontMetrics().height()+8);
57} 50}
58 51
59void OPopupTitle::setTitle(const QString &text, const QPixmap *icon) 52void OPopupTitle::setTitle(const QString &text, const QPixmap *icon)
60{ 53{
61 titleStr = text; 54 titleStr = text;
62 if (icon) 55 if (icon)
63 miniicon = *icon; 56 miniicon = *icon;
64 else 57 else
65 miniicon.resize(0, 0); 58 miniicon.resize(0, 0);
66 59
67 int w = miniicon.width()+fontMetrics().width(titleStr); 60 int w = miniicon.width()+fontMetrics().width(titleStr);
68 int h = QMAX( fontMetrics().height(), miniicon.height() ); 61 int h = QMAX( fontMetrics().height(), miniicon.height() );
69 setMinimumSize( w+16, h+8 ); 62 setMinimumSize( w+16, h+8 );
70} 63}
71 64
72void OPopupTitle::setText( const QString &text ) 65void OPopupTitle::setText( const QString &text )
73{ 66{
74 titleStr = text; 67 titleStr = text;
75 int w = miniicon.width()+fontMetrics().width(titleStr); 68 int w = miniicon.width()+fontMetrics().width(titleStr);
76 int h = QMAX( fontMetrics().height(), miniicon.height() ); 69 int h = QMAX( fontMetrics().height(), miniicon.height() );
77 setMinimumSize( w+16, h+8 ); 70 setMinimumSize( w+16, h+8 );
78} 71}
79 72
80void OPopupTitle::setIcon( const QPixmap &pix ) 73void OPopupTitle::setIcon( const QPixmap &pix )
81{ 74{
82 miniicon = pix; 75 miniicon = pix;
83 int w = miniicon.width()+fontMetrics().width(titleStr); 76 int w = miniicon.width()+fontMetrics().width(titleStr);
84 int h = QMAX( fontMetrics().height(), miniicon.height() ); 77 int h = QMAX( fontMetrics().height(), miniicon.height() );
85 setMinimumSize( w+16, h+8 ); 78 setMinimumSize( w+16, h+8 );
86} 79}
87 80
88void OPopupTitle::paintEvent(QPaintEvent *) 81void OPopupTitle::paintEvent(QPaintEvent *)
89{ 82{
90 QRect r(rect()); 83 QRect r(rect());
91 QPainter p(this); 84 QPainter p(this);
92 #if QT_VERSION > 290 85 #if QT_VERSION > 290
93 qApp->style().drawPrimitive(QStyle::PE_HeaderSection, &p, r, palette().active()); 86 qApp->style().drawPrimitive(QStyle::PE_HeaderSection, &p, r, palette().active());
94 #else 87 #else
95 #warning OPopupMenu is not fully functional on Qt2 88 #warning OPopupMenu is not fully functional on Qt2
96 #endif 89 #endif
97 90
98 if (!miniicon.isNull()) 91 if (!miniicon.isNull())
99 p.drawPixmap(4, (r.height()-miniicon.height())/2, miniicon); 92 p.drawPixmap(4, (r.height()-miniicon.height())/2, miniicon);
100 93
101 if (!titleStr.isNull()) 94 if (!titleStr.isNull())
102 { 95 {
103 p.setPen(palette().active().text()); 96 p.setPen(palette().active().text());
104 QFont f = p.font(); 97 QFont f = p.font();
105 f.setBold(true); 98 f.setBold(true);
106 p.setFont(f); 99 p.setFont(f);
107 if(!miniicon.isNull()) 100 if(!miniicon.isNull())
108 { 101 {
109 p.drawText(miniicon.width()+8, 0, width()-(miniicon.width()+8), 102 p.drawText(miniicon.width()+8, 0, width()-(miniicon.width()+8),
110 height(), AlignLeft | AlignVCenter | SingleLine, 103 height(), AlignLeft | AlignVCenter | SingleLine,
111 titleStr); 104 titleStr);
112 } 105 }
113 else 106 else
114 { 107 {
115 p.drawText(0, 0, width(), height(), 108 p.drawText(0, 0, width(), height(),
116 AlignCenter | SingleLine, titleStr); 109 AlignCenter | SingleLine, titleStr);
117 } 110 }
118 } 111 }
119 112
120 p.setPen(palette().active().highlight()); 113 p.setPen(palette().active().highlight());
121 p.drawLine(0, 0, r.right(), 0); 114 p.drawLine(0, 0, r.right(), 0);
122} 115}
123 116
124QSize OPopupTitle::sizeHint() const 117QSize OPopupTitle::sizeHint() const
125{ 118{
126 return(minimumSize()); 119 return(minimumSize());
127} 120}
128 121
129class OPopupMenu::OPopupMenuPrivate 122class OPopupMenu::OPopupMenuPrivate
130{ 123{
131public: 124public:
132 OPopupMenuPrivate () 125 OPopupMenuPrivate ()
133 : noMatches(false) 126 : noMatches(false)
134 , shortcuts(false) 127 , shortcuts(false)
135 , autoExec(false) 128 , autoExec(false)
136 , lastHitIndex(-1) 129 , lastHitIndex(-1)
137 , m_ctxMenu(0) 130 , m_ctxMenu(0)
138 {} 131 {}
139 132
140 ~OPopupMenuPrivate () 133 ~OPopupMenuPrivate ()
141 { 134 {
142 delete m_ctxMenu; 135 delete m_ctxMenu;
143 } 136 }
144 137
145 QString m_lastTitle; 138 QString m_lastTitle;
146 139
147 // variables for keyboard navigation 140 // variables for keyboard navigation
148 QTimer clearTimer; 141 QTimer clearTimer;
149 142
150 bool noMatches : 1; 143 bool noMatches : 1;
151 bool shortcuts : 1; 144 bool shortcuts : 1;
152 bool autoExec : 1; 145 bool autoExec : 1;
153 146
154 QString keySeq; 147 QString keySeq;
155 QString originalText; 148 QString originalText;
156 149
157 int lastHitIndex; 150 int lastHitIndex;
158 151
159 // support for RMB menus on menus 152 // support for RMB menus on menus
160 QPopupMenu* m_ctxMenu; 153 QPopupMenu* m_ctxMenu;
161 static bool s_continueCtxMenuShow; 154 static bool s_continueCtxMenuShow;
162 static int s_highlightedItem; 155 static int s_highlightedItem;
163 static OPopupMenu* s_contextedMenu; 156 static OPopupMenu* s_contextedMenu;
164}; 157};
165 158
166int OPopupMenu::OPopupMenuPrivate::s_highlightedItem(-1); 159int OPopupMenu::OPopupMenuPrivate::s_highlightedItem(-1);
167OPopupMenu* OPopupMenu::OPopupMenuPrivate::s_contextedMenu(0); 160OPopupMenu* OPopupMenu::OPopupMenuPrivate::s_contextedMenu(0);
168bool OPopupMenu::OPopupMenuPrivate::s_continueCtxMenuShow(true); 161bool OPopupMenu::OPopupMenuPrivate::s_continueCtxMenuShow(true);
169 162
170OPopupMenu::OPopupMenu(QWidget *parent, const char *name) 163OPopupMenu::OPopupMenu(QWidget *parent, const char *name)
171 : QPopupMenu(parent, name) 164 : QPopupMenu(parent, name)
172{ 165{
173 d = new OPopupMenuPrivate; 166 d = new OPopupMenuPrivate;
174 resetKeyboardVars(); 167 resetKeyboardVars();
175 connect(&(d->clearTimer), SIGNAL(timeout()), SLOT(resetKeyboardVars())); 168 connect(&(d->clearTimer), SIGNAL(timeout()), SLOT(resetKeyboardVars()));
176} 169}
177 170
178OPopupMenu::~OPopupMenu() 171OPopupMenu::~OPopupMenu()
179{ 172{
180 if (OPopupMenuPrivate::s_contextedMenu == this) 173 if (OPopupMenuPrivate::s_contextedMenu == this)
181 { 174 {
182 OPopupMenuPrivate::s_contextedMenu = 0; 175 OPopupMenuPrivate::s_contextedMenu = 0;
183 OPopupMenuPrivate::s_highlightedItem = -1; 176 OPopupMenuPrivate::s_highlightedItem = -1;
184 } 177 }
185 178
186 delete d; 179 delete d;
187} 180}
188 181
189int OPopupMenu::insertTitle(const QString &text, int id, int index) 182int OPopupMenu::insertTitle(const QString &text, int id, int index)
190{ 183{
191 OPopupTitle *titleItem = new OPopupTitle(); 184 OPopupTitle *titleItem = new OPopupTitle();
192 titleItem->setTitle(text); 185 titleItem->setTitle(text);
193 int ret = insertItem(titleItem, id, index); 186 int ret = insertItem(titleItem, id, index);
194 setItemEnabled(id, false); 187 setItemEnabled(id, false);
195 return ret; 188 return ret;
196} 189}
197 190
198int OPopupMenu::insertTitle(const QPixmap &icon, const QString &text, int id, 191int OPopupMenu::insertTitle(const QPixmap &icon, const QString &text, int id,
199 int index) 192 int index)
200{ 193{
201 OPopupTitle *titleItem = new OPopupTitle(); 194 OPopupTitle *titleItem = new OPopupTitle();
202 titleItem->setTitle(text, &icon); 195 titleItem->setTitle(text, &icon);
203 int ret = insertItem(titleItem, id, index); 196 int ret = insertItem(titleItem, id, index);
204 setItemEnabled(id, false); 197 setItemEnabled(id, false);
205 return ret; 198 return ret;
206} 199}
207 200
208void OPopupMenu::changeTitle(int id, const QString &text) 201void OPopupMenu::changeTitle(int id, const QString &text)
209{ 202{
210 QMenuItem *item = findItem(id); 203 QMenuItem *item = findItem(id);
211 if(item){ 204 if(item){
212 if(item->widget()) 205 if(item->widget())
213 ((OPopupTitle *)item->widget())->setTitle(text); 206 ((OPopupTitle *)item->widget())->setTitle(text);
214#ifndef NDEBUG 207#ifndef NDEBUG
215 else 208 else
216 qWarning( "KPopupMenu: changeTitle() called with non-title id %d", id ); 209 qWarning( "KPopupMenu: changeTitle() called with non-title id %d", id );
217#endif 210#endif
218 } 211 }
219#ifndef NDEBUG 212#ifndef NDEBUG
220 else 213 else
221 qWarning( "KPopupMenu: changeTitle() called with invalid id %d", id ); 214 qWarning( "KPopupMenu: changeTitle() called with invalid id %d", id );
222#endif 215#endif
223} 216}
224 217
225void OPopupMenu::changeTitle(int id, const QPixmap &icon, const QString &text) 218void OPopupMenu::changeTitle(int id, const QPixmap &icon, const QString &text)
226{ 219{
227 QMenuItem *item = findItem(id); 220 QMenuItem *item = findItem(id);
228 if(item){ 221 if(item){
229 if(item->widget()) 222 if(item->widget())
230 ((OPopupTitle *)item->widget())->setTitle(text, &icon); 223 ((OPopupTitle *)item->widget())->setTitle(text, &icon);
231#ifndef NDEBUG 224#ifndef NDEBUG
232 else 225 else
233 qWarning( "KPopupMenu: changeTitle() called with non-title id %d", id ); 226 qWarning( "KPopupMenu: changeTitle() called with non-title id %d", id );
234#endif 227#endif
235 } 228 }
236#ifndef NDEBUG 229#ifndef NDEBUG
237 else 230 else
238 qWarning( "KPopupMenu: changeTitle() called with invalid id %d", id ); 231 qWarning( "KPopupMenu: changeTitle() called with invalid id %d", id );
239#endif 232#endif
240} 233}
241 234
242QString OPopupMenu::title(int id) const 235QString OPopupMenu::title(int id) const
243{ 236{
244 if(id == -1) // obsolete 237 if(id == -1) // obsolete
245 return(d->m_lastTitle); 238 return(d->m_lastTitle);
246 QMenuItem *item = findItem(id); 239 QMenuItem *item = findItem(id);
247 if(item){ 240 if(item){
248 if(item->widget()) 241 if(item->widget())
249 return(((OPopupTitle *)item->widget())->title()); 242 return(((OPopupTitle *)item->widget())->title());
250 else 243 else
251 qWarning("OPopupMenu: title() called with non-title id %d.", id); 244 qWarning("OPopupMenu: title() called with non-title id %d.", id);
252 } 245 }
253 else 246 else
254 qWarning("OPopupMenu: title() called with invalid id %d.", id); 247 qWarning("OPopupMenu: title() called with invalid id %d.", id);
255 return(QString::null); 248 return(QString::null);
256} 249}
257 250
258QPixmap OPopupMenu::titlePixmap(int id) const 251QPixmap OPopupMenu::titlePixmap(int id) const
259{ 252{
260 QMenuItem *item = findItem(id); 253 QMenuItem *item = findItem(id);
261 if(item){ 254 if(item){
262 if(item->widget()) 255 if(item->widget())
263 return(((OPopupTitle *)item->widget())->icon()); 256 return(((OPopupTitle *)item->widget())->icon());
264 else 257 else
265 qWarning("KPopupMenu: titlePixmap() called with non-title id %d.", id); 258 qWarning("KPopupMenu: titlePixmap() called with non-title id %d.", id);
266 } 259 }
267 else 260 else
268 qWarning("KPopupMenu: titlePixmap() called with invalid id %d.", id); 261 qWarning("KPopupMenu: titlePixmap() called with invalid id %d.", id);
269 QPixmap tmp; 262 QPixmap tmp;
270 return(tmp); 263 return(tmp);
271} 264}
272 265
273/** 266/**
274 * This is re-implemented for keyboard navigation. 267 * This is re-implemented for keyboard navigation.
275 */ 268 */
276void OPopupMenu::closeEvent(QCloseEvent*e) 269void OPopupMenu::closeEvent(QCloseEvent*e)
277{ 270{
278 if (d->shortcuts) 271 if (d->shortcuts)
279 resetKeyboardVars(); 272 resetKeyboardVars();
280 QPopupMenu::closeEvent(e); 273 QPopupMenu::closeEvent(e);
281} 274}
282 275
283void OPopupMenu::keyPressEvent(QKeyEvent* e) 276void OPopupMenu::keyPressEvent(QKeyEvent* e)
284{ 277{
285 if (!d->shortcuts) { 278 if (!d->shortcuts) {
286 // continue event processing by Qpopup 279 // continue event processing by Qpopup
287 //e->ignore(); 280 //e->ignore();
288 QPopupMenu::keyPressEvent(e); 281 QPopupMenu::keyPressEvent(e);
289 return; 282 return;
290 } 283 }
291 284
292 int i = 0; 285 int i = 0;
293 bool firstpass = true; 286 bool firstpass = true;
294 QString keyString = e->text(); 287 QString keyString = e->text();
295 288
296 // check for common commands dealt with by QPopup 289 // check for common commands dealt with by QPopup
297 int key = e->key(); 290 int key = e->key();
298 if (key == Key_Escape || key == Key_Return || key == Key_Enter 291 if (key == Key_Escape || key == Key_Return || key == Key_Enter
299 || key == Key_Up || key == Key_Down || key == Key_Left 292 || key == Key_Up || key == Key_Down || key == Key_Left
300 || key == Key_Right || key == Key_F1) { 293 || key == Key_Right || key == Key_F1) {
301 294
302 resetKeyboardVars(); 295 resetKeyboardVars();
303 // continue event processing by Qpopup 296 // continue event processing by Qpopup
304 //e->ignore(); 297 //e->ignore();
305 QPopupMenu::keyPressEvent(e); 298 QPopupMenu::keyPressEvent(e);
306 return; 299 return;
307 } 300 }
308 301
309 // check to see if the user wants to remove a key from the sequence (backspace) 302 // check to see if the user wants to remove a key from the sequence (backspace)
310 // or clear the sequence (delete) 303 // or clear the sequence (delete)
311 if (!d->keySeq.isNull()) { 304 if (!d->keySeq.isNull()) {
312 305
313 if (key == Key_Backspace) { 306 if (key == Key_Backspace) {
314 307
315 if (d->keySeq.length() == 1) { 308 if (d->keySeq.length() == 1) {
316 resetKeyboardVars(); 309 resetKeyboardVars();
317 return; 310 return;
318 } 311 }
319 312
320 // keep the last sequence in keyString 313 // keep the last sequence in keyString
321 keyString = d->keySeq.left(d->keySeq.length() - 1); 314 keyString = d->keySeq.left(d->keySeq.length() - 1);
322 315
323 // allow sequence matching to be tried again 316 // allow sequence matching to be tried again
324 resetKeyboardVars(); 317 resetKeyboardVars();
325 318
326 } else if (key == Key_Delete) { 319 } else if (key == Key_Delete) {
327 resetKeyboardVars(); 320 resetKeyboardVars();
328 321
329 // clear active item 322 // clear active item
330 setActiveItem(0); 323 setActiveItem(0);
331 return; 324 return;
332 325
333 } else if (d->noMatches) { 326 } else if (d->noMatches) {
334 // clear if there are no matches 327 // clear if there are no matches
335 resetKeyboardVars(); 328 resetKeyboardVars();
336 329
337 // clear active item 330 // clear active item
338 setActiveItem(0); 331 setActiveItem(0);
339 332
340 } else { 333 } else {
341 // the key sequence is not a null string 334 // the key sequence is not a null string
342 // therefore the lastHitIndex is valid 335 // therefore the lastHitIndex is valid
343 i = d->lastHitIndex; 336 i = d->lastHitIndex;
344 } 337 }
345 } else if (key == Key_Backspace && parentMenu) { 338 } else if (key == Key_Backspace && parentMenu) {
346 // backspace with no chars in the buffer... go back a menu. 339 // backspace with no chars in the buffer... go back a menu.
347 hide(); 340 hide();
348 resetKeyboardVars(); 341 resetKeyboardVars();
349 return; 342 return;
350 } 343 }
351 344
352 d->keySeq += keyString; 345 d->keySeq += keyString;
353 int seqLen = d->keySeq.length(); 346 int seqLen = d->keySeq.length();
354 347
355 for (; i < (int)count(); i++) { 348 for (; i < (int)count(); i++) {
356 // compare typed text with text of this entry 349 // compare typed text with text of this entry
357 int j = idAt(i); 350 int j = idAt(i);
358 351
359 // don't search disabled entries 352 // don't search disabled entries
360 if (!isItemEnabled(j)) 353 if (!isItemEnabled(j))
361 continue; 354 continue;
362 355
363 QString thisText; 356 QString thisText;
364 357
365 // retrieve the right text 358 // retrieve the right text
366 // (the last selected item one may have additional ampersands) 359 // (the last selected item one may have additional ampersands)
367 if (i == d->lastHitIndex) 360 if (i == d->lastHitIndex)
368 thisText = d->originalText; 361 thisText = d->originalText;
369 else 362 else
370 thisText = text(j); 363 thisText = text(j);
371 364
372 // if there is an accelerator present, remove it 365 // if there is an accelerator present, remove it
373 if ((int)accel(j) != 0) 366 if ((int)accel(j) != 0)
374 thisText = thisText.replace(QRegExp("&"), ""); 367 thisText = thisText.replace(QRegExp("&"), "");
375 368
376 // chop text to the search length 369 // chop text to the search length
377 thisText = thisText.left(seqLen); 370 thisText = thisText.left(seqLen);
378 371
379 // do the search 372 // do the search
380 if (thisText.find(d->keySeq, 0, false) == 0) { 373 if (thisText.find(d->keySeq, 0, false) == 0) {
381 374
382 if (firstpass) { 375 if (firstpass) {
383 // match 376 // match
384 setActiveItem(i); 377 setActiveItem(i);
385 378
386 // check to see if we're underlining a different item 379 // check to see if we're underlining a different item
387 if (d->lastHitIndex != i) 380 if (d->lastHitIndex != i)
388 // yes; revert the underlining 381 // yes; revert the underlining
389 changeItem(idAt(d->lastHitIndex), d->originalText); 382 changeItem(idAt(d->lastHitIndex), d->originalText);
390 383
391 // set the original text if it's a different item 384 // set the original text if it's a different item
392 if (d->lastHitIndex != i || d->lastHitIndex == -1) 385 if (d->lastHitIndex != i || d->lastHitIndex == -1)
393 d->originalText = text(j); 386 d->originalText = text(j);
394 387
395 // underline the currently selected item 388 // underline the currently selected item
396 changeItem(j, underlineText(d->originalText, d->keySeq.length())); 389 changeItem(j, underlineText(d->originalText, d->keySeq.length()));
397 390
398 // remeber what's going on 391 // remeber what's going on
399 d->lastHitIndex = i; 392 d->lastHitIndex = i;
400 393
401 // start/restart the clear timer 394 // start/restart the clear timer
402 d->clearTimer.start(5000, true); 395 d->clearTimer.start(5000, true);
403 396
404 // go around for another try, to see if we can execute 397 // go around for another try, to see if we can execute
405 firstpass = false; 398 firstpass = false;
406 } else { 399 } else {
407 // don't allow execution 400 // don't allow execution
408 return; 401 return;
409 } 402 }
410 } 403 }
411 404
412 // fall through to allow execution 405 // fall through to allow execution
413 } 406 }
414 407
415 if (!firstpass) { 408 if (!firstpass) {
416 if (d->autoExec) { 409 if (d->autoExec) {
417 // activate anything 410 // activate anything
418 activateItemAt(d->lastHitIndex); 411 activateItemAt(d->lastHitIndex);
419 resetKeyboardVars(); 412 resetKeyboardVars();
420 413
421 } else if (findItem(idAt(d->lastHitIndex)) && 414 } else if (findItem(idAt(d->lastHitIndex)) &&
422 findItem(idAt(d->lastHitIndex))->popup()) { 415 findItem(idAt(d->lastHitIndex))->popup()) {
423 // only activate sub-menus 416 // only activate sub-menus
424 activateItemAt(d->lastHitIndex); 417 activateItemAt(d->lastHitIndex);
425 resetKeyboardVars(); 418 resetKeyboardVars();
426 } 419 }
427 420
428 return; 421 return;
429 } 422 }
430 423
431 // no matches whatsoever, clean up 424 // no matches whatsoever, clean up
432 resetKeyboardVars(true); 425 resetKeyboardVars(true);
433 //e->ignore(); 426 //e->ignore();
434 QPopupMenu::keyPressEvent(e); 427 QPopupMenu::keyPressEvent(e);
435} 428}
436 429
437QString OPopupMenu::underlineText(const QString& text, uint length) 430QString OPopupMenu::underlineText(const QString& text, uint length)
438{ 431{
439 QString ret = text; 432 QString ret = text;
440 for (uint i = 0; i < length; i++) { 433 for (uint i = 0; i < length; i++) {
441 if (ret[2*i] != '&') 434 if (ret[2*i] != '&')
442 ret.insert(2*i, "&"); 435 ret.insert(2*i, "&");
443 } 436 }
444 return ret; 437 return ret;
445} 438}
446 439
447void OPopupMenu::resetKeyboardVars(bool noMatches /* = false */) 440void OPopupMenu::resetKeyboardVars(bool noMatches /* = false */)
448{ 441{
449 // Clean up keyboard variables 442 // Clean up keyboard variables
450 if (d->lastHitIndex != -1) { 443 if (d->lastHitIndex != -1) {
451 changeItem(idAt(d->lastHitIndex), d->originalText); 444 changeItem(idAt(d->lastHitIndex), d->originalText);
452 d->lastHitIndex = -1; 445 d->lastHitIndex = -1;
453 } 446 }
454 447
455 if (!noMatches) { 448 if (!noMatches) {
456 d->keySeq = QString::null; 449 d->keySeq = QString::null;
457 } 450 }
458 451
459 d->noMatches = noMatches; 452 d->noMatches = noMatches;
460} 453}
461 454
462void OPopupMenu::setKeyboardShortcutsEnabled(bool enable) 455void OPopupMenu::setKeyboardShortcutsEnabled(bool enable)
463{ 456{
464 d->shortcuts = enable; 457 d->shortcuts = enable;
465} 458}
466 459
467void OPopupMenu::setKeyboardShortcutsExecute(bool enable) 460void OPopupMenu::setKeyboardShortcutsExecute(bool enable)
468{ 461{
469 d->autoExec = enable; 462 d->autoExec = enable;
470} 463}
471/** 464/**
472 * End keyboard navigation. 465 * End keyboard navigation.
473 */ 466 */
474 467
475/** 468/**
476 * RMB menus on menus 469 * RMB menus on menus
477 */ 470 */
478QPopupMenu* OPopupMenu::contextMenu() 471QPopupMenu* OPopupMenu::contextMenu()
479{ 472{
480 if (!d->m_ctxMenu) 473 if (!d->m_ctxMenu)
481 { 474 {
482 d->m_ctxMenu = new QPopupMenu(this); 475 d->m_ctxMenu = new QPopupMenu(this);
483 installEventFilter(this); 476 installEventFilter(this);
484 connect(d->m_ctxMenu, SIGNAL(aboutToHide()), this, SLOT(ctxMenuHiding())); 477 connect(d->m_ctxMenu, SIGNAL(aboutToHide()), this, SLOT(ctxMenuHiding()));
485 } 478 }
486 479
487 return d->m_ctxMenu; 480 return d->m_ctxMenu;
488} 481}
489 482
490void OPopupMenu::cancelContextMenuShow() 483void OPopupMenu::cancelContextMenuShow()
491{ 484{
492 OPopupMenuPrivate::s_continueCtxMenuShow = false; 485 OPopupMenuPrivate::s_continueCtxMenuShow = false;
493} 486}
494 487
495int OPopupMenu::contextMenuFocusItem() 488int OPopupMenu::contextMenuFocusItem()
496{ 489{
497 return OPopupMenuPrivate::s_highlightedItem; 490 return OPopupMenuPrivate::s_highlightedItem;
498} 491}
499 492
500OPopupMenu* OPopupMenu::contextMenuFocus() 493OPopupMenu* OPopupMenu::contextMenuFocus()
501{ 494{
502 return OPopupMenuPrivate::s_contextedMenu; 495 return OPopupMenuPrivate::s_contextedMenu;
503} 496}
504 497
505void OPopupMenu::itemHighlighted(int /* whichItem */) 498void OPopupMenu::itemHighlighted(int /* whichItem */)
506{ 499{
507 if (!d->m_ctxMenu || !d->m_ctxMenu->isVisible()) 500 if (!d->m_ctxMenu || !d->m_ctxMenu->isVisible())
508 { 501 {
509 return; 502 return;
510 } 503 }
511 504
512 d->m_ctxMenu->hide(); 505 d->m_ctxMenu->hide();
513 showCtxMenu(mapFromGlobal(QCursor::pos())); 506 showCtxMenu(mapFromGlobal(QCursor::pos()));
514} 507}
515 508
516void OPopupMenu::showCtxMenu(QPoint pos) 509void OPopupMenu::showCtxMenu(QPoint pos)
517{ 510{
518 OPopupMenuPrivate::s_highlightedItem = idAt(pos); 511 OPopupMenuPrivate::s_highlightedItem = idAt(pos);
519 512
520 if (OPopupMenuPrivate::s_highlightedItem == -1) 513 if (OPopupMenuPrivate::s_highlightedItem == -1)
521 { 514 {
522 OPopupMenuPrivate::s_contextedMenu = 0; 515 OPopupMenuPrivate::s_contextedMenu = 0;
523 return; 516 return;
524 } 517 }
525 518
526 emit aboutToShowContextMenu(this, OPopupMenuPrivate::s_highlightedItem, d->m_ctxMenu); 519 emit aboutToShowContextMenu(this, OPopupMenuPrivate::s_highlightedItem, d->m_ctxMenu);
527 520
528 if (!OPopupMenuPrivate::s_continueCtxMenuShow) 521 if (!OPopupMenuPrivate::s_continueCtxMenuShow)
529 { 522 {
530 OPopupMenuPrivate::s_continueCtxMenuShow = true; 523 OPopupMenuPrivate::s_continueCtxMenuShow = true;
531 return; 524 return;
532 } 525 }
533 526
534 OPopupMenuPrivate::s_contextedMenu = this; 527 OPopupMenuPrivate::s_contextedMenu = this;
535 d->m_ctxMenu->popup(this->mapToGlobal(pos)); 528 d->m_ctxMenu->popup(this->mapToGlobal(pos));
536 connect(this, SIGNAL(highlighted(int)), this, SLOT(itemHighlighted(int))); 529 connect(this, SIGNAL(highlighted(int)), this, SLOT(itemHighlighted(int)));
537} 530}
538 531
539void OPopupMenu::ctxMenuHiding() 532void OPopupMenu::ctxMenuHiding()
540{ 533{
541 disconnect(this, SIGNAL(highlighted(int)), this, SLOT(itemHighlighted(int))); 534 disconnect(this, SIGNAL(highlighted(int)), this, SLOT(itemHighlighted(int)));
542 OPopupMenuPrivate::s_continueCtxMenuShow = true; 535 OPopupMenuPrivate::s_continueCtxMenuShow = true;
543} 536}
544 537
545bool OPopupMenu::eventFilter(QObject* obj, QEvent* event) 538bool OPopupMenu::eventFilter(QObject* obj, QEvent* event)
546{ 539{
547 if (d->m_ctxMenu && obj == this) 540 if (d->m_ctxMenu && obj == this)
548 { 541 {
549 if (event->type() == QEvent::MouseButtonRelease) 542 if (event->type() == QEvent::MouseButtonRelease)
550 { 543 {
551 if (d->m_ctxMenu->isVisible()) 544 if (d->m_ctxMenu->isVisible())
552 { 545 {
553 return true; 546 return true;
554 } 547 }
555 } 548 }
556 #if QT_VERSION > 290 549 #if QT_VERSION > 290
557 else if (event->type() == QEvent::ContextMenu) 550 else if (event->type() == QEvent::ContextMenu)
558 #else 551 #else
559 else if ( (event->type() == QEvent::MouseButtonPress) && 552 else if ( (event->type() == QEvent::MouseButtonPress) &&
560 ( (QMouseEvent*) event )->button() == QMouseEvent::RightButton ) 553 ( (QMouseEvent*) event )->button() == QMouseEvent::RightButton )
561 #endif 554 #endif
562 { 555 {
563 showCtxMenu(mapFromGlobal(QCursor::pos())); 556 showCtxMenu(mapFromGlobal(QCursor::pos()));
564 return true; 557 return true;
565 } 558 }
566 } 559 }
567 560
568 return QWidget::eventFilter(obj, event); 561 return QWidget::eventFilter(obj, event);
569} 562}
570 563
571void OPopupMenu::hideEvent(QHideEvent*) 564void OPopupMenu::hideEvent(QHideEvent*)
572{ 565{
573 if (d->m_ctxMenu) 566 if (d->m_ctxMenu)
574 { 567 {
575 d->m_ctxMenu->hide(); 568 d->m_ctxMenu->hide();
576 } 569 }
577} 570}
578/** 571/**
579 * end of RMB menus on menus support 572 * end of RMB menus on menus support
580 */ 573 */
581 574
582// Obsolete 575// Obsolete
583OPopupMenu::OPopupMenu(const QString& title, QWidget *parent, const char *name) 576OPopupMenu::OPopupMenu(const QString& title, QWidget *parent, const char *name)
584 : QPopupMenu(parent, name) 577 : QPopupMenu(parent, name)
585{ 578{
586 d = new OPopupMenuPrivate; 579 d = new OPopupMenuPrivate;
587 setTitle(title); 580 setTitle(title);
588} 581}
589 582
590// Obsolete 583// Obsolete
591void OPopupMenu::setTitle(const QString &title) 584void OPopupMenu::setTitle(const QString &title)
592{ 585{
593 OPopupTitle *titleItem = new OPopupTitle(); 586 OPopupTitle *titleItem = new OPopupTitle();
594 titleItem->setTitle(title); 587 titleItem->setTitle(title);
595 insertItem(titleItem); 588 insertItem(titleItem);
596 d->m_lastTitle = title; 589 d->m_lastTitle = title;
597} 590}
598 591
599void OPopupTitle::virtual_hook( int, void* ) 592void OPopupTitle::virtual_hook( int, void* )
600{ /*BASE::virtual_hook( id, data );*/ } 593{ /*BASE::virtual_hook( id, data );*/ }
601 594
602void OPopupMenu::virtual_hook( int, void* ) 595void OPopupMenu::virtual_hook( int, void* )
603{ /*BASE::virtual_hook( id, data );*/ } 596{ /*BASE::virtual_hook( id, data );*/ }
604 597
diff --git a/libopie2/opieui/oselector.cpp b/libopie2/opieui/oselector.cpp
index ec5af6b..23b3ce3 100644
--- a/libopie2/opieui/oselector.cpp
+++ b/libopie2/opieui/oselector.cpp
@@ -1,716 +1,715 @@
1/* This file is part of the KDE libraries 1/* This file is part of the KDE libraries
2 Copyright (C) 1997 Martin Jones (mjones@kde.org) 2 Copyright (C) 1997 Martin Jones (mjones@kde.org)
3 3
4 This library is free software; you can redistribute it and/or 4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public 5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either 6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version. 7 version 2 of the License, or (at your option) any later version.
8 8
9 This library is distributed in the hope that it will be useful, 9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of 10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details. 12 Library General Public License for more details.
13 13
14 You should have received a copy of the GNU Library General Public License 14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to 15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 16 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. 17 Boston, MA 02111-1307, USA.
18*/ 18*/
19 19
20/* QT */ 20/* QT */
21 21
22#include <qimage.h> 22#include <qimage.h>
23#include <qpainter.h>
24#include <qdrawutil.h> 23#include <qdrawutil.h>
25 24
26/* OPIE */ 25/* OPIE */
27 26
28#include <opie2/oimageeffect.h> 27#include <opie2/oimageeffect.h>
29#include <opie2/oselector.h> 28#include <opie2/oselector.h>
30 29
31#define STORE_W 8 30#define STORE_W 8
32#define STORE_W2 STORE_W * 2 31#define STORE_W2 STORE_W * 2
33 32
34//----------------------------------------------------------------------------- 33//-----------------------------------------------------------------------------
35/* 34/*
36 * 2D value selector. 35 * 2D value selector.
37 * The contents of the selector are drawn by derived class. 36 * The contents of the selector are drawn by derived class.
38 */ 37 */
39 38
40OXYSelector::OXYSelector( QWidget *parent, const char *name ) 39OXYSelector::OXYSelector( QWidget *parent, const char *name )
41 : QWidget( parent, name ) 40 : QWidget( parent, name )
42{ 41{
43 xPos = 0; 42 xPos = 0;
44 yPos = 0; 43 yPos = 0;
45 minX = 0; 44 minX = 0;
46 minY = 0; 45 minY = 0;
47 maxX = 100; 46 maxX = 100;
48 maxY = 100; 47 maxY = 100;
49 store.setOptimization( QPixmap::BestOptim ); 48 store.setOptimization( QPixmap::BestOptim );
50 store.resize( STORE_W2, STORE_W2 ); 49 store.resize( STORE_W2, STORE_W2 );
51} 50}
52 51
53 52
54OXYSelector::~OXYSelector() 53OXYSelector::~OXYSelector()
55{} 54{}
56 55
57 56
58void OXYSelector::setRange( int _minX, int _minY, int _maxX, int _maxY ) 57void OXYSelector::setRange( int _minX, int _minY, int _maxX, int _maxY )
59{ 58{
60 px = 2; 59 px = 2;
61 py = 2; 60 py = 2;
62 minX = _minX; 61 minX = _minX;
63 minY = _minY; 62 minY = _minY;
64 maxX = _maxX; 63 maxX = _maxX;
65 maxY = _maxY; 64 maxY = _maxY;
66} 65}
67 66
68void OXYSelector::setValues( int _xPos, int _yPos ) 67void OXYSelector::setValues( int _xPos, int _yPos )
69{ 68{
70 xPos = _xPos; 69 xPos = _xPos;
71 yPos = _yPos; 70 yPos = _yPos;
72 71
73 if ( xPos > maxX ) 72 if ( xPos > maxX )
74 xPos = maxX; 73 xPos = maxX;
75 else if ( xPos < minX ) 74 else if ( xPos < minX )
76 xPos = minX; 75 xPos = minX;
77 76
78 if ( yPos > maxY ) 77 if ( yPos > maxY )
79 yPos = maxY; 78 yPos = maxY;
80 else if ( yPos < minY ) 79 else if ( yPos < minY )
81 yPos = minY; 80 yPos = minY;
82 81
83 int xp = 2 + (width() - 4) * xPos / (maxX - minX); 82 int xp = 2 + (width() - 4) * xPos / (maxX - minX);
84 int yp = height() - 2 - (height() - 4) * yPos / (maxY - minY); 83 int yp = height() - 2 - (height() - 4) * yPos / (maxY - minY);
85 84
86 setPosition( xp, yp ); 85 setPosition( xp, yp );
87} 86}
88 87
89QRect OXYSelector::contentsRect() const 88QRect OXYSelector::contentsRect() const
90{ 89{
91 return QRect( 2, 2, width()-4, height()-4 ); 90 return QRect( 2, 2, width()-4, height()-4 );
92} 91}
93 92
94void OXYSelector::paintEvent( QPaintEvent *ev ) 93void OXYSelector::paintEvent( QPaintEvent *ev )
95{ 94{
96 QRect cursorRect( px - STORE_W, py - STORE_W, STORE_W2, STORE_W2); 95 QRect cursorRect( px - STORE_W, py - STORE_W, STORE_W2, STORE_W2);
97 QRect paintRect = ev->rect(); 96 QRect paintRect = ev->rect();
98 97
99 QPainter painter; 98 QPainter painter;
100 painter.begin( this ); 99 painter.begin( this );
101 100
102 QBrush brush; 101 QBrush brush;
103 qDrawShadePanel( &painter, 0, 0, width(), height(), colorGroup(), 102 qDrawShadePanel( &painter, 0, 0, width(), height(), colorGroup(),
104 TRUE, 2, &brush ); 103 TRUE, 2, &brush );
105 104
106 drawContents( &painter ); 105 drawContents( &painter );
107 if (paintRect.contains(cursorRect)) 106 if (paintRect.contains(cursorRect))
108 { 107 {
109 bitBlt( &store, 0, 0, this, px - STORE_W, py - STORE_W, 108 bitBlt( &store, 0, 0, this, px - STORE_W, py - STORE_W,
110 STORE_W2, STORE_W2, CopyROP ); 109 STORE_W2, STORE_W2, CopyROP );
111 drawCursor( &painter, px, py ); 110 drawCursor( &painter, px, py );
112 } 111 }
113 else if (paintRect.intersects(cursorRect)) 112 else if (paintRect.intersects(cursorRect))
114 { 113 {
115 repaint( cursorRect, false); 114 repaint( cursorRect, false);
116 } 115 }
117 116
118 painter.end(); 117 painter.end();
119} 118}
120 119
121void OXYSelector::mousePressEvent( QMouseEvent *e ) 120void OXYSelector::mousePressEvent( QMouseEvent *e )
122{ 121{
123 int xVal, yVal; 122 int xVal, yVal;
124 valuesFromPosition( e->pos().x() - 2, e->pos().y() - 2, xVal, yVal ); 123 valuesFromPosition( e->pos().x() - 2, e->pos().y() - 2, xVal, yVal );
125 setValues( xVal, yVal ); 124 setValues( xVal, yVal );
126 125
127 emit valueChanged( xPos, yPos ); 126 emit valueChanged( xPos, yPos );
128} 127}
129 128
130void OXYSelector::mouseMoveEvent( QMouseEvent *e ) 129void OXYSelector::mouseMoveEvent( QMouseEvent *e )
131{ 130{
132 int xVal, yVal; 131 int xVal, yVal;
133 valuesFromPosition( e->pos().x() - 2, e->pos().y() - 2, xVal, yVal ); 132 valuesFromPosition( e->pos().x() - 2, e->pos().y() - 2, xVal, yVal );
134 setValues( xVal, yVal ); 133 setValues( xVal, yVal );
135 134
136 emit valueChanged( xPos, yPos ); 135 emit valueChanged( xPos, yPos );
137} 136}
138 137
139void OXYSelector::wheelEvent( QWheelEvent *e ) 138void OXYSelector::wheelEvent( QWheelEvent *e )
140{ 139{
141 #if QT_VERSION > 290 140 #if QT_VERSION > 290
142 if ( e->orientation() == Qt::Horizontal ) 141 if ( e->orientation() == Qt::Horizontal )
143 setValues( xValue() + e->delta()/120, yValue() ); 142 setValues( xValue() + e->delta()/120, yValue() );
144 else 143 else
145 setValues( xValue(), yValue() + e->delta()/120 ); 144 setValues( xValue(), yValue() + e->delta()/120 );
146 145
147 emit valueChanged( xPos, yPos ); 146 emit valueChanged( xPos, yPos );
148 #endif 147 #endif
149} 148}
150 149
151void OXYSelector::valuesFromPosition( int x, int y, int &xVal, int &yVal ) const 150void OXYSelector::valuesFromPosition( int x, int y, int &xVal, int &yVal ) const
152{ 151{
153 xVal = ( (maxX-minX) * (x-2) ) / ( width()-4 ); 152 xVal = ( (maxX-minX) * (x-2) ) / ( width()-4 );
154 yVal = maxY - ( ( (maxY-minY) * (y-2) ) / ( height()-4 ) ); 153 yVal = maxY - ( ( (maxY-minY) * (y-2) ) / ( height()-4 ) );
155 154
156 if ( xVal > maxX ) 155 if ( xVal > maxX )
157 xVal = maxX; 156 xVal = maxX;
158 else if ( xVal < minX ) 157 else if ( xVal < minX )
159 xVal = minX; 158 xVal = minX;
160 159
161 if ( yVal > maxY ) 160 if ( yVal > maxY )
162 yVal = maxY; 161 yVal = maxY;
163 else if ( yVal < minY ) 162 else if ( yVal < minY )
164 yVal = minY; 163 yVal = minY;
165} 164}
166 165
167void OXYSelector::setPosition( int xp, int yp ) 166void OXYSelector::setPosition( int xp, int yp )
168{ 167{
169 if ( xp < 2 ) 168 if ( xp < 2 )
170 xp = 2; 169 xp = 2;
171 else if ( xp > width() - 2 ) 170 else if ( xp > width() - 2 )
172 xp = width() - 2; 171 xp = width() - 2;
173 172
174 if ( yp < 2 ) 173 if ( yp < 2 )
175 yp = 2; 174 yp = 2;
176 else if ( yp > height() - 2 ) 175 else if ( yp > height() - 2 )
177 yp = height() - 2; 176 yp = height() - 2;
178 177
179 QPainter painter; 178 QPainter painter;
180 painter.begin( this ); 179 painter.begin( this );
181 180
182 bitBlt( this, px - STORE_W, py - STORE_W, &store, 0, 0, 181 bitBlt( this, px - STORE_W, py - STORE_W, &store, 0, 0,
183 STORE_W2, STORE_W2, CopyROP ); 182 STORE_W2, STORE_W2, CopyROP );
184 bitBlt( &store, 0, 0, this, xp - STORE_W, yp - STORE_W, 183 bitBlt( &store, 0, 0, this, xp - STORE_W, yp - STORE_W,
185 STORE_W2, STORE_W2, CopyROP ); 184 STORE_W2, STORE_W2, CopyROP );
186 drawCursor( &painter, xp, yp ); 185 drawCursor( &painter, xp, yp );
187 px = xp; 186 px = xp;
188 py = yp; 187 py = yp;
189 188
190 painter.end(); 189 painter.end();
191} 190}
192 191
193void OXYSelector::drawContents( QPainter * ) 192void OXYSelector::drawContents( QPainter * )
194{} 193{}
195 194
196 195
197void OXYSelector::drawCursor( QPainter *p, int xp, int yp ) 196void OXYSelector::drawCursor( QPainter *p, int xp, int yp )
198{ 197{
199 p->setPen( QPen( white ) ); 198 p->setPen( QPen( white ) );
200 199
201 p->drawLine( xp - 6, yp - 6, xp - 2, yp - 2 ); 200 p->drawLine( xp - 6, yp - 6, xp - 2, yp - 2 );
202 p->drawLine( xp - 6, yp + 6, xp - 2, yp + 2 ); 201 p->drawLine( xp - 6, yp + 6, xp - 2, yp + 2 );
203 p->drawLine( xp + 6, yp - 6, xp + 2, yp - 2 ); 202 p->drawLine( xp + 6, yp - 6, xp + 2, yp - 2 );
204 p->drawLine( xp + 6, yp + 6, xp + 2, yp + 2 ); 203 p->drawLine( xp + 6, yp + 6, xp + 2, yp + 2 );
205} 204}
206 205
207//----------------------------------------------------------------------------- 206//-----------------------------------------------------------------------------
208/* 207/*
209 * 1D value selector with contents drawn by derived class. 208 * 1D value selector with contents drawn by derived class.
210 * See OColorDialog for example. 209 * See OColorDialog for example.
211 */ 210 */
212 211
213 212
214OSelector::OSelector( QWidget *parent, const char *name ) 213OSelector::OSelector( QWidget *parent, const char *name )
215 : QWidget( parent, name ), QRangeControl() 214 : QWidget( parent, name ), QRangeControl()
216{ 215{
217 _orientation = Horizontal; 216 _orientation = Horizontal;
218 _indent = TRUE; 217 _indent = TRUE;
219} 218}
220 219
221OSelector::OSelector( Orientation o, QWidget *parent, const char *name ) 220OSelector::OSelector( Orientation o, QWidget *parent, const char *name )
222 : QWidget( parent, name ), QRangeControl() 221 : QWidget( parent, name ), QRangeControl()
223{ 222{
224 _orientation = o; 223 _orientation = o;
225 _indent = TRUE; 224 _indent = TRUE;
226} 225}
227 226
228 227
229OSelector::~OSelector() 228OSelector::~OSelector()
230{} 229{}
231 230
232 231
233QRect OSelector::contentsRect() const 232QRect OSelector::contentsRect() const
234{ 233{
235 if ( orientation() == Vertical ) 234 if ( orientation() == Vertical )
236 return QRect( 2, 5, width()-9, height()-10 ); 235 return QRect( 2, 5, width()-9, height()-10 );
237 else 236 else
238 return QRect( 5, 2, width()-10, height()-9 ); 237 return QRect( 5, 2, width()-10, height()-9 );
239} 238}
240 239
241void OSelector::paintEvent( QPaintEvent * ) 240void OSelector::paintEvent( QPaintEvent * )
242{ 241{
243 QPainter painter; 242 QPainter painter;
244 243
245 painter.begin( this ); 244 painter.begin( this );
246 245
247 drawContents( &painter ); 246 drawContents( &painter );
248 247
249 QBrush brush; 248 QBrush brush;
250 249
251 if ( indent() ) 250 if ( indent() )
252 { 251 {
253 if ( orientation() == Vertical ) 252 if ( orientation() == Vertical )
254 qDrawShadePanel( &painter, 0, 3, width()-5, height()-6, 253 qDrawShadePanel( &painter, 0, 3, width()-5, height()-6,
255 colorGroup(), TRUE, 2, &brush ); 254 colorGroup(), TRUE, 2, &brush );
256 else 255 else
257 qDrawShadePanel( &painter, 3, 0, width()-6, height()-5, 256 qDrawShadePanel( &painter, 3, 0, width()-6, height()-5,
258 colorGroup(), TRUE, 2, &brush ); 257 colorGroup(), TRUE, 2, &brush );
259 } 258 }
260 259
261 QPoint pos = calcArrowPos( value() ); 260 QPoint pos = calcArrowPos( value() );
262 drawArrow( &painter, TRUE, pos ); 261 drawArrow( &painter, TRUE, pos );
263 262
264 painter.end(); 263 painter.end();
265} 264}
266 265
267void OSelector::mousePressEvent( QMouseEvent *e ) 266void OSelector::mousePressEvent( QMouseEvent *e )
268{ 267{
269 moveArrow( e->pos() ); 268 moveArrow( e->pos() );
270} 269}
271 270
272void OSelector::mouseMoveEvent( QMouseEvent *e ) 271void OSelector::mouseMoveEvent( QMouseEvent *e )
273{ 272{
274 moveArrow( e->pos() ); 273 moveArrow( e->pos() );
275} 274}
276 275
277void OSelector::wheelEvent( QWheelEvent *e ) 276void OSelector::wheelEvent( QWheelEvent *e )
278{ 277{
279 int val = value() + e->delta()/120; 278 int val = value() + e->delta()/120;
280 emit valueChanged( val ); 279 emit valueChanged( val );
281 setValue( val ); 280 setValue( val );
282} 281}
283 282
284void OSelector::valueChange() 283void OSelector::valueChange()
285{ 284{
286 QPainter painter; 285 QPainter painter;
287 QPoint pos; 286 QPoint pos;
288 287
289 painter.begin( this ); 288 painter.begin( this );
290 289
291 pos = calcArrowPos( prevValue() ); 290 pos = calcArrowPos( prevValue() );
292 drawArrow( &painter, FALSE, pos ); 291 drawArrow( &painter, FALSE, pos );
293 292
294 pos = calcArrowPos( value() ); 293 pos = calcArrowPos( value() );
295 drawArrow( &painter, TRUE, pos ); 294 drawArrow( &painter, TRUE, pos );
296 295
297 painter.end(); 296 painter.end();
298} 297}
299 298
300void OSelector::moveArrow( const QPoint &pos ) 299void OSelector::moveArrow( const QPoint &pos )
301{ 300{
302 int val; 301 int val;
303 302
304 if ( orientation() == Vertical ) 303 if ( orientation() == Vertical )
305 val = ( maxValue() - minValue() ) * (height()-pos.y()-3) 304 val = ( maxValue() - minValue() ) * (height()-pos.y()-3)
306 / (height()-10) + minValue(); 305 / (height()-10) + minValue();
307 else 306 else
308 val = ( maxValue() - minValue() ) * (width()-pos.x()-3) 307 val = ( maxValue() - minValue() ) * (width()-pos.x()-3)
309 / (width()-10) + minValue(); 308 / (width()-10) + minValue();
310 309
311 if ( val > maxValue() ) 310 if ( val > maxValue() )
312 val = maxValue(); 311 val = maxValue();
313 if ( val < minValue() ) 312 if ( val < minValue() )
314 val = minValue(); 313 val = minValue();
315 314
316 emit valueChanged( val ); 315 emit valueChanged( val );
317 setValue( val ); 316 setValue( val );
318} 317}
319 318
320QPoint OSelector::calcArrowPos( int val ) 319QPoint OSelector::calcArrowPos( int val )
321{ 320{
322 QPoint p; 321 QPoint p;
323 322
324 if ( orientation() == Vertical ) 323 if ( orientation() == Vertical )
325 { 324 {
326 p.setY( height() - ( (height()-10) * val 325 p.setY( height() - ( (height()-10) * val
327 / ( maxValue() - minValue() ) + 5 ) ); 326 / ( maxValue() - minValue() ) + 5 ) );
328 p.setX( width() - 5 ); 327 p.setX( width() - 5 );
329 } 328 }
330 else 329 else
331 { 330 {
332 p.setX( width() - ( (width()-10) * val 331 p.setX( width() - ( (width()-10) * val
333 / ( maxValue() - minValue() ) + 5 ) ); 332 / ( maxValue() - minValue() ) + 5 ) );
334 p.setY( height() - 5 ); 333 p.setY( height() - 5 );
335 } 334 }
336 335
337 return p; 336 return p;
338} 337}
339 338
340void OSelector::drawContents( QPainter * ) 339void OSelector::drawContents( QPainter * )
341{} 340{}
342 341
343void OSelector::drawArrow( QPainter *painter, bool show, const QPoint &pos ) 342void OSelector::drawArrow( QPainter *painter, bool show, const QPoint &pos )
344{ 343{
345 if ( show ) 344 if ( show )
346 { 345 {
347 QPointArray array(3); 346 QPointArray array(3);
348 347
349 painter->setPen( QPen() ); 348 painter->setPen( QPen() );
350 painter->setBrush( QBrush( colorGroup().buttonText() ) ); 349 painter->setBrush( QBrush( colorGroup().buttonText() ) );
351 if ( orientation() == Vertical ) 350 if ( orientation() == Vertical )
352 { 351 {
353 array.setPoint( 0, pos.x()+0, pos.y()+0 ); 352 array.setPoint( 0, pos.x()+0, pos.y()+0 );
354 array.setPoint( 1, pos.x()+5, pos.y()+5 ); 353 array.setPoint( 1, pos.x()+5, pos.y()+5 );
355 array.setPoint( 2, pos.x()+5, pos.y()-5 ); 354 array.setPoint( 2, pos.x()+5, pos.y()-5 );
356 } 355 }
357 else 356 else
358 { 357 {
359 array.setPoint( 0, pos.x()+0, pos.y()+0 ); 358 array.setPoint( 0, pos.x()+0, pos.y()+0 );
360 array.setPoint( 1, pos.x()+5, pos.y()+5 ); 359 array.setPoint( 1, pos.x()+5, pos.y()+5 );
361 array.setPoint( 2, pos.x()-5, pos.y()+5 ); 360 array.setPoint( 2, pos.x()-5, pos.y()+5 );
362 } 361 }
363 362
364 painter->drawPolygon( array ); 363 painter->drawPolygon( array );
365 } 364 }
366 else 365 else
367 { 366 {
368 if ( orientation() == Vertical ) 367 if ( orientation() == Vertical )
369 { 368 {
370 repaint(pos.x(), pos.y()-5, 6, 11, true); 369 repaint(pos.x(), pos.y()-5, 6, 11, true);
371 } 370 }
372 else 371 else
373 { 372 {
374 repaint(pos.x()-5, pos.y(), 11, 6, true); 373 repaint(pos.x()-5, pos.y(), 11, 6, true);
375 } 374 }
376 } 375 }
377} 376}
378 377
379//---------------------------------------------------------------------------- 378//----------------------------------------------------------------------------
380 379
381OGradientSelector::OGradientSelector( QWidget *parent, const char *name ) 380OGradientSelector::OGradientSelector( QWidget *parent, const char *name )
382 : OSelector( parent, name ) 381 : OSelector( parent, name )
383{ 382{
384 init(); 383 init();
385} 384}
386 385
387 386
388OGradientSelector::OGradientSelector( Orientation o, QWidget *parent, 387OGradientSelector::OGradientSelector( Orientation o, QWidget *parent,
389 const char *name ) 388 const char *name )
390 : OSelector( o, parent, name ) 389 : OSelector( o, parent, name )
391{ 390{
392 init(); 391 init();
393} 392}
394 393
395 394
396OGradientSelector::~OGradientSelector() 395OGradientSelector::~OGradientSelector()
397{} 396{}
398 397
399 398
400void OGradientSelector::init() 399void OGradientSelector::init()
401{ 400{
402 color1.setRgb( 0, 0, 0 ); 401 color1.setRgb( 0, 0, 0 );
403 color2.setRgb( 255, 255, 255 ); 402 color2.setRgb( 255, 255, 255 );
404 403
405 text1 = text2 = ""; 404 text1 = text2 = "";
406} 405}
407 406
408 407
409void OGradientSelector::drawContents( QPainter *painter ) 408void OGradientSelector::drawContents( QPainter *painter )
410{ 409{
411 QImage image( contentsRect().width(), contentsRect().height(), 32 ); 410 QImage image( contentsRect().width(), contentsRect().height(), 32 );
412 411
413 QColor col; 412 QColor col;
414 float scale; 413 float scale;
415 414
416 int redDiff = color2.red() - color1.red(); 415 int redDiff = color2.red() - color1.red();
417 int greenDiff = color2.green() - color1.green(); 416 int greenDiff = color2.green() - color1.green();
418 int blueDiff = color2.blue() - color1.blue(); 417 int blueDiff = color2.blue() - color1.blue();
419 418
420 if ( orientation() == Vertical ) 419 if ( orientation() == Vertical )
421 { 420 {
422 for ( int y = 0; y < image.height(); y++ ) 421 for ( int y = 0; y < image.height(); y++ )
423 { 422 {
424 scale = 1.0 * y / image.height(); 423 scale = 1.0 * y / image.height();
425 col.setRgb( color1.red() + int(redDiff*scale), 424 col.setRgb( color1.red() + int(redDiff*scale),
426 color1.green() + int(greenDiff*scale), 425 color1.green() + int(greenDiff*scale),
427 color1.blue() + int(blueDiff*scale) ); 426 color1.blue() + int(blueDiff*scale) );
428 427
429 unsigned int *p = (uint *) image.scanLine( y ); 428 unsigned int *p = (uint *) image.scanLine( y );
430 for ( int x = 0; x < image.width(); x++ ) 429 for ( int x = 0; x < image.width(); x++ )
431 *p++ = col.rgb(); 430 *p++ = col.rgb();
432 } 431 }
433 } 432 }
434 else 433 else
435 { 434 {
436 unsigned int *p = (uint *) image.scanLine( 0 ); 435 unsigned int *p = (uint *) image.scanLine( 0 );
437 436
438 for ( int x = 0; x < image.width(); x++ ) 437 for ( int x = 0; x < image.width(); x++ )
439 { 438 {
440 scale = 1.0 * x / image.width(); 439 scale = 1.0 * x / image.width();
441 col.setRgb( color1.red() + int(redDiff*scale), 440 col.setRgb( color1.red() + int(redDiff*scale),
442 color1.green() + int(greenDiff*scale), 441 color1.green() + int(greenDiff*scale),
443 color1.blue() + int(blueDiff*scale) ); 442 color1.blue() + int(blueDiff*scale) );
444 *p++ = col.rgb(); 443 *p++ = col.rgb();
445 } 444 }
446 445
447 for ( int y = 1; y < image.height(); y++ ) 446 for ( int y = 1; y < image.height(); y++ )
448 memcpy( image.scanLine( y ), image.scanLine( y - 1), 447 memcpy( image.scanLine( y ), image.scanLine( y - 1),
449 sizeof( unsigned int ) * image.width() ); 448 sizeof( unsigned int ) * image.width() );
450 } 449 }
451 450
452 QColor ditherPalette[8]; 451 QColor ditherPalette[8];
453 452
454 for ( int s = 0; s < 8; s++ ) 453 for ( int s = 0; s < 8; s++ )
455 ditherPalette[s].setRgb( color1.red() + redDiff * s / 8, 454 ditherPalette[s].setRgb( color1.red() + redDiff * s / 8,
456 color1.green() + greenDiff * s / 8, 455 color1.green() + greenDiff * s / 8,
457 color1.blue() + blueDiff * s / 8 ); 456 color1.blue() + blueDiff * s / 8 );
458 457
459 OImageEffect::dither( image, ditherPalette, 8 ); 458 OImageEffect::dither( image, ditherPalette, 8 );
460 459
461 QPixmap p; 460 QPixmap p;
462 p.convertFromImage( image ); 461 p.convertFromImage( image );
463 462
464 painter->drawPixmap( contentsRect().x(), contentsRect().y(), p ); 463 painter->drawPixmap( contentsRect().x(), contentsRect().y(), p );
465 464
466 if ( orientation() == Vertical ) 465 if ( orientation() == Vertical )
467 { 466 {
468 int yPos = contentsRect().top() + painter->fontMetrics().ascent() + 2; 467 int yPos = contentsRect().top() + painter->fontMetrics().ascent() + 2;
469 int xPos = contentsRect().left() + (contentsRect().width() - 468 int xPos = contentsRect().left() + (contentsRect().width() -
470 painter->fontMetrics().width( text2 )) / 2; 469 painter->fontMetrics().width( text2 )) / 2;
471 QPen pen( color2 ); 470 QPen pen( color2 );
472 painter->setPen( pen ); 471 painter->setPen( pen );
473 painter->drawText( xPos, yPos, text2 ); 472 painter->drawText( xPos, yPos, text2 );
474 473
475 yPos = contentsRect().bottom() - painter->fontMetrics().descent() - 2; 474 yPos = contentsRect().bottom() - painter->fontMetrics().descent() - 2;
476 xPos = contentsRect().left() + (contentsRect().width() - 475 xPos = contentsRect().left() + (contentsRect().width() -
477 painter->fontMetrics().width( text1 )) / 2; 476 painter->fontMetrics().width( text1 )) / 2;
478 pen.setColor( color1 ); 477 pen.setColor( color1 );
479 painter->setPen( pen ); 478 painter->setPen( pen );
480 painter->drawText( xPos, yPos, text1 ); 479 painter->drawText( xPos, yPos, text1 );
481 } 480 }
482 else 481 else
483 { 482 {
484 int yPos = contentsRect().bottom()-painter->fontMetrics().descent()-2; 483 int yPos = contentsRect().bottom()-painter->fontMetrics().descent()-2;
485 484
486 QPen pen( color2 ); 485 QPen pen( color2 );
487 painter->setPen( pen ); 486 painter->setPen( pen );
488 painter->drawText( contentsRect().left() + 2, yPos, text1 ); 487 painter->drawText( contentsRect().left() + 2, yPos, text1 );
489 488
490 pen.setColor( color1 ); 489 pen.setColor( color1 );
491 painter->setPen( pen ); 490 painter->setPen( pen );
492 painter->drawText( contentsRect().right() - 491 painter->drawText( contentsRect().right() -
493 painter->fontMetrics().width( text2 ) - 2, yPos, text2 ); 492 painter->fontMetrics().width( text2 ) - 2, yPos, text2 );
494 } 493 }
495} 494}
496 495
497//----------------------------------------------------------------------------- 496//-----------------------------------------------------------------------------
498 497
499static QColor *standardPalette = 0; 498static QColor *standardPalette = 0;
500 499
501#define STANDARD_PAL_SIZE 17 500#define STANDARD_PAL_SIZE 17
502 501
503OColor::OColor() 502OColor::OColor()
504: QColor() 503: QColor()
505{ 504{
506 r = 0; g = 0; b = 0; h = 0; s = 0; v = 0; 505 r = 0; g = 0; b = 0; h = 0; s = 0; v = 0;
507}; 506};
508 507
509OColor::OColor( const OColor &col) 508OColor::OColor( const OColor &col)
510: QColor( col ) 509: QColor( col )
511{ 510{
512 h = col.h; s = col.s; v = col.v; 511 h = col.h; s = col.s; v = col.v;
513 r = col.r; g = col.g; b = col.b; 512 r = col.r; g = col.g; b = col.b;
514}; 513};
515 514
516OColor::OColor( const QColor &col) 515OColor::OColor( const QColor &col)
517: QColor( col ) 516: QColor( col )
518{ 517{
519 QColor::rgb(&r, &g, &b); 518 QColor::rgb(&r, &g, &b);
520 QColor::hsv(&h, &s, &v); 519 QColor::hsv(&h, &s, &v);
521}; 520};
522 521
523bool OColor::operator==(const OColor& col) const 522bool OColor::operator==(const OColor& col) const
524{ 523{
525 return (h == col.h) && (s == col.s) && (v == col.v) && 524 return (h == col.h) && (s == col.s) && (v == col.v) &&
526 (r == col.r) && (g == col.g) && (b == col.b); 525 (r == col.r) && (g == col.g) && (b == col.b);
527} 526}
528 527
529OColor& OColor::operator=(const OColor& col) 528OColor& OColor::operator=(const OColor& col)
530{ 529{
531 *(QColor *)this = col; 530 *(QColor *)this = col;
532 h = col.h; s = col.s; v = col.v; 531 h = col.h; s = col.s; v = col.v;
533 r = col.r; g = col.g; b = col.b; 532 r = col.r; g = col.g; b = col.b;
534 return *this; 533 return *this;
535} 534}
536 535
537void 536void
538OColor::setHsv(int _h, int _s, int _v) 537OColor::setHsv(int _h, int _s, int _v)
539{ 538{
540 h = _h; s = _s; v = _v; 539 h = _h; s = _s; v = _v;
541 QColor::setHsv(h, s, v); 540 QColor::setHsv(h, s, v);
542 QColor::rgb(&r, &g, &b); 541 QColor::rgb(&r, &g, &b);
543}; 542};
544 543
545void 544void
546OColor::setRgb(int _r, int _g, int _b) 545OColor::setRgb(int _r, int _g, int _b)
547{ 546{
548 r = _r; g = _g; b = _b; 547 r = _r; g = _g; b = _b;
549 QColor::setRgb(r, g, b); 548 QColor::setRgb(r, g, b);
550 QColor::hsv(&h, &s, &v); 549 QColor::hsv(&h, &s, &v);
551} 550}
552 551
553void 552void
554OColor::rgb(int *_r, int *_g, int *_b) const 553OColor::rgb(int *_r, int *_g, int *_b) const
555{ 554{
556 *_r = r; *_g = g; *_b = b; 555 *_r = r; *_g = g; *_b = b;
557} 556}
558 557
559void 558void
560OColor::hsv(int *_h, int *_s, int *_v) const 559OColor::hsv(int *_h, int *_s, int *_v) const
561{ 560{
562 *_h = h; *_s = s; *_v = v; 561 *_h = h; *_s = s; *_v = v;
563} 562}
564 563
565static void createStandardPalette() 564static void createStandardPalette()
566{ 565{
567 if ( standardPalette ) 566 if ( standardPalette )
568 return; 567 return;
569 568
570 standardPalette = new QColor[STANDARD_PAL_SIZE]; 569 standardPalette = new QColor[STANDARD_PAL_SIZE];
571 570
572 int i = 0; 571 int i = 0;
573 572
574 standardPalette[i++] = Qt::red; 573 standardPalette[i++] = Qt::red;
575 standardPalette[i++] = Qt::green; 574 standardPalette[i++] = Qt::green;
576 standardPalette[i++] = Qt::blue; 575 standardPalette[i++] = Qt::blue;
577 standardPalette[i++] = Qt::cyan; 576 standardPalette[i++] = Qt::cyan;
578 standardPalette[i++] = Qt::magenta; 577 standardPalette[i++] = Qt::magenta;
579 standardPalette[i++] = Qt::yellow; 578 standardPalette[i++] = Qt::yellow;
580 standardPalette[i++] = Qt::darkRed; 579 standardPalette[i++] = Qt::darkRed;
581 standardPalette[i++] = Qt::darkGreen; 580 standardPalette[i++] = Qt::darkGreen;
582 standardPalette[i++] = Qt::darkBlue; 581 standardPalette[i++] = Qt::darkBlue;
583 standardPalette[i++] = Qt::darkCyan; 582 standardPalette[i++] = Qt::darkCyan;
584 standardPalette[i++] = Qt::darkMagenta; 583 standardPalette[i++] = Qt::darkMagenta;
585 standardPalette[i++] = Qt::darkYellow; 584 standardPalette[i++] = Qt::darkYellow;
586 standardPalette[i++] = Qt::white; 585 standardPalette[i++] = Qt::white;
587 standardPalette[i++] = Qt::lightGray; 586 standardPalette[i++] = Qt::lightGray;
588 standardPalette[i++] = Qt::gray; 587 standardPalette[i++] = Qt::gray;
589 standardPalette[i++] = Qt::darkGray; 588 standardPalette[i++] = Qt::darkGray;
590 standardPalette[i++] = Qt::black; 589 standardPalette[i++] = Qt::black;
591} 590}
592 591
593 592
594OHSSelector::OHSSelector( QWidget *parent, const char *name ) 593OHSSelector::OHSSelector( QWidget *parent, const char *name )
595 : OXYSelector( parent, name ) 594 : OXYSelector( parent, name )
596{ 595{
597 setRange( 0, 0, 359, 255 ); 596 setRange( 0, 0, 359, 255 );
598} 597}
599 598
600void OHSSelector::updateContents() 599void OHSSelector::updateContents()
601{ 600{
602 drawPalette(&pixmap); 601 drawPalette(&pixmap);
603} 602}
604 603
605void OHSSelector::resizeEvent( QResizeEvent * ) 604void OHSSelector::resizeEvent( QResizeEvent * )
606{ 605{
607 updateContents(); 606 updateContents();
608} 607}
609 608
610void OHSSelector::drawContents( QPainter *painter ) 609void OHSSelector::drawContents( QPainter *painter )
611{ 610{
612 painter->drawPixmap( contentsRect().x(), contentsRect().y(), pixmap ); 611 painter->drawPixmap( contentsRect().x(), contentsRect().y(), pixmap );
613} 612}
614 613
615void OHSSelector::drawPalette( QPixmap *pixmap ) 614void OHSSelector::drawPalette( QPixmap *pixmap )
616{ 615{
617 int xSize = contentsRect().width(), ySize = contentsRect().height(); 616 int xSize = contentsRect().width(), ySize = contentsRect().height();
618 QImage image( xSize, ySize, 32 ); 617 QImage image( xSize, ySize, 32 );
619 QColor col; 618 QColor col;
620 int h, s; 619 int h, s;
621 uint *p; 620 uint *p;
622 621
623 for ( s = ySize-1; s >= 0; s-- ) 622 for ( s = ySize-1; s >= 0; s-- )
624 { 623 {
625 p = (uint *) image.scanLine( ySize - s - 1 ); 624 p = (uint *) image.scanLine( ySize - s - 1 );
626 for( h = 0; h < xSize; h++ ) 625 for( h = 0; h < xSize; h++ )
627 { 626 {
628 col.setHsv( 359*h/(xSize-1), 255*s/(ySize-1), 192 ); 627 col.setHsv( 359*h/(xSize-1), 255*s/(ySize-1), 192 );
629 *p = col.rgb(); 628 *p = col.rgb();
630 p++; 629 p++;
631 } 630 }
632 } 631 }
633 632
634 if ( QColor::numBitPlanes() <= 8 ) 633 if ( QColor::numBitPlanes() <= 8 )
635 { 634 {
636 createStandardPalette(); 635 createStandardPalette();
637 OImageEffect::dither( image, standardPalette, STANDARD_PAL_SIZE ); 636 OImageEffect::dither( image, standardPalette, STANDARD_PAL_SIZE );
638 } 637 }
639 pixmap->convertFromImage( image ); 638 pixmap->convertFromImage( image );
640} 639}
641 640
642 641
643//----------------------------------------------------------------------------- 642//-----------------------------------------------------------------------------
644 643
645OValueSelector::OValueSelector( QWidget *parent, const char *name ) 644OValueSelector::OValueSelector( QWidget *parent, const char *name )
646 : OSelector( OSelector::Vertical, parent, name ), _hue(0), _sat(0) 645 : OSelector( OSelector::Vertical, parent, name ), _hue(0), _sat(0)
647{ 646{
648 setRange( 0, 255 ); 647 setRange( 0, 255 );
649 pixmap.setOptimization( QPixmap::BestOptim ); 648 pixmap.setOptimization( QPixmap::BestOptim );
650} 649}
651 650
652OValueSelector::OValueSelector(Orientation o, QWidget *parent, const char *name 651OValueSelector::OValueSelector(Orientation o, QWidget *parent, const char *name
653 ) 652 )
654 : OSelector( o, parent, name), _hue(0), _sat(0) 653 : OSelector( o, parent, name), _hue(0), _sat(0)
655{ 654{
656 setRange( 0, 255 ); 655 setRange( 0, 255 );
657 pixmap.setOptimization( QPixmap::BestOptim ); 656 pixmap.setOptimization( QPixmap::BestOptim );
658} 657}
659 658
660void OValueSelector::updateContents() 659void OValueSelector::updateContents()
661{ 660{
662 drawPalette(&pixmap); 661 drawPalette(&pixmap);
663} 662}
664 663
665void OValueSelector::resizeEvent( QResizeEvent * ) 664void OValueSelector::resizeEvent( QResizeEvent * )
666{ 665{
667 updateContents(); 666 updateContents();
668} 667}
669 668
670void OValueSelector::drawContents( QPainter *painter ) 669void OValueSelector::drawContents( QPainter *painter )
671{ 670{
672 painter->drawPixmap( contentsRect().x(), contentsRect().y(), pixmap ); 671 painter->drawPixmap( contentsRect().x(), contentsRect().y(), pixmap );
673} 672}
674 673
675void OValueSelector::drawPalette( QPixmap *pixmap ) 674void OValueSelector::drawPalette( QPixmap *pixmap )
676{ 675{
677 int xSize = contentsRect().width(), ySize = contentsRect().height(); 676 int xSize = contentsRect().width(), ySize = contentsRect().height();
678 QImage image( xSize, ySize, 32 ); 677 QImage image( xSize, ySize, 32 );
679 QColor col; 678 QColor col;
680 uint *p; 679 uint *p;
681 QRgb rgb; 680 QRgb rgb;
682 681
683 if ( orientation() == OSelector::Horizontal ) 682 if ( orientation() == OSelector::Horizontal )
684 { 683 {
685 for ( int v = 0; v < ySize; v++ ) 684 for ( int v = 0; v < ySize; v++ )
686 { 685 {
687 p = (uint *) image.scanLine( ySize - v - 1 ); 686 p = (uint *) image.scanLine( ySize - v - 1 );
688 687
689 for( int x = 0; x < xSize; x++ ) 688 for( int x = 0; x < xSize; x++ )
690 { 689 {
691 col.setHsv( _hue, _sat, 255*x/(xSize-1) ); 690 col.setHsv( _hue, _sat, 255*x/(xSize-1) );
692 rgb = col.rgb(); 691 rgb = col.rgb();
693 *p++ = rgb; 692 *p++ = rgb;
694 } 693 }
695 } 694 }
696 } 695 }
697 696
698 if( orientation() == OSelector::Vertical ) 697 if( orientation() == OSelector::Vertical )
699 { 698 {
700 for ( int v = 0; v < ySize; v++ ) 699 for ( int v = 0; v < ySize; v++ )
701 { 700 {
702 p = (uint *) image.scanLine( ySize - v - 1 ); 701 p = (uint *) image.scanLine( ySize - v - 1 );
703 col.setHsv( _hue, _sat, 255*v/(ySize-1) ); 702 col.setHsv( _hue, _sat, 255*v/(ySize-1) );
704 rgb = col.rgb(); 703 rgb = col.rgb();
705 for ( int i = 0; i < xSize; i++ ) 704 for ( int i = 0; i < xSize; i++ )
706 *p++ = rgb; 705 *p++ = rgb;
707 } 706 }
708 } 707 }
709 708
710 if ( QColor::numBitPlanes() <= 8 ) 709 if ( QColor::numBitPlanes() <= 8 )
711 { 710 {
712 createStandardPalette(); 711 createStandardPalette();
713 OImageEffect::dither( image, standardPalette, STANDARD_PAL_SIZE ); 712 OImageEffect::dither( image, standardPalette, STANDARD_PAL_SIZE );
714 } 713 }
715 pixmap->convertFromImage( image ); 714 pixmap->convertFromImage( image );
716} 715}
diff --git a/libopie2/opieui/oseparator.cpp b/libopie2/opieui/oseparator.cpp
index 98d42c7..b93c225 100644
--- a/libopie2/opieui/oseparator.cpp
+++ b/libopie2/opieui/oseparator.cpp
@@ -1,128 +1,127 @@
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@tm.informatik.uni-frankfurt.de> 3              Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
4 Copyright (C) 1997 Michael Roth <mroth@wirlweb.de> 4 Copyright (C) 1997 Michael Roth <mroth@wirlweb.de>
5 =. 5 =.
6 .=l. 6 .=l.
7           .>+-= 7           .>+-=
8 _;:,     .>    :=|. This program is free software; you can 8 _;:,     .>    :=|. This program is free software; you can
9.> <`_,   >  .   <= redistribute it and/or modify it under 9.> <`_,   >  .   <= redistribute it and/or modify it under
10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
11.="- .-=="i,     .._ License as published by the Free Software 11.="- .-=="i,     .._ License as published by the Free Software
12 - .   .-<_>     .<> Foundation; either version 2 of the License, 12 - .   .-<_>     .<> Foundation; either version 2 of the License,
13     ._= =}       : or (at your option) any later version. 13     ._= =}       : or (at your option) any later version.
14    .%`+i>       _;_. 14    .%`+i>       _;_.
15    .i_,=:_.      -<s. This program is distributed in the hope that 15    .i_,=:_.      -<s. This program is distributed in the hope that
16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
17    : ..    .:,     . . . without even the implied warranty of 17    : ..    .:,     . . . without even the implied warranty of
18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
20..}^=.=       =       ; Library General Public License for more 20..}^=.=       =       ; Library General Public License for more
21++=   -.     .`     .: details. 21++=   -.     .`     .: details.
22 :     =  ...= . :.=- 22 :     =  ...= . :.=-
23 -.   .:....=;==+<; You should have received a copy of the GNU 23 -.   .:....=;==+<; You should have received a copy of the GNU
24  -_. . .   )=.  = Library General Public License along with 24  -_. . .   )=.  = Library General Public License along with
25    --        :-=` this library; see the file COPYING.LIB. 25    --        :-=` this library; see the file COPYING.LIB.
26 If not, write to the Free Software Foundation, 26 If not, write to the Free Software Foundation,
27 Inc., 59 Temple Place - Suite 330, 27 Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. 28 Boston, MA 02111-1307, USA.
29 29
30*/ 30*/
31 31
32/* OPIE */ 32/* OPIE */
33 33
34#include <opie2/odebug.h> 34#include <opie2/odebug.h>
35#include <opie2/oseparator.h> 35#include <opie2/oseparator.h>
36 36
37/* QT */ 37/* QT */
38 38
39#include <qstyle.h>
40 39
41OSeparator::OSeparator(QWidget* parent, const char* name, WFlags f) 40OSeparator::OSeparator(QWidget* parent, const char* name, WFlags f)
42 : QFrame(parent, name, f) 41 : QFrame(parent, name, f)
43{ 42{
44 setLineWidth(1); 43 setLineWidth(1);
45 setMidLineWidth(0); 44 setMidLineWidth(0);
46 setOrientation( HLine ); 45 setOrientation( HLine );
47} 46}
48 47
49 48
50 49
51OSeparator::OSeparator(int orientation, QWidget* parent, const char* name, WFlags f) 50OSeparator::OSeparator(int orientation, QWidget* parent, const char* name, WFlags f)
52 : QFrame(parent, name, f) 51 : QFrame(parent, name, f)
53{ 52{
54 setLineWidth(1); 53 setLineWidth(1);
55 setMidLineWidth(0); 54 setMidLineWidth(0);
56 setOrientation( orientation ); 55 setOrientation( orientation );
57} 56}
58 57
59 58
60 59
61void OSeparator::setOrientation(int orientation) 60void OSeparator::setOrientation(int orientation)
62{ 61{
63 switch(orientation) 62 switch(orientation)
64 { 63 {
65 case Vertical: 64 case Vertical:
66 case VLine: 65 case VLine:
67 setFrameStyle( QFrame::VLine | QFrame::Sunken ); 66 setFrameStyle( QFrame::VLine | QFrame::Sunken );
68 setMinimumSize(2, 0); 67 setMinimumSize(2, 0);
69 break; 68 break;
70 69
71 default: 70 default:
72 owarn << "OSeparator::setOrientation(): invalid orientation, using default orientation HLine" << oendl; 71 owarn << "OSeparator::setOrientation(): invalid orientation, using default orientation HLine" << oendl;
73 72
74 case Horizontal: 73 case Horizontal:
75 case HLine: 74 case HLine:
76 setFrameStyle( QFrame::HLine | QFrame::Sunken ); 75 setFrameStyle( QFrame::HLine | QFrame::Sunken );
77 setMinimumSize(0, 2); 76 setMinimumSize(0, 2);
78 break; 77 break;
79 } 78 }
80} 79}
81 80
82 81
83 82
84int OSeparator::orientation() const 83int OSeparator::orientation() const
85{ 84{
86 if ( frameStyle() & VLine ) 85 if ( frameStyle() & VLine )
87 return VLine; 86 return VLine;
88 87
89 if ( frameStyle() & HLine ) 88 if ( frameStyle() & HLine )
90 return HLine; 89 return HLine;
91 90
92 return 0; 91 return 0;
93} 92}
94 93
95void OSeparator::drawFrame(QPainter *p) 94void OSeparator::drawFrame(QPainter *p)
96{ 95{
97 QPointp1, p2; 96 QPointp1, p2;
98 QRectr = frameRect(); 97 QRectr = frameRect();
99 const QColorGroup & g = colorGroup(); 98 const QColorGroup & g = colorGroup();
100 99
101 if ( frameStyle() & HLine ) { 100 if ( frameStyle() & HLine ) {
102 p1 = QPoint( r.x(), r.height()/2 ); 101 p1 = QPoint( r.x(), r.height()/2 );
103 p2 = QPoint( r.x()+r.width(), p1.y() ); 102 p2 = QPoint( r.x()+r.width(), p1.y() );
104 } 103 }
105 else { 104 else {
106 p1 = QPoint( r.x()+r.width()/2, 0 ); 105 p1 = QPoint( r.x()+r.width()/2, 0 );
107 p2 = QPoint( p1.x(), r.height() ); 106 p2 = QPoint( p1.x(), r.height() );
108 } 107 }
109 108
110#if QT_VERSION < 300 109#if QT_VERSION < 300
111 style().drawSeparator( p, p1.x(), p1.y(), p2.x(), p2.y(), g, true, 1, midLineWidth() ); 110 style().drawSeparator( p, p1.x(), p1.y(), p2.x(), p2.y(), g, true, 1, midLineWidth() );
112#else 111#else
113 QStyleOption opt( lineWidth(), midLineWidth() ); 112 QStyleOption opt( lineWidth(), midLineWidth() );
114 style().drawPrimitive( QStyle::PE_Separator, p, QRect( p1, p2 ), g, QStyle::Style_Sunken, opt ); 113 style().drawPrimitive( QStyle::PE_Separator, p, QRect( p1, p2 ), g, QStyle::Style_Sunken, opt );
115#endif 114#endif
116} 115}
117 116
118 117
119QSize OSeparator::sizeHint() const 118QSize OSeparator::sizeHint() const
120{ 119{
121 if ( frameStyle() & VLine ) 120 if ( frameStyle() & VLine )
122 return QSize(2, 0); 121 return QSize(2, 0);
123 122
124 if ( frameStyle() & HLine ) 123 if ( frameStyle() & HLine )
125 return QSize(0, 2); 124 return QSize(0, 2);
126 125
127 return QSize(-1, -1); 126 return QSize(-1, -1);
128} 127}
diff --git a/libopie2/opieui/otimepicker.cpp b/libopie2/opieui/otimepicker.cpp
index 9f9f2c2..d4712a4 100644
--- a/libopie2/opieui/otimepicker.cpp
+++ b/libopie2/opieui/otimepicker.cpp
@@ -1,295 +1,292 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) Stefan Eilers <eilers.stefan@epost.de> 3 Copyright (C) Stefan Eilers <eilers.stefan@epost.de>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 4 =. Copyright (C) The Opie Team <opie-devel@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/* QT */ 30/* QT */
31#include <qbuttongroup.h>
32#include <qlayout.h> 31#include <qlayout.h>
33#include <qlineedit.h> 32#include <qlineedit.h>
34#include <qstring.h>
35#include <qtoolbutton.h>
36 33
37/* OPIE */ 34/* OPIE */
38#include <opie2/otimepicker.h> 35#include <opie2/otimepicker.h>
39 36
40using namespace Opie; 37using namespace Opie;
41 38
42/** 39/**
43 * Constructs the widget 40 * Constructs the widget
44 * @param parent The parent of the OTimePicker 41 * @param parent The parent of the OTimePicker
45 * @param name The name of the object 42 * @param name The name of the object
46 * @param fl Window Flags 43 * @param fl Window Flags
47 */ 44 */
48OTimePicker::OTimePicker(QWidget* parent, const char* name, Qt::WFlags fl) 45OTimePicker::OTimePicker(QWidget* parent, const char* name, Qt::WFlags fl)
49 :QWidget(parent,name,fl) 46 :QWidget(parent,name,fl)
50{ 47{
51 QVBoxLayout *vbox=new QVBoxLayout(this); 48 QVBoxLayout *vbox=new QVBoxLayout(this);
52 49
53 OClickableLabel *r; 50 OClickableLabel *r;
54 QString s; 51 QString s;
55 52
56 // Hour Row 53 // Hour Row
57 QWidget *row=new QWidget(this); 54 QWidget *row=new QWidget(this);
58 QHBoxLayout *l=new QHBoxLayout(row); 55 QHBoxLayout *l=new QHBoxLayout(row);
59 vbox->addWidget(row); 56 vbox->addWidget(row);
60 57
61 for (int i=0; i<24; i++) 58 for (int i=0; i<24; i++)
62 { 59 {
63 r=new OClickableLabel(row); 60 r=new OClickableLabel(row);
64 hourLst.append(r); 61 hourLst.append(r);
65 s.sprintf("%.2d",i); 62 s.sprintf("%.2d",i);
66 r->setText(s); 63 r->setText(s);
67 r->setToggleButton(true); 64 r->setToggleButton(true);
68 r->setAlignment(AlignHCenter | AlignVCenter); 65 r->setAlignment(AlignHCenter | AlignVCenter);
69 l->addWidget(r); 66 l->addWidget(r);
70 connect(r, SIGNAL(toggled(bool)), 67 connect(r, SIGNAL(toggled(bool)),
71 this, SLOT(slotHour(bool))); 68 this, SLOT(slotHour(bool)));
72 69
73 if (i==11) 70 if (i==11)
74 { // Second row 71 { // Second row
75 row=new QWidget(this); 72 row=new QWidget(this);
76 l=new QHBoxLayout(row); 73 l=new QHBoxLayout(row);
77 vbox->addWidget(row); 74 vbox->addWidget(row);
78 } 75 }
79 } 76 }
80 77
81 // Minute Row 78 // Minute Row
82 row=new QWidget(this); 79 row=new QWidget(this);
83 l=new QHBoxLayout(row); 80 l=new QHBoxLayout(row);
84 vbox->addWidget(row); 81 vbox->addWidget(row);
85 82
86 for (int i=0; i<60; i+=5) 83 for (int i=0; i<60; i+=5)
87 { 84 {
88 r=new OClickableLabel(row); 85 r=new OClickableLabel(row);
89 minuteLst.append(r); 86 minuteLst.append(r);
90 s.sprintf("%.2d",i); 87 s.sprintf("%.2d",i);
91 r->setText(s); 88 r->setText(s);
92 r->setToggleButton(true); 89 r->setToggleButton(true);
93 r->setAlignment(AlignHCenter | AlignVCenter); 90 r->setAlignment(AlignHCenter | AlignVCenter);
94 l->addWidget(r); 91 l->addWidget(r);
95 connect(r, SIGNAL(toggled(bool)), 92 connect(r, SIGNAL(toggled(bool)),
96 this, SLOT(slotMinute(bool))); 93 this, SLOT(slotMinute(bool)));
97 } 94 }
98} 95}
99 96
100/** 97/**
101 * This method return the current time 98 * This method return the current time
102 * @return the time 99 * @return the time
103 */ 100 */
104QTime OTimePicker::time()const 101QTime OTimePicker::time()const
105{ 102{
106 return tm; 103 return tm;
107} 104}
108 105
109void OTimePicker::slotHour(bool b) 106void OTimePicker::slotHour(bool b)
110{ 107{
111 108
112 OClickableLabel *r = (OClickableLabel *) sender(); 109 OClickableLabel *r = (OClickableLabel *) sender();
113 110
114 if (b) 111 if (b)
115 { 112 {
116 QValueListIterator<OClickableLabel *> it; 113 QValueListIterator<OClickableLabel *> it;
117 for (it=hourLst.begin(); it!=hourLst.end(); it++) 114 for (it=hourLst.begin(); it!=hourLst.end(); it++)
118 { 115 {
119 if (*it != r) (*it)->setOn(false); 116 if (*it != r) (*it)->setOn(false);
120 else tm.setHMS((*it)->text().toInt(), tm.minute(), 0); 117 else tm.setHMS((*it)->text().toInt(), tm.minute(), 0);
121 } 118 }
122 emit timeChanged(tm); 119 emit timeChanged(tm);
123 } 120 }
124 else 121 else
125 { 122 {
126 r->setOn(true); 123 r->setOn(true);
127 } 124 }
128 125
129} 126}
130 127
131void OTimePicker::slotMinute(bool b) 128void OTimePicker::slotMinute(bool b)
132{ 129{
133 130
134 OClickableLabel *r = (OClickableLabel *) sender(); 131 OClickableLabel *r = (OClickableLabel *) sender();
135 132
136 if (b) 133 if (b)
137 { 134 {
138 QValueListIterator<OClickableLabel *> it; 135 QValueListIterator<OClickableLabel *> it;
139 for (it=minuteLst.begin(); it!=minuteLst.end(); it++) 136 for (it=minuteLst.begin(); it!=minuteLst.end(); it++)
140 { 137 {
141 if (*it != r) (*it)->setOn(false); 138 if (*it != r) (*it)->setOn(false);
142 else tm.setHMS(tm.hour(),(*it)->text().toInt(), 0); 139 else tm.setHMS(tm.hour(),(*it)->text().toInt(), 0);
143 } 140 }
144 emit timeChanged(tm); 141 emit timeChanged(tm);
145 } 142 }
146 else 143 else
147 { 144 {
148 r->setOn(true); 145 r->setOn(true);
149 } 146 }
150 147
151} 148}
152 149
153/** 150/**
154 * Method to set the time. No signal gets emitted during this method call 151 * Method to set the time. No signal gets emitted during this method call
155 * Minutes must be within 5 minutes step starting at 0 ( 0,5,10,15,20... ) 152 * Minutes must be within 5 minutes step starting at 0 ( 0,5,10,15,20... )
156 * @param t The time to be set 153 * @param t The time to be set
157 */ 154 */
158void OTimePicker::setTime( const QTime& t) 155void OTimePicker::setTime( const QTime& t)
159{ 156{
160 setTime( t.hour(), t.minute() ); 157 setTime( t.hour(), t.minute() );
161} 158}
162 159
163/** 160/**
164 * Method to set the time. No signal gets emitted during this method call 161 * Method to set the time. No signal gets emitted during this method call
165 * @param h The hour 162 * @param h The hour
166 * @param m The minute. Minutes need to set by 5 minute steps 163 * @param m The minute. Minutes need to set by 5 minute steps
167 */ 164 */
168void OTimePicker::setTime( int h, int m ) 165void OTimePicker::setTime( int h, int m )
169{ 166{
170 setHour(h); 167 setHour(h);
171 setMinute(m); 168 setMinute(m);
172} 169}
173 170
174/* 171/*
175 * FIXME round minutes to the 5 minute arrangement -zecke 172 * FIXME round minutes to the 5 minute arrangement -zecke
176 */ 173 */
177/** 174/**
178 * Method to set the minutes 175 * Method to set the minutes
179 * @param m minutes 176 * @param m minutes
180 */ 177 */
181void OTimePicker::setMinute(int m) 178void OTimePicker::setMinute(int m)
182{ 179{
183 180
184 QString minute; 181 QString minute;
185 minute.sprintf("%.2d",m); 182 minute.sprintf("%.2d",m);
186 183
187 QValueListIterator<OClickableLabel *> it; 184 QValueListIterator<OClickableLabel *> it;
188 for (it=minuteLst.begin(); it!=minuteLst.end(); it++) 185 for (it=minuteLst.begin(); it!=minuteLst.end(); it++)
189 { 186 {
190 if ((*it)->text() == minute) (*it)->setOn(true); 187 if ((*it)->text() == minute) (*it)->setOn(true);
191 else (*it)->setOn(false); 188 else (*it)->setOn(false);
192 } 189 }
193 190
194 tm.setHMS(tm.hour(),m,0); 191 tm.setHMS(tm.hour(),m,0);
195} 192}
196 193
197/** 194/**
198 * Method to set the hour 195 * Method to set the hour
199 */ 196 */
200void OTimePicker::setHour(int h) 197void OTimePicker::setHour(int h)
201{ 198{
202 199
203 QString hour; 200 QString hour;
204 hour.sprintf("%.2d",h); 201 hour.sprintf("%.2d",h);
205 202
206 QValueListIterator<OClickableLabel *> it; 203 QValueListIterator<OClickableLabel *> it;
207 for (it=hourLst.begin(); it!=hourLst.end(); it++) 204 for (it=hourLst.begin(); it!=hourLst.end(); it++)
208 { 205 {
209 if ((*it)->text() == hour) (*it)->setOn(true); 206 if ((*it)->text() == hour) (*it)->setOn(true);
210 else (*it)->setOn(false); 207 else (*it)->setOn(false);
211 } 208 }
212 tm.setHMS(h,tm.minute(),0); 209 tm.setHMS(h,tm.minute(),0);
213} 210}
214 211
215 212
216/** 213/**
217 * This is a modal Dialog. 214 * This is a modal Dialog.
218 * 215 *
219 * @param parent The parent widget 216 * @param parent The parent widget
220 * @param name The name of the object 217 * @param name The name of the object
221 * @param fl Possible window flags 218 * @param fl Possible window flags
222 */ 219 */
223OTimePickerDialog::OTimePickerDialog ( QWidget* parent, const char* name, WFlags fl ) 220OTimePickerDialog::OTimePickerDialog ( QWidget* parent, const char* name, WFlags fl )
224 : OTimePickerDialogBase (parent , name, true , fl) 221 : OTimePickerDialogBase (parent , name, true , fl)
225{ 222{
226 223
227 connect ( m_timePicker, SIGNAL( timeChanged( const QTime& ) ), 224 connect ( m_timePicker, SIGNAL( timeChanged( const QTime& ) ),
228 this, SLOT( setTime ( const QTime& ) ) ); 225 this, SLOT( setTime ( const QTime& ) ) );
229 connect ( minuteField, SIGNAL( textChanged ( const QString& ) ), 226 connect ( minuteField, SIGNAL( textChanged ( const QString& ) ),
230 this, SLOT ( setMinute ( const QString& ) ) ); 227 this, SLOT ( setMinute ( const QString& ) ) );
231 connect ( hourField, SIGNAL( textChanged ( const QString& ) ), 228 connect ( hourField, SIGNAL( textChanged ( const QString& ) ),
232 this, SLOT ( setHour ( const QString& ) ) ); 229 this, SLOT ( setHour ( const QString& ) ) );
233 230
234} 231}
235 232
236/** 233/**
237 * @return the time 234 * @return the time
238 */ 235 */
239QTime OTimePickerDialog::time()const 236QTime OTimePickerDialog::time()const
240{ 237{
241 return m_time; 238 return m_time;
242} 239}
243 240
244/** 241/**
245 * Set the time to time 242 * Set the time to time
246 * @param time The time to be set 243 * @param time The time to be set
247 */ 244 */
248void OTimePickerDialog::setTime( const QTime& time ) 245void OTimePickerDialog::setTime( const QTime& time )
249{ 246{
250 m_time = time; 247 m_time = time;
251 248
252 m_timePicker->setHour ( time.hour() ); 249 m_timePicker->setHour ( time.hour() );
253 m_timePicker->setMinute( time.minute() ); 250 m_timePicker->setMinute( time.minute() );
254 251
255 // Set Textfields 252 // Set Textfields
256 if ( time.hour() < 10 ) 253 if ( time.hour() < 10 )
257 hourField->setText( "0" + QString::number( time.hour() ) ); 254 hourField->setText( "0" + QString::number( time.hour() ) );
258 else 255 else
259 hourField->setText( QString::number( time.hour() ) ); 256 hourField->setText( QString::number( time.hour() ) );
260 257
261 if ( time.minute() < 10 ) 258 if ( time.minute() < 10 )
262 minuteField->setText( "0" + QString::number( time.minute() ) ); 259 minuteField->setText( "0" + QString::number( time.minute() ) );
263 else 260 else
264 minuteField->setText( QString::number( time.minute() ) ); 261 minuteField->setText( QString::number( time.minute() ) );
265 262
266} 263}
267 264
268/** 265/**
269 * This method takes the current minute and tries to set hour 266 * This method takes the current minute and tries to set hour
270 * to hour. This succeeds if the resulting date is valid 267 * to hour. This succeeds if the resulting date is valid
271 * @param hour The hour as a string 268 * @param hour The hour as a string
272 */ 269 */
273void OTimePickerDialog::setHour ( const QString& hour ) 270void OTimePickerDialog::setHour ( const QString& hour )
274{ 271{
275 if ( QTime::isValid ( hour.toInt(), m_time.minute() , 00 ) ) 272 if ( QTime::isValid ( hour.toInt(), m_time.minute() , 00 ) )
276 { 273 {
277 m_time.setHMS ( hour.toInt(), m_time.minute() , 00 ); 274 m_time.setHMS ( hour.toInt(), m_time.minute() , 00 );
278 setTime ( m_time ); 275 setTime ( m_time );
279 } 276 }
280 277
281} 278}
282 279
283/** 280/**
284 * Method to set a new minute. It tries to convert the string to int and 281 * Method to set a new minute. It tries to convert the string to int and
285 * if the resulting date is valid a new date is set. 282 * if the resulting date is valid a new date is set.
286 * @see setHour 283 * @see setHour
287 */ 284 */
288void OTimePickerDialog::setMinute ( const QString& minute ) 285void OTimePickerDialog::setMinute ( const QString& minute )
289{ 286{
290 if ( QTime::isValid ( m_time.hour(), minute.toInt(), 00 ) ) 287 if ( QTime::isValid ( m_time.hour(), minute.toInt(), 00 ) )
291 { 288 {
292 m_time.setHMS ( m_time.hour(), minute.toInt(), 00 ); 289 m_time.setHMS ( m_time.hour(), minute.toInt(), 00 );
293 setTime ( m_time ); 290 setTime ( m_time );
294 } 291 }
295} 292}
diff --git a/libopie2/opieui/oversatileview.cpp b/libopie2/opieui/oversatileview.cpp
index 65fe3d8..8839456 100644
--- a/libopie2/opieui/oversatileview.cpp
+++ b/libopie2/opieui/oversatileview.cpp
@@ -1,1180 +1,1169 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3 3
4 =. (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 4 =. (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
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 30
31/* OPIE */ 31/* OPIE */
32 32
33#include <opie2/odebug.h> 33#include <opie2/odebug.h>
34#include <opie2/oversatileview.h> 34#include <opie2/oversatileview.h>
35#include <opie2/oversatileviewitem.h> 35#include <opie2/oversatileviewitem.h>
36#include <opie2/olistview.h> 36#include <opie2/olistview.h>
37 37
38/* QT */ 38/* QT */
39 39
40#include <qaction.h> 40#include <qaction.h>
41#include <qbrush.h>
42#include <qfont.h>
43#include <qiconset.h>
44#include <qiconview.h>
45#include <qlistview.h>
46#include <qpalette.h>
47#include <qpoint.h>
48#include <qpopupmenu.h> 41#include <qpopupmenu.h>
49#include <qrect.h>
50#include <qsize.h>
51#include <qstring.h>
52#include <qwidgetstack.h>
53 42
54/* XPM */ 43/* XPM */
55static const char * view_icon_xpm[] = { 44static const char * view_icon_xpm[] = {
56"16 16 16 1", 45"16 16 16 1",
57 " c None", 46 " c None",
58 ".c #87BD88", 47 ".c #87BD88",
59 "+c #8BBE8B", 48 "+c #8BBE8B",
60 "@c #81BA81", 49 "@c #81BA81",
61 "#c #6DAF6D", 50 "#c #6DAF6D",
62 "$c #87BD87", 51 "$c #87BD87",
63 "%c #FCFDFC", 52 "%c #FCFDFC",
64 "&c #AED0AE", 53 "&c #AED0AE",
65 "*c #4E9C4C", 54 "*c #4E9C4C",
66 "=c #91BD91", 55 "=c #91BD91",
67 "-c #72B172", 56 "-c #72B172",
68 ";c #448643", 57 ";c #448643",
69 ">c #519F50", 58 ">c #519F50",
70 ",c #499247", 59 ",c #499247",
71 "'c #356A35", 60 "'c #356A35",
72 ")c #686868", 61 ")c #686868",
73" ", 62" ",
74" .+@# .+@# ", 63" .+@# .+@# ",
75" $%&* $%&* ", 64" $%&* $%&* ",
76" @=-; @=-; ", 65" @=-; @=-; ",
77" #>,' #>,' ", 66" #>,' #>,' ",
78" ", 67" ",
79" )))))) )))))) ", 68" )))))) )))))) ",
80" ", 69" ",
81" ", 70" ",
82" .+@# .+@# ", 71" .+@# .+@# ",
83" $%&* $%&* ", 72" $%&* $%&* ",
84" @=-; @=-; ", 73" @=-; @=-; ",
85" #>,' #>,' ", 74" #>,' #>,' ",
86" ", 75" ",
87" )))))) )))))) ", 76" )))))) )))))) ",
88" "}; 77" "};
89 78
90/* XPM */ 79/* XPM */
91static const char * view_tree_xpm[] = { 80static const char * view_tree_xpm[] = {
92"16 16 17 1", 81"16 16 17 1",
93 " c None", 82 " c None",
94 ".c #3A3A3A", 83 ".c #3A3A3A",
95 "+c #87BD88", 84 "+c #87BD88",
96 "@c #8BBE8B", 85 "@c #8BBE8B",
97 "#c #81BA81", 86 "#c #81BA81",
98 "$c #6DAF6D", 87 "$c #6DAF6D",
99 "%c #87BD87", 88 "%c #87BD87",
100 "&c #FCFDFC", 89 "&c #FCFDFC",
101 "*c #AED0AE", 90 "*c #AED0AE",
102 "=c #4E9C4C", 91 "=c #4E9C4C",
103 "-c #91BD91", 92 "-c #91BD91",
104 ";c #72B172", 93 ";c #72B172",
105 ">c #448643", 94 ">c #448643",
106 ",c #686868", 95 ",c #686868",
107 "'c #519F50", 96 "'c #519F50",
108 ")c #499247", 97 ")c #499247",
109 "!c #356A35", 98 "!c #356A35",
110" . ", 99" . ",
111" . ", 100" . ",
112" . +@#$ ", 101" . +@#$ ",
113" . %&*= ", 102" . %&*= ",
114" .. #-;> ,, ,,,", 103" .. #-;> ,, ,,,",
115" . $')! ", 104" . $')! ",
116" . ", 105" . ",
117" . ", 106" . ",
118" . ", 107" . ",
119" . +@#$ ", 108" . +@#$ ",
120" . %&*= ", 109" . %&*= ",
121" .. #-;> ,, ,,,", 110" .. #-;> ,, ,,,",
122" $')! ", 111" $')! ",
123" ", 112" ",
124" ", 113" ",
125" "}; 114" "};
126 115
127OVersatileView::OVersatileView( QWidget* parent, const char* name, int mode ) 116OVersatileView::OVersatileView( QWidget* parent, const char* name, int mode )
128 :QWidgetStack( parent, name ), 117 :QWidgetStack( parent, name ),
129 _viewmode( mode ), _warningpolicy( None ), 118 _viewmode( mode ), _warningpolicy( None ),
130 _treeleaf(), _treeopened(), _treeclosed(), 119 _treeleaf(), _treeopened(), _treeclosed(),
131 _iconleaf(), _iconopened(), _iconclosed() 120 _iconleaf(), _iconopened(), _iconclosed()
132{ 121{
133 // 122 //
134 // Create child widgets and set some reasonable default styles 123 // Create child widgets and set some reasonable default styles
135 // 124 //
136 125
137 _listview = new OListView( this, "oversatileview embedded listview" ); 126 _listview = new OListView( this, "oversatileview embedded listview" );
138 _iconview = new QIconView( this, "oversatileview embedded iconview" ); 127 _iconview = new QIconView( this, "oversatileview embedded iconview" );
139 128
140 _listview->setAllColumnsShowFocus( true ); 129 _listview->setAllColumnsShowFocus( true );
141 _listview->setRootIsDecorated( true ); 130 _listview->setRootIsDecorated( true );
142 _listview->setShowSortIndicator( true ); 131 _listview->setShowSortIndicator( true );
143 _iconview->setGridX( 90 ); 132 _iconview->setGridX( 90 );
144 _iconview->setGridY( 42 ); 133 _iconview->setGridY( 42 );
145 _iconview->setAutoArrange( true ); 134 _iconview->setAutoArrange( true );
146 135
147 #ifdef QWS // TODO: Let this depend on current geometry (rotation) 136 #ifdef QWS // TODO: Let this depend on current geometry (rotation)
148 _iconview->setArrangement( QIconView::TopToBottom ); 137 _iconview->setArrangement( QIconView::TopToBottom );
149 #else 138 #else
150 _iconview->setArrangement( QIconView::LeftToRight ); 139 _iconview->setArrangement( QIconView::LeftToRight );
151 #endif 140 #endif
152 141
153 _iconview->setResizeMode( QIconView::Adjust ); 142 _iconview->setResizeMode( QIconView::Adjust );
154 143
155 // qt-embedded: map stylus right on hold to right button press 144 // qt-embedded: map stylus right on hold to right button press
156 145
157 #ifdef QWS 146 #ifdef QWS
158 ( (QPEApplication*) qApp)->setStylusOperation( _iconview->viewport(), QPEApplication::RightOnHold ); 147 ( (QPEApplication*) qApp)->setStylusOperation( _iconview->viewport(), QPEApplication::RightOnHold );
159 ( (QPEApplication*) qApp)->setStylusOperation( _listview->viewport(), QPEApplication::RightOnHold ); 148 ( (QPEApplication*) qApp)->setStylusOperation( _listview->viewport(), QPEApplication::RightOnHold );
160 #endif 149 #endif
161 150
162 setViewMode( mode ); // TODO: Read last style from config 151 setViewMode( mode ); // TODO: Read last style from config
163 // setSynchronization( true ); // TODO: Implement this 152 // setSynchronization( true ); // TODO: Implement this
164 153
165 // create context menu allowing to switch between the views 154 // create context menu allowing to switch between the views
166 155
167 _contextmenu = new QPopupMenu( 0, "oversatileview contextmenu" ); 156 _contextmenu = new QPopupMenu( 0, "oversatileview contextmenu" );
168 _contextmenu->setCaption( "Style" ); 157 _contextmenu->setCaption( "Style" );
169 _contextmenu->setCheckable( true ); 158 _contextmenu->setCheckable( true );
170 QActionGroup* ag = new QActionGroup( _contextmenu, "style option group" ); 159 QActionGroup* ag = new QActionGroup( _contextmenu, "style option group" );
171 QAction* a1 = new QAction( "View Items in Icon Style", QIconSet( QPixmap( view_icon_xpm ) ), 160 QAction* a1 = new QAction( "View Items in Icon Style", QIconSet( QPixmap( view_icon_xpm ) ),
172 "View Icons", 0, ag, "viewicon action", true ); 161 "View Icons", 0, ag, "viewicon action", true );
173 QAction* a2 = new QAction( "View Items in Tree Style", QIconSet( QPixmap( view_tree_xpm ) ), 162 QAction* a2 = new QAction( "View Items in Tree Style", QIconSet( QPixmap( view_tree_xpm ) ),
174 "View Tree", 0, ag, "viewtree action", true ); 163 "View Tree", 0, ag, "viewtree action", true );
175 ag->addTo( _contextmenu ); 164 ag->addTo( _contextmenu );
176 if ( mode == Icons ) 165 if ( mode == Icons )
177 a1->setOn( true ); 166 a1->setOn( true );
178 else if ( mode == Tree ) 167 else if ( mode == Tree )
179 a2->setOn( true ); 168 a2->setOn( true );
180 connect( a1, SIGNAL( activated() ), this, SLOT( setIconViewMode() ) ); 169 connect( a1, SIGNAL( activated() ), this, SLOT( setIconViewMode() ) );
181 connect( a2, SIGNAL( activated() ), this, SLOT( setTreeViewMode() ) ); 170 connect( a2, SIGNAL( activated() ), this, SLOT( setTreeViewMode() ) );
182 171
183 #if (QT_VERSION >= 0x030000) 172 #if (QT_VERSION >= 0x030000)
184 connect( _listview, SIGNAL( contextMenuRequested( QListViewItem*, const QPoint&, int ) ), this, SLOT( contextMenuRequested( QListViewItem*, const QPoint&, int ) ) ); 173 connect( _listview, SIGNAL( contextMenuRequested( QListViewItem*, const QPoint&, int ) ), this, SLOT( contextMenuRequested( QListViewItem*, const QPoint&, int ) ) );
185 connect( _iconview, SIGNAL( contextMenuRequested( QIconViewItem*, const QPoint& ) ), this, SLOT( contextMenuRequested( QIconViewItem*, const QPoint& ) ) ); 174 connect( _iconview, SIGNAL( contextMenuRequested( QIconViewItem*, const QPoint& ) ), this, SLOT( contextMenuRequested( QIconViewItem*, const QPoint& ) ) );
186 #else 175 #else
187 connect( _listview, SIGNAL( rightButtonPressed( QListViewItem*, const QPoint&, int ) ), this, SLOT( contextMenuRequested( QListViewItem*, const QPoint&, int ) ) ); 176 connect( _listview, SIGNAL( rightButtonPressed( QListViewItem*, const QPoint&, int ) ), this, SLOT( contextMenuRequested( QListViewItem*, const QPoint&, int ) ) );
188 connect( _iconview, SIGNAL( rightButtonPressed( QIconViewItem*, const QPoint& ) ), this, SLOT( contextMenuRequested( QIconViewItem*, const QPoint& ) ) ); 177 connect( _iconview, SIGNAL( rightButtonPressed( QIconViewItem*, const QPoint& ) ), this, SLOT( contextMenuRequested( QIconViewItem*, const QPoint& ) ) );
189 #endif 178 #endif
190 179
191 // 180 //
192 // signal forwarders 181 // signal forwarders
193 // 182 //
194 // unfortunately we can't short-circuit all the QListView and QIconView signals 183 // unfortunately we can't short-circuit all the QListView and QIconView signals
195 // to OVersatileView signals, because the signal/slot mechanism doesn't allow 184 // to OVersatileView signals, because the signal/slot mechanism doesn't allow
196 // type-conversion :-( 185 // type-conversion :-(
197 186
198 // common signals for listview 187 // common signals for listview
199 188
200 connect( _listview, SIGNAL( selectionChanged() ), this, SIGNAL( selectionChanged() ) ); 189 connect( _listview, SIGNAL( selectionChanged() ), this, SIGNAL( selectionChanged() ) );
201 connect( _listview, SIGNAL( selectionChanged( QListViewItem * ) ), this, SLOT( selectionChanged( QListViewItem * ) ) ); 190 connect( _listview, SIGNAL( selectionChanged( QListViewItem * ) ), this, SLOT( selectionChanged( QListViewItem * ) ) );
202 connect( _listview, SIGNAL( currentChanged( QListViewItem * ) ), this, SLOT( currentChanged( QListViewItem * ) ) ); 191 connect( _listview, SIGNAL( currentChanged( QListViewItem * ) ), this, SLOT( currentChanged( QListViewItem * ) ) );
203 connect( _listview, SIGNAL( clicked( QListViewItem * ) ), this, SLOT( clicked( QListViewItem * ) ) ); 192 connect( _listview, SIGNAL( clicked( QListViewItem * ) ), this, SLOT( clicked( QListViewItem * ) ) );
204 connect( _listview, SIGNAL( pressed( QListViewItem * ) ), this, SLOT( pressed( QListViewItem * ) ) ); 193 connect( _listview, SIGNAL( pressed( QListViewItem * ) ), this, SLOT( pressed( QListViewItem * ) ) );
205 194
206 connect( _listview, SIGNAL( doubleClicked( QListViewItem * ) ), this, SLOT( doubleClicked( QListViewItem * ) ) ); 195 connect( _listview, SIGNAL( doubleClicked( QListViewItem * ) ), this, SLOT( doubleClicked( QListViewItem * ) ) );
207 connect( _listview, SIGNAL( returnPressed( QListViewItem * ) ), this, SLOT( returnPressed( QListViewItem * ) ) ); 196 connect( _listview, SIGNAL( returnPressed( QListViewItem * ) ), this, SLOT( returnPressed( QListViewItem * ) ) );
208 197
209 connect( _listview, SIGNAL( onItem( QListViewItem * ) ), this, SLOT( onItem( QListViewItem * ) ) ); 198 connect( _listview, SIGNAL( onItem( QListViewItem * ) ), this, SLOT( onItem( QListViewItem * ) ) );
210 connect( _listview, SIGNAL( onViewport() ), this, SIGNAL( onViewport() ) ); 199 connect( _listview, SIGNAL( onViewport() ), this, SIGNAL( onViewport() ) );
211 200
212 // common signals for iconview 201 // common signals for iconview
213 202
214 connect( _iconview, SIGNAL( selectionChanged() ), this, SIGNAL( selectionChanged() ) ); 203 connect( _iconview, SIGNAL( selectionChanged() ), this, SIGNAL( selectionChanged() ) );
215 connect( _iconview, SIGNAL( selectionChanged( QIconViewItem * ) ), this, SLOT( selectionChanged( QIconViewItem * ) ) ); 204 connect( _iconview, SIGNAL( selectionChanged( QIconViewItem * ) ), this, SLOT( selectionChanged( QIconViewItem * ) ) );
216 connect( _iconview, SIGNAL( currentChanged( QIconViewItem * ) ), this, SLOT( currentChanged( QIconViewItem * ) ) ); 205 connect( _iconview, SIGNAL( currentChanged( QIconViewItem * ) ), this, SLOT( currentChanged( QIconViewItem * ) ) );
217 connect( _iconview, SIGNAL( clicked( QIconViewItem * ) ), this, SLOT( clicked( QIconViewItem * ) ) ); 206 connect( _iconview, SIGNAL( clicked( QIconViewItem * ) ), this, SLOT( clicked( QIconViewItem * ) ) );
218 connect( _iconview, SIGNAL( pressed( QIconViewItem * ) ), this, SLOT( pressed( QIconViewItem * ) ) ); 207 connect( _iconview, SIGNAL( pressed( QIconViewItem * ) ), this, SLOT( pressed( QIconViewItem * ) ) );
219 208
220 connect( _iconview, SIGNAL( doubleClicked( QIconViewItem * ) ), this, SLOT( doubleClicked( QIconViewItem * ) ) ); 209 connect( _iconview, SIGNAL( doubleClicked( QIconViewItem * ) ), this, SLOT( doubleClicked( QIconViewItem * ) ) );
221 connect( _iconview, SIGNAL( returnPressed( QIconViewItem * ) ), this, SLOT( returnPressed( QIconViewItem * ) ) ); 210 connect( _iconview, SIGNAL( returnPressed( QIconViewItem * ) ), this, SLOT( returnPressed( QIconViewItem * ) ) );
222 211
223 connect( _iconview, SIGNAL( onItem( QIconViewItem * ) ), this, SLOT( onItem( QIconViewItem * ) ) ); 212 connect( _iconview, SIGNAL( onItem( QIconViewItem * ) ), this, SLOT( onItem( QIconViewItem * ) ) );
224 connect( _iconview, SIGNAL( onViewport() ), this, SIGNAL( onViewport() ) ); 213 connect( _iconview, SIGNAL( onViewport() ), this, SIGNAL( onViewport() ) );
225 214
226 // listview only signals 215 // listview only signals
227 216
228 connect( _listview, SIGNAL( expanded( QListViewItem * ) ), this, SLOT( expanded( QListViewItem * ) ) ); 217 connect( _listview, SIGNAL( expanded( QListViewItem * ) ), this, SLOT( expanded( QListViewItem * ) ) );
229 connect( _listview, SIGNAL( collapsed( QListViewItem * ) ), this, SLOT( collapsed( QListViewItem * ) ) ); 218 connect( _listview, SIGNAL( collapsed( QListViewItem * ) ), this, SLOT( collapsed( QListViewItem * ) ) );
230 219
231 // iconview only signals 220 // iconview only signals
232 221
233 connect( _iconview, SIGNAL( moved() ), this, SIGNAL( moved() ) ); 222 connect( _iconview, SIGNAL( moved() ), this, SIGNAL( moved() ) );
234} 223}
235 224
236OVersatileView::~OVersatileView() 225OVersatileView::~OVersatileView()
237{ 226{
238} 227}
239 228
240QPopupMenu* OVersatileView::contextMenu() const 229QPopupMenu* OVersatileView::contextMenu() const
241{ 230{
242 return _contextmenu; 231 return _contextmenu;
243} 232}
244 233
245void OVersatileView::contextMenuRequested( QListViewItem* item, const QPoint& pos, int col ) 234void OVersatileView::contextMenuRequested( QListViewItem* item, const QPoint& pos, int col )
246{ 235{
247 // can't use QObject::inherits here, because ListViewItems, beit Q, O or K, 236 // can't use QObject::inherits here, because ListViewItems, beit Q, O or K,
248 // do not inherit from QObject - assuming here the programmer is 237 // do not inherit from QObject - assuming here the programmer is
249 // disciplined enough to only add OVersatileViewItems to an OVersatileView 238 // disciplined enough to only add OVersatileViewItems to an OVersatileView
250 popupContextMenu( static_cast<OVersatileViewItem*>( item ), pos, col ); 239 popupContextMenu( static_cast<OVersatileViewItem*>( item ), pos, col );
251} 240}
252 241
253void OVersatileView::contextMenuRequested( QIconViewItem* item, const QPoint& pos ) 242void OVersatileView::contextMenuRequested( QIconViewItem* item, const QPoint& pos )
254{ 243{
255 // see above 244 // see above
256 popupContextMenu( static_cast<OVersatileViewItem*>( item ), pos, -1 ); 245 popupContextMenu( static_cast<OVersatileViewItem*>( item ), pos, -1 );
257} 246}
258 247
259void OVersatileView::popupContextMenu( OVersatileViewItem* item, const QPoint& pos, int col ) 248void OVersatileView::popupContextMenu( OVersatileViewItem* item, const QPoint& pos, int col )
260{ 249{
261 if ( !item ) 250 if ( !item )
262 _contextmenu->exec( pos ); 251 _contextmenu->exec( pos );
263 else 252 else
264 emit( contextMenuRequested( item, pos, col ) ); 253 emit( contextMenuRequested( item, pos, col ) );
265} 254}
266 255
267void OVersatileView::setSynchronization( bool sync ) 256void OVersatileView::setSynchronization( bool sync )
268{ 257{
269 _synchronization = sync; 258 _synchronization = sync;
270} 259}
271 260
272bool OVersatileView::synchronization() 261bool OVersatileView::synchronization()
273{ 262{
274 return _synchronization; 263 return _synchronization;
275} 264}
276 265
277void OVersatileView::setDefaultPixmaps( int mode, QPixmap& leaf, QPixmap& opened, QPixmap& closed ) 266void OVersatileView::setDefaultPixmaps( int mode, QPixmap& leaf, QPixmap& opened, QPixmap& closed )
278{ 267{
279 if ( mode == Tree ) 268 if ( mode == Tree )
280 { 269 {
281 _treeleaf = leaf; 270 _treeleaf = leaf;
282 _treeopened = opened; 271 _treeopened = opened;
283 _treeclosed = closed; 272 _treeclosed = closed;
284 } 273 }
285 else if ( mode == Icons ) 274 else if ( mode == Icons )
286 { 275 {
287 _iconleaf = leaf; 276 _iconleaf = leaf;
288 _iconopened = opened; 277 _iconopened = opened;
289 _iconclosed = closed; 278 _iconclosed = closed;
290 } 279 }
291 else 280 else
292 { 281 {
293 odebug << "OVersatileView::setDefaultPixmaps(): invalid mode" << oendl; 282 odebug << "OVersatileView::setDefaultPixmaps(): invalid mode" << oendl;
294 } 283 }
295} 284}
296 285
297QIconView* OVersatileView::iconView() const 286QIconView* OVersatileView::iconView() const
298{ 287{
299 return _iconview; 288 return _iconview;
300} 289}
301 290
302OListView* OVersatileView::listView() const 291OListView* OVersatileView::listView() const
303{ 292{
304 return _listview; 293 return _listview;
305} 294}
306 295
307void OVersatileView::setViewMode( int mode ) 296void OVersatileView::setViewMode( int mode )
308{ 297{
309 if ( mode == Tree ) 298 if ( mode == Tree )
310 { 299 {
311 _viewmode = mode; 300 _viewmode = mode;
312 raiseWidget( _listview ); 301 raiseWidget( _listview );
313 } 302 }
314 else if ( mode == Icons ) 303 else if ( mode == Icons )
315 { 304 {
316 _viewmode = mode; 305 _viewmode = mode;
317 raiseWidget( _iconview ); 306 raiseWidget( _iconview );
318 } 307 }
319 else 308 else
320 { 309 {
321 odebug << "OVersatileView::setViewMode(): invalid mode" << oendl; 310 odebug << "OVersatileView::setViewMode(): invalid mode" << oendl;
322 } 311 }
323} 312}
324 313
325void OVersatileView::setIconViewMode() 314void OVersatileView::setIconViewMode()
326{ 315{
327 setViewMode( Icons ); 316 setViewMode( Icons );
328} 317}
329 318
330void OVersatileView::setTreeViewMode() 319void OVersatileView::setTreeViewMode()
331{ 320{
332 setViewMode( Tree ); 321 setViewMode( Tree );
333} 322}
334 323
335bool OVersatileView::isValidViewMode( int mode ) const 324bool OVersatileView::isValidViewMode( int mode ) const
336{ 325{
337 switch ( _warningpolicy ) 326 switch ( _warningpolicy )
338 { 327 {
339 case OVersatileView::None: 328 case OVersatileView::None:
340 { 329 {
341 return true; 330 return true;
342 } 331 }
343 case OVersatileView::Warn: 332 case OVersatileView::Warn:
344 { 333 {
345 if ( _viewmode != mode ) 334 if ( _viewmode != mode )
346 { 335 {
347 odebug << "OVersatileView::isValidViewMode(): Requested operation not valid in current mode." << oendl; 336 odebug << "OVersatileView::isValidViewMode(): Requested operation not valid in current mode." << oendl;
348 return true; 337 return true;
349 } 338 }
350 } 339 }
351 case OVersatileView::WarnReturn: 340 case OVersatileView::WarnReturn:
352 { 341 {
353 if ( _viewmode != mode ) 342 if ( _viewmode != mode )
354 { 343 {
355 odebug << "OVersatileView::isValidViewMode(): Requested operation not valid in current mode." << oendl; 344 odebug << "OVersatileView::isValidViewMode(): Requested operation not valid in current mode." << oendl;
356 return false; 345 return false;
357 } 346 }
358 } 347 }
359 default: 348 default:
360 { 349 {
361 owarn << "OVersatileView::isValidViewMode(): Inconsistent object state!" << oendl; 350 owarn << "OVersatileView::isValidViewMode(): Inconsistent object state!" << oendl;
362 return true; 351 return true;
363 } 352 }
364 } 353 }
365} 354}
366void OVersatileView::setWarningPolicy( int policy ) const 355void OVersatileView::setWarningPolicy( int policy ) const
367{ 356{
368 _warningpolicy = policy; 357 _warningpolicy = policy;
369} 358}
370bool OVersatileView::warningPolicy() const 359bool OVersatileView::warningPolicy() const
371{ 360{
372 return _warningpolicy; 361 return _warningpolicy;
373} 362}
374//==============================================================================================// 363//==============================================================================================//
375// Stupid Signal forwarders... 364// Stupid Signal forwarders...
376// Folks, this is why I like python with its dynamic typing: 365// Folks, this is why I like python with its dynamic typing:
377// I can code the following dozens of lines C++ in four Python lines... 366// I can code the following dozens of lines C++ in four Python lines...
378//==============================================================================================// 367//==============================================================================================//
379 368
380void OVersatileView::selectionChanged( QListViewItem * item ) 369void OVersatileView::selectionChanged( QListViewItem * item )
381{ 370{
382 emit( selectionChanged( static_cast<OVersatileViewItem*>( item ) ) ); 371 emit( selectionChanged( static_cast<OVersatileViewItem*>( item ) ) );
383} 372}
384 373
385void OVersatileView::selectionChanged( QIconViewItem * item ) 374void OVersatileView::selectionChanged( QIconViewItem * item )
386{ 375{
387 emit( selectionChanged( static_cast<OVersatileViewItem*>( item ) ) ); 376 emit( selectionChanged( static_cast<OVersatileViewItem*>( item ) ) );
388} 377}
389 378
390void OVersatileView::currentChanged( QListViewItem * item ) 379void OVersatileView::currentChanged( QListViewItem * item )
391{ 380{
392 emit( currentChanged( static_cast<OVersatileViewItem*>( item ) ) ); 381 emit( currentChanged( static_cast<OVersatileViewItem*>( item ) ) );
393} 382}
394 383
395void OVersatileView::currentChanged( QIconViewItem * item ) 384void OVersatileView::currentChanged( QIconViewItem * item )
396{ 385{
397 emit( currentChanged( static_cast<OVersatileViewItem*>( item ) ) ); 386 emit( currentChanged( static_cast<OVersatileViewItem*>( item ) ) );
398} 387}
399 388
400void OVersatileView::clicked( QListViewItem * item ) 389void OVersatileView::clicked( QListViewItem * item )
401{ 390{
402 emit( clicked( static_cast<OVersatileViewItem*>( item ) ) ); 391 emit( clicked( static_cast<OVersatileViewItem*>( item ) ) );
403} 392}
404 393
405void OVersatileView::clicked( QIconViewItem * item ) 394void OVersatileView::clicked( QIconViewItem * item )
406{ 395{
407 emit( clicked( static_cast<OVersatileViewItem*>( item ) ) ); 396 emit( clicked( static_cast<OVersatileViewItem*>( item ) ) );
408} 397}
409 398
410void OVersatileView::pressed( QListViewItem * item ) 399void OVersatileView::pressed( QListViewItem * item )
411{ 400{
412 emit( pressed( static_cast<OVersatileViewItem*>( item ) ) ); 401 emit( pressed( static_cast<OVersatileViewItem*>( item ) ) );
413} 402}
414 403
415void OVersatileView::pressed( QIconViewItem * item ) 404void OVersatileView::pressed( QIconViewItem * item )
416{ 405{
417 emit( pressed( static_cast<OVersatileViewItem*>( item ) ) ); 406 emit( pressed( static_cast<OVersatileViewItem*>( item ) ) );
418} 407}
419 408
420void OVersatileView::doubleClicked( QListViewItem * item ) 409void OVersatileView::doubleClicked( QListViewItem * item )
421{ 410{
422 emit( doubleClicked( static_cast<OVersatileViewItem*>( item ) ) ); 411 emit( doubleClicked( static_cast<OVersatileViewItem*>( item ) ) );
423} 412}
424 413
425void OVersatileView::doubleClicked( QIconViewItem * item ) 414void OVersatileView::doubleClicked( QIconViewItem * item )
426{ 415{
427 emit( doubleClicked( static_cast<OVersatileViewItem*>( item ) ) ); 416 emit( doubleClicked( static_cast<OVersatileViewItem*>( item ) ) );
428} 417}
429 418
430void OVersatileView::returnPressed( QListViewItem * item ) 419void OVersatileView::returnPressed( QListViewItem * item )
431{ 420{
432 emit( returnPressed( static_cast<OVersatileViewItem*>( item ) ) ); 421 emit( returnPressed( static_cast<OVersatileViewItem*>( item ) ) );
433} 422}
434 423
435void OVersatileView::returnPressed( QIconViewItem * item ) 424void OVersatileView::returnPressed( QIconViewItem * item )
436{ 425{
437 emit( returnPressed( static_cast<OVersatileViewItem*>( item ) ) ); 426 emit( returnPressed( static_cast<OVersatileViewItem*>( item ) ) );
438} 427}
439 428
440void OVersatileView::onItem( QListViewItem * item ) 429void OVersatileView::onItem( QListViewItem * item )
441{ 430{
442 emit( onItem( static_cast<OVersatileViewItem*>( item ) ) ); 431 emit( onItem( static_cast<OVersatileViewItem*>( item ) ) );
443} 432}
444 433
445void OVersatileView::onItem( QIconViewItem * item ) 434void OVersatileView::onItem( QIconViewItem * item )
446{ 435{
447 emit( onItem( static_cast<OVersatileViewItem*>( item ) ) ); 436 emit( onItem( static_cast<OVersatileViewItem*>( item ) ) );
448} 437}
449 438
450void OVersatileView::expanded( QListViewItem *item ) // QListView 439void OVersatileView::expanded( QListViewItem *item ) // QListView
451{ 440{
452 //odebug << "OVersatileView::expanded(): opening tree..." << oendl; 441 //odebug << "OVersatileView::expanded(): opening tree..." << oendl;
453 if ( !_treeopened.isNull() ) 442 if ( !_treeopened.isNull() )
454 item->setPixmap( 0, _treeopened ); 443 item->setPixmap( 0, _treeopened );
455 emit( expanded( static_cast<OVersatileViewItem*>( item ) ) ); 444 emit( expanded( static_cast<OVersatileViewItem*>( item ) ) );
456} 445}
457void OVersatileView::collapsed( QListViewItem *item ) // QListView 446void OVersatileView::collapsed( QListViewItem *item ) // QListView
458{ 447{
459 if ( !_treeclosed.isNull() ) 448 if ( !_treeclosed.isNull() )
460 item->setPixmap( 0, _treeclosed ); 449 item->setPixmap( 0, _treeclosed );
461 emit( collapsed( static_cast<OVersatileViewItem*>( item ) ) ); 450 emit( collapsed( static_cast<OVersatileViewItem*>( item ) ) );
462} 451}
463 452
464//=============================================================================================// 453//=============================================================================================//
465// OVersatileView Case I - API only existing in QListView or QIconView but not in both! 454// OVersatileView Case I - API only existing in QListView or QIconView but not in both!
466//==============================================================================================// 455//==============================================================================================//
467 456
468int OVersatileView::treeStepSize() const // QListView 457int OVersatileView::treeStepSize() const // QListView
469{ 458{
470 if ( !isValidViewMode( Tree ) ) 459 if ( !isValidViewMode( Tree ) )
471 { 460 {
472 return -1; 461 return -1;
473 } 462 }
474 return _listview->treeStepSize(); 463 return _listview->treeStepSize();
475} 464}
476 void OVersatileView::setTreeStepSize( int size ) // QListView 465 void OVersatileView::setTreeStepSize( int size ) // QListView
477{ 466{
478 if ( !isValidViewMode( Tree ) ) 467 if ( !isValidViewMode( Tree ) )
479 { 468 {
480 return; 469 return;
481 } 470 }
482 _listview->setTreeStepSize( size ); 471 _listview->setTreeStepSize( size );
483} 472}
484 473
485QHeader * OVersatileView::header() const // QListView 474QHeader * OVersatileView::header() const // QListView
486{ 475{
487 if ( !isValidViewMode( Tree ) ) 476 if ( !isValidViewMode( Tree ) )
488 { 477 {
489 return 0; 478 return 0;
490 } 479 }
491 return _listview->header(); 480 return _listview->header();
492} 481}
493 482
494 int OVersatileView::addColumn( const QString &label, int size ) // QListView 483 int OVersatileView::addColumn( const QString &label, int size ) // QListView
495{ 484{
496 if ( !isValidViewMode( Tree ) ) 485 if ( !isValidViewMode( Tree ) )
497 { 486 {
498 return -1; 487 return -1;
499 } 488 }
500 return _listview->addColumn( label, size ); 489 return _listview->addColumn( label, size );
501} 490}
502 491
503 int OVersatileView::addColumn( const QIconSet& iconset, const QString &label, int size ) // QListView 492 int OVersatileView::addColumn( const QIconSet& iconset, const QString &label, int size ) // QListView
504{ 493{
505 if ( !isValidViewMode( Tree ) ) 494 if ( !isValidViewMode( Tree ) )
506 { 495 {
507 return -1; 496 return -1;
508 } 497 }
509 return _listview->addColumn( iconset, label, size ); 498 return _listview->addColumn( iconset, label, size );
510} 499}
511 500
512void OVersatileView::removeColumn( int index ) // QListView 501void OVersatileView::removeColumn( int index ) // QListView
513{ 502{
514 if ( !isValidViewMode( Tree ) ) 503 if ( !isValidViewMode( Tree ) )
515 { 504 {
516 return; 505 return;
517 } 506 }
518 _listview->removeColumn( index ); 507 _listview->removeColumn( index );
519} 508}
520 void OVersatileView::setColumnText( int column, const QString &label ) // QListView 509 void OVersatileView::setColumnText( int column, const QString &label ) // QListView
521{ 510{
522 if ( !isValidViewMode( Tree ) ) 511 if ( !isValidViewMode( Tree ) )
523 { 512 {
524 return; 513 return;
525 } 514 }
526 _listview->setColumnText( column, label ); 515 _listview->setColumnText( column, label );
527} 516}
528 void OVersatileView::setColumnText( int column, const QIconSet& iconset, const QString &label ) // QListView 517 void OVersatileView::setColumnText( int column, const QIconSet& iconset, const QString &label ) // QListView
529{ 518{
530 if ( !isValidViewMode( Tree ) ) 519 if ( !isValidViewMode( Tree ) )
531 { 520 {
532 return; 521 return;
533 } 522 }
534 _listview->setColumnText( column, iconset, label ); 523 _listview->setColumnText( column, iconset, label );
535} 524}
536QString OVersatileView::columnText( int column ) const // QListView 525QString OVersatileView::columnText( int column ) const // QListView
537{ 526{
538 if ( !isValidViewMode( Tree ) ) 527 if ( !isValidViewMode( Tree ) )
539 { 528 {
540 return QString::null; 529 return QString::null;
541 } 530 }
542 return _listview->columnText( column ); 531 return _listview->columnText( column );
543} 532}
544 void OVersatileView::setColumnWidth( int column, int width ) // QListView 533 void OVersatileView::setColumnWidth( int column, int width ) // QListView
545{ 534{
546 if ( !isValidViewMode( Tree ) ) 535 if ( !isValidViewMode( Tree ) )
547 { 536 {
548 return; 537 return;
549 } 538 }
550 _listview->setColumnWidth( column, width ); 539 _listview->setColumnWidth( column, width );
551} 540}
552int OVersatileView::columnWidth( int column ) const // QListView 541int OVersatileView::columnWidth( int column ) const // QListView
553{ 542{
554 if ( !isValidViewMode( Tree ) ) 543 if ( !isValidViewMode( Tree ) )
555 { 544 {
556 return -1; 545 return -1;
557 } 546 }
558 return _listview->columnWidth( column ); 547 return _listview->columnWidth( column );
559} 548}
560 void OVersatileView::setColumnWidthMode( int column, WidthMode mode ) // QListView 549 void OVersatileView::setColumnWidthMode( int column, WidthMode mode ) // QListView
561{ 550{
562 if ( !isValidViewMode( Tree ) ) 551 if ( !isValidViewMode( Tree ) )
563 { 552 {
564 return; 553 return;
565 } 554 }
566 _listview->setColumnWidth( column, mode ); 555 _listview->setColumnWidth( column, mode );
567} 556}
568int OVersatileView::columns() const // QListView 557int OVersatileView::columns() const // QListView
569{ 558{
570 if ( !isValidViewMode( Tree ) ) 559 if ( !isValidViewMode( Tree ) )
571 { 560 {
572 return -1; 561 return -1;
573 } 562 }
574 return _listview->columns(); 563 return _listview->columns();
575} 564}
576 565
577 void OVersatileView::setColumnAlignment( int column, int align ) // QListView 566 void OVersatileView::setColumnAlignment( int column, int align ) // QListView
578{ 567{
579 if ( !isValidViewMode( Tree ) ) 568 if ( !isValidViewMode( Tree ) )
580 { 569 {
581 return; 570 return;
582 } 571 }
583 _listview->setColumnAlignment( column, align ); 572 _listview->setColumnAlignment( column, align );
584} 573}
585int OVersatileView::columnAlignment( int column ) const // QListView 574int OVersatileView::columnAlignment( int column ) const // QListView
586{ 575{
587 if ( !isValidViewMode( Tree ) ) 576 if ( !isValidViewMode( Tree ) )
588 { 577 {
589 return -1; 578 return -1;
590 } 579 }
591 return _listview->columnAlignment( column ); 580 return _listview->columnAlignment( column );
592} 581}
593 582
594OVersatileViewItem * OVersatileView::itemAt( const QPoint & screenPos ) const // QListView 583OVersatileViewItem * OVersatileView::itemAt( const QPoint & screenPos ) const // QListView
595{ 584{
596 if ( !isValidViewMode( Tree ) ) 585 if ( !isValidViewMode( Tree ) )
597 { 586 {
598 return 0; 587 return 0;
599 } 588 }
600 return static_cast<OVersatileViewItem*>( _listview->itemAt( screenPos ) ); 589 return static_cast<OVersatileViewItem*>( _listview->itemAt( screenPos ) );
601} 590}
602QRect OVersatileView::itemRect( const OVersatileViewItem * item ) const // QListView 591QRect OVersatileView::itemRect( const OVersatileViewItem * item ) const // QListView
603{ 592{
604 if ( !isValidViewMode( Tree ) ) 593 if ( !isValidViewMode( Tree ) )
605 { 594 {
606 return QRect( -1, -1, -1, -1 ); 595 return QRect( -1, -1, -1, -1 );
607 } 596 }
608 return _listview->itemRect( item ); 597 return _listview->itemRect( item );
609} 598}
610int OVersatileView::itemPos( const OVersatileViewItem * item ) // QListView 599int OVersatileView::itemPos( const OVersatileViewItem * item ) // QListView
611{ 600{
612 if ( !isValidViewMode( Tree ) ) 601 if ( !isValidViewMode( Tree ) )
613 { 602 {
614 return -1; 603 return -1;
615 } 604 }
616 return _listview->itemPos( item ); 605 return _listview->itemPos( item );
617} 606}
618 607
619bool OVersatileView::isSelected( const OVersatileViewItem * item ) const // QListView // also in QIconViewItem but !in QIconView *shrug* 608bool OVersatileView::isSelected( const OVersatileViewItem * item ) const // QListView // also in QIconViewItem but !in QIconView *shrug*
620{ 609{
621 if ( !isValidViewMode( Tree ) ) 610 if ( !isValidViewMode( Tree ) )
622 { 611 {
623 return false; 612 return false;
624 } 613 }
625 return _listview->isSelected( item ); 614 return _listview->isSelected( item );
626} 615}
627 616
628 void OVersatileView::setMultiSelection( bool enable ) 617 void OVersatileView::setMultiSelection( bool enable )
629{ 618{
630 _listview->setMultiSelection( enable ); 619 _listview->setMultiSelection( enable );
631} 620}
632bool OVersatileView::isMultiSelection() const 621bool OVersatileView::isMultiSelection() const
633{ 622{
634 return _listview->isMultiSelection(); 623 return _listview->isMultiSelection();
635} 624}
636 625
637OVersatileViewItem * OVersatileView::selectedItem() const // QListView 626OVersatileViewItem * OVersatileView::selectedItem() const // QListView
638{ 627{
639 if ( !isValidViewMode( Tree ) ) 628 if ( !isValidViewMode( Tree ) )
640 { 629 {
641 return 0; 630 return 0;
642 } 631 }
643 return static_cast<OVersatileViewItem*>( _listview->selectedItem() ); 632 return static_cast<OVersatileViewItem*>( _listview->selectedItem() );
644} 633}
645 void OVersatileView::setOpen( OVersatileViewItem * item, bool open ) // QListView 634 void OVersatileView::setOpen( OVersatileViewItem * item, bool open ) // QListView
646{ 635{
647 if ( !isValidViewMode( Tree ) ) 636 if ( !isValidViewMode( Tree ) )
648 { 637 {
649 return; 638 return;
650 } 639 }
651 _listview->setOpen( item, open ); 640 _listview->setOpen( item, open );
652} 641}
653bool OVersatileView::isOpen( const OVersatileViewItem * item ) const // QListView 642bool OVersatileView::isOpen( const OVersatileViewItem * item ) const // QListView
654{ 643{
655 if ( !isValidViewMode( Tree ) ) 644 if ( !isValidViewMode( Tree ) )
656 { 645 {
657 return false; 646 return false;
658 } 647 }
659 return _listview->isOpen( item ); 648 return _listview->isOpen( item );
660} 649}
661 650
662OVersatileViewItem * OVersatileView::firstChild() const // QListView 651OVersatileViewItem * OVersatileView::firstChild() const // QListView
663{ 652{
664 if ( !isValidViewMode( Tree ) ) 653 if ( !isValidViewMode( Tree ) )
665 { 654 {
666 return 0; 655 return 0;
667 } 656 }
668 return static_cast<OVersatileViewItem*>( _listview->firstChild() ); 657 return static_cast<OVersatileViewItem*>( _listview->firstChild() );
669} 658}
670int OVersatileView::childCount() const // QListView 659int OVersatileView::childCount() const // QListView
671{ 660{
672 if ( !isValidViewMode( Tree ) ) 661 if ( !isValidViewMode( Tree ) )
673 { 662 {
674 return -1; 663 return -1;
675 } 664 }
676 return _listview->childCount(); 665 return _listview->childCount();
677} 666}
678 667
679 void OVersatileView::setAllColumnsShowFocus( bool focus ) // QListView 668 void OVersatileView::setAllColumnsShowFocus( bool focus ) // QListView
680{ 669{
681 if ( !isValidViewMode( Tree ) ) 670 if ( !isValidViewMode( Tree ) )
682 { 671 {
683 return; 672 return;
684 } 673 }
685 _listview->setAllColumnsShowFocus( focus ); 674 _listview->setAllColumnsShowFocus( focus );
686} 675}
687bool OVersatileView::allColumnsShowFocus() const // QListView 676bool OVersatileView::allColumnsShowFocus() const // QListView
688{ 677{
689 if ( !isValidViewMode( Tree ) ) 678 if ( !isValidViewMode( Tree ) )
690 { 679 {
691 return false; 680 return false;
692 } 681 }
693 return _listview->allColumnsShowFocus(); 682 return _listview->allColumnsShowFocus();
694} 683}
695 684
696 void OVersatileView::setItemMargin( int margin ) // QListView 685 void OVersatileView::setItemMargin( int margin ) // QListView
697{ 686{
698 if ( !isValidViewMode( Tree ) ) 687 if ( !isValidViewMode( Tree ) )
699 { 688 {
700 return; 689 return;
701 } 690 }
702 _listview->setItemMargin( margin ); 691 _listview->setItemMargin( margin );
703} 692}
704int OVersatileView::itemMargin() const // QListView 693int OVersatileView::itemMargin() const // QListView
705{ 694{
706 if ( !isValidViewMode( Tree ) ) 695 if ( !isValidViewMode( Tree ) )
707 { 696 {
708 return -1; 697 return -1;
709 } 698 }
710 return _listview->itemMargin(); 699 return _listview->itemMargin();
711} 700}
712 701
713 void OVersatileView::setRootIsDecorated( bool decorate ) // QListView 702 void OVersatileView::setRootIsDecorated( bool decorate ) // QListView
714{ 703{
715 if ( !isValidViewMode( Tree ) ) 704 if ( !isValidViewMode( Tree ) )
716 { 705 {
717 return; 706 return;
718 } 707 }
719 _listview->setRootIsDecorated( decorate ); 708 _listview->setRootIsDecorated( decorate );
720} 709}
721bool OVersatileView::rootIsDecorated() const // QListView 710bool OVersatileView::rootIsDecorated() const // QListView
722{ 711{
723 if ( !isValidViewMode( Tree ) ) 712 if ( !isValidViewMode( Tree ) )
724 { 713 {
725 return false; 714 return false;
726 } 715 }
727 return _listview->rootIsDecorated(); 716 return _listview->rootIsDecorated();
728} 717}
729 718
730void OVersatileView::setShowSortIndicator( bool show ) // QListView 719void OVersatileView::setShowSortIndicator( bool show ) // QListView
731{ 720{
732 if ( !isValidViewMode( Tree ) ) 721 if ( !isValidViewMode( Tree ) )
733 { 722 {
734 return; 723 return;
735 } 724 }
736 _listview->setShowSortIndicator( show ); 725 _listview->setShowSortIndicator( show );
737} 726}
738bool OVersatileView::showSortIndicator() const // QListView 727bool OVersatileView::showSortIndicator() const // QListView
739{ 728{
740 if ( !isValidViewMode( Tree ) ) 729 if ( !isValidViewMode( Tree ) )
741 { 730 {
742 return false; 731 return false;
743 } 732 }
744 return _listview->showSortIndicator(); 733 return _listview->showSortIndicator();
745} 734}
746 735
747void OVersatileView::triggerUpdate() // QListView 736void OVersatileView::triggerUpdate() // QListView
748{ 737{
749 if ( !isValidViewMode( Tree ) ) 738 if ( !isValidViewMode( Tree ) )
750 { 739 {
751 return; 740 return;
752 } 741 }
753 _listview->triggerUpdate(); 742 _listview->triggerUpdate();
754} 743}
755 744
756// 745//
757// only in QIconView 746// only in QIconView
758// 747//
759 748
760uint OVersatileView::count() const // QIconView 749uint OVersatileView::count() const // QIconView
761{ 750{
762 if ( !isValidViewMode( Icons ) ) 751 if ( !isValidViewMode( Icons ) )
763 { 752 {
764 return 0; 753 return 0;
765 } 754 }
766 return _iconview->count(); 755 return _iconview->count();
767} 756}
768 757
769int OVersatileView::index( const OVersatileViewItem *item ) const // QIconView 758int OVersatileView::index( const OVersatileViewItem *item ) const // QIconView
770{ 759{
771 if ( !isValidViewMode( Icons ) ) 760 if ( !isValidViewMode( Icons ) )
772 { 761 {
773 return -1; 762 return -1;
774 } 763 }
775 return _iconview->index( item ); 764 return _iconview->index( item );
776} 765}
777 766
778OVersatileViewItem* OVersatileView::firstItem() const // QIconView 767OVersatileViewItem* OVersatileView::firstItem() const // QIconView
779{ 768{
780 if ( !isValidViewMode( Icons ) ) 769 if ( !isValidViewMode( Icons ) )
781 { 770 {
782 return 0; 771 return 0;
783 } 772 }
784 return static_cast<OVersatileViewItem*>( _iconview->firstItem() ); 773 return static_cast<OVersatileViewItem*>( _iconview->firstItem() );
785} 774}
786OVersatileViewItem* OVersatileView::lastItem() const // QIconView 775OVersatileViewItem* OVersatileView::lastItem() const // QIconView
787{ 776{
788 if ( !isValidViewMode( Icons ) ) 777 if ( !isValidViewMode( Icons ) )
789 { 778 {
790 return 0; 779 return 0;
791 } 780 }
792 return static_cast<OVersatileViewItem*>( _iconview->lastItem() ); 781 return static_cast<OVersatileViewItem*>( _iconview->lastItem() );
793} 782}
794 783
795OVersatileViewItem* OVersatileView::findItem( const QPoint &pos ) const // QIconView 784OVersatileViewItem* OVersatileView::findItem( const QPoint &pos ) const // QIconView
796{ 785{
797 if ( !isValidViewMode( Icons ) ) 786 if ( !isValidViewMode( Icons ) )
798 { 787 {
799 return 0; 788 return 0;
800 } 789 }
801 return static_cast<OVersatileViewItem*>( _iconview->findItem( pos ) ); 790 return static_cast<OVersatileViewItem*>( _iconview->findItem( pos ) );
802} 791}
803OVersatileViewItem* OVersatileView::findItem( const QString &text ) const // QIconView 792OVersatileViewItem* OVersatileView::findItem( const QString &text ) const // QIconView
804{ 793{
805 if ( !isValidViewMode( Icons ) ) 794 if ( !isValidViewMode( Icons ) )
806 { 795 {
807 return 0; 796 return 0;
808 } 797 }
809 return static_cast<OVersatileViewItem*>( _iconview->findItem( text ) ); 798 return static_cast<OVersatileViewItem*>( _iconview->findItem( text ) );
810} 799}
811 800
812OVersatileViewItem* OVersatileView::findFirstVisibleItem( const QRect &r ) const // QIconView 801OVersatileViewItem* OVersatileView::findFirstVisibleItem( const QRect &r ) const // QIconView
813{ 802{
814 if ( !isValidViewMode( Icons ) ) 803 if ( !isValidViewMode( Icons ) )
815 { 804 {
816 return 0; 805 return 0;
817 } 806 }
818 return static_cast<OVersatileViewItem*>( _iconview->findFirstVisibleItem( r ) ); 807 return static_cast<OVersatileViewItem*>( _iconview->findFirstVisibleItem( r ) );
819} 808}
820OVersatileViewItem* OVersatileView::findLastVisibleItem( const QRect &r ) const // QIconView 809OVersatileViewItem* OVersatileView::findLastVisibleItem( const QRect &r ) const // QIconView
821{ 810{
822 if ( !isValidViewMode( Icons ) ) 811 if ( !isValidViewMode( Icons ) )
823 { 812 {
824 return 0; 813 return 0;
825 } 814 }
826 return static_cast<OVersatileViewItem*>( _iconview->findLastVisibleItem( r ) ); 815 return static_cast<OVersatileViewItem*>( _iconview->findLastVisibleItem( r ) );
827} 816}
828 817
829 void OVersatileView::setGridX( int rx ) // QIconView 818 void OVersatileView::setGridX( int rx ) // QIconView
830{ 819{
831 if ( !isValidViewMode( Icons ) ) 820 if ( !isValidViewMode( Icons ) )
832 { 821 {
833 return; 822 return;
834 } 823 }
835 _iconview->setGridX( rx ); 824 _iconview->setGridX( rx );
836} 825}
837 void OVersatileView::setGridY( int ry ) // QIconView 826 void OVersatileView::setGridY( int ry ) // QIconView
838{ 827{
839 if ( !isValidViewMode( Icons ) ) 828 if ( !isValidViewMode( Icons ) )
840 { 829 {
841 return; 830 return;
842 } 831 }
843 _iconview->setGridY( ry ); 832 _iconview->setGridY( ry );
844} 833}
845int OVersatileView::gridX() const // QIconView 834int OVersatileView::gridX() const // QIconView
846{ 835{
847 if ( !isValidViewMode( Icons ) ) 836 if ( !isValidViewMode( Icons ) )
848 { 837 {
849 return -1; 838 return -1;
850 } 839 }
851 return _iconview->gridX(); 840 return _iconview->gridX();
852} 841}
853int OVersatileView::gridY() const // QIconView 842int OVersatileView::gridY() const // QIconView
854{ 843{
855 if ( !isValidViewMode( Icons ) ) 844 if ( !isValidViewMode( Icons ) )
856 { 845 {
857 return -1; 846 return -1;
858 } 847 }
859 return _iconview->gridY(); 848 return _iconview->gridY();
860} 849}
861 void OVersatileView::setSpacing( int sp ) // QIconView 850 void OVersatileView::setSpacing( int sp ) // QIconView
862{ 851{
863 if ( !isValidViewMode( Icons ) ) 852 if ( !isValidViewMode( Icons ) )
864 { 853 {
865 return; 854 return;
866 } 855 }
867 _iconview->setSpacing( sp ); 856 _iconview->setSpacing( sp );
868} 857}
869int OVersatileView::spacing() const // QIconView 858int OVersatileView::spacing() const // QIconView
870{ 859{
871 if ( !isValidViewMode( Icons ) ) 860 if ( !isValidViewMode( Icons ) )
872 { 861 {
873 return -1; 862 return -1;
874 } 863 }
875 return _iconview->spacing(); 864 return _iconview->spacing();
876} 865}
877 void OVersatileView::setItemTextPos( QIconView::ItemTextPos pos ) // QIconView 866 void OVersatileView::setItemTextPos( QIconView::ItemTextPos pos ) // QIconView
878{ 867{
879 if ( !isValidViewMode( Icons ) ) 868 if ( !isValidViewMode( Icons ) )
880 { 869 {
881 return; 870 return;
882 } 871 }
883 _iconview->setItemTextPos( pos ); 872 _iconview->setItemTextPos( pos );
884} 873}
885QIconView::ItemTextPos OVersatileView::itemTextPos() const // QIconView 874QIconView::ItemTextPos OVersatileView::itemTextPos() const // QIconView
886{ 875{
887 if ( !isValidViewMode( Icons ) ) 876 if ( !isValidViewMode( Icons ) )
888 { 877 {
889 return (QIconView::ItemTextPos) -1; 878 return (QIconView::ItemTextPos) -1;
890 } 879 }
891 return _iconview->itemTextPos(); 880 return _iconview->itemTextPos();
892} 881}
893 void OVersatileView::setItemTextBackground( const QBrush &b ) // QIconView 882 void OVersatileView::setItemTextBackground( const QBrush &b ) // QIconView
894{ 883{
895 if ( !isValidViewMode( Icons ) ) 884 if ( !isValidViewMode( Icons ) )
896 { 885 {
897 return; 886 return;
898 } 887 }
899 _iconview->setItemTextBackground( b ); 888 _iconview->setItemTextBackground( b );
900} 889}
901QBrush OVersatileView::itemTextBackground() const // QIconView 890QBrush OVersatileView::itemTextBackground() const // QIconView
902{ 891{
903 if ( !isValidViewMode( Icons ) ) 892 if ( !isValidViewMode( Icons ) )
904 { 893 {
905 return QBrush(); 894 return QBrush();
906 } 895 }
907 return _iconview->itemTextBackground(); 896 return _iconview->itemTextBackground();
908} 897}
909 void OVersatileView::setArrangement( QIconView::Arrangement am ) // QIconView 898 void OVersatileView::setArrangement( QIconView::Arrangement am ) // QIconView
910{ 899{
911 if ( !isValidViewMode( Icons ) ) 900 if ( !isValidViewMode( Icons ) )
912 { 901 {
913 return; 902 return;
914 } 903 }
915 _iconview->setArrangement( am ); 904 _iconview->setArrangement( am );
916} 905}
917QIconView::Arrangement OVersatileView::arrangement() const // QIconView 906QIconView::Arrangement OVersatileView::arrangement() const // QIconView
918{ 907{
919 if ( !isValidViewMode( Icons ) ) 908 if ( !isValidViewMode( Icons ) )
920 { 909 {
921 return (QIconView::Arrangement) -1; 910 return (QIconView::Arrangement) -1;
922 } 911 }
923 return _iconview->arrangement(); 912 return _iconview->arrangement();
924} 913}
925 void OVersatileView::setResizeMode( QIconView::ResizeMode am ) // QIconView 914 void OVersatileView::setResizeMode( QIconView::ResizeMode am ) // QIconView
926{ 915{
927 if ( !isValidViewMode( Icons ) ) 916 if ( !isValidViewMode( Icons ) )
928 { 917 {
929 return; 918 return;
930 } 919 }
931 _iconview->setResizeMode( am ); 920 _iconview->setResizeMode( am );
932} 921}
933QIconView::ResizeMode OVersatileView::resizeMode() const // QIconView 922QIconView::ResizeMode OVersatileView::resizeMode() const // QIconView
934{ 923{
935 if ( !isValidViewMode( Icons ) ) 924 if ( !isValidViewMode( Icons ) )
936 { 925 {
937 return (QIconView::ResizeMode) -1; 926 return (QIconView::ResizeMode) -1;
938 } 927 }
939 return _iconview->resizeMode(); 928 return _iconview->resizeMode();
940} 929}
941 void OVersatileView::setMaxItemWidth( int w ) // QIconView 930 void OVersatileView::setMaxItemWidth( int w ) // QIconView
942{ 931{
943 if ( !isValidViewMode( Icons ) ) 932 if ( !isValidViewMode( Icons ) )
944 { 933 {
945 return; 934 return;
946 } 935 }
947 _iconview->setMaxItemWidth( w ); 936 _iconview->setMaxItemWidth( w );
948} 937}
949int OVersatileView::maxItemWidth() const // QIconView 938int OVersatileView::maxItemWidth() const // QIconView
950{ 939{
951 if ( !isValidViewMode( Icons ) ) 940 if ( !isValidViewMode( Icons ) )
952 { 941 {
953 return -1; 942 return -1;
954 } 943 }
955 return _iconview->maxItemWidth(); 944 return _iconview->maxItemWidth();
956} 945}
957 void OVersatileView::setMaxItemTextLength( int w ) // QIconView 946 void OVersatileView::setMaxItemTextLength( int w ) // QIconView
958{ 947{
959 if ( !isValidViewMode( Icons ) ) 948 if ( !isValidViewMode( Icons ) )
960 { 949 {
961 return; 950 return;
962 } 951 }
963 _iconview->setMaxItemTextLength( w ); 952 _iconview->setMaxItemTextLength( w );
964} 953}
965int OVersatileView::maxItemTextLength() const // QIconView 954int OVersatileView::maxItemTextLength() const // QIconView
966{ 955{
967 if ( !isValidViewMode( Icons ) ) 956 if ( !isValidViewMode( Icons ) )
968 { 957 {
969 return -1; 958 return -1;
970 } 959 }
971 return _iconview->maxItemTextLength(); 960 return _iconview->maxItemTextLength();
972} 961}
973 void OVersatileView::setAutoArrange( bool b ) // QIconView 962 void OVersatileView::setAutoArrange( bool b ) // QIconView
974{ 963{
975 if ( !isValidViewMode( Icons ) ) 964 if ( !isValidViewMode( Icons ) )
976 { 965 {
977 return; 966 return;
978 } 967 }
979 _iconview->setAutoArrange( b ); 968 _iconview->setAutoArrange( b );
980} 969}
981bool OVersatileView::autoArrange() const // QIconView 970bool OVersatileView::autoArrange() const // QIconView
982{ 971{
983 if ( !isValidViewMode( Icons ) ) 972 if ( !isValidViewMode( Icons ) )
984 { 973 {
985 return false; 974 return false;
986 } 975 }
987 return _iconview->autoArrange(); 976 return _iconview->autoArrange();
988} 977}
989 void OVersatileView::setShowToolTips( bool b ) // QIconView 978 void OVersatileView::setShowToolTips( bool b ) // QIconView
990{ 979{
991 if ( !isValidViewMode( Icons ) ) 980 if ( !isValidViewMode( Icons ) )
992 { 981 {
993 return; 982 return;
994 } 983 }
995 _iconview->setShowToolTips( b ); 984 _iconview->setShowToolTips( b );
996} 985}
997bool OVersatileView::showToolTips() const // QIconView 986bool OVersatileView::showToolTips() const // QIconView
998{ 987{
999 if ( !isValidViewMode( Icons ) ) 988 if ( !isValidViewMode( Icons ) )
1000 { 989 {
1001 return false; 990 return false;
1002 } 991 }
1003 return _iconview->showToolTips(); 992 return _iconview->showToolTips();
1004} 993}
1005 994
1006bool OVersatileView::sorting() const // QIconView 995bool OVersatileView::sorting() const // QIconView
1007{ 996{
1008 if ( !isValidViewMode( Icons ) ) 997 if ( !isValidViewMode( Icons ) )
1009 { 998 {
1010 return false; 999 return false;
1011 } 1000 }
1012 return _iconview->sorting(); 1001 return _iconview->sorting();
1013} 1002}
1014bool OVersatileView::sortDirection() const // QIconView 1003bool OVersatileView::sortDirection() const // QIconView
1015{ 1004{
1016 if ( !isValidViewMode( Icons ) ) 1005 if ( !isValidViewMode( Icons ) )
1017 { 1006 {
1018 return false; 1007 return false;
1019 } 1008 }
1020 return _iconview->sortDirection(); 1009 return _iconview->sortDirection();
1021} 1010}
1022 1011
1023 void OVersatileView::setItemsMovable( bool b ) // QIconView 1012 void OVersatileView::setItemsMovable( bool b ) // QIconView
1024{ 1013{
1025 if ( !isValidViewMode( Icons ) ) 1014 if ( !isValidViewMode( Icons ) )
1026 { 1015 {
1027 return; 1016 return;
1028 } 1017 }
1029 _iconview->setItemsMovable( b ); 1018 _iconview->setItemsMovable( b );
1030} 1019}
1031bool OVersatileView::itemsMovable() const // QIconView 1020bool OVersatileView::itemsMovable() const // QIconView
1032{ 1021{
1033 if ( !isValidViewMode( Icons ) ) 1022 if ( !isValidViewMode( Icons ) )
1034 { 1023 {
1035 return false; 1024 return false;
1036 } 1025 }
1037 return _iconview->itemsMovable(); 1026 return _iconview->itemsMovable();
1038} 1027}
1039void OVersatileView::setWordWrapIconText( bool b ) // QIconView 1028void OVersatileView::setWordWrapIconText( bool b ) // QIconView
1040{ 1029{
1041 if ( !isValidViewMode( Icons ) ) 1030 if ( !isValidViewMode( Icons ) )
1042 { 1031 {
1043 return; 1032 return;
1044 } 1033 }
1045 _iconview->setWordWrapIconText( b ); 1034 _iconview->setWordWrapIconText( b );
1046} 1035}
1047bool OVersatileView::wordWrapIconText() const // QIconView 1036bool OVersatileView::wordWrapIconText() const // QIconView
1048{ 1037{
1049 if ( !isValidViewMode( Icons ) ) 1038 if ( !isValidViewMode( Icons ) )
1050 { 1039 {
1051 return false; 1040 return false;
1052 } 1041 }
1053 return _iconview->wordWrapIconText(); 1042 return _iconview->wordWrapIconText();
1054} 1043}
1055 1044
1056void OVersatileView::arrangeItemsInGrid( const QSize &grid, bool update ) // QIconView 1045void OVersatileView::arrangeItemsInGrid( const QSize &grid, bool update ) // QIconView
1057{ 1046{
1058 if ( !isValidViewMode( Icons ) ) 1047 if ( !isValidViewMode( Icons ) )
1059 { 1048 {
1060 return; 1049 return;
1061 } 1050 }
1062 _iconview->arrangeItemsInGrid( grid, update ); 1051 _iconview->arrangeItemsInGrid( grid, update );
1063} 1052}
1064void OVersatileView::arrangeItemsInGrid( bool update ) // QIconView 1053void OVersatileView::arrangeItemsInGrid( bool update ) // QIconView
1065{ 1054{
1066 if ( !isValidViewMode( Icons ) ) 1055 if ( !isValidViewMode( Icons ) )
1067 { 1056 {
1068 return; 1057 return;
1069 } 1058 }
1070 _iconview->arrangeItemsInGrid( update ); 1059 _iconview->arrangeItemsInGrid( update );
1071} 1060}
1072void OVersatileView::updateContents() // QIconView 1061void OVersatileView::updateContents() // QIconView
1073{ 1062{
1074 if ( !isValidViewMode( Icons ) ) 1063 if ( !isValidViewMode( Icons ) )
1075 { 1064 {
1076 return; 1065 return;
1077 } 1066 }
1078 _iconview->updateContents(); 1067 _iconview->updateContents();
1079} 1068}
1080 1069
1081//==============================================================================================// 1070//==============================================================================================//
1082// OVersatileView Case II - QListView / QIconView common API 1071// OVersatileView Case II - QListView / QIconView common API
1083//==============================================================================================// 1072//==============================================================================================//
1084 1073
1085void OVersatileView::clear() 1074void OVersatileView::clear()
1086{ 1075{
1087 _iconview->clear(); 1076 _iconview->clear();
1088 _listview->clear(); 1077 _listview->clear();
1089} 1078}
1090 1079
1091void OVersatileView::setFont( const QFont & font ) 1080void OVersatileView::setFont( const QFont & font )
1092{ 1081{
1093 _iconview->setFont( font ); 1082 _iconview->setFont( font );
1094 _listview->setFont( font ); 1083 _listview->setFont( font );
1095} 1084}
1096void OVersatileView::setPalette( const QPalette & palette ) 1085void OVersatileView::setPalette( const QPalette & palette )
1097{ 1086{
1098 _iconview->setPalette( palette ); 1087 _iconview->setPalette( palette );
1099 _listview->setPalette( palette ); 1088 _listview->setPalette( palette );
1100} 1089}
1101 1090
1102void OVersatileView::takeItem( OVersatileViewItem * item ) 1091void OVersatileView::takeItem( OVersatileViewItem * item )
1103{ 1092{
1104 _iconview->takeItem( item ); 1093 _iconview->takeItem( item );
1105 _listview->takeItem( item ); 1094 _listview->takeItem( item );
1106} 1095}
1107 1096
1108void OVersatileView::setSelectionMode( SelectionMode mode ) 1097void OVersatileView::setSelectionMode( SelectionMode mode )
1109{ 1098{
1110 _iconview->setSelectionMode( (QIconView::SelectionMode) mode ); 1099 _iconview->setSelectionMode( (QIconView::SelectionMode) mode );
1111 _listview->setSelectionMode( (QListView::SelectionMode) mode ); 1100 _listview->setSelectionMode( (QListView::SelectionMode) mode );
1112} 1101}
1113OVersatileView::SelectionMode OVersatileView::selectionMode() const 1102OVersatileView::SelectionMode OVersatileView::selectionMode() const
1114{ 1103{
1115 return (OVersatileView::SelectionMode) _iconview->selectionMode(); 1104 return (OVersatileView::SelectionMode) _iconview->selectionMode();
1116} 1105}
1117 1106
1118void OVersatileView::selectAll( bool select ) 1107void OVersatileView::selectAll( bool select )
1119{ 1108{
1120 _iconview->selectAll( select ); 1109 _iconview->selectAll( select );
1121} 1110}
1122void OVersatileView::clearSelection() 1111void OVersatileView::clearSelection()
1123{ 1112{
1124 _iconview->clearSelection(); 1113 _iconview->clearSelection();
1125 _listview->clearSelection(); 1114 _listview->clearSelection();
1126} 1115}
1127void OVersatileView::invertSelection() 1116void OVersatileView::invertSelection()
1128{ 1117{
1129 _iconview->invertSelection(); 1118 _iconview->invertSelection();
1130 _listview->invertSelection(); 1119 _listview->invertSelection();
1131} 1120}
1132 1121
1133void OVersatileView::ensureItemVisible( const OVersatileViewItem * item ) 1122void OVersatileView::ensureItemVisible( const OVersatileViewItem * item )
1134{ 1123{
1135 _iconview->ensureItemVisible( const_cast<OVersatileViewItem*>( item ) ); 1124 _iconview->ensureItemVisible( const_cast<OVersatileViewItem*>( item ) );
1136 _listview->ensureItemVisible( item ); 1125 _listview->ensureItemVisible( item );
1137} 1126}
1138void OVersatileView::repaintItem( const OVersatileViewItem * item ) const 1127void OVersatileView::repaintItem( const OVersatileViewItem * item ) const
1139{ 1128{
1140 _iconview->repaintItem( const_cast<OVersatileViewItem*>( item ) ); 1129 _iconview->repaintItem( const_cast<OVersatileViewItem*>( item ) );
1141 _listview->repaintItem( item ); 1130 _listview->repaintItem( item );
1142} 1131}
1143 1132
1144void OVersatileView::setCurrentItem( OVersatileViewItem * item ) 1133void OVersatileView::setCurrentItem( OVersatileViewItem * item )
1145{ 1134{
1146 _iconview->setCurrentItem( item ); 1135 _iconview->setCurrentItem( item );
1147 _listview->setCurrentItem( item ); 1136 _listview->setCurrentItem( item );
1148} 1137}
1149OVersatileViewItem * OVersatileView::currentItem() const 1138OVersatileViewItem * OVersatileView::currentItem() const
1150{ 1139{
1151 return static_cast<OVersatileViewItem*>( _listview->currentItem() ); 1140 return static_cast<OVersatileViewItem*>( _listview->currentItem() );
1152} 1141}
1153 1142
1154// bool eventFilter( QObject * o, QEvent * ) // use QWidgetStack implementation 1143// bool eventFilter( QObject * o, QEvent * ) // use QWidgetStack implementation
1155 1144
1156// QSize minimumSizeHint() const // use QWidgetStack implementation 1145// QSize minimumSizeHint() const // use QWidgetStack implementation
1157// QSizePolicy sizePolicy() const // use QWidgetStack implementation 1146// QSizePolicy sizePolicy() const // use QWidgetStack implementation
1158// QSize sizeHint() const // use QWidgetStack implementation 1147// QSize sizeHint() const // use QWidgetStack implementation
1159 1148
1160//==============================================================================================// 1149//==============================================================================================//
1161// OVersatileView Case III - APIs which differ slightly 1150// OVersatileView Case III - APIs which differ slightly
1162//==============================================================================================// 1151//==============================================================================================//
1163 1152
1164/* 1153/*
1165 1154
1166 void OVersatileView::insertItem( OVersatileViewItem * ) // QListView 1155 void OVersatileView::insertItem( OVersatileViewItem * ) // QListView
1167 void OVersatileView::insertItem( OVersatileViewItem *item, OVersatileViewItem *after = 0L ) // QIconView 1156 void OVersatileView::insertItem( OVersatileViewItem *item, OVersatileViewItem *after = 0L ) // QIconView
1168 1157
1169 void OVersatileView::setSelected( OVersatileViewItem *, bool ) // QListView 1158 void OVersatileView::setSelected( OVersatileViewItem *, bool ) // QListView
1170 void OVersatileView::setSelected( OVersatileViewItem *item, bool s, bool cb = FALSE ) // QIconView 1159 void OVersatileView::setSelected( OVersatileViewItem *item, bool s, bool cb = FALSE ) // QIconView
1171 1160
1172 void OVersatileView::setSorting( int column, bool increasing = TRUE ) // QListView 1161 void OVersatileView::setSorting( int column, bool increasing = TRUE ) // QListView
1173void OVersatileView::setSorting( bool sort, bool ascending = TRUE ) // QIconView 1162void OVersatileView::setSorting( bool sort, bool ascending = TRUE ) // QIconView
1174 1163
1175void OVersatileView::sort() // #### make in next major release // QListView 1164void OVersatileView::sort() // #### make in next major release // QListView
1176 void OVersatileView::sort( bool ascending = TRUE ) // QIconView 1165 void OVersatileView::sort( bool ascending = TRUE ) // QIconView
1177 1166
1178*/ 1167*/
1179 1168
1180 1169