author | zecke <zecke> | 2003-02-21 16:52:49 (UTC) |
---|---|---|
committer | zecke <zecke> | 2003-02-21 16:52:49 (UTC) |
commit | 0bb9d0f9e7da80f0ae3b91d4ebbb7aab4d2b9df7 (patch) (unidiff) | |
tree | f3ce9c9441a1073762f3e0c61cc85f0d5a1fd81d /libopie2 | |
parent | a298235aa1489937e7657079e6352adfc8746acf (diff) | |
download | opie-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
-rw-r--r-- | libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp | 11 | ||||
-rw-r--r-- | libopie2/opiepim/core/orecur.cpp | 25 | ||||
-rw-r--r-- | libopie2/opiepim/core/orecur.h | 12 | ||||
-rw-r--r-- | libopie2/opiepim/core/otimezone.cpp | 104 | ||||
-rw-r--r-- | libopie2/opiepim/core/otimezone.h | 71 | ||||
-rw-r--r-- | libopie2/opiepim/oevent.cpp | 427 | ||||
-rw-r--r-- | libopie2/opiepim/oevent.h | 198 | ||||
-rw-r--r-- | libopie2/opiepim/otodo.cpp | 2 |
8 files changed, 830 insertions, 20 deletions
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp index 622d40a..e537269 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp +++ b/libopie2/opiepim/backend/ocontactaccessbackend_vcard.cpp | |||
@@ -18,4 +18,13 @@ | |||
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 |
@@ -75,5 +84,5 @@ bool OContactAccessBackend_VCard::load () | |||
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 ) |
diff --git a/libopie2/opiepim/core/orecur.cpp b/libopie2/opiepim/core/orecur.cpp index daf3506..e6a4787 100644 --- a/libopie2/opiepim/core/orecur.cpp +++ b/libopie2/opiepim/core/orecur.cpp | |||
@@ -11,7 +11,7 @@ struct ORecur::Data : public QShared { | |||
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;) |
@@ -20,6 +20,6 @@ struct ORecur::Data : public QShared { | |||
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; |
@@ -53,4 +53,6 @@ bool ORecur::operator==( const ORecur& )const { | |||
53 | } | 53 | } |
54 | ORecur &ORecur::operator=( const ORecur& re) { | 54 | ORecur &ORecur::operator=( const ORecur& re) { |
55 | if ( *this == re ) return *this; | ||
56 | |||
55 | re.data->ref(); | 57 | re.data->ref(); |
56 | deref(); | 58 | deref(); |
@@ -367,13 +369,10 @@ bool ORecur::hasEndDate()const { | |||
367 | } | 369 | } |
368 | QDate ORecur::endDate()const { | 370 | QDate ORecur::endDate()const { |
369 | return TimeConversion::fromUTC( data->end ).date(); | 371 | return data->end; |
370 | } | 372 | } |
371 | QDate ORecur::start()const{ | 373 | QDate ORecur::start()const{ |
372 | return data->start; | 374 | return data->start; |
373 | } | 375 | } |
374 | time_t ORecur::endDateUTC()const { | 376 | QDateTime ORecur::createdDateTime()const { |
375 | return data->end; | ||
376 | } | ||
377 | time_t ORecur::createTime()const { | ||
378 | return data->create; | 377 | return data->create; |
379 | } | 378 | } |
@@ -405,11 +404,7 @@ void ORecur::setDays( char c ) { | |||
405 | void ORecur::setEndDate( const QDate& dt) { | 404 | void ORecur::setEndDate( const QDate& dt) { |
406 | checkOrModify(); | 405 | checkOrModify(); |
407 | data->end = TimeConversion::toUTC( dt ); | 406 | data->end = dt; |
408 | } | ||
409 | void ORecur::setEndDateUTC( time_t t) { | ||
410 | checkOrModify(); | ||
411 | data->end = t; | ||
412 | } | 407 | } |
413 | void ORecur::setCreateTime( time_t t) { | 408 | void ORecur::setCreatedDateTime( const QDateTime& t) { |
414 | checkOrModify(); | 409 | checkOrModify(); |
415 | data->create = t; | 410 | data->create = t; |
diff --git a/libopie2/opiepim/core/orecur.h b/libopie2/opiepim/core/orecur.h index 8713d97..1e0014b 100644 --- a/libopie2/opiepim/core/orecur.h +++ b/libopie2/opiepim/core/orecur.h | |||
@@ -36,6 +36,10 @@ public: | |||
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 | /** |
@@ -43,4 +47,5 @@ public: | |||
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 |
@@ -64,6 +69,5 @@ public: | |||
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 ); |
diff --git a/libopie2/opiepim/core/otimezone.cpp b/libopie2/opiepim/core/otimezone.cpp new file mode 100644 index 0000000..b2bd3aa --- a/dev/null +++ b/libopie2/opiepim/core/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 | |||
8 | namespace { | ||
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 | } | ||
53 | OTimeZone::OTimeZone( const ZoneName& zone ) | ||
54 | : m_name(zone) { | ||
55 | } | ||
56 | OTimeZone::~OTimeZone() { | ||
57 | } | ||
58 | |||
59 | bool 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 | */ | ||
67 | QDateTime OTimeZone::toLocalDateTime( const QDateTime& dt) { | ||
68 | return OTimeZone::current().toDateTime( dt, *this ); | ||
69 | } | ||
70 | QDateTime OTimeZone::toUTCDateTime( const QDateTime& dt ) { | ||
71 | return OTimeZone::utc().toDateTime( dt, *this ); | ||
72 | } | ||
73 | QDateTime OTimeZone::fromUTCDateTime( time_t t) { | ||
74 | return utcTime( t ); | ||
75 | } | ||
76 | QDateTime 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 | */ | ||
83 | QDateTime 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 | } | ||
88 | time_t OTimeZone::fromDateTime( const QDateTime& time ) { | ||
89 | return to_Time_t( time, m_name ); | ||
90 | } | ||
91 | time_t OTimeZone::fromUTCDateTime( const QDateTime& time ) { | ||
92 | return to_Time_t( time, "UTC" ); | ||
93 | } | ||
94 | OTimeZone OTimeZone::current() { | ||
95 | QCString str = ::getenv("TZ"); | ||
96 | OTimeZone zone( str ); | ||
97 | return zone; | ||
98 | } | ||
99 | OTimeZone OTimeZone::utc() { | ||
100 | return OTimeZone("UTC"); | ||
101 | } | ||
102 | QString OTimeZone::timeZone()const { | ||
103 | return m_name; | ||
104 | } | ||
diff --git a/libopie2/opiepim/core/otimezone.h b/libopie2/opiepim/core/otimezone.h new file mode 100644 index 0000000..bb08349 --- a/dev/null +++ b/libopie2/opiepim/core/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 | */ | ||
13 | class 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/libopie2/opiepim/oevent.cpp b/libopie2/opiepim/oevent.cpp new file mode 100644 index 0000000..71b9441 --- a/dev/null +++ b/libopie2/opiepim/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 | |||
12 | namespace 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 | |||
45 | struct 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 | |||
67 | OEvent::OEvent( int uid ) | ||
68 | : OPimRecord( uid ) { | ||
69 | data = new Data; | ||
70 | } | ||
71 | OEvent::OEvent( const OEvent& ev) | ||
72 | : OPimRecord( ev ), data( ev.data ) | ||
73 | { | ||
74 | data->ref(); | ||
75 | } | ||
76 | OEvent::~OEvent() { | ||
77 | if ( data->deref() ) { | ||
78 | delete data; | ||
79 | data = 0; | ||
80 | } | ||
81 | } | ||
82 | OEvent& 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 | } | ||
93 | QString OEvent::description()const { | ||
94 | return data->description; | ||
95 | } | ||
96 | void OEvent::setDescription( const QString& description ) { | ||
97 | changeOrModify(); | ||
98 | data->description = description; | ||
99 | } | ||
100 | void OEvent::setLocation( const QString& loc ) { | ||
101 | changeOrModify(); | ||
102 | data->location = loc; | ||
103 | } | ||
104 | QString OEvent::location()const { | ||
105 | return data->location; | ||
106 | } | ||
107 | OPimNotifyManager &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 | } | ||
116 | bool OEvent::hasNotifiers()const { | ||
117 | return ( data->manager); | ||
118 | } | ||
119 | ORecur OEvent::recurrence()const { | ||
120 | if (!data->recur) | ||
121 | data->recur = new ORecur; | ||
122 | |||
123 | return *data->recur; | ||
124 | } | ||
125 | void OEvent::setRecurrence( const ORecur& rec) { | ||
126 | changeOrModify(); | ||
127 | if (data->recur ) | ||
128 | (*data->recur) = rec; | ||
129 | else | ||
130 | data->recur = new ORecur( rec ); | ||
131 | } | ||
132 | bool OEvent::hasRecurrence()const { | ||
133 | return data->recur; | ||
134 | } | ||
135 | QString OEvent::note()const { | ||
136 | return data->note; | ||
137 | } | ||
138 | void OEvent::setNote( const QString& note ) { | ||
139 | changeOrModify(); | ||
140 | data->note = note; | ||
141 | } | ||
142 | QDateTime OEvent::createdDateTime()const { | ||
143 | return data->created; | ||
144 | } | ||
145 | void OEvent::setCreatedDateTime( const QDateTime& time ) { | ||
146 | changeOrModify(); | ||
147 | data->created = time; | ||
148 | } | ||
149 | QDateTime OEvent::startDateTime()const { | ||
150 | if ( data->isAllDay ) | ||
151 | return QDateTime( data->start.date(), QTime(0, 0, 0 ) ); | ||
152 | return data->start; | ||
153 | } | ||
154 | QDateTime 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 | } | ||
161 | void OEvent::setStartDateTime( const QDateTime& dt ) { | ||
162 | changeOrModify(); | ||
163 | data->start = dt; | ||
164 | } | ||
165 | QDateTime 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 | } | ||
174 | QDateTime 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 | } | ||
181 | void OEvent::setEndDateTime( const QDateTime& dt ) { | ||
182 | changeOrModify(); | ||
183 | data->end = dt; | ||
184 | } | ||
185 | bool OEvent::isMultipleDay()const { | ||
186 | return data->end.date().day() - data->start.date().day(); | ||
187 | } | ||
188 | bool OEvent::isAllDay()const { | ||
189 | return data->isAllDay; | ||
190 | } | ||
191 | void OEvent::setTimeZone( const QString& tz ) { | ||
192 | changeOrModify(); | ||
193 | data->timezone = tz; | ||
194 | } | ||
195 | QString OEvent::timeZone()const { | ||
196 | return data->timezone; | ||
197 | } | ||
198 | bool OEvent::match( const QRegExp& )const { | ||
199 | // FIXME | ||
200 | return false; | ||
201 | } | ||
202 | QString OEvent::toRichText()const { | ||
203 | // FIXME | ||
204 | return "OEvent test"; | ||
205 | } | ||
206 | QString OEvent::toShortText()const { | ||
207 | return "OEvent shotText"; | ||
208 | } | ||
209 | QString OEvent::type()const { | ||
210 | return QString::fromLatin1("OEvent"); | ||
211 | } | ||
212 | QString OEvent::recordField( int /*id */ )const { | ||
213 | return QString::null; | ||
214 | } | ||
215 | int OEvent::rtti() { | ||
216 | return OPimResolver::DateBook; | ||
217 | } | ||
218 | bool OEvent::loadFromStream( QDataStream& ) { | ||
219 | return true; | ||
220 | } | ||
221 | bool OEvent::saveToStream( QDataStream& )const { | ||
222 | return true; | ||
223 | } | ||
224 | void 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 | } | ||
242 | void OEvent::deref() { | ||
243 | if ( data->deref() ) { | ||
244 | delete data; | ||
245 | data = 0; | ||
246 | } | ||
247 | } | ||
248 | // FIXME | ||
249 | QMap<int, QString> OEvent::toMap()const { | ||
250 | return QMap<int, QString>(); | ||
251 | } | ||
252 | QMap<QString, QString> OEvent::toExtraMap()const { | ||
253 | return QMap<QString, QString>(); | ||
254 | } | ||
255 | |||
256 | |||
257 | struct 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 | |||
267 | OEffectiveEvent::OEffectiveEvent() { | ||
268 | data = new Data; | ||
269 | data->date = QDate::currentDate(); | ||
270 | data->start = data->end = QTime::currentTime(); | ||
271 | data->dates = false; | ||
272 | } | ||
273 | OEffectiveEvent::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 | } | ||
290 | OEffectiveEvent::OEffectiveEvent( const OEffectiveEvent& ev) { | ||
291 | data = ev.data; | ||
292 | data->ref(); | ||
293 | } | ||
294 | OEffectiveEvent::~OEffectiveEvent() { | ||
295 | if ( data->deref() ) { | ||
296 | delete data; | ||
297 | data = 0; | ||
298 | } | ||
299 | } | ||
300 | OEffectiveEvent& 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 | |||
310 | void OEffectiveEvent::setStartTime( const QTime& ti) { | ||
311 | changeOrModify(); | ||
312 | data->start = ti; | ||
313 | } | ||
314 | void OEffectiveEvent::setEndTime( const QTime& en) { | ||
315 | changeOrModify(); | ||
316 | data->end = en; | ||
317 | } | ||
318 | void OEffectiveEvent::setEvent( const OEvent& ev) { | ||
319 | changeOrModify(); | ||
320 | data->event = ev; | ||
321 | } | ||
322 | void OEffectiveEvent::setDate( const QDate& da) { | ||
323 | changeOrModify(); | ||
324 | data->date = da; | ||
325 | } | ||
326 | void 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 | } | ||
336 | QString OEffectiveEvent::description()const { | ||
337 | return data->event.description(); | ||
338 | } | ||
339 | QString OEffectiveEvent::location()const { | ||
340 | return data->event.location(); | ||
341 | } | ||
342 | QString OEffectiveEvent::note()const { | ||
343 | return data->event.note(); | ||
344 | } | ||
345 | OEvent OEffectiveEvent::event()const { | ||
346 | return data->event; | ||
347 | } | ||
348 | QTime OEffectiveEvent::startTime()const { | ||
349 | return data->start; | ||
350 | } | ||
351 | QTime OEffectiveEvent::endTime()const { | ||
352 | return data->end; | ||
353 | } | ||
354 | QDate OEffectiveEvent::date()const { | ||
355 | return data->date; | ||
356 | } | ||
357 | int OEffectiveEvent::length()const { | ||
358 | return (data->end.hour() * 60 - data->start.hour() * 60) | ||
359 | + QABS(data->start.minute() - data->end.minute() ); | ||
360 | } | ||
361 | int 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 | } | ||
366 | QDate 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 | } | ||
374 | QDate 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 | } | ||
382 | void OEffectiveEvent::deref() { | ||
383 | if ( data->deref() ) { | ||
384 | delete data; | ||
385 | data = 0; | ||
386 | } | ||
387 | } | ||
388 | void 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 | } | ||
402 | bool 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 | } | ||
410 | bool OEffectiveEvent::operator<=( const OEffectiveEvent &e ) const{ | ||
411 | return (data->date <= e.date() ); | ||
412 | } | ||
413 | bool OEffectiveEvent::operator==( const OEffectiveEvent &e ) const { | ||
414 | return ( date() == e.date() | ||
415 | && startTime() == e.startTime() | ||
416 | && endTime()== e.endTime() | ||
417 | && event() == e.event() ); | ||
418 | } | ||
419 | bool OEffectiveEvent::operator!=( const OEffectiveEvent &e ) const { | ||
420 | return !(*this == e ); | ||
421 | } | ||
422 | bool OEffectiveEvent::operator>( const OEffectiveEvent &e ) const { | ||
423 | return !(*this <= e ); | ||
424 | } | ||
425 | bool OEffectiveEvent::operator>= ( const OEffectiveEvent &e ) const { | ||
426 | return !(*this < e); | ||
427 | } | ||
diff --git a/libopie2/opiepim/oevent.h b/libopie2/opiepim/oevent.h new file mode 100644 index 0000000..4489be7 --- a/dev/null +++ b/libopie2/opiepim/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 | |||
16 | namespace 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 | |||
31 | class OPimNotifyManager; | ||
32 | class ORecur; | ||
33 | class OEvent : public OPimRecord { | ||
34 | public: | ||
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 ¬ifiers(); | ||
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 | */ | ||
126 | private: | ||
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 | |||
140 | class OEffectiveEvent { | ||
141 | public: | ||
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 | |||
189 | private: | ||
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/libopie2/opiepim/otodo.cpp b/libopie2/opiepim/otodo.cpp index b4d4aa9..049359e 100644 --- a/libopie2/opiepim/otodo.cpp +++ b/libopie2/opiepim/otodo.cpp | |||
@@ -341,4 +341,6 @@ void OTodo::deref() { | |||
341 | OTodo &OTodo::operator=(const OTodo &item ) | 341 | OTodo &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 "); |