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 /libopie | |
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-- | libopie/libopie.pro | 14 | ||||
-rw-r--r-- | libopie/orecurrancewidget.cpp | 2 | ||||
-rw-r--r-- | libopie/pim/ocontactaccessbackend_vcard.cpp | 11 | ||||
-rw-r--r-- | libopie/pim/oevent.cpp | 427 | ||||
-rw-r--r-- | libopie/pim/oevent.h | 198 | ||||
-rw-r--r-- | libopie/pim/orecur.cpp | 25 | ||||
-rw-r--r-- | libopie/pim/orecur.h | 12 | ||||
-rw-r--r-- | libopie/pim/otimezone.cpp | 104 | ||||
-rw-r--r-- | libopie/pim/otimezone.h | 71 | ||||
-rw-r--r-- | libopie/pim/otodo.cpp | 2 | ||||
-rw-r--r-- | libopie/pim/test/oevent_test.cpp | 23 | ||||
-rw-r--r-- | libopie/pim/test/oevent_test.pro | 11 | ||||
-rw-r--r-- | libopie/pim/test/test_todo.cpp | 36 | ||||
-rw-r--r-- | libopie/pim/test/todo_test.pro | 11 | ||||
-rw-r--r-- | libopie/tododb.cpp | 268 | ||||
-rw-r--r-- | libopie/tododb.h | 46 | ||||
-rw-r--r-- | libopie/todoevent.cpp | 339 | ||||
-rw-r--r-- | libopie/todoevent.h | 191 | ||||
-rw-r--r-- | libopie/todoresource.h | 14 | ||||
-rw-r--r-- | libopie/todovcalresource.cpp | 158 | ||||
-rw-r--r-- | libopie/todovcalresource.h | 42 |
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,108 +1,112 @@ | |||
1 | TEMPLATE = lib | 1 | TEMPLATE = lib |
2 | CONFIG += qte warn_on release | 2 | CONFIG += qte warn_on release |
3 | HEADERS = ofontmenu.h \ | 3 | HEADERS = 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 \ |
14 | pim/opimrecord.h \ | 14 | pim/opimrecord.h \ |
15 | pim/otodo.h \ | 15 | pim/otodo.h \ |
16 | pim/orecordlist.h \ | 16 | pim/orecordlist.h \ |
17 | pim/opimaccesstemplate.h \ | 17 | pim/opimaccesstemplate.h \ |
18 | pim/opimaccessbackend.h \ | 18 | pim/opimaccessbackend.h \ |
19 | pim/otodoaccess.h \ | 19 | pim/otodoaccess.h \ |
20 | pim/otodoaccessbackend.h \ | 20 | pim/otodoaccessbackend.h \ |
21 | pim/ocontact.h \ | 21 | pim/ocontact.h \ |
22 | pim/ocontactaccess.h \ | 22 | pim/ocontactaccess.h \ |
23 | pim/ocontactaccessbackend.h \ | 23 | pim/ocontactaccessbackend.h \ |
24 | pim/ocontactaccessbackend_xml.h \ | 24 | pim/ocontactaccessbackend_xml.h \ |
25 | pim/ocontactaccessbackend_vcard.h \ | 25 | pim/ocontactaccessbackend_vcard.h \ |
26 | pim/obackendfactory.h \ | 26 | pim/obackendfactory.h \ |
27 | pim/opimcache.h \ | 27 | pim/opimcache.h \ |
28 | pim/otodoaccessvcal.h \ | 28 | pim/otodoaccessvcal.h \ |
29 | pim/orecur.h \ | 29 | pim/orecur.h \ |
30 | pim/opimstate.h \ | 30 | pim/opimstate.h \ |
31 | pim/opimxrefpartner.h \ | 31 | pim/opimxrefpartner.h \ |
32 | pim/opimxref.h \ | 32 | pim/opimxref.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 | ||
43 | SOURCES = ofontmenu.cc \ | 45 | SOURCES = 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 \ |
56 | pim/opimrecord.cpp \ | 58 | pim/opimrecord.cpp \ |
57 | pim/otodoaccess.cpp \ | 59 | pim/otodoaccess.cpp \ |
58 | pim/otodoaccessbackend.cpp \ | 60 | pim/otodoaccessbackend.cpp \ |
59 | pim/otodoaccessxml.cpp \ | 61 | pim/otodoaccessxml.cpp \ |
60 | pim/ocontact.cpp \ | 62 | pim/ocontact.cpp \ |
61 | pim/ocontactaccess.cpp \ | 63 | pim/ocontactaccess.cpp \ |
62 | pim/ocontactaccessbackend_vcard.cpp \ | 64 | pim/ocontactaccessbackend_vcard.cpp \ |
63 | pim/otodoaccessvcal.cpp \ | 65 | pim/otodoaccessvcal.cpp \ |
64 | pim/orecur.cpp \ | 66 | pim/orecur.cpp \ |
65 | pim/opimstate.cpp \ | 67 | pim/opimstate.cpp \ |
66 | pim/opimxrefpartner.cpp \ | 68 | pim/opimxrefpartner.cpp \ |
67 | pim/opimxref.cpp \ | 69 | pim/opimxref.cpp \ |
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 | ||
78 | TARGET = opie | 82 | TARGET = opie |
79 | INCLUDEPATH += $(OPIEDIR)/include | 83 | INCLUDEPATH += $(OPIEDIR)/include |
80 | DESTDIR = $(OPIEDIR)/lib$(PROJMAK) | 84 | DESTDIR = $(OPIEDIR)/lib$(PROJMAK) |
81 | #VERSION = 1.0.0 | 85 | #VERSION = 1.0.0 |
82 | 86 | ||
83 | LIBS += -lqpe | 87 | LIBS += -lqpe |
84 | 88 | ||
85 | # LIBS += -lopiesql | 89 | # LIBS += -lopiesql |
86 | 90 | ||
87 | INTERFACES = otimepickerbase.ui orecurrancebase.ui | 91 | INTERFACES = otimepickerbase.ui orecurrancebase.ui |
88 | 92 | ||
89 | TRANSLATIONS = ../i18n/de/libopie.ts \ | 93 | TRANSLATIONS = ../i18n/de/libopie.ts \ |
90 | ../i18n/xx/libopie.ts \ | 94 | ../i18n/xx/libopie.ts \ |
91 | ../i18n/en/libopie.ts \ | 95 | ../i18n/en/libopie.ts \ |
92 | ../i18n/es/libopie.ts \ | 96 | ../i18n/es/libopie.ts \ |
93 | ../i18n/fr/libopie.ts \ | 97 | ../i18n/fr/libopie.ts \ |
94 | ../i18n/hu/libopie.ts \ | 98 | ../i18n/hu/libopie.ts \ |
95 | ../i18n/ja/libopie.ts \ | 99 | ../i18n/ja/libopie.ts \ |
96 | ../i18n/ko/libopie.ts \ | 100 | ../i18n/ko/libopie.ts \ |
97 | ../i18n/no/libopie.ts \ | 101 | ../i18n/no/libopie.ts \ |
98 | ../i18n/pl/libopie.ts \ | 102 | ../i18n/pl/libopie.ts \ |
99 | ../i18n/pt/libopie.ts \ | 103 | ../i18n/pt/libopie.ts \ |
100 | ../i18n/pt_BR/libopie.ts \ | 104 | ../i18n/pt_BR/libopie.ts \ |
101 | ../i18n/sl/libopie.ts \ | 105 | ../i18n/sl/libopie.ts \ |
102 | ../i18n/zh_CN/libopie.ts \ | 106 | ../i18n/zh_CN/libopie.ts \ |
103 | ../i18n/zh_TW/libopie.ts \ | 107 | ../i18n/zh_TW/libopie.ts \ |
104 | ../i18n/da/libopie.ts | 108 | ../i18n/da/libopie.ts |
105 | 109 | ||
106 | 110 | ||
107 | 111 | ||
108 | include ( $(OPIEDIR)/include.pro ) | 112 | include ( $(OPIEDIR)/include.pro ) |
diff --git a/libopie/orecurrancewidget.cpp b/libopie/orecurrancewidget.cpp index 0484ab9..db86184 100644 --- a/libopie/orecurrancewidget.cpp +++ b/libopie/orecurrancewidget.cpp | |||
@@ -84,193 +84,193 @@ void ORecurranceWidget::setRecurrence( const ORecur& rp, const QDate& date ) { | |||
84 | setupWeekly(); | 84 | setupWeekly(); |
85 | int day, buttons; | 85 | int day, buttons; |
86 | for ( day = 0x01, buttons = 0; buttons < 7; | 86 | for ( day = 0x01, buttons = 0; buttons < 7; |
87 | day = day << 1, buttons++ ) { | 87 | day = day << 1, buttons++ ) { |
88 | if ( rp.days() & day ) { | 88 | if ( rp.days() & day ) { |
89 | if ( startWeekOnMonday ) | 89 | if ( startWeekOnMonday ) |
90 | fraExtra->setButton( buttons ); | 90 | fraExtra->setButton( buttons ); |
91 | else { | 91 | else { |
92 | if ( buttons == 7 ) | 92 | if ( buttons == 7 ) |
93 | fraExtra->setButton( 0 ); | 93 | fraExtra->setButton( 0 ); |
94 | else | 94 | else |
95 | fraExtra->setButton( buttons + 1 ); | 95 | fraExtra->setButton( buttons + 1 ); |
96 | } | 96 | } |
97 | } | 97 | } |
98 | } | 98 | } |
99 | slotWeekLabel(); | 99 | slotWeekLabel(); |
100 | break; | 100 | break; |
101 | case ORecur::MonthlyDay: | 101 | case ORecur::MonthlyDay: |
102 | currInterval = Month; | 102 | currInterval = Month; |
103 | setupMonthly(); | 103 | setupMonthly(); |
104 | fraExtra->setButton( 0 ); | 104 | fraExtra->setButton( 0 ); |
105 | slotMonthLabel( 0 ); | 105 | slotMonthLabel( 0 ); |
106 | break; | 106 | break; |
107 | case ORecur::MonthlyDate: | 107 | case ORecur::MonthlyDate: |
108 | currInterval = Month; | 108 | currInterval = Month; |
109 | setupMonthly(); | 109 | setupMonthly(); |
110 | fraExtra->setButton( 1 ); | 110 | fraExtra->setButton( 1 ); |
111 | slotMonthLabel( 1 ); | 111 | slotMonthLabel( 1 ); |
112 | break; | 112 | break; |
113 | case ORecur::Yearly: | 113 | case ORecur::Yearly: |
114 | currInterval = Year; | 114 | currInterval = Year; |
115 | setupYearly(); | 115 | setupYearly(); |
116 | break; | 116 | break; |
117 | } | 117 | } |
118 | fraType->setButton( currInterval ); | 118 | fraType->setButton( currInterval ); |
119 | spinFreq->setValue( rp.frequency() ); | 119 | spinFreq->setValue( rp.frequency() ); |
120 | if ( !rp.hasEndDate() ) { | 120 | if ( !rp.hasEndDate() ) { |
121 | cmdEnd->setText( tr("No End Date") ); | 121 | cmdEnd->setText( tr("No End Date") ); |
122 | chkNoEnd->setChecked( TRUE ); | 122 | chkNoEnd->setChecked( TRUE ); |
123 | } else | 123 | } else |
124 | cmdEnd->setText( TimeString::shortDate( end ) ); | 124 | cmdEnd->setText( TimeString::shortDate( end ) ); |
125 | } | 125 | } |
126 | ORecur ORecurranceWidget::recurrence()const { | 126 | ORecur ORecurranceWidget::recurrence()const { |
127 | QListIterator<QToolButton> it( listRTypeButtons ); | 127 | QListIterator<QToolButton> it( listRTypeButtons ); |
128 | QListIterator<QToolButton> itExtra( listExtra ); | 128 | QListIterator<QToolButton> itExtra( listExtra ); |
129 | ORecur rpTmp; | 129 | ORecur rpTmp; |
130 | int i; | 130 | int i; |
131 | for ( i = 0; *it; ++it, i++ ) { | 131 | for ( i = 0; *it; ++it, i++ ) { |
132 | if ( (*it)->isOn() ) { | 132 | if ( (*it)->isOn() ) { |
133 | switch ( i ) { | 133 | switch ( i ) { |
134 | case None: | 134 | case None: |
135 | rpTmp.setType( ORecur::NoRepeat ); | 135 | rpTmp.setType( ORecur::NoRepeat ); |
136 | break; | 136 | break; |
137 | case Day: | 137 | case Day: |
138 | rpTmp.setType( ORecur::Daily ); | 138 | rpTmp.setType( ORecur::Daily ); |
139 | break; | 139 | break; |
140 | case Week:{ | 140 | case Week:{ |
141 | rpTmp.setType( ORecur::Weekly ); | 141 | rpTmp.setType( ORecur::Weekly ); |
142 | int day; | 142 | int day; |
143 | int day2 = 0; | 143 | int day2 = 0; |
144 | for ( day = 1; *itExtra; ++itExtra, day = day << 1 ) { | 144 | for ( day = 1; *itExtra; ++itExtra, day = day << 1 ) { |
145 | if ( (*itExtra)->isOn() ) { | 145 | if ( (*itExtra)->isOn() ) { |
146 | if ( startWeekOnMonday ) | 146 | if ( startWeekOnMonday ) |
147 | day2 |= day; | 147 | day2 |= day; |
148 | else { | 148 | else { |
149 | if ( day == 1 ) | 149 | if ( day == 1 ) |
150 | day2 |= Event::SUN; | 150 | day2 |= Event::SUN; |
151 | else | 151 | else |
152 | day2 |= day >> 1; | 152 | day2 |= day >> 1; |
153 | } | 153 | } |
154 | } | 154 | } |
155 | } | 155 | } |
156 | rpTmp.setDays( day2 ); | 156 | rpTmp.setDays( day2 ); |
157 | } | 157 | } |
158 | break; | 158 | break; |
159 | case Month: | 159 | case Month: |
160 | if ( cmdExtra1->isOn() ) | 160 | if ( cmdExtra1->isOn() ) |
161 | rpTmp.setType( ORecur::MonthlyDay ); | 161 | rpTmp.setType( ORecur::MonthlyDay ); |
162 | else if ( cmdExtra2->isOn() ) | 162 | else if ( cmdExtra2->isOn() ) |
163 | rpTmp.setType( ORecur::MonthlyDate ); | 163 | rpTmp.setType( ORecur::MonthlyDate ); |
164 | // figure out the montly day... | 164 | // figure out the montly day... |
165 | rpTmp.setPosition( week( start ) ); | 165 | rpTmp.setPosition( week( start ) ); |
166 | break; | 166 | break; |
167 | case Year: | 167 | case Year: |
168 | rpTmp.setType( ORecur::Yearly ); | 168 | rpTmp.setType( ORecur::Yearly ); |
169 | break; | 169 | break; |
170 | } | 170 | } |
171 | break; // no need to keep looking! | 171 | break; // no need to keep looking! |
172 | } | 172 | } |
173 | } | 173 | } |
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 | } |
183 | QDate ORecurranceWidget::endDate()const { | 183 | QDate ORecurranceWidget::endDate()const { |
184 | return end; | 184 | return end; |
185 | } | 185 | } |
186 | void ORecurranceWidget::slotSetRType(int rtype) { | 186 | void ORecurranceWidget::slotSetRType(int rtype) { |
187 | // now call the right function based on the type... | 187 | // now call the right function based on the type... |
188 | currInterval = static_cast<repeatButtons>(rtype); | 188 | currInterval = static_cast<repeatButtons>(rtype); |
189 | switch ( currInterval ) { | 189 | switch ( currInterval ) { |
190 | case None: | 190 | case None: |
191 | setupNone(); | 191 | setupNone(); |
192 | break; | 192 | break; |
193 | case Day: | 193 | case Day: |
194 | setupDaily(); | 194 | setupDaily(); |
195 | break; | 195 | break; |
196 | case Week: | 196 | case Week: |
197 | setupWeekly(); | 197 | setupWeekly(); |
198 | slotWeekLabel(); | 198 | slotWeekLabel(); |
199 | break; | 199 | break; |
200 | case Month: | 200 | case Month: |
201 | setupMonthly(); | 201 | setupMonthly(); |
202 | cmdExtra2->setOn( TRUE ); | 202 | cmdExtra2->setOn( TRUE ); |
203 | slotMonthLabel( 1 ); | 203 | slotMonthLabel( 1 ); |
204 | break; | 204 | break; |
205 | case Year: | 205 | case Year: |
206 | setupYearly(); | 206 | setupYearly(); |
207 | break; | 207 | break; |
208 | } | 208 | } |
209 | } | 209 | } |
210 | void ORecurranceWidget::endDateChanged(int y, int m, int d) { | 210 | void ORecurranceWidget::endDateChanged(int y, int m, int d) { |
211 | end.setYMD( y, m, d ); | 211 | end.setYMD( y, m, d ); |
212 | if ( end < start ) | 212 | if ( end < start ) |
213 | end = start; | 213 | end = start; |
214 | cmdEnd->setText( TimeString::shortDate( end ) ); | 214 | cmdEnd->setText( TimeString::shortDate( end ) ); |
215 | repeatPicker->setDate( end.year(), end.month(), end.day() ); | 215 | repeatPicker->setDate( end.year(), end.month(), end.day() ); |
216 | } | 216 | } |
217 | void ORecurranceWidget::slotNoEnd( bool unused) { | 217 | void ORecurranceWidget::slotNoEnd( bool unused) { |
218 | // if the item was toggled, then go ahead and set it to the maximum date | 218 | // if the item was toggled, then go ahead and set it to the maximum date |
219 | if ( unused ) { | 219 | if ( unused ) { |
220 | end.setYMD( 3000, 12, 31 ); | 220 | end.setYMD( 3000, 12, 31 ); |
221 | cmdEnd->setText( tr("No End Date") ); | 221 | cmdEnd->setText( tr("No End Date") ); |
222 | } else { | 222 | } else { |
223 | end = start; | 223 | end = start; |
224 | cmdEnd->setText( TimeString::shortDate(end) ); | 224 | cmdEnd->setText( TimeString::shortDate(end) ); |
225 | } | 225 | } |
226 | } | 226 | } |
227 | void ORecurranceWidget::setupRepeatLabel( const QString& s) { | 227 | void ORecurranceWidget::setupRepeatLabel( const QString& s) { |
228 | lblVar1->setText( s ); | 228 | lblVar1->setText( s ); |
229 | } | 229 | } |
230 | void ORecurranceWidget::setupRepeatLabel( int x) { | 230 | void ORecurranceWidget::setupRepeatLabel( int x) { |
231 | // change the spelling based on the value of x | 231 | // change the spelling based on the value of x |
232 | QString strVar2; | 232 | QString strVar2; |
233 | 233 | ||
234 | if ( x > 1 ) | 234 | if ( x > 1 ) |
235 | lblVar1->show(); | 235 | lblVar1->show(); |
236 | else | 236 | else |
237 | lblVar1->hide(); | 237 | lblVar1->hide(); |
238 | 238 | ||
239 | switch ( currInterval ) { | 239 | switch ( currInterval ) { |
240 | case None: | 240 | case None: |
241 | break; | 241 | break; |
242 | case Day: | 242 | case Day: |
243 | if ( x > 1 ) | 243 | if ( x > 1 ) |
244 | strVar2 = tr( "days" ); | 244 | strVar2 = tr( "days" ); |
245 | else | 245 | else |
246 | strVar2 = tr( "day" ); | 246 | strVar2 = tr( "day" ); |
247 | break; | 247 | break; |
248 | case Week: | 248 | case Week: |
249 | if ( x > 1 ) | 249 | if ( x > 1 ) |
250 | strVar2 = tr( "weeks" ); | 250 | strVar2 = tr( "weeks" ); |
251 | else | 251 | else |
252 | strVar2 = tr( "week" ); | 252 | strVar2 = tr( "week" ); |
253 | break; | 253 | break; |
254 | case Month: | 254 | case Month: |
255 | if ( x > 1 ) | 255 | if ( x > 1 ) |
256 | strVar2 = tr( "months" ); | 256 | strVar2 = tr( "months" ); |
257 | else | 257 | else |
258 | strVar2 = tr( "month" ); | 258 | strVar2 = tr( "month" ); |
259 | break; | 259 | break; |
260 | case Year: | 260 | case Year: |
261 | if ( x > 1 ) | 261 | if ( x > 1 ) |
262 | strVar2 = tr( "years" ); | 262 | strVar2 = tr( "years" ); |
263 | else | 263 | else |
264 | strVar2 = tr( "year" ); | 264 | strVar2 = tr( "year" ); |
265 | break; | 265 | break; |
266 | } | 266 | } |
267 | if ( !strVar2.isNull() ) | 267 | if ( !strVar2.isNull() ) |
268 | lblVar2->setText( strVar2 ); | 268 | lblVar2->setText( strVar2 ); |
269 | } | 269 | } |
270 | void ORecurranceWidget::slotWeekLabel() { | 270 | void ORecurranceWidget::slotWeekLabel() { |
271 | QString str; | 271 | QString str; |
272 | QListIterator<QToolButton> it( listExtra ); | 272 | QListIterator<QToolButton> it( listExtra ); |
273 | unsigned int i; | 273 | unsigned int i; |
274 | unsigned int keepMe; | 274 | unsigned int keepMe; |
275 | bool bNeedCarriage = FALSE; | 275 | bool bNeedCarriage = FALSE; |
276 | // don't do something we'll regret!!! | 276 | // don't do something we'll regret!!! |
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 | |||
@@ -1,173 +1,182 @@ | |||
1 | /* | 1 | /* |
2 | * VCard Backend for the OPIE-Contact Database. | 2 | * VCard Backend for the OPIE-Contact Database. |
3 | * | 3 | * |
4 | * Copyright (C) 2000 Trolltech AS. All rights reserved. | 4 | * Copyright (C) 2000 Trolltech AS. All rights reserved. |
5 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) | 5 | * Copyright (c) 2002 by Stefan Eilers (Eilers.Stefan@epost.de) |
6 | * | 6 | * |
7 | * ===================================================================== | 7 | * ===================================================================== |
8 | *This program is free software; you can redistribute it and/or | 8 | *This program is free software; you can redistribute it and/or |
9 | *modify it under the terms of the GNU Library General Public | 9 | *modify it under the terms of the GNU Library General Public |
10 | * License as published by the Free Software Foundation; either | 10 | * License as published by the Free Software Foundation; either |
11 | * version 2 of the License, or (at your option) any later version. | 11 | * version 2 of the License, or (at your option) any later version. |
12 | * ===================================================================== | 12 | * ===================================================================== |
13 | * ToDo: | 13 | * ToDo: |
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.. |
26 | * | 35 | * |
27 | * as a temp I check that it's not equal to HOME|VOICE|CELL before setting the | 36 | * as a temp I check that it's not equal to HOME|VOICE|CELL before setting the |
28 | * number | 37 | * number |
29 | * | 38 | * |
30 | * The right and final fix would be to reorder the if statement to make it | 39 | * The right and final fix would be to reorder the if statement to make it |
31 | * if else based and the less common thing put to the bottom | 40 | * if else based and the less common thing put to the bottom |
32 | * | 41 | * |
33 | * OTodoAccessVcal fix the date for beaming | 42 | * OTodoAccessVcal fix the date for beaming |
34 | * | 43 | * |
35 | * Revision 1.6 2003/01/13 15:49:31 eilers | 44 | * Revision 1.6 2003/01/13 15:49:31 eilers |
36 | * Fixing crash when businesscard.vcf is missing.. | 45 | * Fixing crash when businesscard.vcf is missing.. |
37 | * | 46 | * |
38 | * Revision 1.5 2002/12/07 13:26:22 eilers | 47 | * Revision 1.5 2002/12/07 13:26:22 eilers |
39 | * Fixing bug in storing anniversary.. | 48 | * Fixing bug in storing anniversary.. |
40 | * | 49 | * |
41 | * Revision 1.4 2002/11/13 14:14:51 eilers | 50 | * Revision 1.4 2002/11/13 14:14:51 eilers |
42 | * Added sorted for Contacts.. | 51 | * Added sorted for Contacts.. |
43 | * | 52 | * |
44 | * Revision 1.3 2002/11/11 16:41:09 kergoth | 53 | * Revision 1.3 2002/11/11 16:41:09 kergoth |
45 | * no default arguments in implementation | 54 | * no default arguments in implementation |
46 | * | 55 | * |
47 | * Revision 1.2 2002/11/10 15:41:53 eilers | 56 | * Revision 1.2 2002/11/10 15:41:53 eilers |
48 | * Bugfixes.. | 57 | * Bugfixes.. |
49 | * | 58 | * |
50 | * Revision 1.1 2002/11/09 14:34:52 eilers | 59 | * Revision 1.1 2002/11/09 14:34:52 eilers |
51 | * Added VCard Backend. | 60 | * Added VCard Backend. |
52 | * | 61 | * |
53 | */ | 62 | */ |
54 | #include "ocontactaccessbackend_vcard.h" | 63 | #include "ocontactaccessbackend_vcard.h" |
55 | #include "../../library/backend/vobject_p.h" | 64 | #include "../../library/backend/vobject_p.h" |
56 | #include "../../library/backend/qfiledirect_p.h" | 65 | #include "../../library/backend/qfiledirect_p.h" |
57 | 66 | ||
58 | #include <qpe/timeconversion.h> | 67 | #include <qpe/timeconversion.h> |
59 | 68 | ||
60 | #include <qfile.h> | 69 | #include <qfile.h> |
61 | 70 | ||
62 | OContactAccessBackend_VCard::OContactAccessBackend_VCard ( QString , QString filename ): | 71 | OContactAccessBackend_VCard::OContactAccessBackend_VCard ( QString , QString filename ): |
63 | m_dirty( false ), | 72 | m_dirty( false ), |
64 | m_file( filename ) | 73 | m_file( filename ) |
65 | { | 74 | { |
66 | load(); | 75 | load(); |
67 | } | 76 | } |
68 | 77 | ||
69 | 78 | ||
70 | bool OContactAccessBackend_VCard::load () | 79 | 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; |
84 | } | 93 | } |
85 | 94 | ||
86 | while ( obj ) { | 95 | while ( obj ) { |
87 | OContact con = parseVObject( obj ); | 96 | OContact con = parseVObject( obj ); |
88 | /* | 97 | /* |
89 | * if uid is 0 assign a new one | 98 | * if uid is 0 assign a new one |
90 | * this at least happens on | 99 | * this at least happens on |
91 | * Nokia6210 | 100 | * Nokia6210 |
92 | */ | 101 | */ |
93 | if ( con.uid() == 0 ){ | 102 | if ( con.uid() == 0 ){ |
94 | con.setUid( 1 ); | 103 | con.setUid( 1 ); |
95 | qWarning("assigned new uid %d",con.uid() ); | 104 | qWarning("assigned new uid %d",con.uid() ); |
96 | } | 105 | } |
97 | 106 | ||
98 | m_map.insert( con.uid(), con ); | 107 | m_map.insert( con.uid(), con ); |
99 | 108 | ||
100 | VObject *t = obj; | 109 | VObject *t = obj; |
101 | obj = nextVObjectInList(obj); | 110 | obj = nextVObjectInList(obj); |
102 | cleanVObject( t ); | 111 | cleanVObject( t ); |
103 | } | 112 | } |
104 | 113 | ||
105 | return true; | 114 | return true; |
106 | 115 | ||
107 | } | 116 | } |
108 | bool OContactAccessBackend_VCard::reload() | 117 | bool OContactAccessBackend_VCard::reload() |
109 | { | 118 | { |
110 | return load(); | 119 | return load(); |
111 | } | 120 | } |
112 | bool OContactAccessBackend_VCard::save() | 121 | bool OContactAccessBackend_VCard::save() |
113 | { | 122 | { |
114 | if (!m_dirty ) | 123 | if (!m_dirty ) |
115 | return true; | 124 | return true; |
116 | 125 | ||
117 | QFileDirect file( m_file ); | 126 | QFileDirect file( m_file ); |
118 | if (!file.open(IO_WriteOnly ) ) | 127 | if (!file.open(IO_WriteOnly ) ) |
119 | return false; | 128 | return false; |
120 | 129 | ||
121 | VObject *obj; | 130 | VObject *obj; |
122 | obj = newVObject( VCCalProp ); | 131 | obj = newVObject( VCCalProp ); |
123 | addPropValue( obj, VCVersionProp, "1.0" ); | 132 | addPropValue( obj, VCVersionProp, "1.0" ); |
124 | 133 | ||
125 | VObject *vo; | 134 | VObject *vo; |
126 | for(QMap<int, OContact>::ConstIterator it=m_map.begin(); it !=m_map.end(); ++it ){ | 135 | for(QMap<int, OContact>::ConstIterator it=m_map.begin(); it !=m_map.end(); ++it ){ |
127 | vo = createVObject( *it ); | 136 | vo = createVObject( *it ); |
128 | writeVObject( file.directHandle() , vo ); | 137 | writeVObject( file.directHandle() , vo ); |
129 | cleanVObject( vo ); | 138 | cleanVObject( vo ); |
130 | } | 139 | } |
131 | cleanStrTbl(); | 140 | cleanStrTbl(); |
132 | 141 | ||
133 | m_dirty = false; | 142 | m_dirty = false; |
134 | return true; | 143 | return true; |
135 | 144 | ||
136 | 145 | ||
137 | } | 146 | } |
138 | void OContactAccessBackend_VCard::clear () | 147 | void OContactAccessBackend_VCard::clear () |
139 | { | 148 | { |
140 | m_map.clear(); | 149 | m_map.clear(); |
141 | m_dirty = true; // ??? sure ? (se) | 150 | m_dirty = true; // ??? sure ? (se) |
142 | } | 151 | } |
143 | 152 | ||
144 | bool OContactAccessBackend_VCard::add ( const OContact& newcontact ) | 153 | bool OContactAccessBackend_VCard::add ( const OContact& newcontact ) |
145 | { | 154 | { |
146 | m_map.insert( newcontact.uid(), newcontact ); | 155 | m_map.insert( newcontact.uid(), newcontact ); |
147 | m_dirty = true; | 156 | m_dirty = true; |
148 | return true; | 157 | return true; |
149 | } | 158 | } |
150 | 159 | ||
151 | bool OContactAccessBackend_VCard::remove ( int uid ) | 160 | bool OContactAccessBackend_VCard::remove ( int uid ) |
152 | { | 161 | { |
153 | m_map.remove( uid ); | 162 | m_map.remove( uid ); |
154 | m_dirty = true; | 163 | m_dirty = true; |
155 | return true; | 164 | return true; |
156 | } | 165 | } |
157 | 166 | ||
158 | bool OContactAccessBackend_VCard::replace ( const OContact &contact ) | 167 | bool OContactAccessBackend_VCard::replace ( const OContact &contact ) |
159 | { | 168 | { |
160 | m_map.replace( contact.uid(), contact ); | 169 | m_map.replace( contact.uid(), contact ); |
161 | m_dirty = true; | 170 | m_dirty = true; |
162 | return true; | 171 | return true; |
163 | } | 172 | } |
164 | 173 | ||
165 | OContact OContactAccessBackend_VCard::find ( int uid ) const | 174 | OContact OContactAccessBackend_VCard::find ( int uid ) const |
166 | { | 175 | { |
167 | return m_map[uid]; | 176 | return m_map[uid]; |
168 | } | 177 | } |
169 | 178 | ||
170 | QArray<int> OContactAccessBackend_VCard::allRecords() const | 179 | QArray<int> OContactAccessBackend_VCard::allRecords() const |
171 | { | 180 | { |
172 | QArray<int> ar( m_map.count() ); | 181 | QArray<int> ar( m_map.count() ); |
173 | QMap<int, OContact>::ConstIterator it; | 182 | QMap<int, OContact>::ConstIterator it; |
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 | |||
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/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 | |||
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/libopie/pim/orecur.cpp b/libopie/pim/orecur.cpp index daf3506..e6a4787 100644 --- a/libopie/pim/orecur.cpp +++ b/libopie/pim/orecur.cpp | |||
@@ -1,150 +1,152 @@ | |||
1 | #include <qshared.h> | 1 | #include <qshared.h> |
2 | 2 | ||
3 | #include <qtopia/timeconversion.h> | 3 | #include <qtopia/timeconversion.h> |
4 | 4 | ||
5 | #include "orecur.h" | 5 | #include "orecur.h" |
6 | 6 | ||
7 | struct ORecur::Data : public QShared { | 7 | struct 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 | ||
30 | 30 | ||
31 | ORecur::ORecur() { | 31 | ORecur::ORecur() { |
32 | data = new Data; | 32 | data = new Data; |
33 | } | 33 | } |
34 | ORecur::ORecur( const ORecur& rec) | 34 | ORecur::ORecur( const ORecur& rec) |
35 | : data( rec.data ) | 35 | : data( rec.data ) |
36 | { | 36 | { |
37 | data->ref(); | 37 | data->ref(); |
38 | } | 38 | } |
39 | ORecur::~ORecur() { | 39 | ORecur::~ORecur() { |
40 | if ( data->deref() ) { | 40 | if ( data->deref() ) { |
41 | delete data; | 41 | delete data; |
42 | data = 0l; | 42 | data = 0l; |
43 | } | 43 | } |
44 | } | 44 | } |
45 | void ORecur::deref() { | 45 | void ORecur::deref() { |
46 | if ( data->deref() ) { | 46 | if ( data->deref() ) { |
47 | delete data; | 47 | delete data; |
48 | data = 0l; | 48 | data = 0l; |
49 | } | 49 | } |
50 | } | 50 | } |
51 | bool ORecur::operator==( const ORecur& )const { | 51 | bool ORecur::operator==( const ORecur& )const { |
52 | return false; | 52 | return false; |
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(); |
57 | data = re.data; | 59 | data = re.data; |
58 | 60 | ||
59 | return *this; | 61 | return *this; |
60 | } | 62 | } |
61 | bool ORecur::doesRecur()const { | 63 | bool ORecur::doesRecur()const { |
62 | return !( type() == NoRepeat ); | 64 | return !( type() == NoRepeat ); |
63 | } | 65 | } |
64 | /* | 66 | /* |
65 | * we try to be smart here | 67 | * we try to be smart here |
66 | * | 68 | * |
67 | */ | 69 | */ |
68 | bool ORecur::doesRecur( const QDate& date ) { | 70 | bool ORecur::doesRecur( const QDate& date ) { |
69 | /* the day before the recurrance */ | 71 | /* the day before the recurrance */ |
70 | QDate da = date.addDays(-1); | 72 | QDate da = date.addDays(-1); |
71 | 73 | ||
72 | QDate recur; | 74 | QDate recur; |
73 | if (!nextOcurrence( da, recur ) ) | 75 | if (!nextOcurrence( da, recur ) ) |
74 | return false; | 76 | return false; |
75 | 77 | ||
76 | return (recur == date); | 78 | return (recur == date); |
77 | } | 79 | } |
78 | // FIXME unuglify! | 80 | // FIXME unuglify! |
79 | // GPL from Datebookdb.cpp | 81 | // GPL from Datebookdb.cpp |
80 | // FIXME exception list! | 82 | // FIXME exception list! |
81 | bool ORecur::nextOcurrence( const QDate& from, QDate& next ) { | 83 | bool ORecur::nextOcurrence( const QDate& from, QDate& next ) { |
82 | 84 | ||
83 | // easy checks, first are we too far in the future or too far in the past? | 85 | // easy checks, first are we too far in the future or too far in the past? |
84 | QDate tmpDate; | 86 | QDate tmpDate; |
85 | int freq = frequency(); | 87 | int freq = frequency(); |
86 | int diff, diff2, a; | 88 | int diff, diff2, a; |
87 | int iday, imonth, iyear; | 89 | int iday, imonth, iyear; |
88 | int dayOfWeek = 0; | 90 | int dayOfWeek = 0; |
89 | int firstOfWeek = 0; | 91 | int firstOfWeek = 0; |
90 | int weekOfMonth; | 92 | int weekOfMonth; |
91 | 93 | ||
92 | 94 | ||
93 | if (hasEndDate() && endDate() < from) | 95 | if (hasEndDate() && endDate() < from) |
94 | return FALSE; | 96 | return FALSE; |
95 | 97 | ||
96 | if (start() >= from) { | 98 | if (start() >= from) { |
97 | next = start(); | 99 | next = start(); |
98 | return TRUE; | 100 | return TRUE; |
99 | } | 101 | } |
100 | 102 | ||
101 | switch ( type() ) { | 103 | switch ( type() ) { |
102 | case Weekly: | 104 | case Weekly: |
103 | /* weekly is just daily by 7 */ | 105 | /* weekly is just daily by 7 */ |
104 | /* first convert the repeatPattern.Days() mask to the next | 106 | /* first convert the repeatPattern.Days() mask to the next |
105 | day of week valid after from */ | 107 | day of week valid after from */ |
106 | dayOfWeek = from.dayOfWeek(); | 108 | dayOfWeek = from.dayOfWeek(); |
107 | dayOfWeek--; /* we want 0-6, doco for above specs 1-7 */ | 109 | dayOfWeek--; /* we want 0-6, doco for above specs 1-7 */ |
108 | 110 | ||
109 | /* this is done in case freq > 1 and from in week not | 111 | /* this is done in case freq > 1 and from in week not |
110 | for this round */ | 112 | for this round */ |
111 | // firstOfWeek = 0; this is already done at decl. | 113 | // firstOfWeek = 0; this is already done at decl. |
112 | while(!((1 << firstOfWeek) & days() )) | 114 | while(!((1 << firstOfWeek) & days() )) |
113 | firstOfWeek++; | 115 | firstOfWeek++; |
114 | 116 | ||
115 | /* there is at least one 'day', or there would be no event */ | 117 | /* there is at least one 'day', or there would be no event */ |
116 | while(!((1 << (dayOfWeek % 7)) & days() )) | 118 | while(!((1 << (dayOfWeek % 7)) & days() )) |
117 | dayOfWeek++; | 119 | dayOfWeek++; |
118 | 120 | ||
119 | dayOfWeek = dayOfWeek % 7; /* the actual day of week */ | 121 | dayOfWeek = dayOfWeek % 7; /* the actual day of week */ |
120 | dayOfWeek -= start().dayOfWeek() -1; | 122 | dayOfWeek -= start().dayOfWeek() -1; |
121 | 123 | ||
122 | firstOfWeek = firstOfWeek % 7; /* the actual first of week */ | 124 | firstOfWeek = firstOfWeek % 7; /* the actual first of week */ |
123 | firstOfWeek -= start().dayOfWeek() -1; | 125 | firstOfWeek -= start().dayOfWeek() -1; |
124 | 126 | ||
125 | // dayOfWeek may be negitive now | 127 | // dayOfWeek may be negitive now |
126 | // day of week is number of days to add to start day | 128 | // day of week is number of days to add to start day |
127 | 129 | ||
128 | freq *= 7; | 130 | freq *= 7; |
129 | // FALL-THROUGH !!!!! | 131 | // FALL-THROUGH !!!!! |
130 | case Daily: | 132 | case Daily: |
131 | // the add is for the possible fall through from weekly */ | 133 | // the add is for the possible fall through from weekly */ |
132 | if(start().addDays(dayOfWeek) > from) { | 134 | if(start().addDays(dayOfWeek) > from) { |
133 | /* first week exception */ | 135 | /* first week exception */ |
134 | next = QDate(start().addDays(dayOfWeek) ); | 136 | next = QDate(start().addDays(dayOfWeek) ); |
135 | if ((next > endDate()) | 137 | if ((next > endDate()) |
136 | && hasEndDate() ) | 138 | && hasEndDate() ) |
137 | return FALSE; | 139 | return FALSE; |
138 | return TRUE; | 140 | return TRUE; |
139 | } | 141 | } |
140 | /* if from is middle of a non-week */ | 142 | /* if from is middle of a non-week */ |
141 | 143 | ||
142 | diff = start().addDays(dayOfWeek).daysTo(from) % freq; | 144 | diff = start().addDays(dayOfWeek).daysTo(from) % freq; |
143 | diff2 = start().addDays(firstOfWeek).daysTo(from) % freq; | 145 | diff2 = start().addDays(firstOfWeek).daysTo(from) % freq; |
144 | 146 | ||
145 | if(diff != 0) | 147 | if(diff != 0) |
146 | diff = freq - diff; | 148 | diff = freq - diff; |
147 | if(diff2 != 0) | 149 | if(diff2 != 0) |
148 | diff2 = freq - diff2; | 150 | diff2 = freq - diff2; |
149 | diff = QMIN(diff, diff2); | 151 | diff = QMIN(diff, diff2); |
150 | 152 | ||
@@ -273,179 +275,172 @@ bool ORecur::nextOcurrence( const QDate& from, QDate& next ) { | |||
273 | /* done */ | 275 | /* done */ |
274 | next = QDate(iyear, imonth, iday); | 276 | next = QDate(iyear, imonth, iday); |
275 | if ((next > endDate()) && hasEndDate() ) | 277 | if ((next > endDate()) && hasEndDate() ) |
276 | return FALSE; | 278 | return FALSE; |
277 | return TRUE; | 279 | return TRUE; |
278 | } | 280 | } |
279 | 281 | ||
280 | /* ok, need to cycle */ | 282 | /* ok, need to cycle */ |
281 | imonth += freq; | 283 | imonth += freq; |
282 | imonth--; | 284 | imonth--; |
283 | iyear += imonth / 12; | 285 | iyear += imonth / 12; |
284 | imonth = imonth % 12; | 286 | imonth = imonth % 12; |
285 | imonth++; | 287 | imonth++; |
286 | 288 | ||
287 | while(!QDate::isValid(iyear, imonth, iday) ) { | 289 | while(!QDate::isValid(iyear, imonth, iday) ) { |
288 | imonth += freq; | 290 | imonth += freq; |
289 | imonth--; | 291 | imonth--; |
290 | iyear += imonth / 12; | 292 | iyear += imonth / 12; |
291 | imonth = imonth % 12; | 293 | imonth = imonth % 12; |
292 | imonth++; | 294 | imonth++; |
293 | if ((QDate(iyear, imonth, 1) > endDate()) && hasEndDate() ) | 295 | if ((QDate(iyear, imonth, 1) > endDate()) && hasEndDate() ) |
294 | return FALSE; | 296 | return FALSE; |
295 | } | 297 | } |
296 | 298 | ||
297 | next = QDate(iyear, imonth, iday); | 299 | next = QDate(iyear, imonth, iday); |
298 | if ((next > endDate()) && hasEndDate() ) | 300 | if ((next > endDate()) && hasEndDate() ) |
299 | return FALSE; | 301 | return FALSE; |
300 | return TRUE; | 302 | return TRUE; |
301 | case Yearly: | 303 | case Yearly: |
302 | iday = start().day(); | 304 | iday = start().day(); |
303 | imonth = start().month(); | 305 | imonth = start().month(); |
304 | iyear = from.year(); // after all, we want to start in this year | 306 | iyear = from.year(); // after all, we want to start in this year |
305 | 307 | ||
306 | diff = 1; | 308 | diff = 1; |
307 | if(imonth == 2 && iday > 28) { | 309 | if(imonth == 2 && iday > 28) { |
308 | /* leap year, and it counts, calculate actual frequency */ | 310 | /* leap year, and it counts, calculate actual frequency */ |
309 | if(freq % 4) | 311 | if(freq % 4) |
310 | if (freq % 2) | 312 | if (freq % 2) |
311 | freq = freq * 4; | 313 | freq = freq * 4; |
312 | else | 314 | else |
313 | freq = freq * 2; | 315 | freq = freq * 2; |
314 | /* else divides by 4 already, leave freq alone */ | 316 | /* else divides by 4 already, leave freq alone */ |
315 | diff = 4; | 317 | diff = 4; |
316 | } | 318 | } |
317 | 319 | ||
318 | a = from.year() - start().year(); | 320 | a = from.year() - start().year(); |
319 | if(a % freq) { | 321 | if(a % freq) { |
320 | a = freq - (a % freq); | 322 | a = freq - (a % freq); |
321 | iyear = iyear + a; | 323 | iyear = iyear + a; |
322 | } | 324 | } |
323 | 325 | ||
324 | /* under the assumption we won't hit one of the special not-leap years twice */ | 326 | /* under the assumption we won't hit one of the special not-leap years twice */ |
325 | if(!QDate::isValid(iyear, imonth, iday)) { | 327 | if(!QDate::isValid(iyear, imonth, iday)) { |
326 | /* must have been skipping by leap years and hit one that wasn't, (e.g. 2100) */ | 328 | /* must have been skipping by leap years and hit one that wasn't, (e.g. 2100) */ |
327 | iyear += freq; | 329 | iyear += freq; |
328 | } | 330 | } |
329 | 331 | ||
330 | if(QDate(iyear, imonth, iday) >= from) { | 332 | if(QDate(iyear, imonth, iday) >= from) { |
331 | next = QDate(iyear, imonth, iday); | 333 | next = QDate(iyear, imonth, iday); |
332 | 334 | ||
333 | if ((next > endDate()) && hasEndDate() ) | 335 | if ((next > endDate()) && hasEndDate() ) |
334 | return FALSE; | 336 | return FALSE; |
335 | return TRUE; | 337 | return TRUE; |
336 | } | 338 | } |
337 | /* iyear == from.year(), need to advance again */ | 339 | /* iyear == from.year(), need to advance again */ |
338 | iyear += freq; | 340 | iyear += freq; |
339 | /* under the assumption we won't hit one of the special not-leap years twice */ | 341 | /* under the assumption we won't hit one of the special not-leap years twice */ |
340 | if(!QDate::isValid(iyear, imonth, iday)) { | 342 | if(!QDate::isValid(iyear, imonth, iday)) { |
341 | /* must have been skipping by leap years and hit one that wasn't, (e.g. 2100) */ | 343 | /* must have been skipping by leap years and hit one that wasn't, (e.g. 2100) */ |
342 | iyear += freq; | 344 | iyear += freq; |
343 | } | 345 | } |
344 | 346 | ||
345 | next = QDate(iyear, imonth, iday); | 347 | next = QDate(iyear, imonth, iday); |
346 | if ((next > endDate()) && hasEndDate() ) | 348 | if ((next > endDate()) && hasEndDate() ) |
347 | return FALSE; | 349 | return FALSE; |
348 | return TRUE; | 350 | return TRUE; |
349 | default: | 351 | default: |
350 | return FALSE; | 352 | return FALSE; |
351 | } | 353 | } |
352 | } | 354 | } |
353 | ORecur::RepeatType ORecur::type()const{ | 355 | ORecur::RepeatType ORecur::type()const{ |
354 | return data->type; | 356 | return data->type; |
355 | } | 357 | } |
356 | int ORecur::frequency()const { | 358 | int ORecur::frequency()const { |
357 | return data->freq; | 359 | return data->freq; |
358 | } | 360 | } |
359 | int ORecur::position()const { | 361 | int ORecur::position()const { |
360 | return data->pos; | 362 | return data->pos; |
361 | } | 363 | } |
362 | char ORecur::days() const{ | 364 | char ORecur::days() const{ |
363 | return data->days; | 365 | return data->days; |
364 | } | 366 | } |
365 | bool ORecur::hasEndDate()const { | 367 | bool ORecur::hasEndDate()const { |
366 | return data->hasEnd; | 368 | return data->hasEnd; |
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 | } |
380 | int ORecur::repetition()const { | 379 | int ORecur::repetition()const { |
381 | return data->rep; | 380 | return data->rep; |
382 | } | 381 | } |
383 | QString ORecur::service()const { | 382 | QString ORecur::service()const { |
384 | return data->app; | 383 | return data->app; |
385 | } | 384 | } |
386 | ORecur::ExceptionList& ORecur::exceptions() { | 385 | ORecur::ExceptionList& ORecur::exceptions() { |
387 | return data->list; | 386 | return data->list; |
388 | } | 387 | } |
389 | void ORecur::setType( const RepeatType& z) { | 388 | void ORecur::setType( const RepeatType& z) { |
390 | checkOrModify(); | 389 | checkOrModify(); |
391 | data->type = z; | 390 | data->type = z; |
392 | } | 391 | } |
393 | void ORecur::setFrequency( int freq ) { | 392 | void ORecur::setFrequency( int freq ) { |
394 | checkOrModify(); | 393 | checkOrModify(); |
395 | data->freq = freq; | 394 | data->freq = freq; |
396 | } | 395 | } |
397 | void ORecur::setPosition( int pos ) { | 396 | void ORecur::setPosition( int pos ) { |
398 | checkOrModify(); | 397 | checkOrModify(); |
399 | data->pos = pos; | 398 | data->pos = pos; |
400 | } | 399 | } |
401 | void ORecur::setDays( char c ) { | 400 | void ORecur::setDays( char c ) { |
402 | checkOrModify(); | 401 | checkOrModify(); |
403 | data->days = c; | 402 | data->days = c; |
404 | } | 403 | } |
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; |
416 | } | 411 | } |
417 | void ORecur::setHasEndDate( bool b) { | 412 | void ORecur::setHasEndDate( bool b) { |
418 | checkOrModify(); | 413 | checkOrModify(); |
419 | data->hasEnd = b; | 414 | data->hasEnd = b; |
420 | } | 415 | } |
421 | void ORecur::setRepitition( int rep ) { | 416 | void ORecur::setRepitition( int rep ) { |
422 | checkOrModify(); | 417 | checkOrModify(); |
423 | data->rep = rep; | 418 | data->rep = rep; |
424 | } | 419 | } |
425 | void ORecur::setService( const QString& app ) { | 420 | void ORecur::setService( const QString& app ) { |
426 | checkOrModify(); | 421 | checkOrModify(); |
427 | data->app = app; | 422 | data->app = app; |
428 | } | 423 | } |
429 | void ORecur::setStart( const QDate& dt ) { | 424 | void ORecur::setStart( const QDate& dt ) { |
430 | checkOrModify(); | 425 | checkOrModify(); |
431 | data->start = dt; | 426 | data->start = dt; |
432 | } | 427 | } |
433 | void ORecur::checkOrModify() { | 428 | void ORecur::checkOrModify() { |
434 | if ( data->count != 1 ) { | 429 | if ( data->count != 1 ) { |
435 | data->deref(); | 430 | data->deref(); |
436 | Data* d2 = new Data; | 431 | Data* d2 = new Data; |
437 | d2->days = data->days; | 432 | d2->days = data->days; |
438 | d2->type = data->type; | 433 | d2->type = data->type; |
439 | d2->freq = data->freq; | 434 | d2->freq = data->freq; |
440 | d2->pos = data->pos; | 435 | d2->pos = data->pos; |
441 | d2->hasEnd = data->hasEnd; | 436 | d2->hasEnd = data->hasEnd; |
442 | d2->end = data->end; | 437 | d2->end = data->end; |
443 | d2->create = data->create; | 438 | d2->create = data->create; |
444 | d2->rep = data->rep; | 439 | d2->rep = data->rep; |
445 | d2->app = data->app; | 440 | d2->app = data->app; |
446 | d2->list = data->list; | 441 | d2->list = data->list; |
447 | d2->start = data->start; | 442 | d2->start = data->start; |
448 | data = d2; | 443 | data = d2; |
449 | } | 444 | } |
450 | } | 445 | } |
451 | 446 | ||
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 | |||
@@ -1,83 +1,87 @@ | |||
1 | /* | 1 | /* |
2 | * GPL from TT | 2 | * GPL from TT |
3 | */ | 3 | */ |
4 | 4 | ||
5 | #ifndef OPIE_RECUR_H | 5 | #ifndef OPIE_RECUR_H |
6 | #define OPIE_RECUR_H | 6 | #define OPIE_RECUR_H |
7 | 7 | ||
8 | #include <sys/types.h> | 8 | #include <sys/types.h> |
9 | 9 | ||
10 | #include <qdatetime.h> | 10 | #include <qdatetime.h> |
11 | #include <qvaluelist.h> | 11 | #include <qvaluelist.h> |
12 | 12 | ||
13 | 13 | ||
14 | class ORecur { | 14 | class ORecur { |
15 | public: | 15 | public: |
16 | typedef QValueList<QDate> ExceptionList; | 16 | typedef QValueList<QDate> ExceptionList; |
17 | enum RepeatType{ NoRepeat = -1, Daily, Weekly, MonthlyDay, | 17 | enum RepeatType{ NoRepeat = -1, Daily, Weekly, MonthlyDay, |
18 | MonthlyDate, Yearly }; | 18 | MonthlyDate, Yearly }; |
19 | enum Days { MON = 0x01, TUE = 0x02, WED = 0x04, THU = 0x08, | 19 | enum Days { MON = 0x01, TUE = 0x02, WED = 0x04, THU = 0x08, |
20 | FRI = 0x10, SAT = 0x20, SUN = 0x40 }; | 20 | FRI = 0x10, SAT = 0x20, SUN = 0x40 }; |
21 | ORecur(); | 21 | ORecur(); |
22 | ORecur( const ORecur& ); | 22 | ORecur( const ORecur& ); |
23 | ~ORecur(); | 23 | ~ORecur(); |
24 | 24 | ||
25 | ORecur &operator=( const ORecur& ); | 25 | ORecur &operator=( const ORecur& ); |
26 | bool operator==(const ORecur& )const; | 26 | bool operator==(const ORecur& )const; |
27 | 27 | ||
28 | bool doesRecur()const; | 28 | bool doesRecur()const; |
29 | /* if it recurrs on that day */ | 29 | /* if it recurrs on that day */ |
30 | bool doesRecur( const QDate& ); | 30 | bool doesRecur( const QDate& ); |
31 | RepeatType type()const; | 31 | RepeatType type()const; |
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 | /* |
51 | * reference to the exception list | 56 | * reference to the exception list |
52 | */ | 57 | */ |
53 | ExceptionList &exceptions(); | 58 | ExceptionList &exceptions(); |
54 | 59 | ||
55 | /** | 60 | /** |
56 | * the current repetition | 61 | * the current repetition |
57 | */ | 62 | */ |
58 | int repetition()const; | 63 | int repetition()const; |
59 | 64 | ||
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 ); |
72 | private: | 76 | private: |
73 | void deref(); | 77 | void deref(); |
74 | inline void checkOrModify(); | 78 | inline void checkOrModify(); |
75 | 79 | ||
76 | 80 | ||
77 | class Data; | 81 | class Data; |
78 | Data* data; | 82 | Data* data; |
79 | class ORecurPrivate; | 83 | class ORecurPrivate; |
80 | ORecurPrivate *d; | 84 | ORecurPrivate *d; |
81 | }; | 85 | }; |
82 | 86 | ||
83 | #endif | 87 | #endif |
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 | |||
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/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 | */ | ||
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/libopie/pim/otodo.cpp b/libopie/pim/otodo.cpp index b4d4aa9..049359e 100644 --- a/libopie/pim/otodo.cpp +++ b/libopie/pim/otodo.cpp | |||
@@ -247,176 +247,178 @@ QString OTodo::toRichText() const | |||
247 | text += "<b>" + QObject::tr( "Priority:") +" </b>" | 247 | text += "<b>" + QObject::tr( "Priority:") +" </b>" |
248 | + QString::number( priority() ) + " <br>"; | 248 | + QString::number( priority() ) + " <br>"; |
249 | text += "<b>" + QObject::tr( "Progress:") + " </b>" | 249 | text += "<b>" + QObject::tr( "Progress:") + " </b>" |
250 | + QString::number( progress() ) + " %<br>"; | 250 | + QString::number( progress() ) + " %<br>"; |
251 | if (hasDueDate() ){ | 251 | if (hasDueDate() ){ |
252 | text += "<b>" + QObject::tr( "Deadline:") + " </b>"; | 252 | text += "<b>" + QObject::tr( "Deadline:") + " </b>"; |
253 | text += dueDate().toString(); | 253 | text += dueDate().toString(); |
254 | text += "<br>"; | 254 | text += "<br>"; |
255 | } | 255 | } |
256 | 256 | ||
257 | text += "<b>" + QObject::tr( "Category:") + "</b> "; | 257 | text += "<b>" + QObject::tr( "Category:") + "</b> "; |
258 | text += categoryNames( "Todo List" ).join(", "); | 258 | text += categoryNames( "Todo List" ).join(", "); |
259 | text += "<br>"; | 259 | text += "<br>"; |
260 | 260 | ||
261 | return text; | 261 | return text; |
262 | } | 262 | } |
263 | OPimNotifyManager& OTodo::notifiers() { | 263 | OPimNotifyManager& OTodo::notifiers() { |
264 | return data->notifiers; | 264 | return data->notifiers; |
265 | } | 265 | } |
266 | 266 | ||
267 | bool OTodo::operator<( const OTodo &toDoEvent )const{ | 267 | bool OTodo::operator<( const OTodo &toDoEvent )const{ |
268 | if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; | 268 | if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; |
269 | if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; | 269 | if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; |
270 | if( hasDueDate() && toDoEvent.hasDueDate() ){ | 270 | if( hasDueDate() && toDoEvent.hasDueDate() ){ |
271 | if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide | 271 | if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide |
272 | return priority() < toDoEvent.priority(); | 272 | return priority() < toDoEvent.priority(); |
273 | }else{ | 273 | }else{ |
274 | return dueDate() < toDoEvent.dueDate(); | 274 | return dueDate() < toDoEvent.dueDate(); |
275 | } | 275 | } |
276 | } | 276 | } |
277 | return false; | 277 | return false; |
278 | } | 278 | } |
279 | bool OTodo::operator<=(const OTodo &toDoEvent )const | 279 | bool OTodo::operator<=(const OTodo &toDoEvent )const |
280 | { | 280 | { |
281 | if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; | 281 | if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; |
282 | if( !hasDueDate() && toDoEvent.hasDueDate() ) return true; | 282 | if( !hasDueDate() && toDoEvent.hasDueDate() ) return true; |
283 | if( hasDueDate() && toDoEvent.hasDueDate() ){ | 283 | if( hasDueDate() && toDoEvent.hasDueDate() ){ |
284 | if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide | 284 | if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide |
285 | return priority() <= toDoEvent.priority(); | 285 | return priority() <= toDoEvent.priority(); |
286 | }else{ | 286 | }else{ |
287 | return dueDate() <= toDoEvent.dueDate(); | 287 | return dueDate() <= toDoEvent.dueDate(); |
288 | } | 288 | } |
289 | } | 289 | } |
290 | return true; | 290 | return true; |
291 | } | 291 | } |
292 | bool OTodo::operator>(const OTodo &toDoEvent )const | 292 | bool OTodo::operator>(const OTodo &toDoEvent )const |
293 | { | 293 | { |
294 | if( !hasDueDate() && !toDoEvent.hasDueDate() ) return false; | 294 | if( !hasDueDate() && !toDoEvent.hasDueDate() ) return false; |
295 | if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; | 295 | if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; |
296 | if( hasDueDate() && toDoEvent.hasDueDate() ){ | 296 | if( hasDueDate() && toDoEvent.hasDueDate() ){ |
297 | if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide | 297 | if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide |
298 | return priority() > toDoEvent.priority(); | 298 | return priority() > toDoEvent.priority(); |
299 | }else{ | 299 | }else{ |
300 | return dueDate() > toDoEvent.dueDate(); | 300 | return dueDate() > toDoEvent.dueDate(); |
301 | } | 301 | } |
302 | } | 302 | } |
303 | return false; | 303 | return false; |
304 | } | 304 | } |
305 | bool OTodo::operator>=(const OTodo &toDoEvent )const | 305 | bool OTodo::operator>=(const OTodo &toDoEvent )const |
306 | { | 306 | { |
307 | if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; | 307 | if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; |
308 | if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; | 308 | if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; |
309 | if( hasDueDate() && toDoEvent.hasDueDate() ){ | 309 | if( hasDueDate() && toDoEvent.hasDueDate() ){ |
310 | if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide | 310 | if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide |
311 | return priority() > toDoEvent.priority(); | 311 | return priority() > toDoEvent.priority(); |
312 | }else{ | 312 | }else{ |
313 | return dueDate() > toDoEvent.dueDate(); | 313 | return dueDate() > toDoEvent.dueDate(); |
314 | } | 314 | } |
315 | } | 315 | } |
316 | return true; | 316 | return true; |
317 | } | 317 | } |
318 | bool OTodo::operator==(const OTodo &toDoEvent )const | 318 | bool OTodo::operator==(const OTodo &toDoEvent )const |
319 | { | 319 | { |
320 | if ( data->priority != toDoEvent.data->priority ) return false; | 320 | if ( data->priority != toDoEvent.data->priority ) return false; |
321 | if ( data->priority != toDoEvent.data->prog ) return false; | 321 | if ( data->priority != toDoEvent.data->prog ) return false; |
322 | if ( data->isCompleted != toDoEvent.data->isCompleted ) return false; | 322 | if ( data->isCompleted != toDoEvent.data->isCompleted ) return false; |
323 | if ( data->hasDate != toDoEvent.data->hasDate ) return false; | 323 | if ( data->hasDate != toDoEvent.data->hasDate ) return false; |
324 | if ( data->date != toDoEvent.data->date ) return false; | 324 | if ( data->date != toDoEvent.data->date ) return false; |
325 | if ( data->sum != toDoEvent.data->sum ) return false; | 325 | if ( data->sum != toDoEvent.data->sum ) return false; |
326 | if ( data->desc != toDoEvent.data->desc ) return false; | 326 | if ( data->desc != toDoEvent.data->desc ) return false; |
327 | if ( data->maintainer != toDoEvent.data->maintainer ) | 327 | if ( data->maintainer != toDoEvent.data->maintainer ) |
328 | return false; | 328 | return false; |
329 | 329 | ||
330 | return OPimRecord::operator==( toDoEvent ); | 330 | return OPimRecord::operator==( toDoEvent ); |
331 | } | 331 | } |
332 | void OTodo::deref() { | 332 | void OTodo::deref() { |
333 | 333 | ||
334 | // qWarning("deref in ToDoEvent"); | 334 | // qWarning("deref in ToDoEvent"); |
335 | if ( data->deref() ) { | 335 | if ( data->deref() ) { |
336 | // qWarning("deleting"); | 336 | // qWarning("deleting"); |
337 | delete data; | 337 | delete data; |
338 | data= 0; | 338 | data= 0; |
339 | } | 339 | } |
340 | } | 340 | } |
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 "); |
345 | item.data->ref(); | 347 | item.data->ref(); |
346 | deref(); | 348 | deref(); |
347 | data = item.data; | 349 | data = item.data; |
348 | 350 | ||
349 | return *this; | 351 | return *this; |
350 | } | 352 | } |
351 | 353 | ||
352 | QMap<int, QString> OTodo::toMap() const { | 354 | QMap<int, QString> OTodo::toMap() const { |
353 | QMap<int, QString> map; | 355 | QMap<int, QString> map; |
354 | 356 | ||
355 | map.insert( Uid, QString::number( uid() ) ); | 357 | map.insert( Uid, QString::number( uid() ) ); |
356 | map.insert( Category, idsToString( categories() ) ); | 358 | map.insert( Category, idsToString( categories() ) ); |
357 | map.insert( HasDate, QString::number( data->hasDate ) ); | 359 | map.insert( HasDate, QString::number( data->hasDate ) ); |
358 | map.insert( Completed, QString::number( data->isCompleted ) ); | 360 | map.insert( Completed, QString::number( data->isCompleted ) ); |
359 | map.insert( Description, data->desc ); | 361 | map.insert( Description, data->desc ); |
360 | map.insert( Summary, data->sum ); | 362 | map.insert( Summary, data->sum ); |
361 | map.insert( Priority, QString::number( data->priority ) ); | 363 | map.insert( Priority, QString::number( data->priority ) ); |
362 | map.insert( DateDay, QString::number( data->date.day() ) ); | 364 | map.insert( DateDay, QString::number( data->date.day() ) ); |
363 | map.insert( DateMonth, QString::number( data->date.month() ) ); | 365 | map.insert( DateMonth, QString::number( data->date.month() ) ); |
364 | map.insert( DateYear, QString::number( data->date.year() ) ); | 366 | map.insert( DateYear, QString::number( data->date.year() ) ); |
365 | map.insert( Progress, QString::number( data->prog ) ); | 367 | map.insert( Progress, QString::number( data->prog ) ); |
366 | // map.insert( CrossReference, crossToString() ); | 368 | // map.insert( CrossReference, crossToString() ); |
367 | /* FIXME!!! map.insert( State, ); | 369 | /* FIXME!!! map.insert( State, ); |
368 | map.insert( Recurrence, ); | 370 | map.insert( Recurrence, ); |
369 | map.insert( Reminders, ); | 371 | map.insert( Reminders, ); |
370 | map. | 372 | map. |
371 | */ | 373 | */ |
372 | return map; | 374 | return map; |
373 | } | 375 | } |
374 | 376 | ||
375 | QMap<QString, QString> OTodo::toExtraMap()const { | 377 | QMap<QString, QString> OTodo::toExtraMap()const { |
376 | return data->extra; | 378 | return data->extra; |
377 | } | 379 | } |
378 | /** | 380 | /** |
379 | * change or modify looks at the ref count and either | 381 | * change or modify looks at the ref count and either |
380 | * creates a new QShared Object or it can modify it | 382 | * creates a new QShared Object or it can modify it |
381 | * right in place | 383 | * right in place |
382 | */ | 384 | */ |
383 | void OTodo::changeOrModify() { | 385 | void OTodo::changeOrModify() { |
384 | if ( data->count != 1 ) { | 386 | if ( data->count != 1 ) { |
385 | qWarning("changeOrModify"); | 387 | qWarning("changeOrModify"); |
386 | data->deref(); | 388 | data->deref(); |
387 | OTodoData* d2 = new OTodoData(); | 389 | OTodoData* d2 = new OTodoData(); |
388 | copy(data, d2 ); | 390 | copy(data, d2 ); |
389 | data = d2; | 391 | data = d2; |
390 | } | 392 | } |
391 | } | 393 | } |
392 | // WATCHOUT | 394 | // WATCHOUT |
393 | /* | 395 | /* |
394 | * if you add something to the Data struct | 396 | * if you add something to the Data struct |
395 | * be sure to copy it here | 397 | * be sure to copy it here |
396 | */ | 398 | */ |
397 | void OTodo::copy( OTodoData* src, OTodoData* dest ) { | 399 | void OTodo::copy( OTodoData* src, OTodoData* dest ) { |
398 | dest->date = src->date; | 400 | dest->date = src->date; |
399 | dest->isCompleted = src->isCompleted; | 401 | dest->isCompleted = src->isCompleted; |
400 | dest->hasDate = src->hasDate; | 402 | dest->hasDate = src->hasDate; |
401 | dest->priority = src->priority; | 403 | dest->priority = src->priority; |
402 | dest->desc = src->desc; | 404 | dest->desc = src->desc; |
403 | dest->sum = src->sum; | 405 | dest->sum = src->sum; |
404 | dest->extra = src->extra; | 406 | dest->extra = src->extra; |
405 | dest->prog = src->prog; | 407 | dest->prog = src->prog; |
406 | dest->state = src->state; | 408 | dest->state = src->state; |
407 | dest->recur = src->recur; | 409 | dest->recur = src->recur; |
408 | dest->maintainer = src->maintainer; | 410 | dest->maintainer = src->maintainer; |
409 | dest->start = src->start; | 411 | dest->start = src->start; |
410 | dest->completed = src->completed; | 412 | dest->completed = src->completed; |
411 | dest->notifiers = src->notifiers; | 413 | dest->notifiers = src->notifiers; |
412 | } | 414 | } |
413 | QString OTodo::type() const { | 415 | QString OTodo::type() const { |
414 | return QString::fromLatin1("OTodo"); | 416 | return QString::fromLatin1("OTodo"); |
415 | } | 417 | } |
416 | QString OTodo::recordField(int /*id*/ )const { | 418 | QString OTodo::recordField(int /*id*/ )const { |
417 | return QString::null; | 419 | return QString::null; |
418 | } | 420 | } |
419 | 421 | ||
420 | int OTodo::rtti(){ | 422 | int OTodo::rtti(){ |
421 | return OPimResolver::TodoList; | 423 | return OPimResolver::TodoList; |
422 | } | 424 | } |
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 | |||
5 | int 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 | ||
8 | LIBS += -lqpe -lopie | ||
9 | TARGET = oevent_test | ||
10 | |||
11 | include ( $(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 | |||
8 | int 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(); | ||
26 | ac.save(); | ||
27 | /* | ||
28 | for( it = lis.begin(); it != lis.end(); ++it ) { | ||
29 | qWarning("Desc: " + (*it).summary() ); | ||
30 | qWarning("UID %d", (*it).uid() ); | ||
31 | } | ||
32 | */ | ||
33 | elc = 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 | ||
8 | LIBS += -lqpe -lopie -lopiesql | ||
9 | TARGET = todo_test | ||
10 | |||
11 | include ( $(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 | |||
9 | using namespace Opie; | ||
10 | |||
11 | namespace { | ||
12 | |||
13 | class FileToDoResource : public ToDoResource { | ||
14 | public: | ||
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 | |||
152 | ToDoDB::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 | } | ||
164 | ToDoResource* ToDoDB::resource(){ | ||
165 | return m_res; | ||
166 | }; | ||
167 | void ToDoDB::setResource( ToDoResource *res ) | ||
168 | { | ||
169 | delete m_res; | ||
170 | m_res = res; | ||
171 | } | ||
172 | ToDoDB::~ToDoDB() | ||
173 | { | ||
174 | delete m_res; | ||
175 | } | ||
176 | QValueList<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 | } | ||
190 | QValueList<ToDoEvent> ToDoDB::effectiveToDos(const QDate &from, | ||
191 | bool all) | ||
192 | { | ||
193 | return effectiveToDos( from, QDate::currentDate(), all ); | ||
194 | } | ||
195 | QValueList<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 | } | ||
204 | QValueList<ToDoEvent> ToDoDB::rawToDos() | ||
205 | { | ||
206 | return m_todos; | ||
207 | } | ||
208 | void ToDoDB::addEvent( const ToDoEvent &event ) | ||
209 | { | ||
210 | m_todos.append( event ); | ||
211 | } | ||
212 | void ToDoDB::editEvent( const ToDoEvent &event ) | ||
213 | { | ||
214 | m_todos.remove( event ); | ||
215 | m_todos.append( event ); | ||
216 | } | ||
217 | void ToDoDB::removeEvent( const ToDoEvent &event ) | ||
218 | { | ||
219 | m_todos.remove( event ); | ||
220 | } | ||
221 | void 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 | } | ||
234 | void ToDoDB::reload() | ||
235 | { | ||
236 | load(); | ||
237 | } | ||
238 | void 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 | } | ||
245 | void ToDoDB::setFileName(const QString &file ) | ||
246 | { | ||
247 | m_fileName =file; | ||
248 | } | ||
249 | QString ToDoDB::fileName()const | ||
250 | { | ||
251 | return m_fileName; | ||
252 | } | ||
253 | void ToDoDB::load() | ||
254 | { | ||
255 | m_todos = m_res->load( m_fileName ); | ||
256 | } | ||
257 | bool 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 | |||
9 | class ToDoResource; | ||
10 | class 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 | |||
15 | ToDoEvent::ToDoEvent(const ToDoEvent &event ) | ||
16 | { | ||
17 | *this = event; | ||
18 | } | ||
19 | |||
20 | ToDoEvent::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 | } | ||
42 | QArray<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 | } | ||
48 | bool ToDoEvent::match( const QRegExp ®Exp )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 | } | ||
59 | bool ToDoEvent::isCompleted() const | ||
60 | { | ||
61 | return m_isCompleted; | ||
62 | } | ||
63 | bool ToDoEvent::hasDate() const | ||
64 | { | ||
65 | return m_hasDate; | ||
66 | } | ||
67 | int ToDoEvent::priority()const | ||
68 | { | ||
69 | return m_priority; | ||
70 | } | ||
71 | QStringList ToDoEvent::allCategories()const | ||
72 | { | ||
73 | return m_category; | ||
74 | } | ||
75 | QString ToDoEvent::extra(const QString& )const | ||
76 | { | ||
77 | return QString::null; | ||
78 | } | ||
79 | QString ToDoEvent::summary() const | ||
80 | { | ||
81 | return m_sum; | ||
82 | } | ||
83 | ushort ToDoEvent::progress() const | ||
84 | { | ||
85 | return m_prog; | ||
86 | } | ||
87 | QStringList 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 | } | ||
96 | QArray<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 | } | ||
105 | void ToDoEvent::insertCategory(const QString &str ) | ||
106 | { | ||
107 | m_category.append( str ); | ||
108 | } | ||
109 | void ToDoEvent::clearCategories() | ||
110 | { | ||
111 | m_category.clear(); | ||
112 | } | ||
113 | void ToDoEvent::setCategories(const QStringList &list ) | ||
114 | { | ||
115 | m_category = list; | ||
116 | } | ||
117 | QDate ToDoEvent::date()const | ||
118 | { | ||
119 | return m_date; | ||
120 | } | ||
121 | |||
122 | QString ToDoEvent::description()const | ||
123 | { | ||
124 | return m_desc; | ||
125 | } | ||
126 | void ToDoEvent::setCompleted( bool completed ) | ||
127 | { | ||
128 | m_isCompleted = completed; | ||
129 | } | ||
130 | void ToDoEvent::setHasDate( bool hasDate ) | ||
131 | { | ||
132 | m_hasDate = hasDate; | ||
133 | } | ||
134 | void ToDoEvent::setDescription(const QString &desc ) | ||
135 | { | ||
136 | m_desc = Qtopia::simplifyMultiLineSpace(desc ); | ||
137 | } | ||
138 | void ToDoEvent::setExtra( const QString&, const QString& ) | ||
139 | { | ||
140 | |||
141 | } | ||
142 | void ToDoEvent::setSummary( const QString& sum ) | ||
143 | { | ||
144 | m_sum = sum; | ||
145 | } | ||
146 | void ToDoEvent::setCategory( const QString &cat ) | ||
147 | { | ||
148 | qWarning("setCategory %s", cat.latin1() ); | ||
149 | m_category.clear(); | ||
150 | m_category << cat; | ||
151 | } | ||
152 | void ToDoEvent::setPriority(int prio ) | ||
153 | { | ||
154 | m_priority = prio; | ||
155 | } | ||
156 | void ToDoEvent::setDate( QDate date ) | ||
157 | { | ||
158 | m_date = date; | ||
159 | } | ||
160 | void 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 | } | ||
175 | void 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 | } | ||
195 | void ToDoEvent::clearRelated( const QString& app ) | ||
196 | { | ||
197 | m_relations.remove( app ); | ||
198 | } | ||
199 | bool ToDoEvent::isOverdue( ) | ||
200 | { | ||
201 | if( m_hasDate ) | ||
202 | return QDate::currentDate() > m_date; | ||
203 | return false; | ||
204 | } | ||
205 | void ToDoEvent::setProgress(ushort progress ) | ||
206 | { | ||
207 | m_prog = progress; | ||
208 | } | ||
209 | /*! | ||
210 | Returns a richt text string | ||
211 | */ | ||
212 | QString 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 | |||
255 | bool 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 | } | ||
267 | bool 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 | } | ||
280 | bool 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 | } | ||
293 | bool 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 | } | ||
306 | bool 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 | } | ||
319 | ToDoEvent &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 | |||
13 | class 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 | |||
6 | class ToDoEvent; | ||
7 | class 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 | |||
38 | static 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 | |||
57 | static 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 | |||
104 | QValueList<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 | } | ||
129 | bool 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 | |||
34 | class 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 | ||