summaryrefslogtreecommitdiff
path: root/libopie/pim
authorzecke <zecke>2003-02-21 16:52:49 (UTC)
committer zecke <zecke>2003-02-21 16:52:49 (UTC)
commit0bb9d0f9e7da80f0ae3b91d4ebbb7aab4d2b9df7 (patch) (unidiff)
treef3ce9c9441a1073762f3e0c61cc85f0d5a1fd81d /libopie/pim
parenta298235aa1489937e7657079e6352adfc8746acf (diff)
downloadopie-0bb9d0f9e7da80f0ae3b91d4ebbb7aab4d2b9df7.zip
opie-0bb9d0f9e7da80f0ae3b91d4ebbb7aab4d2b9df7.tar.gz
opie-0bb9d0f9e7da80f0ae3b91d4ebbb7aab4d2b9df7.tar.bz2
-Remove old Todo classes they're deprecated and today I already using the
new API -Guard against self assignment in OTodo -Add test apps for OPIM -Opiefied Event classes -Added TimeZone handling and pinning of TimeZones to OEvent -Adjust ORecur and the widget to better timezone behaviour
Diffstat (limited to 'libopie/pim') (more/less context) (ignore whitespace changes)
-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
12 files changed, 911 insertions, 20 deletions
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
@@ -17,6 +17,15 @@
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
@@ -74,7 +83,7 @@ bool OContactAccessBackend_VCard::load ()
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;
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
@@ -10,17 +10,17 @@ struct ORecur::Data : public QShared {
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;
@@ -52,6 +52,8 @@ bool 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;
@@ -366,15 +368,12 @@ bool 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 {
@@ -404,13 +403,9 @@ void ORecur::setDays( char 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}
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
@@ -35,13 +35,18 @@ public:
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 */
@@ -63,8 +68,7 @@ public:
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
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
@@ -340,6 +340,8 @@ void OTodo::deref() {
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();
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