summaryrefslogtreecommitdiff
path: root/library
authorzecke <zecke>2002-10-15 21:42:20 (UTC)
committer zecke <zecke>2002-10-15 21:42:20 (UTC)
commit676be5604cbdb3213c00775e0ff66f4e766f8dcb (patch) (unidiff)
tree63c29adab530a60371f78880ff75e2689398e239 /library
parentb774e015816e51ac65e5d1c685306f8404a3a19e (diff)
downloadopie-676be5604cbdb3213c00775e0ff66f4e766f8dcb.zip
opie-676be5604cbdb3213c00775e0ff66f4e766f8dcb.tar.gz
opie-676be5604cbdb3213c00775e0ff66f4e766f8dcb.tar.bz2
Actually most of them are -+ cause I opened them in xemacs..
The main goal is to replace some header names to let them be overwritten by external once so "qpeapplication.h" is now <qpe/qpeapplication.h> I'll check if it's building on non Qt2/X11 systems...
Diffstat (limited to 'library') (more/less context) (ignore whitespace changes)
-rw-r--r--library/alarmserver.cpp4
-rw-r--r--library/backend/vcc.y2
-rw-r--r--library/backend/vcc_yacc.cpp2
-rw-r--r--library/backend/vobject.cpp116
-rw-r--r--library/datebookmonth.cpp14
-rw-r--r--library/fileselector.cpp6
-rw-r--r--library/fontdatabase.cpp2
-rw-r--r--library/fontdatabase.h1
-rw-r--r--library/mimetype.cpp2
-rw-r--r--library/qpedialog.cpp4
-rw-r--r--library/qpestyle.cpp14
-rw-r--r--library/resource.cpp2
-rw-r--r--library/timestring.cpp34
13 files changed, 102 insertions, 101 deletions
diff --git a/library/alarmserver.cpp b/library/alarmserver.cpp
index 1ee05c6..177a0cb 100644
--- a/library/alarmserver.cpp
+++ b/library/alarmserver.cpp
@@ -1,403 +1,403 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include <qdir.h> 21#include <qdir.h>
22#include <qfile.h> 22#include <qfile.h>
23#include <qmessagebox.h> 23#include <qmessagebox.h>
24#include <qtextstream.h> 24#include <qtextstream.h>
25 25
26 26
27#include "qpeapplication.h" 27#include <qpe/qpeapplication.h>
28#include "global.h" 28#include "global.h"
29#include "resource.h" 29#include "resource.h"
30 30
31#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 31#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
32#include "qcopenvelope_qws.h" 32#include <qpe/qcopenvelope_qws.h>
33#endif 33#endif
34#include "alarmserver.h" 34#include "alarmserver.h"
35#include <qpe/timeconversion.h> 35#include <qpe/timeconversion.h>
36 36
37#include <sys/types.h> 37#include <sys/types.h>
38#include <sys/stat.h> 38#include <sys/stat.h>
39 39
40#include <stdlib.h> 40#include <stdlib.h>
41#include <unistd.h> 41#include <unistd.h>
42 42
43struct timerEventItem { 43struct timerEventItem {
44 time_t UTCtime; 44 time_t UTCtime;
45 QCString channel, message; 45 QCString channel, message;
46 int data; 46 int data;
47 bool operator==( const timerEventItem &right ) const 47 bool operator==( const timerEventItem &right ) const
48 { 48 {
49 return ( UTCtime == right.UTCtime 49 return ( UTCtime == right.UTCtime
50 && channel == right.channel 50 && channel == right.channel
51 && message == right.message 51 && message == right.message
52 && data == right.data ); 52 && data == right.data );
53 } 53 }
54}; 54};
55 55
56class TimerReceiverObject : public QObject 56class TimerReceiverObject : public QObject
57{ 57{
58public: 58public:
59 TimerReceiverObject() { } 59 TimerReceiverObject() { }
60 ~TimerReceiverObject() { } 60 ~TimerReceiverObject() { }
61 void resetTimer(); 61 void resetTimer();
62 void setTimerEventItem(); 62 void setTimerEventItem();
63 void deleteTimer(); 63 void deleteTimer();
64protected: 64protected:
65 void timerEvent( QTimerEvent *te ); 65 void timerEvent( QTimerEvent *te );
66private: 66private:
67 QString atfilename; 67 QString atfilename;
68}; 68};
69 69
70TimerReceiverObject *timerEventReceiver = NULL; 70TimerReceiverObject *timerEventReceiver = NULL;
71QList<timerEventItem> timerEventList; 71QList<timerEventItem> timerEventList;
72timerEventItem *nearestTimerEvent = NULL; 72timerEventItem *nearestTimerEvent = NULL;
73 73
74 74
75// set the timer to go off on the next event in the list 75// set the timer to go off on the next event in the list
76void setNearestTimerEvent() 76void setNearestTimerEvent()
77{ 77{
78 nearestTimerEvent = NULL; 78 nearestTimerEvent = NULL;
79 QListIterator<timerEventItem> it( timerEventList ); 79 QListIterator<timerEventItem> it( timerEventList );
80 if ( *it ) 80 if ( *it )
81 nearestTimerEvent = *it; 81 nearestTimerEvent = *it;
82 for ( ; *it; ++it ) 82 for ( ; *it; ++it )
83 if ( (*it)->UTCtime < nearestTimerEvent->UTCtime ) 83 if ( (*it)->UTCtime < nearestTimerEvent->UTCtime )
84 nearestTimerEvent = *it; 84 nearestTimerEvent = *it;
85 if (nearestTimerEvent) 85 if (nearestTimerEvent)
86 timerEventReceiver->resetTimer(); 86 timerEventReceiver->resetTimer();
87 else 87 else
88 timerEventReceiver->deleteTimer(); 88 timerEventReceiver->deleteTimer();
89} 89}
90 90
91 91
92//store current state to file 92//store current state to file
93//Simple implementation. Should run on a timer. 93//Simple implementation. Should run on a timer.
94 94
95static void saveState() 95static void saveState()
96{ 96{
97 QString savefilename = Global::applicationFileName( "AlarmServer", "saveFile" ); 97 QString savefilename = Global::applicationFileName( "AlarmServer", "saveFile" );
98 if ( timerEventList.isEmpty() ) { 98 if ( timerEventList.isEmpty() ) {
99 unlink( savefilename ); 99 unlink( savefilename );
100 return; 100 return;
101 } 101 }
102 102
103 QFile savefile(savefilename+".new"); 103 QFile savefile(savefilename+".new");
104 if ( savefile.open(IO_WriteOnly) ) { 104 if ( savefile.open(IO_WriteOnly) ) {
105 QDataStream ds( &savefile ); 105 QDataStream ds( &savefile );
106 106
107 //save 107 //save
108 108
109 QListIterator<timerEventItem> it( timerEventList ); 109 QListIterator<timerEventItem> it( timerEventList );
110 for ( ; *it; ++it ) { 110 for ( ; *it; ++it ) {
111 ds << it.current()->UTCtime; 111 ds << it.current()->UTCtime;
112 ds << it.current()->channel; 112 ds << it.current()->channel;
113 ds << it.current()->message; 113 ds << it.current()->message;
114 ds << it.current()->data; 114 ds << it.current()->data;
115 } 115 }
116 116
117 117
118 savefile.close(); 118 savefile.close();
119 unlink( savefilename ); 119 unlink( savefilename );
120 QDir d; d.rename(savefilename+".new",savefilename); 120 QDir d; d.rename(savefilename+".new",savefilename);
121 121
122 } 122 }
123} 123}
124 124
125/*! 125/*!
126 Sets up the alarm server. Restoring to previous state (session management). 126 Sets up the alarm server. Restoring to previous state (session management).
127 */ 127 */
128void AlarmServer::initialize() 128void AlarmServer::initialize()
129{ 129{
130 //read autosave file and put events in timerEventList 130 //read autosave file and put events in timerEventList
131 131
132 QString savefilename = Global::applicationFileName( "AlarmServer", "saveFile" ); 132 QString savefilename = Global::applicationFileName( "AlarmServer", "saveFile" );
133 133
134 QFile savefile(savefilename); 134 QFile savefile(savefilename);
135 if ( savefile.open(IO_ReadOnly) ) { 135 if ( savefile.open(IO_ReadOnly) ) {
136 QDataStream ds( &savefile ); 136 QDataStream ds( &savefile );
137 while ( !ds.atEnd() ) { 137 while ( !ds.atEnd() ) {
138 timerEventItem *newTimerEventItem = new timerEventItem; 138 timerEventItem *newTimerEventItem = new timerEventItem;
139 ds >> newTimerEventItem->UTCtime; 139 ds >> newTimerEventItem->UTCtime;
140 ds >> newTimerEventItem->channel; 140 ds >> newTimerEventItem->channel;
141 ds >> newTimerEventItem->message; 141 ds >> newTimerEventItem->message;
142 ds >> newTimerEventItem->data; 142 ds >> newTimerEventItem->data;
143 timerEventList.append( newTimerEventItem ); 143 timerEventList.append( newTimerEventItem );
144 } 144 }
145 savefile.close(); 145 savefile.close();
146 if (!timerEventReceiver) 146 if (!timerEventReceiver)
147 timerEventReceiver = new TimerReceiverObject; 147 timerEventReceiver = new TimerReceiverObject;
148 setNearestTimerEvent(); 148 setNearestTimerEvent();
149 } 149 }
150} 150}
151 151
152 152
153 153
154 154
155static const char* atdir = "/var/spool/at/"; 155static const char* atdir = "/var/spool/at/";
156 156
157static bool triggerAtd( bool writeHWClock = FALSE ) 157static bool triggerAtd( bool writeHWClock = FALSE )
158{ 158{
159 QFile trigger(QString(atdir) + "trigger"); 159 QFile trigger(QString(atdir) + "trigger");
160 if ( trigger.open(IO_WriteOnly|IO_Raw) ) { 160 if ( trigger.open(IO_WriteOnly|IO_Raw) ) {
161 161
162 const char* data = 162 const char* data =
163#ifdef QT_QWS_CUSTOM 163#ifdef QT_QWS_CUSTOM
164 //custom atd only writes HW Clock if we write a 'W' 164 //custom atd only writes HW Clock if we write a 'W'
165 ( writeHWClock ) ? "W\n" : 165 ( writeHWClock ) ? "W\n" :
166#endif 166#endif
167 data = "\n"; 167 data = "\n";
168 int len = strlen(data); 168 int len = strlen(data);
169 int total_written = trigger.writeBlock(data,len); 169 int total_written = trigger.writeBlock(data,len);
170 if ( total_written != len ) { 170 if ( total_written != len ) {
171 QMessageBox::critical( 0, QObject::tr( "Out of Space" ), 171 QMessageBox::critical( 0, QObject::tr( "Out of Space" ),
172 QObject::tr( "Unable to schedule alarm.\nFree some memory and try again." ) ); 172 QObject::tr( "Unable to schedule alarm.\nFree some memory and try again." ) );
173 trigger.close(); 173 trigger.close();
174 QFile::remove( trigger.name() ); 174 QFile::remove( trigger.name() );
175 return FALSE; 175 return FALSE;
176 } 176 }
177 return TRUE; 177 return TRUE;
178 } 178 }
179 return FALSE; 179 return FALSE;
180} 180}
181 181
182void TimerReceiverObject::deleteTimer() 182void TimerReceiverObject::deleteTimer()
183{ 183{
184 if ( !atfilename.isEmpty() ) { 184 if ( !atfilename.isEmpty() ) {
185 unlink( atfilename ); 185 unlink( atfilename );
186 atfilename = QString::null; 186 atfilename = QString::null;
187 triggerAtd( FALSE ); 187 triggerAtd( FALSE );
188 } 188 }
189} 189}
190 190
191void TimerReceiverObject::resetTimer() 191void TimerReceiverObject::resetTimer()
192{ 192{
193 const int maxsecs = 2147000; 193 const int maxsecs = 2147000;
194 int total_written; 194 int total_written;
195 QDateTime nearest = TimeConversion::fromUTC(nearestTimerEvent->UTCtime); 195 QDateTime nearest = TimeConversion::fromUTC(nearestTimerEvent->UTCtime);
196 QDateTime now = QDateTime::currentDateTime(); 196 QDateTime now = QDateTime::currentDateTime();
197 if ( nearest < now ) 197 if ( nearest < now )
198 nearest = now; 198 nearest = now;
199 int secs = TimeConversion::secsTo( now, nearest ); 199 int secs = TimeConversion::secsTo( now, nearest );
200 if ( secs > maxsecs ) { 200 if ( secs > maxsecs ) {
201 // too far for millisecond timing 201 // too far for millisecond timing
202 secs = maxsecs; 202 secs = maxsecs;
203 } 203 }
204 204
205 // System timer (needed so that we wake from deep sleep), 205 // System timer (needed so that we wake from deep sleep),
206 // from the Epoch in seconds. 206 // from the Epoch in seconds.
207 // 207 //
208 int at_secs = TimeConversion::toUTC(nearest); 208 int at_secs = TimeConversion::toUTC(nearest);
209 // qDebug("reset timer to %d seconds from Epoch",at_secs); 209 // qDebug("reset timer to %d seconds from Epoch",at_secs);
210 QString fn = atdir + QString::number(at_secs) + "." 210 QString fn = atdir + QString::number(at_secs) + "."
211 + QString::number(getpid()); 211 + QString::number(getpid());
212 if ( fn != atfilename ) { 212 if ( fn != atfilename ) {
213 QFile atfile(fn+".new"); 213 QFile atfile(fn+".new");
214 if ( atfile.open(IO_WriteOnly|IO_Raw) ) { 214 if ( atfile.open(IO_WriteOnly|IO_Raw) ) {
215 // just wake up and delete the at file 215 // just wake up and delete the at file
216 QString cmd = "#!/bin/sh\nrm " + fn; 216 QString cmd = "#!/bin/sh\nrm " + fn;
217 total_written = atfile.writeBlock(cmd.latin1(),cmd.length()); 217 total_written = atfile.writeBlock(cmd.latin1(),cmd.length());
218 if ( total_written != int(cmd.length()) ) { 218 if ( total_written != int(cmd.length()) ) {
219 QMessageBox::critical( 0, tr("Out of Space"), 219 QMessageBox::critical( 0, tr("Out of Space"),
220 tr("Unable to schedule alarm.\n" 220 tr("Unable to schedule alarm.\n"
221 "Please free up space and try again") ); 221 "Please free up space and try again") );
222 atfile.close(); 222 atfile.close();
223 QFile::remove( atfile.name() ); 223 QFile::remove( atfile.name() );
224 return; 224 return;
225 } 225 }
226 atfile.close(); 226 atfile.close();
227 unlink( atfilename ); 227 unlink( atfilename );
228 QDir d; d.rename(fn+".new",fn); 228 QDir d; d.rename(fn+".new",fn);
229 chmod(fn.latin1(),0755); 229 chmod(fn.latin1(),0755);
230 atfilename = fn; 230 atfilename = fn;
231 triggerAtd( FALSE ); 231 triggerAtd( FALSE );
232 } else { 232 } else {
233 qWarning("Cannot open atd file %s",fn.latin1()); 233 qWarning("Cannot open atd file %s",fn.latin1());
234 } 234 }
235 } 235 }
236 // Qt timers (does the actual alarm) 236 // Qt timers (does the actual alarm)
237 // from now in milliseconds 237 // from now in milliseconds
238 // 238 //
239 qDebug("AlarmServer waiting %d seconds",secs); 239 qDebug("AlarmServer waiting %d seconds",secs);
240 startTimer( 1000 * secs + 500 ); 240 startTimer( 1000 * secs + 500 );
241} 241}
242 242
243void TimerReceiverObject::timerEvent( QTimerEvent * ) 243void TimerReceiverObject::timerEvent( QTimerEvent * )
244{ 244{
245 bool needSave = FALSE; 245 bool needSave = FALSE;
246 killTimers(); 246 killTimers();
247 if (nearestTimerEvent) { 247 if (nearestTimerEvent) {
248 if ( nearestTimerEvent->UTCtime 248 if ( nearestTimerEvent->UTCtime
249 <= TimeConversion::toUTC(QDateTime::currentDateTime()) ) { 249 <= TimeConversion::toUTC(QDateTime::currentDateTime()) ) {
250#ifndef QT_NO_COP 250#ifndef QT_NO_COP
251 QCopEnvelope e( nearestTimerEvent->channel, 251 QCopEnvelope e( nearestTimerEvent->channel,
252 nearestTimerEvent->message ); 252 nearestTimerEvent->message );
253 e << TimeConversion::fromUTC( nearestTimerEvent->UTCtime ) 253 e << TimeConversion::fromUTC( nearestTimerEvent->UTCtime )
254 << nearestTimerEvent->data; 254 << nearestTimerEvent->data;
255#endif 255#endif
256 timerEventList.remove( nearestTimerEvent ); 256 timerEventList.remove( nearestTimerEvent );
257 needSave = TRUE; 257 needSave = TRUE;
258 } 258 }
259 setNearestTimerEvent(); 259 setNearestTimerEvent();
260 } else { 260 } else {
261 resetTimer(); 261 resetTimer();
262 } 262 }
263 if ( needSave ) 263 if ( needSave )
264 saveState(); 264 saveState();
265} 265}
266 266
267/*! 267/*!
268 \class AlarmServer alarmserver.h 268 \class AlarmServer alarmserver.h
269 \brief The AlarmServer class allows alarms to be scheduled and unscheduled. 269 \brief The AlarmServer class allows alarms to be scheduled and unscheduled.
270 270
271 Applications can schedule alarms with addAlarm() and can 271 Applications can schedule alarms with addAlarm() and can
272 unschedule alarms with deleteAlarm(). When the time for an alarm 272 unschedule alarms with deleteAlarm(). When the time for an alarm
273 to go off is reached the specified \link qcop.html QCop\endlink 273 to go off is reached the specified \link qcop.html QCop\endlink
274 message is sent on the specified channel (optionally with 274 message is sent on the specified channel (optionally with
275 additional data). 275 additional data).
276 276
277 Scheduling an alarm using this class is important (rather just using 277 Scheduling an alarm using this class is important (rather just using
278 a QTimer) since the machine may be asleep and needs to get woken up using 278 a QTimer) since the machine may be asleep and needs to get woken up using
279 the Linux kernel which implements this at the kernel level to minimize 279 the Linux kernel which implements this at the kernel level to minimize
280 battery usage while asleep. 280 battery usage while asleep.
281 281
282 \ingroup qtopiaemb 282 \ingroup qtopiaemb
283 \sa QCopEnvelope 283 \sa QCopEnvelope
284*/ 284*/
285 285
286/*! 286/*!
287 Schedules an alarm to go off at (or soon after) time \a when. When 287 Schedules an alarm to go off at (or soon after) time \a when. When
288 the alarm goes off, the \link qcop.html QCop\endlink \a message will 288 the alarm goes off, the \link qcop.html QCop\endlink \a message will
289 be sent to \a channel, with \a data as a parameter. 289 be sent to \a channel, with \a data as a parameter.
290 290
291 If this function is called with exactly the same data as a previous 291 If this function is called with exactly the same data as a previous
292 call the subsequent call is ignored, so there is only ever one alarm 292 call the subsequent call is ignored, so there is only ever one alarm
293 with a given set of parameters. 293 with a given set of parameters.
294 294
295 \sa deleteAlarm() 295 \sa deleteAlarm()
296*/ 296*/
297void AlarmServer::addAlarm ( QDateTime when, const QCString& channel, 297void AlarmServer::addAlarm ( QDateTime when, const QCString& channel,
298 const QCString& message, int data) 298 const QCString& message, int data)
299{ 299{
300 if ( qApp->type() == QApplication::GuiServer ) { 300 if ( qApp->type() == QApplication::GuiServer ) {
301 bool needSave = FALSE; 301 bool needSave = FALSE;
302 // Here we are the server so either it has been directly called from 302 // Here we are the server so either it has been directly called from
303 // within the server or it has been sent to us from a client via QCop 303 // within the server or it has been sent to us from a client via QCop
304 if (!timerEventReceiver) 304 if (!timerEventReceiver)
305 timerEventReceiver = new TimerReceiverObject; 305 timerEventReceiver = new TimerReceiverObject;
306 306
307 timerEventItem *newTimerEventItem = new timerEventItem; 307 timerEventItem *newTimerEventItem = new timerEventItem;
308 newTimerEventItem->UTCtime = TimeConversion::toUTC( when ); 308 newTimerEventItem->UTCtime = TimeConversion::toUTC( when );
309 newTimerEventItem->channel = channel; 309 newTimerEventItem->channel = channel;
310 newTimerEventItem->message = message; 310 newTimerEventItem->message = message;
311 newTimerEventItem->data = data; 311 newTimerEventItem->data = data;
312 // explore the case of already having the event in here... 312 // explore the case of already having the event in here...
313 QListIterator<timerEventItem> it( timerEventList ); 313 QListIterator<timerEventItem> it( timerEventList );
314 for ( ; *it; ++it ) 314 for ( ; *it; ++it )
315 if ( *(*it) == *newTimerEventItem ) 315 if ( *(*it) == *newTimerEventItem )
316 return; 316 return;
317 // if we made it here, it is okay to add the item... 317 // if we made it here, it is okay to add the item...
318 timerEventList.append( newTimerEventItem ); 318 timerEventList.append( newTimerEventItem );
319 needSave = TRUE; 319 needSave = TRUE;
320 // quicker than using setNearestTimerEvent() 320 // quicker than using setNearestTimerEvent()
321 if ( nearestTimerEvent ) { 321 if ( nearestTimerEvent ) {
322 if (newTimerEventItem->UTCtime < nearestTimerEvent->UTCtime) { 322 if (newTimerEventItem->UTCtime < nearestTimerEvent->UTCtime) {
323 nearestTimerEvent = newTimerEventItem; 323 nearestTimerEvent = newTimerEventItem;
324 timerEventReceiver->killTimers(); 324 timerEventReceiver->killTimers();
325 timerEventReceiver->resetTimer(); 325 timerEventReceiver->resetTimer();
326 } 326 }
327 } else { 327 } else {
328 nearestTimerEvent = newTimerEventItem; 328 nearestTimerEvent = newTimerEventItem;
329 timerEventReceiver->resetTimer(); 329 timerEventReceiver->resetTimer();
330 } 330 }
331 if ( needSave ) 331 if ( needSave )
332 saveState(); 332 saveState();
333 } else { 333 } else {
334#ifndef QT_NO_COP 334#ifndef QT_NO_COP
335 QCopEnvelope e( "QPE/System", "addAlarm(QDateTime,QCString,QCString,int)" ); 335 QCopEnvelope e( "QPE/System", "addAlarm(QDateTime,QCString,QCString,int)" );
336 e << when << channel << message << data; 336 e << when << channel << message << data;
337#endif 337#endif
338 } 338 }
339} 339}
340 340
341/*! 341/*!
342 Deletes previously scheduled alarms which match \a when, \a channel, 342 Deletes previously scheduled alarms which match \a when, \a channel,
343 \a message, and \a data. 343 \a message, and \a data.
344 344
345 Passing null values for \a when, \a channel, or for the \link 345 Passing null values for \a when, \a channel, or for the \link
346 qcop.html QCop\endlink \a message, acts as a wildcard meaning "any". 346 qcop.html QCop\endlink \a message, acts as a wildcard meaning "any".
347 Similarly, passing -1 for \a data indicates "any". 347 Similarly, passing -1 for \a data indicates "any".
348 348
349 If there is no matching alarm, nothing happens. 349 If there is no matching alarm, nothing happens.
350 350
351 \sa addAlarm() 351 \sa addAlarm()
352 352
353*/ 353*/
354void AlarmServer::deleteAlarm (QDateTime when, const QCString& channel, const QCString& message, int data) 354void AlarmServer::deleteAlarm (QDateTime when, const QCString& channel, const QCString& message, int data)
355{ 355{
356 if ( qApp->type() == QApplication::GuiServer) { 356 if ( qApp->type() == QApplication::GuiServer) {
357 bool needSave = FALSE; 357 bool needSave = FALSE;
358 if ( timerEventReceiver != NULL ) { 358 if ( timerEventReceiver != NULL ) {
359 timerEventReceiver->killTimers(); 359 timerEventReceiver->killTimers();
360 360
361 // iterate over the list of events 361 // iterate over the list of events
362 QListIterator<timerEventItem> it( timerEventList ); 362 QListIterator<timerEventItem> it( timerEventList );
363 time_t deleteTime = TimeConversion::toUTC( when ); 363 time_t deleteTime = TimeConversion::toUTC( when );
364 for ( ; *it; ++it ) { 364 for ( ; *it; ++it ) {
365 // if its a match, delete it 365 // if its a match, delete it
366 if ( ( (*it)->UTCtime == deleteTime || when.isNull() ) 366 if ( ( (*it)->UTCtime == deleteTime || when.isNull() )
367 && ( channel.isNull() || (*it)->channel == channel ) 367 && ( channel.isNull() || (*it)->channel == channel )
368 && ( message.isNull() || (*it)->message == message ) 368 && ( message.isNull() || (*it)->message == message )
369 && ( data==-1 || (*it)->data == data ) ) 369 && ( data==-1 || (*it)->data == data ) )
370 { 370 {
371 // if it's first, then we need to update the timer 371 // if it's first, then we need to update the timer
372 if ( (*it) == nearestTimerEvent ) { 372 if ( (*it) == nearestTimerEvent ) {
373 timerEventList.remove(*it); 373 timerEventList.remove(*it);
374 setNearestTimerEvent(); 374 setNearestTimerEvent();
375 } else { 375 } else {
376 timerEventList.remove(*it); 376 timerEventList.remove(*it);
377 } 377 }
378 needSave = TRUE; 378 needSave = TRUE;
379 } 379 }
380 } 380 }
381 if ( nearestTimerEvent ) 381 if ( nearestTimerEvent )
382 timerEventReceiver->resetTimer(); 382 timerEventReceiver->resetTimer();
383 } 383 }
384 if ( needSave ) 384 if ( needSave )
385 saveState(); 385 saveState();
386 } else { 386 } else {
387#ifndef QT_NO_COP 387#ifndef QT_NO_COP
388 QCopEnvelope e( "QPE/System", "deleteAlarm(QDateTime,QCString,QCString,int)" ); 388 QCopEnvelope e( "QPE/System", "deleteAlarm(QDateTime,QCString,QCString,int)" );
389 e << when << channel << message << data; 389 e << when << channel << message << data;
390#endif 390#endif
391 } 391 }
392} 392}
393 393
394/*! 394/*!
395 Writes the system clock to the hardware clock. 395 Writes the system clock to the hardware clock.
396*/ 396*/
397void Global::writeHWClock() 397void Global::writeHWClock()
398{ 398{
399 if ( !triggerAtd( TRUE ) ) { 399 if ( !triggerAtd( TRUE ) ) {
400 // atd not running? set it ourselves 400 // atd not running? set it ourselves
401 system("/sbin/hwclock --systohc"); // ##### UTC? 401 system("/sbin/hwclock --systohc"); // ##### UTC?
402 } 402 }
403} 403}
diff --git a/library/backend/vcc.y b/library/backend/vcc.y
index 5bcf0cb..6781312 100644
--- a/library/backend/vcc.y
+++ b/library/backend/vcc.y
@@ -1,1208 +1,1208 @@
1%{ 1%{
2 2
3/*************************************************************************** 3/***************************************************************************
4(C) Copyright 1996 Apple Computer, Inc., AT&T Corp., International 4(C) Copyright 1996 Apple Computer, Inc., AT&T Corp., International
5Business Machines Corporation and Siemens Rolm Communications Inc. 5Business Machines Corporation and Siemens Rolm Communications Inc.
6 6
7For purposes of this license notice, the term Licensors shall mean, 7For purposes of this license notice, the term Licensors shall mean,
8collectively, Apple Computer, Inc., AT&T Corp., International 8collectively, Apple Computer, Inc., AT&T Corp., International
9Business Machines Corporation and Siemens Rolm Communications Inc. 9Business Machines Corporation and Siemens Rolm Communications Inc.
10The term Licensor shall mean any of the Licensors. 10The term Licensor shall mean any of the Licensors.
11 11
12Subject to acceptance of the following conditions, permission is hereby 12Subject to acceptance of the following conditions, permission is hereby
13granted by Licensors without the need for written agreement and without 13granted by Licensors without the need for written agreement and without
14license or royalty fees, to use, copy, modify and distribute this 14license or royalty fees, to use, copy, modify and distribute this
15software for any purpose. 15software for any purpose.
16 16
17The above copyright notice and the following four paragraphs must be 17The above copyright notice and the following four paragraphs must be
18reproduced in all copies of this software and any software including 18reproduced in all copies of this software and any software including
19this software. 19this software.
20 20
21THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS AND NO LICENSOR SHALL HAVE 21THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS AND NO LICENSOR SHALL HAVE
22ANY OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR 22ANY OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR
23MODIFICATIONS. 23MODIFICATIONS.
24 24
25IN NO EVENT SHALL ANY LICENSOR BE LIABLE TO ANY PARTY FOR DIRECT, 25IN NO EVENT SHALL ANY LICENSOR BE LIABLE TO ANY PARTY FOR DIRECT,
26INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOST PROFITS ARISING OUT 26INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOST PROFITS ARISING OUT
27OF THE USE OF THIS SOFTWARE EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 27OF THE USE OF THIS SOFTWARE EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
28DAMAGE. 28DAMAGE.
29 29
30EACH LICENSOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, EXPRESS OR IMPLIED, 30EACH LICENSOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, EXPRESS OR IMPLIED,
31INCLUDING BUT NOT LIMITED TO ANY WARRANTY OF NONINFRINGEMENT OR THE 31INCLUDING BUT NOT LIMITED TO ANY WARRANTY OF NONINFRINGEMENT OR THE
32IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 32IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
33PURPOSE. 33PURPOSE.
34 34
35The software is provided with RESTRICTED RIGHTS. Use, duplication, or 35The software is provided with RESTRICTED RIGHTS. Use, duplication, or
36disclosure by the government are subject to restrictions set forth in 36disclosure by the government are subject to restrictions set forth in
37DFARS 252.227-7013 or 48 CFR 52.227-19, as applicable. 37DFARS 252.227-7013 or 48 CFR 52.227-19, as applicable.
38 38
39***************************************************************************/ 39***************************************************************************/
40 40
41/* 41/*
42 * src: vcc.c 42 * src: vcc.c
43 * doc: Parser for vCard and vCalendar. Note that this code is 43 * doc: Parser for vCard and vCalendar. Note that this code is
44 * generated by a yacc parser generator. Generally it should not 44 * generated by a yacc parser generator. Generally it should not
45 * be edited by hand. The real source is vcc.y. The #line directives 45 * be edited by hand. The real source is vcc.y. The #line directives
46 * can be commented out here to make it easier to trace through 46 * can be commented out here to make it easier to trace through
47 * in a debugger. However, if a bug is found it should 47 * in a debugger. However, if a bug is found it should
48 * be fixed in vcc.y and this file regenerated. 48 * be fixed in vcc.y and this file regenerated.
49 */ 49 */
50 50
51 51
52/* debugging utilities */ 52/* debugging utilities */
53#if __DEBUG 53#if __DEBUG
54#define DBG_(x) printf x 54#define DBG_(x) printf x
55#else 55#else
56#define DBG_(x) 56#define DBG_(x)
57#endif 57#endif
58 58
59/**** External Functions ****/ 59/**** External Functions ****/
60 60
61/* assign local name to parser variables and functions so that 61/* assign local name to parser variables and functions so that
62 we can use more than one yacc based parser. 62 we can use more than one yacc based parser.
63*/ 63*/
64 64
65#if 0 65#if 0
66#define yyparse mime_parse 66#define yyparse mime_parse
67#define yylex mime_lex 67#define yylex mime_lex
68#define yyerror mime_error 68#define yyerror mime_error
69#define yychar mime_char 69#define yychar mime_char
70/* #define p_yyval p_mime_val */ 70/* #define p_yyval p_mime_val */
71#undef yyval 71#undef yyval
72#define yyval mime_yyval 72#define yyval mime_yyval
73/* #define p_yylval p_mime_lval */ 73/* #define p_yylval p_mime_lval */
74#undef yylval 74#undef yylval
75#define yylval mime_yylval 75#define yylval mime_yylval
76#define yydebug mime_debug 76#define yydebug mime_debug
77#define yynerrs mime_nerrs 77#define yynerrs mime_nerrs
78#define yyerrflag mime_errflag 78#define yyerrflag mime_errflag
79#define yyss mime_ss 79#define yyss mime_ss
80#define yyssp mime_ssp 80#define yyssp mime_ssp
81#define yyvs mime_vs 81#define yyvs mime_vs
82#define yyvsp mime_vsp 82#define yyvsp mime_vsp
83#define yylhs mime_lhs 83#define yylhs mime_lhs
84#define yylen mime_len 84#define yylen mime_len
85#define yydefred mime_defred 85#define yydefred mime_defred
86#define yydgoto mime_dgoto 86#define yydgoto mime_dgoto
87#define yysindex mime_sindex 87#define yysindex mime_sindex
88#define yyrindex mime_rindex 88#define yyrindex mime_rindex
89#define yygindex mime_gindex 89#define yygindex mime_gindex
90#define yytable mime_table 90#define yytable mime_table
91#define yycheck mime_check 91#define yycheck mime_check
92#define yyname mime_name 92#define yyname mime_name
93#define yyrule mime_rule 93#define yyrule mime_rule
94#ifdef YYPREFIX 94#ifdef YYPREFIX
95#undef YYPREFIX 95#undef YYPREFIX
96#endif 96#endif
97#define YYPREFIX "mime_" 97#define YYPREFIX "mime_"
98#endif 98#endif
99 99
100 100
101#ifndef _NO_LINE_FOLDING 101#ifndef _NO_LINE_FOLDING
102#define _SUPPORT_LINE_FOLDING 1 102#define _SUPPORT_LINE_FOLDING 1
103#endif 103#endif
104 104
105/* undef below if compile with MFC */ 105/* undef below if compile with MFC */
106/* #define INCLUDEMFC 1 */ 106/* #define INCLUDEMFC 1 */
107 107
108#if defined(WIN32) || defined(_WIN32) 108#if defined(WIN32) || defined(_WIN32)
109#ifdef INCLUDEMFC 109#ifdef INCLUDEMFC
110#include <afx.h> 110#include <afx.h>
111#endif 111#endif
112#endif 112#endif
113 113
114#include <string.h> 114#include <string.h>
115#ifndef __MWERKS__ 115#ifndef __MWERKS__
116#include <stdlib.h> 116#include <stdlib.h>
117#endif 117#endif
118#include <stdio.h> 118#include <stdio.h>
119#include <stdlib.h> 119#include <stdlib.h>
120#include <ctype.h> 120#include <ctype.h>
121 121
122//#ifdef PALMTOPCENTER 122//#ifdef PALMTOPCENTER
123//#include <qpe/vobject_p.h> 123//#include <qpe/vobject_p.h>
124//#else 124//#else
125#include "vobject_p.h" 125#include <qtopia/private/vobject_p.h>
126//#endif 126//#endif
127 127
128/**** Types, Constants ****/ 128/**** Types, Constants ****/
129 129
130 #define YYDEBUG 0/* 1 to compile in some debugging code */ 130 #define YYDEBUG 0/* 1 to compile in some debugging code */
131 #define MAXTOKEN 256/* maximum token (line) length */ 131 #define MAXTOKEN 256/* maximum token (line) length */
132 #define YYSTACKSIZE 100// ~unref ? 132 #define YYSTACKSIZE 100// ~unref ?
133 #define MAXLEVEL 10/* max # of nested objects parseable */ 133 #define MAXLEVEL 10/* max # of nested objects parseable */
134 /* (includes outermost) */ 134 /* (includes outermost) */
135 135
136 136
137/**** Global Variables ****/ 137/**** Global Variables ****/
138int mime_lineNum, mime_numErrors; /* yyerror() can use these */ 138int mime_lineNum, mime_numErrors; /* yyerror() can use these */
139static VObject* vObjList; 139static VObject* vObjList;
140static VObject *curProp; 140static VObject *curProp;
141static VObject *curObj; 141static VObject *curObj;
142static VObject* ObjStack[MAXLEVEL]; 142static VObject* ObjStack[MAXLEVEL];
143static int ObjStackTop; 143static int ObjStackTop;
144 144
145 145
146/* A helpful utility for the rest of the app. */ 146/* A helpful utility for the rest of the app. */
147#if __CPLUSPLUS__ 147#if __CPLUSPLUS__
148extern "C" { 148extern "C" {
149#endif 149#endif
150 150
151 extern void yyerror(char *s); 151 extern void yyerror(char *s);
152 152
153#if __CPLUSPLUS__ 153#if __CPLUSPLUS__
154 }; 154 };
155#endif 155#endif
156 156
157int yyparse(); 157int yyparse();
158 158
159enum LexMode { 159enum LexMode {
160 L_NORMAL, 160 L_NORMAL,
161 L_VCARD, 161 L_VCARD,
162 L_VCAL, 162 L_VCAL,
163 L_VEVENT, 163 L_VEVENT,
164 L_VTODO, 164 L_VTODO,
165 L_VALUES, 165 L_VALUES,
166 L_BASE64, 166 L_BASE64,
167 L_QUOTED_PRINTABLE 167 L_QUOTED_PRINTABLE
168 }; 168 };
169 169
170/**** Private Forward Declarations ****/ 170/**** Private Forward Declarations ****/
171static int pushVObject(const char *prop); 171static int pushVObject(const char *prop);
172static VObject* popVObject(); 172static VObject* popVObject();
173static void lexPopMode(int top); 173static void lexPopMode(int top);
174static int lexWithinMode(enum LexMode mode); 174static int lexWithinMode(enum LexMode mode);
175static void lexPushMode(enum LexMode mode); 175static void lexPushMode(enum LexMode mode);
176static void enterProps(const char *s); 176static void enterProps(const char *s);
177static void enterAttr(const char *s1, const char *s2); 177static void enterAttr(const char *s1, const char *s2);
178static void enterValues(const char *value); 178static void enterValues(const char *value);
179#define mime_error yyerror 179#define mime_error yyerror
180void mime_error(char *s); 180void mime_error(char *s);
181void mime_error_(char *s); 181void mime_error_(char *s);
182 182
183%} 183%}
184 184
185/***************************************************************************/ 185/***************************************************************************/
186/*** The grammar ****/ 186/*** The grammar ****/
187/***************************************************************************/ 187/***************************************************************************/
188 188
189%union { 189%union {
190 char *str; 190 char *str;
191 VObject *vobj; 191 VObject *vobj;
192 } 192 }
193 193
194%token 194%token
195 EQ COLON DOT SEMICOLON SPACE HTAB LINESEP NEWLINE 195 EQ COLON DOT SEMICOLON SPACE HTAB LINESEP NEWLINE
196 BEGIN_VCARD END_VCARD BEGIN_VCAL END_VCAL 196 BEGIN_VCARD END_VCARD BEGIN_VCAL END_VCAL
197 BEGIN_VEVENT END_VEVENT BEGIN_VTODO END_VTODO 197 BEGIN_VEVENT END_VEVENT BEGIN_VTODO END_VTODO
198 ID 198 ID
199 199
200/* 200/*
201 * NEWLINE is the token that would occur outside a vCard, 201 * NEWLINE is the token that would occur outside a vCard,
202 * while LINESEP is the token that would occur inside a vCard. 202 * while LINESEP is the token that would occur inside a vCard.
203 */ 203 */
204 204
205%token <str> 205%token <str>
206 STRING ID 206 STRING ID
207 207
208%type <str> name value 208%type <str> name value
209 209
210%type <vobj> vcard vcal vobject 210%type <vobj> vcard vcal vobject
211 211
212%start mime 212%start mime
213 213
214%% 214%%
215 215
216 216
217mime: vobjects 217mime: vobjects
218 ; 218 ;
219 219
220vobjects: vobjects vobject 220vobjects: vobjects vobject
221 { addList(&vObjList, $2); curObj = 0; } 221 { addList(&vObjList, $2); curObj = 0; }
222 | vobject 222 | vobject
223 { addList(&vObjList, $1); curObj = 0; } 223 { addList(&vObjList, $1); curObj = 0; }
224 ; 224 ;
225 225
226vobject: vcard 226vobject: vcard
227 | vcal 227 | vcal
228 ; 228 ;
229 229
230vcard: 230vcard:
231 BEGIN_VCARD 231 BEGIN_VCARD
232 { 232 {
233 lexPushMode(L_VCARD); 233 lexPushMode(L_VCARD);
234 if (!pushVObject(VCCardProp)) YYERROR; 234 if (!pushVObject(VCCardProp)) YYERROR;
235 } 235 }
236 items END_VCARD 236 items END_VCARD
237 { 237 {
238 lexPopMode(0); 238 lexPopMode(0);
239 $$ = popVObject(); 239 $$ = popVObject();
240 } 240 }
241 | BEGIN_VCARD 241 | BEGIN_VCARD
242 { 242 {
243 lexPushMode(L_VCARD); 243 lexPushMode(L_VCARD);
244 if (!pushVObject(VCCardProp)) YYERROR; 244 if (!pushVObject(VCCardProp)) YYERROR;
245 } 245 }
246 END_VCARD 246 END_VCARD
247 { 247 {
248 lexPopMode(0); 248 lexPopMode(0);
249 $$ = popVObject(); 249 $$ = popVObject();
250 } 250 }
251 ; 251 ;
252 252
253items: items item 253items: items item
254 | item 254 | item
255 ; 255 ;
256 256
257item: prop COLON 257item: prop COLON
258 { 258 {
259 lexPushMode(L_VALUES); 259 lexPushMode(L_VALUES);
260 } 260 }
261 values LINESEP 261 values LINESEP
262 { 262 {
263 if (lexWithinMode(L_BASE64) || lexWithinMode(L_QUOTED_PRINTABLE)) 263 if (lexWithinMode(L_BASE64) || lexWithinMode(L_QUOTED_PRINTABLE))
264 lexPopMode(0); 264 lexPopMode(0);
265 lexPopMode(0); 265 lexPopMode(0);
266 } 266 }
267 | error 267 | error
268 ; 268 ;
269 269
270prop: name 270prop: name
271 { 271 {
272 enterProps($1); 272 enterProps($1);
273 } 273 }
274 attr_params 274 attr_params
275 | name 275 | name
276 { 276 {
277 enterProps($1); 277 enterProps($1);
278 } 278 }
279 ; 279 ;
280 280
281attr_params: attr_params attr_param 281attr_params: attr_params attr_param
282 | attr_param 282 | attr_param
283 ; 283 ;
284 284
285attr_param: SEMICOLON attr 285attr_param: SEMICOLON attr
286 ; 286 ;
287 287
288attr: name 288attr: name
289 { 289 {
290 enterAttr($1,0); 290 enterAttr($1,0);
291 } 291 }
292 | name EQ name 292 | name EQ name
293 { 293 {
294 enterAttr($1,$3); 294 enterAttr($1,$3);
295 295
296 } 296 }
297 ; 297 ;
298 298
299name: ID 299name: ID
300 ; 300 ;
301 301
302values: value SEMICOLON { enterValues($1); } values 302values: value SEMICOLON { enterValues($1); } values
303 | value 303 | value
304 { enterValues($1); } 304 { enterValues($1); }
305 ; 305 ;
306 306
307value: STRING 307value: STRING
308 | 308 |
309 { $$ = 0; } 309 { $$ = 0; }
310 ; 310 ;
311 311
312vcal: 312vcal:
313 BEGIN_VCAL 313 BEGIN_VCAL
314 { if (!pushVObject(VCCalProp)) YYERROR; } 314 { if (!pushVObject(VCCalProp)) YYERROR; }
315 calitems 315 calitems
316 END_VCAL 316 END_VCAL
317 { $$ = popVObject(); } 317 { $$ = popVObject(); }
318 | BEGIN_VCAL 318 | BEGIN_VCAL
319 { if (!pushVObject(VCCalProp)) YYERROR; } 319 { if (!pushVObject(VCCalProp)) YYERROR; }
320 END_VCAL 320 END_VCAL
321 { $$ = popVObject(); } 321 { $$ = popVObject(); }
322 ; 322 ;
323 323
324calitems: calitems calitem 324calitems: calitems calitem
325 | calitem 325 | calitem
326 ; 326 ;
327 327
328calitem: 328calitem:
329 eventitem 329 eventitem
330 | todoitem 330 | todoitem
331 | items 331 | items
332 ; 332 ;
333 333
334eventitem: 334eventitem:
335 BEGIN_VEVENT 335 BEGIN_VEVENT
336 { 336 {
337 lexPushMode(L_VEVENT); 337 lexPushMode(L_VEVENT);
338 if (!pushVObject(VCEventProp)) YYERROR; 338 if (!pushVObject(VCEventProp)) YYERROR;
339 } 339 }
340 items 340 items
341 END_VEVENT 341 END_VEVENT
342 { 342 {
343 lexPopMode(0); 343 lexPopMode(0);
344 popVObject(); 344 popVObject();
345 } 345 }
346 | BEGIN_VEVENT 346 | BEGIN_VEVENT
347 { 347 {
348 lexPushMode(L_VEVENT); 348 lexPushMode(L_VEVENT);
349 if (!pushVObject(VCEventProp)) YYERROR; 349 if (!pushVObject(VCEventProp)) YYERROR;
350 } 350 }
351 END_VEVENT 351 END_VEVENT
352 { 352 {
353 lexPopMode(0); 353 lexPopMode(0);
354 popVObject(); 354 popVObject();
355 } 355 }
356 ; 356 ;
357 357
358todoitem: 358todoitem:
359 BEGIN_VTODO 359 BEGIN_VTODO
360 { 360 {
361 lexPushMode(L_VTODO); 361 lexPushMode(L_VTODO);
362 if (!pushVObject(VCTodoProp)) YYERROR; 362 if (!pushVObject(VCTodoProp)) YYERROR;
363 } 363 }
364 items 364 items
365 END_VTODO 365 END_VTODO
366 { 366 {
367 lexPopMode(0); 367 lexPopMode(0);
368 popVObject(); 368 popVObject();
369 } 369 }
370 | BEGIN_VTODO 370 | BEGIN_VTODO
371 { 371 {
372 lexPushMode(L_VTODO); 372 lexPushMode(L_VTODO);
373 if (!pushVObject(VCTodoProp)) YYERROR; 373 if (!pushVObject(VCTodoProp)) YYERROR;
374 } 374 }
375 END_VTODO 375 END_VTODO
376 { 376 {
377 lexPopMode(0); 377 lexPopMode(0);
378 popVObject(); 378 popVObject();
379 } 379 }
380 ; 380 ;
381 381
382%% 382%%
383/*------------------------------------*/ 383/*------------------------------------*/
384static int pushVObject(const char *prop) 384static int pushVObject(const char *prop)
385 { 385 {
386 VObject *newObj; 386 VObject *newObj;
387 if (ObjStackTop == MAXLEVEL) 387 if (ObjStackTop == MAXLEVEL)
388 return FALSE; 388 return FALSE;
389 389
390 ObjStack[++ObjStackTop] = curObj; 390 ObjStack[++ObjStackTop] = curObj;
391 391
392 if (curObj) { 392 if (curObj) {
393 newObj = addProp(curObj,prop); 393 newObj = addProp(curObj,prop);
394 curObj = newObj; 394 curObj = newObj;
395 } 395 }
396 else 396 else
397 curObj = newVObject(prop); 397 curObj = newVObject(prop);
398 398
399 return TRUE; 399 return TRUE;
400 } 400 }
401 401
402 402
403/*---------------------------------------*/ 403/*---------------------------------------*/
404/* This pops the recently built vCard off the stack and returns it. */ 404/* This pops the recently built vCard off the stack and returns it. */
405static VObject* popVObject() 405static VObject* popVObject()
406 { 406 {
407 VObject *oldObj; 407 VObject *oldObj;
408 if (ObjStackTop < 0) { 408 if (ObjStackTop < 0) {
409 yyerror("pop on empty Object Stack\n"); 409 yyerror("pop on empty Object Stack\n");
410 return 0; 410 return 0;
411 } 411 }
412 oldObj = curObj; 412 oldObj = curObj;
413 curObj = ObjStack[ObjStackTop--]; 413 curObj = ObjStack[ObjStackTop--];
414 414
415 return oldObj; 415 return oldObj;
416 } 416 }
417 417
418 418
419static void enterValues(const char *value) 419static void enterValues(const char *value)
420 { 420 {
421 if (fieldedProp && *fieldedProp) { 421 if (fieldedProp && *fieldedProp) {
422 if (value) { 422 if (value) {
423 addPropValue(curProp,*fieldedProp,value); 423 addPropValue(curProp,*fieldedProp,value);
424 } 424 }
425 /* else this field is empty, advance to next field */ 425 /* else this field is empty, advance to next field */
426 fieldedProp++; 426 fieldedProp++;
427 } 427 }
428 else { 428 else {
429 if (value) { 429 if (value) {
430 setVObjectStringZValue_(curProp,strdup( value )); 430 setVObjectStringZValue_(curProp,strdup( value ));
431 } 431 }
432 } 432 }
433 deleteStr(value); 433 deleteStr(value);
434 } 434 }
435 435
436static void enterProps(const char *s) 436static void enterProps(const char *s)
437 { 437 {
438 curProp = addGroup(curObj,s); 438 curProp = addGroup(curObj,s);
439 deleteStr(s); 439 deleteStr(s);
440 } 440 }
441 441
442static void enterAttr(const char *s1, const char *s2) 442static void enterAttr(const char *s1, const char *s2)
443 { 443 {
444 const char *p1, *p2; 444 const char *p1, *p2;
445 p1 = lookupProp_(s1); 445 p1 = lookupProp_(s1);
446 if (s2) { 446 if (s2) {
447 VObject *a; 447 VObject *a;
448 p2 = lookupProp_(s2); 448 p2 = lookupProp_(s2);
449 a = addProp(curProp,p1); 449 a = addProp(curProp,p1);
450 setVObjectStringZValue(a,p2); 450 setVObjectStringZValue(a,p2);
451 } 451 }
452 else 452 else
453 addProp(curProp,p1); 453 addProp(curProp,p1);
454 if (qstricmp(p1,VCBase64Prop) == 0 || (s2 && qstricmp(p2,VCBase64Prop)==0)) 454 if (qstricmp(p1,VCBase64Prop) == 0 || (s2 && qstricmp(p2,VCBase64Prop)==0))
455 lexPushMode(L_BASE64); 455 lexPushMode(L_BASE64);
456 else if (qstricmp(p1,VCQuotedPrintableProp) == 0 456 else if (qstricmp(p1,VCQuotedPrintableProp) == 0
457 || (s2 && qstricmp(p2,VCQuotedPrintableProp)==0)) 457 || (s2 && qstricmp(p2,VCQuotedPrintableProp)==0))
458 lexPushMode(L_QUOTED_PRINTABLE); 458 lexPushMode(L_QUOTED_PRINTABLE);
459 deleteStr(s1); deleteStr(s2); 459 deleteStr(s1); deleteStr(s2);
460 } 460 }
461 461
462 462
463#define MAX_LEX_LOOKAHEAD_0 32 463#define MAX_LEX_LOOKAHEAD_0 32
464#define MAX_LEX_LOOKAHEAD 64 464#define MAX_LEX_LOOKAHEAD 64
465#define MAX_LEX_MODE_STACK_SIZE 10 465#define MAX_LEX_MODE_STACK_SIZE 10
466#define LEXMODE() (lexBuf.lexModeStack[lexBuf.lexModeStackTop]) 466#define LEXMODE() (lexBuf.lexModeStack[lexBuf.lexModeStackTop])
467 467
468struct LexBuf { 468struct LexBuf {
469 /* input */ 469 /* input */
470#ifdef INCLUDEMFC 470#ifdef INCLUDEMFC
471 CFile *inputFile; 471 CFile *inputFile;
472#else 472#else
473 FILE *inputFile; 473 FILE *inputFile;
474#endif 474#endif
475 char *inputString; 475 char *inputString;
476 unsigned long curPos; 476 unsigned long curPos;
477 unsigned long inputLen; 477 unsigned long inputLen;
478 /* lookahead buffer */ 478 /* lookahead buffer */
479 /* -- lookahead buffer is short instead of char so that EOF 479 /* -- lookahead buffer is short instead of char so that EOF
480 / can be represented correctly. 480 / can be represented correctly.
481 */ 481 */
482 unsigned long len; 482 unsigned long len;
483 short buf[MAX_LEX_LOOKAHEAD]; 483 short buf[MAX_LEX_LOOKAHEAD];
484 unsigned long getPtr; 484 unsigned long getPtr;
485 /* context stack */ 485 /* context stack */
486 unsigned long lexModeStackTop; 486 unsigned long lexModeStackTop;
487 enum LexMode lexModeStack[MAX_LEX_MODE_STACK_SIZE]; 487 enum LexMode lexModeStack[MAX_LEX_MODE_STACK_SIZE];
488 /* token buffer */ 488 /* token buffer */
489 unsigned long maxToken; 489 unsigned long maxToken;
490 char *strs; 490 char *strs;
491 unsigned long strsLen; 491 unsigned long strsLen;
492 } lexBuf; 492 } lexBuf;
493 493
494static void lexPushMode(enum LexMode mode) 494static void lexPushMode(enum LexMode mode)
495 { 495 {
496 if (lexBuf.lexModeStackTop == (MAX_LEX_MODE_STACK_SIZE-1)) 496 if (lexBuf.lexModeStackTop == (MAX_LEX_MODE_STACK_SIZE-1))
497 yyerror("lexical context stack overflow"); 497 yyerror("lexical context stack overflow");
498 else { 498 else {
499 lexBuf.lexModeStack[++lexBuf.lexModeStackTop] = mode; 499 lexBuf.lexModeStack[++lexBuf.lexModeStackTop] = mode;
500 } 500 }
501 } 501 }
502 502
503static void lexPopMode(int top) 503static void lexPopMode(int top)
504 { 504 {
505 /* special case of pop for ease of error recovery -- this 505 /* special case of pop for ease of error recovery -- this
506 version will never underflow */ 506 version will never underflow */
507 if (top) 507 if (top)
508 lexBuf.lexModeStackTop = 0; 508 lexBuf.lexModeStackTop = 0;
509 else 509 else
510 if (lexBuf.lexModeStackTop > 0) lexBuf.lexModeStackTop--; 510 if (lexBuf.lexModeStackTop > 0) lexBuf.lexModeStackTop--;
511 } 511 }
512 512
513static int lexWithinMode(enum LexMode mode) { 513static int lexWithinMode(enum LexMode mode) {
514 unsigned long i; 514 unsigned long i;
515 for (i=0;i<lexBuf.lexModeStackTop;i++) 515 for (i=0;i<lexBuf.lexModeStackTop;i++)
516 if (mode == lexBuf.lexModeStack[i]) return 1; 516 if (mode == lexBuf.lexModeStack[i]) return 1;
517 return 0; 517 return 0;
518 } 518 }
519 519
520static int lexGetc_() 520static int lexGetc_()
521 { 521 {
522 /* get next char from input, no buffering. */ 522 /* get next char from input, no buffering. */
523 if (lexBuf.curPos == lexBuf.inputLen) 523 if (lexBuf.curPos == lexBuf.inputLen)
524 return EOF; 524 return EOF;
525 else if (lexBuf.inputString) 525 else if (lexBuf.inputString)
526 return *(lexBuf.inputString + lexBuf.curPos++); 526 return *(lexBuf.inputString + lexBuf.curPos++);
527 else { 527 else {
528#ifdef INCLUDEMFC 528#ifdef INCLUDEMFC
529 char result; 529 char result;
530 return lexBuf.inputFile->Read(&result, 1) == 1 ? result : EOF; 530 return lexBuf.inputFile->Read(&result, 1) == 1 ? result : EOF;
531#else 531#else
532 return fgetc(lexBuf.inputFile); 532 return fgetc(lexBuf.inputFile);
533#endif 533#endif
534 } 534 }
535 } 535 }
536 536
537static int lexGeta() 537static int lexGeta()
538 { 538 {
539 ++lexBuf.len; 539 ++lexBuf.len;
540 return (lexBuf.buf[lexBuf.getPtr] = lexGetc_()); 540 return (lexBuf.buf[lexBuf.getPtr] = lexGetc_());
541 } 541 }
542 542
543static int lexGeta_(int i) 543static int lexGeta_(int i)
544 { 544 {
545 ++lexBuf.len; 545 ++lexBuf.len;
546 return (lexBuf.buf[(lexBuf.getPtr+i)%MAX_LEX_LOOKAHEAD] = lexGetc_()); 546 return (lexBuf.buf[(lexBuf.getPtr+i)%MAX_LEX_LOOKAHEAD] = lexGetc_());
547 } 547 }
548 548
549static void lexSkipLookahead() { 549static void lexSkipLookahead() {
550 if (lexBuf.len > 0 && lexBuf.buf[lexBuf.getPtr]!=EOF) { 550 if (lexBuf.len > 0 && lexBuf.buf[lexBuf.getPtr]!=EOF) {
551 /* don't skip EOF. */ 551 /* don't skip EOF. */
552 lexBuf.getPtr = (lexBuf.getPtr + 1) % MAX_LEX_LOOKAHEAD; 552 lexBuf.getPtr = (lexBuf.getPtr + 1) % MAX_LEX_LOOKAHEAD;
553 lexBuf.len--; 553 lexBuf.len--;
554 } 554 }
555 } 555 }
556 556
557static int lexLookahead() { 557static int lexLookahead() {
558 int c = (lexBuf.len)? 558 int c = (lexBuf.len)?
559 lexBuf.buf[lexBuf.getPtr]: 559 lexBuf.buf[lexBuf.getPtr]:
560 lexGeta(); 560 lexGeta();
561 /* do the \r\n -> \n or \r -> \n translation here */ 561 /* do the \r\n -> \n or \r -> \n translation here */
562 if (c == '\r') { 562 if (c == '\r') {
563 int a = (lexBuf.len>1)? 563 int a = (lexBuf.len>1)?
564 lexBuf.buf[(lexBuf.getPtr+1)%MAX_LEX_LOOKAHEAD]: 564 lexBuf.buf[(lexBuf.getPtr+1)%MAX_LEX_LOOKAHEAD]:
565 lexGeta_(1); 565 lexGeta_(1);
566 if (a == '\n') { 566 if (a == '\n') {
567 lexSkipLookahead(); 567 lexSkipLookahead();
568 } 568 }
569 lexBuf.buf[lexBuf.getPtr] = c = '\n'; 569 lexBuf.buf[lexBuf.getPtr] = c = '\n';
570 } 570 }
571 else if (c == '\n') { 571 else if (c == '\n') {
572 int a = (lexBuf.len>1)? 572 int a = (lexBuf.len>1)?
573 lexBuf.buf[lexBuf.getPtr+1]: 573 lexBuf.buf[lexBuf.getPtr+1]:
574 lexGeta_(1); 574 lexGeta_(1);
575 if (a == '\r') { 575 if (a == '\r') {
576 lexSkipLookahead(); 576 lexSkipLookahead();
577 } 577 }
578 lexBuf.buf[lexBuf.getPtr] = '\n'; 578 lexBuf.buf[lexBuf.getPtr] = '\n';
579 } 579 }
580 return c; 580 return c;
581 } 581 }
582 582
583static int lexGetc() { 583static int lexGetc() {
584 int c = lexLookahead(); 584 int c = lexLookahead();
585 if (lexBuf.len > 0 && lexBuf.buf[lexBuf.getPtr]!=EOF) { 585 if (lexBuf.len > 0 && lexBuf.buf[lexBuf.getPtr]!=EOF) {
586 /* EOF will remain in lookahead buffer */ 586 /* EOF will remain in lookahead buffer */
587 lexBuf.getPtr = (lexBuf.getPtr + 1) % MAX_LEX_LOOKAHEAD; 587 lexBuf.getPtr = (lexBuf.getPtr + 1) % MAX_LEX_LOOKAHEAD;
588 lexBuf.len--; 588 lexBuf.len--;
589 } 589 }
590 return c; 590 return c;
591 } 591 }
592 592
593static void lexSkipLookaheadWord() { 593static void lexSkipLookaheadWord() {
594 if (lexBuf.strsLen <= lexBuf.len) { 594 if (lexBuf.strsLen <= lexBuf.len) {
595 lexBuf.len -= lexBuf.strsLen; 595 lexBuf.len -= lexBuf.strsLen;
596 lexBuf.getPtr = (lexBuf.getPtr + lexBuf.strsLen) % MAX_LEX_LOOKAHEAD; 596 lexBuf.getPtr = (lexBuf.getPtr + lexBuf.strsLen) % MAX_LEX_LOOKAHEAD;
597 } 597 }
598 } 598 }
599 599
600static void lexClearToken() 600static void lexClearToken()
601 { 601 {
602 lexBuf.strsLen = 0; 602 lexBuf.strsLen = 0;
603 } 603 }
604 604
605static void lexAppendc(int c) 605static void lexAppendc(int c)
606 { 606 {
607 lexBuf.strs[lexBuf.strsLen] = c; 607 lexBuf.strs[lexBuf.strsLen] = c;
608 /* append up to zero termination */ 608 /* append up to zero termination */
609 if (c == 0) return; 609 if (c == 0) return;
610 lexBuf.strsLen++; 610 lexBuf.strsLen++;
611 if (lexBuf.strsLen > lexBuf.maxToken) { 611 if (lexBuf.strsLen > lexBuf.maxToken) {
612 /* double the token string size */ 612 /* double the token string size */
613 lexBuf.maxToken <<= 1; 613 lexBuf.maxToken <<= 1;
614 lexBuf.strs = (char*) realloc(lexBuf.strs,(size_t)lexBuf.maxToken); 614 lexBuf.strs = (char*) realloc(lexBuf.strs,(size_t)lexBuf.maxToken);
615 } 615 }
616 } 616 }
617 617
618static char* lexStr() { 618static char* lexStr() {
619 return dupStr(lexBuf.strs,(size_t)lexBuf.strsLen+1); 619 return dupStr(lexBuf.strs,(size_t)lexBuf.strsLen+1);
620 } 620 }
621 621
622static void lexSkipWhite() { 622static void lexSkipWhite() {
623 int c = lexLookahead(); 623 int c = lexLookahead();
624 while (c == ' ' || c == '\t') { 624 while (c == ' ' || c == '\t') {
625 lexSkipLookahead(); 625 lexSkipLookahead();
626 c = lexLookahead(); 626 c = lexLookahead();
627 } 627 }
628 } 628 }
629 629
630static char* lexGetWord() { 630static char* lexGetWord() {
631 int c; 631 int c;
632 lexSkipWhite(); 632 lexSkipWhite();
633 lexClearToken(); 633 lexClearToken();
634 c = lexLookahead(); 634 c = lexLookahead();
635 while (c != EOF && !strchr("\t\n ;:=",c)) { 635 while (c != EOF && !strchr("\t\n ;:=",c)) {
636 lexAppendc(c); 636 lexAppendc(c);
637 lexSkipLookahead(); 637 lexSkipLookahead();
638 c = lexLookahead(); 638 c = lexLookahead();
639 } 639 }
640 lexAppendc(0); 640 lexAppendc(0);
641 return lexStr(); 641 return lexStr();
642 } 642 }
643 643
644static void lexPushLookaheadc(int c) { 644static void lexPushLookaheadc(int c) {
645 int putptr; 645 int putptr;
646 /* can't putback EOF, because it never leaves lookahead buffer */ 646 /* can't putback EOF, because it never leaves lookahead buffer */
647 if (c == EOF) return; 647 if (c == EOF) return;
648 putptr = (int)lexBuf.getPtr - 1; 648 putptr = (int)lexBuf.getPtr - 1;
649 if (putptr < 0) putptr += MAX_LEX_LOOKAHEAD; 649 if (putptr < 0) putptr += MAX_LEX_LOOKAHEAD;
650 lexBuf.getPtr = putptr; 650 lexBuf.getPtr = putptr;
651 lexBuf.buf[putptr] = c; 651 lexBuf.buf[putptr] = c;
652 lexBuf.len += 1; 652 lexBuf.len += 1;
653 } 653 }
654 654
655static char* lexLookaheadWord() { 655static char* lexLookaheadWord() {
656 /* this function can lookahead word with max size of MAX_LEX_LOOKAHEAD_0 656 /* this function can lookahead word with max size of MAX_LEX_LOOKAHEAD_0
657 / and thing bigger than that will stop the lookahead and return 0; 657 / and thing bigger than that will stop the lookahead and return 0;
658 / leading white spaces are not recoverable. 658 / leading white spaces are not recoverable.
659 */ 659 */
660 int c; 660 int c;
661 int len = 0; 661 int len = 0;
662 int curgetptr = 0; 662 int curgetptr = 0;
663 lexSkipWhite(); 663 lexSkipWhite();
664 lexClearToken(); 664 lexClearToken();
665 curgetptr = (int)lexBuf.getPtr;// remember! 665 curgetptr = (int)lexBuf.getPtr;// remember!
666 while (len < (MAX_LEX_LOOKAHEAD_0)) { 666 while (len < (MAX_LEX_LOOKAHEAD_0)) {
667 c = lexGetc(); 667 c = lexGetc();
668 len++; 668 len++;
669 if (c == EOF || strchr("\t\n ;:=", c)) { 669 if (c == EOF || strchr("\t\n ;:=", c)) {
670 lexAppendc(0); 670 lexAppendc(0);
671 /* restore lookahead buf. */ 671 /* restore lookahead buf. */
672 lexBuf.len += len; 672 lexBuf.len += len;
673 lexBuf.getPtr = curgetptr; 673 lexBuf.getPtr = curgetptr;
674 return lexStr(); 674 return lexStr();
675 } 675 }
676 else 676 else
677 lexAppendc(c); 677 lexAppendc(c);
678 } 678 }
679 lexBuf.len += len;/* char that has been moved to lookahead buffer */ 679 lexBuf.len += len;/* char that has been moved to lookahead buffer */
680 lexBuf.getPtr = curgetptr; 680 lexBuf.getPtr = curgetptr;
681 return 0; 681 return 0;
682 } 682 }
683 683
684#ifdef _SUPPORT_LINE_FOLDING 684#ifdef _SUPPORT_LINE_FOLDING
685static void handleMoreRFC822LineBreak(int c) { 685static void handleMoreRFC822LineBreak(int c) {
686 /* suport RFC 822 line break in cases like 686 /* suport RFC 822 line break in cases like
687 *ADR: foo; 687 *ADR: foo;
688 * morefoo; 688 * morefoo;
689 * more foo; 689 * more foo;
690 */ 690 */
691 if (c == ';') { 691 if (c == ';') {
692 int a; 692 int a;
693 lexSkipLookahead(); 693 lexSkipLookahead();
694 /* skip white spaces */ 694 /* skip white spaces */
695 a = lexLookahead(); 695 a = lexLookahead();
696 while (a == ' ' || a == '\t') { 696 while (a == ' ' || a == '\t') {
697 lexSkipLookahead(); 697 lexSkipLookahead();
698 a = lexLookahead(); 698 a = lexLookahead();
699 } 699 }
700 if (a == '\n') { 700 if (a == '\n') {
701 lexSkipLookahead(); 701 lexSkipLookahead();
702 a = lexLookahead(); 702 a = lexLookahead();
703 if (a == ' ' || a == '\t') { 703 if (a == ' ' || a == '\t') {
704 /* continuation, throw away all the \n and spaces read so 704 /* continuation, throw away all the \n and spaces read so
705 * far 705 * far
706 */ 706 */
707 lexSkipWhite(); 707 lexSkipWhite();
708 lexPushLookaheadc(';'); 708 lexPushLookaheadc(';');
709 } 709 }
710 else { 710 else {
711 lexPushLookaheadc('\n'); 711 lexPushLookaheadc('\n');
712 lexPushLookaheadc(';'); 712 lexPushLookaheadc(';');
713 } 713 }
714 } 714 }
715 else { 715 else {
716 lexPushLookaheadc(';'); 716 lexPushLookaheadc(';');
717 } 717 }
718 } 718 }
719 } 719 }
720 720
721static char* lexGet1Value() { 721static char* lexGet1Value() {
722 int c; 722 int c;
723 lexSkipWhite(); 723 lexSkipWhite();
724 c = lexLookahead(); 724 c = lexLookahead();
725 lexClearToken(); 725 lexClearToken();
726 while (c != EOF && c != ';') { 726 while (c != EOF && c != ';') {
727 if (c == '\\' ) { 727 if (c == '\\' ) {
728 int a; 728 int a;
729 lexSkipLookahead(); 729 lexSkipLookahead();
730 a = lexLookahead(); 730 a = lexLookahead();
731 if ( a != ';' ) { 731 if ( a != ';' ) {
732 lexAppendc('\\'); 732 lexAppendc('\\');
733 } else { 733 } else {
734 lexAppendc( ';' ); 734 lexAppendc( ';' );
735 lexSkipLookahead(); 735 lexSkipLookahead();
736 } 736 }
737 } else if (c == '\n') { 737 } else if (c == '\n') {
738 int a; 738 int a;
739 lexSkipLookahead(); 739 lexSkipLookahead();
740 a = lexLookahead(); 740 a = lexLookahead();
741 if (a == ' ' || a == '\t') { 741 if (a == ' ' || a == '\t') {
742 lexAppendc(' '); 742 lexAppendc(' ');
743 lexSkipLookahead(); 743 lexSkipLookahead();
744 } 744 }
745 else { 745 else {
746 lexPushLookaheadc('\n'); 746 lexPushLookaheadc('\n');
747 break; 747 break;
748 } 748 }
749 } 749 }
750 else { 750 else {
751 lexAppendc(c); 751 lexAppendc(c);
752 lexSkipLookahead(); 752 lexSkipLookahead();
753 } 753 }
754 c = lexLookahead(); 754 c = lexLookahead();
755 } 755 }
756 lexAppendc(0); 756 lexAppendc(0);
757 handleMoreRFC822LineBreak(c); 757 handleMoreRFC822LineBreak(c);
758 return c==EOF?0:lexStr(); 758 return c==EOF?0:lexStr();
759 } 759 }
760#endif 760#endif
761 761
762static int match_begin_name(int end) { 762static int match_begin_name(int end) {
763 char *n = lexLookaheadWord(); 763 char *n = lexLookaheadWord();
764 int token = ID; 764 int token = ID;
765 if (n) { 765 if (n) {
766 if (!qstricmp(n,"vcard")) token = end?END_VCARD:BEGIN_VCARD; 766 if (!qstricmp(n,"vcard")) token = end?END_VCARD:BEGIN_VCARD;
767 else if (!qstricmp(n,"vcalendar")) token = end?END_VCAL:BEGIN_VCAL; 767 else if (!qstricmp(n,"vcalendar")) token = end?END_VCAL:BEGIN_VCAL;
768 else if (!qstricmp(n,"vevent")) token = end?END_VEVENT:BEGIN_VEVENT; 768 else if (!qstricmp(n,"vevent")) token = end?END_VEVENT:BEGIN_VEVENT;
769 else if (!qstricmp(n,"vtodo")) token = end?END_VTODO:BEGIN_VTODO; 769 else if (!qstricmp(n,"vtodo")) token = end?END_VTODO:BEGIN_VTODO;
770 deleteStr(n); 770 deleteStr(n);
771 return token; 771 return token;
772 } 772 }
773 return 0; 773 return 0;
774 } 774 }
775 775
776 776
777#ifdef INCLUDEMFC 777#ifdef INCLUDEMFC
778void initLex(const char *inputstring, unsigned long inputlen, CFile *inputfile) 778void initLex(const char *inputstring, unsigned long inputlen, CFile *inputfile)
779#else 779#else
780void initLex(const char *inputstring, unsigned long inputlen, FILE *inputfile) 780void initLex(const char *inputstring, unsigned long inputlen, FILE *inputfile)
781#endif 781#endif
782 { 782 {
783 // initialize lex mode stack 783 // initialize lex mode stack
784 lexBuf.lexModeStack[lexBuf.lexModeStackTop=0] = L_NORMAL; 784 lexBuf.lexModeStack[lexBuf.lexModeStackTop=0] = L_NORMAL;
785 785
786 // iniatialize lex buffer. 786 // iniatialize lex buffer.
787 lexBuf.inputString = (char*) inputstring; 787 lexBuf.inputString = (char*) inputstring;
788 lexBuf.inputLen = inputlen; 788 lexBuf.inputLen = inputlen;
789 lexBuf.curPos = 0; 789 lexBuf.curPos = 0;
790 lexBuf.inputFile = inputfile; 790 lexBuf.inputFile = inputfile;
791 791
792 lexBuf.len = 0; 792 lexBuf.len = 0;
793 lexBuf.getPtr = 0; 793 lexBuf.getPtr = 0;
794 794
795 lexBuf.maxToken = MAXTOKEN; 795 lexBuf.maxToken = MAXTOKEN;
796 lexBuf.strs = (char*)malloc(MAXTOKEN); 796 lexBuf.strs = (char*)malloc(MAXTOKEN);
797 lexBuf.strsLen = 0; 797 lexBuf.strsLen = 0;
798 798
799 } 799 }
800 800
801static void finiLex() { 801static void finiLex() {
802 free(lexBuf.strs); 802 free(lexBuf.strs);
803 } 803 }
804 804
805 805
806/*-----------------------------------*/ 806/*-----------------------------------*/
807/* This parses and converts the base64 format for binary encoding into 807/* This parses and converts the base64 format for binary encoding into
808 * a decoded buffer (allocated with new). See RFC 1521. 808 * a decoded buffer (allocated with new). See RFC 1521.
809 */ 809 */
810static char * lexGetDataFromBase64() 810static char * lexGetDataFromBase64()
811 { 811 {
812 unsigned long bytesLen = 0, bytesMax = 0; 812 unsigned long bytesLen = 0, bytesMax = 0;
813 int quadIx = 0, pad = 0; 813 int quadIx = 0, pad = 0;
814 unsigned long trip = 0; 814 unsigned long trip = 0;
815 unsigned char b; 815 unsigned char b;
816 int c; 816 int c;
817 unsigned char *bytes = NULL; 817 unsigned char *bytes = NULL;
818 unsigned char *oldBytes = NULL; 818 unsigned char *oldBytes = NULL;
819 819
820 DBG_(("db: lexGetDataFromBase64\n")); 820 DBG_(("db: lexGetDataFromBase64\n"));
821 while (1) { 821 while (1) {
822 c = lexGetc(); 822 c = lexGetc();
823 if (c == '\n') { 823 if (c == '\n') {
824 ++mime_lineNum; 824 ++mime_lineNum;
825 if (lexLookahead() == '\n') { 825 if (lexLookahead() == '\n') {
826 /* a '\n' character by itself means end of data */ 826 /* a '\n' character by itself means end of data */
827 break; 827 break;
828 } 828 }
829 else continue; /* ignore '\n' */ 829 else continue; /* ignore '\n' */
830 } 830 }
831 else { 831 else {
832 if ((c >= 'A') && (c <= 'Z')) 832 if ((c >= 'A') && (c <= 'Z'))
833 b = (unsigned char)(c - 'A'); 833 b = (unsigned char)(c - 'A');
834 else if ((c >= 'a') && (c <= 'z')) 834 else if ((c >= 'a') && (c <= 'z'))
835 b = (unsigned char)(c - 'a') + 26; 835 b = (unsigned char)(c - 'a') + 26;
836 else if ((c >= '0') && (c <= '9')) 836 else if ((c >= '0') && (c <= '9'))
837 b = (unsigned char)(c - '0') + 52; 837 b = (unsigned char)(c - '0') + 52;
838 else if (c == '+') 838 else if (c == '+')
839 b = 62; 839 b = 62;
840 else if (c == '/') 840 else if (c == '/')
841 b = 63; 841 b = 63;
842 else if (c == '=') { 842 else if (c == '=') {
843 b = 0; 843 b = 0;
844 pad++; 844 pad++;
845 } else if ((c == ' ') || (c == '\t')) { 845 } else if ((c == ' ') || (c == '\t')) {
846 continue; 846 continue;
847 } else { /* error condition */ 847 } else { /* error condition */
848 if (bytes) free(bytes); 848 if (bytes) free(bytes);
849 else if (oldBytes) free(oldBytes); 849 else if (oldBytes) free(oldBytes);
850 // error recovery: skip until 2 adjacent newlines. 850 // error recovery: skip until 2 adjacent newlines.
851 DBG_(("db: invalid character 0x%x '%c'\n", c,c)); 851 DBG_(("db: invalid character 0x%x '%c'\n", c,c));
852 if (c != EOF) { 852 if (c != EOF) {
853 c = lexGetc(); 853 c = lexGetc();
854 while (c != EOF) { 854 while (c != EOF) {
855 if (c == '\n' && lexLookahead() == '\n') { 855 if (c == '\n' && lexLookahead() == '\n') {
856 ++mime_lineNum; 856 ++mime_lineNum;
857 break; 857 break;
858 } 858 }
859 c = lexGetc(); 859 c = lexGetc();
860 } 860 }
861 } 861 }
862 return NULL; 862 return NULL;
863 } 863 }
864 trip = (trip << 6) | b; 864 trip = (trip << 6) | b;
865 if (++quadIx == 4) { 865 if (++quadIx == 4) {
866 unsigned char outBytes[3]; 866 unsigned char outBytes[3];
867 int numOut; 867 int numOut;
868 int i; 868 int i;
869 for (i = 0; i < 3; i++) { 869 for (i = 0; i < 3; i++) {
870 outBytes[2-i] = (unsigned char)(trip & 0xFF); 870 outBytes[2-i] = (unsigned char)(trip & 0xFF);
871 trip >>= 8; 871 trip >>= 8;
872 } 872 }
873 numOut = 3 - pad; 873 numOut = 3 - pad;
874 if (bytesLen + numOut > bytesMax) { 874 if (bytesLen + numOut > bytesMax) {
875 if (!bytes) { 875 if (!bytes) {
876 bytesMax = 1024; 876 bytesMax = 1024;
877 bytes = (unsigned char*)malloc((size_t)bytesMax); 877 bytes = (unsigned char*)malloc((size_t)bytesMax);
878 } 878 }
879 else { 879 else {
880 bytesMax <<= 2; 880 bytesMax <<= 2;
881 oldBytes = bytes; 881 oldBytes = bytes;
882 bytes = (unsigned char*)realloc(bytes,(size_t)bytesMax); 882 bytes = (unsigned char*)realloc(bytes,(size_t)bytesMax);
883 } 883 }
884 if (bytes == 0) { 884 if (bytes == 0) {
885 mime_error("out of memory while processing BASE64 data\n"); 885 mime_error("out of memory while processing BASE64 data\n");
886 } 886 }
887 } 887 }
888 if (bytes) { 888 if (bytes) {
889 memcpy(bytes + bytesLen, outBytes, numOut); 889 memcpy(bytes + bytesLen, outBytes, numOut);
890 bytesLen += numOut; 890 bytesLen += numOut;
891 } 891 }
892 trip = 0; 892 trip = 0;
893 quadIx = 0; 893 quadIx = 0;
894 } 894 }
895 } 895 }
896 } /* while */ 896 } /* while */
897 DBG_(("db: bytesLen = %d\n", bytesLen)); 897 DBG_(("db: bytesLen = %d\n", bytesLen));
898 /* kludge: all this won't be necessary if we have tree form 898 /* kludge: all this won't be necessary if we have tree form
899 representation */ 899 representation */
900 if (bytes) { 900 if (bytes) {
901 setValueWithSize(curProp,bytes,(unsigned int)bytesLen); 901 setValueWithSize(curProp,bytes,(unsigned int)bytesLen);
902 free(bytes); 902 free(bytes);
903 } 903 }
904 else if (oldBytes) { 904 else if (oldBytes) {
905 setValueWithSize(curProp,oldBytes,(unsigned int)bytesLen); 905 setValueWithSize(curProp,oldBytes,(unsigned int)bytesLen);
906 free(oldBytes); 906 free(oldBytes);
907 } 907 }
908 return 0; 908 return 0;
909 } 909 }
910 910
911static int match_begin_end_name(int end) { 911static int match_begin_end_name(int end) {
912 int token; 912 int token;
913 lexSkipWhite(); 913 lexSkipWhite();
914 if (lexLookahead() != ':') return ID; 914 if (lexLookahead() != ':') return ID;
915 lexSkipLookahead(); 915 lexSkipLookahead();
916 lexSkipWhite(); 916 lexSkipWhite();
917 token = match_begin_name(end); 917 token = match_begin_name(end);
918 if (token == ID) { 918 if (token == ID) {
919 lexPushLookaheadc(':'); 919 lexPushLookaheadc(':');
920 DBG_(("db: ID '%s'\n", yylval.str)); 920 DBG_(("db: ID '%s'\n", yylval.str));
921 return ID; 921 return ID;
922 } 922 }
923 else if (token != 0) { 923 else if (token != 0) {
924 lexSkipLookaheadWord(); 924 lexSkipLookaheadWord();
925 deleteStr(yylval.str); 925 deleteStr(yylval.str);
926 DBG_(("db: begin/end %d\n", token)); 926 DBG_(("db: begin/end %d\n", token));
927 return token; 927 return token;
928 } 928 }
929 return 0; 929 return 0;
930 } 930 }
931 931
932static char* lexGetQuotedPrintable() 932static char* lexGetQuotedPrintable()
933{ 933{
934 int c; 934 int c;
935 lexSkipWhite(); 935 lexSkipWhite();
936 c = lexLookahead(); 936 c = lexLookahead();
937 lexClearToken(); 937 lexClearToken();
938 938
939 while (c != EOF && c != ';') { 939 while (c != EOF && c != ';') {
940 if (c == '\n') { 940 if (c == '\n') {
941 // break, leave '\n' on remaining chars. 941 // break, leave '\n' on remaining chars.
942 break; 942 break;
943 } else if (c == '=') { 943 } else if (c == '=') {
944 int cur = 0; 944 int cur = 0;
945 int next; 945 int next;
946 946
947 lexSkipLookahead(); // skip '=' 947 lexSkipLookahead(); // skip '='
948 next = lexLookahead(); 948 next = lexLookahead();
949 949
950 if (next == '\n') { 950 if (next == '\n') {
951 // skip and only skip the \n 951 // skip and only skip the \n
952 lexSkipLookahead(); 952 lexSkipLookahead();
953 c = lexLookahead(); 953 c = lexLookahead();
954 ++mime_lineNum; // aid in error reporting 954 ++mime_lineNum; // aid in error reporting
955 continue; 955 continue;
956 } else if (next >= '0' && next <= '9') { 956 } else if (next >= '0' && next <= '9') {
957 cur = next - '0'; 957 cur = next - '0';
958 } else if (next >= 'A' && next <= 'F') { 958 } else if (next >= 'A' && next <= 'F') {
959 cur = next - 'A' + 10; 959 cur = next - 'A' + 10;
960 } else { 960 } else {
961 // we have been sent buggy stuff. doesn't matter 961 // we have been sent buggy stuff. doesn't matter
962 // what we do so long as we keep going. 962 // what we do so long as we keep going.
963 // should probably spit an error here 963 // should probably spit an error here
964 c = lexLookahead(); 964 c = lexLookahead();
965 continue; 965 continue;
966 } 966 }
967 967
968 lexSkipLookahead(); // skip A-Z0-9 968 lexSkipLookahead(); // skip A-Z0-9
969 next = lexLookahead(); 969 next = lexLookahead();
970 970
971 cur = cur * 16; 971 cur = cur * 16;
972 // this time really just expecting 0-9A-F 972 // this time really just expecting 0-9A-F
973 if (next >= '0' && next <= '9') { 973 if (next >= '0' && next <= '9') {
974 cur += next - '0'; 974 cur += next - '0';
975 } else if (next >= 'A' && next <= 'F') { 975 } else if (next >= 'A' && next <= 'F') {
976 cur += next - 'A' + 10; 976 cur += next - 'A' + 10;
977 } else { 977 } else {
978 // we have been sent buggy stuff. doesn't matter 978 // we have been sent buggy stuff. doesn't matter
979 // what we do so long as we keep going. 979 // what we do so long as we keep going.
980 // should probably spit an error here 980 // should probably spit an error here
981 c = lexLookahead(); 981 c = lexLookahead();
982 continue; 982 continue;
983 } 983 }
984 984
985 // got a valid escaped =. append it. 985 // got a valid escaped =. append it.
986 lexSkipLookahead(); // skip second 0-9A-F 986 lexSkipLookahead(); // skip second 0-9A-F
987 lexAppendc(cur); 987 lexAppendc(cur);
988 } else { 988 } else {
989 lexSkipLookahead(); // skip whatever we just read. 989 lexSkipLookahead(); // skip whatever we just read.
990 lexAppendc(c); // and append it. 990 lexAppendc(c); // and append it.
991 } 991 }
992 c = lexLookahead(); 992 c = lexLookahead();
993 } 993 }
994 lexAppendc(0); 994 lexAppendc(0);
995 return c==EOF?0:lexStr(); 995 return c==EOF?0:lexStr();
996} 996}
997 997
998static int yylex() { 998static int yylex() {
999 999
1000 int lexmode = LEXMODE(); 1000 int lexmode = LEXMODE();
1001 if (lexmode == L_VALUES) { 1001 if (lexmode == L_VALUES) {
1002 int c = lexGetc(); 1002 int c = lexGetc();
1003 if (c == ';') { 1003 if (c == ';') {
1004 DBG_(("db: SEMICOLON\n")); 1004 DBG_(("db: SEMICOLON\n"));
1005 lexPushLookaheadc(c); 1005 lexPushLookaheadc(c);
1006 handleMoreRFC822LineBreak(c); 1006 handleMoreRFC822LineBreak(c);
1007 lexSkipLookahead(); 1007 lexSkipLookahead();
1008 return SEMICOLON; 1008 return SEMICOLON;
1009 } 1009 }
1010 else if (strchr("\n",c)) { 1010 else if (strchr("\n",c)) {
1011 ++mime_lineNum; 1011 ++mime_lineNum;
1012 /* consume all line separator(s) adjacent to each other */ 1012 /* consume all line separator(s) adjacent to each other */
1013 c = lexLookahead(); 1013 c = lexLookahead();
1014 while (strchr("\n",c)) { 1014 while (strchr("\n",c)) {
1015 lexSkipLookahead(); 1015 lexSkipLookahead();
1016 c = lexLookahead(); 1016 c = lexLookahead();
1017 ++mime_lineNum; 1017 ++mime_lineNum;
1018 } 1018 }
1019 DBG_(("db: LINESEP\n")); 1019 DBG_(("db: LINESEP\n"));
1020 return LINESEP; 1020 return LINESEP;
1021 } 1021 }
1022 else { 1022 else {
1023 char *p = 0; 1023 char *p = 0;
1024 lexPushLookaheadc(c); 1024 lexPushLookaheadc(c);
1025 if (lexWithinMode(L_BASE64)) { 1025 if (lexWithinMode(L_BASE64)) {
1026 /* get each char and convert to bin on the fly... */ 1026 /* get each char and convert to bin on the fly... */
1027 p = lexGetDataFromBase64(); 1027 p = lexGetDataFromBase64();
1028 yylval.str = p; 1028 yylval.str = p;
1029 return STRING; 1029 return STRING;
1030 } 1030 }
1031 else if (lexWithinMode(L_QUOTED_PRINTABLE)) { 1031 else if (lexWithinMode(L_QUOTED_PRINTABLE)) {
1032 p = lexGetQuotedPrintable(); 1032 p = lexGetQuotedPrintable();
1033 } 1033 }
1034 else { 1034 else {
1035#ifdef _SUPPORT_LINE_FOLDING 1035#ifdef _SUPPORT_LINE_FOLDING
1036 p = lexGet1Value(); 1036 p = lexGet1Value();
1037#else 1037#else
1038 p = lexGetStrUntil(";\n"); 1038 p = lexGetStrUntil(";\n");
1039#endif 1039#endif
1040 } 1040 }
1041 if (p) { 1041 if (p) {
1042 DBG_(("db: STRING: '%s'\n", p)); 1042 DBG_(("db: STRING: '%s'\n", p));
1043 yylval.str = p; 1043 yylval.str = p;
1044 return STRING; 1044 return STRING;
1045 } 1045 }
1046 else return 0; 1046 else return 0;
1047 } 1047 }
1048 } 1048 }
1049 else { 1049 else {
1050 /* normal mode */ 1050 /* normal mode */
1051 while (1) { 1051 while (1) {
1052 int c = lexGetc(); 1052 int c = lexGetc();
1053 switch(c) { 1053 switch(c) {
1054 case ':': { 1054 case ':': {
1055 /* consume all line separator(s) adjacent to each other */ 1055 /* consume all line separator(s) adjacent to each other */
1056 /* ignoring linesep immediately after colon. */ 1056 /* ignoring linesep immediately after colon. */
1057 c = lexLookahead(); 1057 c = lexLookahead();
1058 while (strchr("\n",c)) { 1058 while (strchr("\n",c)) {
1059 lexSkipLookahead(); 1059 lexSkipLookahead();
1060 c = lexLookahead(); 1060 c = lexLookahead();
1061 ++mime_lineNum; 1061 ++mime_lineNum;
1062 } 1062 }
1063 DBG_(("db: COLON\n")); 1063 DBG_(("db: COLON\n"));
1064 return COLON; 1064 return COLON;
1065 } 1065 }
1066 case ';': 1066 case ';':
1067 DBG_(("db: SEMICOLON\n")); 1067 DBG_(("db: SEMICOLON\n"));
1068 return SEMICOLON; 1068 return SEMICOLON;
1069 case '=': 1069 case '=':
1070 DBG_(("db: EQ\n")); 1070 DBG_(("db: EQ\n"));
1071 return EQ; 1071 return EQ;
1072 /* ignore whitespace in this mode */ 1072 /* ignore whitespace in this mode */
1073 case '\t': 1073 case '\t':
1074 case ' ': continue; 1074 case ' ': continue;
1075 case '\n': { 1075 case '\n': {
1076 ++mime_lineNum; 1076 ++mime_lineNum;
1077 continue; 1077 continue;
1078 } 1078 }
1079 case EOF: return 0; 1079 case EOF: return 0;
1080 break; 1080 break;
1081 default: { 1081 default: {
1082 lexPushLookaheadc(c); 1082 lexPushLookaheadc(c);
1083 if (isalnum(c)) { 1083 if (isalnum(c)) {
1084 char *t = lexGetWord(); 1084 char *t = lexGetWord();
1085 yylval.str = t; 1085 yylval.str = t;
1086 if (!qstricmp(t, "begin")) { 1086 if (!qstricmp(t, "begin")) {
1087 return match_begin_end_name(0); 1087 return match_begin_end_name(0);
1088 } 1088 }
1089 else if (!qstricmp(t,"end")) { 1089 else if (!qstricmp(t,"end")) {
1090 return match_begin_end_name(1); 1090 return match_begin_end_name(1);
1091 } 1091 }
1092 else { 1092 else {
1093 DBG_(("db: ID '%s'\n", t)); 1093 DBG_(("db: ID '%s'\n", t));
1094 return ID; 1094 return ID;
1095 } 1095 }
1096 } 1096 }
1097 else { 1097 else {
1098 /* unknow token */ 1098 /* unknow token */
1099 return 0; 1099 return 0;
1100 } 1100 }
1101 break; 1101 break;
1102 } 1102 }
1103 } 1103 }
1104 } 1104 }
1105 } 1105 }
1106 return 0; 1106 return 0;
1107 } 1107 }
1108 1108
1109 1109
1110/***************************************************************************/ 1110/***************************************************************************/
1111 /*** Public Functions ****/ 1111 /*** Public Functions ****/
1112/***************************************************************************/ 1112/***************************************************************************/
1113 1113
1114static VObject* Parse_MIMEHelper() 1114static VObject* Parse_MIMEHelper()
1115 { 1115 {
1116 ObjStackTop = -1; 1116 ObjStackTop = -1;
1117 mime_numErrors = 0; 1117 mime_numErrors = 0;
1118 mime_lineNum = 1; 1118 mime_lineNum = 1;
1119 vObjList = 0; 1119 vObjList = 0;
1120 curObj = 0; 1120 curObj = 0;
1121 1121
1122 if (yyparse() != 0) 1122 if (yyparse() != 0)
1123 return 0; 1123 return 0;
1124 1124
1125 finiLex(); 1125 finiLex();
1126 return vObjList; 1126 return vObjList;
1127 } 1127 }
1128 1128
1129/*--------------------------------------------*/ 1129/*--------------------------------------------*/
1130DLLEXPORT(VObject*) Parse_MIME(const char *input, unsigned long len) 1130DLLEXPORT(VObject*) Parse_MIME(const char *input, unsigned long len)
1131 { 1131 {
1132 initLex(input, len, 0); 1132 initLex(input, len, 0);
1133 return Parse_MIMEHelper(); 1133 return Parse_MIMEHelper();
1134 } 1134 }
1135 1135
1136 1136
1137#if INCLUDEMFC 1137#if INCLUDEMFC
1138 1138
1139DLLEXPORT(VObject*) Parse_MIME_FromFile(CFile *file) 1139DLLEXPORT(VObject*) Parse_MIME_FromFile(CFile *file)
1140 { 1140 {
1141 unsigned long startPos; 1141 unsigned long startPos;
1142 VObject *result; 1142 VObject *result;
1143 1143
1144 initLex(0,-1,file); 1144 initLex(0,-1,file);
1145 startPos = file->GetPosition(); 1145 startPos = file->GetPosition();
1146 if (!(result = Parse_MIMEHelper())) 1146 if (!(result = Parse_MIMEHelper()))
1147 file->Seek(startPos, CFile::begin); 1147 file->Seek(startPos, CFile::begin);
1148 return result; 1148 return result;
1149 } 1149 }
1150 1150
1151#else 1151#else
1152 1152
1153VObject* Parse_MIME_FromFile(FILE *file) 1153VObject* Parse_MIME_FromFile(FILE *file)
1154 { 1154 {
1155 VObject *result; 1155 VObject *result;
1156 long startPos; 1156 long startPos;
1157 1157
1158 initLex(0,(unsigned long)-1,file); 1158 initLex(0,(unsigned long)-1,file);
1159 startPos = ftell(file); 1159 startPos = ftell(file);
1160 if (!(result = Parse_MIMEHelper())) { 1160 if (!(result = Parse_MIMEHelper())) {
1161 fseek(file,startPos,SEEK_SET); 1161 fseek(file,startPos,SEEK_SET);
1162 } 1162 }
1163 return result; 1163 return result;
1164 } 1164 }
1165 1165
1166DLLEXPORT(VObject*) Parse_MIME_FromFileName(char *fname) 1166DLLEXPORT(VObject*) Parse_MIME_FromFileName(char *fname)
1167 { 1167 {
1168 FILE *fp = fopen(fname,"r"); 1168 FILE *fp = fopen(fname,"r");
1169 if (fp) { 1169 if (fp) {
1170 VObject* o = Parse_MIME_FromFile(fp); 1170 VObject* o = Parse_MIME_FromFile(fp);
1171 fclose(fp); 1171 fclose(fp);
1172 return o; 1172 return o;
1173 } 1173 }
1174 else { 1174 else {
1175 char msg[80]; 1175 char msg[80];
1176 sprintf(msg, "can't open file '%s' for reading\n", fname); 1176 sprintf(msg, "can't open file '%s' for reading\n", fname);
1177 mime_error_(msg); 1177 mime_error_(msg);
1178 return 0; 1178 return 0;
1179 } 1179 }
1180 } 1180 }
1181 1181
1182#endif 1182#endif
1183 1183
1184/*-------------------------------------*/ 1184/*-------------------------------------*/
1185 1185
1186static MimeErrorHandler mimeErrorHandler; 1186static MimeErrorHandler mimeErrorHandler;
1187 1187
1188DLLEXPORT(void) registerMimeErrorHandler(MimeErrorHandler me) 1188DLLEXPORT(void) registerMimeErrorHandler(MimeErrorHandler me)
1189 { 1189 {
1190 mimeErrorHandler = me; 1190 mimeErrorHandler = me;
1191 } 1191 }
1192 1192
1193void mime_error(char *s) 1193void mime_error(char *s)
1194 { 1194 {
1195 char msg[256]; 1195 char msg[256];
1196 if (mimeErrorHandler) { 1196 if (mimeErrorHandler) {
1197 sprintf(msg,"%s at line %d", s, mime_lineNum); 1197 sprintf(msg,"%s at line %d", s, mime_lineNum);
1198 mimeErrorHandler(msg); 1198 mimeErrorHandler(msg);
1199 } 1199 }
1200 } 1200 }
1201 1201
1202void mime_error_(char *s) 1202void mime_error_(char *s)
1203 { 1203 {
1204 if (mimeErrorHandler) { 1204 if (mimeErrorHandler) {
1205 mimeErrorHandler(s); 1205 mimeErrorHandler(s);
1206 } 1206 }
1207 } 1207 }
1208 1208
diff --git a/library/backend/vcc_yacc.cpp b/library/backend/vcc_yacc.cpp
index 19a108f..b2b0c14 100644
--- a/library/backend/vcc_yacc.cpp
+++ b/library/backend/vcc_yacc.cpp
@@ -1,1576 +1,1576 @@
1#ifndef lint 1#ifndef lint
2 /*static char yysccsid[] = "from: @(#)yaccpar1.9 (Berkeley) 02/21/93";*/ 2 /*static char yysccsid[] = "from: @(#)yaccpar1.9 (Berkeley) 02/21/93";*/
3static char yyrcsid[] = "$Id$"; 3static char yyrcsid[] = "$Id$";
4#endif 4#endif
5#define YYBYACC 1 5#define YYBYACC 1
6#define YYMAJOR 1 6#define YYMAJOR 1
7#define YYMINOR 9 7#define YYMINOR 9
8#define yyclearin (yychar=(-1)) 8#define yyclearin (yychar=(-1))
9#define yyerrok (yyerrflag=0) 9#define yyerrok (yyerrflag=0)
10#define YYRECOVERING (yyerrflag!=0) 10#define YYRECOVERING (yyerrflag!=0)
11#define yyparse vccparse 11#define yyparse vccparse
12#define yylex vcclex 12#define yylex vcclex
13#define yyerror vccerror 13#define yyerror vccerror
14#define yychar vccchar 14#define yychar vccchar
15#define yyval vccval 15#define yyval vccval
16#define yylval vcclval 16#define yylval vcclval
17#define yydebug vccdebug 17#define yydebug vccdebug
18#define yynerrs vccnerrs 18#define yynerrs vccnerrs
19#define yyerrflag vccerrflag 19#define yyerrflag vccerrflag
20#define yyss vccss 20#define yyss vccss
21#define yyssp vccssp 21#define yyssp vccssp
22#define yyvs vccvs 22#define yyvs vccvs
23#define yyvsp vccvsp 23#define yyvsp vccvsp
24#define yylhs vcclhs 24#define yylhs vcclhs
25#define yylen vcclen 25#define yylen vcclen
26#define yydefred vccdefred 26#define yydefred vccdefred
27#define yydgoto vccdgoto 27#define yydgoto vccdgoto
28#define yysindex vccsindex 28#define yysindex vccsindex
29#define yyrindex vccrindex 29#define yyrindex vccrindex
30#define yygindex vccgindex 30#define yygindex vccgindex
31#define yytable vcctable 31#define yytable vcctable
32#define yycheck vcccheck 32#define yycheck vcccheck
33#define yyname vccname 33#define yyname vccname
34#define yyrule vccrule 34#define yyrule vccrule
35#define YYPREFIX "vcc" 35#define YYPREFIX "vcc"
36#line 1 "backend/vcc.y" 36#line 1 "backend/vcc.y"
37 37
38 38
39/*************************************************************************** 39/***************************************************************************
40(C) Copyright 1996 Apple Computer, Inc., AT&T Corp., International 40(C) Copyright 1996 Apple Computer, Inc., AT&T Corp., International
41Business Machines Corporation and Siemens Rolm Communications Inc. 41Business Machines Corporation and Siemens Rolm Communications Inc.
42 42
43For purposes of this license notice, the term Licensors shall mean, 43For purposes of this license notice, the term Licensors shall mean,
44collectively, Apple Computer, Inc., AT&T Corp., International 44collectively, Apple Computer, Inc., AT&T Corp., International
45Business Machines Corporation and Siemens Rolm Communications Inc. 45Business Machines Corporation and Siemens Rolm Communications Inc.
46The term Licensor shall mean any of the Licensors. 46The term Licensor shall mean any of the Licensors.
47 47
48Subject to acceptance of the following conditions, permission is hereby 48Subject to acceptance of the following conditions, permission is hereby
49granted by Licensors without the need for written agreement and without 49granted by Licensors without the need for written agreement and without
50license or royalty fees, to use, copy, modify and distribute this 50license or royalty fees, to use, copy, modify and distribute this
51software for any purpose. 51software for any purpose.
52 52
53The above copyright notice and the following four paragraphs must be 53The above copyright notice and the following four paragraphs must be
54reproduced in all copies of this software and any software including 54reproduced in all copies of this software and any software including
55this software. 55this software.
56 56
57THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS AND NO LICENSOR SHALL HAVE 57THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS AND NO LICENSOR SHALL HAVE
58ANY OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR 58ANY OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR
59MODIFICATIONS. 59MODIFICATIONS.
60 60
61IN NO EVENT SHALL ANY LICENSOR BE LIABLE TO ANY PARTY FOR DIRECT, 61IN NO EVENT SHALL ANY LICENSOR BE LIABLE TO ANY PARTY FOR DIRECT,
62INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOST PROFITS ARISING OUT 62INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOST PROFITS ARISING OUT
63OF THE USE OF THIS SOFTWARE EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 63OF THE USE OF THIS SOFTWARE EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
64DAMAGE. 64DAMAGE.
65 65
66EACH LICENSOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, EXPRESS OR IMPLIED, 66EACH LICENSOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, EXPRESS OR IMPLIED,
67INCLUDING BUT NOT LIMITED TO ANY WARRANTY OF NONINFRINGEMENT OR THE 67INCLUDING BUT NOT LIMITED TO ANY WARRANTY OF NONINFRINGEMENT OR THE
68IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 68IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
69PURPOSE. 69PURPOSE.
70 70
71The software is provided with RESTRICTED RIGHTS. Use, duplication, or 71The software is provided with RESTRICTED RIGHTS. Use, duplication, or
72disclosure by the government are subject to restrictions set forth in 72disclosure by the government are subject to restrictions set forth in
73DFARS 252.227-7013 or 48 CFR 52.227-19, as applicable. 73DFARS 252.227-7013 or 48 CFR 52.227-19, as applicable.
74 74
75***************************************************************************/ 75***************************************************************************/
76 76
77/* 77/*
78 * src: vcc.c 78 * src: vcc.c
79 * doc: Parser for vCard and vCalendar. Note that this code is 79 * doc: Parser for vCard and vCalendar. Note that this code is
80 * generated by a yacc parser generator. Generally it should not 80 * generated by a yacc parser generator. Generally it should not
81 * be edited by hand. The real source is vcc.y. The #line directives 81 * be edited by hand. The real source is vcc.y. The #line directives
82 * can be commented out here to make it easier to trace through 82 * can be commented out here to make it easier to trace through
83 * in a debugger. However, if a bug is found it should 83 * in a debugger. However, if a bug is found it should
84 * be fixed in vcc.y and this file regenerated. 84 * be fixed in vcc.y and this file regenerated.
85 */ 85 */
86 86
87 87
88/* debugging utilities */ 88/* debugging utilities */
89#if __DEBUG 89#if __DEBUG
90#define DBG_(x) printf x 90#define DBG_(x) printf x
91#else 91#else
92#define DBG_(x) 92#define DBG_(x)
93#endif 93#endif
94 94
95/**** External Functions ****/ 95/**** External Functions ****/
96 96
97/* assign local name to parser variables and functions so that 97/* assign local name to parser variables and functions so that
98 we can use more than one yacc based parser. 98 we can use more than one yacc based parser.
99*/ 99*/
100 100
101#if 0 101#if 0
102#define yyparse mime_parse 102#define yyparse mime_parse
103#define yylex mime_lex 103#define yylex mime_lex
104#define yyerror mime_error 104#define yyerror mime_error
105#define yychar mime_char 105#define yychar mime_char
106/* #define p_yyval p_mime_val */ 106/* #define p_yyval p_mime_val */
107#undef yyval 107#undef yyval
108#define yyval mime_yyval 108#define yyval mime_yyval
109/* #define p_yylval p_mime_lval */ 109/* #define p_yylval p_mime_lval */
110#undef yylval 110#undef yylval
111#define yylval mime_yylval 111#define yylval mime_yylval
112#define yydebug mime_debug 112#define yydebug mime_debug
113#define yynerrs mime_nerrs 113#define yynerrs mime_nerrs
114#define yyerrflag mime_errflag 114#define yyerrflag mime_errflag
115#define yyss mime_ss 115#define yyss mime_ss
116#define yyssp mime_ssp 116#define yyssp mime_ssp
117#define yyvs mime_vs 117#define yyvs mime_vs
118#define yyvsp mime_vsp 118#define yyvsp mime_vsp
119#define yylhs mime_lhs 119#define yylhs mime_lhs
120#define yylen mime_len 120#define yylen mime_len
121#define yydefred mime_defred 121#define yydefred mime_defred
122#define yydgoto mime_dgoto 122#define yydgoto mime_dgoto
123#define yysindex mime_sindex 123#define yysindex mime_sindex
124#define yyrindex mime_rindex 124#define yyrindex mime_rindex
125#define yygindex mime_gindex 125#define yygindex mime_gindex
126#define yytable mime_table 126#define yytable mime_table
127#define yycheck mime_check 127#define yycheck mime_check
128#define yyname mime_name 128#define yyname mime_name
129#define yyrule mime_rule 129#define yyrule mime_rule
130#ifdef YYPREFIX 130#ifdef YYPREFIX
131#undef YYPREFIX 131#undef YYPREFIX
132#endif 132#endif
133#define YYPREFIX "mime_" 133#define YYPREFIX "mime_"
134#endif 134#endif
135 135
136 136
137#ifndef _NO_LINE_FOLDING 137#ifndef _NO_LINE_FOLDING
138#define _SUPPORT_LINE_FOLDING 1 138#define _SUPPORT_LINE_FOLDING 1
139#endif 139#endif
140 140
141/* undef below if compile with MFC */ 141/* undef below if compile with MFC */
142/* #define INCLUDEMFC 1 */ 142/* #define INCLUDEMFC 1 */
143 143
144#if defined(WIN32) || defined(_WIN32) 144#if defined(WIN32) || defined(_WIN32)
145#ifdef INCLUDEMFC 145#ifdef INCLUDEMFC
146#include <afx.h> 146#include <afx.h>
147#endif 147#endif
148#endif 148#endif
149 149
150#include <string.h> 150#include <string.h>
151#ifndef __MWERKS__ 151#ifndef __MWERKS__
152#include <stdlib.h> 152#include <stdlib.h>
153#endif 153#endif
154#include <stdio.h> 154#include <stdio.h>
155#include <stdlib.h> 155#include <stdlib.h>
156#include <ctype.h> 156#include <ctype.h>
157 157
158/*#ifdef PALMTOPCENTER */ 158/*#ifdef PALMTOPCENTER */
159/*#include <qpe/vobject_p.h> */ 159/*#include <qpe/vobject_p.h> */
160/*#else */ 160/*#else */
161#include "vobject_p.h" 161#include <qtopia/private/vobject_p.h>
162/*#endif */ 162/*#endif */
163 163
164/**** Types, Constants ****/ 164/**** Types, Constants ****/
165 165
166 #define YYDEBUG 0/* 1 to compile in some debugging code */ 166 #define YYDEBUG 0/* 1 to compile in some debugging code */
167 #define MAXTOKEN 256/* maximum token (line) length */ 167 #define MAXTOKEN 256/* maximum token (line) length */
168 #define YYSTACKSIZE 100/* ~unref ? */ 168 #define YYSTACKSIZE 100/* ~unref ? */
169 #define MAXLEVEL 10/* max # of nested objects parseable */ 169 #define MAXLEVEL 10/* max # of nested objects parseable */
170 /* (includes outermost) */ 170 /* (includes outermost) */
171 171
172 172
173/**** Global Variables ****/ 173/**** Global Variables ****/
174int mime_lineNum, mime_numErrors; /* yyerror() can use these */ 174int mime_lineNum, mime_numErrors; /* yyerror() can use these */
175static VObject* vObjList; 175static VObject* vObjList;
176static VObject *curProp; 176static VObject *curProp;
177static VObject *curObj; 177static VObject *curObj;
178static VObject* ObjStack[MAXLEVEL]; 178static VObject* ObjStack[MAXLEVEL];
179static int ObjStackTop; 179static int ObjStackTop;
180 180
181 181
182/* A helpful utility for the rest of the app. */ 182/* A helpful utility for the rest of the app. */
183#if __CPLUSPLUS__ 183#if __CPLUSPLUS__
184extern "C" { 184extern "C" {
185#endif 185#endif
186 186
187 extern void yyerror(char *s); 187 extern void yyerror(char *s);
188 188
189#if __CPLUSPLUS__ 189#if __CPLUSPLUS__
190 }; 190 };
191#endif 191#endif
192 192
193int yyparse(); 193int yyparse();
194 194
195enum LexMode { 195enum LexMode {
196 L_NORMAL, 196 L_NORMAL,
197 L_VCARD, 197 L_VCARD,
198 L_VCAL, 198 L_VCAL,
199 L_VEVENT, 199 L_VEVENT,
200 L_VTODO, 200 L_VTODO,
201 L_VALUES, 201 L_VALUES,
202 L_BASE64, 202 L_BASE64,
203 L_QUOTED_PRINTABLE 203 L_QUOTED_PRINTABLE
204 }; 204 };
205 205
206/**** Private Forward Declarations ****/ 206/**** Private Forward Declarations ****/
207static int pushVObject(const char *prop); 207static int pushVObject(const char *prop);
208static VObject* popVObject(); 208static VObject* popVObject();
209static void lexPopMode(int top); 209static void lexPopMode(int top);
210static int lexWithinMode(enum LexMode mode); 210static int lexWithinMode(enum LexMode mode);
211static void lexPushMode(enum LexMode mode); 211static void lexPushMode(enum LexMode mode);
212static void enterProps(const char *s); 212static void enterProps(const char *s);
213static void enterAttr(const char *s1, const char *s2); 213static void enterAttr(const char *s1, const char *s2);
214static void enterValues(const char *value); 214static void enterValues(const char *value);
215#define mime_error yyerror 215#define mime_error yyerror
216void mime_error(char *s); 216void mime_error(char *s);
217void mime_error_(char *s); 217void mime_error_(char *s);
218 218
219#line 189 "backend/vcc.y" 219#line 189 "backend/vcc.y"
220typedef union { 220typedef union {
221 char *str; 221 char *str;
222 VObject *vobj; 222 VObject *vobj;
223 } YYSTYPE; 223 } YYSTYPE;
224#line 225 "y.tab.c" 224#line 225 "y.tab.c"
225#define EQ 257 225#define EQ 257
226#define COLON 258 226#define COLON 258
227#define DOT 259 227#define DOT 259
228#define SEMICOLON 260 228#define SEMICOLON 260
229#define SPACE 261 229#define SPACE 261
230#define HTAB 262 230#define HTAB 262
231#define LINESEP 263 231#define LINESEP 263
232#define NEWLINE 264 232#define NEWLINE 264
233#define BEGIN_VCARD 265 233#define BEGIN_VCARD 265
234#define END_VCARD 266 234#define END_VCARD 266
235#define BEGIN_VCAL 267 235#define BEGIN_VCAL 267
236#define END_VCAL 268 236#define END_VCAL 268
237#define BEGIN_VEVENT 269 237#define BEGIN_VEVENT 269
238#define END_VEVENT 270 238#define END_VEVENT 270
239#define BEGIN_VTODO 271 239#define BEGIN_VTODO 271
240#define END_VTODO 272 240#define END_VTODO 272
241#define ID 273 241#define ID 273
242#define STRING 274 242#define STRING 274
243#define YYERRCODE 256 243#define YYERRCODE 256
244short vcclhs[] = { -1, 244short vcclhs[] = { -1,
245 0, 6, 6, 5, 5, 8, 3, 9, 3, 7, 245 0, 6, 6, 5, 5, 8, 3, 9, 3, 7,
246 7, 13, 10, 10, 15, 11, 11, 14, 14, 16, 246 7, 13, 10, 10, 15, 11, 11, 14, 14, 16,
247 17, 17, 1, 18, 12, 12, 2, 2, 20, 4, 247 17, 17, 1, 18, 12, 12, 2, 2, 20, 4,
248 21, 4, 19, 19, 22, 22, 22, 25, 23, 26, 248 21, 4, 19, 19, 22, 22, 22, 25, 23, 26,
249 23, 27, 24, 28, 24, 249 23, 27, 24, 28, 24,
250}; 250};
251short vcclen[] = { 2, 251short vcclen[] = { 2,
252 1, 2, 1, 1, 1, 0, 4, 0, 3, 2, 252 1, 2, 1, 1, 1, 0, 4, 0, 3, 2,
253 1, 0, 5, 1, 0, 3, 1, 2, 1, 2, 253 1, 0, 5, 1, 0, 3, 1, 2, 1, 2,
254 1, 3, 1, 0, 4, 1, 1, 0, 0, 4, 254 1, 3, 1, 0, 4, 1, 1, 0, 0, 4,
255 0, 3, 2, 1, 1, 1, 1, 0, 4, 0, 255 0, 3, 2, 1, 1, 1, 1, 0, 4, 0,
256 3, 0, 4, 0, 3, 256 3, 0, 4, 0, 3,
257}; 257};
258short vccdefred[] = { 0, 258short vccdefred[] = { 0,
259 0, 0, 0, 4, 5, 3, 0, 0, 0, 0, 259 0, 0, 0, 4, 5, 3, 0, 0, 0, 0,
260 0, 2, 14, 23, 0, 0, 11, 0, 9, 0, 260 0, 2, 14, 23, 0, 0, 11, 0, 9, 0,
261 0, 0, 0, 34, 35, 36, 32, 0, 7, 10, 261 0, 0, 0, 34, 35, 36, 32, 0, 7, 10,
262 12, 0, 0, 0, 0, 30, 33, 0, 0, 19, 262 12, 0, 0, 0, 0, 30, 33, 0, 0, 19,
263 0, 0, 41, 0, 45, 0, 20, 18, 27, 0, 263 0, 0, 41, 0, 45, 0, 20, 18, 27, 0,
264 0, 39, 43, 0, 24, 13, 22, 0, 25, 264 0, 39, 43, 0, 24, 13, 22, 0, 25,
265}; 265};
266short vccdgoto[] = { 3, 266short vccdgoto[] = { 3,
267 15, 50, 4, 5, 6, 7, 22, 8, 9, 17, 267 15, 50, 4, 5, 6, 7, 22, 8, 9, 17,
268 18, 51, 41, 39, 28, 40, 47, 58, 23, 10, 268 18, 51, 41, 39, 28, 40, 47, 58, 23, 10,
269 11, 24, 25, 26, 32, 33, 34, 35, 269 11, 24, 25, 26, 32, 33, 34, 35,
270}; 270};
271short vccsindex[] = { -262, 271short vccsindex[] = { -262,
272 0, 0, 0, 0, 0, 0, -262, -252, -219, -249, 272 0, 0, 0, 0, 0, 0, -262, -252, -219, -249,
273 -256, 0, 0, 0, 0, -227, 0, -242, 0, 0, 273 -256, 0, 0, 0, 0, -227, 0, -242, 0, 0,
274 0, -252, -254, 0, 0, 0, 0, -208, 0, 0, 274 0, -252, -254, 0, 0, 0, 0, -208, 0, 0,
275 0, -252, -228, -252, -213, 0, 0, -212, -208, 0, 275 0, -252, -228, -252, -213, 0, 0, -212, -208, 0,
276 -214, -233, 0, -224, 0, -195, 0, 0, 0, -197, 276 -214, -233, 0, -224, 0, -195, 0, 0, 0, -197,
277 -199, 0, 0, -212, 0, 0, 0, -214, 0, 277 -199, 0, 0, -212, 0, 0, 0, -214, 0,
278}; 278};
279short vccrindex[] = { 0, 279short vccrindex[] = { 0,
280 -222, -238, 0, 0, 0, 0, 65, 0, 0, 0, 280 -222, -238, 0, 0, 0, 0, 65, 0, 0, 0,
281 0, 0, 0, 0, -215, 0, 0, 0, 0, -220, 281 0, 0, 0, 0, -215, 0, 0, 0, 0, -220,
282 -218, -260, 0, 0, 0, 0, 0, 0, 0, 0, 282 -218, -260, 0, 0, 0, 0, 0, 0, 0, 0,
283 0, 0, 0, 0, 0, 0, 0, 0, -192, 0, 283 0, 0, 0, 0, 0, 0, 0, 0, -192, 0,
284 -250, 0, 0, 0, 0, -202, 0, 0, 0, -196, 284 -250, 0, 0, 0, 0, -202, 0, 0, 0, -196,
285 0, 0, 0, 0, 0, 0, 0, -250, 0, 285 0, 0, 0, 0, 0, 0, 0, -250, 0,
286}; 286};
287short vccgindex[] = { 0, 287short vccgindex[] = { 0,
288 3, 0, 0, 0, 61, 0, -7, 0, 0, -16, 288 3, 0, 0, 0, 61, 0, -7, 0, 0, -16,
289 0, 11, 0, 0, 0, 31, 0, 0, 0, 0, 289 0, 11, 0, 0, 0, 31, 0, 0, 0, 0,
290 0, 48, 0, 0, 0, 0, 0, 0, 290 0, 48, 0, 0, 0, 0, 0, 0,
291}; 291};
292#define YYTABLESIZE 71 292#define YYTABLESIZE 71
293short vcctable[] = { 30, 293short vcctable[] = { 30,
294 16, 13, 1, 13, 2, 30, 13, 37, 37, 28, 294 16, 13, 1, 13, 2, 30, 13, 37, 37, 28,
295 37, 27, 28, 36, 20, 31, 21, 29, 14, 20, 295 37, 27, 28, 36, 20, 31, 21, 29, 14, 20,
296 14, 21, 13, 14, 42, 30, 44, 30, 13, 31, 296 14, 21, 13, 14, 42, 30, 44, 30, 13, 31,
297 29, 13, 29, 6, 29, 38, 52, 42, 29, 14, 297 29, 13, 29, 6, 29, 38, 52, 42, 29, 14,
298 46, 43, 17, 8, 15, 14, 19, 53, 14, 40, 298 46, 43, 17, 8, 15, 14, 19, 53, 14, 40,
299 6, 38, 38, 44, 42, 21, 57, 21, 45, 49, 299 6, 38, 38, 44, 42, 21, 57, 21, 45, 49,
300 14, 54, 55, 56, 1, 16, 26, 12, 59, 48, 300 14, 54, 55, 56, 1, 16, 26, 12, 59, 48,
301 37, 301 37,
302}; 302};
303short vcccheck[] = { 16, 303short vcccheck[] = { 16,
304 8, 256, 265, 256, 267, 22, 256, 268, 269, 260, 304 8, 256, 265, 256, 267, 22, 256, 268, 269, 260,
305 271, 268, 263, 268, 269, 258, 271, 256, 273, 269, 305 271, 268, 263, 268, 269, 258, 271, 256, 273, 269,
306 273, 271, 256, 273, 32, 42, 34, 44, 256, 268, 306 273, 271, 256, 273, 32, 42, 34, 44, 256, 268,
307 269, 256, 271, 256, 273, 256, 270, 256, 266, 273, 307 269, 256, 271, 256, 273, 256, 270, 256, 266, 273,
308 38, 270, 258, 266, 260, 273, 266, 272, 273, 270, 308 38, 270, 258, 266, 260, 273, 266, 272, 273, 270,
309 273, 260, 273, 272, 273, 258, 54, 260, 272, 274, 309 273, 260, 273, 272, 273, 258, 54, 260, 272, 274,
310 273, 257, 260, 263, 0, 258, 263, 7, 58, 39, 310 273, 257, 260, 263, 0, 258, 263, 7, 58, 39,
311 23, 311 23,
312}; 312};
313#define YYFINAL 3 313#define YYFINAL 3
314#ifndef YYDEBUG 314#ifndef YYDEBUG
315#define YYDEBUG 0 315#define YYDEBUG 0
316#endif 316#endif
317#define YYMAXTOKEN 274 317#define YYMAXTOKEN 274
318#if YYDEBUG 318#if YYDEBUG
319char *vccname[] = { 319char *vccname[] = {
320"end-of-file",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 320"end-of-file",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
3210,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 3210,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
3220,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 3220,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
3230,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 3230,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
3240,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 3240,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
3250,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 3250,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
3260,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"EQ","COLON","DOT","SEMICOLON", 3260,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"EQ","COLON","DOT","SEMICOLON",
327"SPACE","HTAB","LINESEP","NEWLINE","BEGIN_VCARD","END_VCARD","BEGIN_VCAL", 327"SPACE","HTAB","LINESEP","NEWLINE","BEGIN_VCARD","END_VCARD","BEGIN_VCAL",
328"END_VCAL","BEGIN_VEVENT","END_VEVENT","BEGIN_VTODO","END_VTODO","ID","STRING", 328"END_VCAL","BEGIN_VEVENT","END_VEVENT","BEGIN_VTODO","END_VTODO","ID","STRING",
329}; 329};
330char *vccrule[] = { 330char *vccrule[] = {
331"$accept : mime", 331"$accept : mime",
332"mime : vobjects", 332"mime : vobjects",
333"vobjects : vobjects vobject", 333"vobjects : vobjects vobject",
334"vobjects : vobject", 334"vobjects : vobject",
335"vobject : vcard", 335"vobject : vcard",
336"vobject : vcal", 336"vobject : vcal",
337"$$1 :", 337"$$1 :",
338"vcard : BEGIN_VCARD $$1 items END_VCARD", 338"vcard : BEGIN_VCARD $$1 items END_VCARD",
339"$$2 :", 339"$$2 :",
340"vcard : BEGIN_VCARD $$2 END_VCARD", 340"vcard : BEGIN_VCARD $$2 END_VCARD",
341"items : items item", 341"items : items item",
342"items : item", 342"items : item",
343"$$3 :", 343"$$3 :",
344"item : prop COLON $$3 values LINESEP", 344"item : prop COLON $$3 values LINESEP",
345"item : error", 345"item : error",
346"$$4 :", 346"$$4 :",
347"prop : name $$4 attr_params", 347"prop : name $$4 attr_params",
348"prop : name", 348"prop : name",
349"attr_params : attr_params attr_param", 349"attr_params : attr_params attr_param",
350"attr_params : attr_param", 350"attr_params : attr_param",
351"attr_param : SEMICOLON attr", 351"attr_param : SEMICOLON attr",
352"attr : name", 352"attr : name",
353"attr : name EQ name", 353"attr : name EQ name",
354"name : ID", 354"name : ID",
355"$$5 :", 355"$$5 :",
356"values : value SEMICOLON $$5 values", 356"values : value SEMICOLON $$5 values",
357"values : value", 357"values : value",
358"value : STRING", 358"value : STRING",
359"value :", 359"value :",
360"$$6 :", 360"$$6 :",
361"vcal : BEGIN_VCAL $$6 calitems END_VCAL", 361"vcal : BEGIN_VCAL $$6 calitems END_VCAL",
362"$$7 :", 362"$$7 :",
363"vcal : BEGIN_VCAL $$7 END_VCAL", 363"vcal : BEGIN_VCAL $$7 END_VCAL",
364"calitems : calitems calitem", 364"calitems : calitems calitem",
365"calitems : calitem", 365"calitems : calitem",
366"calitem : eventitem", 366"calitem : eventitem",
367"calitem : todoitem", 367"calitem : todoitem",
368"calitem : items", 368"calitem : items",
369"$$8 :", 369"$$8 :",
370"eventitem : BEGIN_VEVENT $$8 items END_VEVENT", 370"eventitem : BEGIN_VEVENT $$8 items END_VEVENT",
371"$$9 :", 371"$$9 :",
372"eventitem : BEGIN_VEVENT $$9 END_VEVENT", 372"eventitem : BEGIN_VEVENT $$9 END_VEVENT",
373"$$10 :", 373"$$10 :",
374"todoitem : BEGIN_VTODO $$10 items END_VTODO", 374"todoitem : BEGIN_VTODO $$10 items END_VTODO",
375"$$11 :", 375"$$11 :",
376"todoitem : BEGIN_VTODO $$11 END_VTODO", 376"todoitem : BEGIN_VTODO $$11 END_VTODO",
377}; 377};
378#endif 378#endif
379#ifdef YYSTACKSIZE 379#ifdef YYSTACKSIZE
380#undef YYMAXDEPTH 380#undef YYMAXDEPTH
381#define YYMAXDEPTH YYSTACKSIZE 381#define YYMAXDEPTH YYSTACKSIZE
382#else 382#else
383#ifdef YYMAXDEPTH 383#ifdef YYMAXDEPTH
384#define YYSTACKSIZE YYMAXDEPTH 384#define YYSTACKSIZE YYMAXDEPTH
385#else 385#else
386#define YYSTACKSIZE 500 386#define YYSTACKSIZE 500
387#define YYMAXDEPTH 500 387#define YYMAXDEPTH 500
388#endif 388#endif
389#endif 389#endif
390int yydebug; 390int yydebug;
391int yynerrs; 391int yynerrs;
392int yyerrflag; 392int yyerrflag;
393int yychar; 393int yychar;
394short *yyssp; 394short *yyssp;
395YYSTYPE *yyvsp; 395YYSTYPE *yyvsp;
396YYSTYPE yyval; 396YYSTYPE yyval;
397YYSTYPE yylval; 397YYSTYPE yylval;
398short yyss[YYSTACKSIZE]; 398short yyss[YYSTACKSIZE];
399YYSTYPE yyvs[YYSTACKSIZE]; 399YYSTYPE yyvs[YYSTACKSIZE];
400#define yystacksize YYSTACKSIZE 400#define yystacksize YYSTACKSIZE
401#line 382 "backend/vcc.y" 401#line 382 "backend/vcc.y"
402 402
403/*------------------------------------*/ 403/*------------------------------------*/
404static int pushVObject(const char *prop) 404static int pushVObject(const char *prop)
405 { 405 {
406 VObject *newObj; 406 VObject *newObj;
407 if (ObjStackTop == MAXLEVEL) 407 if (ObjStackTop == MAXLEVEL)
408 return FALSE; 408 return FALSE;
409 409
410 ObjStack[++ObjStackTop] = curObj; 410 ObjStack[++ObjStackTop] = curObj;
411 411
412 if (curObj) { 412 if (curObj) {
413 newObj = addProp(curObj,prop); 413 newObj = addProp(curObj,prop);
414 curObj = newObj; 414 curObj = newObj;
415 } 415 }
416 else 416 else
417 curObj = newVObject(prop); 417 curObj = newVObject(prop);
418 418
419 return TRUE; 419 return TRUE;
420 } 420 }
421 421
422 422
423/*---------------------------------------*/ 423/*---------------------------------------*/
424/* This pops the recently built vCard off the stack and returns it. */ 424/* This pops the recently built vCard off the stack and returns it. */
425static VObject* popVObject() 425static VObject* popVObject()
426 { 426 {
427 VObject *oldObj; 427 VObject *oldObj;
428 if (ObjStackTop < 0) { 428 if (ObjStackTop < 0) {
429 yyerror("pop on empty Object Stack\n"); 429 yyerror("pop on empty Object Stack\n");
430 return 0; 430 return 0;
431 } 431 }
432 oldObj = curObj; 432 oldObj = curObj;
433 curObj = ObjStack[ObjStackTop--]; 433 curObj = ObjStack[ObjStackTop--];
434 434
435 return oldObj; 435 return oldObj;
436 } 436 }
437 437
438 438
439static void enterValues(const char *value) 439static void enterValues(const char *value)
440 { 440 {
441 if (fieldedProp && *fieldedProp) { 441 if (fieldedProp && *fieldedProp) {
442 if (value) { 442 if (value) {
443 addPropValue(curProp,*fieldedProp,value); 443 addPropValue(curProp,*fieldedProp,value);
444 } 444 }
445 /* else this field is empty, advance to next field */ 445 /* else this field is empty, advance to next field */
446 fieldedProp++; 446 fieldedProp++;
447 } 447 }
448 else { 448 else {
449 if (value) { 449 if (value) {
450 setVObjectStringZValue_(curProp,strdup( value )); 450 setVObjectStringZValue_(curProp,strdup( value ));
451 } 451 }
452 } 452 }
453 deleteStr(value); 453 deleteStr(value);
454 } 454 }
455 455
456static void enterProps(const char *s) 456static void enterProps(const char *s)
457 { 457 {
458 curProp = addGroup(curObj,s); 458 curProp = addGroup(curObj,s);
459 deleteStr(s); 459 deleteStr(s);
460 } 460 }
461 461
462static void enterAttr(const char *s1, const char *s2) 462static void enterAttr(const char *s1, const char *s2)
463 { 463 {
464 const char *p1, *p2; 464 const char *p1, *p2;
465 p1 = lookupProp_(s1); 465 p1 = lookupProp_(s1);
466 if (s2) { 466 if (s2) {
467 VObject *a; 467 VObject *a;
468 p2 = lookupProp_(s2); 468 p2 = lookupProp_(s2);
469 a = addProp(curProp,p1); 469 a = addProp(curProp,p1);
470 setVObjectStringZValue(a,p2); 470 setVObjectStringZValue(a,p2);
471 } 471 }
472 else 472 else
473 addProp(curProp,p1); 473 addProp(curProp,p1);
474 if (qstricmp(p1,VCBase64Prop) == 0 || (s2 && qstricmp(p2,VCBase64Prop)==0)) 474 if (qstricmp(p1,VCBase64Prop) == 0 || (s2 && qstricmp(p2,VCBase64Prop)==0))
475 lexPushMode(L_BASE64); 475 lexPushMode(L_BASE64);
476 else if (qstricmp(p1,VCQuotedPrintableProp) == 0 476 else if (qstricmp(p1,VCQuotedPrintableProp) == 0
477 || (s2 && qstricmp(p2,VCQuotedPrintableProp)==0)) 477 || (s2 && qstricmp(p2,VCQuotedPrintableProp)==0))
478 lexPushMode(L_QUOTED_PRINTABLE); 478 lexPushMode(L_QUOTED_PRINTABLE);
479 deleteStr(s1); deleteStr(s2); 479 deleteStr(s1); deleteStr(s2);
480 } 480 }
481 481
482 482
483#define MAX_LEX_LOOKAHEAD_0 32 483#define MAX_LEX_LOOKAHEAD_0 32
484#define MAX_LEX_LOOKAHEAD 64 484#define MAX_LEX_LOOKAHEAD 64
485#define MAX_LEX_MODE_STACK_SIZE 10 485#define MAX_LEX_MODE_STACK_SIZE 10
486#define LEXMODE() (lexBuf.lexModeStack[lexBuf.lexModeStackTop]) 486#define LEXMODE() (lexBuf.lexModeStack[lexBuf.lexModeStackTop])
487 487
488struct LexBuf { 488struct LexBuf {
489 /* input */ 489 /* input */
490#ifdef INCLUDEMFC 490#ifdef INCLUDEMFC
491 CFile *inputFile; 491 CFile *inputFile;
492#else 492#else
493 FILE *inputFile; 493 FILE *inputFile;
494#endif 494#endif
495 char *inputString; 495 char *inputString;
496 unsigned long curPos; 496 unsigned long curPos;
497 unsigned long inputLen; 497 unsigned long inputLen;
498 /* lookahead buffer */ 498 /* lookahead buffer */
499 /* -- lookahead buffer is short instead of char so that EOF 499 /* -- lookahead buffer is short instead of char so that EOF
500 / can be represented correctly. 500 / can be represented correctly.
501 */ 501 */
502 unsigned long len; 502 unsigned long len;
503 short buf[MAX_LEX_LOOKAHEAD]; 503 short buf[MAX_LEX_LOOKAHEAD];
504 unsigned long getPtr; 504 unsigned long getPtr;
505 /* context stack */ 505 /* context stack */
506 unsigned long lexModeStackTop; 506 unsigned long lexModeStackTop;
507 enum LexMode lexModeStack[MAX_LEX_MODE_STACK_SIZE]; 507 enum LexMode lexModeStack[MAX_LEX_MODE_STACK_SIZE];
508 /* token buffer */ 508 /* token buffer */
509 unsigned long maxToken; 509 unsigned long maxToken;
510 char *strs; 510 char *strs;
511 unsigned long strsLen; 511 unsigned long strsLen;
512 } lexBuf; 512 } lexBuf;
513 513
514static void lexPushMode(enum LexMode mode) 514static void lexPushMode(enum LexMode mode)
515 { 515 {
516 if (lexBuf.lexModeStackTop == (MAX_LEX_MODE_STACK_SIZE-1)) 516 if (lexBuf.lexModeStackTop == (MAX_LEX_MODE_STACK_SIZE-1))
517 yyerror("lexical context stack overflow"); 517 yyerror("lexical context stack overflow");
518 else { 518 else {
519 lexBuf.lexModeStack[++lexBuf.lexModeStackTop] = mode; 519 lexBuf.lexModeStack[++lexBuf.lexModeStackTop] = mode;
520 } 520 }
521 } 521 }
522 522
523static void lexPopMode(int top) 523static void lexPopMode(int top)
524 { 524 {
525 /* special case of pop for ease of error recovery -- this 525 /* special case of pop for ease of error recovery -- this
526 version will never underflow */ 526 version will never underflow */
527 if (top) 527 if (top)
528 lexBuf.lexModeStackTop = 0; 528 lexBuf.lexModeStackTop = 0;
529 else 529 else
530 if (lexBuf.lexModeStackTop > 0) lexBuf.lexModeStackTop--; 530 if (lexBuf.lexModeStackTop > 0) lexBuf.lexModeStackTop--;
531 } 531 }
532 532
533static int lexWithinMode(enum LexMode mode) { 533static int lexWithinMode(enum LexMode mode) {
534 unsigned long i; 534 unsigned long i;
535 for (i=0;i<lexBuf.lexModeStackTop;i++) 535 for (i=0;i<lexBuf.lexModeStackTop;i++)
536 if (mode == lexBuf.lexModeStack[i]) return 1; 536 if (mode == lexBuf.lexModeStack[i]) return 1;
537 return 0; 537 return 0;
538 } 538 }
539 539
540static int lexGetc_() 540static int lexGetc_()
541 { 541 {
542 /* get next char from input, no buffering. */ 542 /* get next char from input, no buffering. */
543 if (lexBuf.curPos == lexBuf.inputLen) 543 if (lexBuf.curPos == lexBuf.inputLen)
544 return EOF; 544 return EOF;
545 else if (lexBuf.inputString) 545 else if (lexBuf.inputString)
546 return *(lexBuf.inputString + lexBuf.curPos++); 546 return *(lexBuf.inputString + lexBuf.curPos++);
547 else { 547 else {
548#ifdef INCLUDEMFC 548#ifdef INCLUDEMFC
549 char result; 549 char result;
550 return lexBuf.inputFile->Read(&result, 1) == 1 ? result : EOF; 550 return lexBuf.inputFile->Read(&result, 1) == 1 ? result : EOF;
551#else 551#else
552 return fgetc(lexBuf.inputFile); 552 return fgetc(lexBuf.inputFile);
553#endif 553#endif
554 } 554 }
555 } 555 }
556 556
557static int lexGeta() 557static int lexGeta()
558 { 558 {
559 ++lexBuf.len; 559 ++lexBuf.len;
560 return (lexBuf.buf[lexBuf.getPtr] = lexGetc_()); 560 return (lexBuf.buf[lexBuf.getPtr] = lexGetc_());
561 } 561 }
562 562
563static int lexGeta_(int i) 563static int lexGeta_(int i)
564 { 564 {
565 ++lexBuf.len; 565 ++lexBuf.len;
566 return (lexBuf.buf[(lexBuf.getPtr+i)%MAX_LEX_LOOKAHEAD] = lexGetc_()); 566 return (lexBuf.buf[(lexBuf.getPtr+i)%MAX_LEX_LOOKAHEAD] = lexGetc_());
567 } 567 }
568 568
569static void lexSkipLookahead() { 569static void lexSkipLookahead() {
570 if (lexBuf.len > 0 && lexBuf.buf[lexBuf.getPtr]!=EOF) { 570 if (lexBuf.len > 0 && lexBuf.buf[lexBuf.getPtr]!=EOF) {
571 /* don't skip EOF. */ 571 /* don't skip EOF. */
572 lexBuf.getPtr = (lexBuf.getPtr + 1) % MAX_LEX_LOOKAHEAD; 572 lexBuf.getPtr = (lexBuf.getPtr + 1) % MAX_LEX_LOOKAHEAD;
573 lexBuf.len--; 573 lexBuf.len--;
574 } 574 }
575 } 575 }
576 576
577static int lexLookahead() { 577static int lexLookahead() {
578 int c = (lexBuf.len)? 578 int c = (lexBuf.len)?
579 lexBuf.buf[lexBuf.getPtr]: 579 lexBuf.buf[lexBuf.getPtr]:
580 lexGeta(); 580 lexGeta();
581 /* do the \r\n -> \n or \r -> \n translation here */ 581 /* do the \r\n -> \n or \r -> \n translation here */
582 if (c == '\r') { 582 if (c == '\r') {
583 int a = (lexBuf.len>1)? 583 int a = (lexBuf.len>1)?
584 lexBuf.buf[(lexBuf.getPtr+1)%MAX_LEX_LOOKAHEAD]: 584 lexBuf.buf[(lexBuf.getPtr+1)%MAX_LEX_LOOKAHEAD]:
585 lexGeta_(1); 585 lexGeta_(1);
586 if (a == '\n') { 586 if (a == '\n') {
587 lexSkipLookahead(); 587 lexSkipLookahead();
588 } 588 }
589 lexBuf.buf[lexBuf.getPtr] = c = '\n'; 589 lexBuf.buf[lexBuf.getPtr] = c = '\n';
590 } 590 }
591 else if (c == '\n') { 591 else if (c == '\n') {
592 int a = (lexBuf.len>1)? 592 int a = (lexBuf.len>1)?
593 lexBuf.buf[lexBuf.getPtr+1]: 593 lexBuf.buf[lexBuf.getPtr+1]:
594 lexGeta_(1); 594 lexGeta_(1);
595 if (a == '\r') { 595 if (a == '\r') {
596 lexSkipLookahead(); 596 lexSkipLookahead();
597 } 597 }
598 lexBuf.buf[lexBuf.getPtr] = '\n'; 598 lexBuf.buf[lexBuf.getPtr] = '\n';
599 } 599 }
600 return c; 600 return c;
601 } 601 }
602 602
603static int lexGetc() { 603static int lexGetc() {
604 int c = lexLookahead(); 604 int c = lexLookahead();
605 if (lexBuf.len > 0 && lexBuf.buf[lexBuf.getPtr]!=EOF) { 605 if (lexBuf.len > 0 && lexBuf.buf[lexBuf.getPtr]!=EOF) {
606 /* EOF will remain in lookahead buffer */ 606 /* EOF will remain in lookahead buffer */
607 lexBuf.getPtr = (lexBuf.getPtr + 1) % MAX_LEX_LOOKAHEAD; 607 lexBuf.getPtr = (lexBuf.getPtr + 1) % MAX_LEX_LOOKAHEAD;
608 lexBuf.len--; 608 lexBuf.len--;
609 } 609 }
610 return c; 610 return c;
611 } 611 }
612 612
613static void lexSkipLookaheadWord() { 613static void lexSkipLookaheadWord() {
614 if (lexBuf.strsLen <= lexBuf.len) { 614 if (lexBuf.strsLen <= lexBuf.len) {
615 lexBuf.len -= lexBuf.strsLen; 615 lexBuf.len -= lexBuf.strsLen;
616 lexBuf.getPtr = (lexBuf.getPtr + lexBuf.strsLen) % MAX_LEX_LOOKAHEAD; 616 lexBuf.getPtr = (lexBuf.getPtr + lexBuf.strsLen) % MAX_LEX_LOOKAHEAD;
617 } 617 }
618 } 618 }
619 619
620static void lexClearToken() 620static void lexClearToken()
621 { 621 {
622 lexBuf.strsLen = 0; 622 lexBuf.strsLen = 0;
623 } 623 }
624 624
625static void lexAppendc(int c) 625static void lexAppendc(int c)
626 { 626 {
627 lexBuf.strs[lexBuf.strsLen] = c; 627 lexBuf.strs[lexBuf.strsLen] = c;
628 /* append up to zero termination */ 628 /* append up to zero termination */
629 if (c == 0) return; 629 if (c == 0) return;
630 lexBuf.strsLen++; 630 lexBuf.strsLen++;
631 if (lexBuf.strsLen > lexBuf.maxToken) { 631 if (lexBuf.strsLen > lexBuf.maxToken) {
632 /* double the token string size */ 632 /* double the token string size */
633 lexBuf.maxToken <<= 1; 633 lexBuf.maxToken <<= 1;
634 lexBuf.strs = (char*) realloc(lexBuf.strs,(size_t)lexBuf.maxToken); 634 lexBuf.strs = (char*) realloc(lexBuf.strs,(size_t)lexBuf.maxToken);
635 } 635 }
636 } 636 }
637 637
638static char* lexStr() { 638static char* lexStr() {
639 return dupStr(lexBuf.strs,(size_t)lexBuf.strsLen+1); 639 return dupStr(lexBuf.strs,(size_t)lexBuf.strsLen+1);
640 } 640 }
641 641
642static void lexSkipWhite() { 642static void lexSkipWhite() {
643 int c = lexLookahead(); 643 int c = lexLookahead();
644 while (c == ' ' || c == '\t') { 644 while (c == ' ' || c == '\t') {
645 lexSkipLookahead(); 645 lexSkipLookahead();
646 c = lexLookahead(); 646 c = lexLookahead();
647 } 647 }
648 } 648 }
649 649
650static char* lexGetWord() { 650static char* lexGetWord() {
651 int c; 651 int c;
652 lexSkipWhite(); 652 lexSkipWhite();
653 lexClearToken(); 653 lexClearToken();
654 c = lexLookahead(); 654 c = lexLookahead();
655 while (c != EOF && !strchr("\t\n ;:=",c)) { 655 while (c != EOF && !strchr("\t\n ;:=",c)) {
656 lexAppendc(c); 656 lexAppendc(c);
657 lexSkipLookahead(); 657 lexSkipLookahead();
658 c = lexLookahead(); 658 c = lexLookahead();
659 } 659 }
660 lexAppendc(0); 660 lexAppendc(0);
661 return lexStr(); 661 return lexStr();
662 } 662 }
663 663
664static void lexPushLookaheadc(int c) { 664static void lexPushLookaheadc(int c) {
665 int putptr; 665 int putptr;
666 /* can't putback EOF, because it never leaves lookahead buffer */ 666 /* can't putback EOF, because it never leaves lookahead buffer */
667 if (c == EOF) return; 667 if (c == EOF) return;
668 putptr = (int)lexBuf.getPtr - 1; 668 putptr = (int)lexBuf.getPtr - 1;
669 if (putptr < 0) putptr += MAX_LEX_LOOKAHEAD; 669 if (putptr < 0) putptr += MAX_LEX_LOOKAHEAD;
670 lexBuf.getPtr = putptr; 670 lexBuf.getPtr = putptr;
671 lexBuf.buf[putptr] = c; 671 lexBuf.buf[putptr] = c;
672 lexBuf.len += 1; 672 lexBuf.len += 1;
673 } 673 }
674 674
675static char* lexLookaheadWord() { 675static char* lexLookaheadWord() {
676 /* this function can lookahead word with max size of MAX_LEX_LOOKAHEAD_0 676 /* this function can lookahead word with max size of MAX_LEX_LOOKAHEAD_0
677 / and thing bigger than that will stop the lookahead and return 0; 677 / and thing bigger than that will stop the lookahead and return 0;
678 / leading white spaces are not recoverable. 678 / leading white spaces are not recoverable.
679 */ 679 */
680 int c; 680 int c;
681 int len = 0; 681 int len = 0;
682 int curgetptr = 0; 682 int curgetptr = 0;
683 lexSkipWhite(); 683 lexSkipWhite();
684 lexClearToken(); 684 lexClearToken();
685 curgetptr = (int)lexBuf.getPtr;// remember! 685 curgetptr = (int)lexBuf.getPtr;// remember!
686 while (len < (MAX_LEX_LOOKAHEAD_0)) { 686 while (len < (MAX_LEX_LOOKAHEAD_0)) {
687 c = lexGetc(); 687 c = lexGetc();
688 len++; 688 len++;
689 if (c == EOF || strchr("\t\n ;:=", c)) { 689 if (c == EOF || strchr("\t\n ;:=", c)) {
690 lexAppendc(0); 690 lexAppendc(0);
691 /* restore lookahead buf. */ 691 /* restore lookahead buf. */
692 lexBuf.len += len; 692 lexBuf.len += len;
693 lexBuf.getPtr = curgetptr; 693 lexBuf.getPtr = curgetptr;
694 return lexStr(); 694 return lexStr();
695 } 695 }
696 else 696 else
697 lexAppendc(c); 697 lexAppendc(c);
698 } 698 }
699 lexBuf.len += len;/* char that has been moved to lookahead buffer */ 699 lexBuf.len += len;/* char that has been moved to lookahead buffer */
700 lexBuf.getPtr = curgetptr; 700 lexBuf.getPtr = curgetptr;
701 return 0; 701 return 0;
702 } 702 }
703 703
704#ifdef _SUPPORT_LINE_FOLDING 704#ifdef _SUPPORT_LINE_FOLDING
705static void handleMoreRFC822LineBreak(int c) { 705static void handleMoreRFC822LineBreak(int c) {
706 /* suport RFC 822 line break in cases like 706 /* suport RFC 822 line break in cases like
707 *ADR: foo; 707 *ADR: foo;
708 * morefoo; 708 * morefoo;
709 * more foo; 709 * more foo;
710 */ 710 */
711 if (c == ';') { 711 if (c == ';') {
712 int a; 712 int a;
713 lexSkipLookahead(); 713 lexSkipLookahead();
714 /* skip white spaces */ 714 /* skip white spaces */
715 a = lexLookahead(); 715 a = lexLookahead();
716 while (a == ' ' || a == '\t') { 716 while (a == ' ' || a == '\t') {
717 lexSkipLookahead(); 717 lexSkipLookahead();
718 a = lexLookahead(); 718 a = lexLookahead();
719 } 719 }
720 if (a == '\n') { 720 if (a == '\n') {
721 lexSkipLookahead(); 721 lexSkipLookahead();
722 a = lexLookahead(); 722 a = lexLookahead();
723 if (a == ' ' || a == '\t') { 723 if (a == ' ' || a == '\t') {
724 /* continuation, throw away all the \n and spaces read so 724 /* continuation, throw away all the \n and spaces read so
725 * far 725 * far
726 */ 726 */
727 lexSkipWhite(); 727 lexSkipWhite();
728 lexPushLookaheadc(';'); 728 lexPushLookaheadc(';');
729 } 729 }
730 else { 730 else {
731 lexPushLookaheadc('\n'); 731 lexPushLookaheadc('\n');
732 lexPushLookaheadc(';'); 732 lexPushLookaheadc(';');
733 } 733 }
734 } 734 }
735 else { 735 else {
736 lexPushLookaheadc(';'); 736 lexPushLookaheadc(';');
737 } 737 }
738 } 738 }
739 } 739 }
740 740
741static char* lexGet1Value() { 741static char* lexGet1Value() {
742 int c; 742 int c;
743 lexSkipWhite(); 743 lexSkipWhite();
744 c = lexLookahead(); 744 c = lexLookahead();
745 lexClearToken(); 745 lexClearToken();
746 while (c != EOF && c != ';') { 746 while (c != EOF && c != ';') {
747 if (c == '\\' ) { 747 if (c == '\\' ) {
748 int a; 748 int a;
749 lexSkipLookahead(); 749 lexSkipLookahead();
750 a = lexLookahead(); 750 a = lexLookahead();
751 if ( a != ';' ) { 751 if ( a != ';' ) {
752 lexAppendc('\\'); 752 lexAppendc('\\');
753 } else { 753 } else {
754 lexAppendc( ';' ); 754 lexAppendc( ';' );
755 lexSkipLookahead(); 755 lexSkipLookahead();
756 } 756 }
757 } else if (c == '\n') { 757 } else if (c == '\n') {
758 int a; 758 int a;
759 lexSkipLookahead(); 759 lexSkipLookahead();
760 a = lexLookahead(); 760 a = lexLookahead();
761 if (a == ' ' || a == '\t') { 761 if (a == ' ' || a == '\t') {
762 lexAppendc(' '); 762 lexAppendc(' ');
763 lexSkipLookahead(); 763 lexSkipLookahead();
764 } 764 }
765 else { 765 else {
766 lexPushLookaheadc('\n'); 766 lexPushLookaheadc('\n');
767 break; 767 break;
768 } 768 }
769 } 769 }
770 else { 770 else {
771 lexAppendc(c); 771 lexAppendc(c);
772 lexSkipLookahead(); 772 lexSkipLookahead();
773 } 773 }
774 c = lexLookahead(); 774 c = lexLookahead();
775 } 775 }
776 lexAppendc(0); 776 lexAppendc(0);
777 handleMoreRFC822LineBreak(c); 777 handleMoreRFC822LineBreak(c);
778 return c==EOF?0:lexStr(); 778 return c==EOF?0:lexStr();
779 } 779 }
780#endif 780#endif
781 781
782static int match_begin_name(int end) { 782static int match_begin_name(int end) {
783 char *n = lexLookaheadWord(); 783 char *n = lexLookaheadWord();
784 int token = ID; 784 int token = ID;
785 if (n) { 785 if (n) {
786 if (!qstricmp(n,"vcard")) token = end?END_VCARD:BEGIN_VCARD; 786 if (!qstricmp(n,"vcard")) token = end?END_VCARD:BEGIN_VCARD;
787 else if (!qstricmp(n,"vcalendar")) token = end?END_VCAL:BEGIN_VCAL; 787 else if (!qstricmp(n,"vcalendar")) token = end?END_VCAL:BEGIN_VCAL;
788 else if (!qstricmp(n,"vevent")) token = end?END_VEVENT:BEGIN_VEVENT; 788 else if (!qstricmp(n,"vevent")) token = end?END_VEVENT:BEGIN_VEVENT;
789 else if (!qstricmp(n,"vtodo")) token = end?END_VTODO:BEGIN_VTODO; 789 else if (!qstricmp(n,"vtodo")) token = end?END_VTODO:BEGIN_VTODO;
790 deleteStr(n); 790 deleteStr(n);
791 return token; 791 return token;
792 } 792 }
793 return 0; 793 return 0;
794 } 794 }
795 795
796 796
797#ifdef INCLUDEMFC 797#ifdef INCLUDEMFC
798void initLex(const char *inputstring, unsigned long inputlen, CFile *inputfile) 798void initLex(const char *inputstring, unsigned long inputlen, CFile *inputfile)
799#else 799#else
800void initLex(const char *inputstring, unsigned long inputlen, FILE *inputfile) 800void initLex(const char *inputstring, unsigned long inputlen, FILE *inputfile)
801#endif 801#endif
802 { 802 {
803 // initialize lex mode stack 803 // initialize lex mode stack
804 lexBuf.lexModeStack[lexBuf.lexModeStackTop=0] = L_NORMAL; 804 lexBuf.lexModeStack[lexBuf.lexModeStackTop=0] = L_NORMAL;
805 805
806 // iniatialize lex buffer. 806 // iniatialize lex buffer.
807 lexBuf.inputString = (char*) inputstring; 807 lexBuf.inputString = (char*) inputstring;
808 lexBuf.inputLen = inputlen; 808 lexBuf.inputLen = inputlen;
809 lexBuf.curPos = 0; 809 lexBuf.curPos = 0;
810 lexBuf.inputFile = inputfile; 810 lexBuf.inputFile = inputfile;
811 811
812 lexBuf.len = 0; 812 lexBuf.len = 0;
813 lexBuf.getPtr = 0; 813 lexBuf.getPtr = 0;
814 814
815 lexBuf.maxToken = MAXTOKEN; 815 lexBuf.maxToken = MAXTOKEN;
816 lexBuf.strs = (char*)malloc(MAXTOKEN); 816 lexBuf.strs = (char*)malloc(MAXTOKEN);
817 lexBuf.strsLen = 0; 817 lexBuf.strsLen = 0;
818 818
819 } 819 }
820 820
821static void finiLex() { 821static void finiLex() {
822 free(lexBuf.strs); 822 free(lexBuf.strs);
823 } 823 }
824 824
825 825
826/*-----------------------------------*/ 826/*-----------------------------------*/
827/* This parses and converts the base64 format for binary encoding into 827/* This parses and converts the base64 format for binary encoding into
828 * a decoded buffer (allocated with new). See RFC 1521. 828 * a decoded buffer (allocated with new). See RFC 1521.
829 */ 829 */
830static char * lexGetDataFromBase64() 830static char * lexGetDataFromBase64()
831 { 831 {
832 unsigned long bytesLen = 0, bytesMax = 0; 832 unsigned long bytesLen = 0, bytesMax = 0;
833 int quadIx = 0, pad = 0; 833 int quadIx = 0, pad = 0;
834 unsigned long trip = 0; 834 unsigned long trip = 0;
835 unsigned char b; 835 unsigned char b;
836 int c; 836 int c;
837 unsigned char *bytes = NULL; 837 unsigned char *bytes = NULL;
838 unsigned char *oldBytes = NULL; 838 unsigned char *oldBytes = NULL;
839 839
840 DBG_(("db: lexGetDataFromBase64\n")); 840 DBG_(("db: lexGetDataFromBase64\n"));
841 while (1) { 841 while (1) {
842 c = lexGetc(); 842 c = lexGetc();
843 if (c == '\n') { 843 if (c == '\n') {
844 ++mime_lineNum; 844 ++mime_lineNum;
845 if (lexLookahead() == '\n') { 845 if (lexLookahead() == '\n') {
846 /* a '\n' character by itself means end of data */ 846 /* a '\n' character by itself means end of data */
847 break; 847 break;
848 } 848 }
849 else continue; /* ignore '\n' */ 849 else continue; /* ignore '\n' */
850 } 850 }
851 else { 851 else {
852 if ((c >= 'A') && (c <= 'Z')) 852 if ((c >= 'A') && (c <= 'Z'))
853 b = (unsigned char)(c - 'A'); 853 b = (unsigned char)(c - 'A');
854 else if ((c >= 'a') && (c <= 'z')) 854 else if ((c >= 'a') && (c <= 'z'))
855 b = (unsigned char)(c - 'a') + 26; 855 b = (unsigned char)(c - 'a') + 26;
856 else if ((c >= '0') && (c <= '9')) 856 else if ((c >= '0') && (c <= '9'))
857 b = (unsigned char)(c - '0') + 52; 857 b = (unsigned char)(c - '0') + 52;
858 else if (c == '+') 858 else if (c == '+')
859 b = 62; 859 b = 62;
860 else if (c == '/') 860 else if (c == '/')
861 b = 63; 861 b = 63;
862 else if (c == '=') { 862 else if (c == '=') {
863 b = 0; 863 b = 0;
864 pad++; 864 pad++;
865 } else if ((c == ' ') || (c == '\t')) { 865 } else if ((c == ' ') || (c == '\t')) {
866 continue; 866 continue;
867 } else { /* error condition */ 867 } else { /* error condition */
868 if (bytes) free(bytes); 868 if (bytes) free(bytes);
869 else if (oldBytes) free(oldBytes); 869 else if (oldBytes) free(oldBytes);
870 // error recovery: skip until 2 adjacent newlines. 870 // error recovery: skip until 2 adjacent newlines.
871 DBG_(("db: invalid character 0x%x '%c'\n", c,c)); 871 DBG_(("db: invalid character 0x%x '%c'\n", c,c));
872 if (c != EOF) { 872 if (c != EOF) {
873 c = lexGetc(); 873 c = lexGetc();
874 while (c != EOF) { 874 while (c != EOF) {
875 if (c == '\n' && lexLookahead() == '\n') { 875 if (c == '\n' && lexLookahead() == '\n') {
876 ++mime_lineNum; 876 ++mime_lineNum;
877 break; 877 break;
878 } 878 }
879 c = lexGetc(); 879 c = lexGetc();
880 } 880 }
881 } 881 }
882 return NULL; 882 return NULL;
883 } 883 }
884 trip = (trip << 6) | b; 884 trip = (trip << 6) | b;
885 if (++quadIx == 4) { 885 if (++quadIx == 4) {
886 unsigned char outBytes[3]; 886 unsigned char outBytes[3];
887 int numOut; 887 int numOut;
888 int i; 888 int i;
889 for (i = 0; i < 3; i++) { 889 for (i = 0; i < 3; i++) {
890 outBytes[2-i] = (unsigned char)(trip & 0xFF); 890 outBytes[2-i] = (unsigned char)(trip & 0xFF);
891 trip >>= 8; 891 trip >>= 8;
892 } 892 }
893 numOut = 3 - pad; 893 numOut = 3 - pad;
894 if (bytesLen + numOut > bytesMax) { 894 if (bytesLen + numOut > bytesMax) {
895 if (!bytes) { 895 if (!bytes) {
896 bytesMax = 1024; 896 bytesMax = 1024;
897 bytes = (unsigned char*)malloc((size_t)bytesMax); 897 bytes = (unsigned char*)malloc((size_t)bytesMax);
898 } 898 }
899 else { 899 else {
900 bytesMax <<= 2; 900 bytesMax <<= 2;
901 oldBytes = bytes; 901 oldBytes = bytes;
902 bytes = (unsigned char*)realloc(bytes,(size_t)bytesMax); 902 bytes = (unsigned char*)realloc(bytes,(size_t)bytesMax);
903 } 903 }
904 if (bytes == 0) { 904 if (bytes == 0) {
905 mime_error("out of memory while processing BASE64 data\n"); 905 mime_error("out of memory while processing BASE64 data\n");
906 } 906 }
907 } 907 }
908 if (bytes) { 908 if (bytes) {
909 memcpy(bytes + bytesLen, outBytes, numOut); 909 memcpy(bytes + bytesLen, outBytes, numOut);
910 bytesLen += numOut; 910 bytesLen += numOut;
911 } 911 }
912 trip = 0; 912 trip = 0;
913 quadIx = 0; 913 quadIx = 0;
914 } 914 }
915 } 915 }
916 } /* while */ 916 } /* while */
917 DBG_(("db: bytesLen = %d\n", bytesLen)); 917 DBG_(("db: bytesLen = %d\n", bytesLen));
918 /* kludge: all this won't be necessary if we have tree form 918 /* kludge: all this won't be necessary if we have tree form
919 representation */ 919 representation */
920 if (bytes) { 920 if (bytes) {
921 setValueWithSize(curProp,bytes,(unsigned int)bytesLen); 921 setValueWithSize(curProp,bytes,(unsigned int)bytesLen);
922 free(bytes); 922 free(bytes);
923 } 923 }
924 else if (oldBytes) { 924 else if (oldBytes) {
925 setValueWithSize(curProp,oldBytes,(unsigned int)bytesLen); 925 setValueWithSize(curProp,oldBytes,(unsigned int)bytesLen);
926 free(oldBytes); 926 free(oldBytes);
927 } 927 }
928 return 0; 928 return 0;
929 } 929 }
930 930
931static int match_begin_end_name(int end) { 931static int match_begin_end_name(int end) {
932 int token; 932 int token;
933 lexSkipWhite(); 933 lexSkipWhite();
934 if (lexLookahead() != ':') return ID; 934 if (lexLookahead() != ':') return ID;
935 lexSkipLookahead(); 935 lexSkipLookahead();
936 lexSkipWhite(); 936 lexSkipWhite();
937 token = match_begin_name(end); 937 token = match_begin_name(end);
938 if (token == ID) { 938 if (token == ID) {
939 lexPushLookaheadc(':'); 939 lexPushLookaheadc(':');
940 DBG_(("db: ID '%s'\n", yylval.str)); 940 DBG_(("db: ID '%s'\n", yylval.str));
941 return ID; 941 return ID;
942 } 942 }
943 else if (token != 0) { 943 else if (token != 0) {
944 lexSkipLookaheadWord(); 944 lexSkipLookaheadWord();
945 deleteStr(yylval.str); 945 deleteStr(yylval.str);
946 DBG_(("db: begin/end %d\n", token)); 946 DBG_(("db: begin/end %d\n", token));
947 return token; 947 return token;
948 } 948 }
949 return 0; 949 return 0;
950 } 950 }
951 951
952static char* lexGetQuotedPrintable() 952static char* lexGetQuotedPrintable()
953 { 953 {
954 int cur; 954 int cur;
955 955
956 lexClearToken(); 956 lexClearToken();
957 do { 957 do {
958 cur = lexGetc(); 958 cur = lexGetc();
959 switch (cur) { 959 switch (cur) {
960 case '=': { 960 case '=': {
961 int c = 0; 961 int c = 0;
962 int next[2]; 962 int next[2];
963 int i; 963 int i;
964 for (i = 0; i < 2; i++) { 964 for (i = 0; i < 2; i++) {
965 next[i] = lexGetc(); 965 next[i] = lexGetc();
966 if (next[i] >= '0' && next[i] <= '9') 966 if (next[i] >= '0' && next[i] <= '9')
967 c = c * 16 + next[i] - '0'; 967 c = c * 16 + next[i] - '0';
968 else if (next[i] >= 'A' && next[i] <= 'F') 968 else if (next[i] >= 'A' && next[i] <= 'F')
969 c = c * 16 + next[i] - 'A' + 10; 969 c = c * 16 + next[i] - 'A' + 10;
970 else 970 else
971 break; 971 break;
972 } 972 }
973 if (i == 0) { 973 if (i == 0) {
974 /* single '=' follow by LINESEP is continuation sign? */ 974 /* single '=' follow by LINESEP is continuation sign? */
975 if (next[0] == '\n') { 975 if (next[0] == '\n') {
976 ++mime_lineNum; 976 ++mime_lineNum;
977 } 977 }
978 else { 978 else {
979 lexPushLookaheadc('='); 979 lexPushLookaheadc('=');
980 goto EndString; 980 goto EndString;
981 } 981 }
982 } 982 }
983 else if (i == 1) { 983 else if (i == 1) {
984 lexPushLookaheadc(next[1]); 984 lexPushLookaheadc(next[1]);
985 lexPushLookaheadc(next[0]); 985 lexPushLookaheadc(next[0]);
986 lexAppendc('='); 986 lexAppendc('=');
987 } else { 987 } else {
988 lexAppendc(c); 988 lexAppendc(c);
989 } 989 }
990 break; 990 break;
991 } /* '=' */ 991 } /* '=' */
992 case '\n': { 992 case '\n': {
993 lexPushLookaheadc('\n'); 993 lexPushLookaheadc('\n');
994 goto EndString; 994 goto EndString;
995 } 995 }
996 case (int)EOF: 996 case (int)EOF:
997 break; 997 break;
998 default: 998 default:
999 lexAppendc(cur); 999 lexAppendc(cur);
1000 break; 1000 break;
1001 } /* switch */ 1001 } /* switch */
1002 } while (cur != (int)EOF); 1002 } while (cur != (int)EOF);
1003 1003
1004EndString: 1004EndString:
1005 lexAppendc(0); 1005 lexAppendc(0);
1006 return lexStr(); 1006 return lexStr();
1007 } /* LexQuotedPrintable */ 1007 } /* LexQuotedPrintable */
1008 1008
1009static int yylex() { 1009static int yylex() {
1010 1010
1011 int lexmode = LEXMODE(); 1011 int lexmode = LEXMODE();
1012 if (lexmode == L_VALUES) { 1012 if (lexmode == L_VALUES) {
1013 int c = lexGetc(); 1013 int c = lexGetc();
1014 if (c == ';') { 1014 if (c == ';') {
1015 DBG_(("db: SEMICOLON\n")); 1015 DBG_(("db: SEMICOLON\n"));
1016 lexPushLookaheadc(c); 1016 lexPushLookaheadc(c);
1017 handleMoreRFC822LineBreak(c); 1017 handleMoreRFC822LineBreak(c);
1018 lexSkipLookahead(); 1018 lexSkipLookahead();
1019 return SEMICOLON; 1019 return SEMICOLON;
1020 } 1020 }
1021 else if (strchr("\n",c)) { 1021 else if (strchr("\n",c)) {
1022 ++mime_lineNum; 1022 ++mime_lineNum;
1023 /* consume all line separator(s) adjacent to each other */ 1023 /* consume all line separator(s) adjacent to each other */
1024 c = lexLookahead(); 1024 c = lexLookahead();
1025 while (strchr("\n",c)) { 1025 while (strchr("\n",c)) {
1026 lexSkipLookahead(); 1026 lexSkipLookahead();
1027 c = lexLookahead(); 1027 c = lexLookahead();
1028 ++mime_lineNum; 1028 ++mime_lineNum;
1029 } 1029 }
1030 DBG_(("db: LINESEP\n")); 1030 DBG_(("db: LINESEP\n"));
1031 return LINESEP; 1031 return LINESEP;
1032 } 1032 }
1033 else { 1033 else {
1034 char *p = 0; 1034 char *p = 0;
1035 lexPushLookaheadc(c); 1035 lexPushLookaheadc(c);
1036 if (lexWithinMode(L_BASE64)) { 1036 if (lexWithinMode(L_BASE64)) {
1037 /* get each char and convert to bin on the fly... */ 1037 /* get each char and convert to bin on the fly... */
1038 p = lexGetDataFromBase64(); 1038 p = lexGetDataFromBase64();
1039 yylval.str = p; 1039 yylval.str = p;
1040 return STRING; 1040 return STRING;
1041 } 1041 }
1042 else if (lexWithinMode(L_QUOTED_PRINTABLE)) { 1042 else if (lexWithinMode(L_QUOTED_PRINTABLE)) {
1043 p = lexGetQuotedPrintable(); 1043 p = lexGetQuotedPrintable();
1044 } 1044 }
1045 else { 1045 else {
1046#ifdef _SUPPORT_LINE_FOLDING 1046#ifdef _SUPPORT_LINE_FOLDING
1047 p = lexGet1Value(); 1047 p = lexGet1Value();
1048#else 1048#else
1049 p = lexGetStrUntil(";\n"); 1049 p = lexGetStrUntil(";\n");
1050#endif 1050#endif
1051 } 1051 }
1052 if (p) { 1052 if (p) {
1053 DBG_(("db: STRING: '%s'\n", p)); 1053 DBG_(("db: STRING: '%s'\n", p));
1054 yylval.str = p; 1054 yylval.str = p;
1055 return STRING; 1055 return STRING;
1056 } 1056 }
1057 else return 0; 1057 else return 0;
1058 } 1058 }
1059 } 1059 }
1060 else { 1060 else {
1061 /* normal mode */ 1061 /* normal mode */
1062 while (1) { 1062 while (1) {
1063 int c = lexGetc(); 1063 int c = lexGetc();
1064 switch(c) { 1064 switch(c) {
1065 case ':': { 1065 case ':': {
1066 /* consume all line separator(s) adjacent to each other */ 1066 /* consume all line separator(s) adjacent to each other */
1067 /* ignoring linesep immediately after colon. */ 1067 /* ignoring linesep immediately after colon. */
1068 c = lexLookahead(); 1068 c = lexLookahead();
1069 while (strchr("\n",c)) { 1069 while (strchr("\n",c)) {
1070 lexSkipLookahead(); 1070 lexSkipLookahead();
1071 c = lexLookahead(); 1071 c = lexLookahead();
1072 ++mime_lineNum; 1072 ++mime_lineNum;
1073 } 1073 }
1074 DBG_(("db: COLON\n")); 1074 DBG_(("db: COLON\n"));
1075 return COLON; 1075 return COLON;
1076 } 1076 }
1077 case ';': 1077 case ';':
1078 DBG_(("db: SEMICOLON\n")); 1078 DBG_(("db: SEMICOLON\n"));
1079 return SEMICOLON; 1079 return SEMICOLON;
1080 case '=': 1080 case '=':
1081 DBG_(("db: EQ\n")); 1081 DBG_(("db: EQ\n"));
1082 return EQ; 1082 return EQ;
1083 /* ignore whitespace in this mode */ 1083 /* ignore whitespace in this mode */
1084 case '\t': 1084 case '\t':
1085 case ' ': continue; 1085 case ' ': continue;
1086 case '\n': { 1086 case '\n': {
1087 ++mime_lineNum; 1087 ++mime_lineNum;
1088 continue; 1088 continue;
1089 } 1089 }
1090 case EOF: return 0; 1090 case EOF: return 0;
1091 break; 1091 break;
1092 default: { 1092 default: {
1093 lexPushLookaheadc(c); 1093 lexPushLookaheadc(c);
1094 if (isalnum(c)) { 1094 if (isalnum(c)) {
1095 char *t = lexGetWord(); 1095 char *t = lexGetWord();
1096 yylval.str = t; 1096 yylval.str = t;
1097 if (!qstricmp(t, "begin")) { 1097 if (!qstricmp(t, "begin")) {
1098 return match_begin_end_name(0); 1098 return match_begin_end_name(0);
1099 } 1099 }
1100 else if (!qstricmp(t,"end")) { 1100 else if (!qstricmp(t,"end")) {
1101 return match_begin_end_name(1); 1101 return match_begin_end_name(1);
1102 } 1102 }
1103 else { 1103 else {
1104 DBG_(("db: ID '%s'\n", t)); 1104 DBG_(("db: ID '%s'\n", t));
1105 return ID; 1105 return ID;
1106 } 1106 }
1107 } 1107 }
1108 else { 1108 else {
1109 /* unknow token */ 1109 /* unknow token */
1110 return 0; 1110 return 0;
1111 } 1111 }
1112 break; 1112 break;
1113 } 1113 }
1114 } 1114 }
1115 } 1115 }
1116 } 1116 }
1117 return 0; 1117 return 0;
1118 } 1118 }
1119 1119
1120 1120
1121/***************************************************************************/ 1121/***************************************************************************/
1122 /*** Public Functions ****/ 1122 /*** Public Functions ****/
1123/***************************************************************************/ 1123/***************************************************************************/
1124 1124
1125static VObject* Parse_MIMEHelper() 1125static VObject* Parse_MIMEHelper()
1126 { 1126 {
1127 ObjStackTop = -1; 1127 ObjStackTop = -1;
1128 mime_numErrors = 0; 1128 mime_numErrors = 0;
1129 mime_lineNum = 1; 1129 mime_lineNum = 1;
1130 vObjList = 0; 1130 vObjList = 0;
1131 curObj = 0; 1131 curObj = 0;
1132 1132
1133 if (yyparse() != 0) 1133 if (yyparse() != 0)
1134 return 0; 1134 return 0;
1135 1135
1136 finiLex(); 1136 finiLex();
1137 return vObjList; 1137 return vObjList;
1138 } 1138 }
1139 1139
1140/*--------------------------------------------*/ 1140/*--------------------------------------------*/
1141DLLEXPORT(VObject*) Parse_MIME(const char *input, unsigned long len) 1141DLLEXPORT(VObject*) Parse_MIME(const char *input, unsigned long len)
1142 { 1142 {
1143 initLex(input, len, 0); 1143 initLex(input, len, 0);
1144 return Parse_MIMEHelper(); 1144 return Parse_MIMEHelper();
1145 } 1145 }
1146 1146
1147 1147
1148#if INCLUDEMFC 1148#if INCLUDEMFC
1149 1149
1150DLLEXPORT(VObject*) Parse_MIME_FromFile(CFile *file) 1150DLLEXPORT(VObject*) Parse_MIME_FromFile(CFile *file)
1151 { 1151 {
1152 unsigned long startPos; 1152 unsigned long startPos;
1153 VObject *result; 1153 VObject *result;
1154 1154
1155 initLex(0,-1,file); 1155 initLex(0,-1,file);
1156 startPos = file->GetPosition(); 1156 startPos = file->GetPosition();
1157 if (!(result = Parse_MIMEHelper())) 1157 if (!(result = Parse_MIMEHelper()))
1158 file->Seek(startPos, CFile::begin); 1158 file->Seek(startPos, CFile::begin);
1159 return result; 1159 return result;
1160 } 1160 }
1161 1161
1162#else 1162#else
1163 1163
1164VObject* Parse_MIME_FromFile(FILE *file) 1164VObject* Parse_MIME_FromFile(FILE *file)
1165 { 1165 {
1166 VObject *result; 1166 VObject *result;
1167 long startPos; 1167 long startPos;
1168 1168
1169 initLex(0,(unsigned long)-1,file); 1169 initLex(0,(unsigned long)-1,file);
1170 startPos = ftell(file); 1170 startPos = ftell(file);
1171 if (!(result = Parse_MIMEHelper())) { 1171 if (!(result = Parse_MIMEHelper())) {
1172 fseek(file,startPos,SEEK_SET); 1172 fseek(file,startPos,SEEK_SET);
1173 } 1173 }
1174 return result; 1174 return result;
1175 } 1175 }
1176 1176
1177DLLEXPORT(VObject*) Parse_MIME_FromFileName(char *fname) 1177DLLEXPORT(VObject*) Parse_MIME_FromFileName(char *fname)
1178 { 1178 {
1179 FILE *fp = fopen(fname,"r"); 1179 FILE *fp = fopen(fname,"r");
1180 if (fp) { 1180 if (fp) {
1181 VObject* o = Parse_MIME_FromFile(fp); 1181 VObject* o = Parse_MIME_FromFile(fp);
1182 fclose(fp); 1182 fclose(fp);
1183 return o; 1183 return o;
1184 } 1184 }
1185 else { 1185 else {
1186 char msg[80]; 1186 char msg[80];
1187 sprintf(msg, "can't open file '%s' for reading\n", fname); 1187 sprintf(msg, "can't open file '%s' for reading\n", fname);
1188 mime_error_(msg); 1188 mime_error_(msg);
1189 return 0; 1189 return 0;
1190 } 1190 }
1191 } 1191 }
1192 1192
1193#endif 1193#endif
1194 1194
1195/*-------------------------------------*/ 1195/*-------------------------------------*/
1196 1196
1197static MimeErrorHandler mimeErrorHandler; 1197static MimeErrorHandler mimeErrorHandler;
1198 1198
1199DLLEXPORT(void) registerMimeErrorHandler(MimeErrorHandler me) 1199DLLEXPORT(void) registerMimeErrorHandler(MimeErrorHandler me)
1200 { 1200 {
1201 mimeErrorHandler = me; 1201 mimeErrorHandler = me;
1202 } 1202 }
1203 1203
1204void mime_error(char *s) 1204void mime_error(char *s)
1205 { 1205 {
1206 char msg[256]; 1206 char msg[256];
1207 if (mimeErrorHandler) { 1207 if (mimeErrorHandler) {
1208 sprintf(msg,"%s at line %d", s, mime_lineNum); 1208 sprintf(msg,"%s at line %d", s, mime_lineNum);
1209 mimeErrorHandler(msg); 1209 mimeErrorHandler(msg);
1210 } 1210 }
1211 } 1211 }
1212 1212
1213void mime_error_(char *s) 1213void mime_error_(char *s)
1214 { 1214 {
1215 if (mimeErrorHandler) { 1215 if (mimeErrorHandler) {
1216 mimeErrorHandler(s); 1216 mimeErrorHandler(s);
1217 } 1217 }
1218 } 1218 }
1219 1219
1220#line 1221 "y.tab.c" 1220#line 1221 "y.tab.c"
1221#define YYABORT goto yyabort 1221#define YYABORT goto yyabort
1222#define YYREJECT goto yyabort 1222#define YYREJECT goto yyabort
1223#define YYACCEPT goto yyaccept 1223#define YYACCEPT goto yyaccept
1224#define YYERROR goto yyerrlab 1224#define YYERROR goto yyerrlab
1225int 1225int
1226#if defined(__STDC__) 1226#if defined(__STDC__)
1227yyparse(void) 1227yyparse(void)
1228#else 1228#else
1229yyparse() 1229yyparse()
1230#endif 1230#endif
1231{ 1231{
1232 register int yym, yyn, yystate; 1232 register int yym, yyn, yystate;
1233#if YYDEBUG 1233#if YYDEBUG
1234 register char *yys; 1234 register char *yys;
1235 extern char *getenv(); 1235 extern char *getenv();
1236 1236
1237 if (yys = getenv("YYDEBUG")) 1237 if (yys = getenv("YYDEBUG"))
1238 { 1238 {
1239 yyn = *yys; 1239 yyn = *yys;
1240 if (yyn >= '0' && yyn <= '9') 1240 if (yyn >= '0' && yyn <= '9')
1241 yydebug = yyn - '0'; 1241 yydebug = yyn - '0';
1242 } 1242 }
1243#endif 1243#endif
1244 1244
1245 yynerrs = 0; 1245 yynerrs = 0;
1246 yyerrflag = 0; 1246 yyerrflag = 0;
1247 yychar = (-1); 1247 yychar = (-1);
1248 1248
1249 yyssp = yyss; 1249 yyssp = yyss;
1250 yyvsp = yyvs; 1250 yyvsp = yyvs;
1251 *yyssp = yystate = 0; 1251 *yyssp = yystate = 0;
1252 1252
1253yyloop: 1253yyloop:
1254 if ((yyn = yydefred[yystate]) != 0) goto yyreduce; 1254 if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
1255 if (yychar < 0) 1255 if (yychar < 0)
1256 { 1256 {
1257 if ((yychar = yylex()) < 0) yychar = 0; 1257 if ((yychar = yylex()) < 0) yychar = 0;
1258#if YYDEBUG 1258#if YYDEBUG
1259 if (yydebug) 1259 if (yydebug)
1260 { 1260 {
1261 yys = 0; 1261 yys = 0;
1262 if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; 1262 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
1263 if (!yys) yys = "illegal-symbol"; 1263 if (!yys) yys = "illegal-symbol";
1264 printf("%sdebug: state %d, reading %d (%s)\n", 1264 printf("%sdebug: state %d, reading %d (%s)\n",
1265 YYPREFIX, yystate, yychar, yys); 1265 YYPREFIX, yystate, yychar, yys);
1266 } 1266 }
1267#endif 1267#endif
1268 } 1268 }
1269 if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 && 1269 if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
1270 yyn <= YYTABLESIZE && yycheck[yyn] == yychar) 1270 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
1271 { 1271 {
1272#if YYDEBUG 1272#if YYDEBUG
1273 if (yydebug) 1273 if (yydebug)
1274 printf("%sdebug: state %d, shifting to state %d\n", 1274 printf("%sdebug: state %d, shifting to state %d\n",
1275 YYPREFIX, yystate, yytable[yyn]); 1275 YYPREFIX, yystate, yytable[yyn]);
1276#endif 1276#endif
1277 if (yyssp >= yyss + yystacksize - 1) 1277 if (yyssp >= yyss + yystacksize - 1)
1278 { 1278 {
1279 goto yyoverflow; 1279 goto yyoverflow;
1280 } 1280 }
1281 *++yyssp = yystate = yytable[yyn]; 1281 *++yyssp = yystate = yytable[yyn];
1282 *++yyvsp = yylval; 1282 *++yyvsp = yylval;
1283 yychar = (-1); 1283 yychar = (-1);
1284 if (yyerrflag > 0) --yyerrflag; 1284 if (yyerrflag > 0) --yyerrflag;
1285 goto yyloop; 1285 goto yyloop;
1286 } 1286 }
1287 if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 && 1287 if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
1288 yyn <= YYTABLESIZE && yycheck[yyn] == yychar) 1288 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
1289 { 1289 {
1290 yyn = yytable[yyn]; 1290 yyn = yytable[yyn];
1291 goto yyreduce; 1291 goto yyreduce;
1292 } 1292 }
1293 if (yyerrflag) goto yyinrecovery; 1293 if (yyerrflag) goto yyinrecovery;
1294 yyerror("syntax error"); 1294 yyerror("syntax error");
1295#ifdef lint 1295#ifdef lint
1296 goto yyerrlab; 1296 goto yyerrlab;
1297#endif 1297#endif
1298yyerrlab: 1298yyerrlab:
1299 ++yynerrs; 1299 ++yynerrs;
1300yyinrecovery: 1300yyinrecovery:
1301 if (yyerrflag < 3) 1301 if (yyerrflag < 3)
1302 { 1302 {
1303 yyerrflag = 3; 1303 yyerrflag = 3;
1304 for (;;) 1304 for (;;)
1305 { 1305 {
1306 if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 && 1306 if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&
1307 yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE) 1307 yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
1308 { 1308 {
1309#if YYDEBUG 1309#if YYDEBUG
1310 if (yydebug) 1310 if (yydebug)
1311 printf("%sdebug: state %d, error recovery shifting\ 1311 printf("%sdebug: state %d, error recovery shifting\
1312 to state %d\n", YYPREFIX, *yyssp, yytable[yyn]); 1312 to state %d\n", YYPREFIX, *yyssp, yytable[yyn]);
1313#endif 1313#endif
1314 if (yyssp >= yyss + yystacksize - 1) 1314 if (yyssp >= yyss + yystacksize - 1)
1315 { 1315 {
1316 goto yyoverflow; 1316 goto yyoverflow;
1317 } 1317 }
1318 *++yyssp = yystate = yytable[yyn]; 1318 *++yyssp = yystate = yytable[yyn];
1319 *++yyvsp = yylval; 1319 *++yyvsp = yylval;
1320 goto yyloop; 1320 goto yyloop;
1321 } 1321 }
1322 else 1322 else
1323 { 1323 {
1324#if YYDEBUG 1324#if YYDEBUG
1325 if (yydebug) 1325 if (yydebug)
1326 printf("%sdebug: error recovery discarding state %d\n", 1326 printf("%sdebug: error recovery discarding state %d\n",
1327 YYPREFIX, *yyssp); 1327 YYPREFIX, *yyssp);
1328#endif 1328#endif
1329 if (yyssp <= yyss) goto yyabort; 1329 if (yyssp <= yyss) goto yyabort;
1330 --yyssp; 1330 --yyssp;
1331 --yyvsp; 1331 --yyvsp;
1332 } 1332 }
1333 } 1333 }
1334 } 1334 }
1335 else 1335 else
1336 { 1336 {
1337 if (yychar == 0) goto yyabort; 1337 if (yychar == 0) goto yyabort;
1338#if YYDEBUG 1338#if YYDEBUG
1339 if (yydebug) 1339 if (yydebug)
1340 { 1340 {
1341 yys = 0; 1341 yys = 0;
1342 if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; 1342 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
1343 if (!yys) yys = "illegal-symbol"; 1343 if (!yys) yys = "illegal-symbol";
1344 printf("%sdebug: state %d, error recovery discards token %d (%s)\n", 1344 printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
1345 YYPREFIX, yystate, yychar, yys); 1345 YYPREFIX, yystate, yychar, yys);
1346 } 1346 }
1347#endif 1347#endif
1348 yychar = (-1); 1348 yychar = (-1);
1349 goto yyloop; 1349 goto yyloop;
1350 } 1350 }
1351yyreduce: 1351yyreduce:
1352#if YYDEBUG 1352#if YYDEBUG
1353 if (yydebug) 1353 if (yydebug)
1354 printf("%sdebug: state %d, reducing by rule %d (%s)\n", 1354 printf("%sdebug: state %d, reducing by rule %d (%s)\n",
1355 YYPREFIX, yystate, yyn, yyrule[yyn]); 1355 YYPREFIX, yystate, yyn, yyrule[yyn]);
1356#endif 1356#endif
1357 yym = yylen[yyn]; 1357 yym = yylen[yyn];
1358 yyval = yyvsp[1-yym]; 1358 yyval = yyvsp[1-yym];
1359 switch (yyn) 1359 switch (yyn)
1360 { 1360 {
1361case 2: 1361case 2:
1362#line 221 "backend/vcc.y" 1362#line 221 "backend/vcc.y"
1363{ addList(&vObjList, yyvsp[0].vobj); curObj = 0; } 1363{ addList(&vObjList, yyvsp[0].vobj); curObj = 0; }
1364break; 1364break;
1365case 3: 1365case 3:
1366#line 223 "backend/vcc.y" 1366#line 223 "backend/vcc.y"
1367{ addList(&vObjList, yyvsp[0].vobj); curObj = 0; } 1367{ addList(&vObjList, yyvsp[0].vobj); curObj = 0; }
1368break; 1368break;
1369case 6: 1369case 6:
1370#line 232 "backend/vcc.y" 1370#line 232 "backend/vcc.y"
1371{ 1371{
1372 lexPushMode(L_VCARD); 1372 lexPushMode(L_VCARD);
1373 if (!pushVObject(VCCardProp)) YYERROR; 1373 if (!pushVObject(VCCardProp)) YYERROR;
1374 } 1374 }
1375break; 1375break;
1376case 7: 1376case 7:
1377#line 237 "backend/vcc.y" 1377#line 237 "backend/vcc.y"
1378{ 1378{
1379 lexPopMode(0); 1379 lexPopMode(0);
1380 yyval.vobj = popVObject(); 1380 yyval.vobj = popVObject();
1381 } 1381 }
1382break; 1382break;
1383case 8: 1383case 8:
1384#line 242 "backend/vcc.y" 1384#line 242 "backend/vcc.y"
1385{ 1385{
1386 lexPushMode(L_VCARD); 1386 lexPushMode(L_VCARD);
1387 if (!pushVObject(VCCardProp)) YYERROR; 1387 if (!pushVObject(VCCardProp)) YYERROR;
1388 } 1388 }
1389break; 1389break;
1390case 9: 1390case 9:
1391#line 247 "backend/vcc.y" 1391#line 247 "backend/vcc.y"
1392{ 1392{
1393 lexPopMode(0); 1393 lexPopMode(0);
1394 yyval.vobj = popVObject(); 1394 yyval.vobj = popVObject();
1395 } 1395 }
1396break; 1396break;
1397case 12: 1397case 12:
1398#line 258 "backend/vcc.y" 1398#line 258 "backend/vcc.y"
1399{ 1399{
1400 lexPushMode(L_VALUES); 1400 lexPushMode(L_VALUES);
1401 } 1401 }
1402break; 1402break;
1403case 13: 1403case 13:
1404#line 262 "backend/vcc.y" 1404#line 262 "backend/vcc.y"
1405{ 1405{
1406 if (lexWithinMode(L_BASE64) || lexWithinMode(L_QUOTED_PRINTABLE)) 1406 if (lexWithinMode(L_BASE64) || lexWithinMode(L_QUOTED_PRINTABLE))
1407 lexPopMode(0); 1407 lexPopMode(0);
1408 lexPopMode(0); 1408 lexPopMode(0);
1409 } 1409 }
1410break; 1410break;
1411case 15: 1411case 15:
1412#line 271 "backend/vcc.y" 1412#line 271 "backend/vcc.y"
1413{ 1413{
1414 enterProps(yyvsp[0].str); 1414 enterProps(yyvsp[0].str);
1415 } 1415 }
1416break; 1416break;
1417case 17: 1417case 17:
1418#line 276 "backend/vcc.y" 1418#line 276 "backend/vcc.y"
1419{ 1419{
1420 enterProps(yyvsp[0].str); 1420 enterProps(yyvsp[0].str);
1421 } 1421 }
1422break; 1422break;
1423case 21: 1423case 21:
1424#line 289 "backend/vcc.y" 1424#line 289 "backend/vcc.y"
1425{ 1425{
1426 enterAttr(yyvsp[0].str,0); 1426 enterAttr(yyvsp[0].str,0);
1427 } 1427 }
1428break; 1428break;
1429case 22: 1429case 22:
1430#line 293 "backend/vcc.y" 1430#line 293 "backend/vcc.y"
1431{ 1431{
1432 enterAttr(yyvsp[-2].str,yyvsp[0].str); 1432 enterAttr(yyvsp[-2].str,yyvsp[0].str);
1433 1433
1434 } 1434 }
1435break; 1435break;
1436case 24: 1436case 24:
1437#line 302 "backend/vcc.y" 1437#line 302 "backend/vcc.y"
1438{ enterValues(yyvsp[-1].str); } 1438{ enterValues(yyvsp[-1].str); }
1439break; 1439break;
1440case 26: 1440case 26:
1441#line 304 "backend/vcc.y" 1441#line 304 "backend/vcc.y"
1442{ enterValues(yyvsp[0].str); } 1442{ enterValues(yyvsp[0].str); }
1443break; 1443break;
1444case 28: 1444case 28:
1445#line 309 "backend/vcc.y" 1445#line 309 "backend/vcc.y"
1446{ yyval.str = 0; } 1446{ yyval.str = 0; }
1447break; 1447break;
1448case 29: 1448case 29:
1449#line 314 "backend/vcc.y" 1449#line 314 "backend/vcc.y"
1450{ if (!pushVObject(VCCalProp)) YYERROR; } 1450{ if (!pushVObject(VCCalProp)) YYERROR; }
1451break; 1451break;
1452case 30: 1452case 30:
1453#line 317 "backend/vcc.y" 1453#line 317 "backend/vcc.y"
1454{ yyval.vobj = popVObject(); } 1454{ yyval.vobj = popVObject(); }
1455break; 1455break;
1456case 31: 1456case 31:
1457#line 319 "backend/vcc.y" 1457#line 319 "backend/vcc.y"
1458{ if (!pushVObject(VCCalProp)) YYERROR; } 1458{ if (!pushVObject(VCCalProp)) YYERROR; }
1459break; 1459break;
1460case 32: 1460case 32:
1461#line 321 "backend/vcc.y" 1461#line 321 "backend/vcc.y"
1462{ yyval.vobj = popVObject(); } 1462{ yyval.vobj = popVObject(); }
1463break; 1463break;
1464case 38: 1464case 38:
1465#line 336 "backend/vcc.y" 1465#line 336 "backend/vcc.y"
1466{ 1466{
1467 lexPushMode(L_VEVENT); 1467 lexPushMode(L_VEVENT);
1468 if (!pushVObject(VCEventProp)) YYERROR; 1468 if (!pushVObject(VCEventProp)) YYERROR;
1469 } 1469 }
1470break; 1470break;
1471case 39: 1471case 39:
1472#line 342 "backend/vcc.y" 1472#line 342 "backend/vcc.y"
1473{ 1473{
1474 lexPopMode(0); 1474 lexPopMode(0);
1475 popVObject(); 1475 popVObject();
1476 } 1476 }
1477break; 1477break;
1478case 40: 1478case 40:
1479#line 347 "backend/vcc.y" 1479#line 347 "backend/vcc.y"
1480{ 1480{
1481 lexPushMode(L_VEVENT); 1481 lexPushMode(L_VEVENT);
1482 if (!pushVObject(VCEventProp)) YYERROR; 1482 if (!pushVObject(VCEventProp)) YYERROR;
1483 } 1483 }
1484break; 1484break;
1485case 41: 1485case 41:
1486#line 352 "backend/vcc.y" 1486#line 352 "backend/vcc.y"
1487{ 1487{
1488 lexPopMode(0); 1488 lexPopMode(0);
1489 popVObject(); 1489 popVObject();
1490 } 1490 }
1491break; 1491break;
1492case 42: 1492case 42:
1493#line 360 "backend/vcc.y" 1493#line 360 "backend/vcc.y"
1494{ 1494{
1495 lexPushMode(L_VTODO); 1495 lexPushMode(L_VTODO);
1496 if (!pushVObject(VCTodoProp)) YYERROR; 1496 if (!pushVObject(VCTodoProp)) YYERROR;
1497 } 1497 }
1498break; 1498break;
1499case 43: 1499case 43:
1500#line 366 "backend/vcc.y" 1500#line 366 "backend/vcc.y"
1501{ 1501{
1502 lexPopMode(0); 1502 lexPopMode(0);
1503 popVObject(); 1503 popVObject();
1504 } 1504 }
1505break; 1505break;
1506case 44: 1506case 44:
1507#line 371 "backend/vcc.y" 1507#line 371 "backend/vcc.y"
1508{ 1508{
1509 lexPushMode(L_VTODO); 1509 lexPushMode(L_VTODO);
1510 if (!pushVObject(VCTodoProp)) YYERROR; 1510 if (!pushVObject(VCTodoProp)) YYERROR;
1511 } 1511 }
1512break; 1512break;
1513case 45: 1513case 45:
1514#line 376 "backend/vcc.y" 1514#line 376 "backend/vcc.y"
1515{ 1515{
1516 lexPopMode(0); 1516 lexPopMode(0);
1517 popVObject(); 1517 popVObject();
1518 } 1518 }
1519break; 1519break;
1520#line 1521 "y.tab.c" 1520#line 1521 "y.tab.c"
1521 } 1521 }
1522 yyssp -= yym; 1522 yyssp -= yym;
1523 yystate = *yyssp; 1523 yystate = *yyssp;
1524 yyvsp -= yym; 1524 yyvsp -= yym;
1525 yym = yylhs[yyn]; 1525 yym = yylhs[yyn];
1526 if (yystate == 0 && yym == 0) 1526 if (yystate == 0 && yym == 0)
1527 { 1527 {
1528#if YYDEBUG 1528#if YYDEBUG
1529 if (yydebug) 1529 if (yydebug)
1530 printf("%sdebug: after reduction, shifting from state 0 to\ 1530 printf("%sdebug: after reduction, shifting from state 0 to\
1531 state %d\n", YYPREFIX, YYFINAL); 1531 state %d\n", YYPREFIX, YYFINAL);
1532#endif 1532#endif
1533 yystate = YYFINAL; 1533 yystate = YYFINAL;
1534 *++yyssp = YYFINAL; 1534 *++yyssp = YYFINAL;
1535 *++yyvsp = yyval; 1535 *++yyvsp = yyval;
1536 if (yychar < 0) 1536 if (yychar < 0)
1537 { 1537 {
1538 if ((yychar = yylex()) < 0) yychar = 0; 1538 if ((yychar = yylex()) < 0) yychar = 0;
1539#if YYDEBUG 1539#if YYDEBUG
1540 if (yydebug) 1540 if (yydebug)
1541 { 1541 {
1542 yys = 0; 1542 yys = 0;
1543 if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; 1543 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
1544 if (!yys) yys = "illegal-symbol"; 1544 if (!yys) yys = "illegal-symbol";
1545 printf("%sdebug: state %d, reading %d (%s)\n", 1545 printf("%sdebug: state %d, reading %d (%s)\n",
1546 YYPREFIX, YYFINAL, yychar, yys); 1546 YYPREFIX, YYFINAL, yychar, yys);
1547 } 1547 }
1548#endif 1548#endif
1549 } 1549 }
1550 if (yychar == 0) goto yyaccept; 1550 if (yychar == 0) goto yyaccept;
1551 goto yyloop; 1551 goto yyloop;
1552 } 1552 }
1553 if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 && 1553 if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
1554 yyn <= YYTABLESIZE && yycheck[yyn] == yystate) 1554 yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
1555 yystate = yytable[yyn]; 1555 yystate = yytable[yyn];
1556 else 1556 else
1557 yystate = yydgoto[yym]; 1557 yystate = yydgoto[yym];
1558#if YYDEBUG 1558#if YYDEBUG
1559 if (yydebug) 1559 if (yydebug)
1560 printf("%sdebug: after reduction, shifting from state %d \ 1560 printf("%sdebug: after reduction, shifting from state %d \
1561to state %d\n", YYPREFIX, *yyssp, yystate); 1561to state %d\n", YYPREFIX, *yyssp, yystate);
1562#endif 1562#endif
1563 if (yyssp >= yyss + yystacksize - 1) 1563 if (yyssp >= yyss + yystacksize - 1)
1564 { 1564 {
1565 goto yyoverflow; 1565 goto yyoverflow;
1566 } 1566 }
1567 *++yyssp = yystate; 1567 *++yyssp = yystate;
1568 *++yyvsp = yyval; 1568 *++yyvsp = yyval;
1569 goto yyloop; 1569 goto yyloop;
1570yyoverflow: 1570yyoverflow:
1571 yyerror("yacc stack overflow"); 1571 yyerror("yacc stack overflow");
1572yyabort: 1572yyabort:
1573 return (1); 1573 return (1);
1574yyaccept: 1574yyaccept:
1575 return (0); 1575 return (0);
1576} 1576}
diff --git a/library/backend/vobject.cpp b/library/backend/vobject.cpp
index e6f6b78..dab128e 100644
--- a/library/backend/vobject.cpp
+++ b/library/backend/vobject.cpp
@@ -1,1315 +1,1315 @@
1/*************************************************************************** 1/***************************************************************************
2(C) Copyright 1996 Apple Computer, Inc., AT&T Corp., International 2(C) Copyright 1996 Apple Computer, Inc., AT&T Corp., International
3Business Machines Corporation and Siemens Rolm Communications Inc. 3Business Machines Corporation and Siemens Rolm Communications Inc.
4 4
5For purposes of this license notice, the term Licensors shall mean, 5For purposes of this license notice, the term Licensors shall mean,
6collectively, Apple Computer, Inc., AT&T Corp., International 6collectively, Apple Computer, Inc., AT&T Corp., International
7Business Machines Corporation and Siemens Rolm Communications Inc. 7Business Machines Corporation and Siemens Rolm Communications Inc.
8The term Licensor shall mean any of the Licensors. 8The term Licensor shall mean any of the Licensors.
9 9
10Subject to acceptance of the following conditions, permission is hereby 10Subject to acceptance of the following conditions, permission is hereby
11granted by Licensors without the need for written agreement and without 11granted by Licensors without the need for written agreement and without
12license or royalty fees, to use, copy, modify and distribute this 12license or royalty fees, to use, copy, modify and distribute this
13software for any purpose. 13software for any purpose.
14 14
15The above copyright notice and the following four paragraphs must be 15The above copyright notice and the following four paragraphs must be
16reproduced in all copies of this software and any software including 16reproduced in all copies of this software and any software including
17this software. 17this software.
18 18
19THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS AND NO LICENSOR SHALL HAVE 19THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS AND NO LICENSOR SHALL HAVE
20ANY OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR 20ANY OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR
21MODIFICATIONS. 21MODIFICATIONS.
22 22
23IN NO EVENT SHALL ANY LICENSOR BE LIABLE TO ANY PARTY FOR DIRECT, 23IN NO EVENT SHALL ANY LICENSOR BE LIABLE TO ANY PARTY FOR DIRECT,
24INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOST PROFITS ARISING OUT 24INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOST PROFITS ARISING OUT
25OF THE USE OF THIS SOFTWARE EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 25OF THE USE OF THIS SOFTWARE EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
26DAMAGE. 26DAMAGE.
27 27
28EACH LICENSOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, EXPRESS OR IMPLIED, 28EACH LICENSOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, EXPRESS OR IMPLIED,
29INCLUDING BUT NOT LIMITED TO ANY WARRANTY OF NONINFRINGEMENT OR THE 29INCLUDING BUT NOT LIMITED TO ANY WARRANTY OF NONINFRINGEMENT OR THE
30IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 30IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
31PURPOSE. 31PURPOSE.
32 32
33The software is provided with RESTRICTED RIGHTS. Use, duplication, or 33The software is provided with RESTRICTED RIGHTS. Use, duplication, or
34disclosure by the government are subject to restrictions set forth in 34disclosure by the government are subject to restrictions set forth in
35DFARS 252.227-7013 or 48 CFR 52.227-19, as applicable. 35DFARS 252.227-7013 or 48 CFR 52.227-19, as applicable.
36 36
37***************************************************************************/ 37***************************************************************************/
38 38
39/* 39/*
40 * src: vobject.c 40 * src: vobject.c
41 * doc: vobject and APIs to construct vobject, APIs pretty print 41 * doc: vobject and APIs to construct vobject, APIs pretty print
42 * vobject, and convert a vobject into its textual representation. 42 * vobject, and convert a vobject into its textual representation.
43 */ 43 */
44 44
45 #ifndef MWERKS 45 #ifndef MWERKS
46#include <malloc.h> 46#include <malloc.h>
47#endif 47#endif
48 48
49#include "vobject_p.h" 49#include <qtopia/private/vobject_p.h>
50#include "qfiledirect_p.h" 50#include <qtopia/private/qfiledirect_p.h>
51#include <string.h> 51#include <string.h>
52#include <stdio.h> 52#include <stdio.h>
53#include <fcntl.h> 53#include <fcntl.h>
54//#include <io.h> 54//#include <io.h>
55 55
56 56
57 #define NAME_OF(o) o->id 57 #define NAME_OF(o) o->id
58 #define VALUE_TYPE(o) o->valType 58 #define VALUE_TYPE(o) o->valType
59 #define STRINGZ_VALUE_OF(o) o->val.strs 59 #define STRINGZ_VALUE_OF(o) o->val.strs
60 #define INTEGER_VALUE_OF(o) o->val.i 60 #define INTEGER_VALUE_OF(o) o->val.i
61 #define LONG_VALUE_OF(o) o->val.l 61 #define LONG_VALUE_OF(o) o->val.l
62 #define ANY_VALUE_OF(o) o->val.any 62 #define ANY_VALUE_OF(o) o->val.any
63 #define VOBJECT_VALUE_OF(o) o->val.vobj 63 #define VOBJECT_VALUE_OF(o) o->val.vobj
64 64
65typedef union ValueItem { 65typedef union ValueItem {
66 const char *strs; 66 const char *strs;
67 unsigned int i; 67 unsigned int i;
68 unsigned long l; 68 unsigned long l;
69 void *any; 69 void *any;
70 VObject *vobj; 70 VObject *vobj;
71 } ValueItem; 71 } ValueItem;
72 72
73struct VObject { 73struct VObject {
74 VObject *next; 74 VObject *next;
75 const char *id; 75 const char *id;
76 VObject *prop; 76 VObject *prop;
77 unsigned short valType; 77 unsigned short valType;
78 ValueItem val; 78 ValueItem val;
79 }; 79 };
80 80
81typedef struct StrItem StrItem; 81typedef struct StrItem StrItem;
82 82
83struct StrItem { 83struct StrItem {
84 StrItem *next; 84 StrItem *next;
85 const char *s; 85 const char *s;
86 unsigned int refCnt; 86 unsigned int refCnt;
87 }; 87 };
88 88
89const char** fieldedProp; 89const char** fieldedProp;
90 90
91 91
92 92
93/*---------------------------------------------------------------------- 93/*----------------------------------------------------------------------
94 The following functions involve with memory allocation: 94 The following functions involve with memory allocation:
95 newVObject 95 newVObject
96 deleteVObject 96 deleteVObject
97 dupStr 97 dupStr
98 deleteStr 98 deleteStr
99 newStrItem 99 newStrItem
100 deleteStrItem 100 deleteStrItem
101 ----------------------------------------------------------------------*/ 101 ----------------------------------------------------------------------*/
102 102
103DLLEXPORT(VObject*) newVObject_(const char *id) 103DLLEXPORT(VObject*) newVObject_(const char *id)
104{ 104{
105 VObject *p = (VObject*)malloc(sizeof(VObject)); 105 VObject *p = (VObject*)malloc(sizeof(VObject));
106 p->next = 0; 106 p->next = 0;
107 p->id = id; 107 p->id = id;
108 p->prop = 0; 108 p->prop = 0;
109 VALUE_TYPE(p) = 0; 109 VALUE_TYPE(p) = 0;
110 ANY_VALUE_OF(p) = 0; 110 ANY_VALUE_OF(p) = 0;
111 return p; 111 return p;
112} 112}
113 113
114DLLEXPORT(VObject*) newVObject(const char *id) 114DLLEXPORT(VObject*) newVObject(const char *id)
115{ 115{
116 return newVObject_(lookupStr(id)); 116 return newVObject_(lookupStr(id));
117} 117}
118 118
119DLLEXPORT(void) deleteVObject(VObject *p) 119DLLEXPORT(void) deleteVObject(VObject *p)
120{ 120{
121 unUseStr(p->id); 121 unUseStr(p->id);
122 free(p); 122 free(p);
123} 123}
124 124
125DLLEXPORT(char*) dupStr(const char *s, unsigned int size) 125DLLEXPORT(char*) dupStr(const char *s, unsigned int size)
126{ 126{
127 char *t; 127 char *t;
128 if (size == 0) { 128 if (size == 0) {
129 size = strlen(s); 129 size = strlen(s);
130 } 130 }
131 t = (char*)malloc(size+1); 131 t = (char*)malloc(size+1);
132 if (t) { 132 if (t) {
133 memcpy(t,s,size); 133 memcpy(t,s,size);
134 t[size] = 0; 134 t[size] = 0;
135 return t; 135 return t;
136 } 136 }
137 else { 137 else {
138 return (char*)0; 138 return (char*)0;
139 } 139 }
140} 140}
141 141
142DLLEXPORT(void) deleteStr(const char *p) 142DLLEXPORT(void) deleteStr(const char *p)
143{ 143{
144 if (p) free((void*)p); 144 if (p) free((void*)p);
145} 145}
146 146
147 147
148static StrItem* newStrItem(const char *s, StrItem *next) 148static StrItem* newStrItem(const char *s, StrItem *next)
149{ 149{
150 StrItem *p = (StrItem*)malloc(sizeof(StrItem)); 150 StrItem *p = (StrItem*)malloc(sizeof(StrItem));
151 p->next = next; 151 p->next = next;
152 p->s = s; 152 p->s = s;
153 p->refCnt = 1; 153 p->refCnt = 1;
154 return p; 154 return p;
155} 155}
156 156
157static void deleteStrItem(StrItem *p) 157static void deleteStrItem(StrItem *p)
158{ 158{
159 free((void*)p); 159 free((void*)p);
160} 160}
161 161
162 162
163/*---------------------------------------------------------------------- 163/*----------------------------------------------------------------------
164 The following function provide accesses to VObject's value. 164 The following function provide accesses to VObject's value.
165 ----------------------------------------------------------------------*/ 165 ----------------------------------------------------------------------*/
166 166
167DLLEXPORT(const char*) vObjectName(VObject *o) 167DLLEXPORT(const char*) vObjectName(VObject *o)
168{ 168{
169 return NAME_OF(o); 169 return NAME_OF(o);
170} 170}
171 171
172DLLEXPORT(void) setVObjectName(VObject *o, const char* id) 172DLLEXPORT(void) setVObjectName(VObject *o, const char* id)
173{ 173{
174 NAME_OF(o) = id; 174 NAME_OF(o) = id;
175} 175}
176 176
177DLLEXPORT(const char*) vObjectStringZValue(VObject *o) 177DLLEXPORT(const char*) vObjectStringZValue(VObject *o)
178{ 178{
179 return STRINGZ_VALUE_OF(o); 179 return STRINGZ_VALUE_OF(o);
180} 180}
181 181
182DLLEXPORT(void) setVObjectStringZValue(VObject *o, const char *s) 182DLLEXPORT(void) setVObjectStringZValue(VObject *o, const char *s)
183{ 183{
184 STRINGZ_VALUE_OF(o) = dupStr(s,0); 184 STRINGZ_VALUE_OF(o) = dupStr(s,0);
185 VALUE_TYPE(o) = VCVT_STRINGZ; 185 VALUE_TYPE(o) = VCVT_STRINGZ;
186} 186}
187 187
188DLLEXPORT(void) setVObjectStringZValue_(VObject *o, const char *s) 188DLLEXPORT(void) setVObjectStringZValue_(VObject *o, const char *s)
189{ 189{
190 STRINGZ_VALUE_OF(o) = s; 190 STRINGZ_VALUE_OF(o) = s;
191 VALUE_TYPE(o) = VCVT_STRINGZ; 191 VALUE_TYPE(o) = VCVT_STRINGZ;
192} 192}
193 193
194DLLEXPORT(unsigned int) vObjectIntegerValue(VObject *o) 194DLLEXPORT(unsigned int) vObjectIntegerValue(VObject *o)
195{ 195{
196 return INTEGER_VALUE_OF(o); 196 return INTEGER_VALUE_OF(o);
197} 197}
198 198
199DLLEXPORT(void) setVObjectIntegerValue(VObject *o, unsigned int i) 199DLLEXPORT(void) setVObjectIntegerValue(VObject *o, unsigned int i)
200{ 200{
201 INTEGER_VALUE_OF(o) = i; 201 INTEGER_VALUE_OF(o) = i;
202 VALUE_TYPE(o) = VCVT_UINT; 202 VALUE_TYPE(o) = VCVT_UINT;
203} 203}
204 204
205DLLEXPORT(unsigned long) vObjectLongValue(VObject *o) 205DLLEXPORT(unsigned long) vObjectLongValue(VObject *o)
206{ 206{
207 return LONG_VALUE_OF(o); 207 return LONG_VALUE_OF(o);
208} 208}
209 209
210DLLEXPORT(void) setVObjectLongValue(VObject *o, unsigned long l) 210DLLEXPORT(void) setVObjectLongValue(VObject *o, unsigned long l)
211{ 211{
212 LONG_VALUE_OF(o) = l; 212 LONG_VALUE_OF(o) = l;
213 VALUE_TYPE(o) = VCVT_ULONG; 213 VALUE_TYPE(o) = VCVT_ULONG;
214} 214}
215 215
216DLLEXPORT(void*) vObjectAnyValue(VObject *o) 216DLLEXPORT(void*) vObjectAnyValue(VObject *o)
217{ 217{
218 return ANY_VALUE_OF(o); 218 return ANY_VALUE_OF(o);
219} 219}
220 220
221DLLEXPORT(void) setVObjectAnyValue(VObject *o, void *t) 221DLLEXPORT(void) setVObjectAnyValue(VObject *o, void *t)
222{ 222{
223 ANY_VALUE_OF(o) = t; 223 ANY_VALUE_OF(o) = t;
224 VALUE_TYPE(o) = VCVT_RAW; 224 VALUE_TYPE(o) = VCVT_RAW;
225} 225}
226 226
227DLLEXPORT(VObject*) vObjectVObjectValue(VObject *o) 227DLLEXPORT(VObject*) vObjectVObjectValue(VObject *o)
228{ 228{
229 return VOBJECT_VALUE_OF(o); 229 return VOBJECT_VALUE_OF(o);
230} 230}
231 231
232DLLEXPORT(void) setVObjectVObjectValue(VObject *o, VObject *p) 232DLLEXPORT(void) setVObjectVObjectValue(VObject *o, VObject *p)
233{ 233{
234 VOBJECT_VALUE_OF(o) = p; 234 VOBJECT_VALUE_OF(o) = p;
235 VALUE_TYPE(o) = VCVT_VOBJECT; 235 VALUE_TYPE(o) = VCVT_VOBJECT;
236} 236}
237 237
238DLLEXPORT(int) vObjectValueType(VObject *o) 238DLLEXPORT(int) vObjectValueType(VObject *o)
239{ 239{
240 return VALUE_TYPE(o); 240 return VALUE_TYPE(o);
241} 241}
242 242
243 243
244/*---------------------------------------------------------------------- 244/*----------------------------------------------------------------------
245 The following functions can be used to build VObject. 245 The following functions can be used to build VObject.
246 ----------------------------------------------------------------------*/ 246 ----------------------------------------------------------------------*/
247 247
248DLLEXPORT(VObject*) addVObjectProp(VObject *o, VObject *p) 248DLLEXPORT(VObject*) addVObjectProp(VObject *o, VObject *p)
249{ 249{
250 /* circular link list pointed to tail */ 250 /* circular link list pointed to tail */
251 /* 251 /*
252 o {next,id,prop,val} 252 o {next,id,prop,val}
253 V 253 V
254 pn {next,id,prop,val} 254 pn {next,id,prop,val}
255 V 255 V
256 ... 256 ...
257 p1 {next,id,prop,val} 257 p1 {next,id,prop,val}
258 V 258 V
259 pn 259 pn
260 --> 260 -->
261 o {next,id,prop,val} 261 o {next,id,prop,val}
262 V 262 V
263 pn {next,id,prop,val} 263 pn {next,id,prop,val}
264 V 264 V
265 p {next,id,prop,val} 265 p {next,id,prop,val}
266 ... 266 ...
267 p1 {next,id,prop,val} 267 p1 {next,id,prop,val}
268 V 268 V
269 pn 269 pn
270 */ 270 */
271 271
272 VObject *tail = o->prop; 272 VObject *tail = o->prop;
273 if (tail) { 273 if (tail) {
274 p->next = tail->next; 274 p->next = tail->next;
275 o->prop = tail->next = p; 275 o->prop = tail->next = p;
276 } 276 }
277 else { 277 else {
278 o->prop = p->next = p; 278 o->prop = p->next = p;
279 } 279 }
280 return p; 280 return p;
281} 281}
282 282
283DLLEXPORT(VObject*) addProp(VObject *o, const char *id) 283DLLEXPORT(VObject*) addProp(VObject *o, const char *id)
284{ 284{
285 return addVObjectProp(o,newVObject(id)); 285 return addVObjectProp(o,newVObject(id));
286} 286}
287 287
288DLLEXPORT(VObject*) addProp_(VObject *o, const char *id) 288DLLEXPORT(VObject*) addProp_(VObject *o, const char *id)
289{ 289{
290 return addVObjectProp(o,newVObject_(id)); 290 return addVObjectProp(o,newVObject_(id));
291} 291}
292 292
293DLLEXPORT(void) addList(VObject **o, VObject *p) 293DLLEXPORT(void) addList(VObject **o, VObject *p)
294{ 294{
295 p->next = 0; 295 p->next = 0;
296 if (*o == 0) { 296 if (*o == 0) {
297 *o = p; 297 *o = p;
298 } 298 }
299 else { 299 else {
300 VObject *t = *o; 300 VObject *t = *o;
301 while (t->next) { 301 while (t->next) {
302 t = t->next; 302 t = t->next;
303 } 303 }
304 t->next = p; 304 t->next = p;
305 } 305 }
306} 306}
307 307
308DLLEXPORT(VObject*) nextVObjectInList(VObject *o) 308DLLEXPORT(VObject*) nextVObjectInList(VObject *o)
309{ 309{
310 return o->next; 310 return o->next;
311} 311}
312 312
313DLLEXPORT(VObject*) setValueWithSize_(VObject *prop, void *val, unsigned int size) 313DLLEXPORT(VObject*) setValueWithSize_(VObject *prop, void *val, unsigned int size)
314{ 314{
315 VObject *sizeProp; 315 VObject *sizeProp;
316 setVObjectAnyValue(prop, val); 316 setVObjectAnyValue(prop, val);
317 sizeProp = addProp(prop,VCDataSizeProp); 317 sizeProp = addProp(prop,VCDataSizeProp);
318 setVObjectLongValue(sizeProp, size); 318 setVObjectLongValue(sizeProp, size);
319 return prop; 319 return prop;
320} 320}
321 321
322DLLEXPORT(VObject*) setValueWithSize(VObject *prop, void *val, unsigned int size) 322DLLEXPORT(VObject*) setValueWithSize(VObject *prop, void *val, unsigned int size)
323{ 323{
324 void *p = dupStr((const char *)val,size); 324 void *p = dupStr((const char *)val,size);
325 return setValueWithSize_(prop,p,p?size:0); 325 return setValueWithSize_(prop,p,p?size:0);
326} 326}
327 327
328DLLEXPORT(void) initPropIterator(VObjectIterator *i, VObject *o) 328DLLEXPORT(void) initPropIterator(VObjectIterator *i, VObject *o)
329{ 329{
330 i->start = o->prop; 330 i->start = o->prop;
331 i->next = 0; 331 i->next = 0;
332} 332}
333 333
334DLLEXPORT(void) initVObjectIterator(VObjectIterator *i, VObject *o) 334DLLEXPORT(void) initVObjectIterator(VObjectIterator *i, VObject *o)
335{ 335{
336 i->start = o->next; 336 i->start = o->next;
337 i->next = 0; 337 i->next = 0;
338} 338}
339 339
340DLLEXPORT(int) moreIteration(VObjectIterator *i) 340DLLEXPORT(int) moreIteration(VObjectIterator *i)
341{ 341{
342 return (i->start && (i->next==0 || i->next!=i->start)); 342 return (i->start && (i->next==0 || i->next!=i->start));
343} 343}
344 344
345DLLEXPORT(VObject*) nextVObject(VObjectIterator *i) 345DLLEXPORT(VObject*) nextVObject(VObjectIterator *i)
346{ 346{
347 if (i->start && i->next != i->start) { 347 if (i->start && i->next != i->start) {
348 if (i->next == 0) { 348 if (i->next == 0) {
349 i->next = i->start->next; 349 i->next = i->start->next;
350 return i->next; 350 return i->next;
351 } 351 }
352 else { 352 else {
353 i->next = i->next->next; 353 i->next = i->next->next;
354 return i->next; 354 return i->next;
355 } 355 }
356 } 356 }
357 else return (VObject*)0; 357 else return (VObject*)0;
358} 358}
359 359
360DLLEXPORT(VObject*) isAPropertyOf(VObject *o, const char *id) 360DLLEXPORT(VObject*) isAPropertyOf(VObject *o, const char *id)
361{ 361{
362 VObjectIterator i; 362 VObjectIterator i;
363 initPropIterator(&i,o); 363 initPropIterator(&i,o);
364 while (moreIteration(&i)) { 364 while (moreIteration(&i)) {
365 VObject *each = nextVObject(&i); 365 VObject *each = nextVObject(&i);
366 if (!qstricmp(id,each->id)) 366 if (!qstricmp(id,each->id))
367 return each; 367 return each;
368 } 368 }
369 return (VObject*)0; 369 return (VObject*)0;
370} 370}
371 371
372DLLEXPORT(VObject*) addGroup(VObject *o, const char *g) 372DLLEXPORT(VObject*) addGroup(VObject *o, const char *g)
373{ 373{
374 /* 374 /*
375 a.b.c 375 a.b.c
376 --> 376 -->
377 prop(c) 377 prop(c)
378 prop(VCGrouping=b) 378 prop(VCGrouping=b)
379 prop(VCGrouping=a) 379 prop(VCGrouping=a)
380 */ 380 */
381 char *dot = strrchr(g,'.'); 381 char *dot = strrchr(g,'.');
382 if (dot) { 382 if (dot) {
383 VObject *p, *t; 383 VObject *p, *t;
384 char *gs, *n = dot+1; 384 char *gs, *n = dot+1;
385 gs = dupStr(g,0);/* so we can write to it. */ 385 gs = dupStr(g,0);/* so we can write to it. */
386 /* used to be 386 /* used to be
387 * t = p = addProp_(o,lookupProp_(n)); 387 * t = p = addProp_(o,lookupProp_(n));
388 */ 388 */
389 t = p = addProp_(o,lookupProp(n)); 389 t = p = addProp_(o,lookupProp(n));
390 dot = strrchr(gs,'.'); 390 dot = strrchr(gs,'.');
391 *dot = 0; 391 *dot = 0;
392 do { 392 do {
393 dot = strrchr(gs,'.'); 393 dot = strrchr(gs,'.');
394 if (dot) { 394 if (dot) {
395 n = dot+1; 395 n = dot+1;
396 *dot=0; 396 *dot=0;
397 } 397 }
398 else 398 else
399 n = gs; 399 n = gs;
400 /* property(VCGroupingProp=n); 400 /* property(VCGroupingProp=n);
401 *and the value may have VCGrouping property 401 *and the value may have VCGrouping property
402 */ 402 */
403 t = addProp(t,VCGroupingProp); 403 t = addProp(t,VCGroupingProp);
404 setVObjectStringZValue(t,lookupProp_(n)); 404 setVObjectStringZValue(t,lookupProp_(n));
405 } while (n != gs); 405 } while (n != gs);
406 deleteStr(gs); 406 deleteStr(gs);
407 return p; 407 return p;
408 } 408 }
409 else 409 else
410 return addProp_(o,lookupProp(g)); 410 return addProp_(o,lookupProp(g));
411} 411}
412 412
413DLLEXPORT(VObject*) addPropValue(VObject *o, const char *p, const char *v) 413DLLEXPORT(VObject*) addPropValue(VObject *o, const char *p, const char *v)
414{ 414{
415 VObject *prop; 415 VObject *prop;
416 prop = addProp(o,p); 416 prop = addProp(o,p);
417 setVObjectStringZValue_(prop, strdup( v ) ); 417 setVObjectStringZValue_(prop, strdup( v ) );
418 return prop; 418 return prop;
419} 419}
420 420
421DLLEXPORT(VObject*) addPropSizedValue_(VObject *o, const char *p, const char *v, 421DLLEXPORT(VObject*) addPropSizedValue_(VObject *o, const char *p, const char *v,
422 unsigned int size) 422 unsigned int size)
423{ 423{
424 VObject *prop; 424 VObject *prop;
425 prop = addProp(o,p); 425 prop = addProp(o,p);
426 setValueWithSize_(prop, (void*)v, size); 426 setValueWithSize_(prop, (void*)v, size);
427 return prop; 427 return prop;
428} 428}
429 429
430DLLEXPORT(VObject*) addPropSizedValue(VObject *o, const char *p, const char *v, 430DLLEXPORT(VObject*) addPropSizedValue(VObject *o, const char *p, const char *v,
431 unsigned int size) 431 unsigned int size)
432{ 432{
433 return addPropSizedValue_(o,p,dupStr(v,size),size); 433 return addPropSizedValue_(o,p,dupStr(v,size),size);
434} 434}
435 435
436 436
437DLLEXPORT(void) cleanVObject(VObject *o) 437DLLEXPORT(void) cleanVObject(VObject *o)
438{ 438{
439 if (o == 0) return; 439 if (o == 0) return;
440 if (o->prop) { 440 if (o->prop) {
441 /* destroy time: cannot use the iterator here. 441 /* destroy time: cannot use the iterator here.
442 Have to break the cycle in the circular link 442 Have to break the cycle in the circular link
443 list and turns it into regular NULL-terminated 443 list and turns it into regular NULL-terminated
444 list -- since at some point of destruction, 444 list -- since at some point of destruction,
445 the reference entry for the iterator to work 445 the reference entry for the iterator to work
446 will not longer be valid. 446 will not longer be valid.
447 */ 447 */
448 VObject *p; 448 VObject *p;
449 p = o->prop->next; 449 p = o->prop->next;
450 o->prop->next = 0; 450 o->prop->next = 0;
451 do { 451 do {
452 VObject *t = p->next; 452 VObject *t = p->next;
453 cleanVObject(p); 453 cleanVObject(p);
454 p = t; 454 p = t;
455 } while (p); 455 } while (p);
456 } 456 }
457 switch (VALUE_TYPE(o)) { 457 switch (VALUE_TYPE(o)) {
458 case VCVT_STRINGZ: 458 case VCVT_STRINGZ:
459 case VCVT_RAW: 459 case VCVT_RAW:
460 // assume they are all allocated by malloc. 460 // assume they are all allocated by malloc.
461 free((char*)STRINGZ_VALUE_OF(o)); 461 free((char*)STRINGZ_VALUE_OF(o));
462 break; 462 break;
463 case VCVT_VOBJECT: 463 case VCVT_VOBJECT:
464 cleanVObject(VOBJECT_VALUE_OF(o)); 464 cleanVObject(VOBJECT_VALUE_OF(o));
465 break; 465 break;
466 } 466 }
467 deleteVObject(o); 467 deleteVObject(o);
468} 468}
469 469
470DLLEXPORT(void) cleanVObjects(VObject *list) 470DLLEXPORT(void) cleanVObjects(VObject *list)
471{ 471{
472 while (list) { 472 while (list) {
473 VObject *t = list; 473 VObject *t = list;
474 list = nextVObjectInList(list); 474 list = nextVObjectInList(list);
475 cleanVObject(t); 475 cleanVObject(t);
476 } 476 }
477} 477}
478 478
479/*---------------------------------------------------------------------- 479/*----------------------------------------------------------------------
480 The following is a String Table Facilities. 480 The following is a String Table Facilities.
481 ----------------------------------------------------------------------*/ 481 ----------------------------------------------------------------------*/
482 482
483#define STRTBLSIZE 255 483#define STRTBLSIZE 255
484 484
485static StrItem *strTbl[STRTBLSIZE]; 485static StrItem *strTbl[STRTBLSIZE];
486 486
487static unsigned int hashStr(const char *s) 487static unsigned int hashStr(const char *s)
488{ 488{
489 unsigned int h = 0; 489 unsigned int h = 0;
490 int i; 490 int i;
491 for (i=0;s[i];i++) { 491 for (i=0;s[i];i++) {
492 h += s[i]*i; 492 h += s[i]*i;
493 } 493 }
494 return h % STRTBLSIZE; 494 return h % STRTBLSIZE;
495} 495}
496 496
497DLLEXPORT(const char*) lookupStr(const char *s) 497DLLEXPORT(const char*) lookupStr(const char *s)
498{ 498{
499 StrItem *t; 499 StrItem *t;
500 unsigned int h = hashStr(s); 500 unsigned int h = hashStr(s);
501 if ((t = strTbl[h]) != 0) { 501 if ((t = strTbl[h]) != 0) {
502 do { 502 do {
503 if (qstricmp(t->s,s) == 0) { 503 if (qstricmp(t->s,s) == 0) {
504 t->refCnt++; 504 t->refCnt++;
505 return t->s; 505 return t->s;
506 } 506 }
507 t = t->next; 507 t = t->next;
508 } while (t); 508 } while (t);
509 } 509 }
510 s = dupStr(s,0); 510 s = dupStr(s,0);
511 strTbl[h] = newStrItem(s,strTbl[h]); 511 strTbl[h] = newStrItem(s,strTbl[h]);
512 return s; 512 return s;
513} 513}
514 514
515DLLEXPORT(void) unUseStr(const char *s) 515DLLEXPORT(void) unUseStr(const char *s)
516{ 516{
517 StrItem *t, *p; 517 StrItem *t, *p;
518 unsigned int h = hashStr(s); 518 unsigned int h = hashStr(s);
519 if ((t = strTbl[h]) != 0) { 519 if ((t = strTbl[h]) != 0) {
520 p = t; 520 p = t;
521 do { 521 do {
522 if (qstricmp(t->s,s) == 0) { 522 if (qstricmp(t->s,s) == 0) {
523 t->refCnt--; 523 t->refCnt--;
524 if (t->refCnt == 0) { 524 if (t->refCnt == 0) {
525 if (p == strTbl[h]) { 525 if (p == strTbl[h]) {
526 strTbl[h] = t->next; 526 strTbl[h] = t->next;
527 } 527 }
528 else { 528 else {
529 p->next = t->next; 529 p->next = t->next;
530 } 530 }
531 deleteStr(t->s); 531 deleteStr(t->s);
532 deleteStrItem(t); 532 deleteStrItem(t);
533 return; 533 return;
534 } 534 }
535 } 535 }
536 p = t; 536 p = t;
537 t = t->next; 537 t = t->next;
538 } while (t); 538 } while (t);
539 } 539 }
540} 540}
541 541
542DLLEXPORT(void) cleanStrTbl() 542DLLEXPORT(void) cleanStrTbl()
543{ 543{
544 int i; 544 int i;
545 for (i=0; i<STRTBLSIZE;i++) { 545 for (i=0; i<STRTBLSIZE;i++) {
546 StrItem *t = strTbl[i]; 546 StrItem *t = strTbl[i];
547 while (t) { 547 while (t) {
548 StrItem *p; 548 StrItem *p;
549 deleteStr(t->s); 549 deleteStr(t->s);
550 p = t; 550 p = t;
551 t = t->next; 551 t = t->next;
552 deleteStrItem(p); 552 deleteStrItem(p);
553 } while (t); 553 } while (t);
554 strTbl[i] = 0; 554 strTbl[i] = 0;
555 } 555 }
556} 556}
557 557
558 558
559struct PreDefProp { 559struct PreDefProp {
560 const char *name; 560 const char *name;
561 const char *alias; 561 const char *alias;
562 const char** fields; 562 const char** fields;
563 unsigned int flags; 563 unsigned int flags;
564 }; 564 };
565 565
566/* flags in PreDefProp */ 566/* flags in PreDefProp */
567 #define PD_BEGIN0x1 567 #define PD_BEGIN0x1
568 #define PD_INTERNAL0x2 568 #define PD_INTERNAL0x2
569 569
570static const char *adrFields[] = { 570static const char *adrFields[] = {
571 VCPostalBoxProp, 571 VCPostalBoxProp,
572 VCExtAddressProp, 572 VCExtAddressProp,
573 VCStreetAddressProp, 573 VCStreetAddressProp,
574 VCCityProp, 574 VCCityProp,
575 VCRegionProp, 575 VCRegionProp,
576 VCPostalCodeProp, 576 VCPostalCodeProp,
577 VCCountryNameProp, 577 VCCountryNameProp,
578 0 578 0
579}; 579};
580 580
581static const char *nameFields[] = { 581static const char *nameFields[] = {
582 VCFamilyNameProp, 582 VCFamilyNameProp,
583 VCGivenNameProp, 583 VCGivenNameProp,
584 VCAdditionalNamesProp, 584 VCAdditionalNamesProp,
585 VCNamePrefixesProp, 585 VCNamePrefixesProp,
586 VCNameSuffixesProp, 586 VCNameSuffixesProp,
587 NULL 587 NULL
588 }; 588 };
589 589
590static const char *orgFields[] = { 590static const char *orgFields[] = {
591 VCOrgNameProp, 591 VCOrgNameProp,
592 VCOrgUnitProp, 592 VCOrgUnitProp,
593 VCOrgUnit2Prop, 593 VCOrgUnit2Prop,
594 VCOrgUnit3Prop, 594 VCOrgUnit3Prop,
595 VCOrgUnit4Prop, 595 VCOrgUnit4Prop,
596 NULL 596 NULL
597 }; 597 };
598 598
599static const char *AAlarmFields[] = { 599static const char *AAlarmFields[] = {
600 VCRunTimeProp, 600 VCRunTimeProp,
601 VCSnoozeTimeProp, 601 VCSnoozeTimeProp,
602 VCRepeatCountProp, 602 VCRepeatCountProp,
603 VCAudioContentProp, 603 VCAudioContentProp,
604 0 604 0
605 }; 605 };
606 606
607/* ExDate -- has unamed fields */ 607/* ExDate -- has unamed fields */
608/* RDate -- has unamed fields */ 608/* RDate -- has unamed fields */
609 609
610static const char *DAlarmFields[] = { 610static const char *DAlarmFields[] = {
611 VCRunTimeProp, 611 VCRunTimeProp,
612 VCSnoozeTimeProp, 612 VCSnoozeTimeProp,
613 VCRepeatCountProp, 613 VCRepeatCountProp,
614 VCDisplayStringProp, 614 VCDisplayStringProp,
615 0 615 0
616 }; 616 };
617 617
618static const char *MAlarmFields[] = { 618static const char *MAlarmFields[] = {
619 VCRunTimeProp, 619 VCRunTimeProp,
620 VCSnoozeTimeProp, 620 VCSnoozeTimeProp,
621 VCRepeatCountProp, 621 VCRepeatCountProp,
622 VCEmailAddressProp, 622 VCEmailAddressProp,
623 VCNoteProp, 623 VCNoteProp,
624 0 624 0
625 }; 625 };
626 626
627static const char *PAlarmFields[] = { 627static const char *PAlarmFields[] = {
628 VCRunTimeProp, 628 VCRunTimeProp,
629 VCSnoozeTimeProp, 629 VCSnoozeTimeProp,
630 VCRepeatCountProp, 630 VCRepeatCountProp,
631 VCProcedureNameProp, 631 VCProcedureNameProp,
632 0 632 0
633 }; 633 };
634 634
635static struct PreDefProp propNames[] = { 635static struct PreDefProp propNames[] = {
636 { VC7bitProp, 0, 0, 0 }, 636 { VC7bitProp, 0, 0, 0 },
637 { VC8bitProp, 0, 0, 0 }, 637 { VC8bitProp, 0, 0, 0 },
638 { VCAAlarmProp, 0, AAlarmFields, 0 }, 638 { VCAAlarmProp, 0, AAlarmFields, 0 },
639 { VCAdditionalNamesProp, 0, 0, 0 }, 639 { VCAdditionalNamesProp, 0, 0, 0 },
640 { VCAdrProp, 0, adrFields, 0 }, 640 { VCAdrProp, 0, adrFields, 0 },
641 { VCAgentProp, 0, 0, 0 }, 641 { VCAgentProp, 0, 0, 0 },
642 { VCAIFFProp, 0, 0, 0 }, 642 { VCAIFFProp, 0, 0, 0 },
643 { VCAOLProp, 0, 0, 0 }, 643 { VCAOLProp, 0, 0, 0 },
644 { VCAppleLinkProp, 0, 0, 0 }, 644 { VCAppleLinkProp, 0, 0, 0 },
645 { VCAttachProp, 0, 0, 0 }, 645 { VCAttachProp, 0, 0, 0 },
646 { VCAttendeeProp, 0, 0, 0 }, 646 { VCAttendeeProp, 0, 0, 0 },
647 { VCATTMailProp, 0, 0, 0 }, 647 { VCATTMailProp, 0, 0, 0 },
648 { VCAudioContentProp, 0, 0, 0 }, 648 { VCAudioContentProp, 0, 0, 0 },
649 { VCAVIProp, 0, 0, 0 }, 649 { VCAVIProp, 0, 0, 0 },
650 { VCBase64Prop, 0, 0, 0 }, 650 { VCBase64Prop, 0, 0, 0 },
651 { VCBBSProp, 0, 0, 0 }, 651 { VCBBSProp, 0, 0, 0 },
652 { VCBirthDateProp, 0, 0, 0 }, 652 { VCBirthDateProp, 0, 0, 0 },
653 { VCBMPProp, 0, 0, 0 }, 653 { VCBMPProp, 0, 0, 0 },
654 { VCBodyProp, 0, 0, 0 }, 654 { VCBodyProp, 0, 0, 0 },
655 { VCBusinessRoleProp, 0, 0, 0 }, 655 { VCBusinessRoleProp, 0, 0, 0 },
656 { VCCalProp, 0, 0, PD_BEGIN }, 656 { VCCalProp, 0, 0, PD_BEGIN },
657 { VCCaptionProp, 0, 0, 0 }, 657 { VCCaptionProp, 0, 0, 0 },
658 { VCCardProp, 0, 0, PD_BEGIN }, 658 { VCCardProp, 0, 0, PD_BEGIN },
659 { VCCarProp, 0, 0, 0 }, 659 { VCCarProp, 0, 0, 0 },
660 { VCCategoriesProp, 0, 0, 0 }, 660 { VCCategoriesProp, 0, 0, 0 },
661 { VCCellularProp, 0, 0, 0 }, 661 { VCCellularProp, 0, 0, 0 },
662 { VCCGMProp, 0, 0, 0 }, 662 { VCCGMProp, 0, 0, 0 },
663 { VCCharSetProp, 0, 0, 0 }, 663 { VCCharSetProp, 0, 0, 0 },
664 { VCCIDProp, VCContentIDProp, 0, 0 }, 664 { VCCIDProp, VCContentIDProp, 0, 0 },
665 { VCCISProp, 0, 0, 0 }, 665 { VCCISProp, 0, 0, 0 },
666 { VCCityProp, 0, 0, 0 }, 666 { VCCityProp, 0, 0, 0 },
667 { VCClassProp, 0, 0, 0 }, 667 { VCClassProp, 0, 0, 0 },
668 { VCCommentProp, 0, 0, 0 }, 668 { VCCommentProp, 0, 0, 0 },
669 { VCCompletedProp, 0, 0, 0 }, 669 { VCCompletedProp, 0, 0, 0 },
670 { VCContentIDProp, 0, 0, 0 }, 670 { VCContentIDProp, 0, 0, 0 },
671 { VCCountryNameProp, 0, 0, 0 }, 671 { VCCountryNameProp, 0, 0, 0 },
672 { VCDAlarmProp, 0, DAlarmFields, 0 }, 672 { VCDAlarmProp, 0, DAlarmFields, 0 },
673 { VCDataSizeProp, 0, 0, PD_INTERNAL }, 673 { VCDataSizeProp, 0, 0, PD_INTERNAL },
674 { VCDayLightProp, 0, 0, 0 }, 674 { VCDayLightProp, 0, 0, 0 },
675 { VCDCreatedProp, 0, 0, 0 }, 675 { VCDCreatedProp, 0, 0, 0 },
676 { VCDeliveryLabelProp, 0, 0, 0 }, 676 { VCDeliveryLabelProp, 0, 0, 0 },
677 { VCDescriptionProp, 0, 0, 0 }, 677 { VCDescriptionProp, 0, 0, 0 },
678 { VCDIBProp, 0, 0, 0 }, 678 { VCDIBProp, 0, 0, 0 },
679 { VCDisplayStringProp, 0, 0, 0 }, 679 { VCDisplayStringProp, 0, 0, 0 },
680 { VCDomesticProp, 0, 0, 0 }, 680 { VCDomesticProp, 0, 0, 0 },
681 { VCDTendProp, 0, 0, 0 }, 681 { VCDTendProp, 0, 0, 0 },
682 { VCDTstartProp, 0, 0, 0 }, 682 { VCDTstartProp, 0, 0, 0 },
683 { VCDueProp, 0, 0, 0 }, 683 { VCDueProp, 0, 0, 0 },
684 { VCEmailAddressProp, 0, 0, 0 }, 684 { VCEmailAddressProp, 0, 0, 0 },
685 { VCEncodingProp, 0, 0, 0 }, 685 { VCEncodingProp, 0, 0, 0 },
686 { VCEndProp, 0, 0, 0 }, 686 { VCEndProp, 0, 0, 0 },
687 { VCEventProp, 0, 0, PD_BEGIN }, 687 { VCEventProp, 0, 0, PD_BEGIN },
688 { VCEWorldProp, 0, 0, 0 }, 688 { VCEWorldProp, 0, 0, 0 },
689 { VCExNumProp, 0, 0, 0 }, 689 { VCExNumProp, 0, 0, 0 },
690 { VCExpDateProp, 0, 0, 0 }, 690 { VCExpDateProp, 0, 0, 0 },
691 { VCExpectProp, 0, 0, 0 }, 691 { VCExpectProp, 0, 0, 0 },
692 { VCExtAddressProp, 0, 0, 0 }, 692 { VCExtAddressProp, 0, 0, 0 },
693 { VCFamilyNameProp, 0, 0, 0 }, 693 { VCFamilyNameProp, 0, 0, 0 },
694 { VCFaxProp, 0, 0, 0 }, 694 { VCFaxProp, 0, 0, 0 },
695 { VCFullNameProp, 0, 0, 0 }, 695 { VCFullNameProp, 0, 0, 0 },
696 { VCGeoLocationProp, 0, 0, 0 }, 696 { VCGeoLocationProp, 0, 0, 0 },
697 { VCGeoProp, 0, 0, 0 }, 697 { VCGeoProp, 0, 0, 0 },
698 { VCGIFProp, 0, 0, 0 }, 698 { VCGIFProp, 0, 0, 0 },
699 { VCGivenNameProp, 0, 0, 0 }, 699 { VCGivenNameProp, 0, 0, 0 },
700 { VCGroupingProp, 0, 0, 0 }, 700 { VCGroupingProp, 0, 0, 0 },
701 { VCHomeProp, 0, 0, 0 }, 701 { VCHomeProp, 0, 0, 0 },
702 { VCIBMMailProp, 0, 0, 0 }, 702 { VCIBMMailProp, 0, 0, 0 },
703 { VCInlineProp, 0, 0, 0 }, 703 { VCInlineProp, 0, 0, 0 },
704 { VCInternationalProp, 0, 0, 0 }, 704 { VCInternationalProp, 0, 0, 0 },
705 { VCInternetProp, 0, 0, 0 }, 705 { VCInternetProp, 0, 0, 0 },
706 { VCISDNProp, 0, 0, 0 }, 706 { VCISDNProp, 0, 0, 0 },
707 { VCJPEGProp, 0, 0, 0 }, 707 { VCJPEGProp, 0, 0, 0 },
708 { VCLanguageProp, 0, 0, 0 }, 708 { VCLanguageProp, 0, 0, 0 },
709 { VCLastModifiedProp, 0, 0, 0 }, 709 { VCLastModifiedProp, 0, 0, 0 },
710 { VCLastRevisedProp, 0, 0, 0 }, 710 { VCLastRevisedProp, 0, 0, 0 },
711 { VCLocationProp, 0, 0, 0 }, 711 { VCLocationProp, 0, 0, 0 },
712 { VCLogoProp, 0, 0, 0 }, 712 { VCLogoProp, 0, 0, 0 },
713 { VCMailerProp, 0, 0, 0 }, 713 { VCMailerProp, 0, 0, 0 },
714 { VCMAlarmProp, 0, MAlarmFields, 0 }, 714 { VCMAlarmProp, 0, MAlarmFields, 0 },
715 { VCMCIMailProp, 0, 0, 0 }, 715 { VCMCIMailProp, 0, 0, 0 },
716 { VCMessageProp, 0, 0, 0 }, 716 { VCMessageProp, 0, 0, 0 },
717 { VCMETProp, 0, 0, 0 }, 717 { VCMETProp, 0, 0, 0 },
718 { VCModemProp, 0, 0, 0 }, 718 { VCModemProp, 0, 0, 0 },
719 { VCMPEG2Prop, 0, 0, 0 }, 719 { VCMPEG2Prop, 0, 0, 0 },
720 { VCMPEGProp, 0, 0, 0 }, 720 { VCMPEGProp, 0, 0, 0 },
721 { VCMSNProp, 0, 0, 0 }, 721 { VCMSNProp, 0, 0, 0 },
722 { VCNamePrefixesProp, 0, 0, 0 }, 722 { VCNamePrefixesProp, 0, 0, 0 },
723 { VCNameProp, 0, nameFields, 0 }, 723 { VCNameProp, 0, nameFields, 0 },
724 { VCNameSuffixesProp, 0, 0, 0 }, 724 { VCNameSuffixesProp, 0, 0, 0 },
725 { VCNoteProp, 0, 0, 0 }, 725 { VCNoteProp, 0, 0, 0 },
726 { VCOrgNameProp, 0, 0, 0 }, 726 { VCOrgNameProp, 0, 0, 0 },
727 { VCOrgProp, 0, orgFields, 0 }, 727 { VCOrgProp, 0, orgFields, 0 },
728 { VCOrgUnit2Prop, 0, 0, 0 }, 728 { VCOrgUnit2Prop, 0, 0, 0 },
729 { VCOrgUnit3Prop, 0, 0, 0 }, 729 { VCOrgUnit3Prop, 0, 0, 0 },
730 { VCOrgUnit4Prop, 0, 0, 0 }, 730 { VCOrgUnit4Prop, 0, 0, 0 },
731 { VCOrgUnitProp, 0, 0, 0 }, 731 { VCOrgUnitProp, 0, 0, 0 },
732 { VCPagerProp, 0, 0, 0 }, 732 { VCPagerProp, 0, 0, 0 },
733 { VCPAlarmProp, 0, PAlarmFields, 0 }, 733 { VCPAlarmProp, 0, PAlarmFields, 0 },
734 { VCParcelProp, 0, 0, 0 }, 734 { VCParcelProp, 0, 0, 0 },
735 { VCPartProp, 0, 0, 0 }, 735 { VCPartProp, 0, 0, 0 },
736 { VCPCMProp, 0, 0, 0 }, 736 { VCPCMProp, 0, 0, 0 },
737 { VCPDFProp, 0, 0, 0 }, 737 { VCPDFProp, 0, 0, 0 },
738 { VCPGPProp, 0, 0, 0 }, 738 { VCPGPProp, 0, 0, 0 },
739 { VCPhotoProp, 0, 0, 0 }, 739 { VCPhotoProp, 0, 0, 0 },
740 { VCPICTProp, 0, 0, 0 }, 740 { VCPICTProp, 0, 0, 0 },
741 { VCPMBProp, 0, 0, 0 }, 741 { VCPMBProp, 0, 0, 0 },
742 { VCPostalBoxProp, 0, 0, 0 }, 742 { VCPostalBoxProp, 0, 0, 0 },
743 { VCPostalCodeProp, 0, 0, 0 }, 743 { VCPostalCodeProp, 0, 0, 0 },
744 { VCPostalProp, 0, 0, 0 }, 744 { VCPostalProp, 0, 0, 0 },
745 { VCPowerShareProp, 0, 0, 0 }, 745 { VCPowerShareProp, 0, 0, 0 },
746 { VCPreferredProp, 0, 0, 0 }, 746 { VCPreferredProp, 0, 0, 0 },
747 { VCPriorityProp, 0, 0, 0 }, 747 { VCPriorityProp, 0, 0, 0 },
748 { VCProcedureNameProp, 0, 0, 0 }, 748 { VCProcedureNameProp, 0, 0, 0 },
749 { VCProdIdProp, 0, 0, 0 }, 749 { VCProdIdProp, 0, 0, 0 },
750 { VCProdigyProp, 0, 0, 0 }, 750 { VCProdigyProp, 0, 0, 0 },
751 { VCPronunciationProp, 0, 0, 0 }, 751 { VCPronunciationProp, 0, 0, 0 },
752 { VCPSProp, 0, 0, 0 }, 752 { VCPSProp, 0, 0, 0 },
753 { VCPublicKeyProp, 0, 0, 0 }, 753 { VCPublicKeyProp, 0, 0, 0 },
754 { VCQPProp, VCQuotedPrintableProp, 0, 0 }, 754 { VCQPProp, VCQuotedPrintableProp, 0, 0 },
755 { VCQuickTimeProp, 0, 0, 0 }, 755 { VCQuickTimeProp, 0, 0, 0 },
756 { VCQuotedPrintableProp, 0, 0, 0 }, 756 { VCQuotedPrintableProp, 0, 0, 0 },
757 { VCRDateProp, 0, 0, 0 }, 757 { VCRDateProp, 0, 0, 0 },
758 { VCRegionProp, 0, 0, 0 }, 758 { VCRegionProp, 0, 0, 0 },
759 { VCRelatedToProp, 0, 0, 0 }, 759 { VCRelatedToProp, 0, 0, 0 },
760 { VCRepeatCountProp, 0, 0, 0 }, 760 { VCRepeatCountProp, 0, 0, 0 },
761 { VCResourcesProp, 0, 0, 0 }, 761 { VCResourcesProp, 0, 0, 0 },
762 { VCRNumProp, 0, 0, 0 }, 762 { VCRNumProp, 0, 0, 0 },
763 { VCRoleProp, 0, 0, 0 }, 763 { VCRoleProp, 0, 0, 0 },
764 { VCRRuleProp, 0, 0, 0 }, 764 { VCRRuleProp, 0, 0, 0 },
765 { VCRSVPProp, 0, 0, 0 }, 765 { VCRSVPProp, 0, 0, 0 },
766 { VCRunTimeProp, 0, 0, 0 }, 766 { VCRunTimeProp, 0, 0, 0 },
767 { VCSequenceProp, 0, 0, 0 }, 767 { VCSequenceProp, 0, 0, 0 },
768 { VCSnoozeTimeProp, 0, 0, 0 }, 768 { VCSnoozeTimeProp, 0, 0, 0 },
769 { VCStartProp, 0, 0, 0 }, 769 { VCStartProp, 0, 0, 0 },
770 { VCStatusProp, 0, 0, 0 }, 770 { VCStatusProp, 0, 0, 0 },
771 { VCStreetAddressProp, 0, 0, 0 }, 771 { VCStreetAddressProp, 0, 0, 0 },
772 { VCSubTypeProp, 0, 0, 0 }, 772 { VCSubTypeProp, 0, 0, 0 },
773 { VCSummaryProp, 0, 0, 0 }, 773 { VCSummaryProp, 0, 0, 0 },
774 { VCTelephoneProp, 0, 0, 0 }, 774 { VCTelephoneProp, 0, 0, 0 },
775 { VCTIFFProp, 0, 0, 0 }, 775 { VCTIFFProp, 0, 0, 0 },
776 { VCTimeZoneProp, 0, 0, 0 }, 776 { VCTimeZoneProp, 0, 0, 0 },
777 { VCTitleProp, 0, 0, 0 }, 777 { VCTitleProp, 0, 0, 0 },
778 { VCTLXProp, 0, 0, 0 }, 778 { VCTLXProp, 0, 0, 0 },
779 { VCTodoProp, 0, 0, PD_BEGIN }, 779 { VCTodoProp, 0, 0, PD_BEGIN },
780 { VCTranspProp, 0, 0, 0 }, 780 { VCTranspProp, 0, 0, 0 },
781 { VCUniqueStringProp, 0, 0, 0 }, 781 { VCUniqueStringProp, 0, 0, 0 },
782 { VCURLProp, 0, 0, 0 }, 782 { VCURLProp, 0, 0, 0 },
783 { VCURLValueProp, 0, 0, 0 }, 783 { VCURLValueProp, 0, 0, 0 },
784 { VCValueProp, 0, 0, 0 }, 784 { VCValueProp, 0, 0, 0 },
785 { VCVersionProp, 0, 0, 0 }, 785 { VCVersionProp, 0, 0, 0 },
786 { VCVideoProp, 0, 0, 0 }, 786 { VCVideoProp, 0, 0, 0 },
787 { VCVoiceProp, 0, 0, 0 }, 787 { VCVoiceProp, 0, 0, 0 },
788 { VCWAVEProp, 0, 0, 0 }, 788 { VCWAVEProp, 0, 0, 0 },
789 { VCWMFProp, 0, 0, 0 }, 789 { VCWMFProp, 0, 0, 0 },
790 { VCWorkProp, 0, 0, 0 }, 790 { VCWorkProp, 0, 0, 0 },
791 { VCX400Prop, 0, 0, 0 }, 791 { VCX400Prop, 0, 0, 0 },
792 { VCX509Prop, 0, 0, 0 }, 792 { VCX509Prop, 0, 0, 0 },
793 { VCXRuleProp, 0, 0, 0 }, 793 { VCXRuleProp, 0, 0, 0 },
794 { 0,0,0,0 } 794 { 0,0,0,0 }
795 }; 795 };
796 796
797 797
798static struct PreDefProp* lookupPropInfo(const char* str) 798static struct PreDefProp* lookupPropInfo(const char* str)
799{ 799{
800 /* brute force for now, could use a hash table here. */ 800 /* brute force for now, could use a hash table here. */
801 int i; 801 int i;
802 802
803 for (i = 0; propNames[i].name; i++) 803 for (i = 0; propNames[i].name; i++)
804 if (qstricmp(str, propNames[i].name) == 0) { 804 if (qstricmp(str, propNames[i].name) == 0) {
805 return &propNames[i]; 805 return &propNames[i];
806 } 806 }
807 807
808 return 0; 808 return 0;
809} 809}
810 810
811 811
812DLLEXPORT(const char*) lookupProp_(const char* str) 812DLLEXPORT(const char*) lookupProp_(const char* str)
813{ 813{
814 int i; 814 int i;
815 815
816 for (i = 0; propNames[i].name; i++) 816 for (i = 0; propNames[i].name; i++)
817 if (qstricmp(str, propNames[i].name) == 0) { 817 if (qstricmp(str, propNames[i].name) == 0) {
818 const char* s; 818 const char* s;
819 s = propNames[i].alias?propNames[i].alias:propNames[i].name; 819 s = propNames[i].alias?propNames[i].alias:propNames[i].name;
820 return lookupStr(s); 820 return lookupStr(s);
821 } 821 }
822 return lookupStr(str); 822 return lookupStr(str);
823} 823}
824 824
825 825
826DLLEXPORT(const char*) lookupProp(const char* str) 826DLLEXPORT(const char*) lookupProp(const char* str)
827{ 827{
828 int i; 828 int i;
829 829
830 for (i = 0; propNames[i].name; i++) 830 for (i = 0; propNames[i].name; i++)
831 if (qstricmp(str, propNames[i].name) == 0) { 831 if (qstricmp(str, propNames[i].name) == 0) {
832 const char *s; 832 const char *s;
833 fieldedProp = propNames[i].fields; 833 fieldedProp = propNames[i].fields;
834 s = propNames[i].alias?propNames[i].alias:propNames[i].name; 834 s = propNames[i].alias?propNames[i].alias:propNames[i].name;
835 return lookupStr(s); 835 return lookupStr(s);
836 } 836 }
837 fieldedProp = 0; 837 fieldedProp = 0;
838 return lookupStr(str); 838 return lookupStr(str);
839} 839}
840 840
841 841
842/*---------------------------------------------------------------------- 842/*----------------------------------------------------------------------
843 APIs to Output text form. 843 APIs to Output text form.
844 ----------------------------------------------------------------------*/ 844 ----------------------------------------------------------------------*/
845#define OFILE_REALLOC_SIZE 256 845#define OFILE_REALLOC_SIZE 256
846typedef struct OFile { 846typedef struct OFile {
847 FILE *fp; 847 FILE *fp;
848 char *s; 848 char *s;
849 int len; 849 int len;
850 int limit; 850 int limit;
851 int alloc:1; 851 int alloc:1;
852 int fail:1; 852 int fail:1;
853 } OFile; 853 } OFile;
854 854
855#if 0 855#if 0
856static void appendsOFile(OFile *fp, const char *s) 856static void appendsOFile(OFile *fp, const char *s)
857{ 857{
858 int slen; 858 int slen;
859 if (fp->fail) return; 859 if (fp->fail) return;
860 slen = strlen(s); 860 slen = strlen(s);
861 if (fp->fp) { 861 if (fp->fp) {
862 fwrite(s,1,slen,fp->fp); 862 fwrite(s,1,slen,fp->fp);
863 } 863 }
864 else { 864 else {
865stuff: 865stuff:
866 if (fp->len + slen < fp->limit) { 866 if (fp->len + slen < fp->limit) {
867 memcpy(fp->s+fp->len,s,slen); 867 memcpy(fp->s+fp->len,s,slen);
868 fp->len += slen; 868 fp->len += slen;
869 return; 869 return;
870 } 870 }
871 else if (fp->alloc) { 871 else if (fp->alloc) {
872 fp->limit = fp->limit + OFILE_REALLOC_SIZE; 872 fp->limit = fp->limit + OFILE_REALLOC_SIZE;
873 if (OFILE_REALLOC_SIZE <= slen) fp->limit += slen; 873 if (OFILE_REALLOC_SIZE <= slen) fp->limit += slen;
874 fp->s = (char *) realloc(fp->s,fp->limit); 874 fp->s = (char *) realloc(fp->s,fp->limit);
875 if (fp->s) goto stuff; 875 if (fp->s) goto stuff;
876 } 876 }
877 if (fp->alloc) 877 if (fp->alloc)
878 free(fp->s); 878 free(fp->s);
879 fp->s = 0; 879 fp->s = 0;
880 fp->fail = 1; 880 fp->fail = 1;
881 } 881 }
882} 882}
883 883
884static void appendcOFile(OFile *fp, char c) 884static void appendcOFile(OFile *fp, char c)
885{ 885{
886 if (fp->fail) return; 886 if (fp->fail) return;
887 if (fp->fp) { 887 if (fp->fp) {
888 fputc(c,fp->fp); 888 fputc(c,fp->fp);
889 } 889 }
890 else { 890 else {
891stuff: 891stuff:
892 if (fp->len+1 < fp->limit) { 892 if (fp->len+1 < fp->limit) {
893 fp->s[fp->len] = c; 893 fp->s[fp->len] = c;
894 fp->len++; 894 fp->len++;
895 return; 895 return;
896 } 896 }
897 else if (fp->alloc) { 897 else if (fp->alloc) {
898 fp->limit = fp->limit + OFILE_REALLOC_SIZE; 898 fp->limit = fp->limit + OFILE_REALLOC_SIZE;
899 fp->s = (char *) realloc(fp->s,fp->limit); 899 fp->s = (char *) realloc(fp->s,fp->limit);
900 if (fp->s) goto stuff; 900 if (fp->s) goto stuff;
901 } 901 }
902 if (fp->alloc) 902 if (fp->alloc)
903 free(fp->s); 903 free(fp->s);
904 fp->s = 0; 904 fp->s = 0;
905 fp->fail = 1; 905 fp->fail = 1;
906 } 906 }
907} 907}
908#else 908#else
909static void appendcOFile_(OFile *fp, char c) 909static void appendcOFile_(OFile *fp, char c)
910{ 910{
911 if (fp->fail) return; 911 if (fp->fail) return;
912 if (fp->fp) { 912 if (fp->fp) {
913 fputc(c,fp->fp); 913 fputc(c,fp->fp);
914 } 914 }
915 else { 915 else {
916stuff: 916stuff:
917 if (fp->len+1 < fp->limit) { 917 if (fp->len+1 < fp->limit) {
918 fp->s[fp->len] = c; 918 fp->s[fp->len] = c;
919 fp->len++; 919 fp->len++;
920 return; 920 return;
921 } 921 }
922 else if (fp->alloc) { 922 else if (fp->alloc) {
923 fp->limit = fp->limit + OFILE_REALLOC_SIZE; 923 fp->limit = fp->limit + OFILE_REALLOC_SIZE;
924 fp->s = (char *)realloc(fp->s,fp->limit); 924 fp->s = (char *)realloc(fp->s,fp->limit);
925 if (fp->s) goto stuff; 925 if (fp->s) goto stuff;
926 } 926 }
927 if (fp->alloc) 927 if (fp->alloc)
928 free(fp->s); 928 free(fp->s);
929 fp->s = 0; 929 fp->s = 0;
930 fp->fail = 1; 930 fp->fail = 1;
931 } 931 }
932} 932}
933 933
934static void appendcOFile(OFile *fp, char c) 934static void appendcOFile(OFile *fp, char c)
935{ 935{
936 if (c == '\n') { 936 if (c == '\n') {
937 /* write out as <CR><LF> */ 937 /* write out as <CR><LF> */
938 appendcOFile_(fp,0xd); 938 appendcOFile_(fp,0xd);
939 appendcOFile_(fp,0xa); 939 appendcOFile_(fp,0xa);
940 } 940 }
941 else 941 else
942 appendcOFile_(fp,c); 942 appendcOFile_(fp,c);
943} 943}
944 944
945static void appendsOFile(OFile *fp, const char *s) 945static void appendsOFile(OFile *fp, const char *s)
946{ 946{
947 int i, slen; 947 int i, slen;
948 slen = strlen(s); 948 slen = strlen(s);
949 for (i=0; i<slen; i++) { 949 for (i=0; i<slen; i++) {
950 appendcOFile(fp,s[i]); 950 appendcOFile(fp,s[i]);
951 } 951 }
952} 952}
953 953
954#endif 954#endif
955 955
956static void initOFile(OFile *fp, FILE *ofp) 956static void initOFile(OFile *fp, FILE *ofp)
957{ 957{
958 fp->fp = ofp; 958 fp->fp = ofp;
959 fp->s = 0; 959 fp->s = 0;
960 fp->len = 0; 960 fp->len = 0;
961 fp->limit = 0; 961 fp->limit = 0;
962 fp->alloc = 0; 962 fp->alloc = 0;
963 fp->fail = 0; 963 fp->fail = 0;
964} 964}
965 965
966static int writeBase64(OFile *fp, unsigned char *s, long len) 966static int writeBase64(OFile *fp, unsigned char *s, long len)
967{ 967{
968 long cur = 0; 968 long cur = 0;
969 int i, numQuads = 0; 969 int i, numQuads = 0;
970 unsigned long trip; 970 unsigned long trip;
971 unsigned char b; 971 unsigned char b;
972 char quad[5]; 972 char quad[5];
973#define MAXQUADS 16 973#define MAXQUADS 16
974 974
975 quad[4] = 0; 975 quad[4] = 0;
976 976
977 while (cur < len) { 977 while (cur < len) {
978 // collect the triplet of bytes into 'trip' 978 // collect the triplet of bytes into 'trip'
979 trip = 0; 979 trip = 0;
980 for (i = 0; i < 3; i++) { 980 for (i = 0; i < 3; i++) {
981 b = (cur < len) ? *(s + cur) : 0; 981 b = (cur < len) ? *(s + cur) : 0;
982 cur++; 982 cur++;
983 trip = trip << 8 | b; 983 trip = trip << 8 | b;
984 } 984 }
985 // fill in 'quad' with the appropriate four characters 985 // fill in 'quad' with the appropriate four characters
986 for (i = 3; i >= 0; i--) { 986 for (i = 3; i >= 0; i--) {
987 b = (unsigned char)(trip & 0x3F); 987 b = (unsigned char)(trip & 0x3F);
988 trip = trip >> 6; 988 trip = trip >> 6;
989 if ((3 - i) < (cur - len)) 989 if ((3 - i) < (cur - len))
990 quad[i] = '='; // pad char 990 quad[i] = '='; // pad char
991 else if (b < 26) quad[i] = (char)b + 'A'; 991 else if (b < 26) quad[i] = (char)b + 'A';
992 else if (b < 52) quad[i] = (char)(b - 26) + 'a'; 992 else if (b < 52) quad[i] = (char)(b - 26) + 'a';
993 else if (b < 62) quad[i] = (char)(b - 52) + '0'; 993 else if (b < 62) quad[i] = (char)(b - 52) + '0';
994 else if (b == 62) quad[i] = '+'; 994 else if (b == 62) quad[i] = '+';
995 else quad[i] = '/'; 995 else quad[i] = '/';
996 } 996 }
997 // now output 'quad' with appropriate whitespace and line ending 997 // now output 'quad' with appropriate whitespace and line ending
998 appendsOFile(fp, (numQuads == 0 ? " " : "")); 998 appendsOFile(fp, (numQuads == 0 ? " " : ""));
999 appendsOFile(fp, quad); 999 appendsOFile(fp, quad);
1000 appendsOFile(fp, ((cur >= len)?"\n" :(numQuads==MAXQUADS-1?"\n" : ""))); 1000 appendsOFile(fp, ((cur >= len)?"\n" :(numQuads==MAXQUADS-1?"\n" : "")));
1001 numQuads = (numQuads + 1) % MAXQUADS; 1001 numQuads = (numQuads + 1) % MAXQUADS;
1002 } 1002 }
1003 appendcOFile(fp,'\n'); 1003 appendcOFile(fp,'\n');
1004 1004
1005 return 1; 1005 return 1;
1006} 1006}
1007 1007
1008static const char *replaceChar(unsigned char c) 1008static const char *replaceChar(unsigned char c)
1009{ 1009{
1010 if (c == '\n') { 1010 if (c == '\n') {
1011 return "=0A=\n"; 1011 return "=0A=\n";
1012 } else if ( 1012 } else if (
1013 (c >= 'A' && c <= 'Z') 1013 (c >= 'A' && c <= 'Z')
1014 || 1014 ||
1015 (c >= 'a' && c <= 'z') 1015 (c >= 'a' && c <= 'z')
1016 || 1016 ||
1017 (c >= '0' && c <= '9') 1017 (c >= '0' && c <= '9')
1018 || 1018 ||
1019 (c >= '\'' && c <= ')') 1019 (c >= '\'' && c <= ')')
1020 || 1020 ||
1021 (c >= '+' && c <= '-') 1021 (c >= '+' && c <= '-')
1022 || 1022 ||
1023 (c == '/') 1023 (c == '/')
1024 || 1024 ||
1025 (c == '?') 1025 (c == '?')
1026 || 1026 ||
1027 (c == ' ')) 1027 (c == ' '))
1028 { 1028 {
1029 return 0; 1029 return 0;
1030 } 1030 }
1031 1031
1032 static char trans[4]; 1032 static char trans[4];
1033 trans[0] = '='; 1033 trans[0] = '=';
1034 trans[3] = '\0'; 1034 trans[3] = '\0';
1035 int rem = c % 16; 1035 int rem = c % 16;
1036 int div = c / 16; 1036 int div = c / 16;
1037 1037
1038 if (div < 10) 1038 if (div < 10)
1039 trans[1] = '0' + div; 1039 trans[1] = '0' + div;
1040 else 1040 else
1041 trans[1] = 'A' + (div - 10); 1041 trans[1] = 'A' + (div - 10);
1042 1042
1043 if (rem < 10) 1043 if (rem < 10)
1044 trans[2] = '0' + rem; 1044 trans[2] = '0' + rem;
1045 else 1045 else
1046 trans[2] = 'A' + (rem - 10); 1046 trans[2] = 'A' + (rem - 10);
1047 1047
1048 return trans; 1048 return trans;
1049} 1049}
1050 1050
1051static void writeQPString(OFile *fp, const char *s) 1051static void writeQPString(OFile *fp, const char *s)
1052{ 1052{
1053 /* 1053 /*
1054 only A-Z, 0-9 and 1054 only A-Z, 0-9 and
1055 "'" (ASCII code 39) 1055 "'" (ASCII code 39)
1056 "(" (ASCII code 40) 1056 "(" (ASCII code 40)
1057 ")" (ASCII code 41) 1057 ")" (ASCII code 41)
1058 "+" (ASCII code 43) 1058 "+" (ASCII code 43)
1059 "," (ASCII code 44) 1059 "," (ASCII code 44)
1060 "-" (ASCII code 45) 1060 "-" (ASCII code 45)
1061 "/" (ASCII code 47) 1061 "/" (ASCII code 47)
1062 "?" (ASCII code 63) 1062 "?" (ASCII code 63)
1063 1063
1064 should remain un-encoded. 1064 should remain un-encoded.
1065 '=' needs to be encoded as it is the escape character. 1065 '=' needs to be encoded as it is the escape character.
1066 ';' needs to be as it is a field separator. 1066 ';' needs to be as it is a field separator.
1067 1067
1068 */ 1068 */
1069 const char *p = s; 1069 const char *p = s;
1070 while (*p) { 1070 while (*p) {
1071 const char *rep = replaceChar(*p); 1071 const char *rep = replaceChar(*p);
1072 if (rep) 1072 if (rep)
1073 appendsOFile(fp, rep); 1073 appendsOFile(fp, rep);
1074 else 1074 else
1075 appendcOFile(fp, *p); 1075 appendcOFile(fp, *p);
1076 p++; 1076 p++;
1077 } 1077 }
1078} 1078}
1079 1079
1080static bool includesUnprintable(VObject *o) 1080static bool includesUnprintable(VObject *o)
1081{ 1081{
1082 if (o) { 1082 if (o) {
1083 if (VALUE_TYPE(o) == VCVT_STRINGZ) { 1083 if (VALUE_TYPE(o) == VCVT_STRINGZ) {
1084 const char *p = STRINGZ_VALUE_OF(o); 1084 const char *p = STRINGZ_VALUE_OF(o);
1085 if (p) { 1085 if (p) {
1086 while (*p) { 1086 while (*p) {
1087 if (replaceChar(*p)) 1087 if (replaceChar(*p))
1088 return TRUE; 1088 return TRUE;
1089 p++; 1089 p++;
1090 } 1090 }
1091 } 1091 }
1092 } 1092 }
1093 } 1093 }
1094 return FALSE; 1094 return FALSE;
1095} 1095}
1096 1096
1097static void writeVObject_(OFile *fp, VObject *o); 1097static void writeVObject_(OFile *fp, VObject *o);
1098 1098
1099static void writeValue(OFile *fp, VObject *o, unsigned long size) 1099static void writeValue(OFile *fp, VObject *o, unsigned long size)
1100{ 1100{
1101 if (o == 0) return; 1101 if (o == 0) return;
1102 switch (VALUE_TYPE(o)) { 1102 switch (VALUE_TYPE(o)) {
1103 case VCVT_STRINGZ: { 1103 case VCVT_STRINGZ: {
1104 writeQPString(fp, STRINGZ_VALUE_OF(o)); 1104 writeQPString(fp, STRINGZ_VALUE_OF(o));
1105 break; 1105 break;
1106 } 1106 }
1107 case VCVT_UINT: { 1107 case VCVT_UINT: {
1108 char buf[16]; 1108 char buf[16];
1109 sprintf(buf,"%u", INTEGER_VALUE_OF(o)); 1109 sprintf(buf,"%u", INTEGER_VALUE_OF(o));
1110 appendsOFile(fp,buf); 1110 appendsOFile(fp,buf);
1111 break; 1111 break;
1112 } 1112 }
1113 case VCVT_ULONG: { 1113 case VCVT_ULONG: {
1114 char buf[16]; 1114 char buf[16];
1115 sprintf(buf,"%lu", LONG_VALUE_OF(o)); 1115 sprintf(buf,"%lu", LONG_VALUE_OF(o));
1116 appendsOFile(fp,buf); 1116 appendsOFile(fp,buf);
1117 break; 1117 break;
1118 } 1118 }
1119 case VCVT_RAW: { 1119 case VCVT_RAW: {
1120 appendcOFile(fp,'\n'); 1120 appendcOFile(fp,'\n');
1121 writeBase64(fp,(unsigned char*)(ANY_VALUE_OF(o)),size); 1121 writeBase64(fp,(unsigned char*)(ANY_VALUE_OF(o)),size);
1122 break; 1122 break;
1123 } 1123 }
1124 case VCVT_VOBJECT: 1124 case VCVT_VOBJECT:
1125 appendcOFile(fp,'\n'); 1125 appendcOFile(fp,'\n');
1126 writeVObject_(fp,VOBJECT_VALUE_OF(o)); 1126 writeVObject_(fp,VOBJECT_VALUE_OF(o));
1127 break; 1127 break;
1128 } 1128 }
1129} 1129}
1130 1130
1131static void writeAttrValue(OFile *fp, VObject *o) 1131static void writeAttrValue(OFile *fp, VObject *o)
1132{ 1132{
1133 if (NAME_OF(o)) { 1133 if (NAME_OF(o)) {
1134 struct PreDefProp *pi; 1134 struct PreDefProp *pi;
1135 pi = lookupPropInfo(NAME_OF(o)); 1135 pi = lookupPropInfo(NAME_OF(o));
1136 if (pi && ((pi->flags & PD_INTERNAL) != 0)) return; 1136 if (pi && ((pi->flags & PD_INTERNAL) != 0)) return;
1137 if ( includesUnprintable(o) ) { 1137 if ( includesUnprintable(o) ) {
1138 appendsOFile(fp, ";" VCEncodingProp "=" VCQuotedPrintableProp); 1138 appendsOFile(fp, ";" VCEncodingProp "=" VCQuotedPrintableProp);
1139 appendsOFile(fp, ";" VCCharSetProp "=" "UTF-8"); 1139 appendsOFile(fp, ";" VCCharSetProp "=" "UTF-8");
1140 } 1140 }
1141 appendcOFile(fp,';'); 1141 appendcOFile(fp,';');
1142 appendsOFile(fp,NAME_OF(o)); 1142 appendsOFile(fp,NAME_OF(o));
1143 } 1143 }
1144 else 1144 else
1145 appendcOFile(fp,';'); 1145 appendcOFile(fp,';');
1146 if (VALUE_TYPE(o)) { 1146 if (VALUE_TYPE(o)) {
1147 appendcOFile(fp,'='); 1147 appendcOFile(fp,'=');
1148 writeValue(fp,o,0); 1148 writeValue(fp,o,0);
1149 } 1149 }
1150} 1150}
1151 1151
1152static void writeGroup(OFile *fp, VObject *o) 1152static void writeGroup(OFile *fp, VObject *o)
1153{ 1153{
1154 char buf1[256]; 1154 char buf1[256];
1155 char buf2[256]; 1155 char buf2[256];
1156 strcpy(buf1,NAME_OF(o)); 1156 strcpy(buf1,NAME_OF(o));
1157 while ((o=isAPropertyOf(o,VCGroupingProp)) != 0) { 1157 while ((o=isAPropertyOf(o,VCGroupingProp)) != 0) {
1158 strcpy(buf2,STRINGZ_VALUE_OF(o)); 1158 strcpy(buf2,STRINGZ_VALUE_OF(o));
1159 strcat(buf2,"."); 1159 strcat(buf2,".");
1160 strcat(buf2,buf1); 1160 strcat(buf2,buf1);
1161 strcpy(buf1,buf2); 1161 strcpy(buf1,buf2);
1162 } 1162 }
1163 appendsOFile(fp,buf1); 1163 appendsOFile(fp,buf1);
1164} 1164}
1165 1165
1166static int inList(const char **list, const char *s) 1166static int inList(const char **list, const char *s)
1167{ 1167{
1168 if (list == 0) return 0; 1168 if (list == 0) return 0;
1169 while (*list) { 1169 while (*list) {
1170 if (qstricmp(*list,s) == 0) return 1; 1170 if (qstricmp(*list,s) == 0) return 1;
1171 list++; 1171 list++;
1172 } 1172 }
1173 return 0; 1173 return 0;
1174} 1174}
1175 1175
1176static void writeProp(OFile *fp, VObject *o) 1176static void writeProp(OFile *fp, VObject *o)
1177{ 1177{
1178 if (NAME_OF(o)) { 1178 if (NAME_OF(o)) {
1179 struct PreDefProp *pi; 1179 struct PreDefProp *pi;
1180 VObjectIterator t; 1180 VObjectIterator t;
1181 const char **fields_ = 0; 1181 const char **fields_ = 0;
1182 pi = lookupPropInfo(NAME_OF(o)); 1182 pi = lookupPropInfo(NAME_OF(o));
1183 if (pi && ((pi->flags & PD_BEGIN) != 0)) { 1183 if (pi && ((pi->flags & PD_BEGIN) != 0)) {
1184 writeVObject_(fp,o); 1184 writeVObject_(fp,o);
1185 return; 1185 return;
1186 } 1186 }
1187 if (isAPropertyOf(o,VCGroupingProp)) 1187 if (isAPropertyOf(o,VCGroupingProp))
1188 writeGroup(fp,o); 1188 writeGroup(fp,o);
1189 else 1189 else
1190 appendsOFile(fp,NAME_OF(o)); 1190 appendsOFile(fp,NAME_OF(o));
1191 if (pi) fields_ = pi->fields; 1191 if (pi) fields_ = pi->fields;
1192 initPropIterator(&t,o); 1192 initPropIterator(&t,o);
1193 while (moreIteration(&t)) { 1193 while (moreIteration(&t)) {
1194 const char *s; 1194 const char *s;
1195 VObject *eachProp = nextVObject(&t); 1195 VObject *eachProp = nextVObject(&t);
1196 s = NAME_OF(eachProp); 1196 s = NAME_OF(eachProp);
1197 if (qstricmp(VCGroupingProp,s) && !inList(fields_,s)) 1197 if (qstricmp(VCGroupingProp,s) && !inList(fields_,s))
1198 writeAttrValue(fp,eachProp); 1198 writeAttrValue(fp,eachProp);
1199 } 1199 }
1200 if (fields_) { 1200 if (fields_) {
1201 int i = 0, n = 0; 1201 int i = 0, n = 0;
1202 const char** fields = fields_; 1202 const char** fields = fields_;
1203 /* output prop as fields */ 1203 /* output prop as fields */
1204 bool printable = TRUE; 1204 bool printable = TRUE;
1205 while (*fields && printable) { 1205 while (*fields && printable) {
1206 VObject *t = isAPropertyOf(o,*fields); 1206 VObject *t = isAPropertyOf(o,*fields);
1207 if (includesUnprintable(t)) 1207 if (includesUnprintable(t))
1208 printable = FALSE; 1208 printable = FALSE;
1209 fields++; 1209 fields++;
1210 } 1210 }
1211 fields = fields_; 1211 fields = fields_;
1212 if (!printable) { 1212 if (!printable) {
1213 appendsOFile(fp, ";" VCEncodingProp "=" VCQuotedPrintableProp); 1213 appendsOFile(fp, ";" VCEncodingProp "=" VCQuotedPrintableProp);
1214 appendsOFile(fp, ";" VCCharSetProp "=" "UTF-8"); 1214 appendsOFile(fp, ";" VCCharSetProp "=" "UTF-8");
1215 } 1215 }
1216 appendcOFile(fp,':'); 1216 appendcOFile(fp,':');
1217 while (*fields) { 1217 while (*fields) {
1218 VObject *t = isAPropertyOf(o,*fields); 1218 VObject *t = isAPropertyOf(o,*fields);
1219 i++; 1219 i++;
1220 if (t) n = i; 1220 if (t) n = i;
1221 fields++; 1221 fields++;
1222 } 1222 }
1223 fields = fields_; 1223 fields = fields_;
1224 for (i=0;i<n;i++) { 1224 for (i=0;i<n;i++) {
1225 writeValue(fp,isAPropertyOf(o,*fields),0); 1225 writeValue(fp,isAPropertyOf(o,*fields),0);
1226 fields++; 1226 fields++;
1227 if (i<(n-1)) appendcOFile(fp,';'); 1227 if (i<(n-1)) appendcOFile(fp,';');
1228 } 1228 }
1229 } 1229 }
1230 } 1230 }
1231 1231
1232 1232
1233 if (VALUE_TYPE(o)) { 1233 if (VALUE_TYPE(o)) {
1234 if ( includesUnprintable(o) ) { 1234 if ( includesUnprintable(o) ) {
1235 appendsOFile(fp, ";" VCEncodingProp "=" VCQuotedPrintableProp); 1235 appendsOFile(fp, ";" VCEncodingProp "=" VCQuotedPrintableProp);
1236 appendsOFile(fp, ";" VCCharSetProp "=" "UTF-8"); 1236 appendsOFile(fp, ";" VCCharSetProp "=" "UTF-8");
1237 } 1237 }
1238 unsigned long size = 0; 1238 unsigned long size = 0;
1239 VObject *p = isAPropertyOf(o,VCDataSizeProp); 1239 VObject *p = isAPropertyOf(o,VCDataSizeProp);
1240 if (p) size = LONG_VALUE_OF(p); 1240 if (p) size = LONG_VALUE_OF(p);
1241 appendcOFile(fp,':'); 1241 appendcOFile(fp,':');
1242 writeValue(fp,o,size); 1242 writeValue(fp,o,size);
1243 } 1243 }
1244 1244
1245 appendcOFile(fp,'\n'); 1245 appendcOFile(fp,'\n');
1246} 1246}
1247 1247
1248static void writeVObject_(OFile *fp, VObject *o) 1248static void writeVObject_(OFile *fp, VObject *o)
1249{ 1249{
1250 if (NAME_OF(o)) { 1250 if (NAME_OF(o)) {
1251 struct PreDefProp *pi; 1251 struct PreDefProp *pi;
1252 pi = lookupPropInfo(NAME_OF(o)); 1252 pi = lookupPropInfo(NAME_OF(o));
1253 1253
1254 if (pi && ((pi->flags & PD_BEGIN) != 0)) { 1254 if (pi && ((pi->flags & PD_BEGIN) != 0)) {
1255 VObjectIterator t; 1255 VObjectIterator t;
1256 const char *begin = NAME_OF(o); 1256 const char *begin = NAME_OF(o);
1257 appendsOFile(fp,"BEGIN:"); 1257 appendsOFile(fp,"BEGIN:");
1258 appendsOFile(fp,begin); 1258 appendsOFile(fp,begin);
1259 appendcOFile(fp,'\n'); 1259 appendcOFile(fp,'\n');
1260 initPropIterator(&t,o); 1260 initPropIterator(&t,o);
1261 while (moreIteration(&t)) { 1261 while (moreIteration(&t)) {
1262 VObject *eachProp = nextVObject(&t); 1262 VObject *eachProp = nextVObject(&t);
1263 writeProp(fp, eachProp); 1263 writeProp(fp, eachProp);
1264 } 1264 }
1265 appendsOFile(fp,"END:"); 1265 appendsOFile(fp,"END:");
1266 appendsOFile(fp,begin); 1266 appendsOFile(fp,begin);
1267 appendsOFile(fp,"\n\n"); 1267 appendsOFile(fp,"\n\n");
1268 } 1268 }
1269 } 1269 }
1270} 1270}
1271 1271
1272void writeVObject(FILE *fp, VObject *o) 1272void writeVObject(FILE *fp, VObject *o)
1273{ 1273{
1274 OFile ofp; 1274 OFile ofp;
1275 // ##### 1275 // #####
1276 //_setmode(_fileno(fp), _O_BINARY); 1276 //_setmode(_fileno(fp), _O_BINARY);
1277 initOFile(&ofp,fp); 1277 initOFile(&ofp,fp);
1278 writeVObject_(&ofp,o); 1278 writeVObject_(&ofp,o);
1279} 1279}
1280 1280
1281DLLEXPORT(void) writeVObjectToFile(char *fname, VObject *o) 1281DLLEXPORT(void) writeVObjectToFile(char *fname, VObject *o)
1282{ 1282{
1283 QFileDirect f( fname); 1283 QFileDirect f( fname);
1284 if ( !f.open( IO_WriteOnly ) ) { 1284 if ( !f.open( IO_WriteOnly ) ) {
1285 qWarning("Unable to open vobject write %s", fname); 1285 qWarning("Unable to open vobject write %s", fname);
1286 return; 1286 return;
1287 } 1287 }
1288 1288
1289 writeVObject( f.directHandle(),o ); 1289 writeVObject( f.directHandle(),o );
1290} 1290}
1291 1291
1292DLLEXPORT(void) writeVObjectsToFile(char *fname, VObject *list) 1292DLLEXPORT(void) writeVObjectsToFile(char *fname, VObject *list)
1293{ 1293{
1294 QFileDirect f( fname); 1294 QFileDirect f( fname);
1295 if ( !f.open( IO_WriteOnly ) ) { 1295 if ( !f.open( IO_WriteOnly ) ) {
1296 qWarning("Unable to open vobject write %s", fname); 1296 qWarning("Unable to open vobject write %s", fname);
1297 return; 1297 return;
1298 } 1298 }
1299 1299
1300 while (list) { 1300 while (list) {
1301 writeVObject(f.directHandle(),list); 1301 writeVObject(f.directHandle(),list);
1302 list = nextVObjectInList(list); 1302 list = nextVObjectInList(list);
1303 } 1303 }
1304} 1304}
1305 1305
1306DLLEXPORT(const char *) vObjectTypeInfo(VObject *o) 1306DLLEXPORT(const char *) vObjectTypeInfo(VObject *o)
1307{ 1307{
1308 const char *type = vObjectName( o ); 1308 const char *type = vObjectName( o );
1309 if ( strcmp( type, "TYPE" ) == 0 ) 1309 if ( strcmp( type, "TYPE" ) == 0 )
1310 type = vObjectStringZValue( o ); 1310 type = vObjectStringZValue( o );
1311 return type; 1311 return type;
1312} 1312}
1313 1313
1314 1314
1315// end of source file vobject.c 1315// end of source file vobject.c
diff --git a/library/datebookmonth.cpp b/library/datebookmonth.cpp
index 272c223..4a9dcbd 100644
--- a/library/datebookmonth.cpp
+++ b/library/datebookmonth.cpp
@@ -1,750 +1,750 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#include "config.h" 20#include "config.h"
21#include "datebookmonth.h" 21#include "datebookmonth.h"
22#include "datebookdb.h" 22#include "datebookdb.h"
23#include <qtopia/private/event.h> 23#include <qtopia/private/event.h>
24#include "resource.h" 24#include "resource.h"
25#include "qpeapplication.h" 25#include <qpe/qpeapplication.h>
26#include "timestring.h" 26#include "timestring.h"
27 27
28#include <qtoolbutton.h> 28#include <qtoolbutton.h>
29#include <qspinbox.h> 29#include <qspinbox.h>
30#include <qcombobox.h> 30#include <qcombobox.h>
31#include <qdatetime.h> 31#include <qdatetime.h>
32#include <qpainter.h> 32#include <qpainter.h>
33#include <qpopupmenu.h> 33#include <qpopupmenu.h>
34#include <qvaluestack.h> 34#include <qvaluestack.h>
35#include <qwhatsthis.h> 35#include <qwhatsthis.h>
36 36
37 37
38DateBookMonthHeader::DateBookMonthHeader( QWidget *parent, const char *name ) 38DateBookMonthHeader::DateBookMonthHeader( QWidget *parent, const char *name )
39 : QHBox( parent, name ) 39 : QHBox( parent, name )
40{ 40{
41 setBackgroundMode( PaletteButton ); 41 setBackgroundMode( PaletteButton );
42 42
43 begin = new QToolButton( this ); 43 begin = new QToolButton( this );
44 begin->setFocusPolicy(NoFocus); 44 begin->setFocusPolicy(NoFocus);
45 begin->setPixmap( Resource::loadPixmap( "start" ) ); 45 begin->setPixmap( Resource::loadPixmap( "start" ) );
46 begin->setAutoRaise( TRUE ); 46 begin->setAutoRaise( TRUE );
47 begin->setFixedSize( begin->sizeHint() ); 47 begin->setFixedSize( begin->sizeHint() );
48 QWhatsThis::add( begin, tr("Show January in the selected year") ); 48 QWhatsThis::add( begin, tr("Show January in the selected year") );
49 49
50 back = new QToolButton( this ); 50 back = new QToolButton( this );
51 back->setFocusPolicy(NoFocus); 51 back->setFocusPolicy(NoFocus);
52 back->setPixmap( Resource::loadPixmap( "back" ) ); 52 back->setPixmap( Resource::loadPixmap( "back" ) );
53 back->setAutoRaise( TRUE ); 53 back->setAutoRaise( TRUE );
54 back->setFixedSize( back->sizeHint() ); 54 back->setFixedSize( back->sizeHint() );
55 QWhatsThis::add( back, tr("Show the previous month") ); 55 QWhatsThis::add( back, tr("Show the previous month") );
56 56
57 month = new QComboBox( FALSE, this ); 57 month = new QComboBox( FALSE, this );
58 for ( int i = 0; i < 12; ++i ) 58 for ( int i = 0; i < 12; ++i )
59 month->insertItem( Calendar::nameOfMonth( i + 1 ) ); 59 month->insertItem( Calendar::nameOfMonth( i + 1 ) );
60 60
61 year = new QSpinBox( 1752, 8000, 1, this ); 61 year = new QSpinBox( 1752, 8000, 1, this );
62 62
63 next = new QToolButton( this ); 63 next = new QToolButton( this );
64 next->setFocusPolicy(NoFocus); 64 next->setFocusPolicy(NoFocus);
65 next->setPixmap( Resource::loadPixmap( "forward" ) ); 65 next->setPixmap( Resource::loadPixmap( "forward" ) );
66 next->setAutoRaise( TRUE ); 66 next->setAutoRaise( TRUE );
67 next->setFixedSize( next->sizeHint() ); 67 next->setFixedSize( next->sizeHint() );
68 QWhatsThis::add( next, tr("Show the next month") ); 68 QWhatsThis::add( next, tr("Show the next month") );
69 69
70 end = new QToolButton( this ); 70 end = new QToolButton( this );
71 end->setFocusPolicy(NoFocus); 71 end->setFocusPolicy(NoFocus);
72 end->setPixmap( Resource::loadPixmap( "finish" ) ); 72 end->setPixmap( Resource::loadPixmap( "finish" ) );
73 end->setAutoRaise( TRUE ); 73 end->setAutoRaise( TRUE );
74 end->setFixedSize( end->sizeHint() ); 74 end->setFixedSize( end->sizeHint() );
75 QWhatsThis::add( end, tr("Show December in the selected year") ); 75 QWhatsThis::add( end, tr("Show December in the selected year") );
76 76
77 connect( month, SIGNAL( activated( int ) ), 77 connect( month, SIGNAL( activated( int ) ),
78 this, SLOT( updateDate() ) ); 78 this, SLOT( updateDate() ) );
79 connect( year, SIGNAL( valueChanged( int ) ), 79 connect( year, SIGNAL( valueChanged( int ) ),
80 this, SLOT( updateDate() ) ); 80 this, SLOT( updateDate() ) );
81 connect( begin, SIGNAL( clicked() ), 81 connect( begin, SIGNAL( clicked() ),
82 this, SLOT( firstMonth() ) ); 82 this, SLOT( firstMonth() ) );
83 connect( end, SIGNAL( clicked() ), 83 connect( end, SIGNAL( clicked() ),
84 this, SLOT( lastMonth() ) ); 84 this, SLOT( lastMonth() ) );
85 connect( back, SIGNAL( clicked() ), 85 connect( back, SIGNAL( clicked() ),
86 this, SLOT( monthBack() ) ); 86 this, SLOT( monthBack() ) );
87 connect( next, SIGNAL( clicked() ), 87 connect( next, SIGNAL( clicked() ),
88 this, SLOT( monthForward() ) ); 88 this, SLOT( monthForward() ) );
89 back->setAutoRepeat( TRUE ); 89 back->setAutoRepeat( TRUE );
90 next->setAutoRepeat( TRUE ); 90 next->setAutoRepeat( TRUE );
91} 91}
92 92
93 93
94DateBookMonthHeader::~DateBookMonthHeader() 94DateBookMonthHeader::~DateBookMonthHeader()
95{ 95{
96 96
97} 97}
98 98
99void DateBookMonthHeader::updateDate() 99void DateBookMonthHeader::updateDate()
100{ 100{
101 emit dateChanged( year->value(), month->currentItem() + 1 ); 101 emit dateChanged( year->value(), month->currentItem() + 1 );
102} 102}
103 103
104void DateBookMonthHeader::firstMonth() 104void DateBookMonthHeader::firstMonth()
105{ 105{
106 emit dateChanged( year->value(), 1 ); 106 emit dateChanged( year->value(), 1 );
107 month->setCurrentItem( 0 ); 107 month->setCurrentItem( 0 );
108} 108}
109 109
110void DateBookMonthHeader::lastMonth() 110void DateBookMonthHeader::lastMonth()
111{ 111{
112 emit dateChanged( year->value(), 12 ); 112 emit dateChanged( year->value(), 12 );
113 month->setCurrentItem( 11 ); 113 month->setCurrentItem( 11 );
114} 114}
115 115
116void DateBookMonthHeader::monthBack() 116void DateBookMonthHeader::monthBack()
117{ 117{
118 if ( month->currentItem() > 0 ) { 118 if ( month->currentItem() > 0 ) {
119 emit dateChanged( year->value(), month->currentItem() ); 119 emit dateChanged( year->value(), month->currentItem() );
120 month->setCurrentItem( month->currentItem() - 1 ); 120 month->setCurrentItem( month->currentItem() - 1 );
121 } else { 121 } else {
122 emit dateChanged( year->value() - 1, 12 ); 122 emit dateChanged( year->value() - 1, 12 );
123 // we have a signal set to a changed value in year so we only need to change 123 // we have a signal set to a changed value in year so we only need to change
124 // year to get the result... 124 // year to get the result...
125 month->setCurrentItem( 11 ); 125 month->setCurrentItem( 11 );
126 year->setValue( year->value() - 1 ); 126 year->setValue( year->value() - 1 );
127 } 127 }
128} 128}
129 129
130void DateBookMonthHeader::monthForward() 130void DateBookMonthHeader::monthForward()
131{ 131{
132 if ( month->currentItem() < 11 ) { 132 if ( month->currentItem() < 11 ) {
133 emit dateChanged( year->value(), month->currentItem() + 2 ); 133 emit dateChanged( year->value(), month->currentItem() + 2 );
134 month->setCurrentItem( month->currentItem() + 1 ); 134 month->setCurrentItem( month->currentItem() + 1 );
135 } else { 135 } else {
136 // we have a signal set to a changed value in year so we only need to change 136 // we have a signal set to a changed value in year so we only need to change
137 // year to get the result... 137 // year to get the result...
138 month->setCurrentItem( 0 ); 138 month->setCurrentItem( 0 );
139 year->setValue( year->value() + 1 ); 139 year->setValue( year->value() + 1 );
140 } 140 }
141} 141}
142 142
143void DateBookMonthHeader::setDate( int y, int m ) 143void DateBookMonthHeader::setDate( int y, int m )
144{ 144{
145 year->setValue( y ); 145 year->setValue( y );
146 month->setCurrentItem( m - 1 ); 146 month->setCurrentItem( m - 1 );
147} 147}
148 148
149//--------------------------------------------------------------------------- 149//---------------------------------------------------------------------------
150 150
151class DateBookMonthTablePrivate 151class DateBookMonthTablePrivate
152{ 152{
153public: 153public:
154 DateBookMonthTablePrivate() {}; 154 DateBookMonthTablePrivate() {};
155 ~DateBookMonthTablePrivate() { mMonthEvents.clear(); }; 155 ~DateBookMonthTablePrivate() { mMonthEvents.clear(); };
156 156
157 QValueList<EffectiveEvent> mMonthEvents; 157 QValueList<EffectiveEvent> mMonthEvents;
158 bool onMonday; 158 bool onMonday;
159}; 159};
160 160
161DateBookMonthTable::DateBookMonthTable( QWidget *parent, const char *name, 161DateBookMonthTable::DateBookMonthTable( QWidget *parent, const char *name,
162 DateBookDB *newDb ) 162 DateBookDB *newDb )
163 : QTable( 6, 7, parent, name ), 163 : QTable( 6, 7, parent, name ),
164 db( newDb ) 164 db( newDb )
165{ 165{
166 d = new DateBookMonthTablePrivate(); 166 d = new DateBookMonthTablePrivate();
167 selYear = -1; 167 selYear = -1;
168 selMonth = -1; 168 selMonth = -1;
169 selDay = -1; 169 selDay = -1;
170 170
171 Config cfg( "qpe" ); 171 Config cfg( "qpe" );
172 cfg.setGroup( "Time" ); 172 cfg.setGroup( "Time" );
173 d->onMonday = cfg.readBoolEntry( "MONDAY" ); 173 d->onMonday = cfg.readBoolEntry( "MONDAY" );
174 174
175 horizontalHeader()->setResizeEnabled( FALSE ); 175 horizontalHeader()->setResizeEnabled( FALSE );
176 // we have to do this here... or suffer the consequences later... 176 // we have to do this here... or suffer the consequences later...
177 for ( int i = 0; i < 7; i++ ){ 177 for ( int i = 0; i < 7; i++ ){
178 horizontalHeader()->resizeSection( i, 30 ); 178 horizontalHeader()->resizeSection( i, 30 );
179 setColumnStretchable( i, TRUE ); 179 setColumnStretchable( i, TRUE );
180 } 180 }
181 setupLabels(); 181 setupLabels();
182 182
183 verticalHeader()->hide(); 183 verticalHeader()->hide();
184 setLeftMargin( 0 ); 184 setLeftMargin( 0 );
185 for ( int i = 0; i < 6; ++i ) 185 for ( int i = 0; i < 6; ++i )
186 setRowStretchable( i, TRUE ); 186 setRowStretchable( i, TRUE );
187 187
188 setSelectionMode( NoSelection ); 188 setSelectionMode( NoSelection );
189 189
190 connect( this, SIGNAL( clicked( int, int, int, const QPoint & ) ), 190 connect( this, SIGNAL( clicked( int, int, int, const QPoint & ) ),
191 this, SLOT( dayClicked( int, int ) ) ); 191 this, SLOT( dayClicked( int, int ) ) );
192 connect( this, SIGNAL( currentChanged( int, int ) ), 192 connect( this, SIGNAL( currentChanged( int, int ) ),
193 this, SLOT( dragDay( int, int ) ) ); 193 this, SLOT( dragDay( int, int ) ) );
194 setVScrollBarMode( AlwaysOff ); 194 setVScrollBarMode( AlwaysOff );
195 setHScrollBarMode( AlwaysOff ); 195 setHScrollBarMode( AlwaysOff );
196} 196}
197 197
198DateBookMonthTable::~DateBookMonthTable() 198DateBookMonthTable::~DateBookMonthTable()
199{ 199{
200 monthsEvents.clear(); 200 monthsEvents.clear();
201 delete d; 201 delete d;
202} 202}
203 203
204void DateBookMonthTable::setDate(int y, int m, int d) 204void DateBookMonthTable::setDate(int y, int m, int d)
205{ 205{
206 if (month == m && year == y) { 206 if (month == m && year == y) {
207 if ( selYear == -1 ) 207 if ( selYear == -1 )
208 year = selYear; 208 year = selYear;
209 if ( selMonth == -1 ) 209 if ( selMonth == -1 )
210 month = selMonth; 210 month = selMonth;
211 int r1, c1, r2, c2; 211 int r1, c1, r2, c2;
212 findDay(selDay, r1, c1); 212 findDay(selDay, r1, c1);
213 selDay = day = d; 213 selDay = day = d;
214 findDay(selDay, r2, c2); 214 findDay(selDay, r2, c2);
215 setCurrentCell( r2, c2 ); 215 setCurrentCell( r2, c2 );
216 //updateCell(r1,c1); 216 //updateCell(r1,c1);
217 //updateCell(r2,c2); 217 //updateCell(r2,c2);
218 } else { 218 } else {
219 selYear = year = y; 219 selYear = year = y;
220 selMonth = month = m; 220 selMonth = month = m;
221 selDay = day = d; 221 selDay = day = d;
222 setupTable(); 222 setupTable();
223 } 223 }
224} 224}
225 225
226void DateBookMonthTable::redraw() 226void DateBookMonthTable::redraw()
227{ 227{
228 setupLabels(); 228 setupLabels();
229 setupTable(); 229 setupTable();
230} 230}
231 231
232void DateBookMonthTable::setWeekStart( bool onMonday ) 232void DateBookMonthTable::setWeekStart( bool onMonday )
233{ 233{
234 d->onMonday = onMonday; 234 d->onMonday = onMonday;
235 setupLabels(); 235 setupLabels();
236 setupTable(); 236 setupTable();
237} 237}
238 238
239void DateBookMonthTable::setupTable() 239void DateBookMonthTable::setupTable()
240{ 240{
241 QValueList<Calendar::Day> days = Calendar::daysOfMonth( year, month, d->onMonday ); 241 QValueList<Calendar::Day> days = Calendar::daysOfMonth( year, month, d->onMonday );
242 QValueList<Calendar::Day>::Iterator it = days.begin(); 242 QValueList<Calendar::Day>::Iterator it = days.begin();
243 int row = 0, col = 0; 243 int row = 0, col = 0;
244 int crow = 0; 244 int crow = 0;
245 int ccol = 0; 245 int ccol = 0;
246 for ( ; it != days.end(); ++it ) { 246 for ( ; it != days.end(); ++it ) {
247 DayItemMonth *i = (DayItemMonth *)item( row, col ); 247 DayItemMonth *i = (DayItemMonth *)item( row, col );
248 if ( !i ) { 248 if ( !i ) {
249 i = new DayItemMonth( this, QTableItem::Never, "" ); 249 i = new DayItemMonth( this, QTableItem::Never, "" );
250 setItem( row, col, i ); 250 setItem( row, col, i );
251 } 251 }
252 Calendar::Day calDay = *it; 252 Calendar::Day calDay = *it;
253 i->clearEffEvents(); 253 i->clearEffEvents();
254 i->setDay( calDay.date ); 254 i->setDay( calDay.date );
255 i->setType( calDay.type ); 255 i->setType( calDay.type );
256 if ( i->day() == day && calDay.type == Calendar::Day::ThisMonth ) { 256 if ( i->day() == day && calDay.type == Calendar::Day::ThisMonth ) {
257 crow = row; 257 crow = row;
258 ccol = col; 258 ccol = col;
259 } 259 }
260 260
261 updateCell( row, col ); 261 updateCell( row, col );
262 262
263 if ( col == 6 ) { 263 if ( col == 6 ) {
264 ++row; 264 ++row;
265 col = 0; 265 col = 0;
266 } else { 266 } else {
267 ++col; 267 ++col;
268 } 268 }
269 } 269 }
270 setCurrentCell( crow, ccol ); 270 setCurrentCell( crow, ccol );
271 getEvents(); 271 getEvents();
272} 272}
273 273
274void DateBookMonthTable::findDay( int day, int &row, int &col ) 274void DateBookMonthTable::findDay( int day, int &row, int &col )
275{ 275{
276 QDate dtBegin( year, month, 1 ); 276 QDate dtBegin( year, month, 1 );
277 int skips = dtBegin.dayOfWeek(); 277 int skips = dtBegin.dayOfWeek();
278 int effective_day = day + skips - 1; // row/columns begin at 0 278 int effective_day = day + skips - 1; // row/columns begin at 0
279 // make an extra adjustment if we start on Mondays. 279 // make an extra adjustment if we start on Mondays.
280 if ( d->onMonday ) 280 if ( d->onMonday )
281 effective_day--; 281 effective_day--;
282 row = effective_day / 7; 282 row = effective_day / 7;
283 col = effective_day % 7; 283 col = effective_day % 7;
284} 284}
285 285
286void DateBookMonthTable::dayClicked( int row, int col ) 286void DateBookMonthTable::dayClicked( int row, int col )
287{ 287{
288 changeDaySelection( row, col ); 288 changeDaySelection( row, col );
289 emit dateClicked( selYear, selMonth, selDay ); 289 emit dateClicked( selYear, selMonth, selDay );
290} 290}
291 291
292void DateBookMonthTable::dragDay( int row, int col ) 292void DateBookMonthTable::dragDay( int row, int col )
293{ 293{
294 changeDaySelection( row, col ); 294 changeDaySelection( row, col );
295} 295}
296 296
297void DateBookMonthTable::changeDaySelection( int row, int col ) 297void DateBookMonthTable::changeDaySelection( int row, int col )
298{ 298{
299 DayItemMonth *i = (DayItemMonth*)item( row, col ); 299 DayItemMonth *i = (DayItemMonth*)item( row, col );
300 if ( !i ) 300 if ( !i )
301 return; 301 return;
302 switch ( i->type() ) { 302 switch ( i->type() ) {
303 case Calendar::Day::ThisMonth: 303 case Calendar::Day::ThisMonth:
304 selMonth = month; 304 selMonth = month;
305 break; 305 break;
306 case Calendar::Day::PrevMonth: 306 case Calendar::Day::PrevMonth:
307 selMonth = month-1; 307 selMonth = month-1;
308 break; 308 break;
309 default: 309 default:
310 selMonth = month+1; 310 selMonth = month+1;
311 } 311 }
312 312
313 selYear = year; 313 selYear = year;
314 if ( selMonth <= 0 ) { 314 if ( selMonth <= 0 ) {
315 selMonth = 12; 315 selMonth = 12;
316 selYear--; 316 selYear--;
317 } else if ( selMonth > 12 ) { 317 } else if ( selMonth > 12 ) {
318 selMonth = 1; 318 selMonth = 1;
319 selYear++; 319 selYear++;
320 } 320 }
321 selDay = i->day(); 321 selDay = i->day();
322} 322}
323 323
324 324
325void DateBookMonthTable::viewportMouseReleaseEvent( QMouseEvent * ) 325void DateBookMonthTable::viewportMouseReleaseEvent( QMouseEvent * )
326{ 326{
327 dayClicked( currentRow(), currentColumn() ); 327 dayClicked( currentRow(), currentColumn() );
328} 328}
329 329
330void DateBookMonthTable::getEvents() 330void DateBookMonthTable::getEvents()
331{ 331{
332 if ( !db ) 332 if ( !db )
333 return; 333 return;
334 334
335 QDate dtStart( year, month, 1 ); 335 QDate dtStart( year, month, 1 );
336 d->mMonthEvents = db->getEffectiveEvents( dtStart, 336 d->mMonthEvents = db->getEffectiveEvents( dtStart,
337 QDate( year, month, 337 QDate( year, month,
338 dtStart.daysInMonth() ) ); 338 dtStart.daysInMonth() ) );
339 QValueListIterator<EffectiveEvent> it = d->mMonthEvents.begin(); 339 QValueListIterator<EffectiveEvent> it = d->mMonthEvents.begin();
340 // now that the events are sorted, basically go through the list, make 340 // now that the events are sorted, basically go through the list, make
341 // a small list for every day and set it for each item... 341 // a small list for every day and set it for each item...
342 // clear all the items... 342 // clear all the items...
343 while ( it != d->mMonthEvents.end() ) { 343 while ( it != d->mMonthEvents.end() ) {
344 QValueList<EffectiveEvent> dayEvent; 344 QValueList<EffectiveEvent> dayEvent;
345 EffectiveEvent e = *it; 345 EffectiveEvent e = *it;
346 ++it; 346 ++it;
347 dayEvent.append( e ); 347 dayEvent.append( e );
348 while ( it != d->mMonthEvents.end() 348 while ( it != d->mMonthEvents.end()
349 && e.date() == (*it).date() ) { 349 && e.date() == (*it).date() ) {
350 dayEvent.append( *it ); 350 dayEvent.append( *it );
351 ++it; 351 ++it;
352 } 352 }
353 int row, col; 353 int row, col;
354 findDay( e.date().day(), row, col ); 354 findDay( e.date().day(), row, col );
355 DayItemMonth* w = static_cast<DayItemMonth*>( item( row, col ) ); 355 DayItemMonth* w = static_cast<DayItemMonth*>( item( row, col ) );
356 w->setEvents( dayEvent ); 356 w->setEvents( dayEvent );
357 updateCell( row, col ); 357 updateCell( row, col );
358 dayEvent.clear(); 358 dayEvent.clear();
359 } 359 }
360} 360}
361 361
362 362
363void DateBookMonthTable::setupLabels() 363void DateBookMonthTable::setupLabels()
364{ 364{
365 for ( int i = 0; i < 7; ++i ) { 365 for ( int i = 0; i < 7; ++i ) {
366 // horizontalHeader()->resizeSection( i, 30 ); 366 // horizontalHeader()->resizeSection( i, 30 );
367 // setColumnStretchable( i, TRUE ); 367 // setColumnStretchable( i, TRUE );
368 if ( d->onMonday ) 368 if ( d->onMonday )
369 horizontalHeader()->setLabel( i, Calendar::nameOfDay( i + 1 ) ); 369 horizontalHeader()->setLabel( i, Calendar::nameOfDay( i + 1 ) );
370 else { 370 else {
371 if ( i == 0 ) 371 if ( i == 0 )
372 horizontalHeader()->setLabel( i, Calendar::nameOfDay( 7 ) ); 372 horizontalHeader()->setLabel( i, Calendar::nameOfDay( 7 ) );
373 else 373 else
374 horizontalHeader()->setLabel( i, Calendar::nameOfDay( i ) ); 374 horizontalHeader()->setLabel( i, Calendar::nameOfDay( i ) );
375 } 375 }
376 } 376 }
377} 377}
378 378
379 379
380//--------------------------------------------------------------------------- 380//---------------------------------------------------------------------------
381 381
382DateBookMonth::DateBookMonth( QWidget *parent, const char *name, bool ac, 382DateBookMonth::DateBookMonth( QWidget *parent, const char *name, bool ac,
383 DateBookDB *data ) 383 DateBookDB *data )
384 : QVBox( parent, name ), 384 : QVBox( parent, name ),
385 autoClose( ac ) 385 autoClose( ac )
386{ 386{
387 setFocusPolicy(StrongFocus); 387 setFocusPolicy(StrongFocus);
388 year = QDate::currentDate().year(); 388 year = QDate::currentDate().year();
389 month = QDate::currentDate().month(); 389 month = QDate::currentDate().month();
390 day = QDate::currentDate().day(); 390 day = QDate::currentDate().day();
391 header = new DateBookMonthHeader( this, "DateBookMonthHeader" ); 391 header = new DateBookMonthHeader( this, "DateBookMonthHeader" );
392 table = new DateBookMonthTable( this, "DateBookMonthTable", data ); 392 table = new DateBookMonthTable( this, "DateBookMonthTable", data );
393 header->setDate( year, month ); 393 header->setDate( year, month );
394 table->setDate( year, month, QDate::currentDate().day() ); 394 table->setDate( year, month, QDate::currentDate().day() );
395 header->setFocusPolicy(NoFocus); 395 header->setFocusPolicy(NoFocus);
396 table->setFocusPolicy(NoFocus); 396 table->setFocusPolicy(NoFocus);
397 connect( header, SIGNAL( dateChanged( int, int ) ), 397 connect( header, SIGNAL( dateChanged( int, int ) ),
398 this, SLOT( setDate( int, int ) ) ); 398 this, SLOT( setDate( int, int ) ) );
399 connect( table, SIGNAL( dateClicked( int, int, int ) ), 399 connect( table, SIGNAL( dateClicked( int, int, int ) ),
400 this, SLOT( finalDate(int, int, int) ) ); 400 this, SLOT( finalDate(int, int, int) ) );
401 connect( qApp, SIGNAL(weekChanged(bool)), this, 401 connect( qApp, SIGNAL(weekChanged(bool)), this,
402 SLOT(slotWeekChange(bool)) ); 402 SLOT(slotWeekChange(bool)) );
403 table->setFocus(); 403 table->setFocus();
404} 404}
405 405
406DateBookMonth::~DateBookMonth() 406DateBookMonth::~DateBookMonth()
407{ 407{
408 408
409} 409}
410 410
411void DateBookMonth::setDate( int y, int m ) 411void DateBookMonth::setDate( int y, int m )
412{ 412{
413 /* only change the date if this is a different date, 413 /* only change the date if this is a different date,
414 * other wise we may mistakenly overide the day */ 414 * other wise we may mistakenly overide the day */
415 if ( (y != year) || (m != month) ) { 415 if ( (y != year) || (m != month) ) {
416 year = y; 416 year = y;
417 month = m; 417 month = m;
418 QDate nd( y, m, 1 ); 418 QDate nd( y, m, 1 );
419 if ( nd.daysInMonth() < day ) 419 if ( nd.daysInMonth() < day )
420 day = nd.daysInMonth(); 420 day = nd.daysInMonth();
421 table->setDate( year, month, day ); 421 table->setDate( year, month, day );
422 } 422 }
423} 423}
424 424
425void DateBookMonth::setDate( int y, int m, int d ) 425void DateBookMonth::setDate( int y, int m, int d )
426{ 426{
427 header->setDate( y, m); 427 header->setDate( y, m);
428 table->setDate( y, m, d); 428 table->setDate( y, m, d);
429 year = y; 429 year = y;
430 month = m; 430 month = m;
431 day = d; 431 day = d;
432} 432}
433 433
434/* called when we wish to close or pass back the date */ 434/* called when we wish to close or pass back the date */
435void DateBookMonth::finalDate(int y, int m, int d) 435void DateBookMonth::finalDate(int y, int m, int d)
436{ 436{
437 setDate( y, m, d ); 437 setDate( y, m, d );
438 438
439 emit dateClicked(y, m, d); 439 emit dateClicked(y, m, d);
440 // emit dateClicked(QDate(y, m, d).toString()); 440 // emit dateClicked(QDate(y, m, d).toString());
441 441
442 if ( autoClose && parentWidget() ) 442 if ( autoClose && parentWidget() )
443 parentWidget()->close(); 443 parentWidget()->close();
444} 444}
445 445
446void DateBookMonth::setDate( QDate d) 446void DateBookMonth::setDate( QDate d)
447{ 447{
448 setDate(d.year(), d.month(), d.day()); 448 setDate(d.year(), d.month(), d.day());
449} 449}
450 450
451void DateBookMonth::redraw() 451void DateBookMonth::redraw()
452{ 452{
453 table->setDate( year, month, day ); 453 table->setDate( year, month, day );
454 table->redraw(); 454 table->redraw();
455} 455}
456 456
457QDate DateBookMonth::selectedDate() const 457QDate DateBookMonth::selectedDate() const
458{ 458{
459 if ( !table ) 459 if ( !table )
460 return QDate::currentDate(); 460 return QDate::currentDate();
461 int y, m, d; 461 int y, m, d;
462 table->getDate( y, m, d ); 462 table->getDate( y, m, d );
463 return QDate( y, m, d ); 463 return QDate( y, m, d );
464} 464}
465 465
466void DateBookMonth::slotWeekChange( bool startOnMonday ) 466void DateBookMonth::slotWeekChange( bool startOnMonday )
467{ 467{
468 table->setWeekStart( startOnMonday ); 468 table->setWeekStart( startOnMonday );
469} 469}
470 470
471void DateBookMonth::keyPressEvent( QKeyEvent *e ) 471void DateBookMonth::keyPressEvent( QKeyEvent *e )
472{ 472{
473 switch(e->key()) { 473 switch(e->key()) {
474 case Key_Up: 474 case Key_Up:
475 setDate(QDate(year, month, day).addDays(-7)); 475 setDate(QDate(year, month, day).addDays(-7));
476 break; 476 break;
477 case Key_Down: 477 case Key_Down:
478 setDate(QDate(year, month, day).addDays(7)); 478 setDate(QDate(year, month, day).addDays(7));
479 break; 479 break;
480 case Key_Left: 480 case Key_Left:
481 setDate(QDate(year, month, day).addDays(-1)); 481 setDate(QDate(year, month, day).addDays(-1));
482 break; 482 break;
483 case Key_Right: 483 case Key_Right:
484 setDate(QDate(year, month, day).addDays(1)); 484 setDate(QDate(year, month, day).addDays(1));
485 break; 485 break;
486 case Key_Space: 486 case Key_Space:
487 qWarning("space"); 487 qWarning("space");
488 emit dateClicked(year, month, day); 488 emit dateClicked(year, month, day);
489 if ( autoClose && parentWidget() ) 489 if ( autoClose && parentWidget() )
490 parentWidget()->close(); 490 parentWidget()->close();
491 break; 491 break;
492 default: 492 default:
493 qWarning("ignore"); 493 qWarning("ignore");
494 e->ignore(); 494 e->ignore();
495 break; 495 break;
496 } 496 }
497} 497}
498 498
499//--------------------------------------------------------------------------- 499//---------------------------------------------------------------------------
500class DayItemMonthPrivate 500class DayItemMonthPrivate
501{ 501{
502public: 502public:
503 DayItemMonthPrivate() {}; 503 DayItemMonthPrivate() {};
504 ~DayItemMonthPrivate() { mDayEvents.clear(); }; 504 ~DayItemMonthPrivate() { mDayEvents.clear(); };
505 QValueList<EffectiveEvent> mDayEvents; 505 QValueList<EffectiveEvent> mDayEvents;
506}; 506};
507 507
508DayItemMonth::DayItemMonth( QTable *table, EditType et, const QString &t ) 508DayItemMonth::DayItemMonth( QTable *table, EditType et, const QString &t )
509 : QTableItem( table, et, t ) 509 : QTableItem( table, et, t )
510{ 510{
511 d = new DayItemMonthPrivate(); 511 d = new DayItemMonthPrivate();
512} 512}
513 513
514DayItemMonth::~DayItemMonth() 514DayItemMonth::~DayItemMonth()
515{ 515{
516 daysEvents.clear(); 516 daysEvents.clear();
517 delete d; 517 delete d;
518} 518}
519 519
520void DayItemMonth::setEvents( const QValueList<EffectiveEvent> &effEv ) 520void DayItemMonth::setEvents( const QValueList<EffectiveEvent> &effEv )
521{ 521{
522 d->mDayEvents = effEv; 522 d->mDayEvents = effEv;
523} 523}
524 524
525void DayItemMonth::clearEffEvents() 525void DayItemMonth::clearEffEvents()
526{ 526{
527 d->mDayEvents.clear(); 527 d->mDayEvents.clear();
528} 528}
529 529
530void DayItemMonth::paint( QPainter *p, const QColorGroup &cg, 530void DayItemMonth::paint( QPainter *p, const QColorGroup &cg,
531 const QRect &cr, bool selected ) 531 const QRect &cr, bool selected )
532{ 532{
533 p->save(); 533 p->save();
534 534
535 QColorGroup g( cg ); 535 QColorGroup g( cg );
536 g.setBrush( QColorGroup::Base, back ); 536 g.setBrush( QColorGroup::Base, back );
537 g.setColor( QColorGroup::Text, forg ); 537 g.setColor( QColorGroup::Text, forg );
538 if ( selected ) 538 if ( selected )
539 p->setPen( g.highlightedText() ); 539 p->setPen( g.highlightedText() );
540 else 540 else
541 p->setPen( g.text() ); 541 p->setPen( g.text() );
542 542
543 QValueStack<int> normalLine; 543 QValueStack<int> normalLine;
544 QValueStack<int> repeatLine; 544 QValueStack<int> repeatLine;
545 QValueStack<int> travelLine; 545 QValueStack<int> travelLine;
546 546
547 bool normalAllDay = FALSE; 547 bool normalAllDay = FALSE;
548 bool repeatAllDay = FALSE; 548 bool repeatAllDay = FALSE;
549 bool travelAllDay = FALSE; 549 bool travelAllDay = FALSE;
550 550
551 QValueListIterator<EffectiveEvent> itDays = d->mDayEvents.begin(); 551 QValueListIterator<EffectiveEvent> itDays = d->mDayEvents.begin();
552 552
553 for ( ; itDays != d->mDayEvents.end(); ++itDays ) { 553 for ( ; itDays != d->mDayEvents.end(); ++itDays ) {
554 int w = cr.width(); 554 int w = cr.width();
555 Event ev = (*itDays).event(); 555 Event ev = (*itDays).event();
556 556
557 int f = (*itDays).start().hour(); // assume Effective event 557 int f = (*itDays).start().hour(); // assume Effective event
558 int t = (*itDays).end().hour(); // is truncated. 558 int t = (*itDays).end().hour(); // is truncated.
559 559
560 if (ev.isAllDay()) { 560 if (ev.isAllDay()) {
561 if (!ev.hasRepeat()) 561 if (!ev.hasRepeat())
562 normalAllDay = TRUE; 562 normalAllDay = TRUE;
563 else 563 else
564 repeatAllDay = TRUE; 564 repeatAllDay = TRUE;
565 } else { 565 } else {
566 int sLine, eLine; 566 int sLine, eLine;
567 if (f == 0) 567 if (f == 0)
568 sLine = 0; 568 sLine = 0;
569 else if (f < 8 ) 569 else if (f < 8 )
570 sLine = 1; 570 sLine = 1;
571 else if (f >= 17) 571 else if (f >= 17)
572 sLine = w - 4; 572 sLine = w - 4;
573 else { 573 else {
574 sLine = (f - 8) * (w - 8); 574 sLine = (f - 8) * (w - 8);
575 if (sLine) 575 if (sLine)
576 sLine /= 8; 576 sLine /= 8;
577 sLine += 4; 577 sLine += 4;
578 } 578 }
579 if (t == 23) 579 if (t == 23)
580 eLine = w; 580 eLine = w;
581 else if (t < 8) 581 else if (t < 8)
582 eLine = 4; 582 eLine = 4;
583 else if (t >= 17) 583 else if (t >= 17)
584 eLine = w - 1; 584 eLine = w - 1;
585 else { 585 else {
586 eLine = (t - 8) * (w - 8); 586 eLine = (t - 8) * (w - 8);
587 if (eLine) 587 if (eLine)
588 eLine /= 8; 588 eLine /= 8;
589 eLine += 4; 589 eLine += 4;
590 } 590 }
591 if (!ev.hasRepeat()) { 591 if (!ev.hasRepeat()) {
592 normalLine.push(sLine); 592 normalLine.push(sLine);
593 normalLine.push(eLine); 593 normalLine.push(eLine);
594 } else { 594 } else {
595 repeatLine.push(sLine); 595 repeatLine.push(sLine);
596 repeatLine.push(eLine); 596 repeatLine.push(eLine);
597 } 597 }
598 } 598 }
599 } 599 }
600 600
601 // draw the background 601 // draw the background
602 if (normalAllDay || repeatAllDay || travelAllDay) { 602 if (normalAllDay || repeatAllDay || travelAllDay) {
603 p->save(); 603 p->save();
604 604
605 if (normalAllDay) 605 if (normalAllDay)
606 if (repeatAllDay) { 606 if (repeatAllDay) {
607 p->fillRect( 0, 0, cr.width(), cr.height() / 2, 607 p->fillRect( 0, 0, cr.width(), cr.height() / 2,
608 colorNormalLight ); 608 colorNormalLight );
609 p->fillRect( 0, cr.height() / 2, cr.width(), cr.height() / 2, 609 p->fillRect( 0, cr.height() / 2, cr.width(), cr.height() / 2,
610 colorRepeatLight ); 610 colorRepeatLight );
611 } else 611 } else
612 p->fillRect( 0, 0, cr.width(), cr.height(), 612 p->fillRect( 0, 0, cr.width(), cr.height(),
613 colorNormalLight ); 613 colorNormalLight );
614 else if (repeatAllDay) 614 else if (repeatAllDay)
615 p->fillRect( 0, 0, cr.width(), cr.height(), 615 p->fillRect( 0, 0, cr.width(), cr.height(),
616 colorRepeatLight ); 616 colorRepeatLight );
617 } else { 617 } else {
618 p->fillRect( 0, 0, cr.width(), 618 p->fillRect( 0, 0, cr.width(),
619 cr.height(), selected 619 cr.height(), selected
620 ? g.brush( QColorGroup::Highlight ) 620 ? g.brush( QColorGroup::Highlight )
621 : g.brush( QColorGroup::Base ) ); 621 : g.brush( QColorGroup::Base ) );
622 } 622 }
623 623
624 // The lines 624 // The lines
625 // now for the lines. 625 // now for the lines.
626 int h = 5; 626 int h = 5;
627 int y = cr.height() / 2 - h; 627 int y = cr.height() / 2 - h;
628 628
629 while(normalLine.count() >= 2) { 629 while(normalLine.count() >= 2) {
630 int x2 = normalLine.pop(); 630 int x2 = normalLine.pop();
631 int x1 = normalLine.pop(); 631 int x1 = normalLine.pop();
632 if (x2 < x1 + 2) 632 if (x2 < x1 + 2)
633 x2 = x1 + 2; 633 x2 = x1 + 2;
634 p->fillRect(x1, y, x2 - x1, h, colorNormal); 634 p->fillRect(x1, y, x2 - x1, h, colorNormal);
635 } 635 }
636 636
637 y += h; 637 y += h;
638 638
639 while(repeatLine.count() >= 2) { 639 while(repeatLine.count() >= 2) {
640 int x2 = repeatLine.pop(); 640 int x2 = repeatLine.pop();
641 int x1 = repeatLine.pop(); 641 int x1 = repeatLine.pop();
642 if (x2 < x1 + 2) 642 if (x2 < x1 + 2)
643 x2 = x1 + 2; 643 x2 = x1 + 2;
644 p->fillRect(x1, y, x2 - x1, h, colorRepeat); 644 p->fillRect(x1, y, x2 - x1, h, colorRepeat);
645 } 645 }
646 646
647 647
648 // Finally, draw the number. 648 // Finally, draw the number.
649 QFont f = p->font(); 649 QFont f = p->font();
650 f.setPointSize( ( f.pointSize() / 3 ) * 2 ); 650 f.setPointSize( ( f.pointSize() / 3 ) * 2 );
651 p->setFont( f ); 651 p->setFont( f );
652 QFontMetrics fm( f ); 652 QFontMetrics fm( f );
653 p->drawText( 1, 1 + fm.ascent(), QString::number( day() ) ); 653 p->drawText( 1, 1 + fm.ascent(), QString::number( day() ) );
654 654
655 p->restore(); 655 p->restore();
656} 656}
657 657
658 658
659 659
660void DayItemMonth::setType( Calendar::Day::Type t ) 660void DayItemMonth::setType( Calendar::Day::Type t )
661{ 661{
662 switch ( t ) { 662 switch ( t ) {
663 case Calendar::Day::PrevMonth: 663 case Calendar::Day::PrevMonth:
664 case Calendar::Day::NextMonth: 664 case Calendar::Day::NextMonth:
665 back = QBrush( QColor( 224, 224, 224 ) ); 665 back = QBrush( QColor( 224, 224, 224 ) );
666 forg = black; 666 forg = black;
667 break; 667 break;
668 case Calendar::Day::ThisMonth: 668 case Calendar::Day::ThisMonth:
669 back = QBrush( white ); 669 back = QBrush( white );
670 forg = black; 670 forg = black;
671 break; 671 break;
672 } 672 }
673 typ = t; 673 typ = t;
674} 674}
675 675
676 676
677 677
678DateButton::DateButton( bool longDate, QWidget *parent, const char * name ) 678DateButton::DateButton( bool longDate, QWidget *parent, const char * name )
679 :QPushButton( parent, name ) 679 :QPushButton( parent, name )
680{ 680{
681 longFormat = longDate; 681 longFormat = longDate;
682 df = DateFormat('/', DateFormat::MonthDayYear, DateFormat::MonthDayYear); 682 df = DateFormat('/', DateFormat::MonthDayYear, DateFormat::MonthDayYear);
683 setDate( QDate::currentDate() ); 683 setDate( QDate::currentDate() );
684 684
685 connect(this,SIGNAL(pressed()),this,SLOT(pickDate())); 685 connect(this,SIGNAL(pressed()),this,SLOT(pickDate()));
686 686
687 687
688} 688}
689 689
690 690
691void DateButton::pickDate() 691void DateButton::pickDate()
692{ 692{
693 static QPopupMenu *m1 = 0; 693 static QPopupMenu *m1 = 0;
694 static DateBookMonth *picker = 0; 694 static DateBookMonth *picker = 0;
695 if ( !m1 ) { 695 if ( !m1 ) {
696 m1 = new QPopupMenu( this ); 696 m1 = new QPopupMenu( this );
697 picker = new DateBookMonth( m1, 0, TRUE ); 697 picker = new DateBookMonth( m1, 0, TRUE );
698 m1->insertItem( picker ); 698 m1->insertItem( picker );
699 connect( picker, SIGNAL( dateClicked( int, int, int ) ), 699 connect( picker, SIGNAL( dateClicked( int, int, int ) ),
700 this, SLOT( setDate( int, int, int ) ) ); 700 this, SLOT( setDate( int, int, int ) ) );
701 connect( picker, SIGNAL( dateClicked( int, int, int ) ), 701 connect( picker, SIGNAL( dateClicked( int, int, int ) ),
702 this, SIGNAL( dateSelected( int, int, int ) ) ); 702 this, SIGNAL( dateSelected( int, int, int ) ) );
703 connect( m1, SIGNAL( aboutToHide() ), 703 connect( m1, SIGNAL( aboutToHide() ),
704 this, SLOT( gotHide() ) ); 704 this, SLOT( gotHide() ) );
705 } 705 }
706 picker->slotWeekChange( weekStartsMonday ); 706 picker->slotWeekChange( weekStartsMonday );
707 picker->setDate( currDate.year(), currDate.month(), currDate.day() ); 707 picker->setDate( currDate.year(), currDate.month(), currDate.day() );
708 m1->popup(mapToGlobal(QPoint(0,height()))); 708 m1->popup(mapToGlobal(QPoint(0,height())));
709 picker->setFocus(); 709 picker->setFocus();
710} 710}
711 711
712 712
713void DateButton::gotHide() 713void DateButton::gotHide()
714{ 714{
715 // we have to redo the button... 715 // we have to redo the button...
716 setDown( false ); 716 setDown( false );
717} 717}
718 718
719 719
720// void dateSelected( int year, int month, int day ); 720// void dateSelected( int year, int month, int day );
721 721
722void DateButton::setWeekStartsMonday( int b ) 722void DateButton::setWeekStartsMonday( int b )
723{ 723{
724 weekStartsMonday = b; 724 weekStartsMonday = b;
725} 725}
726 726
727void DateButton::setDate( int y, int m, int d ) 727void DateButton::setDate( int y, int m, int d )
728{ 728{
729 setDate( QDate( y,m,d) ); 729 setDate( QDate( y,m,d) );
730} 730}
731 731
732void DateButton::setDate( QDate d ) 732void DateButton::setDate( QDate d )
733{ 733{
734 currDate = d; 734 currDate = d;
735 setText( longFormat ? TimeString::longDateString( d, df ) : 735 setText( longFormat ? TimeString::longDateString( d, df ) :
736 TimeString::shortDate( d, df ) ); 736 TimeString::shortDate( d, df ) );
737 737
738} 738}
739 739
740void DateButton::setDateFormat( DateFormat f ) 740void DateButton::setDateFormat( DateFormat f )
741{ 741{
742 df = f; 742 df = f;
743 setDate( currDate ); 743 setDate( currDate );
744} 744}
745 745
746bool DateButton::customWhatsThis() const 746bool DateButton::customWhatsThis() const
747{ 747{
748 return TRUE; 748 return TRUE;
749} 749}
750 750
diff --git a/library/fileselector.cpp b/library/fileselector.cpp
index 7ff09b4..052a29e 100644
--- a/library/fileselector.cpp
+++ b/library/fileselector.cpp
@@ -1,583 +1,583 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21// WARNING: Do *NOT* define this yourself. The SL5xxx from SHARP does NOT 21// WARNING: Do *NOT* define this yourself. The SL5xxx from SHARP does NOT
22// have this class. 22// have this class.
23#define QTOPIA_INTERNAL_FSLP 23#define QTOPIA_INTERNAL_FSLP
24 24
25#include "fileselector.h" 25#include "fileselector.h"
26#include "fileselector_p.h" 26#include "fileselector_p.h"
27#include "global.h" 27#include "global.h"
28#include "resource.h" 28#include "resource.h"
29#include "config.h" 29#include "config.h"
30#include "applnk.h" 30#include "applnk.h"
31#include "storage.h" 31#include "storage.h"
32#include "qpemenubar.h" 32#include "qpemenubar.h"
33#ifdef QWS 33#ifdef QWS
34#include "qcopchannel_qws.h" 34#include <qcopchannel_qws.h>
35#endif 35#endif
36#include "lnkproperties.h" 36#include "lnkproperties.h"
37#include "applnk.h" 37#include "applnk.h"
38#include "qpeapplication.h" 38#include <qpe/qpeapplication.h>
39#include "categorymenu.h" 39#include "categorymenu.h"
40#include "categoryselect.h" 40#include "categoryselect.h"
41#include "mimetype.h" 41#include "mimetype.h"
42#include "categories.h" 42#include <qpe/categories.h>
43 43
44#include <stdlib.h> 44#include <stdlib.h>
45 45
46#include <qdir.h> 46#include <qdir.h>
47#include <qwidget.h> 47#include <qwidget.h>
48#include <qpopupmenu.h> 48#include <qpopupmenu.h>
49#include <qtoolbutton.h> 49#include <qtoolbutton.h>
50#include <qpushbutton.h> 50#include <qpushbutton.h>
51#include <qheader.h> 51#include <qheader.h>
52#include <qtooltip.h> 52#include <qtooltip.h>
53#include <qwhatsthis.h> 53#include <qwhatsthis.h>
54 54
55class TypeCombo : public QComboBox 55class TypeCombo : public QComboBox
56{ 56{
57 Q_OBJECT 57 Q_OBJECT
58public: 58public:
59 TypeCombo( QWidget *parent, const char *name=0 ) 59 TypeCombo( QWidget *parent, const char *name=0 )
60 : QComboBox( parent, name ) 60 : QComboBox( parent, name )
61 { 61 {
62 connect( this, SIGNAL(activated(int)), this, SLOT(selectType(int)) ); 62 connect( this, SIGNAL(activated(int)), this, SLOT(selectType(int)) );
63 } 63 }
64 64
65 void reread( DocLnkSet &files, const QString &filter ); 65 void reread( DocLnkSet &files, const QString &filter );
66 66
67signals: 67signals:
68 void selected( const QString & ); 68 void selected( const QString & );
69 69
70protected slots: 70protected slots:
71 void selectType( int idx ) { 71 void selectType( int idx ) {
72 emit selected( typelist[idx] ); 72 emit selected( typelist[idx] );
73 } 73 }
74 74
75protected: 75protected:
76 QStringList typelist; 76 QStringList typelist;
77 QString prev; 77 QString prev;
78}; 78};
79 79
80void TypeCombo::reread( DocLnkSet &files, const QString &filter ) 80void TypeCombo::reread( DocLnkSet &files, const QString &filter )
81{ 81{
82 typelist.clear(); 82 typelist.clear();
83 QStringList filters = QStringList::split( ';', filter ); 83 QStringList filters = QStringList::split( ';', filter );
84 int pos = filter.find( '/' ); 84 int pos = filter.find( '/' );
85 //### do for each filter 85 //### do for each filter
86 if ( filters.count() == 1 && pos >= 0 && filter[pos+1] != '*' ) { 86 if ( filters.count() == 1 && pos >= 0 && filter[pos+1] != '*' ) {
87 typelist.append( filter ); 87 typelist.append( filter );
88 clear(); 88 clear();
89 QString minor = filter.mid( pos+1 ); 89 QString minor = filter.mid( pos+1 );
90 minor[0] = minor[0].upper(); 90 minor[0] = minor[0].upper();
91 insertItem( tr("%1 files").arg(minor) ); 91 insertItem( tr("%1 files").arg(minor) );
92 setCurrentItem(0); 92 setCurrentItem(0);
93 setEnabled( FALSE ); 93 setEnabled( FALSE );
94 return; 94 return;
95 } 95 }
96 96
97 QListIterator<DocLnk> dit( files.children() ); 97 QListIterator<DocLnk> dit( files.children() );
98 for ( ; dit.current(); ++dit ) { 98 for ( ; dit.current(); ++dit ) {
99 if ( !typelist.contains( (*dit)->type() ) ) 99 if ( !typelist.contains( (*dit)->type() ) )
100 typelist.append( (*dit)->type() ); 100 typelist.append( (*dit)->type() );
101 } 101 }
102 102
103 QStringList types; 103 QStringList types;
104 QStringList::ConstIterator it; 104 QStringList::ConstIterator it;
105 for (it = typelist.begin(); it!=typelist.end(); ++it) { 105 for (it = typelist.begin(); it!=typelist.end(); ++it) {
106 QString t = *it; 106 QString t = *it;
107 if ( t.left(12) == "application/" ) { 107 if ( t.left(12) == "application/" ) {
108 MimeType mt(t); 108 MimeType mt(t);
109 const AppLnk* app = mt.application(); 109 const AppLnk* app = mt.application();
110 if ( app ) 110 if ( app )
111 t = app->name(); 111 t = app->name();
112 else 112 else
113 t = t.mid(12); 113 t = t.mid(12);
114 } else { 114 } else {
115 QString major, minor; 115 QString major, minor;
116 int pos = t.find( '/' ); 116 int pos = t.find( '/' );
117 if ( pos >= 0 ) { 117 if ( pos >= 0 ) {
118 major = t.left( pos ); 118 major = t.left( pos );
119 minor = t.mid( pos+1 ); 119 minor = t.mid( pos+1 );
120 } 120 }
121 if ( minor.find( "x-" ) == 0 ) 121 if ( minor.find( "x-" ) == 0 )
122 minor = minor.mid( 2 ); 122 minor = minor.mid( 2 );
123 minor[0] = minor[0].upper(); 123 minor[0] = minor[0].upper();
124 major[0] = major[0].upper(); 124 major[0] = major[0].upper();
125 if ( filters.count() > 1 ) 125 if ( filters.count() > 1 )
126 t = tr("%1 %2", "minor mimetype / major mimetype").arg(minor).arg(major); 126 t = tr("%1 %2", "minor mimetype / major mimetype").arg(minor).arg(major);
127 else 127 else
128 t = minor; 128 t = minor;
129 } 129 }
130 types += tr("%1 files").arg(t); 130 types += tr("%1 files").arg(t);
131 } 131 }
132 for (it = filters.begin(); it!=filters.end(); ++it) { 132 for (it = filters.begin(); it!=filters.end(); ++it) {
133 typelist.append( *it ); 133 typelist.append( *it );
134 int pos = (*it).find( '/' ); 134 int pos = (*it).find( '/' );
135 if ( pos >= 0 ) { 135 if ( pos >= 0 ) {
136 QString maj = (*it).left( pos ); 136 QString maj = (*it).left( pos );
137 maj[0] = maj[0].upper(); 137 maj[0] = maj[0].upper();
138 types << tr("All %1 files").arg(maj); 138 types << tr("All %1 files").arg(maj);
139 } 139 }
140 } 140 }
141 if ( filters.count() > 1 ) { 141 if ( filters.count() > 1 ) {
142 typelist.append( filter ); 142 typelist.append( filter );
143 types << tr("All files"); 143 types << tr("All files");
144 } 144 }
145 prev = currentText(); 145 prev = currentText();
146 clear(); 146 clear();
147 insertStringList(types); 147 insertStringList(types);
148 for (int i=0; i<count(); i++) { 148 for (int i=0; i<count(); i++) {
149 if ( text(i) == prev ) { 149 if ( text(i) == prev ) {
150 setCurrentItem(i); 150 setCurrentItem(i);
151 break; 151 break;
152 } 152 }
153 } 153 }
154 if ( prev.isNull() ) 154 if ( prev.isNull() )
155 setCurrentItem(count()-1); 155 setCurrentItem(count()-1);
156 setEnabled( TRUE ); 156 setEnabled( TRUE );
157} 157}
158 158
159 159
160//=========================================================================== 160//===========================================================================
161 161
162FileSelectorItem::FileSelectorItem( QListView *parent, const DocLnk &f ) 162FileSelectorItem::FileSelectorItem( QListView *parent, const DocLnk &f )
163 : QListViewItem( parent ), fl( f ) 163 : QListViewItem( parent ), fl( f )
164{ 164{
165 setText( 0, f.name() ); 165 setText( 0, f.name() );
166 setPixmap( 0, f.pixmap() ); 166 setPixmap( 0, f.pixmap() );
167} 167}
168 168
169FileSelectorItem::~FileSelectorItem() 169FileSelectorItem::~FileSelectorItem()
170{ 170{
171} 171}
172 172
173FileSelectorView::FileSelectorView( QWidget *parent, const char *name ) 173FileSelectorView::FileSelectorView( QWidget *parent, const char *name )
174 : QListView( parent, name ) 174 : QListView( parent, name )
175{ 175{
176 setAllColumnsShowFocus( TRUE ); 176 setAllColumnsShowFocus( TRUE );
177 addColumn( tr( "Name" ) ); 177 addColumn( tr( "Name" ) );
178 header()->hide(); 178 header()->hide();
179} 179}
180 180
181FileSelectorView::~FileSelectorView() 181FileSelectorView::~FileSelectorView()
182{ 182{
183} 183}
184 184
185void FileSelectorView::keyPressEvent( QKeyEvent *e ) 185void FileSelectorView::keyPressEvent( QKeyEvent *e )
186{ 186{
187 QString txt = e->text(); 187 QString txt = e->text();
188 if (e->key() == Key_Space) 188 if (e->key() == Key_Space)
189 emit returnPressed( currentItem() ); 189 emit returnPressed( currentItem() );
190 else if ( !txt.isNull() && txt[0] > ' ' && e->key() < 0x1000 ) 190 else if ( !txt.isNull() && txt[0] > ' ' && e->key() < 0x1000 )
191 e->ignore(); 191 e->ignore();
192 else 192 else
193 QListView::keyPressEvent(e); 193 QListView::keyPressEvent(e);
194} 194}
195 195
196class NewDocItem : public FileSelectorItem 196class NewDocItem : public FileSelectorItem
197{ 197{
198public: 198public:
199 NewDocItem( QListView *parent, const DocLnk &f ) 199 NewDocItem( QListView *parent, const DocLnk &f )
200 : FileSelectorItem( parent, f ) { 200 : FileSelectorItem( parent, f ) {
201 setText( 0, QObject::tr("New Document") ); 201 setText( 0, QObject::tr("New Document") );
202 QImage img( Resource::loadImage( "new" ) ); 202 QImage img( Resource::loadImage( "new" ) );
203 QPixmap pm; 203 QPixmap pm;
204 pm = img.smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ); 204 pm = img.smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() );
205 setPixmap( 0, pm ); 205 setPixmap( 0, pm );
206 } 206 }
207 QString key ( int, bool ) const { 207 QString key ( int, bool ) const {
208 return QString("\n"); 208 return QString("\n");
209 } 209 }
210 210
211 void paintCell( QPainter *p, const QColorGroup &cg, int column, int width, int alignment ) { 211 void paintCell( QPainter *p, const QColorGroup &cg, int column, int width, int alignment ) {
212 QFont oldFont = p->font(); 212 QFont oldFont = p->font();
213 QFont newFont = p->font(); 213 QFont newFont = p->font();
214 newFont.setWeight( QFont::Bold ); 214 newFont.setWeight( QFont::Bold );
215 p->setFont( newFont ); 215 p->setFont( newFont );
216 FileSelectorItem::paintCell( p, cg, column, width, alignment ); 216 FileSelectorItem::paintCell( p, cg, column, width, alignment );
217 p->setFont( oldFont ); 217 p->setFont( oldFont );
218 } 218 }
219 219
220 int width( const QFontMetrics &fm, const QListView *v, int c ) const { 220 int width( const QFontMetrics &fm, const QListView *v, int c ) const {
221 return FileSelectorItem::width( fm, v, c )*4/3; // allow for bold font 221 return FileSelectorItem::width( fm, v, c )*4/3; // allow for bold font
222 } 222 }
223}; 223};
224 224
225//=========================================================================== 225//===========================================================================
226 226
227class FileSelectorPrivate 227class FileSelectorPrivate
228{ 228{
229public: 229public:
230 TypeCombo *typeCombo; 230 TypeCombo *typeCombo;
231 CategorySelect *catSelect; 231 CategorySelect *catSelect;
232 QValueList<QRegExp> mimeFilters; 232 QValueList<QRegExp> mimeFilters;
233 int catId; 233 int catId;
234 bool showNew; 234 bool showNew;
235 NewDocItem *newDocItem; 235 NewDocItem *newDocItem;
236 DocLnkSet files; 236 DocLnkSet files;
237 QHBox *toolbar; 237 QHBox *toolbar;
238}; 238};
239 239
240/*! 240/*!
241 \class FileSelector fileselector.h 241 \class FileSelector fileselector.h
242 \brief The FileSelector widget allows the user to select DocLnk objects. 242 \brief The FileSelector widget allows the user to select DocLnk objects.
243 243
244 This class presents a file selection dialog to the user. This widget 244 This class presents a file selection dialog to the user. This widget
245 is usually the first widget seen in a \link docwidget.html 245 is usually the first widget seen in a \link docwidget.html
246 document-oriented application\endlink. The developer will most often 246 document-oriented application\endlink. The developer will most often
247 create this widget in combination with a <a 247 create this widget in combination with a <a
248 href="../qt/qwidgetstack.html"> QWidgetStack</a> and the appropriate 248 href="../qt/qwidgetstack.html"> QWidgetStack</a> and the appropriate
249 editor and/or viewer widget for their application. This widget 249 editor and/or viewer widget for their application. This widget
250 should be shown first and the user can the select which document 250 should be shown first and the user can the select which document
251 they wish to operate on. Please refer to the implementation of 251 they wish to operate on. Please refer to the implementation of
252 texteditor for an example of how to tie these classes together. 252 texteditor for an example of how to tie these classes together.
253 253
254 Use setNewVisible() depending on whether the application can be used 254 Use setNewVisible() depending on whether the application can be used
255 to create new files or not. Use setCloseVisible() depending on 255 to create new files or not. Use setCloseVisible() depending on
256 whether the user may leave the dialog without creating or selecting 256 whether the user may leave the dialog without creating or selecting
257 a document or not. The number of files in the view is available from 257 a document or not. The number of files in the view is available from
258 fileCount(). To force the view to be updated call reread(). 258 fileCount(). To force the view to be updated call reread().
259 259
260 If the user presses the 'New Document' button the newSelected() 260 If the user presses the 'New Document' button the newSelected()
261 signal is emitted. If the user selects an existing file the 261 signal is emitted. If the user selects an existing file the
262 fileSelected() signal is emitted. The selected file's \link 262 fileSelected() signal is emitted. The selected file's \link
263 doclnk.html DocLnk\endlink is available from the selected() 263 doclnk.html DocLnk\endlink is available from the selected()
264 function. If the file selector is no longer necessary the closeMe() 264 function. If the file selector is no longer necessary the closeMe()
265 signal is emitted. 265 signal is emitted.
266 266
267 \ingroup qtopiaemb 267 \ingroup qtopiaemb
268 \sa FileManager 268 \sa FileManager
269*/ 269*/
270 270
271/*! 271/*!
272 Constructs a FileSelector with mime filter \a f. 272 Constructs a FileSelector with mime filter \a f.
273 The standard Qt \a parent and \a name parameters are passed to the 273 The standard Qt \a parent and \a name parameters are passed to the
274 parent widget. 274 parent widget.
275 275
276 If \a newVisible is TRUE, the widget has a button to allow the user 276 If \a newVisible is TRUE, the widget has a button to allow the user
277 the create "new" documents; this is useful for applications that can 277 the create "new" documents; this is useful for applications that can
278 create and edit documents but not suitable for applications that 278 create and edit documents but not suitable for applications that
279 only provide viewing. 279 only provide viewing.
280 280
281 \a closeVisible is deprecated 281 \a closeVisible is deprecated
282 282
283 \sa DocLnkSet::DocLnkSet() 283 \sa DocLnkSet::DocLnkSet()
284*/ 284*/
285FileSelector::FileSelector( const QString &f, QWidget *parent, const char *name, bool newVisible, bool closeVisible ) 285FileSelector::FileSelector( const QString &f, QWidget *parent, const char *name, bool newVisible, bool closeVisible )
286 : QVBox( parent, name ), filter( f ) 286 : QVBox( parent, name ), filter( f )
287{ 287{
288 setMargin( 0 ); 288 setMargin( 0 );
289 setSpacing( 0 ); 289 setSpacing( 0 );
290 290
291 d = new FileSelectorPrivate(); 291 d = new FileSelectorPrivate();
292 d->newDocItem = 0; 292 d->newDocItem = 0;
293 d->showNew = newVisible; 293 d->showNew = newVisible;
294 d->catId = -2; // All files 294 d->catId = -2; // All files
295 295
296 d->toolbar = new QHBox( this ); 296 d->toolbar = new QHBox( this );
297 d->toolbar->setBackgroundMode( PaletteButton ); // same colour as toolbars 297 d->toolbar->setBackgroundMode( PaletteButton ); // same colour as toolbars
298 d->toolbar->setSpacing( 0 ); 298 d->toolbar->setSpacing( 0 );
299 d->toolbar->hide(); 299 d->toolbar->hide();
300 300
301 QWidget *spacer = new QWidget( d->toolbar ); 301 QWidget *spacer = new QWidget( d->toolbar );
302 spacer->setBackgroundMode( PaletteButton ); 302 spacer->setBackgroundMode( PaletteButton );
303 303
304 QToolButton *tb = new QToolButton( d->toolbar ); 304 QToolButton *tb = new QToolButton( d->toolbar );
305 tb->setPixmap( Resource::loadPixmap( "close" ) ); 305 tb->setPixmap( Resource::loadPixmap( "close" ) );
306 connect( tb, SIGNAL( clicked() ), this, SIGNAL( closeMe() ) ); 306 connect( tb, SIGNAL( clicked() ), this, SIGNAL( closeMe() ) );
307 buttonClose = tb; 307 buttonClose = tb;
308 tb->setFixedSize( 18, 20 ); // tb->sizeHint() ); 308 tb->setFixedSize( 18, 20 ); // tb->sizeHint() );
309 tb->setAutoRaise( TRUE ); 309 tb->setAutoRaise( TRUE );
310 QToolTip::add( tb, tr( "Close the File Selector" ) ); 310 QToolTip::add( tb, tr( "Close the File Selector" ) );
311 QPEMenuToolFocusManager::manager()->addWidget( tb ); 311 QPEMenuToolFocusManager::manager()->addWidget( tb );
312 312
313 view = new FileSelectorView( this, "fileview" ); 313 view = new FileSelectorView( this, "fileview" );
314 QPEApplication::setStylusOperation( view->viewport(), QPEApplication::RightOnHold ); 314 QPEApplication::setStylusOperation( view->viewport(), QPEApplication::RightOnHold );
315 connect( view, SIGNAL( mouseButtonClicked( int, QListViewItem *, const QPoint &, int ) ), 315 connect( view, SIGNAL( mouseButtonClicked( int, QListViewItem *, const QPoint &, int ) ),
316 this, SLOT( fileClicked( int, QListViewItem *, const QPoint &, int ) ) ); 316 this, SLOT( fileClicked( int, QListViewItem *, const QPoint &, int ) ) );
317 connect( view, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint &, int ) ), 317 connect( view, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint &, int ) ),
318 this, SLOT( filePressed( int, QListViewItem *, const QPoint &, int ) ) ); 318 this, SLOT( filePressed( int, QListViewItem *, const QPoint &, int ) ) );
319 connect( view, SIGNAL( returnPressed( QListViewItem * ) ), 319 connect( view, SIGNAL( returnPressed( QListViewItem * ) ),
320 this, SLOT( fileClicked( QListViewItem * ) ) ); 320 this, SLOT( fileClicked( QListViewItem * ) ) );
321 321
322 QHBox *hb = new QHBox( this ); 322 QHBox *hb = new QHBox( this );
323 323
324 d->typeCombo = new TypeCombo( hb ); 324 d->typeCombo = new TypeCombo( hb );
325 connect( d->typeCombo, SIGNAL(selected(const QString&)), 325 connect( d->typeCombo, SIGNAL(selected(const QString&)),
326 this, SLOT(typeSelected(const QString&)) ); 326 this, SLOT(typeSelected(const QString&)) );
327 QWhatsThis::add( d->typeCombo, tr("Show documents of this type") ); 327 QWhatsThis::add( d->typeCombo, tr("Show documents of this type") );
328 328
329 Categories c; 329 Categories c;
330 c.load(categoryFileName()); 330 c.load(categoryFileName());
331 QArray<int> vl( 0 ); 331 QArray<int> vl( 0 );
332 d->catSelect = new CategorySelect( hb ); 332 d->catSelect = new CategorySelect( hb );
333 d->catSelect->setRemoveCategoryEdit( TRUE ); 333 d->catSelect->setRemoveCategoryEdit( TRUE );
334 d->catSelect->setCategories( vl, "Document View", tr("Document View") ); 334 d->catSelect->setCategories( vl, "Document View", tr("Document View") );
335 d->catSelect->setAllCategories( TRUE ); 335 d->catSelect->setAllCategories( TRUE );
336 connect( d->catSelect, SIGNAL(signalSelected(int)), this, SLOT(catSelected(int)) ); 336 connect( d->catSelect, SIGNAL(signalSelected(int)), this, SLOT(catSelected(int)) );
337 QWhatsThis::add( d->catSelect, tr("Show documents in this category") ); 337 QWhatsThis::add( d->catSelect, tr("Show documents in this category") );
338 338
339 setCloseVisible( closeVisible ); 339 setCloseVisible( closeVisible );
340 340
341 QCopChannel *channel = new QCopChannel( "QPE/Card", this ); 341 QCopChannel *channel = new QCopChannel( "QPE/Card", this );
342 connect( channel, SIGNAL(received(const QCString &, const QByteArray &)), 342 connect( channel, SIGNAL(received(const QCString &, const QByteArray &)),
343 this, SLOT(cardMessage( const QCString &, const QByteArray &)) ); 343 this, SLOT(cardMessage( const QCString &, const QByteArray &)) );
344 344
345 reread(); 345 reread();
346 updateWhatsThis(); 346 updateWhatsThis();
347} 347}
348 348
349/*! 349/*!
350 Destroys the widget. 350 Destroys the widget.
351*/ 351*/
352FileSelector::~FileSelector() 352FileSelector::~FileSelector()
353{ 353{
354 delete d; 354 delete d;
355} 355}
356 356
357/*! 357/*!
358 Returns the number of files in the view. If this is zero, an editor 358 Returns the number of files in the view. If this is zero, an editor
359 application might bypass the selector and immediately start with 359 application might bypass the selector and immediately start with
360 a "new" document. 360 a "new" document.
361*/ 361*/
362int FileSelector::fileCount() 362int FileSelector::fileCount()
363{ 363{
364 return d->files.children().count();; 364 return d->files.children().count();;
365} 365}
366 366
367/*! 367/*!
368 Calling this function is the programmatic equivalent of the user 368 Calling this function is the programmatic equivalent of the user
369 pressing the "new" button. 369 pressing the "new" button.
370 370
371 \sa newSelected(), closeMe() 371 \sa newSelected(), closeMe()
372*/ 372*/
373void FileSelector::createNew() 373void FileSelector::createNew()
374{ 374{
375 DocLnk f; 375 DocLnk f;
376 emit newSelected( f ); 376 emit newSelected( f );
377 emit closeMe(); 377 emit closeMe();
378} 378}
379 379
380void FileSelector::fileClicked( int button, QListViewItem *i, const QPoint &, int ) 380void FileSelector::fileClicked( int button, QListViewItem *i, const QPoint &, int )
381{ 381{
382 if ( !i ) 382 if ( !i )
383 return; 383 return;
384 if ( button == Qt::LeftButton ) { 384 if ( button == Qt::LeftButton ) {
385 fileClicked( i ); 385 fileClicked( i );
386 } 386 }
387} 387}
388 388
389void FileSelector::filePressed( int button, QListViewItem *i, const QPoint &, int ) 389void FileSelector::filePressed( int button, QListViewItem *i, const QPoint &, int )
390{ 390{
391 if ( !i || i == d->newDocItem ) 391 if ( !i || i == d->newDocItem )
392 return; 392 return;
393 if ( button == Qt::RightButton ) { 393 if ( button == Qt::RightButton ) {
394 DocLnk l = ((FileSelectorItem *)i)->file(); 394 DocLnk l = ((FileSelectorItem *)i)->file();
395 LnkProperties prop( &l ); 395 LnkProperties prop( &l );
396 prop.showMaximized(); 396 prop.showMaximized();
397 prop.exec(); 397 prop.exec();
398 reread(); 398 reread();
399 } 399 }
400} 400}
401 401
402void FileSelector::fileClicked( QListViewItem *i ) 402void FileSelector::fileClicked( QListViewItem *i )
403{ 403{
404 if ( !i ) 404 if ( !i )
405 return; 405 return;
406 if ( i == d->newDocItem ) { 406 if ( i == d->newDocItem ) {
407 createNew(); 407 createNew();
408 } else { 408 } else {
409 emit fileSelected( ( (FileSelectorItem*)i )->file() ); 409 emit fileSelected( ( (FileSelectorItem*)i )->file() );
410 emit closeMe(); 410 emit closeMe();
411 } 411 }
412} 412}
413 413
414void FileSelector::typeSelected( const QString &type ) 414void FileSelector::typeSelected( const QString &type )
415{ 415{
416 d->mimeFilters.clear(); 416 d->mimeFilters.clear();
417 QStringList subFilter = QStringList::split(";", type); 417 QStringList subFilter = QStringList::split(";", type);
418 for( QStringList::Iterator it = subFilter.begin(); it != subFilter.end(); ++it ) 418 for( QStringList::Iterator it = subFilter.begin(); it != subFilter.end(); ++it )
419 d->mimeFilters.append( QRegExp(*it, FALSE, TRUE) ); 419 d->mimeFilters.append( QRegExp(*it, FALSE, TRUE) );
420 updateView(); 420 updateView();
421} 421}
422 422
423void FileSelector::catSelected( int c ) 423void FileSelector::catSelected( int c )
424{ 424{
425 d->catId = c; 425 d->catId = c;
426 updateView(); 426 updateView();
427} 427}
428 428
429void FileSelector::cardMessage( const QCString &msg, const QByteArray &) 429void FileSelector::cardMessage( const QCString &msg, const QByteArray &)
430{ 430{
431 if ( msg == "mtabChanged()" ) 431 if ( msg == "mtabChanged()" )
432 reread(); 432 reread();
433} 433}
434 434
435 435
436/*! 436/*!
437 Returns the selected \link doclnk.html DocLnk\endlink. The caller is 437 Returns the selected \link doclnk.html DocLnk\endlink. The caller is
438 responsible for deleting the returned value. 438 responsible for deleting the returned value.
439*/ 439*/
440const DocLnk *FileSelector::selected() 440const DocLnk *FileSelector::selected()
441{ 441{
442 FileSelectorItem *item = (FileSelectorItem *)view->selectedItem(); 442 FileSelectorItem *item = (FileSelectorItem *)view->selectedItem();
443 if ( item && item != d->newDocItem ) 443 if ( item && item != d->newDocItem )
444 return new DocLnk( item->file() ); 444 return new DocLnk( item->file() );
445 return NULL; 445 return NULL;
446} 446}
447 447
448/*! 448/*!
449 \fn void FileSelector::fileSelected( const DocLnk &f ) 449 \fn void FileSelector::fileSelected( const DocLnk &f )
450 450
451 This signal is emitted when the user selects a document. 451 This signal is emitted when the user selects a document.
452 \a f is the document. 452 \a f is the document.
453*/ 453*/
454 454
455/*! 455/*!
456 \fn void FileSelector::newSelected( const DocLnk &f ) 456 \fn void FileSelector::newSelected( const DocLnk &f )
457 457
458 This signal is emitted when the user selects a "new" document. 458 This signal is emitted when the user selects a "new" document.
459 \a f is a DocLnk for the document. You will need to set the type 459 \a f is a DocLnk for the document. You will need to set the type
460 of the document after copying it. 460 of the document after copying it.
461*/ 461*/
462 462
463/*! 463/*!
464 \fn void FileSelector::closeMe() 464 \fn void FileSelector::closeMe()
465 465
466 This signal is emitted when the user no longer needs to view the widget. 466 This signal is emitted when the user no longer needs to view the widget.
467*/ 467*/
468 468
469 469
470/*! 470/*!
471 If \a b is TRUE a "new document" entry is visible; if \a b is FALSE 471 If \a b is TRUE a "new document" entry is visible; if \a b is FALSE
472 this entry is not visible and the user is unable to create new 472 this entry is not visible and the user is unable to create new
473 documents from the dialog. 473 documents from the dialog.
474*/ 474*/
475void FileSelector::setNewVisible( bool b ) 475void FileSelector::setNewVisible( bool b )
476{ 476{
477 if ( d->showNew != b ) { 477 if ( d->showNew != b ) {
478 d->showNew = b; 478 d->showNew = b;
479 updateView(); 479 updateView();
480 updateWhatsThis(); 480 updateWhatsThis();
481 } 481 }
482} 482}
483 483
484/*! 484/*!
485 If \a b is TRUE a "close" or "no document" button is visible; if \a 485 If \a b is TRUE a "close" or "no document" button is visible; if \a
486 b is FALSE this button is not visible and the user is unable to 486 b is FALSE this button is not visible and the user is unable to
487 leave the dialog without creating or selecting a document. 487 leave the dialog without creating or selecting a document.
488 488
489 This function is deprecated. 489 This function is deprecated.
490*/ 490*/
491void FileSelector::setCloseVisible( bool b ) 491void FileSelector::setCloseVisible( bool b )
492{ 492{
493 if ( b ) 493 if ( b )
494 d->toolbar->show(); 494 d->toolbar->show();
495 else 495 else
496 d->toolbar->hide(); 496 d->toolbar->hide();
497} 497}
498 498
499/*! 499/*!
500 500
501*/ 501*/
502void FileSelector::setTypeComboVisible( bool b ) { 502void FileSelector::setTypeComboVisible( bool b ) {
503 if ( b ) 503 if ( b )
504 d->typeCombo->show(); 504 d->typeCombo->show();
505 else 505 else
506 d->typeCombo->hide(); 506 d->typeCombo->hide();
507} 507}
508/*! 508/*!
509 509
510*/ 510*/
511void FileSelector::setCategorySelectVisible( bool b ) { 511void FileSelector::setCategorySelectVisible( bool b ) {
512 if ( b ) 512 if ( b )
513 d->catSelect->show(); 513 d->catSelect->show();
514 else 514 else
515 d->catSelect->hide(); 515 d->catSelect->hide();
516} 516}
517 517
518/*! 518/*!
519 Rereads the list of documents. 519 Rereads the list of documents.
520*/ 520*/
521void FileSelector::reread() 521void FileSelector::reread()
522{ 522{
523 d->files.clear(); 523 d->files.clear();
524 Global::findDocuments(&d->files, filter); 524 Global::findDocuments(&d->files, filter);
525 d->typeCombo->reread( d->files, filter ); 525 d->typeCombo->reread( d->files, filter );
526 updateView(); 526 updateView();
527} 527}
528 528
529void FileSelector::updateView() 529void FileSelector::updateView()
530{ 530{
531 FileSelectorItem *item = (FileSelectorItem *)view->selectedItem(); 531 FileSelectorItem *item = (FileSelectorItem *)view->selectedItem();
532 if ( item == d->newDocItem ) 532 if ( item == d->newDocItem )
533 item = 0; 533 item = 0;
534 QString oldFile; 534 QString oldFile;
535 if ( item ) 535 if ( item )
536 oldFile = item->file().file(); 536 oldFile = item->file().file();
537 view->clear(); 537 view->clear();
538 QListIterator<DocLnk> dit( d->files.children() ); 538 QListIterator<DocLnk> dit( d->files.children() );
539 for ( ; dit.current(); ++dit ) { 539 for ( ; dit.current(); ++dit ) {
540 bool mimeMatch = FALSE; 540 bool mimeMatch = FALSE;
541 if ( d->mimeFilters.count() ) { 541 if ( d->mimeFilters.count() ) {
542 QValueList<QRegExp>::Iterator it; 542 QValueList<QRegExp>::Iterator it;
543 for ( it = d->mimeFilters.begin(); it != d->mimeFilters.end(); ++it ) { 543 for ( it = d->mimeFilters.begin(); it != d->mimeFilters.end(); ++it ) {
544 if ( (*it).match((*dit)->type()) >= 0 ) { 544 if ( (*it).match((*dit)->type()) >= 0 ) {
545 mimeMatch = TRUE; 545 mimeMatch = TRUE;
546 break; 546 break;
547 } 547 }
548 } 548 }
549 } else { 549 } else {
550 mimeMatch = TRUE; 550 mimeMatch = TRUE;
551 } 551 }
552 if ( mimeMatch && 552 if ( mimeMatch &&
553 (d->catId == -2 || (*dit)->categories().contains(d->catId) || 553 (d->catId == -2 || (*dit)->categories().contains(d->catId) ||
554 (d->catId == -1 && (*dit)->categories().isEmpty())) ) { 554 (d->catId == -1 && (*dit)->categories().isEmpty())) ) {
555 item = new FileSelectorItem( view, **dit ); 555 item = new FileSelectorItem( view, **dit );
556 if ( item->file().file() == oldFile ) 556 if ( item->file().file() == oldFile )
557 view->setCurrentItem( item ); 557 view->setCurrentItem( item );
558 } 558 }
559 } 559 }
560 560
561 if ( d->showNew ) 561 if ( d->showNew )
562 d->newDocItem = new NewDocItem( view, DocLnk() ); 562 d->newDocItem = new NewDocItem( view, DocLnk() );
563 else 563 else
564 d->newDocItem = 0; 564 d->newDocItem = 0;
565 565
566 if ( !view->selectedItem() || view->childCount() == 1 ) { 566 if ( !view->selectedItem() || view->childCount() == 1 ) {
567 view->setCurrentItem( view->firstChild() ); 567 view->setCurrentItem( view->firstChild() );
568 view->setSelected( view->firstChild(), TRUE ); 568 view->setSelected( view->firstChild(), TRUE );
569 } 569 }
570} 570}
571 571
572void FileSelector::updateWhatsThis() 572void FileSelector::updateWhatsThis()
573{ 573{
574 QWhatsThis::remove( this ); 574 QWhatsThis::remove( this );
575 QString text = tr("Click to select a document from the list"); 575 QString text = tr("Click to select a document from the list");
576 if ( d->showNew ) 576 if ( d->showNew )
577 text += tr(", or select <b>New Document</b> to create a new document."); 577 text += tr(", or select <b>New Document</b> to create a new document.");
578 text += tr("<br><br>Click and hold for document properties."); 578 text += tr("<br><br>Click and hold for document properties.");
579 QWhatsThis::add( this, text ); 579 QWhatsThis::add( this, text );
580} 580}
581 581
582#include "fileselector.moc" 582#include "fileselector.moc"
583 583
diff --git a/library/fontdatabase.cpp b/library/fontdatabase.cpp
index c64e645..2b5e0d2 100644
--- a/library/fontdatabase.cpp
+++ b/library/fontdatabase.cpp
@@ -1,232 +1,232 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include "qpeapplication.h" 21#include <qpe/qpeapplication.h>
22#include "fontfactoryinterface.h" 22#include "fontfactoryinterface.h"
23#include "fontdatabase.h" 23#include "fontdatabase.h"
24 24
25#include <qpe/qlibrary.h> 25#include <qpe/qlibrary.h>
26 26
27#ifdef QWS 27#ifdef QWS
28#include <qfontmanager_qws.h> 28#include <qfontmanager_qws.h>
29#endif 29#endif
30#include <qdir.h> 30#include <qdir.h>
31#include <qdict.h> 31#include <qdict.h>
32#include <stdio.h> 32#include <stdio.h>
33#include <stdlib.h> 33#include <stdlib.h>
34 34
35static QString fontDir() 35static QString fontDir()
36{ 36{
37 QString qtdir = getenv("QTDIR"); 37 QString qtdir = getenv("QTDIR");
38 if ( qtdir.isEmpty() ) qtdir = "/usr/local/qt-embedded"; 38 if ( qtdir.isEmpty() ) qtdir = "/usr/local/qt-embedded";
39 return qtdir+"/lib/fonts/"; 39 return qtdir+"/lib/fonts/";
40} 40}
41 41
42#ifdef QT_NO_FONTDATABASE 42#ifdef QT_NO_FONTDATABASE
43static QString fontFamily( const QString& key ) 43static QString fontFamily( const QString& key )
44{ 44{
45 int u0 = key.find('_'); 45 int u0 = key.find('_');
46 int u1 = key.find('_',u0+1); 46 int u1 = key.find('_',u0+1);
47 int u2 = key.find('_',u1+1); 47 int u2 = key.find('_',u1+1);
48 QString family = key.left(u0); 48 QString family = key.left(u0);
49 //int pointSize = key.mid(u0+1,u1-u0-1).toInt(); 49 //int pointSize = key.mid(u0+1,u1-u0-1).toInt();
50 //int weight = key.mid(u1+1,u2-u1-1).toInt(); 50 //int weight = key.mid(u1+1,u2-u1-1).toInt();
51 //bool italic = key.mid(u2-1,1) == "i"; 51 //bool italic = key.mid(u2-1,1) == "i";
52 // #### ignores _t and _I fields 52 // #### ignores _t and _I fields
53 return family; 53 return family;
54} 54}
55#endif 55#endif
56 56
57QValueList<FontFactory> *FontDatabase::factoryList = 0; 57QValueList<FontFactory> *FontDatabase::factoryList = 0;
58 58
59/*! 59/*!
60 \class FontDatabase fontdatabase.h 60 \class FontDatabase fontdatabase.h
61 \brief The FontDatabase class provides information about available fonts. 61 \brief The FontDatabase class provides information about available fonts.
62 62
63 Most often you will simply want to query the database for the 63 Most often you will simply want to query the database for the
64 available font families(). 64 available font families().
65 65
66 Use FontDatabase rather than QFontDatabase when you may need access 66 Use FontDatabase rather than QFontDatabase when you may need access
67 to fonts that are not normally available. For example, if the 67 to fonts that are not normally available. For example, if the
68 freetype library and the Qtopia freetype plugin are installed, 68 freetype library and the Qtopia freetype plugin are installed,
69 TrueType fonts will be available to your application. Font renderer 69 TrueType fonts will be available to your application. Font renderer
70 plugins have greater resource requirements than system fonts so they 70 plugins have greater resource requirements than system fonts so they
71 should be used only when necessary. You can force the loading of 71 should be used only when necessary. You can force the loading of
72 font renderer plugins with loadRenderers(). 72 font renderer plugins with loadRenderers().
73 73
74 \ingroup qtopiaemb 74 \ingroup qtopiaemb
75*/ 75*/
76 76
77/*! 77/*!
78 Constructs a FontDatabase object. 78 Constructs a FontDatabase object.
79*/ 79*/
80FontDatabase::FontDatabase() 80FontDatabase::FontDatabase()
81#ifndef QT_NO_FONTDATABASE 81#ifndef QT_NO_FONTDATABASE
82 : QFontDatabase() 82 : QFontDatabase()
83#endif 83#endif
84{ 84{
85 if ( !factoryList ) 85 if ( !factoryList )
86 loadRenderers(); 86 loadRenderers();
87} 87}
88 88
89/*! 89/*!
90 Returns a list of names of all the available font families. 90 Returns a list of names of all the available font families.
91*/ 91*/
92QStringList FontDatabase::families() const 92QStringList FontDatabase::families() const
93{ 93{
94#ifndef QT_NO_FONTDATABASE 94#ifndef QT_NO_FONTDATABASE
95 return QFontDatabase::families(); 95 return QFontDatabase::families();
96#else 96#else
97 QStringList list; 97 QStringList list;
98 QDict<void> familyDict; 98 QDict<void> familyDict;
99 QDiskFont *qdf; 99 QDiskFont *qdf;
100 for ( qdf=qt_fontmanager->diskfonts.first(); qdf!=0; 100 for ( qdf=qt_fontmanager->diskfonts.first(); qdf!=0;
101 qdf=qt_fontmanager->diskfonts.next()) { 101 qdf=qt_fontmanager->diskfonts.next()) {
102 QString familyname = qdf->name; 102 QString familyname = qdf->name;
103 if ( !familyDict.find( familyname ) ) { 103 if ( !familyDict.find( familyname ) ) {
104 familyDict.insert( familyname, (void *)1 ); 104 familyDict.insert( familyname, (void *)1 );
105 list.append( familyname ); 105 list.append( familyname );
106 } 106 }
107 } 107 }
108 108
109 QDir dir(fontDir(),"*.qpf"); 109 QDir dir(fontDir(),"*.qpf");
110 for (int i=0; i<(int)dir.count(); i++) { 110 for (int i=0; i<(int)dir.count(); i++) {
111 QString familyname = fontFamily(dir[i]); 111 QString familyname = fontFamily(dir[i]);
112 if ( !familyDict.find( familyname ) ) { 112 if ( !familyDict.find( familyname ) ) {
113 familyDict.insert( familyname, (void *)1 ); 113 familyDict.insert( familyname, (void *)1 );
114 list.append( familyname ); 114 list.append( familyname );
115 } 115 }
116 } 116 }
117 117
118 return list; 118 return list;
119#endif 119#endif
120} 120}
121 121
122#ifdef QT_NO_FONTDATABASE 122#ifdef QT_NO_FONTDATABASE
123/*! 123/*!
124 Returns a list of standard fontsizes. 124 Returns a list of standard fontsizes.
125*/ 125*/
126QValueList<int> FontDatabase::standardSizes() 126QValueList<int> FontDatabase::standardSizes()
127{ 127{
128 static int s[]={ 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 128 static int s[]={ 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28,
129 36, 48, 72, 0 }; 129 36, 48, 72, 0 };
130 static bool first = TRUE; 130 static bool first = TRUE;
131 static QValueList<int> sList; 131 static QValueList<int> sList;
132 if ( first ) { 132 if ( first ) {
133 first = FALSE; 133 first = FALSE;
134 int i = 0; 134 int i = 0;
135 while( s[i] ) 135 while( s[i] )
136 sList.append( s[i++] ); 136 sList.append( s[i++] );
137 } 137 }
138 return sList; 138 return sList;
139} 139}
140 140
141#endif 141#endif
142 142
143/*! 143/*!
144 Load any font renderer plugins that are available and make the fonts 144 Load any font renderer plugins that are available and make the fonts
145 that the plugins can read available. 145 that the plugins can read available.
146*/ 146*/
147void FontDatabase::loadRenderers() 147void FontDatabase::loadRenderers()
148{ 148{
149#ifndef QT_NO_COMPONENT 149#ifndef QT_NO_COMPONENT
150 if ( !factoryList ) 150 if ( !factoryList )
151 factoryList = new QValueList<FontFactory>; 151 factoryList = new QValueList<FontFactory>;
152 152
153 QValueList<FontFactory>::Iterator mit; 153 QValueList<FontFactory>::Iterator mit;
154 for ( mit = factoryList->begin(); mit != factoryList->end(); ++mit ) { 154 for ( mit = factoryList->begin(); mit != factoryList->end(); ++mit ) {
155 qt_fontmanager->factories.setAutoDelete( false ); 155 qt_fontmanager->factories.setAutoDelete( false );
156 qt_fontmanager->factories.removeRef( (*mit).factory ); 156 qt_fontmanager->factories.removeRef( (*mit).factory );
157 qt_fontmanager->factories.setAutoDelete( true ); 157 qt_fontmanager->factories.setAutoDelete( true );
158 (*mit).interface->release(); 158 (*mit).interface->release();
159 (*mit).library->unload(); 159 (*mit).library->unload();
160 delete (*mit).library; 160 delete (*mit).library;
161 } 161 }
162 factoryList->clear(); 162 factoryList->clear();
163 163
164 QString path = QPEApplication::qpeDir() + "/plugins/fontfactories"; 164 QString path = QPEApplication::qpeDir() + "/plugins/fontfactories";
165 QDir dir( path, "lib*.so" ); 165 QDir dir( path, "lib*.so" );
166 QStringList list = dir.entryList(); 166 QStringList list = dir.entryList();
167 QStringList::Iterator it; 167 QStringList::Iterator it;
168 for ( it = list.begin(); it != list.end(); ++it ) { 168 for ( it = list.begin(); it != list.end(); ++it ) {
169 FontFactoryInterface *iface = 0; 169 FontFactoryInterface *iface = 0;
170 QLibrary *lib = new QLibrary( path + "/" + *it ); 170 QLibrary *lib = new QLibrary( path + "/" + *it );
171 if ( lib->queryInterface( IID_FontFactory, (QUnknownInterface**)&iface ) == QS_OK ) { 171 if ( lib->queryInterface( IID_FontFactory, (QUnknownInterface**)&iface ) == QS_OK ) {
172 FontFactory factory; 172 FontFactory factory;
173 factory.library = lib; 173 factory.library = lib;
174 factory.interface = iface; 174 factory.interface = iface;
175 factory.factory = factory.interface->fontFactory(); 175 factory.factory = factory.interface->fontFactory();
176 factoryList->append( factory ); 176 factoryList->append( factory );
177 qt_fontmanager->factories.append( factory.factory ); 177 qt_fontmanager->factories.append( factory.factory );
178 readFonts( factory.factory ); 178 readFonts( factory.factory );
179 } else { 179 } else {
180 delete lib; 180 delete lib;
181 } 181 }
182 } 182 }
183#endif 183#endif
184} 184}
185 185
186/*! 186/*!
187 \internal 187 \internal
188*/ 188*/
189void FontDatabase::readFonts( QFontFactory *factory ) 189void FontDatabase::readFonts( QFontFactory *factory )
190{ 190{
191 // Load in font definition file 191 // Load in font definition file
192 QString fn = fontDir() + "fontdir"; 192 QString fn = fontDir() + "fontdir";
193 FILE* fontdef=fopen(fn.local8Bit(),"r"); 193 FILE* fontdef=fopen(fn.local8Bit(),"r");
194 if(!fontdef) { 194 if(!fontdef) {
195 QCString temp=fn.local8Bit(); 195 QCString temp=fn.local8Bit();
196 qWarning("Cannot find font definition file %s - is $QTDIR set correctly?", 196 qWarning("Cannot find font definition file %s - is $QTDIR set correctly?",
197 temp.data()); 197 temp.data());
198 return; 198 return;
199 } 199 }
200 char buf[200]=""; 200 char buf[200]="";
201 char name[200]=""; 201 char name[200]="";
202 char render[200]=""; 202 char render[200]="";
203 char file[200]=""; 203 char file[200]="";
204 char flags[200]=""; 204 char flags[200]="";
205 char isitalic[10]=""; 205 char isitalic[10]="";
206 fgets(buf,200,fontdef); 206 fgets(buf,200,fontdef);
207 while(!feof(fontdef)) { 207 while(!feof(fontdef)) {
208 if ( buf[0] != '#' ) { 208 if ( buf[0] != '#' ) {
209 int weight=50; 209 int weight=50;
210 int size=0; 210 int size=0;
211 flags[0]=0; 211 flags[0]=0;
212 sscanf(buf,"%s %s %s %s %d %d %s",name,file,render,isitalic,&weight,&size,flags); 212 sscanf(buf,"%s %s %s %s %d %d %s",name,file,render,isitalic,&weight,&size,flags);
213 QString filename; 213 QString filename;
214 if ( file[0] != '/' ) 214 if ( file[0] != '/' )
215 filename = fontDir(); 215 filename = fontDir();
216 filename += file; 216 filename += file;
217 if ( QFile::exists(filename) ) { 217 if ( QFile::exists(filename) ) {
218 if( factory->name() == render ) { 218 if( factory->name() == render ) {
219 QDiskFont * qdf=new QDiskFont(factory,name,isitalic[0]=='y', 219 QDiskFont * qdf=new QDiskFont(factory,name,isitalic[0]=='y',
220 weight,size,flags,filename); 220 weight,size,flags,filename);
221 qt_fontmanager->diskfonts.append(qdf); 221 qt_fontmanager->diskfonts.append(qdf);
222#if QT_VERSION >= 232 222#if QT_VERSION >= 232
223 QFontDatabase::qwsAddDiskFont( qdf ); 223 QFontDatabase::qwsAddDiskFont( qdf );
224#endif 224#endif
225 } 225 }
226 } 226 }
227 } 227 }
228 fgets(buf,200,fontdef); 228 fgets(buf,200,fontdef);
229 } 229 }
230 fclose(fontdef); 230 fclose(fontdef);
231} 231}
232 232
diff --git a/library/fontdatabase.h b/library/fontdatabase.h
index 10aec91..991847b 100644
--- a/library/fontdatabase.h
+++ b/library/fontdatabase.h
@@ -1,62 +1,63 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#ifndef FONTFACTORY_H 20#ifndef FONTFACTORY_H
21#define FONTFACTORY_H 21#define FONTFACTORY_H
22 22
23#include <qpe/fontfactoryinterface.h> 23#include <qpe/fontfactoryinterface.h>
24 24
25#include <qfontdatabase.h> 25#include <qfontdatabase.h>
26#include <qvaluelist.h> 26#include <qvaluelist.h>
27 27
28class QLibrary; 28class QLibrary;
29 29
30struct FontFactory 30struct FontFactory
31{ 31{
32#ifndef QT_NO_COMPONENT 32#ifndef QT_NO_COMPONENT
33 QLibrary *library; 33 QLibrary *library;
34#endif 34#endif
35 FontFactoryInterface *interface; 35 FontFactoryInterface *interface;
36 QFontFactory *factory; 36 QFontFactory *factory;
37}; 37};
38 38
39#undef QT_NO_FONTDATABASE
39class FontDatabase 40class FontDatabase
40#ifndef QT_NO_FONTDATABASE 41#ifndef QT_NO_FONTDATABASE
41 : public QFontDatabase 42 : public QFontDatabase
42#endif 43#endif
43{ 44{
44public: 45public:
45 FontDatabase(); 46 FontDatabase();
46 47
47 // minimal functionality 48 // minimal functionality
48 QStringList families () const; 49 QStringList families () const;
49#ifdef QT_NO_FONTDATABASE 50#ifdef QT_NO_FONTDATABASE
50 static QValueList<int> standardSizes (); 51 static QValueList<int> standardSizes ();
51#endif 52#endif
52 53
53 static void loadRenderers(); 54 static void loadRenderers();
54 55
55private: 56private:
56 static void readFonts( QFontFactory *factory ); 57 static void readFonts( QFontFactory *factory );
57 58
58private: 59private:
59 static QValueList<FontFactory> *factoryList; 60 static QValueList<FontFactory> *factoryList;
60}; 61};
61 62
62#endif 63#endif
diff --git a/library/mimetype.cpp b/library/mimetype.cpp
index 92fe5e6..ef5d619 100644
--- a/library/mimetype.cpp
+++ b/library/mimetype.cpp
@@ -1,306 +1,306 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#define QTOPIA_INTERNAL_MIMEEXT 21#define QTOPIA_INTERNAL_MIMEEXT
22#include "mimetype.h" 22#include "mimetype.h"
23#include "applnk.h" 23#include "applnk.h"
24#include "resource.h" 24#include "resource.h"
25#include "qpeapplication.h" 25#include <qpe/qpeapplication.h>
26#include "config.h" 26#include "config.h"
27 27
28#include <qfile.h> 28#include <qfile.h>
29#include <qdict.h> 29#include <qdict.h>
30#include <qregexp.h> 30#include <qregexp.h>
31#include <qstringlist.h> 31#include <qstringlist.h>
32#include <qtextstream.h> 32#include <qtextstream.h>
33#include <qmap.h> 33#include <qmap.h>
34 34
35 35
36static void cleanupMime() 36static void cleanupMime()
37{ 37{
38 MimeType::clear(); 38 MimeType::clear();
39} 39}
40 40
41class MimeTypeData { 41class MimeTypeData {
42public: 42public:
43 MimeTypeData(const QString& i) : 43 MimeTypeData(const QString& i) :
44 id(i) 44 id(i)
45 { 45 {
46 apps.setAutoDelete(TRUE); 46 apps.setAutoDelete(TRUE);
47 } 47 }
48 QString id; 48 QString id;
49 QString extension; 49 QString extension;
50 QList<AppLnk> apps; 50 QList<AppLnk> apps;
51 51
52 QString description() 52 QString description()
53 { 53 {
54 if ( desc.isEmpty() ) 54 if ( desc.isEmpty() )
55 desc = QPEApplication::tr("%1 document").arg(apps.first()->name()); 55 desc = QPEApplication::tr("%1 document").arg(apps.first()->name());
56 return desc; 56 return desc;
57 } 57 }
58 58
59 QPixmap regIcon() 59 QPixmap regIcon()
60 { 60 {
61 if ( regicon.isNull() ) 61 if ( regicon.isNull() )
62 loadPixmaps(); 62 loadPixmaps();
63 return regicon; 63 return regicon;
64 } 64 }
65 65
66 QPixmap bigIcon() 66 QPixmap bigIcon()
67 { 67 {
68 if ( bigicon.isNull() ) 68 if ( bigicon.isNull() )
69 loadPixmaps(); 69 loadPixmaps();
70 return bigicon; 70 return bigicon;
71 } 71 }
72 72
73private: 73private:
74 void loadPixmaps() 74 void loadPixmaps()
75 { 75 {
76 if ( apps.count() ) { 76 if ( apps.count() ) {
77 QString icon; 77 QString icon;
78 for (AppLnk* lnk = apps.first(); icon.isNull() && lnk; lnk=apps.next()) { 78 for (AppLnk* lnk = apps.first(); icon.isNull() && lnk; lnk=apps.next()) {
79 QStringList icons = lnk->mimeTypeIcons(); 79 QStringList icons = lnk->mimeTypeIcons();
80 if ( icons.count() ) { 80 if ( icons.count() ) {
81 QStringList types = lnk->mimeTypes(); 81 QStringList types = lnk->mimeTypes();
82 for (QStringList::ConstIterator t=types.begin(),i=icons.begin(); t!=types.end() && i!=icons.end(); ++i,++t) { 82 for (QStringList::ConstIterator t=types.begin(),i=icons.begin(); t!=types.end() && i!=icons.end(); ++i,++t) {
83 if ( *t == id ) { 83 if ( *t == id ) {
84 icon = *i; 84 icon = *i;
85 break; 85 break;
86 } 86 }
87 } 87 }
88 } 88 }
89 } 89 }
90 if ( icon.isNull() ) { 90 if ( icon.isNull() ) {
91 AppLnk* lnk = apps.first(); 91 AppLnk* lnk = apps.first();
92 regicon = lnk->pixmap(); 92 regicon = lnk->pixmap();
93 bigicon = lnk->bigPixmap(); 93 bigicon = lnk->bigPixmap();
94 } else { 94 } else {
95 QImage unscaledIcon = Resource::loadImage( icon ); 95 QImage unscaledIcon = Resource::loadImage( icon );
96 regicon.convertFromImage( unscaledIcon.smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ) ); 96 regicon.convertFromImage( unscaledIcon.smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ) );
97 bigicon.convertFromImage( unscaledIcon.smoothScale( AppLnk::bigIconSize(), AppLnk::bigIconSize() ) ); 97 bigicon.convertFromImage( unscaledIcon.smoothScale( AppLnk::bigIconSize(), AppLnk::bigIconSize() ) );
98 } 98 }
99 } 99 }
100 } 100 }
101 101
102 QPixmap regicon; 102 QPixmap regicon;
103 QPixmap bigicon; 103 QPixmap bigicon;
104 QString desc; 104 QString desc;
105}; 105};
106 106
107class MimeType::Private : public QDict<MimeTypeData> { 107class MimeType::Private : public QDict<MimeTypeData> {
108public: 108public:
109 Private() {} 109 Private() {}
110 ~Private() {} 110 ~Private() {}
111 111
112 // ... 112 // ...
113}; 113};
114 114
115MimeType::Private* MimeType::d=0; 115MimeType::Private* MimeType::d=0;
116static QMap<QString,QString> *typeFor = 0; 116static QMap<QString,QString> *typeFor = 0;
117static QMap<QString,QStringList> *extFor = 0; 117static QMap<QString,QStringList> *extFor = 0;
118 118
119MimeType::Private& MimeType::data() 119MimeType::Private& MimeType::data()
120{ 120{
121 if ( !d ) { 121 if ( !d ) {
122 d = new Private; 122 d = new Private;
123 d->setAutoDelete(TRUE); 123 d->setAutoDelete(TRUE);
124 static bool setCleanup = FALSE; 124 static bool setCleanup = FALSE;
125 if ( !setCleanup ) { 125 if ( !setCleanup ) {
126 qAddPostRoutine( cleanupMime ); 126 qAddPostRoutine( cleanupMime );
127 setCleanup = TRUE; 127 setCleanup = TRUE;
128 } 128 }
129 } 129 }
130 return *d; 130 return *d;
131} 131}
132 132
133MimeType::MimeType( const QString& ext_or_id ) 133MimeType::MimeType( const QString& ext_or_id )
134{ 134{
135 init(ext_or_id); 135 init(ext_or_id);
136} 136}
137 137
138MimeType::MimeType( const DocLnk& lnk ) 138MimeType::MimeType( const DocLnk& lnk )
139{ 139{
140 init(lnk.type()); 140 init(lnk.type());
141} 141}
142 142
143QString MimeType::id() const 143QString MimeType::id() const
144{ 144{
145 return i; 145 return i;
146} 146}
147 147
148QString MimeType::description() const 148QString MimeType::description() const
149{ 149{
150 MimeTypeData* d = data(i); 150 MimeTypeData* d = data(i);
151 return d ? d->description() : QString::null; 151 return d ? d->description() : QString::null;
152} 152}
153 153
154QPixmap MimeType::pixmap() const 154QPixmap MimeType::pixmap() const
155{ 155{
156 MimeTypeData* d = data(i); 156 MimeTypeData* d = data(i);
157 return d ? d->regIcon() : QPixmap(); 157 return d ? d->regIcon() : QPixmap();
158} 158}
159 159
160QString MimeType::extension() const 160QString MimeType::extension() const
161{ 161{
162 return extensions().first(); 162 return extensions().first();
163} 163}
164 164
165QStringList MimeType::extensions() const 165QStringList MimeType::extensions() const
166{ 166{
167 loadExtensions(); 167 loadExtensions();
168 return *(*extFor).find(i); 168 return *(*extFor).find(i);
169} 169}
170 170
171QPixmap MimeType::bigPixmap() const 171QPixmap MimeType::bigPixmap() const
172{ 172{
173 MimeTypeData* d = data(i); 173 MimeTypeData* d = data(i);
174 return d ? d->bigIcon() : QPixmap(); 174 return d ? d->bigIcon() : QPixmap();
175} 175}
176 176
177const AppLnk* MimeType::application() const 177const AppLnk* MimeType::application() const
178{ 178{
179 MimeTypeData* d = data(i); 179 MimeTypeData* d = data(i);
180 return d ? d->apps.first() : 0; 180 return d ? d->apps.first() : 0;
181} 181}
182 182
183static QString serviceBinding(const QString& service) 183static QString serviceBinding(const QString& service)
184{ 184{
185 // Copied from qtopiaservices 185 // Copied from qtopiaservices
186 QString svrc = service; 186 QString svrc = service;
187 for (int i=0; i<(int)svrc.length(); i++) 187 for (int i=0; i<(int)svrc.length(); i++)
188 if ( svrc[i]=='/' ) svrc[i] = '-'; 188 if ( svrc[i]=='/' ) svrc[i] = '-';
189 return "Service-"+svrc; 189 return "Service-"+svrc;
190} 190}
191 191
192void MimeType::registerApp( const AppLnk& lnk ) 192void MimeType::registerApp( const AppLnk& lnk )
193{ 193{
194 QStringList list = lnk.mimeTypes(); 194 QStringList list = lnk.mimeTypes();
195 for (QStringList::ConstIterator it = list.begin(); it != list.end(); ++it) { 195 for (QStringList::ConstIterator it = list.begin(); it != list.end(); ++it) {
196 MimeTypeData* cur = data()[*it]; 196 MimeTypeData* cur = data()[*it];
197 AppLnk* l = new AppLnk(lnk); 197 AppLnk* l = new AppLnk(lnk);
198 if ( !cur ) { 198 if ( !cur ) {
199 cur = new MimeTypeData( *it ); 199 cur = new MimeTypeData( *it );
200 data().insert( *it, cur ); 200 data().insert( *it, cur );
201 cur->apps.append(l); 201 cur->apps.append(l);
202 } else if ( cur->apps.count() ) { 202 } else if ( cur->apps.count() ) {
203 Config binding(serviceBinding("Open/"+*it)); 203 Config binding(serviceBinding("Open/"+*it));
204 binding.setGroup("Service"); 204 binding.setGroup("Service");
205 QString def = binding.readEntry("default"); 205 QString def = binding.readEntry("default");
206 if ( l->exec() == def ) 206 if ( l->exec() == def )
207 cur->apps.prepend(l); 207 cur->apps.prepend(l);
208 else 208 else
209 cur->apps.append(l); 209 cur->apps.append(l);
210 } else { 210 } else {
211 cur->apps.append(l); 211 cur->apps.append(l);
212 } 212 }
213 } 213 }
214} 214}
215 215
216void MimeType::clear() 216void MimeType::clear()
217{ 217{
218 delete d; 218 delete d;
219 d = 0; 219 d = 0;
220} 220}
221 221
222void MimeType::loadExtensions() 222void MimeType::loadExtensions()
223{ 223{
224 if ( !typeFor ) { 224 if ( !typeFor ) {
225 extFor = new QMap<QString,QStringList>; 225 extFor = new QMap<QString,QStringList>;
226 typeFor = new QMap<QString,QString>; 226 typeFor = new QMap<QString,QString>;
227 loadExtensions("/etc/mime.types"); 227 loadExtensions("/etc/mime.types");
228 loadExtensions(QPEApplication::qpeDir()+"etc/mime.types"); 228 loadExtensions(QPEApplication::qpeDir()+"etc/mime.types");
229 } 229 }
230} 230}
231 231
232void MimeType::loadExtensions(const QString& filename) 232void MimeType::loadExtensions(const QString& filename)
233{ 233{
234 QFile file(filename); 234 QFile file(filename);
235 if ( file.open(IO_ReadOnly) ) { 235 if ( file.open(IO_ReadOnly) ) {
236 QTextStream in(&file); 236 QTextStream in(&file);
237 QRegExp space("[ \t]+"); 237 QRegExp space("[ \t]+");
238 while (!in.atEnd()) { 238 while (!in.atEnd()) {
239 QStringList tokens = QStringList::split(space, in.readLine()); 239 QStringList tokens = QStringList::split(space, in.readLine());
240 QStringList::ConstIterator it = tokens.begin(); 240 QStringList::ConstIterator it = tokens.begin();
241 if ( it != tokens.end() ) { 241 if ( it != tokens.end() ) {
242 QString id = *it; ++it; 242 QString id = *it; ++it;
243 // new override old (though left overrides right) 243 // new override old (though left overrides right)
244 QStringList exts = (*extFor)[id]; 244 QStringList exts = (*extFor)[id];
245 QStringList newexts; 245 QStringList newexts;
246 while ( it != tokens.end() ) { 246 while ( it != tokens.end() ) {
247 exts.remove(*it); 247 exts.remove(*it);
248 if ( !newexts.contains(*it) ) 248 if ( !newexts.contains(*it) )
249 newexts.append(*it); 249 newexts.append(*it);
250 (*typeFor)[*it] = id; 250 (*typeFor)[*it] = id;
251 ++it; 251 ++it;
252 } 252 }
253 (*extFor)[id] = newexts + exts; 253 (*extFor)[id] = newexts + exts;
254 } 254 }
255 } 255 }
256 } 256 }
257} 257}
258 258
259void MimeType::init( const QString& ext_or_id ) 259void MimeType::init( const QString& ext_or_id )
260{ 260{
261 if ( ext_or_id[0] != '/' && ext_or_id.contains('/') ) { 261 if ( ext_or_id[0] != '/' && ext_or_id.contains('/') ) {
262 i = ext_or_id.lower(); 262 i = ext_or_id.lower();
263 } else { 263 } else {
264 loadExtensions(); 264 loadExtensions();
265 int dot = ext_or_id.findRev('.'); 265 int dot = ext_or_id.findRev('.');
266 QString ext = dot >= 0 ? ext_or_id.mid(dot+1) : ext_or_id; 266 QString ext = dot >= 0 ? ext_or_id.mid(dot+1) : ext_or_id;
267 i = (*typeFor)[ext.lower()]; 267 i = (*typeFor)[ext.lower()];
268 if ( i.isNull() ) 268 if ( i.isNull() )
269 i = "application/octet-stream"; 269 i = "application/octet-stream";
270 } 270 }
271 static bool appsUpdated = FALSE; 271 static bool appsUpdated = FALSE;
272 if ( !appsUpdated ) { 272 if ( !appsUpdated ) {
273 appsUpdated = TRUE; 273 appsUpdated = TRUE;
274 updateApplications(); 274 updateApplications();
275 } 275 }
276} 276}
277 277
278MimeTypeData* MimeType::data(const QString& id) 278MimeTypeData* MimeType::data(const QString& id)
279{ 279{
280 MimeTypeData* d = data()[id]; 280 MimeTypeData* d = data()[id];
281 if ( !d ) { 281 if ( !d ) {
282 int s = id.find('/'); 282 int s = id.find('/');
283 QString idw = id.left(s)+"/*"; 283 QString idw = id.left(s)+"/*";
284 d = data()[idw]; 284 d = data()[idw];
285 } 285 }
286 return d; 286 return d;
287} 287}
288 288
289QString MimeType::appsFolderName() 289QString MimeType::appsFolderName()
290{ 290{
291 return QPEApplication::qpeDir() + "apps"; 291 return QPEApplication::qpeDir() + "apps";
292} 292}
293 293
294void MimeType::updateApplications() 294void MimeType::updateApplications()
295{ 295{
296 clear(); 296 clear();
297 AppLnkSet apps( appsFolderName() ); 297 AppLnkSet apps( appsFolderName() );
298 updateApplications(&apps); 298 updateApplications(&apps);
299} 299}
300 300
301void MimeType::updateApplications(AppLnkSet* folder) 301void MimeType::updateApplications(AppLnkSet* folder)
302{ 302{
303 for ( QListIterator<AppLnk> it( folder->children() ); it.current(); ++it ) { 303 for ( QListIterator<AppLnk> it( folder->children() ); it.current(); ++it ) {
304 registerApp(*it.current()); 304 registerApp(*it.current());
305 } 305 }
306} 306}
diff --git a/library/qpedialog.cpp b/library/qpedialog.cpp
index 0db161b..b98e42e 100644
--- a/library/qpedialog.cpp
+++ b/library/qpedialog.cpp
@@ -1,46 +1,46 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#define protected public 21#define protected public
22#include <qdialog.h> 22#include <qdialog.h>
23#undef protected 23#undef protected
24 24
25#include "qpedialog.h" 25#include "qpedialog.h"
26#include "qpeapplication.h" 26#include <qpe/qpeapplication.h>
27 27
28QPEDialogListener::QPEDialogListener(QDialog *di ) : QObject(di) 28QPEDialogListener::QPEDialogListener(QDialog *di ) : QObject(di)
29{ 29{
30 dialog = di; 30 dialog = di;
31 connect(qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)), 31 connect(qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)),
32 this, SLOT(appMessage(const QCString&, const QByteArray&)) ); 32 this, SLOT(appMessage(const QCString&, const QByteArray&)) );
33} 33}
34 34
35QPEDialogListener::~QPEDialogListener() {} 35QPEDialogListener::~QPEDialogListener() {}
36 36
37void QPEDialogListener::appMessage( const QCString &msg, const QByteArray & ) 37void QPEDialogListener::appMessage( const QCString &msg, const QByteArray & )
38{ 38{
39 if (!dialog) 39 if (!dialog)
40 return; 40 return;
41 if (msg == "accept()") { 41 if (msg == "accept()") {
42 dialog->accept(); 42 dialog->accept();
43 } else if (msg == "reject()") { 43 } else if (msg == "reject()") {
44 dialog->reject(); 44 dialog->reject();
45 } 45 }
46} 46}
diff --git a/library/qpestyle.cpp b/library/qpestyle.cpp
index dfd300f..665910c 100644
--- a/library/qpestyle.cpp
+++ b/library/qpestyle.cpp
@@ -1,1194 +1,1194 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include "qpestyle.h" 21#include "qpestyle.h"
22#include "qpeapplication.h" 22#include <qpe/qpeapplication.h>
23#include <qpushbutton.h> 23#include <qpushbutton.h>
24 24
25#include <qpainter.h> 25#include <qpainter.h>
26 26
27#define QCOORDARRLEN(x) sizeof(x)/(sizeof(QCOORD)*2) 27#define QCOORDARRLEN(x) sizeof(x)/(sizeof(QCOORD)*2)
28 28
29#if QT_VERSION >= 300 29#if QT_VERSION >= 300
30 30
31#include <qdrawutil.h> 31#include <qdrawutil.h>
32#include <qcombobox.h> 32#include <qcombobox.h>
33#include <qtabbar.h> 33#include <qtabbar.h>
34 34
35QPEStyle::QPEStyle() 35QPEStyle::QPEStyle()
36{ 36{
37} 37}
38 38
39QPEStyle::~QPEStyle() 39QPEStyle::~QPEStyle()
40{ 40{
41} 41}
42 42
43void QPEStyle::drawPrimitive( PrimitiveElement pe, QPainter *p, const QRect &r, 43void QPEStyle::drawPrimitive( PrimitiveElement pe, QPainter *p, const QRect &r,
44 const QColorGroup &cg, SFlags flags, const QStyleOption &data) const 44 const QColorGroup &cg, SFlags flags, const QStyleOption &data) const
45{ 45{
46 switch ( pe ) { 46 switch ( pe ) {
47 case PE_ButtonTool: 47 case PE_ButtonTool:
48 { 48 {
49 QColorGroup mycg = cg; 49 QColorGroup mycg = cg;
50 if ( flags & Style_On ) { 50 if ( flags & Style_On ) {
51 QBrush fill( cg.mid(), Dense4Pattern ); 51 QBrush fill( cg.mid(), Dense4Pattern );
52 mycg.setBrush( QColorGroup::Button, fill ); 52 mycg.setBrush( QColorGroup::Button, fill );
53 } 53 }
54 drawPrimitive( PE_ButtonBevel, p, r, mycg, flags, data ); 54 drawPrimitive( PE_ButtonBevel, p, r, mycg, flags, data );
55 break; 55 break;
56 } 56 }
57 case PE_ButtonCommand: 57 case PE_ButtonCommand:
58 case PE_ButtonDefault: 58 case PE_ButtonDefault:
59 case PE_ButtonBevel: 59 case PE_ButtonBevel:
60 case PE_HeaderSection: 60 case PE_HeaderSection:
61 { 61 {
62 QPen oldPen = p->pen(); 62 QPen oldPen = p->pen();
63 p->fillRect( r.x()+1, r.y()+1, r.width()-2, r.height()-2, cg.brush(QColorGroup::Button) ); 63 p->fillRect( r.x()+1, r.y()+1, r.width()-2, r.height()-2, cg.brush(QColorGroup::Button) );
64 64
65 int x2 = r.right(); 65 int x2 = r.right();
66 int y2 = r.bottom(); 66 int y2 = r.bottom();
67 67
68 if ( flags & (Style_Sunken | Style_Down | Style_On) ) 68 if ( flags & (Style_Sunken | Style_Down | Style_On) )
69 p->setPen( cg.dark() ); 69 p->setPen( cg.dark() );
70 else 70 else
71 p->setPen( cg.light() ); 71 p->setPen( cg.light() );
72 p->drawLine( r.x(), r.y()+1, r.x(), y2-1 ); 72 p->drawLine( r.x(), r.y()+1, r.x(), y2-1 );
73 p->drawLine( r.x()+1, r.y(), x2-1, r.y() ); 73 p->drawLine( r.x()+1, r.y(), x2-1, r.y() );
74 74
75 if ( flags & (Style_Sunken | Style_Down | Style_On) ) 75 if ( flags & (Style_Sunken | Style_Down | Style_On) )
76 p->setPen( cg.light() ); 76 p->setPen( cg.light() );
77 else 77 else
78 p->setPen( cg.dark() ); 78 p->setPen( cg.dark() );
79 p->drawLine( x2, r.y()+1, x2, y2-1 ); 79 p->drawLine( x2, r.y()+1, x2, y2-1 );
80 p->drawLine( r.x()+1, y2, x2-1, y2 ); 80 p->drawLine( r.x()+1, y2, x2-1, y2 );
81 p->setPen( oldPen ); 81 p->setPen( oldPen );
82 break; 82 break;
83 } 83 }
84 case PE_FocusRect: 84 case PE_FocusRect:
85 break; 85 break;
86 case PE_Indicator: 86 case PE_Indicator:
87 { 87 {
88 QColorGroup mycg( cg ); 88 QColorGroup mycg( cg );
89 QBrush fill; 89 QBrush fill;
90 if ( flags & Style_Down ) 90 if ( flags & Style_Down )
91 fill = cg.brush( QColorGroup::Button ); 91 fill = cg.brush( QColorGroup::Button );
92 else 92 else
93 fill = cg.brush( (flags&Style_Enabled) ? QColorGroup::Base : QColorGroup::Background ); 93 fill = cg.brush( (flags&Style_Enabled) ? QColorGroup::Base : QColorGroup::Background );
94 mycg.setBrush( QColorGroup::Button, fill ); 94 mycg.setBrush( QColorGroup::Button, fill );
95 if ( flags&Style_Enabled ) 95 if ( flags&Style_Enabled )
96 flags |= Style_Sunken; 96 flags |= Style_Sunken;
97 drawPrimitive( PE_ButtonBevel, p, r, mycg, flags ); 97 drawPrimitive( PE_ButtonBevel, p, r, mycg, flags );
98 if ( flags & Style_On ) { 98 if ( flags & Style_On ) {
99 QPointArray a( 7*2 ); 99 QPointArray a( 7*2 );
100 int i, xx, yy; 100 int i, xx, yy;
101 xx = r.x()+3; 101 xx = r.x()+3;
102 yy = r.y()+5; 102 yy = r.y()+5;
103 for ( i=0; i<3; i++ ) { 103 for ( i=0; i<3; i++ ) {
104 a.setPoint( 2*i, xx, yy ); 104 a.setPoint( 2*i, xx, yy );
105 a.setPoint( 2*i+1, xx, yy+2 ); 105 a.setPoint( 2*i+1, xx, yy+2 );
106 xx++; yy++; 106 xx++; yy++;
107 } 107 }
108 yy -= 2; 108 yy -= 2;
109 for ( i=3; i<7; i++ ) { 109 for ( i=3; i<7; i++ ) {
110 a.setPoint( 2*i, xx, yy ); 110 a.setPoint( 2*i, xx, yy );
111 a.setPoint( 2*i+1, xx, yy+2 ); 111 a.setPoint( 2*i+1, xx, yy+2 );
112 xx++; yy--; 112 xx++; yy--;
113 } 113 }
114 if ( flags & Style_NoChange ) { 114 if ( flags & Style_NoChange ) {
115 p->setPen( mycg.dark() ); 115 p->setPen( mycg.dark() );
116 } else { 116 } else {
117 p->setPen( mycg.text() ); 117 p->setPen( mycg.text() );
118 } 118 }
119 p->drawLineSegments( a ); 119 p->drawLineSegments( a );
120 } 120 }
121 break; 121 break;
122 } 122 }
123 case PE_ExclusiveIndicator: 123 case PE_ExclusiveIndicator:
124 { 124 {
125 static const QCOORD pts1[] = { // dark lines 125 static const QCOORD pts1[] = { // dark lines
126 1,9, 1,8, 0,7, 0,4, 1,3, 1,2, 2,1, 3,1, 4,0, 7,0, 8,1, 9,1 }; 126 1,9, 1,8, 0,7, 0,4, 1,3, 1,2, 2,1, 3,1, 4,0, 7,0, 8,1, 9,1 };
127 static const QCOORD pts4[] = { // white lines 127 static const QCOORD pts4[] = { // white lines
128 2,10, 3,10, 4,11, 7,11, 8,10, 9,10, 10,9, 10,8, 11,7, 128 2,10, 3,10, 4,11, 7,11, 8,10, 9,10, 10,9, 10,8, 11,7,
129 11,4, 10,3, 10,2 }; 129 11,4, 10,3, 10,2 };
130 static const QCOORD pts5[] = { // inner fill 130 static const QCOORD pts5[] = { // inner fill
131 4,2, 7,2, 9,4, 9,7, 7,9, 4,9, 2,7, 2,4 }; 131 4,2, 7,2, 9,4, 9,7, 7,9, 4,9, 2,7, 2,4 };
132 132
133 int x, y, w, h; 133 int x, y, w, h;
134 r.rect( &x, &y, &w, &h ); 134 r.rect( &x, &y, &w, &h );
135 p->eraseRect( x, y, w, h ); 135 p->eraseRect( x, y, w, h );
136 QPointArray a( QCOORDARRLEN(pts1), pts1 ); 136 QPointArray a( QCOORDARRLEN(pts1), pts1 );
137 a.translate( x, y ); 137 a.translate( x, y );
138 p->setPen( cg.dark() ); 138 p->setPen( cg.dark() );
139 p->drawPolyline( a ); 139 p->drawPolyline( a );
140 a.setPoints( QCOORDARRLEN(pts4), pts4 ); 140 a.setPoints( QCOORDARRLEN(pts4), pts4 );
141 a.translate( x, y ); 141 a.translate( x, y );
142 p->setPen( cg.light() ); 142 p->setPen( cg.light() );
143 p->drawPolyline( a ); 143 p->drawPolyline( a );
144 a.setPoints( QCOORDARRLEN(pts5), pts5 ); 144 a.setPoints( QCOORDARRLEN(pts5), pts5 );
145 a.translate( x, y ); 145 a.translate( x, y );
146 QColor fillColor = ( flags&Style_Down || !(flags&Style_Enabled) ) ? cg.button() : cg.base(); 146 QColor fillColor = ( flags&Style_Down || !(flags&Style_Enabled) ) ? cg.button() : cg.base();
147 p->setPen( fillColor ); 147 p->setPen( fillColor );
148 p->setBrush( fillColor ) ; 148 p->setBrush( fillColor ) ;
149 p->drawPolygon( a ); 149 p->drawPolygon( a );
150 if ( flags&Style_On ) { 150 if ( flags&Style_On ) {
151 p->setPen( NoPen ); 151 p->setPen( NoPen );
152 p->setBrush( cg.text() ); 152 p->setBrush( cg.text() );
153 p->drawRect( x+5, y+4, 2, 4 ); 153 p->drawRect( x+5, y+4, 2, 4 );
154 p->drawRect( x+4, y+5, 4, 2 ); 154 p->drawRect( x+4, y+5, 4, 2 );
155 } 155 }
156 break; 156 break;
157 } 157 }
158 default: 158 default:
159 QWindowsStyle::drawPrimitive( pe, p, r, cg, flags, data ); 159 QWindowsStyle::drawPrimitive( pe, p, r, cg, flags, data );
160 break; 160 break;
161 } 161 }
162} 162}
163 163
164void QPEStyle::drawControl( ControlElement ce, QPainter *p, 164void QPEStyle::drawControl( ControlElement ce, QPainter *p,
165 const QWidget *widget, const QRect &r, 165 const QWidget *widget, const QRect &r,
166 const QColorGroup &cg, SFlags how, const QStyleOption &data) const 166 const QColorGroup &cg, SFlags how, const QStyleOption &data) const
167{ 167{
168 switch ( ce ) { 168 switch ( ce ) {
169 case CE_PushButton: 169 case CE_PushButton:
170 { 170 {
171 const QPushButton *btn = (QPushButton*)widget; 171 const QPushButton *btn = (QPushButton*)widget;
172 SFlags flags; 172 SFlags flags;
173 flags = Style_Default; 173 flags = Style_Default;
174 if ( btn->isDown() ) 174 if ( btn->isDown() )
175 flags |= Style_Down; 175 flags |= Style_Down;
176 if ( btn->isOn() ) 176 if ( btn->isOn() )
177 flags |= Style_On; 177 flags |= Style_On;
178 if ( btn->isEnabled() ) 178 if ( btn->isEnabled() )
179 flags |= Style_Enabled; 179 flags |= Style_Enabled;
180 if ( btn->isDefault() ) 180 if ( btn->isDefault() )
181 flags |= Style_Default; 181 flags |= Style_Default;
182 if (! btn->isFlat() && !(flags & Style_Down)) 182 if (! btn->isFlat() && !(flags & Style_Down))
183 flags |= Style_Raised; 183 flags |= Style_Raised;
184 p->setPen( cg.foreground() ); 184 p->setPen( cg.foreground() );
185 p->setBrush( QBrush(cg.button(), NoBrush) ); 185 p->setBrush( QBrush(cg.button(), NoBrush) );
186 QColorGroup mycg( cg ); 186 QColorGroup mycg( cg );
187 if ( flags & Style_On ) { 187 if ( flags & Style_On ) {
188 QBrush fill = QBrush( cg.mid(), Dense4Pattern ); 188 QBrush fill = QBrush( cg.mid(), Dense4Pattern );
189 mycg.setBrush( QColorGroup::Button, fill ); 189 mycg.setBrush( QColorGroup::Button, fill );
190 } 190 }
191 drawPrimitive( PE_ButtonBevel, p, r, mycg, flags, data ); 191 drawPrimitive( PE_ButtonBevel, p, r, mycg, flags, data );
192 break; 192 break;
193 } 193 }
194 case CE_TabBarTab: 194 case CE_TabBarTab:
195 { 195 {
196 if ( !widget || !widget->parentWidget() ) 196 if ( !widget || !widget->parentWidget() )
197 break; 197 break;
198 198
199 const QTabBar *tb = (const QTabBar *) widget; 199 const QTabBar *tb = (const QTabBar *) widget;
200 bool selected = how & Style_Selected; 200 bool selected = how & Style_Selected;
201 201
202 QRect r2(r); 202 QRect r2(r);
203 if ( tb->shape() == QTabBar::RoundedAbove ) { 203 if ( tb->shape() == QTabBar::RoundedAbove ) {
204 p->setPen( cg.light() ); 204 p->setPen( cg.light() );
205 p->drawLine( r2.left(), r2.bottom(), r2.right(), r2.bottom() ); 205 p->drawLine( r2.left(), r2.bottom(), r2.right(), r2.bottom() );
206 if ( r2.left() == 0 ) 206 if ( r2.left() == 0 )
207 p->drawPoint( tb->rect().bottomLeft() ); 207 p->drawPoint( tb->rect().bottomLeft() );
208 else { 208 else {
209 p->setPen( cg.light() ); 209 p->setPen( cg.light() );
210 p->drawLine( r2.left(), r2.bottom(), r2.right(), r2.bottom() ); 210 p->drawLine( r2.left(), r2.bottom(), r2.right(), r2.bottom() );
211 } 211 }
212 212
213 if ( selected ) { 213 if ( selected ) {
214 p->setPen( cg.background() ); 214 p->setPen( cg.background() );
215 p->drawLine( r2.left()+2, r2.top()+1, r2.right()-2, r2.top()+1 ); 215 p->drawLine( r2.left()+2, r2.top()+1, r2.right()-2, r2.top()+1 );
216 p->fillRect( QRect( r2.left()+1, r2.top()+2, r2.width()-2, r2.height()-2), 216 p->fillRect( QRect( r2.left()+1, r2.top()+2, r2.width()-2, r2.height()-2),
217 cg.brush( QColorGroup::Background )); 217 cg.brush( QColorGroup::Background ));
218 } else { 218 } else {
219 r2.setRect( r2.left() + 2, r2.top() + 2, 219 r2.setRect( r2.left() + 2, r2.top() + 2,
220 r2.width() - 4, r2.height() - 2 ); 220 r2.width() - 4, r2.height() - 2 );
221 p->setPen( cg.button() ); 221 p->setPen( cg.button() );
222 p->drawLine( r2.left()+2, r2.top()+1, r2.right()-2, r2.top()+1 ); 222 p->drawLine( r2.left()+2, r2.top()+1, r2.right()-2, r2.top()+1 );
223 p->fillRect( QRect( r2.left()+1, r2.top()+2, r2.width()-2, r2.height()-3), 223 p->fillRect( QRect( r2.left()+1, r2.top()+2, r2.width()-2, r2.height()-3),
224 cg.brush( QColorGroup::Button )); 224 cg.brush( QColorGroup::Button ));
225 225
226 //do shading; will not work for pixmap brushes 226 //do shading; will not work for pixmap brushes
227 QColor bg = cg.button(); 227 QColor bg = cg.button();
228 // int h,s,v; 228 // int h,s,v;
229 // bg.hsv( &h, &s, &v ); 229 // bg.hsv( &h, &s, &v );
230 int n = r2.height()/2; 230 int n = r2.height()/2;
231 int dark = 100; 231 int dark = 100;
232 for ( int i = 1; i < n; i++ ) { 232 for ( int i = 1; i < n; i++ ) {
233 dark = (dark * (100+(i*15)/n) )/100; 233 dark = (dark * (100+(i*15)/n) )/100;
234 p->setPen( bg.dark( dark ) ); 234 p->setPen( bg.dark( dark ) );
235 int y = r2.bottom()-n+i; 235 int y = r2.bottom()-n+i;
236 int x1 = r2.left()+1; 236 int x1 = r2.left()+1;
237 int x2 = r2.right()-1; 237 int x2 = r2.right()-1;
238 p->drawLine( x1, y, x2, y ); 238 p->drawLine( x1, y, x2, y );
239 } 239 }
240 } 240 }
241 241
242 p->setPen( cg.light() ); 242 p->setPen( cg.light() );
243 p->drawLine( r2.left(), r2.bottom()-1, r2.left(), r2.top() + 2 ); 243 p->drawLine( r2.left(), r2.bottom()-1, r2.left(), r2.top() + 2 );
244 p->drawPoint( r2.left()+1, r2.top() + 1 ); 244 p->drawPoint( r2.left()+1, r2.top() + 1 );
245 p->drawLine( r2.left()+2, r2.top(), 245 p->drawLine( r2.left()+2, r2.top(),
246 r2.right() - 2, r2.top() ); 246 r2.right() - 2, r2.top() );
247 247
248 p->setPen( cg.dark() ); 248 p->setPen( cg.dark() );
249 p->drawPoint( r2.right() - 1, r2.top() + 1 ); 249 p->drawPoint( r2.right() - 1, r2.top() + 1 );
250 p->drawLine( r2.right(), r2.top() + 2, r2.right(), r2.bottom() - 1); 250 p->drawLine( r2.right(), r2.top() + 2, r2.right(), r2.bottom() - 1);
251 } else if ( tb->shape() == QTabBar::RoundedBelow ) { 251 } else if ( tb->shape() == QTabBar::RoundedBelow ) {
252 if ( selected ) { 252 if ( selected ) {
253 p->setPen( cg.background() ); 253 p->setPen( cg.background() );
254 p->drawLine( r2.left()+2, r2.bottom()-1, r2.right()-2, r2.bottom()-1 ); 254 p->drawLine( r2.left()+2, r2.bottom()-1, r2.right()-2, r2.bottom()-1 );
255 p->fillRect( QRect( r2.left()+1, r2.top(), r2.width()-2, r2.height()-2), 255 p->fillRect( QRect( r2.left()+1, r2.top(), r2.width()-2, r2.height()-2),
256 tb->palette().normal().brush( QColorGroup::Background )); 256 tb->palette().normal().brush( QColorGroup::Background ));
257 } else { 257 } else {
258 p->setPen( cg.dark() ); 258 p->setPen( cg.dark() );
259 p->drawLine( r2.left(), r2.top(), 259 p->drawLine( r2.left(), r2.top(),
260 r2.right(), r2.top() ); 260 r2.right(), r2.top() );
261 r2.setRect( r2.left() + 2, r2.top(), 261 r2.setRect( r2.left() + 2, r2.top(),
262 r2.width() - 4, r2.height() - 2 ); 262 r2.width() - 4, r2.height() - 2 );
263 p->setPen( cg.button() ); 263 p->setPen( cg.button() );
264 p->drawLine( r2.left()+2, r2.bottom()-1, r2.right()-2, r2.bottom()-1 ); 264 p->drawLine( r2.left()+2, r2.bottom()-1, r2.right()-2, r2.bottom()-1 );
265 p->fillRect( QRect( r2.left()+1, r2.top()+1, r2.width()-2, r2.height()-3), 265 p->fillRect( QRect( r2.left()+1, r2.top()+1, r2.width()-2, r2.height()-3),
266 tb->palette().normal().brush( QColorGroup::Button )); 266 tb->palette().normal().brush( QColorGroup::Button ));
267 } 267 }
268 268
269 p->setPen( cg.dark() ); 269 p->setPen( cg.dark() );
270 p->drawLine( r2.right(), r2.top(), 270 p->drawLine( r2.right(), r2.top(),
271 r2.right(), r2.bottom() - 2 ); 271 r2.right(), r2.bottom() - 2 );
272 p->drawPoint( r2.right() - 1, r2.bottom() - 1 ); 272 p->drawPoint( r2.right() - 1, r2.bottom() - 1 );
273 p->drawLine( r2.right() - 2, r2.bottom(), 273 p->drawLine( r2.right() - 2, r2.bottom(),
274 r2.left() + 2, r2.bottom() ); 274 r2.left() + 2, r2.bottom() );
275 275
276 p->setPen( cg.light() ); 276 p->setPen( cg.light() );
277 p->drawLine( r2.left(), r2.top()+1, 277 p->drawLine( r2.left(), r2.top()+1,
278 r2.left(), r2.bottom() - 2 ); 278 r2.left(), r2.bottom() - 2 );
279 p->drawPoint( r2.left() + 1, r2.bottom() - 1 ); 279 p->drawPoint( r2.left() + 1, r2.bottom() - 1 );
280 if ( r2.left() == 0 ) 280 if ( r2.left() == 0 )
281 p->drawPoint( tb->rect().topLeft() ); 281 p->drawPoint( tb->rect().topLeft() );
282 282
283 } else { 283 } else {
284 QCommonStyle::drawControl( ce, p, widget, r, cg, how, data ); 284 QCommonStyle::drawControl( ce, p, widget, r, cg, how, data );
285 } 285 }
286 break; 286 break;
287 } 287 }
288 default: 288 default:
289 QWindowsStyle::drawControl( ce, p, widget, r, cg, how, data ); 289 QWindowsStyle::drawControl( ce, p, widget, r, cg, how, data );
290 break; 290 break;
291 } 291 }
292} 292}
293 293
294void QPEStyle::drawComplexControl( ComplexControl control, QPainter *p, 294void QPEStyle::drawComplexControl( ComplexControl control, QPainter *p,
295 const QWidget *widget, const QRect &r, 295 const QWidget *widget, const QRect &r,
296 const QColorGroup &cg, SFlags how, 296 const QColorGroup &cg, SFlags how,
297 SCFlags sub, SCFlags subActive, const QStyleOption &data) const 297 SCFlags sub, SCFlags subActive, const QStyleOption &data) const
298{ 298{
299 switch ( control ) { 299 switch ( control ) {
300 case CC_ComboBox: 300 case CC_ComboBox:
301 if ( sub & SC_ComboBoxArrow ) { 301 if ( sub & SC_ComboBoxArrow ) {
302 SFlags flags = Style_Default; 302 SFlags flags = Style_Default;
303 303
304 drawPrimitive( PE_ButtonBevel, p, r, cg, flags, data ); 304 drawPrimitive( PE_ButtonBevel, p, r, cg, flags, data );
305 305
306 QRect ar = 306 QRect ar =
307 QStyle::visualRect( querySubControlMetrics( CC_ComboBox, widget, 307 QStyle::visualRect( querySubControlMetrics( CC_ComboBox, widget,
308 SC_ComboBoxArrow ), widget ); 308 SC_ComboBoxArrow ), widget );
309 309
310 if ( subActive == SC_ComboBoxArrow ) { 310 if ( subActive == SC_ComboBoxArrow ) {
311 p->setPen( cg.dark() ); 311 p->setPen( cg.dark() );
312 p->setBrush( cg.brush( QColorGroup::Button ) ); 312 p->setBrush( cg.brush( QColorGroup::Button ) );
313 p->drawRect( ar ); 313 p->drawRect( ar );
314 } 314 }
315 315
316 ar.addCoords( 2, 2, -2, -2 ); 316 ar.addCoords( 2, 2, -2, -2 );
317 if ( widget->isEnabled() ) 317 if ( widget->isEnabled() )
318 flags |= Style_Enabled; 318 flags |= Style_Enabled;
319 319
320 if ( subActive & Style_Sunken ) { 320 if ( subActive & Style_Sunken ) {
321 flags |= Style_Sunken; 321 flags |= Style_Sunken;
322 } 322 }
323 drawPrimitive( PE_ArrowDown, p, ar, cg, flags ); 323 drawPrimitive( PE_ArrowDown, p, ar, cg, flags );
324 } 324 }
325 325
326 if ( sub & SC_ComboBoxEditField ) { 326 if ( sub & SC_ComboBoxEditField ) {
327 const QComboBox * cb = (const QComboBox *) widget; 327 const QComboBox * cb = (const QComboBox *) widget;
328 QRect re = 328 QRect re =
329 QStyle::visualRect( querySubControlMetrics( CC_ComboBox, widget, 329 QStyle::visualRect( querySubControlMetrics( CC_ComboBox, widget,
330 SC_ComboBoxEditField ), widget ); 330 SC_ComboBoxEditField ), widget );
331 if ( cb->hasFocus() && !cb->editable() ) 331 if ( cb->hasFocus() && !cb->editable() )
332 p->fillRect( re.x(), re.y(), re.width(), re.height(), 332 p->fillRect( re.x(), re.y(), re.width(), re.height(),
333 cg.brush( QColorGroup::Highlight ) ); 333 cg.brush( QColorGroup::Highlight ) );
334 334
335 if ( cb->hasFocus() ) { 335 if ( cb->hasFocus() ) {
336 p->setPen( cg.highlightedText() ); 336 p->setPen( cg.highlightedText() );
337 p->setBackgroundColor( cg.highlight() ); 337 p->setBackgroundColor( cg.highlight() );
338 338
339 } else { 339 } else {
340 p->setPen( cg.text() ); 340 p->setPen( cg.text() );
341 p->setBackgroundColor( cg.background() ); 341 p->setBackgroundColor( cg.background() );
342 } 342 }
343 343
344 if ( cb->hasFocus() && !cb->editable() ) { 344 if ( cb->hasFocus() && !cb->editable() ) {
345 QRect re = 345 QRect re =
346 QStyle::visualRect( subRect( SR_ComboBoxFocusRect, cb ), widget ); 346 QStyle::visualRect( subRect( SR_ComboBoxFocusRect, cb ), widget );
347 drawPrimitive( PE_FocusRect, p, re, cg, Style_FocusAtBorder, QStyleOption(cg.highlight())); 347 drawPrimitive( PE_FocusRect, p, re, cg, Style_FocusAtBorder, QStyleOption(cg.highlight()));
348 } 348 }
349 } 349 }
350 break; 350 break;
351 default: 351 default:
352 QWindowsStyle::drawComplexControl( control, p, widget, r, cg, how, 352 QWindowsStyle::drawComplexControl( control, p, widget, r, cg, how,
353 sub, subActive, data ); 353 sub, subActive, data );
354 break; 354 break;
355 } 355 }
356} 356}
357 357
358int QPEStyle::pixelMetric( PixelMetric metric, const QWidget *widget ) const 358int QPEStyle::pixelMetric( PixelMetric metric, const QWidget *widget ) const
359{ 359{
360 int ret; 360 int ret;
361 switch( metric ) { 361 switch( metric ) {
362 case PM_ButtonMargin: 362 case PM_ButtonMargin:
363 ret = 2; 363 ret = 2;
364 break; 364 break;
365 case PM_DefaultFrameWidth: 365 case PM_DefaultFrameWidth:
366 ret = 1; 366 ret = 1;
367 break; 367 break;
368 case PM_ButtonDefaultIndicator: 368 case PM_ButtonDefaultIndicator:
369 ret = 2; 369 ret = 2;
370 break; 370 break;
371 case PM_ButtonShiftHorizontal: 371 case PM_ButtonShiftHorizontal:
372 case PM_ButtonShiftVertical: 372 case PM_ButtonShiftVertical:
373 ret = -1; 373 ret = -1;
374 break; 374 break;
375 case PM_IndicatorWidth: 375 case PM_IndicatorWidth:
376 ret = 15; 376 ret = 15;
377 break; 377 break;
378 case PM_IndicatorHeight: 378 case PM_IndicatorHeight:
379 ret = 13; 379 ret = 13;
380 break; 380 break;
381 case PM_ExclusiveIndicatorHeight: 381 case PM_ExclusiveIndicatorHeight:
382 case PM_ExclusiveIndicatorWidth: 382 case PM_ExclusiveIndicatorWidth:
383 ret = 15; 383 ret = 15;
384 break; 384 break;
385 case PM_ScrollBarExtent: 385 case PM_ScrollBarExtent:
386 ret = 13; 386 ret = 13;
387 break; 387 break;
388 case PM_SliderLength: 388 case PM_SliderLength:
389 ret = 12; 389 ret = 12;
390 break; 390 break;
391 default: 391 default:
392 ret = QWindowsStyle::pixelMetric( metric, widget ); 392 ret = QWindowsStyle::pixelMetric( metric, widget );
393 break; 393 break;
394 } 394 }
395 return ret; 395 return ret;
396} 396}
397 397
398QSize QPEStyle::sizeFromContents( ContentsType contents, const QWidget *widget, 398QSize QPEStyle::sizeFromContents( ContentsType contents, const QWidget *widget,
399 const QSize &contentsSize, const QStyleOption &data) const 399 const QSize &contentsSize, const QStyleOption &data) const
400{ 400{
401 QSize sz(contentsSize); 401 QSize sz(contentsSize);
402 402
403 switch ( contents ) { 403 switch ( contents ) {
404 case CT_PopupMenuItem: 404 case CT_PopupMenuItem:
405 { 405 {
406 if ( !widget || data.isDefault() ) 406 if ( !widget || data.isDefault() )
407 break; 407 break;
408 sz = QWindowsStyle::sizeFromContents( contents, widget, contentsSize, data ); 408 sz = QWindowsStyle::sizeFromContents( contents, widget, contentsSize, data );
409 sz = QSize( sz.width(), sz.height()-2 ); 409 sz = QSize( sz.width(), sz.height()-2 );
410 break; 410 break;
411 } 411 }
412 default: 412 default:
413 sz = QWindowsStyle::sizeFromContents( contents, widget, contentsSize, data ); 413 sz = QWindowsStyle::sizeFromContents( contents, widget, contentsSize, data );
414 break; 414 break;
415 } 415 }
416 416
417 return sz; 417 return sz;
418} 418}
419 419
420#else 420#else
421 421
422#include <qfontmetrics.h> 422#include <qfontmetrics.h>
423#include <qpalette.h> 423#include <qpalette.h>
424#include <qdrawutil.h> 424#include <qdrawutil.h>
425#include <qscrollbar.h> 425#include <qscrollbar.h>
426#include <qbutton.h> 426#include <qbutton.h>
427#include <qframe.h> 427#include <qframe.h>
428#include <qtabbar.h> 428#include <qtabbar.h>
429 429
430#define INCLUDE_MENUITEM_DEF 430#define INCLUDE_MENUITEM_DEF
431#include <qmenudata.h> 431#include <qmenudata.h>
432 432
433QPEStyle::QPEStyle() 433QPEStyle::QPEStyle()
434{ 434{
435#if QT_VERSION < 300 435#if QT_VERSION < 300
436 setButtonMargin(buttonMargin()); 436 setButtonMargin(buttonMargin());
437 setScrollBarExtent(scrollBarExtent().width(),scrollBarExtent().height()); 437 setScrollBarExtent(scrollBarExtent().width(),scrollBarExtent().height());
438#endif 438#endif
439} 439}
440 440
441QPEStyle::~QPEStyle() 441QPEStyle::~QPEStyle()
442{ 442{
443} 443}
444 444
445int QPEStyle::buttonMargin() const 445int QPEStyle::buttonMargin() const
446{ 446{
447 return 2; 447 return 2;
448} 448}
449 449
450QSize QPEStyle::scrollBarExtent() const 450QSize QPEStyle::scrollBarExtent() const
451{ 451{
452 return QSize(13,13); 452 return QSize(13,13);
453} 453}
454 454
455void QPEStyle::polish ( QPalette & ) 455void QPEStyle::polish ( QPalette & )
456{ 456{
457} 457}
458 458
459void QPEStyle::polish( QWidget *w ) 459void QPEStyle::polish( QWidget *w )
460{ 460{
461 if ( w->inherits( "QListBox" ) || 461 if ( w->inherits( "QListBox" ) ||
462 w->inherits( "QListView" ) || 462 w->inherits( "QListView" ) ||
463 w->inherits( "QPopupMenu" ) || 463 w->inherits( "QPopupMenu" ) ||
464 w->inherits( "QSpinBox" ) ) { 464 w->inherits( "QSpinBox" ) ) {
465 QFrame *f = (QFrame *)w; 465 QFrame *f = (QFrame *)w;
466 f->setFrameShape( QFrame::StyledPanel ); 466 f->setFrameShape( QFrame::StyledPanel );
467 f->setLineWidth( 1 ); 467 f->setLineWidth( 1 );
468 } 468 }
469} 469}
470 470
471void QPEStyle::unPolish( QWidget *w ) 471void QPEStyle::unPolish( QWidget *w )
472{ 472{
473 if ( w->inherits( "QListBox" ) || 473 if ( w->inherits( "QListBox" ) ||
474 w->inherits( "QListView" ) || 474 w->inherits( "QListView" ) ||
475 w->inherits( "QPopupMenu" ) || 475 w->inherits( "QPopupMenu" ) ||
476 w->inherits( "QSpinBox" ) ) { 476 w->inherits( "QSpinBox" ) ) {
477 QFrame *f = (QFrame *)w; 477 QFrame *f = (QFrame *)w;
478 f->setFrameShape( QFrame::StyledPanel ); 478 f->setFrameShape( QFrame::StyledPanel );
479 f->setLineWidth( 2 ); 479 f->setLineWidth( 2 );
480 } 480 }
481} 481}
482 482
483int QPEStyle::defaultFrameWidth() const 483int QPEStyle::defaultFrameWidth() const
484{ 484{
485 return 1; 485 return 1;
486} 486}
487 487
488void QPEStyle::drawPanel ( QPainter * p, int x, int y, int w, int h, 488void QPEStyle::drawPanel ( QPainter * p, int x, int y, int w, int h,
489 const QColorGroup &g, bool sunken, int lineWidth, const QBrush * fill ) 489 const QColorGroup &g, bool sunken, int lineWidth, const QBrush * fill )
490{ 490{
491 qDrawShadePanel( p, QRect(x, y, w, h), g, sunken, lineWidth, fill ); 491 qDrawShadePanel( p, QRect(x, y, w, h), g, sunken, lineWidth, fill );
492} 492}
493 493
494void QPEStyle::drawButton( QPainter *p, int x, int y, int w, int h, 494void QPEStyle::drawButton( QPainter *p, int x, int y, int w, int h,
495 const QColorGroup &g, bool sunken, const QBrush* fill ) 495 const QColorGroup &g, bool sunken, const QBrush* fill )
496{ 496{
497 QPen oldPen = p->pen(); 497 QPen oldPen = p->pen();
498 if ( sunken ) 498 if ( sunken )
499 p->setPen( g.dark() ); 499 p->setPen( g.dark() );
500 else 500 else
501 p->setPen( g.light() ); 501 p->setPen( g.light() );
502 502
503 int x2 = x+w-1; 503 int x2 = x+w-1;
504 int y2 = y+h-1; 504 int y2 = y+h-1;
505 505
506 p->drawLine( x, y, x, y2 ); 506 p->drawLine( x, y, x, y2 );
507 p->drawLine( x, y, x2, y ); 507 p->drawLine( x, y, x2, y );
508 508
509 if ( sunken ) 509 if ( sunken )
510 p->setPen( g.light() ); 510 p->setPen( g.light() );
511 else 511 else
512 p->setPen( g.dark() ); 512 p->setPen( g.dark() );
513 513
514 p->drawLine( x2, y, x2, y2 ); 514 p->drawLine( x2, y, x2, y2 );
515 p->drawLine( x, y2, x2, y2 ); 515 p->drawLine( x, y2, x2, y2 );
516 p->setPen( oldPen ); 516 p->setPen( oldPen );
517 517
518 p->fillRect( x+1, y+1, w-2, h-2, fill?(*fill):g.brush(QColorGroup::Button) ); 518 p->fillRect( x+1, y+1, w-2, h-2, fill?(*fill):g.brush(QColorGroup::Button) );
519} 519}
520 520
521void QPEStyle::drawButtonMask ( QPainter * p, int x, int y, int w, int h ) 521void QPEStyle::drawButtonMask ( QPainter * p, int x, int y, int w, int h )
522{ 522{
523 p->fillRect( x, y, w, h, color1 ); 523 p->fillRect( x, y, w, h, color1 );
524} 524}
525 525
526void QPEStyle::drawBevelButton( QPainter *p, int x, int y, int w, int h, 526void QPEStyle::drawBevelButton( QPainter *p, int x, int y, int w, int h,
527 const QColorGroup &g, bool sunken, const QBrush* fill ) 527 const QColorGroup &g, bool sunken, const QBrush* fill )
528{ 528{
529 drawButton( p, x, y, w, h, g, sunken, fill ); 529 drawButton( p, x, y, w, h, g, sunken, fill );
530} 530}
531 531
532QRect QPEStyle::comboButtonRect( int x, int y, int w, int h) 532QRect QPEStyle::comboButtonRect( int x, int y, int w, int h)
533{ 533{
534 return QRect(x+1, y+1, w-2-14, h-2); 534 return QRect(x+1, y+1, w-2-14, h-2);
535} 535}
536 536
537 537
538QRect QPEStyle::comboButtonFocusRect( int x, int y, int w, int h) 538QRect QPEStyle::comboButtonFocusRect( int x, int y, int w, int h)
539{ 539{
540 return QRect(x+2, y+2, w-4-14, h-4); 540 return QRect(x+2, y+2, w-4-14, h-4);
541} 541}
542 542
543void QPEStyle::drawComboButton( QPainter *p, int x, int y, int w, int h, 543void QPEStyle::drawComboButton( QPainter *p, int x, int y, int w, int h,
544 const QColorGroup &g, bool sunken, 544 const QColorGroup &g, bool sunken,
545 bool /*editable*/, 545 bool /*editable*/,
546 bool enabled, 546 bool enabled,
547 const QBrush *fill ) 547 const QBrush *fill )
548{ 548{
549 drawBevelButton( p, x, y, w, h, g, FALSE, fill ); 549 drawBevelButton( p, x, y, w, h, g, FALSE, fill );
550 drawBevelButton( p, x+w-14, y, 14, h, g, sunken, fill ); 550 drawBevelButton( p, x+w-14, y, 14, h, g, sunken, fill );
551 drawArrow( p, QStyle::DownArrow, sunken, 551 drawArrow( p, QStyle::DownArrow, sunken,
552 x+w-14+ 2, y+ 2, 14- 4, h- 4, g, enabled, 552 x+w-14+ 2, y+ 2, 14- 4, h- 4, g, enabled,
553 &g.brush( QColorGroup::Button ) ); 553 &g.brush( QColorGroup::Button ) );
554 554
555} 555}
556 556
557 557
558void QPEStyle::drawExclusiveIndicator ( QPainter * p, int x, int y, int w, 558void QPEStyle::drawExclusiveIndicator ( QPainter * p, int x, int y, int w,
559 int h, const QColorGroup & g, bool on, bool down, bool enabled ) 559 int h, const QColorGroup & g, bool on, bool down, bool enabled )
560{ 560{
561 static const QCOORD pts1[] = { // dark lines 561 static const QCOORD pts1[] = { // dark lines
562 1,9, 1,8, 0,7, 0,4, 1,3, 1,2, 2,1, 3,1, 4,0, 7,0, 8,1, 9,1 }; 562 1,9, 1,8, 0,7, 0,4, 1,3, 1,2, 2,1, 3,1, 4,0, 7,0, 8,1, 9,1 };
563 static const QCOORD pts4[] = { // white lines 563 static const QCOORD pts4[] = { // white lines
564 2,10, 3,10, 4,11, 7,11, 8,10, 9,10, 10,9, 10,8, 11,7, 564 2,10, 3,10, 4,11, 7,11, 8,10, 9,10, 10,9, 10,8, 11,7,
565 11,4, 10,3, 10,2 }; 565 11,4, 10,3, 10,2 };
566 static const QCOORD pts5[] = { // inner fill 566 static const QCOORD pts5[] = { // inner fill
567 4,2, 7,2, 9,4, 9,7, 7,9, 4,9, 2,7, 2,4 }; 567 4,2, 7,2, 9,4, 9,7, 7,9, 4,9, 2,7, 2,4 };
568 568
569 p->eraseRect( x, y, w, h ); 569 p->eraseRect( x, y, w, h );
570 QPointArray a( QCOORDARRLEN(pts1), pts1 ); 570 QPointArray a( QCOORDARRLEN(pts1), pts1 );
571 a.translate( x, y ); 571 a.translate( x, y );
572 p->setPen( g.dark() ); 572 p->setPen( g.dark() );
573 p->drawPolyline( a ); 573 p->drawPolyline( a );
574 a.setPoints( QCOORDARRLEN(pts4), pts4 ); 574 a.setPoints( QCOORDARRLEN(pts4), pts4 );
575 a.translate( x, y ); 575 a.translate( x, y );
576 p->setPen( g.light() ); 576 p->setPen( g.light() );
577 p->drawPolyline( a ); 577 p->drawPolyline( a );
578 a.setPoints( QCOORDARRLEN(pts5), pts5 ); 578 a.setPoints( QCOORDARRLEN(pts5), pts5 );
579 a.translate( x, y ); 579 a.translate( x, y );
580 QColor fillColor = ( down || !enabled ) ? g.button() : g.base(); 580 QColor fillColor = ( down || !enabled ) ? g.button() : g.base();
581 p->setPen( fillColor ); 581 p->setPen( fillColor );
582 p->setBrush( fillColor ) ; 582 p->setBrush( fillColor ) ;
583 p->drawPolygon( a ); 583 p->drawPolygon( a );
584 if ( on ) { 584 if ( on ) {
585 p->setPen( NoPen ); 585 p->setPen( NoPen );
586 p->setBrush( g.text() ); 586 p->setBrush( g.text() );
587 p->drawRect( x+5, y+4, 2, 4 ); 587 p->drawRect( x+5, y+4, 2, 4 );
588 p->drawRect( x+4, y+5, 4, 2 ); 588 p->drawRect( x+4, y+5, 4, 2 );
589 } 589 }
590} 590}
591 591
592void QPEStyle::drawIndicator ( QPainter * p, int x, int y, int w, int h, 592void QPEStyle::drawIndicator ( QPainter * p, int x, int y, int w, int h,
593 const QColorGroup & g, int state, bool down, bool enabled ) 593 const QColorGroup & g, int state, bool down, bool enabled )
594{ 594{
595 595
596 QBrush fill; 596 QBrush fill;
597 if ( state == QButton::NoChange ) { 597 if ( state == QButton::NoChange ) {
598 QBrush b = p->brush(); 598 QBrush b = p->brush();
599 QColor c = p->backgroundColor(); 599 QColor c = p->backgroundColor();
600 p->setBackgroundMode( TransparentMode ); 600 p->setBackgroundMode( TransparentMode );
601 p->setBackgroundColor( green ); 601 p->setBackgroundColor( green );
602 fill = QBrush(g.base(), Dense4Pattern); 602 fill = QBrush(g.base(), Dense4Pattern);
603 p->setBackgroundColor( c ); 603 p->setBackgroundColor( c );
604 p->setBrush( b ); 604 p->setBrush( b );
605 } else if ( down ) 605 } else if ( down )
606 fill = g.brush( QColorGroup::Button ); 606 fill = g.brush( QColorGroup::Button );
607 else 607 else
608 fill = g.brush( enabled ? QColorGroup::Base : QColorGroup::Background ); 608 fill = g.brush( enabled ? QColorGroup::Base : QColorGroup::Background );
609 drawPanel( p, x, y, w, h, g, TRUE, 1, &fill ); 609 drawPanel( p, x, y, w, h, g, TRUE, 1, &fill );
610 if ( state != QButton::Off ) { 610 if ( state != QButton::Off ) {
611 QPointArray a( 7*2 ); 611 QPointArray a( 7*2 );
612 int i, xx, yy; 612 int i, xx, yy;
613 xx = x+3; 613 xx = x+3;
614 yy = y+5; 614 yy = y+5;
615 for ( i=0; i<3; i++ ) { 615 for ( i=0; i<3; i++ ) {
616 a.setPoint( 2*i, xx, yy ); 616 a.setPoint( 2*i, xx, yy );
617 a.setPoint( 2*i+1, xx, yy+2 ); 617 a.setPoint( 2*i+1, xx, yy+2 );
618 xx++; yy++; 618 xx++; yy++;
619 } 619 }
620 yy -= 2; 620 yy -= 2;
621 for ( i=3; i<7; i++ ) { 621 for ( i=3; i<7; i++ ) {
622 a.setPoint( 2*i, xx, yy ); 622 a.setPoint( 2*i, xx, yy );
623 a.setPoint( 2*i+1, xx, yy+2 ); 623 a.setPoint( 2*i+1, xx, yy+2 );
624 xx++; yy--; 624 xx++; yy--;
625 } 625 }
626 if ( state == QButton::NoChange ) { 626 if ( state == QButton::NoChange ) {
627 p->setPen( g.dark() ); 627 p->setPen( g.dark() );
628 } else { 628 } else {
629 p->setPen( g.text() ); 629 p->setPen( g.text() );
630 } 630 }
631 p->drawLineSegments( a ); 631 p->drawLineSegments( a );
632 } 632 }
633} 633}
634 634
635 #define HORIZONTAL(sb->orientation() == QScrollBar::Horizontal) 635 #define HORIZONTAL(sb->orientation() == QScrollBar::Horizontal)
636 #define VERTICAL!HORIZONTAL 636 #define VERTICAL!HORIZONTAL
637 #define MOTIF_BORDER2 637 #define MOTIF_BORDER2
638 #define SLIDER_MIN9 // ### motif says 6 but that's too small 638 #define SLIDER_MIN9 // ### motif says 6 but that's too small
639 639
640/*! \reimp */ 640/*! \reimp */
641 641
642void QPEStyle::scrollBarMetrics( const QScrollBar* sb, int &sliderMin, int &sliderMax, int &sliderLength, int& buttonDim ) 642void QPEStyle::scrollBarMetrics( const QScrollBar* sb, int &sliderMin, int &sliderMax, int &sliderLength, int& buttonDim )
643{ 643{
644 int maxLength; 644 int maxLength;
645 int length = HORIZONTAL ? sb->width() : sb->height(); 645 int length = HORIZONTAL ? sb->width() : sb->height();
646 int extent = HORIZONTAL ? sb->height() : sb->width(); 646 int extent = HORIZONTAL ? sb->height() : sb->width();
647 647
648 if ( length > (extent - 1)*2 ) 648 if ( length > (extent - 1)*2 )
649 buttonDim = extent; 649 buttonDim = extent;
650 else 650 else
651 buttonDim = length/2 - 1; 651 buttonDim = length/2 - 1;
652 652
653 sliderMin = 0; 653 sliderMin = 0;
654 maxLength = length - buttonDim*2; 654 maxLength = length - buttonDim*2;
655 655
656 if ( sb->maxValue() == sb->minValue() ) { 656 if ( sb->maxValue() == sb->minValue() ) {
657 sliderLength = maxLength; 657 sliderLength = maxLength;
658 } else { 658 } else {
659 sliderLength = (sb->pageStep()*maxLength)/ 659 sliderLength = (sb->pageStep()*maxLength)/
660 (sb->maxValue()-sb->minValue()+sb->pageStep()); 660 (sb->maxValue()-sb->minValue()+sb->pageStep());
661 uint range = sb->maxValue()-sb->minValue(); 661 uint range = sb->maxValue()-sb->minValue();
662 if ( sliderLength < SLIDER_MIN || range > INT_MAX/2 ) 662 if ( sliderLength < SLIDER_MIN || range > INT_MAX/2 )
663 sliderLength = SLIDER_MIN; 663 sliderLength = SLIDER_MIN;
664 if ( sliderLength > maxLength ) 664 if ( sliderLength > maxLength )
665 sliderLength = maxLength; 665 sliderLength = maxLength;
666 } 666 }
667 667
668 sliderMax = sliderMin + maxLength - sliderLength; 668 sliderMax = sliderMin + maxLength - sliderLength;
669} 669}
670 670
671/*!\reimp 671/*!\reimp
672 */ 672 */
673QStyle::ScrollControl QPEStyle::scrollBarPointOver( const QScrollBar* sb, int sliderStart, const QPoint& p ) 673QStyle::ScrollControl QPEStyle::scrollBarPointOver( const QScrollBar* sb, int sliderStart, const QPoint& p )
674{ 674{
675 if ( !sb->rect().contains( p ) ) 675 if ( !sb->rect().contains( p ) )
676 return NoScroll; 676 return NoScroll;
677 int sliderMin, sliderMax, sliderLength, buttonDim, pos; 677 int sliderMin, sliderMax, sliderLength, buttonDim, pos;
678 scrollBarMetrics( sb, sliderMin, sliderMax, sliderLength, buttonDim ); 678 scrollBarMetrics( sb, sliderMin, sliderMax, sliderLength, buttonDim );
679 679
680 if (sb->orientation() == QScrollBar::Horizontal) 680 if (sb->orientation() == QScrollBar::Horizontal)
681 pos = p.x(); 681 pos = p.x();
682 else 682 else
683 pos = p.y(); 683 pos = p.y();
684 684
685 if (pos < sliderStart) 685 if (pos < sliderStart)
686 return SubPage; 686 return SubPage;
687 if (pos < sliderStart + sliderLength) 687 if (pos < sliderStart + sliderLength)
688 return Slider; 688 return Slider;
689 if (pos < sliderMax + sliderLength) 689 if (pos < sliderMax + sliderLength)
690 return AddPage; 690 return AddPage;
691 if (pos < sliderMax + sliderLength + buttonDim) 691 if (pos < sliderMax + sliderLength + buttonDim)
692 return SubLine; 692 return SubLine;
693 return AddLine; 693 return AddLine;
694} 694}
695 695
696/*! \reimp */ 696/*! \reimp */
697 697
698void QPEStyle::drawScrollBarControls( QPainter* p, const QScrollBar* sb, int sliderStart, uint controls, uint activeControl ) 698void QPEStyle::drawScrollBarControls( QPainter* p, const QScrollBar* sb, int sliderStart, uint controls, uint activeControl )
699{ 699{
700#define ADD_LINE_ACTIVE ( activeControl == AddLine ) 700#define ADD_LINE_ACTIVE ( activeControl == AddLine )
701#define SUB_LINE_ACTIVE ( activeControl == SubLine ) 701#define SUB_LINE_ACTIVE ( activeControl == SubLine )
702 QColorGroup g = sb->colorGroup(); 702 QColorGroup g = sb->colorGroup();
703 703
704 int sliderMin, sliderMax, sliderLength, buttonDim; 704 int sliderMin, sliderMax, sliderLength, buttonDim;
705 scrollBarMetrics( sb, sliderMin, sliderMax, sliderLength, buttonDim ); 705 scrollBarMetrics( sb, sliderMin, sliderMax, sliderLength, buttonDim );
706 706
707 if ( controls == (AddLine | SubLine | AddPage | SubPage | Slider | First | Last ) ) 707 if ( controls == (AddLine | SubLine | AddPage | SubPage | Slider | First | Last ) )
708 p->fillRect( 0, 0, sb->width(), sb->height(), g.brush( QColorGroup::Mid )); 708 p->fillRect( 0, 0, sb->width(), sb->height(), g.brush( QColorGroup::Mid ));
709 709
710 if (sliderStart > sliderMax) { // sanity check 710 if (sliderStart > sliderMax) { // sanity check
711 sliderStart = sliderMax; 711 sliderStart = sliderMax;
712 } 712 }
713 713
714 int dimB = buttonDim; 714 int dimB = buttonDim;
715 QRect addB; 715 QRect addB;
716 QRect subB; 716 QRect subB;
717 QRect addPageR; 717 QRect addPageR;
718 QRect subPageR; 718 QRect subPageR;
719 QRect sliderR; 719 QRect sliderR;
720 int addX, addY, subX, subY; 720 int addX, addY, subX, subY;
721 int length = HORIZONTAL ? sb->width() : sb->height(); 721 int length = HORIZONTAL ? sb->width() : sb->height();
722 int extent = HORIZONTAL ? sb->height() : sb->width(); 722 int extent = HORIZONTAL ? sb->height() : sb->width();
723 723
724 if ( HORIZONTAL ) { 724 if ( HORIZONTAL ) {
725 subY = addY = ( extent - dimB ) / 2; 725 subY = addY = ( extent - dimB ) / 2;
726 subX = length - dimB - dimB; 726 subX = length - dimB - dimB;
727 addX = length - dimB; 727 addX = length - dimB;
728 } else { 728 } else {
729 subX = addX = ( extent - dimB ) / 2; 729 subX = addX = ( extent - dimB ) / 2;
730 subY = length - dimB - dimB; 730 subY = length - dimB - dimB;
731 addY = length - dimB; 731 addY = length - dimB;
732 } 732 }
733 733
734 int sliderEnd = sliderStart + sliderLength; 734 int sliderEnd = sliderStart + sliderLength;
735 int sliderW = extent; 735 int sliderW = extent;
736 if ( HORIZONTAL ) { 736 if ( HORIZONTAL ) {
737 subB.setRect( subX,subY+1,dimB,dimB-1 ); 737 subB.setRect( subX,subY+1,dimB,dimB-1 );
738 addB.setRect( addX,addY+1,dimB,dimB-1 ); 738 addB.setRect( addX,addY+1,dimB,dimB-1 );
739 739
740 subPageR.setRect( 0, 0, 740 subPageR.setRect( 0, 0,
741 sliderStart+1, sliderW ); 741 sliderStart+1, sliderW );
742 addPageR.setRect( sliderEnd-1, 0, subX - sliderEnd+1, sliderW ); 742 addPageR.setRect( sliderEnd-1, 0, subX - sliderEnd+1, sliderW );
743 sliderR .setRect( sliderStart, 1, sliderLength, sliderW-1 ); 743 sliderR .setRect( sliderStart, 1, sliderLength, sliderW-1 );
744 744
745 } else { 745 } else {
746 subB.setRect( subX+1,subY,dimB-1,dimB ); 746 subB.setRect( subX+1,subY,dimB-1,dimB );
747 addB.setRect( addX+1,addY,dimB-1,dimB ); 747 addB.setRect( addX+1,addY,dimB-1,dimB );
748 748
749 subPageR.setRect( 0, 0, sliderW, 749 subPageR.setRect( 0, 0, sliderW,
750 sliderStart+1 ); 750 sliderStart+1 );
751 addPageR.setRect( 0, sliderEnd-1, sliderW, subY - sliderEnd+1 ); 751 addPageR.setRect( 0, sliderEnd-1, sliderW, subY - sliderEnd+1 );
752 sliderR .setRect( 1, sliderStart, sliderW-1, sliderLength ); 752 sliderR .setRect( 1, sliderStart, sliderW-1, sliderLength );
753 } 753 }
754 754
755 bool maxedOut = (sb->maxValue() == sb->minValue()); 755 bool maxedOut = (sb->maxValue() == sb->minValue());
756 if ( controls & AddLine ) { 756 if ( controls & AddLine ) {
757 drawBevelButton( p, addB.x(), addB.y(), 757 drawBevelButton( p, addB.x(), addB.y(),
758 addB.width(), addB.height(), g, 758 addB.width(), addB.height(), g,
759 ADD_LINE_ACTIVE); 759 ADD_LINE_ACTIVE);
760 p->setPen(g.shadow()); 760 p->setPen(g.shadow());
761 drawArrow( p, VERTICAL ? DownArrow : RightArrow, 761 drawArrow( p, VERTICAL ? DownArrow : RightArrow,
762 FALSE, addB.x()+2, addB.y()+2, 762 FALSE, addB.x()+2, addB.y()+2,
763 addB.width()-4, addB.height()-4, g, !maxedOut, 763 addB.width()-4, addB.height()-4, g, !maxedOut,
764 &g.brush( QColorGroup::Button )); 764 &g.brush( QColorGroup::Button ));
765 } 765 }
766 if ( controls & SubLine ) { 766 if ( controls & SubLine ) {
767 drawBevelButton( p, subB.x(), subB.y(), 767 drawBevelButton( p, subB.x(), subB.y(),
768 subB.width(), subB.height(), g, 768 subB.width(), subB.height(), g,
769 SUB_LINE_ACTIVE ); 769 SUB_LINE_ACTIVE );
770 p->setPen(g.shadow()); 770 p->setPen(g.shadow());
771 drawArrow( p, VERTICAL ? UpArrow : LeftArrow, 771 drawArrow( p, VERTICAL ? UpArrow : LeftArrow,
772 FALSE, subB.x()+2, subB.y()+2, 772 FALSE, subB.x()+2, subB.y()+2,
773 subB.width()-4, subB.height()-4, g, !maxedOut, 773 subB.width()-4, subB.height()-4, g, !maxedOut,
774 &g.brush( QColorGroup::Button )); 774 &g.brush( QColorGroup::Button ));
775 } 775 }
776 776
777 777
778 if ( controls & SubPage ) 778 if ( controls & SubPage )
779 p->fillRect( subPageR.x(), subPageR.y(), subPageR.width(), 779 p->fillRect( subPageR.x(), subPageR.y(), subPageR.width(),
780 subPageR.height(), g.brush( QColorGroup::Mid )); 780 subPageR.height(), g.brush( QColorGroup::Mid ));
781 if ( controls & AddPage ) 781 if ( controls & AddPage )
782 p->fillRect( addPageR.x(), addPageR.y(), addPageR.width(), 782 p->fillRect( addPageR.x(), addPageR.y(), addPageR.width(),
783 addPageR.height(), g.brush( QColorGroup::Mid )); 783 addPageR.height(), g.brush( QColorGroup::Mid ));
784 if ( controls & Slider ) { 784 if ( controls & Slider ) {
785 QPoint bo = p->brushOrigin(); 785 QPoint bo = p->brushOrigin();
786 p->setBrushOrigin(sliderR.topLeft()); 786 p->setBrushOrigin(sliderR.topLeft());
787 drawBevelButton( p, sliderR.x(), sliderR.y(), 787 drawBevelButton( p, sliderR.x(), sliderR.y(),
788 sliderR.width(), sliderR.height(), g, 788 sliderR.width(), sliderR.height(), g,
789 FALSE, &g.brush( QColorGroup::Button ) ); 789 FALSE, &g.brush( QColorGroup::Button ) );
790 p->setBrushOrigin(bo); 790 p->setBrushOrigin(bo);
791 drawRiffles( p, sliderR.x(), sliderR.y(), 791 drawRiffles( p, sliderR.x(), sliderR.y(),
792 sliderR.width(), sliderR.height(), g, HORIZONTAL ); 792 sliderR.width(), sliderR.height(), g, HORIZONTAL );
793 } 793 }
794 794
795 // ### perhaps this should not be able to accept focus if maxedOut? 795 // ### perhaps this should not be able to accept focus if maxedOut?
796 if ( sb->hasFocus() && (controls & Slider) ) 796 if ( sb->hasFocus() && (controls & Slider) )
797 p->drawWinFocusRect( sliderR.x()+2, sliderR.y()+2, 797 p->drawWinFocusRect( sliderR.x()+2, sliderR.y()+2,
798 sliderR.width()-5, sliderR.height()-5, 798 sliderR.width()-5, sliderR.height()-5,
799 sb->backgroundColor() ); 799 sb->backgroundColor() );
800 800
801} 801}
802 802
803void QPEStyle::drawRiffles( QPainter* p, int x, int y, int w, int h, 803void QPEStyle::drawRiffles( QPainter* p, int x, int y, int w, int h,
804 const QColorGroup &g, bool horizontal ) 804 const QColorGroup &g, bool horizontal )
805{ 805{
806 if (!horizontal) { 806 if (!horizontal) {
807 if (h > 20) { 807 if (h > 20) {
808 y += (h-20)/2 ; 808 y += (h-20)/2 ;
809 h = 20; 809 h = 20;
810 } 810 }
811 if (h > 12) { 811 if (h > 12) {
812 int n = 3; 812 int n = 3;
813 int my = y+h/2-4; 813 int my = y+h/2-4;
814 int i ; 814 int i ;
815 p->setPen(g.light()); 815 p->setPen(g.light());
816 for (i=0; i<n; i++) { 816 for (i=0; i<n; i++) {
817 p->drawLine(x+2, my+3*i, x+w-4, my+3*i); 817 p->drawLine(x+2, my+3*i, x+w-4, my+3*i);
818 } 818 }
819 p->setPen(g.dark()); 819 p->setPen(g.dark());
820 my++; 820 my++;
821 for (i=0; i<n; i++) { 821 for (i=0; i<n; i++) {
822 p->drawLine(x+2, my+3*i, x+w-4, my+3*i); 822 p->drawLine(x+2, my+3*i, x+w-4, my+3*i);
823 } 823 }
824 } 824 }
825 } 825 }
826 else { 826 else {
827 if (w > 20) { 827 if (w > 20) {
828 x += (w-20)/2 ; 828 x += (w-20)/2 ;
829 w = 20; 829 w = 20;
830 } 830 }
831 if (w > 12) { 831 if (w > 12) {
832 int n = 3; 832 int n = 3;
833 int mx = x+w/2-4; 833 int mx = x+w/2-4;
834 int i ; 834 int i ;
835 p->setPen(g.light()); 835 p->setPen(g.light());
836 for (i=0; i<n; i++) { 836 for (i=0; i<n; i++) {
837 p->drawLine(mx+3*i, y+2, mx + 3*i, y+h-4); 837 p->drawLine(mx+3*i, y+2, mx + 3*i, y+h-4);
838 } 838 }
839 p->setPen(g.dark()); 839 p->setPen(g.dark());
840 mx++; 840 mx++;
841 for (i=0; i<n; i++) { 841 for (i=0; i<n; i++) {
842 p->drawLine(mx+3*i, y+2, mx + 3*i, y+h-4); 842 p->drawLine(mx+3*i, y+2, mx + 3*i, y+h-4);
843 } 843 }
844 } 844 }
845 } 845 }
846} 846}
847 847
848int QPEStyle::sliderLength() const 848int QPEStyle::sliderLength() const
849{ 849{
850 return 12; 850 return 12;
851} 851}
852 852
853void QPEStyle::drawSlider( QPainter *p, int x, int y, int w, int h, 853void QPEStyle::drawSlider( QPainter *p, int x, int y, int w, int h,
854 const QColorGroup &g, Orientation o, bool tickAbove, bool tickBelow ) 854 const QColorGroup &g, Orientation o, bool tickAbove, bool tickBelow )
855{ 855{
856 int a = tickAbove ? 3 : 0; 856 int a = tickAbove ? 3 : 0;
857 int b = tickBelow ? 3 : 0; 857 int b = tickBelow ? 3 : 0;
858 858
859 if ( o == Horizontal ) { 859 if ( o == Horizontal ) {
860 drawBevelButton( p, x, y+a, w, h-a-b, g, FALSE, &g.brush( QColorGroup::Button ) ); 860 drawBevelButton( p, x, y+a, w, h-a-b, g, FALSE, &g.brush( QColorGroup::Button ) );
861 int xp = x + w/2; 861 int xp = x + w/2;
862 qDrawShadeLine( p, xp, y+a+2, xp, y+h-b-3, g ); 862 qDrawShadeLine( p, xp, y+a+2, xp, y+h-b-3, g );
863 } else { 863 } else {
864 drawBevelButton( p, x+a, y, w-a-b, h, g, FALSE, &g.brush( QColorGroup::Button ) ); 864 drawBevelButton( p, x+a, y, w-a-b, h, g, FALSE, &g.brush( QColorGroup::Button ) );
865 int yp = y + h/2; 865 int yp = y + h/2;
866 qDrawShadeLine( p, x+a+2, yp, x+w-b-3, yp, g ); 866 qDrawShadeLine( p, x+a+2, yp, x+w-b-3, yp, g );
867 } 867 }
868} 868}
869 869
870void QPEStyle::drawSliderMask ( QPainter * p, int x, int y, int w, int h, 870void QPEStyle::drawSliderMask ( QPainter * p, int x, int y, int w, int h,
871 Orientation o, bool tickAbove, bool tickBelow ) 871 Orientation o, bool tickAbove, bool tickBelow )
872{ 872{
873 int a = tickAbove ? 3 : 0; 873 int a = tickAbove ? 3 : 0;
874 int b = tickBelow ? 3 : 0; 874 int b = tickBelow ? 3 : 0;
875 if ( o == Horizontal ) 875 if ( o == Horizontal )
876 p->fillRect( x, y+a, w, h-a-b, color1 ); 876 p->fillRect( x, y+a, w, h-a-b, color1 );
877 else 877 else
878 p->fillRect( x+a, y, w-a-b, h, color1 ); 878 p->fillRect( x+a, y, w-a-b, h, color1 );
879} 879}
880 880
881/*!\reimp 881/*!\reimp
882 */ 882 */
883void QPEStyle::drawSliderGrooveMask( QPainter *p, 883void QPEStyle::drawSliderGrooveMask( QPainter *p,
884 int x, int y, int w, int h, 884 int x, int y, int w, int h,
885 const QColorGroup& , QCOORD c, 885 const QColorGroup& , QCOORD c,
886 Orientation orient ) 886 Orientation orient )
887{ 887{
888 if ( orient == Horizontal ) 888 if ( orient == Horizontal )
889 p->fillRect( x, y + c - 2, w, 4, color1 ); 889 p->fillRect( x, y + c - 2, w, 4, color1 );
890 else 890 else
891 p->fillRect( x + c - 2, y, 4, h, color1 ); 891 p->fillRect( x + c - 2, y, 4, h, color1 );
892} 892}
893 893
894void QPEStyle::drawTab( QPainter *p, const QTabBar *tb, QTab *t, bool selected ) 894void QPEStyle::drawTab( QPainter *p, const QTabBar *tb, QTab *t, bool selected )
895{ 895{
896 QRect r( t->rect() ); 896 QRect r( t->rect() );
897 if ( tb->shape() == QTabBar::RoundedAbove ) { 897 if ( tb->shape() == QTabBar::RoundedAbove ) {
898 p->setPen( tb->colorGroup().light() ); 898 p->setPen( tb->colorGroup().light() );
899 p->drawLine( r.left(), r.bottom(), r.right(), r.bottom() ); 899 p->drawLine( r.left(), r.bottom(), r.right(), r.bottom() );
900 if ( r.left() == 0 ) 900 if ( r.left() == 0 )
901 p->drawPoint( tb->rect().bottomLeft() ); 901 p->drawPoint( tb->rect().bottomLeft() );
902 else { 902 else {
903 p->setPen( tb->colorGroup().light() ); 903 p->setPen( tb->colorGroup().light() );
904 p->drawLine( r.left(), r.bottom(), r.right(), r.bottom() ); 904 p->drawLine( r.left(), r.bottom(), r.right(), r.bottom() );
905 } 905 }
906 906
907 if ( selected ) { 907 if ( selected ) {
908 p->setPen( tb->colorGroup().background() ); 908 p->setPen( tb->colorGroup().background() );
909 p->drawLine( r.left()+2, r.top()+1, r.right()-2, r.top()+1 ); 909 p->drawLine( r.left()+2, r.top()+1, r.right()-2, r.top()+1 );
910 p->fillRect( QRect( r.left()+1, r.top()+2, r.width()-2, r.height()-2), 910 p->fillRect( QRect( r.left()+1, r.top()+2, r.width()-2, r.height()-2),
911 tb->colorGroup().brush( QColorGroup::Background )); 911 tb->colorGroup().brush( QColorGroup::Background ));
912 } else { 912 } else {
913 r.setRect( r.left() + 2, r.top() + 2, 913 r.setRect( r.left() + 2, r.top() + 2,
914 r.width() - 4, r.height() - 2 ); 914 r.width() - 4, r.height() - 2 );
915 p->setPen( tb->colorGroup().button() ); 915 p->setPen( tb->colorGroup().button() );
916 p->drawLine( r.left()+2, r.top()+1, r.right()-2, r.top()+1 ); 916 p->drawLine( r.left()+2, r.top()+1, r.right()-2, r.top()+1 );
917 p->fillRect( QRect( r.left()+1, r.top()+2, r.width()-2, r.height()-3), 917 p->fillRect( QRect( r.left()+1, r.top()+2, r.width()-2, r.height()-3),
918 tb->colorGroup().brush( QColorGroup::Button )); 918 tb->colorGroup().brush( QColorGroup::Button ));
919 919
920 //do shading; will not work for pixmap brushes 920 //do shading; will not work for pixmap brushes
921 QColor bg = tb->colorGroup().button(); 921 QColor bg = tb->colorGroup().button();
922 // int h,s,v; 922 // int h,s,v;
923 // bg.hsv( &h, &s, &v ); 923 // bg.hsv( &h, &s, &v );
924 int n = r.height()/2; 924 int n = r.height()/2;
925 int dark = 100; 925 int dark = 100;
926 for ( int i = 1; i < n; i++ ) { 926 for ( int i = 1; i < n; i++ ) {
927 dark = (dark * (100+(i*15)/n) )/100; 927 dark = (dark * (100+(i*15)/n) )/100;
928 p->setPen( bg.dark( dark ) ); 928 p->setPen( bg.dark( dark ) );
929 int y = r.bottom()-n+i; 929 int y = r.bottom()-n+i;
930 int x1 = r.left()+1; 930 int x1 = r.left()+1;
931 int x2 = r.right()-1; 931 int x2 = r.right()-1;
932 p->drawLine( x1, y, x2, y ); 932 p->drawLine( x1, y, x2, y );
933 } 933 }
934 } 934 }
935 935
936 p->setPen( tb->colorGroup().light() ); 936 p->setPen( tb->colorGroup().light() );
937 p->drawLine( r.left(), r.bottom()-1, r.left(), r.top() + 2 ); 937 p->drawLine( r.left(), r.bottom()-1, r.left(), r.top() + 2 );
938 p->drawPoint( r.left()+1, r.top() + 1 ); 938 p->drawPoint( r.left()+1, r.top() + 1 );
939 p->drawLine( r.left()+2, r.top(), 939 p->drawLine( r.left()+2, r.top(),
940 r.right() - 2, r.top() ); 940 r.right() - 2, r.top() );
941 941
942 p->setPen( tb->colorGroup().dark() ); 942 p->setPen( tb->colorGroup().dark() );
943 p->drawPoint( r.right() - 1, r.top() + 1 ); 943 p->drawPoint( r.right() - 1, r.top() + 1 );
944 p->drawLine( r.right(), r.top() + 2, r.right(), r.bottom() - 1); 944 p->drawLine( r.right(), r.top() + 2, r.right(), r.bottom() - 1);
945 } else if ( tb->shape() == QTabBar::RoundedBelow ) { 945 } else if ( tb->shape() == QTabBar::RoundedBelow ) {
946 if ( selected ) { 946 if ( selected ) {
947 p->setPen( tb->colorGroup().background() ); 947 p->setPen( tb->colorGroup().background() );
948 p->drawLine( r.left()+2, r.bottom()-1, r.right()-2, r.bottom()-1 ); 948 p->drawLine( r.left()+2, r.bottom()-1, r.right()-2, r.bottom()-1 );
949 p->fillRect( QRect( r.left()+1, r.top(), r.width()-2, r.height()-2), 949 p->fillRect( QRect( r.left()+1, r.top(), r.width()-2, r.height()-2),
950 tb->palette().normal().brush( QColorGroup::Background )); 950 tb->palette().normal().brush( QColorGroup::Background ));
951 } else { 951 } else {
952 p->setPen( tb->colorGroup().dark() ); 952 p->setPen( tb->colorGroup().dark() );
953 p->drawLine( r.left(), r.top(), 953 p->drawLine( r.left(), r.top(),
954 r.right(), r.top() ); 954 r.right(), r.top() );
955 r.setRect( r.left() + 2, r.top(), 955 r.setRect( r.left() + 2, r.top(),
956 r.width() - 4, r.height() - 2 ); 956 r.width() - 4, r.height() - 2 );
957 p->setPen( tb->colorGroup().button() ); 957 p->setPen( tb->colorGroup().button() );
958 p->drawLine( r.left()+2, r.bottom()-1, r.right()-2, r.bottom()-1 ); 958 p->drawLine( r.left()+2, r.bottom()-1, r.right()-2, r.bottom()-1 );
959 p->fillRect( QRect( r.left()+1, r.top()+1, r.width()-2, r.height()-3), 959 p->fillRect( QRect( r.left()+1, r.top()+1, r.width()-2, r.height()-3),
960 tb->palette().normal().brush( QColorGroup::Button )); 960 tb->palette().normal().brush( QColorGroup::Button ));
961 } 961 }
962 962
963 p->setPen( tb->colorGroup().dark() ); 963 p->setPen( tb->colorGroup().dark() );
964 p->drawLine( r.right(), r.top(), 964 p->drawLine( r.right(), r.top(),
965 r.right(), r.bottom() - 2 ); 965 r.right(), r.bottom() - 2 );
966 p->drawPoint( r.right() - 1, r.bottom() - 1 ); 966 p->drawPoint( r.right() - 1, r.bottom() - 1 );
967 p->drawLine( r.right() - 2, r.bottom(), 967 p->drawLine( r.right() - 2, r.bottom(),
968 r.left() + 2, r.bottom() ); 968 r.left() + 2, r.bottom() );
969 969
970 p->setPen( tb->colorGroup().light() ); 970 p->setPen( tb->colorGroup().light() );
971 p->drawLine( r.left(), r.top()+1, 971 p->drawLine( r.left(), r.top()+1,
972 r.left(), r.bottom() - 2 ); 972 r.left(), r.bottom() - 2 );
973 p->drawPoint( r.left() + 1, r.bottom() - 1 ); 973 p->drawPoint( r.left() + 1, r.bottom() - 1 );
974 if ( r.left() == 0 ) 974 if ( r.left() == 0 )
975 p->drawPoint( tb->rect().topLeft() ); 975 p->drawPoint( tb->rect().topLeft() );
976 976
977 } else { 977 } else {
978 QCommonStyle::drawTab( p, tb, t, selected ); 978 QCommonStyle::drawTab( p, tb, t, selected );
979 } 979 }
980} 980}
981 981
982 static const int motifItemFrame = 0;// menu item frame width 982 static const int motifItemFrame = 0;// menu item frame width
983 static const int motifSepHeight = 2;// separator item height 983 static const int motifSepHeight = 2;// separator item height
984 static const int motifItemHMargin = 1;// menu item hor text margin 984 static const int motifItemHMargin = 1;// menu item hor text margin
985 static const int motifItemVMargin = 2;// menu item ver text margin 985 static const int motifItemVMargin = 2;// menu item ver text margin
986 static const int motifArrowHMargin = 0;// arrow horizontal margin 986 static const int motifArrowHMargin = 0;// arrow horizontal margin
987 static const int motifTabSpacing = 12;// space between text and tab 987 static const int motifTabSpacing = 12;// space between text and tab
988 static const int motifCheckMarkHMargin = 1;// horiz. margins of check mark 988 static const int motifCheckMarkHMargin = 1;// horiz. margins of check mark
989 static const int windowsRightBorder= 8; // right border on windows 989 static const int windowsRightBorder= 8; // right border on windows
990static const int windowsCheckMarkWidth = 2; // checkmarks width on windows 990static const int windowsCheckMarkWidth = 2; // checkmarks width on windows
991 991
992/*! \reimp 992/*! \reimp
993*/ 993*/
994int QPEStyle::extraPopupMenuItemWidth( bool checkable, int maxpmw, QMenuItem* mi, const QFontMetrics& /*fm*/ ) 994int QPEStyle::extraPopupMenuItemWidth( bool checkable, int maxpmw, QMenuItem* mi, const QFontMetrics& /*fm*/ )
995{ 995{
996#ifndef QT_NO_MENUDATA 996#ifndef QT_NO_MENUDATA
997 int w = 2*motifItemHMargin + 2*motifItemFrame; // a little bit of border can never harm 997 int w = 2*motifItemHMargin + 2*motifItemFrame; // a little bit of border can never harm
998 998
999 if ( mi->isSeparator() ) 999 if ( mi->isSeparator() )
1000 return 10; // arbitrary 1000 return 10; // arbitrary
1001 else if ( mi->pixmap() ) 1001 else if ( mi->pixmap() )
1002 w += mi->pixmap()->width();// pixmap only 1002 w += mi->pixmap()->width();// pixmap only
1003 1003
1004 if ( !mi->text().isNull() ) { 1004 if ( !mi->text().isNull() ) {
1005 if ( mi->text().find('\t') >= 0 )// string contains tab 1005 if ( mi->text().find('\t') >= 0 )// string contains tab
1006 w += motifTabSpacing; 1006 w += motifTabSpacing;
1007 } 1007 }
1008 1008
1009 if ( maxpmw ) { // we have iconsets 1009 if ( maxpmw ) { // we have iconsets
1010 w += maxpmw; 1010 w += maxpmw;
1011 w += 6; // add a little extra border around the iconset 1011 w += 6; // add a little extra border around the iconset
1012 } 1012 }
1013 1013
1014 if ( checkable && maxpmw < windowsCheckMarkWidth ) { 1014 if ( checkable && maxpmw < windowsCheckMarkWidth ) {
1015 w += windowsCheckMarkWidth - maxpmw; // space for the checkmarks 1015 w += windowsCheckMarkWidth - maxpmw; // space for the checkmarks
1016 } 1016 }
1017 1017
1018 if ( maxpmw > 0 || checkable ) // we have a check-column ( iconsets or checkmarks) 1018 if ( maxpmw > 0 || checkable ) // we have a check-column ( iconsets or checkmarks)
1019 w += motifCheckMarkHMargin; // add space to separate the columns 1019 w += motifCheckMarkHMargin; // add space to separate the columns
1020 1020
1021 w += windowsRightBorder; // windows has a strange wide border on the right side 1021 w += windowsRightBorder; // windows has a strange wide border on the right side
1022 1022
1023 return w; 1023 return w;
1024#endif 1024#endif
1025} 1025}
1026 1026
1027/*! \reimp 1027/*! \reimp
1028*/ 1028*/
1029int QPEStyle::popupMenuItemHeight( bool /*checkable*/, QMenuItem* mi, const QFontMetrics& fm ) 1029int QPEStyle::popupMenuItemHeight( bool /*checkable*/, QMenuItem* mi, const QFontMetrics& fm )
1030{ 1030{
1031#ifndef QT_NO_MENUDATA 1031#ifndef QT_NO_MENUDATA
1032 int h = 0; 1032 int h = 0;
1033 if ( mi->isSeparator() ) // separator height 1033 if ( mi->isSeparator() ) // separator height
1034 h = motifSepHeight; 1034 h = motifSepHeight;
1035 else if ( mi->pixmap() ) // pixmap height 1035 else if ( mi->pixmap() ) // pixmap height
1036 h = mi->pixmap()->height() + 2*motifItemFrame; 1036 h = mi->pixmap()->height() + 2*motifItemFrame;
1037 else // text height 1037 else // text height
1038 h = fm.height() + 2*motifItemVMargin + 2*motifItemFrame - 1; 1038 h = fm.height() + 2*motifItemVMargin + 2*motifItemFrame - 1;
1039 1039
1040 if ( !mi->isSeparator() && mi->iconSet() != 0 ) { 1040 if ( !mi->isSeparator() && mi->iconSet() != 0 ) {
1041 h = QMAX( h, mi->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).height() + 2*motifItemFrame ); 1041 h = QMAX( h, mi->iconSet()->pixmap( QIconSet::Small, QIconSet::Normal ).height() + 2*motifItemFrame );
1042 } 1042 }
1043 if ( mi->custom() ) 1043 if ( mi->custom() )
1044 h = QMAX( h, mi->custom()->sizeHint().height() + 2*motifItemVMargin + 2*motifItemFrame ) - 1; 1044 h = QMAX( h, mi->custom()->sizeHint().height() + 2*motifItemVMargin + 2*motifItemFrame ) - 1;
1045 return h; 1045 return h;
1046#endif 1046#endif
1047} 1047}
1048 1048
1049void QPEStyle::drawPopupMenuItem( QPainter* p, bool checkable, int maxpmw, int tab, QMenuItem* mi, 1049void QPEStyle::drawPopupMenuItem( QPainter* p, bool checkable, int maxpmw, int tab, QMenuItem* mi,
1050 const QPalette& pal, 1050 const QPalette& pal,
1051 bool act, bool enabled, int x, int y, int w, int h) 1051 bool act, bool enabled, int x, int y, int w, int h)
1052{ 1052{
1053#ifndef QT_NO_MENUDATA 1053#ifndef QT_NO_MENUDATA
1054 const QColorGroup & g = pal.active(); 1054 const QColorGroup & g = pal.active();
1055 bool dis = !enabled; 1055 bool dis = !enabled;
1056 QColorGroup itemg = dis ? pal.disabled() : pal.active(); 1056 QColorGroup itemg = dis ? pal.disabled() : pal.active();
1057 1057
1058 if ( checkable ) 1058 if ( checkable )
1059 maxpmw = QMAX( maxpmw, 8 ); // space for the checkmarks 1059 maxpmw = QMAX( maxpmw, 8 ); // space for the checkmarks
1060 1060
1061 int checkcol = maxpmw; 1061 int checkcol = maxpmw;
1062 1062
1063 if ( mi && mi->isSeparator() ) { // draw separator 1063 if ( mi && mi->isSeparator() ) { // draw separator
1064 p->setPen( g.dark() ); 1064 p->setPen( g.dark() );
1065 p->drawLine( x, y, x+w, y ); 1065 p->drawLine( x, y, x+w, y );
1066 p->setPen( g.light() ); 1066 p->setPen( g.light() );
1067 p->drawLine( x, y+1, x+w, y+1 ); 1067 p->drawLine( x, y+1, x+w, y+1 );
1068 return; 1068 return;
1069 } 1069 }
1070 1070
1071 QBrush fill = act? g.brush( QColorGroup::Highlight ) : 1071 QBrush fill = act? g.brush( QColorGroup::Highlight ) :
1072 g.brush( QColorGroup::Button ); 1072 g.brush( QColorGroup::Button );
1073 p->fillRect( x, y, w, h, fill); 1073 p->fillRect( x, y, w, h, fill);
1074 1074
1075 if ( !mi ) 1075 if ( !mi )
1076 return; 1076 return;
1077 1077
1078 if ( mi->isChecked() ) { 1078 if ( mi->isChecked() ) {
1079 if ( act && !dis ) { 1079 if ( act && !dis ) {
1080 qDrawShadePanel( p, x, y, checkcol, h, 1080 qDrawShadePanel( p, x, y, checkcol, h,
1081 g, TRUE, 1, &g.brush( QColorGroup::Button ) ); 1081 g, TRUE, 1, &g.brush( QColorGroup::Button ) );
1082 } else { 1082 } else {
1083 qDrawShadePanel( p, x, y, checkcol, h, 1083 qDrawShadePanel( p, x, y, checkcol, h,
1084 g, TRUE, 1, &g.brush( QColorGroup::Midlight ) ); 1084 g, TRUE, 1, &g.brush( QColorGroup::Midlight ) );
1085 } 1085 }
1086 } else if ( !act ) { 1086 } else if ( !act ) {
1087 p->fillRect(x, y, checkcol , h, 1087 p->fillRect(x, y, checkcol , h,
1088 g.brush( QColorGroup::Button )); 1088 g.brush( QColorGroup::Button ));
1089 } 1089 }
1090 1090
1091 if ( mi->iconSet() ) { // draw iconset 1091 if ( mi->iconSet() ) { // draw iconset
1092 QIconSet::Mode mode = dis ? QIconSet::Disabled : QIconSet::Normal; 1092 QIconSet::Mode mode = dis ? QIconSet::Disabled : QIconSet::Normal;
1093 if (act && !dis ) 1093 if (act && !dis )
1094 mode = QIconSet::Active; 1094 mode = QIconSet::Active;
1095 QPixmap pixmap = mi->iconSet()->pixmap( QIconSet::Small, mode ); 1095 QPixmap pixmap = mi->iconSet()->pixmap( QIconSet::Small, mode );
1096 int pixw = pixmap.width(); 1096 int pixw = pixmap.width();
1097 int pixh = pixmap.height(); 1097 int pixh = pixmap.height();
1098 if ( act && !dis ) { 1098 if ( act && !dis ) {
1099 if ( !mi->isChecked() ) 1099 if ( !mi->isChecked() )
1100 qDrawShadePanel( p, x, y, checkcol, h, g, FALSE, 1, &g.brush( QColorGroup::Button ) ); 1100 qDrawShadePanel( p, x, y, checkcol, h, g, FALSE, 1, &g.brush( QColorGroup::Button ) );
1101 } 1101 }
1102 QRect cr( x, y, checkcol, h ); 1102 QRect cr( x, y, checkcol, h );
1103 QRect pmr( 0, 0, pixw, pixh ); 1103 QRect pmr( 0, 0, pixw, pixh );
1104 pmr.moveCenter( cr.center() ); 1104 pmr.moveCenter( cr.center() );
1105 p->setPen( itemg.text() ); 1105 p->setPen( itemg.text() );
1106 p->drawPixmap( pmr.topLeft(), pixmap ); 1106 p->drawPixmap( pmr.topLeft(), pixmap );
1107 1107
1108 QBrush fill = act? g.brush( QColorGroup::Highlight ) : 1108 QBrush fill = act? g.brush( QColorGroup::Highlight ) :
1109 g.brush( QColorGroup::Button ); 1109 g.brush( QColorGroup::Button );
1110 p->fillRect( x+checkcol + 1, y, w - checkcol - 1, h, fill); 1110 p->fillRect( x+checkcol + 1, y, w - checkcol - 1, h, fill);
1111 } else if ( checkable ) {// just "checking"... 1111 } else if ( checkable ) {// just "checking"...
1112 int mw = checkcol + motifItemFrame; 1112 int mw = checkcol + motifItemFrame;
1113 int mh = h - 2*motifItemFrame; 1113 int mh = h - 2*motifItemFrame;
1114 if ( mi->isChecked() ) { 1114 if ( mi->isChecked() ) {
1115 drawCheckMark( p, x + motifItemFrame + 2, 1115 drawCheckMark( p, x + motifItemFrame + 2,
1116 y+motifItemFrame, mw, mh, itemg, act, dis ); 1116 y+motifItemFrame, mw, mh, itemg, act, dis );
1117 } 1117 }
1118 } 1118 }
1119 1119
1120 p->setPen( act ? g.highlightedText() : g.buttonText() ); 1120 p->setPen( act ? g.highlightedText() : g.buttonText() );
1121 1121
1122 QColor discol; 1122 QColor discol;
1123 if ( dis ) { 1123 if ( dis ) {
1124 discol = itemg.text(); 1124 discol = itemg.text();
1125 p->setPen( discol ); 1125 p->setPen( discol );
1126 } 1126 }
1127 1127
1128 int xm = motifItemFrame + checkcol + motifItemHMargin; 1128 int xm = motifItemFrame + checkcol + motifItemHMargin;
1129 1129
1130 if ( mi->custom() ) { 1130 if ( mi->custom() ) {
1131 int m = motifItemVMargin; 1131 int m = motifItemVMargin;
1132 p->save(); 1132 p->save();
1133 if ( dis && !act ) { 1133 if ( dis && !act ) {
1134 p->setPen( g.light() ); 1134 p->setPen( g.light() );
1135 mi->custom()->paint( p, itemg, act, enabled, 1135 mi->custom()->paint( p, itemg, act, enabled,
1136 x+xm+1, y+m+1, w-xm-tab+1, h-2*m ); 1136 x+xm+1, y+m+1, w-xm-tab+1, h-2*m );
1137 p->setPen( discol ); 1137 p->setPen( discol );
1138 } 1138 }
1139 mi->custom()->paint( p, itemg, act, enabled, 1139 mi->custom()->paint( p, itemg, act, enabled,
1140 x+xm, y+m, w-xm-tab+1, h-2*m ); 1140 x+xm, y+m, w-xm-tab+1, h-2*m );
1141 p->restore(); 1141 p->restore();
1142 } 1142 }
1143 QString s = mi->text(); 1143 QString s = mi->text();
1144 if ( !s.isNull() ) { // draw text 1144 if ( !s.isNull() ) { // draw text
1145 int t = s.find( '\t' ); 1145 int t = s.find( '\t' );
1146 int m = motifItemVMargin; 1146 int m = motifItemVMargin;
1147 const int text_flags = AlignVCenter|ShowPrefix | DontClip | SingleLine; 1147 const int text_flags = AlignVCenter|ShowPrefix | DontClip | SingleLine;
1148 if ( t >= 0 ) { // draw tab text 1148 if ( t >= 0 ) { // draw tab text
1149 if ( dis && !act ) { 1149 if ( dis && !act ) {
1150 p->setPen( g.light() ); 1150 p->setPen( g.light() );
1151 p->drawText( x+w-tab-windowsRightBorder-motifItemHMargin-motifItemFrame+1, 1151 p->drawText( x+w-tab-windowsRightBorder-motifItemHMargin-motifItemFrame+1,
1152 y+m+1, tab, h-2*m, text_flags, s.mid( t+1 )); 1152 y+m+1, tab, h-2*m, text_flags, s.mid( t+1 ));
1153 p->setPen( discol ); 1153 p->setPen( discol );
1154 } 1154 }
1155 p->drawText( x+w-tab-windowsRightBorder-motifItemHMargin-motifItemFrame, 1155 p->drawText( x+w-tab-windowsRightBorder-motifItemHMargin-motifItemFrame,
1156 y+m, tab, h-2*m, text_flags, s.mid( t+1 ) ); 1156 y+m, tab, h-2*m, text_flags, s.mid( t+1 ) );
1157 } 1157 }
1158 if ( dis && !act ) { 1158 if ( dis && !act ) {
1159 p->setPen( g.light() ); 1159 p->setPen( g.light() );
1160 p->drawText( x+xm+1, y+m+1, w-xm+1, h-2*m, text_flags, s, t ); 1160 p->drawText( x+xm+1, y+m+1, w-xm+1, h-2*m, text_flags, s, t );
1161 p->setPen( discol ); 1161 p->setPen( discol );
1162 } 1162 }
1163 p->drawText( x+xm, y+m, w-xm-tab+1, h-2*m, text_flags, s, t ); 1163 p->drawText( x+xm, y+m, w-xm-tab+1, h-2*m, text_flags, s, t );
1164 } else if ( mi->pixmap() ) { // draw pixmap 1164 } else if ( mi->pixmap() ) { // draw pixmap
1165 QPixmap *pixmap = mi->pixmap(); 1165 QPixmap *pixmap = mi->pixmap();
1166 if ( pixmap->depth() == 1 ) 1166 if ( pixmap->depth() == 1 )
1167 p->setBackgroundMode( OpaqueMode ); 1167 p->setBackgroundMode( OpaqueMode );
1168 p->drawPixmap( x+xm, y+motifItemFrame, *pixmap ); 1168 p->drawPixmap( x+xm, y+motifItemFrame, *pixmap );
1169 if ( pixmap->depth() == 1 ) 1169 if ( pixmap->depth() == 1 )
1170 p->setBackgroundMode( TransparentMode ); 1170 p->setBackgroundMode( TransparentMode );
1171 } 1171 }
1172 if ( mi->popup() ) { // draw sub menu arrow 1172 if ( mi->popup() ) { // draw sub menu arrow
1173 int dim = (h-2*motifItemFrame) / 2; 1173 int dim = (h-2*motifItemFrame) / 2;
1174 if ( act ) { 1174 if ( act ) {
1175 if ( !dis ) 1175 if ( !dis )
1176 discol = white; 1176 discol = white;
1177 QColorGroup g2( discol, g.highlight(), 1177 QColorGroup g2( discol, g.highlight(),
1178 white, white, 1178 white, white,
1179 dis ? discol : white, 1179 dis ? discol : white,
1180 discol, white ); 1180 discol, white );
1181 drawArrow( p, RightArrow, FALSE, 1181 drawArrow( p, RightArrow, FALSE,
1182 x+w - motifArrowHMargin - motifItemFrame - dim, y+h/2-dim/2, 1182 x+w - motifArrowHMargin - motifItemFrame - dim, y+h/2-dim/2,
1183 dim, dim, g2, TRUE ); 1183 dim, dim, g2, TRUE );
1184 } else { 1184 } else {
1185 drawArrow( p, RightArrow, 1185 drawArrow( p, RightArrow,
1186 FALSE, 1186 FALSE,
1187 x+w - motifArrowHMargin - motifItemFrame - dim, y+h/2-dim/2, 1187 x+w - motifArrowHMargin - motifItemFrame - dim, y+h/2-dim/2,
1188 dim, dim, g, mi->isEnabled() ); 1188 dim, dim, g, mi->isEnabled() );
1189 } 1189 }
1190 } 1190 }
1191#endif 1191#endif
1192} 1192}
1193 1193
1194#endif 1194#endif
diff --git a/library/resource.cpp b/library/resource.cpp
index bdcd603..0920b67 100644
--- a/library/resource.cpp
+++ b/library/resource.cpp
@@ -1,217 +1,217 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#define QTOPIA_INTERNAL_MIMEEXT 21#define QTOPIA_INTERNAL_MIMEEXT
22#include "qpeapplication.h" 22#include <qpe/qpeapplication.h>
23#include "resource.h" 23#include "resource.h"
24#include "mimetype.h" 24#include "mimetype.h"
25#include <qdir.h> 25#include <qdir.h>
26#include <qfile.h> 26#include <qfile.h>
27#include <qregexp.h> 27#include <qregexp.h>
28#include <qpixmapcache.h> 28#include <qpixmapcache.h>
29#include <qpainter.h> 29#include <qpainter.h>
30 30
31// this namespace is just a workaround for a gcc bug 31// this namespace is just a workaround for a gcc bug
32// gcc exports inline functions in the generated file 32// gcc exports inline functions in the generated file
33// inlinepics_p.h 33// inlinepics_p.h
34 34
35namespace { 35namespace {
36#include "inlinepics_p.h" 36#include "inlinepics_p.h"
37} 37}
38 38
39/*! 39/*!
40 \class Resource resource.h 40 \class Resource resource.h
41 \brief The Resource class provides access to named resources. 41 \brief The Resource class provides access to named resources.
42 42
43 The resources may be provided from files or other sources. 43 The resources may be provided from files or other sources.
44 44
45 The allSounds() function returns a list of all the sounds available. 45 The allSounds() function returns a list of all the sounds available.
46 A particular sound can be searched for using findSound(). 46 A particular sound can be searched for using findSound().
47 47
48 Images can be loaded with loadImage(), loadPixmap(), loadBitmap() 48 Images can be loaded with loadImage(), loadPixmap(), loadBitmap()
49 and loadIconSet(). 49 and loadIconSet().
50 50
51 \ingroup qtopiaemb 51 \ingroup qtopiaemb
52*/ 52*/
53 53
54/*! 54/*!
55 \fn Resource::Resource() 55 \fn Resource::Resource()
56 \internal 56 \internal
57*/ 57*/
58 58
59/*! 59/*!
60 Returns the QPixmap called \a pix. You should avoid including 60 Returns the QPixmap called \a pix. You should avoid including
61 any filename type extension (e.g. .png, .xpm). 61 any filename type extension (e.g. .png, .xpm).
62*/ 62*/
63QPixmap Resource::loadPixmap( const QString &pix ) 63QPixmap Resource::loadPixmap( const QString &pix )
64{ 64{
65 QPixmap pm; 65 QPixmap pm;
66 QString key="QPE_"+pix; 66 QString key="QPE_"+pix;
67 if ( !QPixmapCache::find(key,pm) ) { 67 if ( !QPixmapCache::find(key,pm) ) {
68 pm.convertFromImage(loadImage(pix)); 68 pm.convertFromImage(loadImage(pix));
69 QPixmapCache::insert(key,pm); 69 QPixmapCache::insert(key,pm);
70 } 70 }
71 return pm; 71 return pm;
72} 72}
73 73
74/*! 74/*!
75 Returns the QBitmap called \a pix. You should avoid including 75 Returns the QBitmap called \a pix. You should avoid including
76 any filename type extension (e.g. .png, .xpm). 76 any filename type extension (e.g. .png, .xpm).
77*/ 77*/
78QBitmap Resource::loadBitmap( const QString &pix ) 78QBitmap Resource::loadBitmap( const QString &pix )
79{ 79{
80 QBitmap bm; 80 QBitmap bm;
81 bm = loadPixmap(pix); 81 bm = loadPixmap(pix);
82 return bm; 82 return bm;
83} 83}
84 84
85/*! 85/*!
86 Returns the filename of a pixmap called \a pix. You should avoid including 86 Returns the filename of a pixmap called \a pix. You should avoid including
87 any filename type extension (e.g. .png, .xpm). 87 any filename type extension (e.g. .png, .xpm).
88 88
89 Normally you will use loadPixmap() rather than this function. 89 Normally you will use loadPixmap() rather than this function.
90*/ 90*/
91QString Resource::findPixmap( const QString &pix ) 91QString Resource::findPixmap( const QString &pix )
92{ 92{
93 QString picsPath = QPEApplication::qpeDir() + "pics/"; 93 QString picsPath = QPEApplication::qpeDir() + "pics/";
94 94
95 QString f; 95 QString f;
96 96
97 // Common case optimizations... 97 // Common case optimizations...
98 f = picsPath + pix + ".png"; 98 f = picsPath + pix + ".png";
99 if ( QFile( f ).exists() ) 99 if ( QFile( f ).exists() )
100 return f; 100 return f;
101 f = picsPath + pix + ".xpm"; 101 f = picsPath + pix + ".xpm";
102 if ( QFile( f ).exists() ) 102 if ( QFile( f ).exists() )
103 return f; 103 return f;
104 104
105 // All formats... 105 // All formats...
106 QStrList fileFormats = QImageIO::inputFormats(); 106 QStrList fileFormats = QImageIO::inputFormats();
107 QString ff = fileFormats.first(); 107 QString ff = fileFormats.first();
108 while ( fileFormats.current() ) { 108 while ( fileFormats.current() ) {
109 QStringList exts = MimeType("image/"+ff.lower()).extensions(); 109 QStringList exts = MimeType("image/"+ff.lower()).extensions();
110 for ( QStringList::ConstIterator it = exts.begin(); it!=exts.end(); ++it ) { 110 for ( QStringList::ConstIterator it = exts.begin(); it!=exts.end(); ++it ) {
111 QString f = picsPath + pix + "." + *it; 111 QString f = picsPath + pix + "." + *it;
112 if ( QFile(f).exists() ) 112 if ( QFile(f).exists() )
113 return f; 113 return f;
114 } 114 }
115 ff = fileFormats.next(); 115 ff = fileFormats.next();
116 } 116 }
117 117
118 // Finally, no (or existing) extension... 118 // Finally, no (or existing) extension...
119 if ( QFile( picsPath + pix ).exists() ) 119 if ( QFile( picsPath + pix ).exists() )
120 return picsPath + pix; 120 return picsPath + pix;
121 121
122 //qDebug("Cannot find pixmap: %s", pix.latin1()); 122 //qDebug("Cannot find pixmap: %s", pix.latin1());
123 return QString(); 123 return QString();
124} 124}
125 125
126/*! 126/*!
127 Returns a sound file for a sound called \a name. 127 Returns a sound file for a sound called \a name.
128 128
129 You should avoid including any filename type extension (e.g. .wav), 129 You should avoid including any filename type extension (e.g. .wav),
130 as the system will search for only those fileformats which are supported 130 as the system will search for only those fileformats which are supported
131 by the library. 131 by the library.
132 132
133 Currently, only WAV files are supported. 133 Currently, only WAV files are supported.
134*/ 134*/
135QString Resource::findSound( const QString &name ) 135QString Resource::findSound( const QString &name )
136{ 136{
137 QString picsPath = QPEApplication::qpeDir() + "sounds/"; 137 QString picsPath = QPEApplication::qpeDir() + "sounds/";
138 138
139 QString result; 139 QString result;
140 if ( QFile( (result = picsPath + name + ".wav") ).exists() ) 140 if ( QFile( (result = picsPath + name + ".wav") ).exists() )
141 return result; 141 return result;
142 142
143 return QString(); 143 return QString();
144} 144}
145 145
146/*! 146/*!
147 Returns a list of all sound names. 147 Returns a list of all sound names.
148*/ 148*/
149QStringList Resource::allSounds() 149QStringList Resource::allSounds()
150{ 150{
151 QDir resourcedir( QPEApplication::qpeDir() + "sounds/", "*.wav" ); 151 QDir resourcedir( QPEApplication::qpeDir() + "sounds/", "*.wav" );
152 QStringList entries = resourcedir.entryList(); 152 QStringList entries = resourcedir.entryList();
153 QStringList result; 153 QStringList result;
154 for (QStringList::Iterator i=entries.begin(); i != entries.end(); ++i) 154 for (QStringList::Iterator i=entries.begin(); i != entries.end(); ++i)
155 result.append((*i).replace(QRegExp("\\.wav"),"")); 155 result.append((*i).replace(QRegExp("\\.wav"),""));
156 return result; 156 return result;
157} 157}
158 158
159static QImage load_image(const QString &name) 159static QImage load_image(const QString &name)
160{ 160{
161 QImage img = qembed_findImage(name.latin1()); 161 QImage img = qembed_findImage(name.latin1());
162 if ( img.isNull() ) { 162 if ( img.isNull() ) {
163 // No inlined image, try file 163 // No inlined image, try file
164 QString f = Resource::findPixmap(name); 164 QString f = Resource::findPixmap(name);
165 if ( !f.isEmpty() ) 165 if ( !f.isEmpty() )
166 img.load(f); 166 img.load(f);
167 } 167 }
168 return img; 168 return img;
169} 169}
170 170
171/*! 171/*!
172 Returns the QImage called \a name. You should avoid including 172 Returns the QImage called \a name. You should avoid including
173 any filename type extension (e.g. .png, .xpm). 173 any filename type extension (e.g. .png, .xpm).
174*/ 174*/
175QImage Resource::loadImage( const QString &name) 175QImage Resource::loadImage( const QString &name)
176{ 176{
177 #ifndef QT_NO_DEPTH_32// have alpha-blended pixmaps 177 #ifndef QT_NO_DEPTH_32// have alpha-blended pixmaps
178 static QImage last_enabled; 178 static QImage last_enabled;
179 static QString last_enabled_name; 179 static QString last_enabled_name;
180 if ( name == last_enabled_name ) 180 if ( name == last_enabled_name )
181 return last_enabled; 181 return last_enabled;
182#endif 182#endif
183 QImage img = load_image(name); 183 QImage img = load_image(name);
184 #ifndef QT_NO_DEPTH_32// have alpha-blended pixmaps 184 #ifndef QT_NO_DEPTH_32// have alpha-blended pixmaps
185 if ( img.isNull() ) { 185 if ( img.isNull() ) {
186 // No file, try generating 186 // No file, try generating
187 if ( name[name.length()-1]=='d' && name.right(9)=="_disabled" ) { 187 if ( name[name.length()-1]=='d' && name.right(9)=="_disabled" ) {
188 last_enabled_name = name.left(name.length()-9); 188 last_enabled_name = name.left(name.length()-9);
189 last_enabled = load_image(last_enabled_name); 189 last_enabled = load_image(last_enabled_name);
190 if ( last_enabled.isNull() ) { 190 if ( last_enabled.isNull() ) {
191 last_enabled_name = QString::null; 191 last_enabled_name = QString::null;
192 } else { 192 } else {
193 img.detach(); 193 img.detach();
194 img.create( last_enabled.width(), last_enabled.height(), 32 ); 194 img.create( last_enabled.width(), last_enabled.height(), 32 );
195 for ( int y = 0; y < img.height(); y++ ) { 195 for ( int y = 0; y < img.height(); y++ ) {
196 for ( int x = 0; x < img.width(); x++ ) { 196 for ( int x = 0; x < img.width(); x++ ) {
197 QRgb p = last_enabled.pixel( x, y ); 197 QRgb p = last_enabled.pixel( x, y );
198 int a = qAlpha(p)/3; 198 int a = qAlpha(p)/3;
199 int g = qGray(qRed(p),qGreen(p),qBlue(p)); 199 int g = qGray(qRed(p),qGreen(p),qBlue(p));
200 img.setPixel( x, y, qRgba(g,g,g,a) ); 200 img.setPixel( x, y, qRgba(g,g,g,a) );
201 } 201 }
202 } 202 }
203 img.setAlphaBuffer( TRUE ); 203 img.setAlphaBuffer( TRUE );
204 } 204 }
205 } 205 }
206 } 206 }
207#endif 207#endif
208 return img; 208 return img;
209} 209}
210 210
211/*! 211/*!
212 \fn QIconSet Resource::loadIconSet( const QString &name ) 212 \fn QIconSet Resource::loadIconSet( const QString &name )
213 213
214 Returns a QIconSet for the pixmap named \a name. A disabled icon is 214 Returns a QIconSet for the pixmap named \a name. A disabled icon is
215 generated that conforms to the Qtopia look & feel. You should avoid 215 generated that conforms to the Qtopia look & feel. You should avoid
216 including any filename type extension (eg. .png, .xpm). 216 including any filename type extension (eg. .png, .xpm).
217*/ 217*/
diff --git a/library/timestring.cpp b/library/timestring.cpp
index 4c6fa72..6443b6b 100644
--- a/library/timestring.cpp
+++ b/library/timestring.cpp
@@ -1,365 +1,365 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include "timestring.h" 21#include "timestring.h"
22#include <qobject.h> 22#include <qobject.h>
23#include "qpeapplication.h" //for qApp 23#include <qpe/qpeapplication.h> //for qApp
24#include "config.h" 24#include "config.h"
25 25
26 26
27class TimeStringFormatKeeper : public QObject 27class TimeStringFormatKeeper : public QObject
28{ 28{
29 Q_OBJECT 29 Q_OBJECT
30public: 30public:
31 static DateFormat currentFormat() 31 static DateFormat currentFormat()
32 { 32 {
33 if ( !self ) 33 if ( !self )
34 self = new TimeStringFormatKeeper; 34 self = new TimeStringFormatKeeper;
35 return self->format; 35 return self->format;
36 } 36 }
37private slots: 37private slots:
38 void formatChanged( DateFormat f ) 38 void formatChanged( DateFormat f )
39 { 39 {
40 format = f; 40 format = f;
41 } 41 }
42private: 42private:
43 static TimeStringFormatKeeper *self; 43 static TimeStringFormatKeeper *self;
44 DateFormat format; 44 DateFormat format;
45 45
46 TimeStringFormatKeeper() 46 TimeStringFormatKeeper()
47 : QObject( qApp ) 47 : QObject( qApp )
48 { 48 {
49 Config config("qpe"); 49 Config config("qpe");
50 config.setGroup( "Date" ); 50 config.setGroup( "Date" );
51 format = DateFormat(QChar(config.readEntry("Separator", "/")[0]), 51 format = DateFormat(QChar(config.readEntry("Separator", "/")[0]),
52 (DateFormat::Order)config .readNumEntry("ShortOrder", DateFormat::DayMonthYear), 52 (DateFormat::Order)config .readNumEntry("ShortOrder", DateFormat::DayMonthYear),
53 (DateFormat::Order)config.readNumEntry("LongOrder", DateFormat::DayMonthYear)); 53 (DateFormat::Order)config.readNumEntry("LongOrder", DateFormat::DayMonthYear));
54 54
55 connect( qApp, SIGNAL( dateFormatChanged(DateFormat) ), 55 connect( qApp, SIGNAL( dateFormatChanged(DateFormat) ),
56 this, SLOT( formatChanged( DateFormat ) ) ); 56 this, SLOT( formatChanged( DateFormat ) ) );
57 } 57 }
58}; 58};
59 59
60TimeStringFormatKeeper *TimeStringFormatKeeper::self = 0; 60TimeStringFormatKeeper *TimeStringFormatKeeper::self = 0;
61 61
62QString DateFormat::toNumberString() const 62QString DateFormat::toNumberString() const
63{ 63{
64 QString buf = ""; 64 QString buf = "";
65 // for each part of the order 65 // for each part of the order
66 for (int i = 0; i < 3; i++) { 66 for (int i = 0; i < 3; i++) {
67 // switch on the relavent 3 bits. 67 // switch on the relavent 3 bits.
68 switch((_shortOrder >> (i * 3)) & 0x0007) { 68 switch((_shortOrder >> (i * 3)) & 0x0007) {
69 case 0x0001: 69 case 0x0001:
70 buf += QObject::tr( "D" ); 70 buf += QObject::tr( "D" );
71 break; 71 break;
72 case 0x0002: 72 case 0x0002:
73 buf += QObject::tr( "M" ); 73 buf += QObject::tr( "M" );
74 break; 74 break;
75 case 0x0004: 75 case 0x0004:
76 buf += QObject::tr( "Y" ); 76 buf += QObject::tr( "Y" );
77 break; 77 break;
78 } 78 }
79 if (i < 2) 79 if (i < 2)
80 buf += _shortSeparator; 80 buf += _shortSeparator;
81 } 81 }
82 return buf; 82 return buf;
83} 83}
84 84
85QString DateFormat::toWordString() const 85QString DateFormat::toWordString() const
86{ 86{
87 QString buf = ""; 87 QString buf = "";
88 // for each part of the order 88 // for each part of the order
89 for (int i = 0; i < 3; i++) { 89 for (int i = 0; i < 3; i++) {
90 // switch on the relavent 3 bits. 90 // switch on the relavent 3 bits.
91 switch((_longOrder >> (i * 3)) & 0x0007) { 91 switch((_longOrder >> (i * 3)) & 0x0007) {
92 case 0x0001: 92 case 0x0001:
93 buf += QObject::tr( "day" ); 93 buf += QObject::tr( "day" );
94 if (i < 2) { 94 if (i < 2) {
95 if ((_shortOrder << ((i+1) * 3)) & 0x0007) 95 if ((_shortOrder << ((i+1) * 3)) & 0x0007)
96 buf += ", "; 96 buf += ", ";
97 else 97 else
98 buf += " "; 98 buf += " ";
99 } 99 }
100 break; 100 break;
101 case 0x0002: 101 case 0x0002:
102 buf += QObject::tr( "month" ); 102 buf += QObject::tr( "month" );
103 if (i < 2) 103 if (i < 2)
104 buf += " "; 104 buf += " ";
105 break; 105 break;
106 case 0x0004: 106 case 0x0004:
107 buf += QObject::tr( "year" ); 107 buf += QObject::tr( "year" );
108 if (i < 2) 108 if (i < 2)
109 buf += ", "; 109 buf += ", ";
110 break; 110 break;
111 } 111 }
112 } 112 }
113 return buf; 113 return buf;
114} 114}
115 115
116QString DateFormat::numberDate(const QDate &d, int v) const 116QString DateFormat::numberDate(const QDate &d, int v) const
117{ 117{
118 QString buf = ""; 118 QString buf = "";
119 119
120 int pad = 2; 120 int pad = 2;
121 121
122 // for each part of the order 122 // for each part of the order
123 for (int i = 0; i < 3; i++) { 123 for (int i = 0; i < 3; i++) {
124 // switch on the relavent 3 bits. 124 // switch on the relavent 3 bits.
125 switch((_shortOrder >> (i * 3)) & 0x0007) { 125 switch((_shortOrder >> (i * 3)) & 0x0007) {
126 case 0x0001: 126 case 0x0001:
127 if (pad==2) buf += QString().sprintf("%02d",d.day()); 127 if (pad==2) buf += QString().sprintf("%02d",d.day());
128 else buf += QString().sprintf("%d",d.day()); 128 else buf += QString().sprintf("%d",d.day());
129 break; 129 break;
130 case 0x0002: 130 case 0x0002:
131 if (i==0) { // no padding with only MM/DD/YY format 131 if (i==0) { // no padding with only MM/DD/YY format
132 pad=0; 132 pad=0;
133 } 133 }
134 if (pad==2) buf += QString().sprintf("%02d",d.month()); 134 if (pad==2) buf += QString().sprintf("%02d",d.month());
135 else buf += QString().sprintf("%d",d.month()); 135 else buf += QString().sprintf("%d",d.month());
136 break; 136 break;
137 case 0x0004: 137 case 0x0004:
138 { 138 {
139 int year = d.year(); 139 int year = d.year();
140 if (!(v & longNumber)) 140 if (!(v & longNumber))
141 year = year % 100; 141 year = year % 100;
142 buf += QString().sprintf("%02d",year); 142 buf += QString().sprintf("%02d",year);
143 } 143 }
144 break; 144 break;
145 } 145 }
146 if (i < 2) 146 if (i < 2)
147 buf += _shortSeparator; 147 buf += _shortSeparator;
148 } 148 }
149 return buf; 149 return buf;
150} 150}
151 151
152QString DateFormat::wordDate(const QDate &d, int v) const 152QString DateFormat::wordDate(const QDate &d, int v) const
153{ 153{
154 QString buf = ""; 154 QString buf = "";
155 // for each part of the order 155 // for each part of the order
156 if (v & showWeekDay) { 156 if (v & showWeekDay) {
157 QString weekDay = d.dayName(d.dayOfWeek()); 157 QString weekDay = d.dayName(d.dayOfWeek());
158 if (!(v & longWord)) { 158 if (!(v & longWord)) {
159 weekDay = weekDay.left(3); 159 weekDay = weekDay.left(3);
160 } 160 }
161 buf += weekDay; 161 buf += weekDay;
162 if ((_longOrder & 0x0007) == 0x0002) 162 if ((_longOrder & 0x0007) == 0x0002)
163 buf += ' '; 163 buf += ' ';
164 else 164 else
165 buf += ", "; 165 buf += ", ";
166 } 166 }
167 167
168 for (int i = 0; i < 3; i++) { 168 for (int i = 0; i < 3; i++) {
169 // switch on the relavent 3 bits. 169 // switch on the relavent 3 bits.
170 switch((_longOrder >> (i * 3)) & 0x0007) { 170 switch((_longOrder >> (i * 3)) & 0x0007) {
171 case 0x0001: 171 case 0x0001:
172 if (i==1) { 172 if (i==1) {
173 buf += QString().sprintf("%02d, ",d.day()); 173 buf += QString().sprintf("%02d, ",d.day());
174 } else { 174 } else {
175 buf += QString().sprintf("%2d",d.day()); 175 buf += QString().sprintf("%2d",d.day());
176 if (separator()=='.') // 2002/1/11 176 if (separator()=='.') // 2002/1/11
177 buf += ". "; 177 buf += ". ";
178 else 178 else
179 buf += " "; 179 buf += " ";
180 } 180 }
181 break; 181 break;
182 case 0x0002: 182 case 0x0002:
183 { 183 {
184 QString monthName = d.monthName(d.month()); 184 QString monthName = d.monthName(d.month());
185 if (!(v & longWord)) { 185 if (!(v & longWord)) {
186 monthName = monthName.left(3); 186 monthName = monthName.left(3);
187 } 187 }
188 buf += monthName; 188 buf += monthName;
189 } 189 }
190 if (i < 2) 190 if (i < 2)
191 buf += " "; 191 buf += " ";
192 break; 192 break;
193 case 0x0004: 193 case 0x0004:
194 { 194 {
195 int year = d.year(); 195 int year = d.year();
196 if (!(v & longNumber)) 196 if (!(v & longNumber))
197 year = year % 100; 197 year = year % 100;
198 198
199 if (year < 10) 199 if (year < 10)
200 buf += "0"; 200 buf += "0";
201 201
202 buf += QString::number(year); 202 buf += QString::number(year);
203 } 203 }
204 if (i < 2) 204 if (i < 2)
205 buf += ", "; 205 buf += ", ";
206 break; 206 break;
207 } 207 }
208 } 208 }
209 return buf; 209 return buf;
210} 210}
211 211
212#ifndef QT_NO_DATASTREAM 212#ifndef QT_NO_DATASTREAM
213void DateFormat::save(QDataStream &d) const 213void DateFormat::save(QDataStream &d) const
214{ 214{
215 d << _shortSeparator.unicode(); 215 d << _shortSeparator.unicode();
216 uint v= _shortOrder; 216 uint v= _shortOrder;
217 d << v; 217 d << v;
218 v = _longOrder; 218 v = _longOrder;
219 d << v; 219 d << v;
220} 220}
221 221
222void DateFormat::load(QDataStream &d) 222void DateFormat::load(QDataStream &d)
223{ 223{
224 ushort value; 224 ushort value;
225 d >> value; 225 d >> value;
226 _shortSeparator = QChar(value); 226 _shortSeparator = QChar(value);
227 uint v = 0; 227 uint v = 0;
228 d >> v; 228 d >> v;
229 _shortOrder = (Order)v; 229 _shortOrder = (Order)v;
230 v = 0; 230 v = 0;
231 d >> v; 231 d >> v;
232 _longOrder = (Order)v; 232 _longOrder = (Order)v;
233} 233}
234 234
235QDataStream &operator<<(QDataStream &s, const DateFormat&df) 235QDataStream &operator<<(QDataStream &s, const DateFormat&df)
236{ 236{
237 df.save(s); 237 df.save(s);
238 return s; 238 return s;
239} 239}
240QDataStream &operator>>(QDataStream &s, DateFormat&df) 240QDataStream &operator>>(QDataStream &s, DateFormat&df)
241{ 241{
242 df.load(s); 242 df.load(s);
243 return s; 243 return s;
244} 244}
245#endif 245#endif
246 246
247QString TimeString::shortDate( const QDate &d, DateFormat dtf ) 247QString TimeString::shortDate( const QDate &d, DateFormat dtf )
248{ 248{
249 return dtf.wordDate(d); 249 return dtf.wordDate(d);
250} 250}
251 251
252QString TimeString::dateString( const QDate &d, DateFormat dtf ) 252QString TimeString::dateString( const QDate &d, DateFormat dtf )
253{ 253{
254 return dtf.wordDate(d, DateFormat::longNumber | DateFormat::longWord); 254 return dtf.wordDate(d, DateFormat::longNumber | DateFormat::longWord);
255} 255}
256 256
257 257
258QString TimeString::longDateString( const QDate &d, DateFormat dtf ) 258QString TimeString::longDateString( const QDate &d, DateFormat dtf )
259{ 259{
260 return dtf.wordDate(d, DateFormat::showWeekDay | DateFormat::longNumber 260 return dtf.wordDate(d, DateFormat::showWeekDay | DateFormat::longNumber
261 | DateFormat::longWord); 261 | DateFormat::longWord);
262} 262}
263 263
264DateFormat TimeString::currentDateFormat() 264DateFormat TimeString::currentDateFormat()
265{ 265{
266 return TimeStringFormatKeeper::currentFormat(); 266 return TimeStringFormatKeeper::currentFormat();
267} 267}
268 268
269 269
270QString TimeString::dateString( const QDateTime &dt, bool ampm, bool seconds, DateFormat dtf ) 270QString TimeString::dateString( const QDateTime &dt, bool ampm, bool seconds, DateFormat dtf )
271{ 271{
272 const QDate& d = dt.date(); 272 const QDate& d = dt.date();
273 const QTime& t = dt.time(); 273 const QTime& t = dt.time();
274 274
275 // based on QDateTime::toString() 275 // based on QDateTime::toString()
276 QString buf = timeString(t,ampm,seconds); 276 QString buf = timeString(t,ampm,seconds);
277 buf += " "; 277 buf += " ";
278 buf += longDateString( d, dtf ); 278 buf += longDateString( d, dtf );
279 279
280 return buf; 280 return buf;
281} 281}
282 282
283QString TimeString::timeString( const QTime &t, bool ampm, bool seconds ) 283QString TimeString::timeString( const QTime &t, bool ampm, bool seconds )
284{ 284{
285 if ( !ampm ) { 285 if ( !ampm ) {
286 if ( seconds ) 286 if ( seconds )
287 return t.toString(); 287 return t.toString();
288 QString r = QString::number(t.hour()); 288 QString r = QString::number(t.hour());
289 if ( t.hour() < 10 ) r.prepend( "0" ); 289 if ( t.hour() < 10 ) r.prepend( "0" );
290 r.append( ":" ); 290 r.append( ":" );
291 if ( t.minute() < 10 ) r.append( "0" ); 291 if ( t.minute() < 10 ) r.append( "0" );
292 r.append(QString::number(t.minute())); 292 r.append(QString::number(t.minute()));
293 return r; 293 return r;
294 } 294 }
295 // ### else the hard case that should disappear in Qt 3.0 295 // ### else the hard case that should disappear in Qt 3.0
296 QString argString = seconds ? "%4:%5:%6 %7" : "%4:%5 %7"; 296 QString argString = seconds ? "%4:%5:%6 %7" : "%4:%5 %7";
297 int hour = t.hour(); 297 int hour = t.hour();
298 QString strMin = QString::number( t.minute() ); 298 QString strMin = QString::number( t.minute() );
299 QString strSec = QString::number( t.second() ); 299 QString strSec = QString::number( t.second() );
300 if ( hour > 12 ) 300 if ( hour > 12 )
301 argString = argString.arg( hour - 12, 2 ); 301 argString = argString.arg( hour - 12, 2 );
302 else { 302 else {
303 if ( hour == 0 ) 303 if ( hour == 0 )
304 argString = argString.arg( 12 ); 304 argString = argString.arg( 12 );
305 else 305 else
306 argString = argString.arg( hour, 2 ); 306 argString = argString.arg( hour, 2 );
307 } 307 }
308 if ( t.minute() < 10 ) 308 if ( t.minute() < 10 )
309 strMin.prepend( "0" ); 309 strMin.prepend( "0" );
310 if ( t.second() < 10 ) 310 if ( t.second() < 10 )
311 strSec.prepend( "0" ); 311 strSec.prepend( "0" );
312 argString = argString.arg( strMin ); 312 argString = argString.arg( strMin );
313 if ( seconds ) 313 if ( seconds )
314 argString = argString.arg( strSec ); 314 argString = argString.arg( strSec );
315 if ( hour >= 12 ) 315 if ( hour >= 12 )
316 argString = argString.arg( QObject::tr("PM") ); 316 argString = argString.arg( QObject::tr("PM") );
317 else 317 else
318 argString = argString.arg( QObject::tr("AM") ); 318 argString = argString.arg( QObject::tr("AM") );
319 return argString; 319 return argString;
320} 320}
321 321
322QString TimeString::shortTime( bool ampm, bool seconds ) 322QString TimeString::shortTime( bool ampm, bool seconds )
323{ 323{
324 static const char* const day[] = { 324 static const char* const day[] = {
325 QT_TRANSLATE_NOOP( "QObject", "Mon" ), 325 QT_TRANSLATE_NOOP( "QObject", "Mon" ),
326 QT_TRANSLATE_NOOP( "QObject", "Tue" ), 326 QT_TRANSLATE_NOOP( "QObject", "Tue" ),
327 QT_TRANSLATE_NOOP( "QObject", "Wed" ), 327 QT_TRANSLATE_NOOP( "QObject", "Wed" ),
328 QT_TRANSLATE_NOOP( "QObject", "Thu" ), 328 QT_TRANSLATE_NOOP( "QObject", "Thu" ),
329 QT_TRANSLATE_NOOP( "QObject", "Fri" ), 329 QT_TRANSLATE_NOOP( "QObject", "Fri" ),
330 QT_TRANSLATE_NOOP( "QObject", "Sat" ), 330 QT_TRANSLATE_NOOP( "QObject", "Sat" ),
331 QT_TRANSLATE_NOOP( "QObject", "Sun" ) 331 QT_TRANSLATE_NOOP( "QObject", "Sun" )
332 }; 332 };
333 // just create a shorter time String 333 // just create a shorter time String
334 QDateTime dtTmp = QDateTime::currentDateTime(); 334 QDateTime dtTmp = QDateTime::currentDateTime();
335 QString strTime; 335 QString strTime;
336 strTime = QObject::tr( day[dtTmp.date().dayOfWeek()-1] ) + " " + 336 strTime = QObject::tr( day[dtTmp.date().dayOfWeek()-1] ) + " " +
337 timeString( dtTmp.time(), ampm, seconds ); 337 timeString( dtTmp.time(), ampm, seconds );
338 return strTime; 338 return strTime;
339} 339}
340 340
341QString TimeString::dateString( const QDateTime &t, bool ampm ) 341QString TimeString::dateString( const QDateTime &t, bool ampm )
342{ 342{
343 return dateString(t,ampm,FALSE); 343 return dateString(t,ampm,FALSE);
344} 344}
345 345
346QString TimeString::timeString( const QTime &t, bool ampm) 346QString TimeString::timeString( const QTime &t, bool ampm)
347{ 347{
348 return timeString(t,ampm,FALSE); 348 return timeString(t,ampm,FALSE);
349} 349}
350 350
351QString TimeString::shortTime( bool ampm ) 351QString TimeString::shortTime( bool ampm )
352{ 352{
353 return shortTime(ampm,FALSE); 353 return shortTime(ampm,FALSE);
354} 354}
355 355
356QString TimeString::numberDateString( const QDate &d, DateFormat dtf ) 356QString TimeString::numberDateString( const QDate &d, DateFormat dtf )
357{ 357{
358 return dtf.numberDate(d); 358 return dtf.numberDate(d);
359} 359}
360QString TimeString::longNumberDateString( const QDate &d, DateFormat dtf ) 360QString TimeString::longNumberDateString( const QDate &d, DateFormat dtf )
361{ 361{
362 return dtf.numberDate(d,DateFormat::longNumber); 362 return dtf.numberDate(d,DateFormat::longNumber);
363} 363}
364 364
365#include "timestring.moc" 365#include "timestring.moc"