summaryrefslogtreecommitdiff
path: root/libopie
Unidiff
Diffstat (limited to 'libopie') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/libopie.pro14
-rw-r--r--libopie/orecurrancewidget.cpp2
-rw-r--r--libopie/pim/ocontactaccessbackend_vcard.cpp11
-rw-r--r--libopie/pim/oevent.cpp427
-rw-r--r--libopie/pim/oevent.h198
-rw-r--r--libopie/pim/orecur.cpp25
-rw-r--r--libopie/pim/orecur.h12
-rw-r--r--libopie/pim/otimezone.cpp104
-rw-r--r--libopie/pim/otimezone.h71
-rw-r--r--libopie/pim/otodo.cpp2
-rw-r--r--libopie/pim/test/oevent_test.cpp23
-rw-r--r--libopie/pim/test/oevent_test.pro11
-rw-r--r--libopie/pim/test/test_todo.cpp36
-rw-r--r--libopie/pim/test/todo_test.pro11
-rw-r--r--libopie/tododb.cpp268
-rw-r--r--libopie/tododb.h46
-rw-r--r--libopie/todoevent.cpp339
-rw-r--r--libopie/todoevent.h191
-rw-r--r--libopie/todoresource.h14
-rw-r--r--libopie/todovcalresource.cpp158
-rw-r--r--libopie/todovcalresource.h42
21 files changed, 921 insertions, 1084 deletions
diff --git a/libopie/libopie.pro b/libopie/libopie.pro
index 675e1fa..2b843c1 100644
--- a/libopie/libopie.pro
+++ b/libopie/libopie.pro
@@ -1,13 +1,13 @@
1TEMPLATE = lib 1TEMPLATE = lib
2CONFIG += qte warn_on release 2CONFIG += qte warn_on release
3HEADERS = ofontmenu.h \ 3HEADERS = ofontmenu.h \
4 ocolorbutton.h \ 4 ocolorbutton.h \
5 ofiledialog.h ofileselector.h tododb.h \ 5 ofiledialog.h ofileselector.h \
6 ocheckitem.h todoevent.h todoresource.h \ 6 ocheckitem.h \
7 todovcalresource.h xmltree.h \ 7 xmltree.h \
8 colordialog.h colorpopupmenu.h \ 8 colordialog.h colorpopupmenu.h \
9 oclickablelabel.h oprocctrl.h \ 9 oclickablelabel.h oprocctrl.h \
10 oprocess.h odevice.h odevicebutton.h \ 10 oprocess.h odevice.h odevicebutton.h \
11 otimepicker.h otabwidget.h \ 11 otimepicker.h otabwidget.h \
12 otabbar.h otabinfo.h \ 12 otabbar.h otabinfo.h \
13 ofontselector.h \ 13 ofontselector.h \
@@ -33,23 +33,25 @@ HEADERS = ofontmenu.h \
33 pim/opimxrefmanager.h \ 33 pim/opimxrefmanager.h \
34 pim/opimmaintainer.h \ 34 pim/opimmaintainer.h \
35 pim/opimnotify.h \ 35 pim/opimnotify.h \
36 pim/opimnotifymanager.h \ 36 pim/opimnotifymanager.h \
37 pim/opimmainwindow.h \ 37 pim/opimmainwindow.h \
38 pim/opimresolver.h \ 38 pim/opimresolver.h \
39 pim/oevent.h \
40 pim/otimezone.h \
39 orecurrancewidget.h \ 41 orecurrancewidget.h \
40 oticker.h 42 oticker.h
41# pim/otodoaccesssql.h \ 43# pim/otodoaccesssql.h \
42 44
43SOURCES = ofontmenu.cc \ 45SOURCES = ofontmenu.cc \
44 ocolorbutton.cpp \ 46 ocolorbutton.cpp \
45 sharp_compat.cpp \ 47 sharp_compat.cpp \
46 xmltree.cc \ 48 xmltree.cc \
47 ofiledialog.cc ofileselector.cc \ 49 ofiledialog.cc ofileselector.cc \
48 ocheckitem.cpp tododb.cpp todoevent.cpp \ 50 ocheckitem.cpp \
49 todovcalresource.cpp colordialog.cpp \ 51 colordialog.cpp \
50 colorpopupmenu.cpp oclickablelabel.cpp \ 52 colorpopupmenu.cpp oclickablelabel.cpp \
51 oprocctrl.cpp oprocess.cpp \ 53 oprocctrl.cpp oprocess.cpp \
52 odevice.cpp odevicebutton.cpp otimepicker.cpp \ 54 odevice.cpp odevicebutton.cpp otimepicker.cpp \
53 otabwidget.cpp otabbar.cpp \ 55 otabwidget.cpp otabbar.cpp \
54 ofontselector.cpp \ 56 ofontselector.cpp \
55 pim/otodo.cpp \ 57 pim/otodo.cpp \
@@ -68,12 +70,14 @@ SOURCES = ofontmenu.cc \
68 pim/opimxrefmanager.cpp \ 70 pim/opimxrefmanager.cpp \
69 pim/opimmaintainer.cpp \ 71 pim/opimmaintainer.cpp \
70 pim/opimnotify.cpp \ 72 pim/opimnotify.cpp \
71 pim/opimnotifymanager.cpp \ 73 pim/opimnotifymanager.cpp \
72 pim/opimmainwindow.cpp \ 74 pim/opimmainwindow.cpp \
73 pim/opimresolver.cpp \ 75 pim/opimresolver.cpp \
76 pim/oevent.cpp \
77 pim/otimezone.cpp \
74 orecurrancewidget.cpp \ 78 orecurrancewidget.cpp \
75 oticker.cpp 79 oticker.cpp
76# pim/otodoaccesssql.cpp \ 80# pim/otodoaccesssql.cpp \
77 81
78TARGET = opie 82TARGET = opie
79INCLUDEPATH += $(OPIEDIR)/include 83INCLUDEPATH += $(OPIEDIR)/include
diff --git a/libopie/orecurrancewidget.cpp b/libopie/orecurrancewidget.cpp
index 0484ab9..db86184 100644
--- a/libopie/orecurrancewidget.cpp
+++ b/libopie/orecurrancewidget.cpp
@@ -174,13 +174,13 @@ ORecur ORecurranceWidget::recurrence()const {
174 rpTmp.setFrequency(spinFreq->value() ); 174 rpTmp.setFrequency(spinFreq->value() );
175 rpTmp.setHasEndDate( !chkNoEnd->isChecked() ); 175 rpTmp.setHasEndDate( !chkNoEnd->isChecked() );
176 if ( rpTmp.hasEndDate() ) { 176 if ( rpTmp.hasEndDate() ) {
177 rpTmp.setEndDate( end ); 177 rpTmp.setEndDate( end );
178 } 178 }
179 // timestamp it... 179 // timestamp it...
180 rpTmp.setCreateTime( time( NULL ) ); 180// rpTmp.setCreateTime( ); current DateTime is already set -zecke
181 return rpTmp; 181 return rpTmp;
182} 182}
183QDate ORecurranceWidget::endDate()const { 183QDate ORecurranceWidget::endDate()const {
184 return end; 184 return end;
185} 185}
186void ORecurranceWidget::slotSetRType(int rtype) { 186void ORecurranceWidget::slotSetRType(int rtype) {
diff --git a/libopie/pim/ocontactaccessbackend_vcard.cpp b/libopie/pim/ocontactaccessbackend_vcard.cpp
index 622d40a..e537269 100644
--- a/libopie/pim/ocontactaccessbackend_vcard.cpp
+++ b/libopie/pim/ocontactaccessbackend_vcard.cpp
@@ -14,12 +14,21 @@
14 * 14 *
15 * ===================================================================== 15 * =====================================================================
16 * Version: $Id$ 16 * Version: $Id$
17 * ===================================================================== 17 * =====================================================================
18 * History: 18 * History:
19 * $Log$ 19 * $Log$
20 * Revision 1.8 2003/02/21 16:52:49 zecke
21 * -Remove old Todo classes they're deprecated and today I already using the
22 * new API
23 * -Guard against self assignment in OTodo
24 * -Add test apps for OPIM
25 * -Opiefied Event classes
26 * -Added TimeZone handling and pinning of TimeZones to OEvent
27 * -Adjust ORecur and the widget to better timezone behaviour
28 *
20 * Revision 1.7 2003/02/16 22:25:46 zecke 29 * Revision 1.7 2003/02/16 22:25:46 zecke
21 * 0000276 Fix for that bug.. or better temp workaround 30 * 0000276 Fix for that bug.. or better temp workaround
22 * A Preferred Number is HOME|VOICE 31 * A Preferred Number is HOME|VOICE
23 * A CellPhone is HOME|VOICE|CELL the type & HOME|VOICE test 32 * A CellPhone is HOME|VOICE|CELL the type & HOME|VOICE test
24 * triggers both 33 * triggers both
25 * and the cell phone number overrides the other entries.. 34 * and the cell phone number overrides the other entries..
@@ -71,13 +80,13 @@ bool OContactAccessBackend_VCard::load ()
71{ 80{
72 m_map.clear(); 81 m_map.clear();
73 m_dirty = false; 82 m_dirty = false;
74 83
75 VObject* obj = 0l; 84 VObject* obj = 0l;
76 85
77 if ( QFile( m_file ).exists() ){ 86 if ( QFile::exists(m_file) ){
78 obj = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() ); 87 obj = Parse_MIME_FromFileName( QFile::encodeName(m_file).data() );
79 if ( !obj ) 88 if ( !obj )
80 return false; 89 return false;
81 }else{ 90 }else{
82 qWarning("File \"%s\" not found !", m_file.latin1() ); 91 qWarning("File \"%s\" not found !", m_file.latin1() );
83 return false; 92 return false;
diff --git a/libopie/pim/oevent.cpp b/libopie/pim/oevent.cpp
new file mode 100644
index 0000000..71b9441
--- a/dev/null
+++ b/libopie/pim/oevent.cpp
@@ -0,0 +1,427 @@
1#include <qshared.h>
2
3#include <qpe/palmtopuidgen.h>
4#include <qpe/categories.h>
5
6#include "orecur.h"
7#include "opimresolver.h"
8#include "opimnotifymanager.h"
9
10#include "oevent.h"
11
12namespace OCalendarHelper {
13 static int week( const QDate& date) {
14 // Calculates the week this date is in within that
15 // month. Equals the "row" is is in in the month view
16 int week = 1;
17 QDate tmp( date.year(), date.month(), 1 );
18 if ( date.dayOfWeek() < tmp.dayOfWeek() )
19 ++week;
20
21 week += ( date.day() - 1 ) / 7;
22
23 return week;
24 }
25 static int occurence( const QDate& date) {
26 // calculates the number of occurrances of this day of the
27 // week till the given date (e.g 3rd Wednesday of the month)
28 return ( date.day() - 1 ) / 7 + 1;
29 }
30 static int dayOfWeek( char day ) {
31 int dayOfWeek = 1;
32 char i = ORecur::MON;
33 while ( !( i & day ) && i <= ORecur::SUN ) {
34 i <<= 1;
35 ++dayOfWeek;
36 }
37 return dayOfWeek;
38 }
39 static int monthDiff( const QDate& first, const QDate& second ) {
40 return ( second.year() - first.year() ) * 12 +
41 second.month() - first.month();
42 }
43}
44
45struct OEvent::Data : public QShared {
46 Data() : QShared() {
47 recur = 0;
48 manager = 0;
49 isAllDay = false;
50 }
51 ~Data() {
52 delete manager;
53 delete recur;
54 }
55 QString description;
56 QString location;
57 OPimNotifyManager* manager;
58 ORecur* recur;
59 QString note;
60 QDateTime created;
61 QDateTime start;
62 QDateTime end;
63 bool isAllDay : 1;
64 QString timezone;
65};
66
67OEvent::OEvent( int uid )
68 : OPimRecord( uid ) {
69 data = new Data;
70}
71OEvent::OEvent( const OEvent& ev)
72 : OPimRecord( ev ), data( ev.data )
73{
74 data->ref();
75}
76OEvent::~OEvent() {
77 if ( data->deref() ) {
78 delete data;
79 data = 0;
80 }
81}
82OEvent& OEvent::operator=( const OEvent& ev) {
83 if ( *this == ev ) return *this;
84
85 OPimRecord::operator=( ev );
86 ev.data->ref();
87 deref();
88 data = ev.data;
89
90
91 return *this;
92}
93QString OEvent::description()const {
94 return data->description;
95}
96void OEvent::setDescription( const QString& description ) {
97 changeOrModify();
98 data->description = description;
99}
100void OEvent::setLocation( const QString& loc ) {
101 changeOrModify();
102 data->location = loc;
103}
104QString OEvent::location()const {
105 return data->location;
106}
107OPimNotifyManager &OEvent::notifiers() {
108 // I hope we can skip the changeOrModify here
109 // the notifier should take care of it
110 // and OPimNotify is shared too
111 if (!data->manager )
112 data->manager = new OPimNotifyManager;
113
114 return *data->manager;
115}
116bool OEvent::hasNotifiers()const {
117 return ( data->manager);
118}
119ORecur OEvent::recurrence()const {
120 if (!data->recur)
121 data->recur = new ORecur;
122
123 return *data->recur;
124}
125void OEvent::setRecurrence( const ORecur& rec) {
126 changeOrModify();
127 if (data->recur )
128 (*data->recur) = rec;
129 else
130 data->recur = new ORecur( rec );
131}
132bool OEvent::hasRecurrence()const {
133 return data->recur;
134}
135QString OEvent::note()const {
136 return data->note;
137}
138void OEvent::setNote( const QString& note ) {
139 changeOrModify();
140 data->note = note;
141}
142QDateTime OEvent::createdDateTime()const {
143 return data->created;
144}
145void OEvent::setCreatedDateTime( const QDateTime& time ) {
146 changeOrModify();
147 data->created = time;
148}
149QDateTime OEvent::startDateTime()const {
150 if ( data->isAllDay )
151 return QDateTime( data->start.date(), QTime(0, 0, 0 ) );
152 return data->start;
153}
154QDateTime OEvent::startDateTimeInZone()const {
155 /* if no timezone, or all day event or if the current and this timeZone match... */
156 if (data->timezone.isEmpty() || data->isAllDay || data->timezone == OTimeZone::current().timeZone() ) return startDateTime();
157
158 OTimeZone zone(data->timezone );
159 return zone.toDateTime( data->start, OTimeZone::current() );
160}
161void OEvent::setStartDateTime( const QDateTime& dt ) {
162 changeOrModify();
163 data->start = dt;
164}
165QDateTime OEvent::endDateTime()const {
166 /*
167 * if all Day event the end time needs
168 * to be on the same day as the start
169 */
170 if ( data->isAllDay )
171 return QDateTime( data->start.date(), QTime(23, 59, 59 ) );
172 return data->end;
173}
174QDateTime OEvent::endDateTimeInZone()const {
175 /* if no timezone, or all day event or if the current and this timeZone match... */
176 if (data->timezone.isEmpty() || data->isAllDay || data->timezone == OTimeZone::current().timeZone() ) return endDateTime();
177
178 OTimeZone zone(data->timezone );
179 return zone.toDateTime( data->end, OTimeZone::current() );
180}
181void OEvent::setEndDateTime( const QDateTime& dt ) {
182 changeOrModify();
183 data->end = dt;
184}
185bool OEvent::isMultipleDay()const {
186 return data->end.date().day() - data->start.date().day();
187}
188bool OEvent::isAllDay()const {
189 return data->isAllDay;
190}
191void OEvent::setTimeZone( const QString& tz ) {
192 changeOrModify();
193 data->timezone = tz;
194}
195QString OEvent::timeZone()const {
196 return data->timezone;
197}
198bool OEvent::match( const QRegExp& )const {
199 // FIXME
200 return false;
201}
202QString OEvent::toRichText()const {
203 // FIXME
204 return "OEvent test";
205}
206QString OEvent::toShortText()const {
207 return "OEvent shotText";
208}
209QString OEvent::type()const {
210 return QString::fromLatin1("OEvent");
211}
212QString OEvent::recordField( int /*id */ )const {
213 return QString::null;
214}
215int OEvent::rtti() {
216 return OPimResolver::DateBook;
217}
218bool OEvent::loadFromStream( QDataStream& ) {
219 return true;
220}
221bool OEvent::saveToStream( QDataStream& )const {
222 return true;
223}
224void OEvent::changeOrModify() {
225 if ( data->count != 1 ) {
226 data->deref();
227 Data* d2 = new Data;
228 d2->description = data->description;
229 d2->location = data->location;
230 d2->manager = data->manager;
231 d2->recur = data->recur;
232 d2->note = data->note;
233 d2->created = data->created;
234 d2->start = data->start;
235 d2->end = data->end;
236 d2->isAllDay = data->isAllDay;
237 d2->timezone = data->timezone;
238
239 data = d2;
240 }
241}
242void OEvent::deref() {
243 if ( data->deref() ) {
244 delete data;
245 data = 0;
246 }
247}
248// FIXME
249QMap<int, QString> OEvent::toMap()const {
250 return QMap<int, QString>();
251}
252QMap<QString, QString> OEvent::toExtraMap()const {
253 return QMap<QString, QString>();
254}
255
256
257struct OEffectiveEvent::Data : public QShared {
258 Data() : QShared() {
259 }
260 OEvent event;
261 QDate date;
262 QTime start, end;
263 QDate startDate, endDate;
264 bool dates : 1;
265};
266
267OEffectiveEvent::OEffectiveEvent() {
268 data = new Data;
269 data->date = QDate::currentDate();
270 data->start = data->end = QTime::currentTime();
271 data->dates = false;
272}
273OEffectiveEvent::OEffectiveEvent( const OEvent& ev, const QDate& startDate,
274 Position pos ) {
275 data = new Data;
276 data->event = ev;
277 data->date = startDate;
278 if ( pos & Start )
279 data->start = ev.startDateTime().time();
280 else
281 data->start = QTime( 0, 0, 0 );
282
283 if ( pos & End )
284 data->end = ev.endDateTime().time();
285 else
286 data->end = QTime( 23, 59, 59 );
287
288 data->dates = false;
289}
290OEffectiveEvent::OEffectiveEvent( const OEffectiveEvent& ev) {
291 data = ev.data;
292 data->ref();
293}
294OEffectiveEvent::~OEffectiveEvent() {
295 if ( data->deref() ) {
296 delete data;
297 data = 0;
298 }
299}
300OEffectiveEvent& OEffectiveEvent::operator=( const OEffectiveEvent& ev ) {
301 if ( *this == ev ) return *this;
302
303 ev.data->ref();
304 deref();
305 data = ev.data;
306
307 return *this;
308}
309
310void OEffectiveEvent::setStartTime( const QTime& ti) {
311 changeOrModify();
312 data->start = ti;
313}
314void OEffectiveEvent::setEndTime( const QTime& en) {
315 changeOrModify();
316 data->end = en;
317}
318void OEffectiveEvent::setEvent( const OEvent& ev) {
319 changeOrModify();
320 data->event = ev;
321}
322void OEffectiveEvent::setDate( const QDate& da) {
323 changeOrModify();
324 data->date = da;
325}
326void OEffectiveEvent::setEffectiveDates( const QDate& from,
327 const QDate& to ) {
328 if (!from.isValid() ) {
329 data->dates = false;
330 return;
331 }
332
333 data->startDate = from;
334 data->endDate = to;
335}
336QString OEffectiveEvent::description()const {
337 return data->event.description();
338}
339QString OEffectiveEvent::location()const {
340 return data->event.location();
341}
342QString OEffectiveEvent::note()const {
343 return data->event.note();
344}
345OEvent OEffectiveEvent::event()const {
346 return data->event;
347}
348QTime OEffectiveEvent::startTime()const {
349 return data->start;
350}
351QTime OEffectiveEvent::endTime()const {
352 return data->end;
353}
354QDate OEffectiveEvent::date()const {
355 return data->date;
356}
357int OEffectiveEvent::length()const {
358 return (data->end.hour() * 60 - data->start.hour() * 60)
359 + QABS(data->start.minute() - data->end.minute() );
360}
361int OEffectiveEvent::size()const {
362 return ( data->end.hour() - data->start.hour() ) * 3600
363 + (data->end.minute() - data->start.minute() * 60
364 + data->end.second() - data->start.second() );
365}
366QDate OEffectiveEvent::startDate()const {
367 if ( data->dates )
368 return data->startDate;
369 else if ( data->event.hasRecurrence() ) // single day, since multi-day should have a d pointer
370 return data->date;
371 else
372 return data->event.startDateTime().date();
373}
374QDate OEffectiveEvent::endDate()const {
375 if ( data->dates )
376 return data->endDate;
377 else if ( data->event.hasRecurrence() )
378 return data->date;
379 else
380 return data->event.endDateTime().date();
381}
382void OEffectiveEvent::deref() {
383 if ( data->deref() ) {
384 delete data;
385 data = 0;
386 }
387}
388void OEffectiveEvent::changeOrModify() {
389 if ( data->count != 1 ) {
390 data->deref();
391 Data* d2 = new Data;
392 d2->event = data->event;
393 d2->date = data->date;
394 d2->start = data->start;
395 d2->end = data->end;
396 d2->startDate = data->startDate;
397 d2->endDate = data->endDate;
398 d2->dates = data->dates;
399 data = d2;
400 }
401}
402bool OEffectiveEvent::operator<( const OEffectiveEvent &e ) const{
403 if ( data->date < e.date() )
404 return TRUE;
405 if ( data->date == e.date() )
406 return ( startTime() < e.startTime() );
407 else
408 return FALSE;
409}
410bool OEffectiveEvent::operator<=( const OEffectiveEvent &e ) const{
411 return (data->date <= e.date() );
412}
413bool OEffectiveEvent::operator==( const OEffectiveEvent &e ) const {
414 return ( date() == e.date()
415 && startTime() == e.startTime()
416 && endTime()== e.endTime()
417 && event() == e.event() );
418}
419bool OEffectiveEvent::operator!=( const OEffectiveEvent &e ) const {
420 return !(*this == e );
421}
422bool OEffectiveEvent::operator>( const OEffectiveEvent &e ) const {
423 return !(*this <= e );
424}
425bool OEffectiveEvent::operator>= ( const OEffectiveEvent &e ) const {
426 return !(*this < e);
427}
diff --git a/libopie/pim/oevent.h b/libopie/pim/oevent.h
new file mode 100644
index 0000000..4489be7
--- a/dev/null
+++ b/libopie/pim/oevent.h
@@ -0,0 +1,198 @@
1// CONTAINS GPLed code of TT
2
3#ifndef OPIE_PIM_EVENT_H
4#define OPIE_PIM_EVENT_H
5
6#include <qstring.h>
7#include <qdatetime.h>
8#include <qvaluelist.h>
9
10#include <qpe/recordfields.h>
11#include <qpe/palmtopuidgen.h>
12
13#include "otimezone.h"
14#include "opimrecord.h"
15
16namespace OCalendarHelper {
17 /** calculate the week number of the date */
18 static int week( const QDate& );
19 /** calculate the occurence of week days since the start of the month */
20 static int ocurrence( const QDate& );
21
22 // returns the dayOfWeek for the *first* day it finds (ignores
23 // any further days!). Returns 1 (Monday) if there isn't any day found
24 static int dayOfWeek( char day );
25
26 /** returns the diff of month */
27 static int monthDiff( const QDate& first, const QDate& second );
28
29}
30
31class OPimNotifyManager;
32class ORecur;
33class OEvent : public OPimRecord {
34public:
35 typedef QValueList<OEvent> ValueList;
36 enum RecordFields {
37 Uid = Qtopia::UID_ID,
38 Category = Qtopia::CATEGORY_ID,
39 Description,
40 Location,
41 Alarm,
42 Reminder,
43 Recurrence,
44 Note,
45 Created,
46 StartDate,
47 EndDate,
48 AllDay,
49 TimeZone
50 };
51
52 OEvent(int uid = 0);
53 OEvent( const OEvent& );
54 ~OEvent();
55 OEvent &operator=( const OEvent& );
56
57 QString description()const;
58 void setDescription( const QString& description );
59
60 QString location()const;
61 void setLocation( const QString& loc );
62
63 bool hasNotifiers()const;
64 OPimNotifyManager &notifiers();
65
66 ORecur recurrence()const;
67 void setRecurrence( const ORecur& );
68 bool hasRecurrence()const;
69
70 QString note()const;
71 void setNote( const QString& note );
72
73
74 QDateTime createdDateTime()const;
75 void setCreatedDateTime( const QDateTime& dt);
76
77 /** set the date to dt. dt is the QDateTime in localtime */
78 void setStartDateTime( const QDateTime& );
79 /** returns the datetime in the local timeZone */
80 QDateTime startDateTime()const;
81
82 /** returns the start datetime in the current zone */
83 QDateTime startDateTimeInZone()const;
84
85 /** in current timezone */
86 void setEndDateTime( const QDateTime& );
87 /** in current timezone */
88 QDateTime endDateTime()const;
89 QDateTime endDateTimeInZone()const;
90
91 bool isMultipleDay()const;
92 bool isAllDay()const;
93 void setAllDay( bool isAllDay );
94
95 /* pin this event to a timezone! FIXME */
96 void setTimeZone( const QString& timeZone );
97 QString timeZone()const;
98
99
100 bool match( const QRegExp& )const;
101
102
103
104
105 /* needed reimp */
106 QString toRichText()const;
107 QString toShortText()const;
108 QString type()const;
109
110 QMap<int, QString> toMap()const;
111 QMap<QString, QString> toExtraMap()const;
112 QString recordField(int )const;
113
114 static int rtti();
115
116 bool loadFromStream( QDataStream& );
117 bool saveToStream( QDataStream& )const;
118
119/* bool operator==( const OEvent& );
120 bool operator!=( const OEvent& );
121 bool operator<( const OEvent& );
122 bool operator<=( const OEvent& );
123 bool operator>( const OEvent& );
124 bool operator>=(const OEvent& );
125*/
126private:
127 inline void changeOrModify();
128 void deref();
129 struct Data;
130 Data* data;
131 class Private;
132 Private* priv;
133
134};
135
136/**
137 * AN Event can span through multiple days. We split up a multiday eve
138 */
139
140class OEffectiveEvent {
141public:
142 QValueList<OEffectiveEvent> ValueList;
143 enum Position { MidWay, Start, End, StartEnd };
144 // If we calculate the effective event of a multi-day event
145 // we have to figure out whether we are at the first day,
146 // at the end, or anywhere else ("middle"). This is important
147 // for the start/end times (00:00/23:59)
148 // MidWay: 00:00 -> 23:59, as we are "in the middle" of a multi-
149 // day event
150 // Start: start time -> 23:59
151 // End: 00:00 -> end time
152 // Start | End == StartEnd: for single-day events (default)
153 // here we draw start time -> end time
154 OEffectiveEvent();
155 OEffectiveEvent( const OEvent& event, const QDate& startDate, Position pos = StartEnd );
156 OEffectiveEvent( const OEffectiveEvent& );
157 OEffectiveEvent &operator=(const OEffectiveEvent& );
158 ~OEffectiveEvent();
159
160 void setStartTime( const QTime& );
161 void setEndTime( const QTime& );
162 void setEvent( const OEvent& );
163 void setDate( const QDate& );
164
165 void setEffectiveDates( const QDate& from, const QDate& to );
166
167 QString description()const;
168 QString location()const;
169 QString note()const;
170 OEvent event()const;
171 QTime startTime()const;
172 QTime endTime()const;
173 QDate date()const;
174
175 /* return the length in hours */
176 int length()const;
177 int size()const;
178
179 QDate startDate()const;
180 QDate endDate()const;
181
182 bool operator<( const OEffectiveEvent &e ) const;
183 bool operator<=( const OEffectiveEvent &e ) const;
184 bool operator==( const OEffectiveEvent &e ) const;
185 bool operator!=( const OEffectiveEvent &e ) const;
186 bool operator>( const OEffectiveEvent &e ) const;
187 bool operator>= ( const OEffectiveEvent &e ) const;
188
189private:
190 void deref();
191 inline void changeOrModify();
192 class Private;
193 Private* priv;
194 struct Data;
195 Data* data;
196
197};
198#endif
diff --git a/libopie/pim/orecur.cpp b/libopie/pim/orecur.cpp
index daf3506..e6a4787 100644
--- a/libopie/pim/orecur.cpp
+++ b/libopie/pim/orecur.cpp
@@ -7,23 +7,23 @@
7struct ORecur::Data : public QShared { 7struct ORecur::Data : public QShared {
8 Data() : QShared() { 8 Data() : QShared() {
9 type = ORecur::NoRepeat; 9 type = ORecur::NoRepeat;
10 freq = -1; 10 freq = -1;
11 days = 0; 11 days = 0;
12 pos = 0; 12 pos = 0;
13 create = -1; 13 create = QDateTime::currentDateTime();
14 hasEnd = FALSE; 14 hasEnd = FALSE;
15 end = 0; 15 end = QDate::currentDate();
16 } 16 }
17 char days; // Q_UINT8 for 8 seven days;) 17 char days; // Q_UINT8 for 8 seven days;)
18 ORecur::RepeatType type; 18 ORecur::RepeatType type;
19 int freq; 19 int freq;
20 int pos; 20 int pos;
21 bool hasEnd : 1; 21 bool hasEnd : 1;
22 time_t end; 22 QDate end;
23 time_t create; 23 QDateTime create;
24 int rep; 24 int rep;
25 QString app; 25 QString app;
26 ExceptionList list; 26 ExceptionList list;
27 QDate start; 27 QDate start;
28}; 28};
29 29
@@ -49,12 +49,14 @@ void ORecur::deref() {
49 } 49 }
50} 50}
51bool ORecur::operator==( const ORecur& )const { 51bool ORecur::operator==( const ORecur& )const {
52 return false; 52 return false;
53} 53}
54ORecur &ORecur::operator=( const ORecur& re) { 54ORecur &ORecur::operator=( const ORecur& re) {
55 if ( *this == re ) return *this;
56
55 re.data->ref(); 57 re.data->ref();
56 deref(); 58 deref();
57 data = re.data; 59 data = re.data;
58 60
59 return *this; 61 return *this;
60} 62}
@@ -363,21 +365,18 @@ char ORecur::days() const{
363 return data->days; 365 return data->days;
364} 366}
365bool ORecur::hasEndDate()const { 367bool ORecur::hasEndDate()const {
366 return data->hasEnd; 368 return data->hasEnd;
367} 369}
368QDate ORecur::endDate()const { 370QDate ORecur::endDate()const {
369 return TimeConversion::fromUTC( data->end ).date(); 371 return data->end;
370} 372}
371QDate ORecur::start()const{ 373QDate ORecur::start()const{
372 return data->start; 374 return data->start;
373} 375}
374time_t ORecur::endDateUTC()const { 376QDateTime ORecur::createdDateTime()const {
375 return data->end;
376}
377time_t ORecur::createTime()const {
378 return data->create; 377 return data->create;
379} 378}
380int ORecur::repetition()const { 379int ORecur::repetition()const {
381 return data->rep; 380 return data->rep;
382} 381}
383QString ORecur::service()const { 382QString ORecur::service()const {
@@ -401,19 +400,15 @@ void ORecur::setPosition( int pos ) {
401void ORecur::setDays( char c ) { 400void ORecur::setDays( char c ) {
402 checkOrModify(); 401 checkOrModify();
403 data->days = c; 402 data->days = c;
404} 403}
405void ORecur::setEndDate( const QDate& dt) { 404void ORecur::setEndDate( const QDate& dt) {
406 checkOrModify(); 405 checkOrModify();
407 data->end = TimeConversion::toUTC( dt ); 406 data->end = dt;
408}
409void ORecur::setEndDateUTC( time_t t) {
410 checkOrModify();
411 data->end = t;
412} 407}
413void ORecur::setCreateTime( time_t t) { 408void ORecur::setCreatedDateTime( const QDateTime& t) {
414 checkOrModify(); 409 checkOrModify();
415 data->create = t; 410 data->create = t;
416} 411}
417void ORecur::setHasEndDate( bool b) { 412void ORecur::setHasEndDate( bool b) {
418 checkOrModify(); 413 checkOrModify();
419 data->hasEnd = b; 414 data->hasEnd = b;
diff --git a/libopie/pim/orecur.h b/libopie/pim/orecur.h
index 8713d97..1e0014b 100644
--- a/libopie/pim/orecur.h
+++ b/libopie/pim/orecur.h
@@ -32,19 +32,24 @@ public:
32 int frequency()const; 32 int frequency()const;
33 int position()const; 33 int position()const;
34 char days()const; 34 char days()const;
35 bool hasEndDate()const; 35 bool hasEndDate()const;
36 QDate start()const; 36 QDate start()const;
37 QDate endDate()const; 37 QDate endDate()const;
38 time_t endDateUTC()const; 38 QDateTime createdDateTime()const;
39 time_t createTime()const; 39 /**
40 * starting on monday=0, sunday=6
41 * for convience
42 */
43 bool repeatOnWeekDay( int day )const;
40 44
41 /** 45 /**
42 * FromWhereToStart is not included!!! 46 * FromWhereToStart is not included!!!
43 */ 47 */
44 bool nextOcurrence( const QDate& FromWhereToStart, QDate &recurDate ); 48 bool nextOcurrence( const QDate& FromWhereToStart, QDate &recurDate );
49
45 /** 50 /**
46 * The module this ORecur belongs to 51 * The module this ORecur belongs to
47 */ 52 */
48 QString service()const; 53 QString service()const;
49 54
50 /* 55 /*
@@ -60,14 +65,13 @@ public:
60 void setType( const RepeatType& ); 65 void setType( const RepeatType& );
61 void setFrequency( int freq ); 66 void setFrequency( int freq );
62 void setPosition( int pos ); 67 void setPosition( int pos );
63 void setDays( char c); 68 void setDays( char c);
64 void setEndDate( const QDate& dt ); 69 void setEndDate( const QDate& dt );
65 void setStart( const QDate& dt ); 70 void setStart( const QDate& dt );
66 void setEndDateUTC( time_t ); 71 void setCreatedDateTime( const QDateTime& );
67 void setCreateTime( time_t );
68 void setHasEndDate( bool b ); 72 void setHasEndDate( bool b );
69 void setRepitition(int ); 73 void setRepitition(int );
70 74
71 void setService( const QString& ser ); 75 void setService( const QString& ser );
72private: 76private:
73 void deref(); 77 void deref();
diff --git a/libopie/pim/otimezone.cpp b/libopie/pim/otimezone.cpp
new file mode 100644
index 0000000..b2bd3aa
--- a/dev/null
+++ b/libopie/pim/otimezone.cpp
@@ -0,0 +1,104 @@
1#include <stdio.h>
2#include <stdlib.h>
3
4#include <sys/types.h>
5
6#include "otimezone.h"
7
8namespace {
9
10 QDateTime utcTime( time_t t) {
11 tm* broken = ::gmtime( &t );
12 QDateTime ret;
13 ret.setDate( QDate( broken->tm_year + 1900, broken->tm_mon +1, broken->tm_mday ) );
14 ret.setTime( QTime( broken->tm_hour, broken->tm_min, broken->tm_sec ) );
15 return ret;
16 }
17 QDateTime utcTime( time_t t, const QString& zone) {
18 QCString org = ::getenv( "TZ" );
19 ::setenv( "TZ", zone.latin1(), true );
20 ::tzset();
21
22 tm* broken = ::localtime( &t );
23 ::setenv( "TZ", org, true );
24
25 QDateTime ret;
26 ret.setDate( QDate( broken->tm_year + 1900, broken->tm_mon +1, broken->tm_mday ) );
27 ret.setTime( QTime( broken->tm_hour, broken->tm_min, broken->tm_sec ) );
28
29 return ret;
30 }
31 time_t to_Time_t( const QDateTime& utc, const QString& str ) {
32 QDate d = utc.date();
33 QTime t = utc.time();
34
35 tm broken;
36 broken.tm_year = d.year() - 1900;
37 broken.tm_mon = d.month() - 1;
38 broken.tm_mday = d.day();
39 broken.tm_hour = t.hour();
40 broken.tm_min = t.minute();
41 broken.tm_sec = t.second();
42
43 QCString org = ::getenv( "TZ" );
44 ::setenv( "TZ", str.latin1(), true );
45 ::tzset();
46
47 time_t ti = ::mktime( &broken );
48 ::setenv( "TZ", org, true );
49
50 return ti;
51 }
52}
53OTimeZone::OTimeZone( const ZoneName& zone )
54 : m_name(zone) {
55}
56OTimeZone::~OTimeZone() {
57}
58
59bool OTimeZone::isValid()const {
60 return !m_name.isEmpty();
61}
62
63/*
64 * we will get the current timezone
65 * and ask it to convert to the timezone date
66 */
67QDateTime OTimeZone::toLocalDateTime( const QDateTime& dt) {
68 return OTimeZone::current().toDateTime( dt, *this );
69}
70QDateTime OTimeZone::toUTCDateTime( const QDateTime& dt ) {
71 return OTimeZone::utc().toDateTime( dt, *this );
72}
73QDateTime OTimeZone::fromUTCDateTime( time_t t) {
74 return utcTime( t );
75}
76QDateTime OTimeZone::toDateTime( time_t t) {
77 return utcTime( t, m_name );
78}
79/*
80 * convert dt to utc using zone.m_name
81 * convert utc -> timeZoneDT using this->m_name
82 */
83QDateTime OTimeZone::toDateTime( const QDateTime& dt, const OTimeZone& zone ) {
84 time_t utc = to_Time_t( dt, zone.m_name );
85 qWarning("%d %s", utc, zone.m_name.latin1() );
86 return utcTime( utc, m_name );
87}
88time_t OTimeZone::fromDateTime( const QDateTime& time ) {
89 return to_Time_t( time, m_name );
90}
91time_t OTimeZone::fromUTCDateTime( const QDateTime& time ) {
92 return to_Time_t( time, "UTC" );
93}
94OTimeZone OTimeZone::current() {
95 QCString str = ::getenv("TZ");
96 OTimeZone zone( str );
97 return zone;
98}
99OTimeZone OTimeZone::utc() {
100 return OTimeZone("UTC");
101}
102QString OTimeZone::timeZone()const {
103 return m_name;
104}
diff --git a/libopie/pim/otimezone.h b/libopie/pim/otimezone.h
new file mode 100644
index 0000000..bb08349
--- a/dev/null
+++ b/libopie/pim/otimezone.h
@@ -0,0 +1,71 @@
1#ifndef OPIE_TIME_ZONE_H
2#define OPIE_TIME_ZONE_H
3
4#include <time.h>
5#include <qdatetime.h>
6
7/**
8 * A very primitive class to convert time
9 * from one timezone to another
10 * and to localtime
11 * and time_t
12 */
13class OTimeZone {
14 public:
15 typedef QString ZoneName;
16 OTimeZone( const ZoneName& = ZoneName::null );
17 virtual ~OTimeZone(); // just in case.
18
19 bool isValid()const;
20
21 /**
22 * converts the QDateTime to a DateTime
23 * in the local timezone
24 * if QDateTime is 25th Jan and takes place in Europe/Berlin at 12h
25 * and the current timezone is Europe/London the returned
26 * time will be 11h.
27 */
28 QDateTime toLocalDateTime( const QDateTime& dt );
29
30 /**
31 * converts the QDateTime to UTC time
32 */
33 QDateTime toUTCDateTime( const QDateTime& dt );
34
35 /**
36 * reads the time_t into a QDateTime using UTC as timezone!
37 */
38 QDateTime fromUTCDateTime( time_t );
39
40 /**
41 * converts the time_t to the time in the timezone
42 */
43 QDateTime toDateTime( time_t );
44
45 /**
46 * converts the QDateTime from one timezone to this timeZone
47 */
48 QDateTime toDateTime( const QDateTime&, const OTimeZone& timeZone );
49
50 /**
51 * converts the date time into a time_t. It takes the timezone into account
52 */
53 time_t fromDateTime( const QDateTime& );
54
55 /**
56 * converts the datetime with timezone UTC
57 */
58 time_t fromUTCDateTime( const QDateTime& );
59
60 static OTimeZone current();
61 static OTimeZone utc();
62
63 QString timeZone()const;
64 private:
65 ZoneName m_name;
66 class Private;
67 Private* d;
68};
69
70
71#endif
diff --git a/libopie/pim/otodo.cpp b/libopie/pim/otodo.cpp
index b4d4aa9..049359e 100644
--- a/libopie/pim/otodo.cpp
+++ b/libopie/pim/otodo.cpp
@@ -337,12 +337,14 @@ void OTodo::deref() {
337 delete data; 337 delete data;
338 data= 0; 338 data= 0;
339 } 339 }
340} 340}
341OTodo &OTodo::operator=(const OTodo &item ) 341OTodo &OTodo::operator=(const OTodo &item )
342{ 342{
343 if ( *this == item ) return *this;
344
343 OPimRecord::operator=( item ); 345 OPimRecord::operator=( item );
344 //qWarning("operator= ref "); 346 //qWarning("operator= ref ");
345 item.data->ref(); 347 item.data->ref();
346 deref(); 348 deref();
347 data = item.data; 349 data = item.data;
348 350
diff --git a/libopie/pim/test/oevent_test.cpp b/libopie/pim/test/oevent_test.cpp
new file mode 100644
index 0000000..50cc032
--- a/dev/null
+++ b/libopie/pim/test/oevent_test.cpp
@@ -0,0 +1,23 @@
1#include <qdatetime.h>
2
3#include "../oevent.h"
4
5int main(int argc, char* argv ) {
6 OEvent ev;
7 ev.setUid( 20 );
8
9 ev.setDescription( "Foo" );
10
11 OEvent ev2 = ev;
12 ev2.setDescription("Foo2");
13 qWarning("%s", ev2.description().latin1() );
14 qWarning("%s", ev.description().latin1() );
15
16 QDateTime time = QDateTime::currentDateTime();
17 ev2.setStartDateTime( time );
18 ev2.setTimeZone( "Europe/London" );
19
20 qWarning("%s", ev2.startDateTime().toString().latin1() );
21 qWarning("%s", ev2.startDateTimeInZone().toString().latin1() );
22 return 0;
23}
diff --git a/libopie/pim/test/oevent_test.pro b/libopie/pim/test/oevent_test.pro
new file mode 100644
index 0000000..3365def
--- a/dev/null
+++ b/libopie/pim/test/oevent_test.pro
@@ -0,0 +1,11 @@
1 TEMPLATE= app
2 #CONFIG = qt warn_on debug
3 CONFIG = qt warn_on release
4 #HEADERS =
5 SOURCES = oevent_test.cpp
6 INCLUDEPATH+= $(OPIEDIR)/include
7 DEPENDPATH+= $(OPIEDIR)/include
8LIBS += -lqpe -lopie
9 TARGET = oevent_test
10
11include ( $(OPIEDIR)/include.pro ) \ No newline at end of file
diff --git a/libopie/pim/test/test_todo.cpp b/libopie/pim/test/test_todo.cpp
new file mode 100644
index 0000000..7440503
--- a/dev/null
+++ b/libopie/pim/test/test_todo.cpp
@@ -0,0 +1,36 @@
1#include <qdatetime.h>
2#include <qmap.h>
3
4#include <opie/otodo.h>
5#include <opie/otodoaccess.h>
6#include <opie/otodoaccessxml.h>
7
8int main(int argc, char* argv[] ) {
9
10 OTodoAccessXML* xml = new OTodoAccessXML("demo");
11 OTodoAccess ac(xml);
12 int elc;
13 QTime timer;
14 qWarning("start loading");
15 timer.start();
16 ac.load();
17 elc = timer.elapsed();
18 qWarning("Elapsed loading %d %d", elc, elc/1000);
19
20 timer.start();
21 OTodoAccess::List lis = ac.allRecords();
22 elc = timer.elapsed();
23 qWarning("Elapsed allRecords %d %d", elc, elc/1000 );
24 OTodoAccess::List::Iterator it;
25 timer.start();
26ac.save();
27/*
28 for( it = lis.begin(); it != lis.end(); ++it ) {
29 qWarning("Desc: " + (*it).summary() );
30 qWarning("UID %d", (*it).uid() );
31 }
32 */
33elc = timer.elapsed();
34
35 qWarning("elapsed iterating %d %d", elc, elc/1000 );
36};
diff --git a/libopie/pim/test/todo_test.pro b/libopie/pim/test/todo_test.pro
new file mode 100644
index 0000000..3d14dda
--- a/dev/null
+++ b/libopie/pim/test/todo_test.pro
@@ -0,0 +1,11 @@
1 TEMPLATE= app
2 #CONFIG = qt warn_on debug
3 CONFIG = qt warn_on release
4 #HEADERS =
5 SOURCES = test_todo.cpp
6 INCLUDEPATH+= $(OPIEDIR)/include
7 DEPENDPATH+= $(OPIEDIR)/include
8LIBS += -lqpe -lopie -lopiesql
9 TARGET = todo_test
10
11include ( $(OPIEDIR)/ ) \ No newline at end of file
diff --git a/libopie/tododb.cpp b/libopie/tododb.cpp
deleted file mode 100644
index 17163a0..0000000
--- a/libopie/tododb.cpp
+++ b/dev/null
@@ -1,268 +0,0 @@
1
2#include <qdir.h>
3#include <opie/tododb.h>
4#include <opie/xmltree.h>
5#include <opie/todoresource.h>
6#include <qpe/palmtoprecord.h>
7#include <qpe/global.h>
8
9using namespace Opie;
10
11namespace {
12
13class FileToDoResource : public ToDoResource {
14public:
15 FileToDoResource() {};
16 // FIXME better parsing
17 bool save(const QString &name, const QValueList<ToDoEvent> &m_todos ){
18 // prepare the XML
19 XMLElement *tasks = new XMLElement( );
20 tasks->setTagName("Tasks" );
21 for( QValueList<ToDoEvent>::ConstIterator it = m_todos.begin(); it != m_todos.end(); ++it ){
22 XMLElement::AttributeMap map;
23 XMLElement *task = new XMLElement();
24 map.insert( "Completed", QString::number((int)(*it).isCompleted() ) );
25 map.insert( "HasDate", QString::number((int)(*it).hasDate() ) );
26 map.insert( "Priority", QString::number( (*it).priority() ) );
27 map.insert( "Progress", QString::number( (*it).progress() ) );
28 map.insert( "Summary", (*it).summary() );
29 QArray<int> arrat = (*it).categories();
30 QString attr;
31 for(uint i=0; i < arrat.count(); i++ ){
32 attr.append(QString::number(arrat[i])+";" );
33 }
34 if(!attr.isEmpty() ) // remove the last ;
35 attr.remove(attr.length()-1, 1 );
36 map.insert( "Categories", attr );
37 //else
38 //map.insert( "Categories", QString::null );
39 map.insert( "Description", (*it).description() );
40 if( (*it).hasDate() ){
41 map.insert("DateYear", QString::number( (*it).date().year() ) );
42 map.insert("DateMonth", QString::number( (*it).date().month() ) );
43 map.insert("DateDay", QString::number( (*it).date().day() ) );
44 }
45 map.insert("Uid", QString::number( (*it).uid() ) );
46 task->setTagName("Task" );
47 task->setAttributes( map );
48 tasks->appendChild(task);
49 }
50 QFile file( name);
51 if( file.open(IO_WriteOnly ) ){
52 QTextStream stream(&file );
53 stream.setEncoding( QTextStream::UnicodeUTF8 );
54 stream << "<!DOCTYPE Tasks>" << endl;
55 tasks->save(stream );
56 delete tasks;
57 stream << "</Tasks>" << endl;
58 file.close();
59 return true;
60 }
61 return false;
62 }
63 QValueList<ToDoEvent> load( const QString &name ){
64 qWarning("loading tododb" );
65 QValueList<ToDoEvent> m_todos;
66 XMLElement *root = XMLElement::load( name );
67 if(root != 0l ){ // start parsing
68 qWarning("ToDoDB::load tagName(): %s", root->tagName().latin1() );
69 //if( root->tagName() == QString::fromLatin1("Tasks" ) ){// Start
70 XMLElement *element = root->firstChild();
71 if (element == 0 )
72 return m_todos;
73 element = element->firstChild();
74 while( element ){
75 if( element->tagName() != QString::fromLatin1("Task") ){
76 element = element->nextChild();
77 continue;
78 }
79 qWarning("ToDoDB::load element tagName() : %s", element->tagName().latin1() );
80 QString dummy;
81 ToDoEvent event;
82 bool ok;
83 int dumInt;
84 // completed
85 dummy = element->attribute("Completed" );
86 dumInt = dummy.toInt(&ok );
87 if(ok ) event.setCompleted( dumInt == 0 ? false : true );
88 // progress
89 dummy = element->attribute("Progress" );
90 {
91 ushort dumShort = dummy.toUShort(&ok);
92 event.setProgress( dumShort );
93
94 }
95 // hasDate
96 dummy = element->attribute("HasDate" );
97 dumInt = dummy.toInt(&ok );
98 if(ok ) event.setHasDate( dumInt == 0 ? false: true );
99 // set the date
100 bool hasDa = dumInt;
101 if ( hasDa ) { //parse the date
102 int year, day, month = 0;
103 year = day = month;
104 // year
105 dummy = element->attribute("DateYear" );
106 dumInt = dummy.toInt(&ok );
107 if( ok ) year = dumInt;
108 // month
109 dummy = element->attribute("DateMonth" );
110 dumInt = dummy.toInt(&ok );
111 if(ok ) month = dumInt;
112 dummy = element->attribute("DateDay" );
113 dumInt = dummy.toInt(&ok );
114 if(ok ) day = dumInt;
115 // set the date
116 QDate date( year, month, day );
117 event.setDate( date);
118 }
119 dummy = element->attribute("Priority" );
120 dumInt = dummy.toInt(&ok );
121 if(!ok ) dumInt = ToDoEvent::NORMAL;
122 event.setPriority( dumInt );
123 //description
124 dummy = element->attribute("Description" );
125 event.setDescription( dummy );
126 dummy = element->attribute("Summary" );
127 event.setSummary( dummy );
128 // category
129 dummy = element->attribute("Categories" );
130 QStringList ids = QStringList::split(";", dummy );
131 event.setCategories( ids );
132
133 //uid
134 dummy = element->attribute("Uid" );
135 dumInt = dummy.toInt(&ok );
136 if(ok ) event.setUid( dumInt );
137 m_todos.append( event );
138 element = element->nextChild(); // next element
139 }
140 //}
141 }else {
142 qWarning("could not load" );
143 }
144 delete root;
145 qWarning("returning" );
146 return m_todos;
147 }
148};
149
150}
151
152ToDoDB::ToDoDB(const QString &fileName, ToDoResource *res ){
153 m_fileName = fileName;
154 if( fileName.isEmpty() && res == 0 ){
155 m_fileName = Global::applicationFileName("todolist","todolist.xml");
156 res = new FileToDoResource();
157 //qWarning("%s", m_fileName.latin1() );
158 }else if(res == 0 ){ // let's create a ToDoResource for xml
159 res = new FileToDoResource();
160 }
161 m_res = res;
162 load();
163}
164ToDoResource* ToDoDB::resource(){
165 return m_res;
166};
167void ToDoDB::setResource( ToDoResource *res )
168{
169 delete m_res;
170 m_res = res;
171}
172ToDoDB::~ToDoDB()
173{
174 delete m_res;
175}
176QValueList<ToDoEvent> ToDoDB::effectiveToDos(const QDate &from, const QDate &to,
177 bool all )
178{
179 QValueList<ToDoEvent> events;
180 for( QValueList<ToDoEvent>::Iterator it = m_todos.begin(); it!= m_todos.end(); ++it ){
181 if( (*it).hasDate() ){
182 if( (*it).date() >= from && (*it).date() <= to )
183 events.append( (*it) );
184 }else if( all ){
185 events.append( (*it) );
186 }
187 }
188 return events;
189}
190QValueList<ToDoEvent> ToDoDB::effectiveToDos(const QDate &from,
191 bool all)
192{
193 return effectiveToDos( from, QDate::currentDate(), all );
194}
195QValueList<ToDoEvent> ToDoDB::overDue()
196{
197 QValueList<ToDoEvent> events;
198 for( QValueList<ToDoEvent>::Iterator it = m_todos.begin(); it!= m_todos.end(); ++it ){
199 if( (*it).isOverdue() )
200 events.append((*it) );
201 }
202 return events;
203}
204QValueList<ToDoEvent> ToDoDB::rawToDos()
205{
206 return m_todos;
207}
208void ToDoDB::addEvent( const ToDoEvent &event )
209{
210 m_todos.append( event );
211}
212void ToDoDB::editEvent( const ToDoEvent &event )
213{
214 m_todos.remove( event );
215 m_todos.append( event );
216}
217void ToDoDB::removeEvent( const ToDoEvent &event )
218{
219 m_todos.remove( event );
220}
221void ToDoDB::replaceEvent(const ToDoEvent &event )
222{
223 QValueList<ToDoEvent>::Iterator it;
224 int uid = event.uid();
225 // == is not overloaded as we would like :( so let's search for the uid
226 for(it = m_todos.begin(); it != m_todos.end(); ++it ){
227 if( (*it).uid() == uid ){
228 m_todos.remove( (*it) );
229 break; // should save us the iterate is now borked
230 }
231 }
232 m_todos.append(event);
233}
234void ToDoDB::reload()
235{
236 load();
237}
238void ToDoDB::mergeWith(const QValueList<ToDoEvent>& events )
239{
240 QValueList<ToDoEvent>::ConstIterator it;
241 for( it = events.begin(); it != events.end(); ++it ){
242 replaceEvent( (*it) );
243 }
244}
245void ToDoDB::setFileName(const QString &file )
246{
247 m_fileName =file;
248}
249QString ToDoDB::fileName()const
250{
251 return m_fileName;
252}
253void ToDoDB::load()
254{
255 m_todos = m_res->load( m_fileName );
256}
257bool ToDoDB::save()
258{
259 return m_res->save( m_fileName, m_todos );
260}
261
262
263
264
265
266
267
268
diff --git a/libopie/tododb.h b/libopie/tododb.h
deleted file mode 100644
index 7fd9f96..0000000
--- a/libopie/tododb.h
+++ b/dev/null
@@ -1,46 +0,0 @@
1
2#ifndef tododb_h
3#define tododb_h
4
5#include <qvaluelist.h>
6
7#include <opie/todoevent.h>
8
9class ToDoResource;
10class ToDoDB
11{
12 public:
13 // if no argument is supplied pick the default book
14 ToDoDB(const QString &fileName = QString::null, ToDoResource* resource= 0 );
15 ~ToDoDB();
16 QValueList<ToDoEvent> effectiveToDos(const QDate &from,
17 const QDate &to,
18 bool includeNoDates = true);
19 QValueList<ToDoEvent> effectiveToDos(const QDate &start, bool includeNoDates = true );
20 QValueList<ToDoEvent> rawToDos(); // all events
21 QValueList<ToDoEvent> overDue();
22
23 void addEvent(const ToDoEvent &event );
24 void editEvent(const ToDoEvent &editEvent );
25 void removeEvent(const ToDoEvent &event);
26 void replaceEvent(const ToDoEvent &event );
27 // QValueList<ToDoEvents will overwrite existing ones no smart code at all ;)
28 void mergeWith(const QValueList<ToDoEvent>& );
29 void reload();
30 void setFileName(const QString & );
31 QString fileName()const;
32 bool save();
33 ToDoResource *resource();
34 void setResource(ToDoResource* res);
35
36 private:
37 class ToDoDBPrivate;
38 ToDoDBPrivate *d;
39 QString m_fileName;
40 ToDoResource *m_res;
41 QValueList<ToDoEvent> m_todos;
42 void load();
43};
44
45
46#endif
diff --git a/libopie/todoevent.cpp b/libopie/todoevent.cpp
deleted file mode 100644
index f744550..0000000
--- a/libopie/todoevent.cpp
+++ b/dev/null
@@ -1,339 +0,0 @@
1
2#include <opie/todoevent.h>
3
4
5#include <qpe/palmtopuidgen.h>
6#include <qpe/stringutil.h>
7#include <qpe/palmtoprecord.h>
8
9#include <qpe/stringutil.h>
10#include <qpe/categories.h>
11#include <qpe/categoryselect.h>
12
13#include <qobject.h>
14
15ToDoEvent::ToDoEvent(const ToDoEvent &event )
16{
17 *this = event;
18}
19
20ToDoEvent::ToDoEvent(bool completed, int priority,
21 const QStringList &category,
22 const QString& summary,
23 const QString &description,
24 ushort progress,
25 bool hasDate, QDate date, int uid )
26{
27 m_date = date;
28 m_isCompleted = completed;
29 m_hasDate = hasDate;
30 m_priority = priority;
31 m_category = category;
32 m_sum = summary;
33 m_prog = progress;
34 m_desc = Qtopia::simplifyMultiLineSpace(description );
35 if (uid == -1 ) {
36 Qtopia::UidGen *uidgen = new Qtopia::UidGen();
37 uid = uidgen->generate();
38 delete uidgen;
39 }// generate the ids
40 m_uid = uid;
41}
42QArray<int> ToDoEvent::categories()const
43{
44 QArray<int> array(m_category.count() ); // currently the datebook can be only in one category
45 array = Qtopia::Record::idsFromString( m_category.join(";") );
46 return array;
47}
48bool ToDoEvent::match( const QRegExp &regExp )const
49{
50 if( QString::number( m_priority ).find( regExp ) != -1 ){
51 return true;
52 }else if( m_hasDate && m_date.toString().find( regExp) != -1 ){
53 return true;
54 }else if(m_desc.find( regExp ) != -1 ){
55 return true;
56 }
57 return false;
58}
59bool ToDoEvent::isCompleted() const
60{
61 return m_isCompleted;
62}
63bool ToDoEvent::hasDate() const
64{
65 return m_hasDate;
66}
67int ToDoEvent::priority()const
68{
69 return m_priority;
70}
71QStringList ToDoEvent::allCategories()const
72{
73 return m_category;
74}
75QString ToDoEvent::extra(const QString& )const
76{
77 return QString::null;
78}
79QString ToDoEvent::summary() const
80{
81 return m_sum;
82}
83ushort ToDoEvent::progress() const
84{
85 return m_prog;
86}
87QStringList ToDoEvent::relatedApps() const
88{
89 QStringList list;
90 QMap<QString, QArray<int> >::ConstIterator it;
91 for ( it = m_relations.begin(); it != m_relations.end(); ++it ) {
92 list << it.key();
93 }
94 return list;
95}
96QArray<int> ToDoEvent::relations( const QString& app)const
97{
98 QArray<int> tmp;
99 QMap<QString, QArray<int> >::ConstIterator it;
100 it = m_relations.find( app);
101 if ( it != m_relations.end() )
102 tmp = it.data();
103 return tmp;
104}
105void ToDoEvent::insertCategory(const QString &str )
106{
107 m_category.append( str );
108}
109void ToDoEvent::clearCategories()
110{
111 m_category.clear();
112}
113void ToDoEvent::setCategories(const QStringList &list )
114{
115 m_category = list;
116}
117QDate ToDoEvent::date()const
118{
119 return m_date;
120}
121
122QString ToDoEvent::description()const
123{
124 return m_desc;
125}
126void ToDoEvent::setCompleted( bool completed )
127{
128 m_isCompleted = completed;
129}
130void ToDoEvent::setHasDate( bool hasDate )
131{
132 m_hasDate = hasDate;
133}
134void ToDoEvent::setDescription(const QString &desc )
135{
136 m_desc = Qtopia::simplifyMultiLineSpace(desc );
137}
138void ToDoEvent::setExtra( const QString&, const QString& )
139{
140
141}
142void ToDoEvent::setSummary( const QString& sum )
143{
144 m_sum = sum;
145}
146void ToDoEvent::setCategory( const QString &cat )
147{
148 qWarning("setCategory %s", cat.latin1() );
149 m_category.clear();
150 m_category << cat;
151}
152void ToDoEvent::setPriority(int prio )
153{
154 m_priority = prio;
155}
156void ToDoEvent::setDate( QDate date )
157{
158 m_date = date;
159}
160void ToDoEvent::addRelated( const QString &app, int id )
161{
162 QMap<QString, QArray<int> >::Iterator it;
163 QArray<int> tmp;
164 it = m_relations.find( app );
165 if ( it == m_relations.end() ) {
166 tmp.resize(1 );
167 tmp[0] = id;
168 }else{
169 tmp = it.data();
170 tmp.resize( tmp.size() + 1 );
171 tmp[tmp.size() - 1] = id;
172 }
173 m_relations.replace( app, tmp );
174}
175void ToDoEvent::addRelated(const QString& app, QArray<int> ids )
176{
177 QMap<QString, QArray<int> >::Iterator it;
178 QArray<int> tmp;
179 it = m_relations.find( app);
180 if ( it == m_relations.end() ) { // not there
181 /** tmp.resize( ids.size() ); stupid??
182 */
183 tmp = ids;
184 }else{
185 tmp = it.data();
186 int offset = tmp.size()-1;
187 tmp.resize( tmp.size() + ids.size() );
188 for (uint i = 0; i < ids.size(); i++ ) {
189 tmp[offset+i] = ids[i];
190 }
191
192 }
193 m_relations.replace( app, tmp );
194}
195void ToDoEvent::clearRelated( const QString& app )
196{
197 m_relations.remove( app );
198}
199bool ToDoEvent::isOverdue( )
200{
201 if( m_hasDate )
202 return QDate::currentDate() > m_date;
203 return false;
204}
205void ToDoEvent::setProgress(ushort progress )
206{
207 m_prog = progress;
208}
209/*!
210 Returns a richt text string
211*/
212QString ToDoEvent::richText() const
213{
214 QString text;
215 QStringList catlist;
216
217 // Description of the todo
218 if ( !description().isEmpty() ){
219 text += "<b>" + QObject::tr( "Summary:") + "</b><br>";
220 text += Qtopia::escapeString(summary() ).replace(QRegExp( "[\n]"), "<br>" ) + "<br>";
221 text += "<b>" + QObject::tr( "Description:" ) + "</b><br>";
222 text += Qtopia::escapeString(description() ).replace(QRegExp( "[\n]"), "<br>" ) + "<br><br><br>";
223 }
224 text += "<b>" + QObject::tr( "Priority:") +" </b>"
225 + QString::number( priority() ) + " <br>";
226 text += "<b>" + QObject::tr( "Progress:") + " </b>"
227 + QString::number( progress() ) + " %<br>";
228 if (hasDate() ){
229 text += "<b>" + QObject::tr( "Deadline:") + " </b>";
230 text += date().toString();
231 text += "<br>";
232 }
233
234 // Open database of all categories and get the list of
235 // the categories this todoevent belongs to.
236 // Then print them...
237 // I am not sure whether there is no better way doing this !?
238 Categories catdb;
239 bool firstloop = true;
240 catdb.load( categoryFileName() );
241 catlist = allCategories();
242
243 text += "<b>" + QObject::tr( "Category:") + "</b> ";
244 for ( QStringList::Iterator it = catlist.begin(); it != catlist.end(); ++it ) {
245 if (!firstloop){
246 text += ", ";
247 }
248 firstloop = false;
249 text += catdb.label ("todo", (*it).toInt());
250 }
251 text += "<br>";
252 return text;
253}
254
255bool ToDoEvent::operator<( const ToDoEvent &toDoEvent )const{
256 if( !hasDate() && !toDoEvent.hasDate() ) return true;
257 if( !hasDate() && toDoEvent.hasDate() ) return false;
258 if( hasDate() && toDoEvent.hasDate() ){
259 if( date() == toDoEvent.date() ){ // let's the priority decide
260 return priority() < toDoEvent.priority();
261 }else{
262 return date() < toDoEvent.date();
263 }
264 }
265 return false;
266}
267bool ToDoEvent::operator<=(const ToDoEvent &toDoEvent )const
268{
269 if( !hasDate() && !toDoEvent.hasDate() ) return true;
270 if( !hasDate() && toDoEvent.hasDate() ) return true;
271 if( hasDate() && toDoEvent.hasDate() ){
272 if( date() == toDoEvent.date() ){ // let's the priority decide
273 return priority() <= toDoEvent.priority();
274 }else{
275 return date() <= toDoEvent.date();
276 }
277 }
278 return true;
279}
280bool ToDoEvent::operator>(const ToDoEvent &toDoEvent )const
281{
282 if( !hasDate() && !toDoEvent.hasDate() ) return false;
283 if( !hasDate() && toDoEvent.hasDate() ) return false;
284 if( hasDate() && toDoEvent.hasDate() ){
285 if( date() == toDoEvent.date() ){ // let's the priority decide
286 return priority() > toDoEvent.priority();
287 }else{
288 return date() > toDoEvent.date();
289 }
290 }
291 return false;
292}
293bool ToDoEvent::operator>=(const ToDoEvent &toDoEvent )const
294{
295 if( !hasDate() && !toDoEvent.hasDate() ) return true;
296 if( !hasDate() && toDoEvent.hasDate() ) return false;
297 if( hasDate() && toDoEvent.hasDate() ){
298 if( date() == toDoEvent.date() ){ // let's the priority decide
299 return priority() > toDoEvent.priority();
300 }else{
301 return date() > toDoEvent.date();
302 }
303 }
304 return true;
305}
306bool ToDoEvent::operator==(const ToDoEvent &toDoEvent )const
307{
308 if( m_priority == toDoEvent.m_priority &&
309 m_priority == toDoEvent.m_prog &&
310 m_isCompleted == toDoEvent.m_isCompleted &&
311 m_hasDate == toDoEvent.m_hasDate &&
312 m_date == toDoEvent.m_date &&
313 m_category == toDoEvent.m_category &&
314 m_sum == toDoEvent.m_sum &&
315 m_desc == toDoEvent.m_desc )
316 return true;
317 return false;
318}
319ToDoEvent &ToDoEvent::operator=(const ToDoEvent &item )
320{
321 m_date = item.m_date;
322 m_isCompleted = item.m_isCompleted;
323 m_hasDate = item.m_hasDate;
324 m_priority = item.m_priority;
325 m_category = item.m_category;
326 m_desc = item.m_desc;
327 m_uid = item.m_uid;
328 m_sum = item.m_sum;
329 m_prog = item.m_prog;
330 return *this;
331}
332
333
334
335
336
337
338
339
diff --git a/libopie/todoevent.h b/libopie/todoevent.h
deleted file mode 100644
index b55a39b..0000000
--- a/libopie/todoevent.h
+++ b/dev/null
@@ -1,191 +0,0 @@
1
2#ifndef todoevent_h
3#define todoevent_h
4
5
6#include <qarray.h>
7#include <qmap.h>
8#include <qregexp.h>
9#include <qstringlist.h>
10#include <qdatetime.h>
11
12
13class ToDoEvent {
14 friend class ToDoDB;
15 public:
16 // priorities from Very low to very high
17 enum Priority { VERYHIGH=1, HIGH, NORMAL, LOW, VERYLOW };
18 /* Constructs a new ToDoEvent
19 @param completed Is the TodoEvent completed
20 @param priority What is the priority of this ToDoEvent
21 @param category Which category does it belong( uid )
22 @param summary A small summary of the todo
23 @param description What is this ToDoEvent about
24 @param hasDate Does this Event got a deadline
25 @param date what is the deadline?
26 @param uid what is the UUID of this Event
27 **/
28 ToDoEvent( bool completed = false, int priority = NORMAL,
29 const QStringList &category = QStringList(),
30 const QString &summary = QString::null ,
31 const QString &description = QString::null,
32 ushort progress = 0,
33 bool hasDate = false, QDate date = QDate::currentDate(), int uid = -1 );
34 /* Copy c'tor
35
36 **/
37 ToDoEvent(const ToDoEvent & );
38
39 /*
40 Is this event completed?
41 **/
42 bool isCompleted() const;
43
44 /*
45 Does this Event have a deadline
46 **/
47 bool hasDate() const;
48
49 /*
50 What is the priority?
51 **/
52 int priority()const ;
53
54 /**
55 * progress as ushort 0, 20, 40, 60, 80 or 100%
56 */
57 ushort progress() const;
58 /*
59 All category numbers as QString in a List
60 **/
61 QStringList allCategories()const;
62
63 /*
64 * Same as above but with QArray<int>
65 */
66 QArray<int> categories() const;
67
68 /**
69 * The end Date
70 */
71 QDate date()const;
72
73 /**
74 * The description of the todo
75 */
76 QString description()const;
77
78 /**
79 * A small summary of the todo
80 */
81 QString summary() const;
82
83 /**
84 * Return this todoevent in a RichText formatted QString
85 */
86 QString richText() const;
87
88 /**
89 * Returns the UID of the Todo
90 */
91 int uid()const { return m_uid;};
92
93
94 QString extra(const QString& )const;
95
96 /**
97 * returns a list of apps which have related items
98 */
99 QStringList relatedApps()const;
100
101 /**
102 * returns all relations for one app
103 */
104 QArray<int> relations( const QString& app )const;
105 /**
106 * Set if this Todo is completed
107 */
108 void setCompleted(bool completed );
109
110 /**
111 * set if this todo got an end data
112 */
113 void setHasDate( bool hasDate );
114 // if the category doesn't exist we will create it
115 // this sets the the Category after this call category will be the only category
116 void setCategory( const QString &category );
117 // adds a category to the Categories of this event
118 void insertCategory(const QString &category );
119
120 /**
121 * Removes this event from all categories
122 */
123 void clearCategories();
124
125 /**
126 * This todo belongs to xxx categories
127 */
128 void setCategories(const QStringList& );
129
130 /**
131 * Set the priority of the Todo
132 */
133 void setPriority(int priority );
134
135 /**
136 * Set the progress.
137 */
138 void setProgress( ushort progress );
139
140 /**
141 * add related function it replaces too ;)
142 */
143 void addRelated( const QString& app, int id );
144
145 /**
146 * add related
147 */
148 void addRelated( const QString& app, QArray<int> ids );
149
150 /**
151 * clear relations for one app
152 */
153 void clearRelated(const QString& app);
154
155 /**
156 * set the end date
157 */
158 void setDate( QDate date );
159 void setDescription(const QString& );
160 void setSummary(const QString& );
161 void setExtra( const QString&, const QString& );
162 bool isOverdue();
163
164 bool match( const QRegExp &r )const;
165
166 void setUid(int id) {m_uid = id; };
167 bool operator<(const ToDoEvent &toDoEvent )const;
168 bool operator<=(const ToDoEvent &toDoEvent )const;
169 bool operator!=(const ToDoEvent &toDoEvent )const { return !(*this == toDoEvent); };
170 bool operator>(const ToDoEvent &toDoEvent )const;
171 bool operator>=(const ToDoEvent &toDoEvent)const;
172 bool operator==(const ToDoEvent &toDoEvent )const;
173 ToDoEvent &operator=(const ToDoEvent &toDoEvent );
174 private:
175 class ToDoEventPrivate;
176 ToDoEventPrivate *d;
177 QDate m_date;
178 bool m_isCompleted:1;
179 bool m_hasDate:1;
180 int m_priority;
181 QStringList m_category;
182 QString m_desc;
183 QString m_sum;
184 QMap<QString, QString> m_extra;
185 QMap<QString, QArray<int> > m_relations;
186 int m_uid;
187 ushort m_prog;
188};
189
190
191#endif
diff --git a/libopie/todoresource.h b/libopie/todoresource.h
deleted file mode 100644
index 34edb04..0000000
--- a/libopie/todoresource.h
+++ b/dev/null
@@ -1,14 +0,0 @@
1
2
3#ifndef opietodoresource_h
4#define opietodoresource_h
5
6class ToDoEvent;
7class ToDoResource {
8 public:
9 ToDoResource( ) {};
10 virtual QValueList<ToDoEvent> load(const QString &file ) = 0;
11 virtual bool save( const QString &file, const QValueList<ToDoEvent> & ) = 0;
12};
13
14#endif
diff --git a/libopie/todovcalresource.cpp b/libopie/todovcalresource.cpp
deleted file mode 100644
index 1df5aff..0000000
--- a/libopie/todovcalresource.cpp
+++ b/dev/null
@@ -1,158 +0,0 @@
1/*
2               =. This file is part of the OPIE Project
3             .=l. Copyright (c) 2002 Holger Freyther <freyther@kde.org>
4           .>+-= the use of vobject was inspired by libkcal
5 _;:,     .>    :=|. This library is free software; you can
6.> <`_,   >  .   <= redistribute it and/or modify it under
7:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; either version 2 of the License,
10     ._= =}       : or (at your option) any later version.
11    .%`+i>       _;_.
12    .i_,=:_.      -<s. This library is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
17..}^=.=       =       ; Library General Public License for more
18++=   -.     .`     .: details.
19 :     =  ...= . :.=-
20 -.   .:....=;==+<; You should have received a copy of the GNU
21  -_. . .   )=.  = Library General Public License along with
22    --        :-=` this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA.
26
27*/
28
29#include <qfile.h>
30#include <qvaluelist.h>
31#include <opie/todoevent.h>
32#include <opie/todovcalresource.h>
33
34#include "../library/backend/vobject_p.h"
35#include "../library/timeconversion.h"
36#include "../library/backend/qfiledirect_p.h"
37
38static VObject *vobjByEvent( const ToDoEvent &event )
39{
40 VObject *task = newVObject( VCTodoProp );
41 if( task == 0 )
42 return 0l;
43 if( event.hasDate() )
44 addPropValue( task, VCDueProp, TimeConversion::toISO8601( event.date() ) );
45
46 if( event.isCompleted() )
47 addPropValue( task, VCStatusProp, "COMPLETED");
48
49 QString string = QString::number(event.priority() );
50 addPropValue( task, VCPriorityProp, string.local8Bit() );
51 addPropValue( task, VCCategoriesProp, event.allCategories().join(";").local8Bit() );
52 addPropValue( task, VCDescriptionProp, event.description().local8Bit() );
53 addPropValue( task, VCSummaryProp, event.summary().left(15).local8Bit() );
54 return task;
55};
56
57static ToDoEvent eventByVObj( VObject *obj ){
58 ToDoEvent event;
59 VObject *ob;
60 QCString name;
61 // no uid, attendees, ... and no fun
62 // description
63 if( ( ob = isAPropertyOf( obj, VCDescriptionProp )) != 0 ){
64 name = vObjectStringZValue( ob );
65 event.setDescription( name );
66 }
67 // summary
68 if ( ( ob = isAPropertyOf( obj, VCSummaryProp ) ) != 0 ) {
69 name = vObjectStringZValue( ob );
70 event.setSummary( name );
71 }
72 // completed
73 if( ( ob = isAPropertyOf( obj, VCStatusProp )) != 0 ){
74 name = vObjectStringZValue( ob );
75 if( name == "COMPLETED" ){
76 event.setCompleted( true );
77 }else{
78 event.setCompleted( false );
79 }
80 }else
81 event.setCompleted( false );
82 // priority
83 if ((ob = isAPropertyOf(obj, VCPriorityProp))) {
84 name = vObjectStringZValue( ob );
85 bool ok;
86 event.setPriority(name.toInt(&ok) );
87 }
88 //due date
89 if((ob = isAPropertyOf(obj, VCDueProp)) ){
90 event.setHasDate( true );
91 name = vObjectStringZValue( ob );
92 event.setDate( TimeConversion::fromISO8601( name).date() );
93 }
94 // categories
95 if((ob = isAPropertyOf( obj, VCCategoriesProp )) != 0 ){
96 name = vObjectStringZValue( ob );
97 qWarning("Categories:%s", name.data() );
98 }
99
100 return event;
101};
102
103
104QValueList<ToDoEvent> ToDoVCalResource::load(const QString &file)
105{
106 QValueList<ToDoEvent> events;
107 VObject *vcal = 0l;
108 vcal = Parse_MIME_FromFileName( (char *)file.utf8().data() ); // from vobject
109 if(!vcal )
110 return events;
111 // start parsing
112
113 VObjectIterator it;
114 VObject *vobj;
115 initPropIterator(&it, vcal);
116
117 while( moreIteration( &it ) ) {
118 vobj = ::nextVObject( &it );
119 QCString name = ::vObjectName( vobj );
120 //QCString objVal = ::vObjectStringZValue( vobj );
121 // let's find out the type
122 if( name == VCTodoProp ){
123 events.append( eventByVObj( vobj ) );
124
125 } // parse the value
126 }
127 return events;
128}
129bool ToDoVCalResource::save(const QString &fileName, const QValueList<ToDoEvent>&list )
130{
131 QFileDirect file ( fileName );
132 if(!file.open(IO_WriteOnly ) )
133 return false;
134 // obj
135 VObject *obj;
136 obj = newVObject( VCCalProp );
137 addPropValue( obj, VCVersionProp, "1.0" );
138 VObject *vo;
139 for(QValueList<ToDoEvent>::ConstIterator it = list.begin(); it != list.end(); ++it ){
140 vo = vobjByEvent( (*it) );
141 addVObjectProp(obj, vo );
142 }
143 writeVObject( file.directHandle(), obj );
144 cleanVObject( obj );
145 cleanStrTbl();
146
147 return true;
148}
149
150
151
152
153
154
155
156
157
158
diff --git a/libopie/todovcalresource.h b/libopie/todovcalresource.h
deleted file mode 100644
index 0663bc2..0000000
--- a/libopie/todovcalresource.h
+++ b/dev/null
@@ -1,42 +0,0 @@
1/*
2               =. This file is part of the OPIE Project
3             .=l. Copyright (c) 2002 Holger Freyther <freyther@kde.org>
4           .>+-=
5 _;:,     .>    :=|. This library is free software; you can
6.> <`_,   >  .   <= redistribute it and/or modify it under
7:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; either version 2 of the License,
10     ._= =}       : or (at your option) any later version.
11    .%`+i>       _;_.
12    .i_,=:_.      -<s. This library is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
17..}^=.=       =       ; Library General Public License for more
18++=   -.     .`     .: details.
19 :     =  ...= . :.=-
20 -.   .:....=;==+<; You should have received a copy of the GNU
21  -_. . .   )=.  = Library General Public License along with
22    --        :-=` this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA.
26
27*/
28
29#ifndef opievcaltodoresource_h
30#define opievcaltodoresource_h
31
32#include <opie/todoresource.h>
33
34class ToDoVCalResource : public ToDoResource {
35 public:
36 ToDoVCalResource() { };
37 QValueList<ToDoEvent> load(const QString &file );
38 bool save( const QString &filename, const QValueList<ToDoEvent> & );
39
40};
41
42#endif