author | zautrix <zautrix> | 2004-08-10 19:41:31 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-08-10 19:41:31 (UTC) |
commit | 2f1b58e344b882578977dd3786f7a94495096d22 (patch) (unidiff) | |
tree | 6658bef546b6feac1688aa465ca94344e15704d7 /libkcal | |
parent | 467e50111dfd6d66aca205501b6bf369b7f0a166 (diff) | |
download | kdepimpi-2f1b58e344b882578977dd3786f7a94495096d22.zip kdepimpi-2f1b58e344b882578977dd3786f7a94495096d22.tar.gz kdepimpi-2f1b58e344b882578977dd3786f7a94495096d22.tar.bz2 |
More syncing stuff
-rw-r--r-- | libkcal/calendar.cpp | 15 | ||||
-rw-r--r-- | libkcal/calendar.h | 1 | ||||
-rw-r--r-- | libkcal/incidencebase.cpp | 3 | ||||
-rw-r--r-- | libkcal/phoneformat.cpp | 227 | ||||
-rw-r--r-- | libkcal/phoneformat.h | 4 | ||||
-rw-r--r-- | libkcal/vcalformat.cpp | 7 | ||||
-rw-r--r-- | libkcal/vcalformat.h | 4 |
7 files changed, 221 insertions, 40 deletions
diff --git a/libkcal/calendar.cpp b/libkcal/calendar.cpp index 32aac7a..a3977d7 100644 --- a/libkcal/calendar.cpp +++ b/libkcal/calendar.cpp | |||
@@ -1,426 +1,441 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | Copyright (c) 1998 Preston Brown | 3 | Copyright (c) 1998 Preston Brown |
4 | Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> | 4 | Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> |
5 | 5 | ||
6 | This library is free software; you can redistribute it and/or | 6 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Library General Public | 7 | modify it under the terms of the GNU Library General Public |
8 | License as published by the Free Software Foundation; either | 8 | License as published by the Free Software Foundation; either |
9 | version 2 of the License, or (at your option) any later version. | 9 | version 2 of the License, or (at your option) any later version. |
10 | 10 | ||
11 | This library is distributed in the hope that it will be useful, | 11 | This library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Library General Public License for more details. | 14 | Library General Public License for more details. |
15 | 15 | ||
16 | You should have received a copy of the GNU Library General Public License | 16 | You should have received a copy of the GNU Library General Public License |
17 | along with this library; see the file COPYING.LIB. If not, write to | 17 | along with this library; see the file COPYING.LIB. If not, write to |
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
19 | Boston, MA 02111-1307, USA. | 19 | Boston, MA 02111-1307, USA. |
20 | */ | 20 | */ |
21 | 21 | ||
22 | #include <stdlib.h> | 22 | #include <stdlib.h> |
23 | #include <time.h> | 23 | #include <time.h> |
24 | 24 | ||
25 | #include <kdebug.h> | 25 | #include <kdebug.h> |
26 | #include <kglobal.h> | 26 | #include <kglobal.h> |
27 | #include <klocale.h> | 27 | #include <klocale.h> |
28 | 28 | ||
29 | #include "exceptions.h" | 29 | #include "exceptions.h" |
30 | #include "calfilter.h" | 30 | #include "calfilter.h" |
31 | 31 | ||
32 | #include "calendar.h" | 32 | #include "calendar.h" |
33 | #include "syncdefines.h" | ||
33 | 34 | ||
34 | using namespace KCal; | 35 | using namespace KCal; |
35 | 36 | ||
36 | Calendar::Calendar() | 37 | Calendar::Calendar() |
37 | { | 38 | { |
38 | 39 | ||
39 | init(); | 40 | init(); |
40 | setTimeZoneId( i18n (" 00:00 Europe/London(UTC)") ); | 41 | setTimeZoneId( i18n (" 00:00 Europe/London(UTC)") ); |
41 | } | 42 | } |
42 | 43 | ||
43 | Calendar::Calendar( const QString &timeZoneId ) | 44 | Calendar::Calendar( const QString &timeZoneId ) |
44 | { | 45 | { |
45 | 46 | ||
46 | init(); | 47 | init(); |
47 | setTimeZoneId(timeZoneId); | 48 | setTimeZoneId(timeZoneId); |
48 | } | 49 | } |
49 | 50 | ||
50 | void Calendar::init() | 51 | void Calendar::init() |
51 | { | 52 | { |
52 | mObserver = 0; | 53 | mObserver = 0; |
53 | mNewObserver = false; | 54 | mNewObserver = false; |
54 | 55 | ||
55 | mModified = false; | 56 | mModified = false; |
56 | 57 | ||
57 | // Setup default filter, which does nothing | 58 | // Setup default filter, which does nothing |
58 | mDefaultFilter = new CalFilter; | 59 | mDefaultFilter = new CalFilter; |
59 | mFilter = mDefaultFilter; | 60 | mFilter = mDefaultFilter; |
60 | mFilter->setEnabled(false); | 61 | mFilter->setEnabled(false); |
61 | 62 | ||
62 | // initialize random numbers. This is a hack, and not | 63 | // initialize random numbers. This is a hack, and not |
63 | // even that good of one at that. | 64 | // even that good of one at that. |
64 | // srandom(time(0)); | 65 | // srandom(time(0)); |
65 | 66 | ||
66 | // user information... | 67 | // user information... |
67 | setOwner(i18n("Unknown Name")); | 68 | setOwner(i18n("Unknown Name")); |
68 | setEmail(i18n("unknown@nowhere")); | 69 | setEmail(i18n("unknown@nowhere")); |
69 | 70 | ||
70 | #if 0 | 71 | #if 0 |
71 | tmpStr = KOPrefs::instance()->mTimeZone; | 72 | tmpStr = KOPrefs::instance()->mTimeZone; |
72 | // kdDebug(5800) << "Calendar::Calendar(): TimeZone: " << tmpStr << endl; | 73 | // kdDebug(5800) << "Calendar::Calendar(): TimeZone: " << tmpStr << endl; |
73 | int dstSetting = KOPrefs::instance()->mDaylightSavings; | 74 | int dstSetting = KOPrefs::instance()->mDaylightSavings; |
74 | extern long int timezone; | 75 | extern long int timezone; |
75 | struct tm *now; | 76 | struct tm *now; |
76 | time_t curtime; | 77 | time_t curtime; |
77 | curtime = time(0); | 78 | curtime = time(0); |
78 | now = localtime(&curtime); | 79 | now = localtime(&curtime); |
79 | int hourOff = - ((timezone / 60) / 60); | 80 | int hourOff = - ((timezone / 60) / 60); |
80 | if (now->tm_isdst) | 81 | if (now->tm_isdst) |
81 | hourOff += 1; | 82 | hourOff += 1; |
82 | QString tzStr; | 83 | QString tzStr; |
83 | tzStr.sprintf("%.2d%.2d", | 84 | tzStr.sprintf("%.2d%.2d", |
84 | hourOff, | 85 | hourOff, |
85 | abs((timezone / 60) % 60)); | 86 | abs((timezone / 60) % 60)); |
86 | 87 | ||
87 | // if no time zone was in the config file, write what we just discovered. | 88 | // if no time zone was in the config file, write what we just discovered. |
88 | if (tmpStr.isEmpty()) { | 89 | if (tmpStr.isEmpty()) { |
89 | // KOPrefs::instance()->mTimeZone = tzStr; | 90 | // KOPrefs::instance()->mTimeZone = tzStr; |
90 | } else { | 91 | } else { |
91 | tzStr = tmpStr; | 92 | tzStr = tmpStr; |
92 | } | 93 | } |
93 | 94 | ||
94 | // if daylight savings has changed since last load time, we need | 95 | // if daylight savings has changed since last load time, we need |
95 | // to rewrite these settings to the config file. | 96 | // to rewrite these settings to the config file. |
96 | if ((now->tm_isdst && !dstSetting) || | 97 | if ((now->tm_isdst && !dstSetting) || |
97 | (!now->tm_isdst && dstSetting)) { | 98 | (!now->tm_isdst && dstSetting)) { |
98 | KOPrefs::instance()->mTimeZone = tzStr; | 99 | KOPrefs::instance()->mTimeZone = tzStr; |
99 | KOPrefs::instance()->mDaylightSavings = now->tm_isdst; | 100 | KOPrefs::instance()->mDaylightSavings = now->tm_isdst; |
100 | } | 101 | } |
101 | 102 | ||
102 | setTimeZone(tzStr); | 103 | setTimeZone(tzStr); |
103 | #endif | 104 | #endif |
104 | 105 | ||
105 | // KOPrefs::instance()->writeConfig(); | 106 | // KOPrefs::instance()->writeConfig(); |
106 | } | 107 | } |
107 | 108 | ||
108 | Calendar::~Calendar() | 109 | Calendar::~Calendar() |
109 | { | 110 | { |
110 | delete mDefaultFilter; | 111 | delete mDefaultFilter; |
111 | } | 112 | } |
112 | 113 | ||
113 | const QString &Calendar::getOwner() const | 114 | const QString &Calendar::getOwner() const |
114 | { | 115 | { |
115 | return mOwner; | 116 | return mOwner; |
116 | } | 117 | } |
117 | 118 | ||
118 | void Calendar::setOwner(const QString &os) | 119 | void Calendar::setOwner(const QString &os) |
119 | { | 120 | { |
120 | int i; | 121 | int i; |
121 | mOwner = os; | 122 | mOwner = os; |
122 | i = mOwner.find(','); | 123 | i = mOwner.find(','); |
123 | if (i != -1) | 124 | if (i != -1) |
124 | mOwner = mOwner.left(i); | 125 | mOwner = mOwner.left(i); |
125 | 126 | ||
126 | setModified( true ); | 127 | setModified( true ); |
127 | } | 128 | } |
128 | 129 | ||
129 | void Calendar::setTimeZone(const QString & tz) | 130 | void Calendar::setTimeZone(const QString & tz) |
130 | { | 131 | { |
131 | bool neg = FALSE; | 132 | bool neg = FALSE; |
132 | int hours, minutes; | 133 | int hours, minutes; |
133 | QString tmpStr(tz); | 134 | QString tmpStr(tz); |
134 | 135 | ||
135 | if (tmpStr.left(1) == "-") | 136 | if (tmpStr.left(1) == "-") |
136 | neg = TRUE; | 137 | neg = TRUE; |
137 | if (tmpStr.left(1) == "-" || tmpStr.left(1) == "+") | 138 | if (tmpStr.left(1) == "-" || tmpStr.left(1) == "+") |
138 | tmpStr.remove(0, 1); | 139 | tmpStr.remove(0, 1); |
139 | hours = tmpStr.left(2).toInt(); | 140 | hours = tmpStr.left(2).toInt(); |
140 | if (tmpStr.length() > 2) | 141 | if (tmpStr.length() > 2) |
141 | minutes = tmpStr.right(2).toInt(); | 142 | minutes = tmpStr.right(2).toInt(); |
142 | else | 143 | else |
143 | minutes = 0; | 144 | minutes = 0; |
144 | mTimeZone = (60*hours+minutes); | 145 | mTimeZone = (60*hours+minutes); |
145 | if (neg) | 146 | if (neg) |
146 | mTimeZone = -mTimeZone; | 147 | mTimeZone = -mTimeZone; |
147 | mLocalTime = false; | 148 | mLocalTime = false; |
148 | 149 | ||
149 | setModified( true ); | 150 | setModified( true ); |
150 | } | 151 | } |
151 | 152 | ||
152 | QString Calendar::getTimeZoneStr() const | 153 | QString Calendar::getTimeZoneStr() const |
153 | { | 154 | { |
154 | if (mLocalTime) | 155 | if (mLocalTime) |
155 | return ""; | 156 | return ""; |
156 | QString tmpStr; | 157 | QString tmpStr; |
157 | int hours = abs(mTimeZone / 60); | 158 | int hours = abs(mTimeZone / 60); |
158 | int minutes = abs(mTimeZone % 60); | 159 | int minutes = abs(mTimeZone % 60); |
159 | bool neg = mTimeZone < 0; | 160 | bool neg = mTimeZone < 0; |
160 | 161 | ||
161 | tmpStr.sprintf("%c%.2d%.2d", | 162 | tmpStr.sprintf("%c%.2d%.2d", |
162 | (neg ? '-' : '+'), | 163 | (neg ? '-' : '+'), |
163 | hours, minutes); | 164 | hours, minutes); |
164 | return tmpStr; | 165 | return tmpStr; |
165 | } | 166 | } |
166 | 167 | ||
167 | void Calendar::setTimeZone(int tz) | 168 | void Calendar::setTimeZone(int tz) |
168 | { | 169 | { |
169 | mTimeZone = tz; | 170 | mTimeZone = tz; |
170 | mLocalTime = false; | 171 | mLocalTime = false; |
171 | 172 | ||
172 | setModified( true ); | 173 | setModified( true ); |
173 | } | 174 | } |
174 | 175 | ||
175 | int Calendar::getTimeZone() const | 176 | int Calendar::getTimeZone() const |
176 | { | 177 | { |
177 | return mTimeZone; | 178 | return mTimeZone; |
178 | } | 179 | } |
179 | 180 | ||
180 | void Calendar::setTimeZoneId(const QString &id) | 181 | void Calendar::setTimeZoneId(const QString &id) |
181 | { | 182 | { |
182 | mTimeZoneId = id; | 183 | mTimeZoneId = id; |
183 | mLocalTime = false; | 184 | mLocalTime = false; |
184 | mTimeZone = KGlobal::locale()->timezoneOffset(mTimeZoneId); | 185 | mTimeZone = KGlobal::locale()->timezoneOffset(mTimeZoneId); |
185 | if ( mTimeZone > 1000) | 186 | if ( mTimeZone > 1000) |
186 | setLocalTime(); | 187 | setLocalTime(); |
187 | //qDebug("Calendar::setTimeZoneOffset %s %d ",mTimeZoneId.latin1(), mTimeZone); | 188 | //qDebug("Calendar::setTimeZoneOffset %s %d ",mTimeZoneId.latin1(), mTimeZone); |
188 | setModified( true ); | 189 | setModified( true ); |
189 | } | 190 | } |
190 | 191 | ||
191 | QString Calendar::timeZoneId() const | 192 | QString Calendar::timeZoneId() const |
192 | { | 193 | { |
193 | return mTimeZoneId; | 194 | return mTimeZoneId; |
194 | } | 195 | } |
195 | 196 | ||
196 | void Calendar::setLocalTime() | 197 | void Calendar::setLocalTime() |
197 | { | 198 | { |
198 | //qDebug("Calendar::setLocalTime() "); | 199 | //qDebug("Calendar::setLocalTime() "); |
199 | mLocalTime = true; | 200 | mLocalTime = true; |
200 | mTimeZone = 0; | 201 | mTimeZone = 0; |
201 | mTimeZoneId = ""; | 202 | mTimeZoneId = ""; |
202 | 203 | ||
203 | setModified( true ); | 204 | setModified( true ); |
204 | } | 205 | } |
205 | 206 | ||
206 | bool Calendar::isLocalTime() const | 207 | bool Calendar::isLocalTime() const |
207 | { | 208 | { |
208 | return mLocalTime; | 209 | return mLocalTime; |
209 | } | 210 | } |
210 | 211 | ||
211 | const QString &Calendar::getEmail() | 212 | const QString &Calendar::getEmail() |
212 | { | 213 | { |
213 | return mOwnerEmail; | 214 | return mOwnerEmail; |
214 | } | 215 | } |
215 | 216 | ||
216 | void Calendar::setEmail(const QString &e) | 217 | void Calendar::setEmail(const QString &e) |
217 | { | 218 | { |
218 | mOwnerEmail = e; | 219 | mOwnerEmail = e; |
219 | 220 | ||
220 | setModified( true ); | 221 | setModified( true ); |
221 | } | 222 | } |
222 | 223 | ||
223 | void Calendar::setFilter(CalFilter *filter) | 224 | void Calendar::setFilter(CalFilter *filter) |
224 | { | 225 | { |
225 | mFilter = filter; | 226 | mFilter = filter; |
226 | } | 227 | } |
227 | 228 | ||
228 | CalFilter *Calendar::filter() | 229 | CalFilter *Calendar::filter() |
229 | { | 230 | { |
230 | return mFilter; | 231 | return mFilter; |
231 | } | 232 | } |
232 | 233 | ||
233 | QPtrList<Incidence> Calendar::incidences() | 234 | QPtrList<Incidence> Calendar::incidences() |
234 | { | 235 | { |
235 | QPtrList<Incidence> incidences; | 236 | QPtrList<Incidence> incidences; |
236 | 237 | ||
237 | Incidence *i; | 238 | Incidence *i; |
238 | 239 | ||
239 | QPtrList<Event> e = events(); | 240 | QPtrList<Event> e = events(); |
240 | for( i = e.first(); i; i = e.next() ) incidences.append( i ); | 241 | for( i = e.first(); i; i = e.next() ) incidences.append( i ); |
241 | 242 | ||
242 | QPtrList<Todo> t = todos(); | 243 | QPtrList<Todo> t = todos(); |
243 | for( i = t.first(); i; i = t.next() ) incidences.append( i ); | 244 | for( i = t.first(); i; i = t.next() ) incidences.append( i ); |
244 | 245 | ||
245 | QPtrList<Journal> j = journals(); | 246 | QPtrList<Journal> j = journals(); |
246 | for( i = j.first(); i; i = j.next() ) incidences.append( i ); | 247 | for( i = j.first(); i; i = j.next() ) incidences.append( i ); |
247 | 248 | ||
248 | return incidences; | 249 | return incidences; |
249 | } | 250 | } |
251 | void Calendar::resetTempSyncStat() | ||
252 | { | ||
253 | QPtrList<Incidence> incidences; | ||
254 | |||
255 | Incidence *i; | ||
256 | |||
257 | QPtrList<Event> e = rawEvents(); | ||
258 | for( i = e.first(); i; i = e.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | ||
250 | 259 | ||
260 | QPtrList<Todo> t = rawTodos(); | ||
261 | for( i = t.first(); i; i = t.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | ||
262 | |||
263 | QPtrList<Journal> j = journals(); | ||
264 | for( i = j.first(); i; i = j.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | ||
265 | } | ||
251 | QPtrList<Incidence> Calendar::rawIncidences() | 266 | QPtrList<Incidence> Calendar::rawIncidences() |
252 | { | 267 | { |
253 | QPtrList<Incidence> incidences; | 268 | QPtrList<Incidence> incidences; |
254 | 269 | ||
255 | Incidence *i; | 270 | Incidence *i; |
256 | 271 | ||
257 | QPtrList<Event> e = rawEvents(); | 272 | QPtrList<Event> e = rawEvents(); |
258 | for( i = e.first(); i; i = e.next() ) incidences.append( i ); | 273 | for( i = e.first(); i; i = e.next() ) incidences.append( i ); |
259 | 274 | ||
260 | QPtrList<Todo> t = rawTodos(); | 275 | QPtrList<Todo> t = rawTodos(); |
261 | for( i = t.first(); i; i = t.next() ) incidences.append( i ); | 276 | for( i = t.first(); i; i = t.next() ) incidences.append( i ); |
262 | 277 | ||
263 | QPtrList<Journal> j = journals(); | 278 | QPtrList<Journal> j = journals(); |
264 | for( i = j.first(); i; i = j.next() ) incidences.append( i ); | 279 | for( i = j.first(); i; i = j.next() ) incidences.append( i ); |
265 | 280 | ||
266 | return incidences; | 281 | return incidences; |
267 | } | 282 | } |
268 | 283 | ||
269 | QPtrList<Event> Calendar::events( const QDate &date, bool sorted ) | 284 | QPtrList<Event> Calendar::events( const QDate &date, bool sorted ) |
270 | { | 285 | { |
271 | QPtrList<Event> el = rawEventsForDate(date,sorted); | 286 | QPtrList<Event> el = rawEventsForDate(date,sorted); |
272 | mFilter->apply(&el); | 287 | mFilter->apply(&el); |
273 | return el; | 288 | return el; |
274 | } | 289 | } |
275 | 290 | ||
276 | QPtrList<Event> Calendar::events( const QDateTime &qdt ) | 291 | QPtrList<Event> Calendar::events( const QDateTime &qdt ) |
277 | { | 292 | { |
278 | QPtrList<Event> el = rawEventsForDate(qdt); | 293 | QPtrList<Event> el = rawEventsForDate(qdt); |
279 | mFilter->apply(&el); | 294 | mFilter->apply(&el); |
280 | return el; | 295 | return el; |
281 | } | 296 | } |
282 | 297 | ||
283 | QPtrList<Event> Calendar::events( const QDate &start, const QDate &end, | 298 | QPtrList<Event> Calendar::events( const QDate &start, const QDate &end, |
284 | bool inclusive) | 299 | bool inclusive) |
285 | { | 300 | { |
286 | QPtrList<Event> el = rawEvents(start,end,inclusive); | 301 | QPtrList<Event> el = rawEvents(start,end,inclusive); |
287 | mFilter->apply(&el); | 302 | mFilter->apply(&el); |
288 | return el; | 303 | return el; |
289 | } | 304 | } |
290 | 305 | ||
291 | QPtrList<Event> Calendar::events() | 306 | QPtrList<Event> Calendar::events() |
292 | { | 307 | { |
293 | QPtrList<Event> el = rawEvents(); | 308 | QPtrList<Event> el = rawEvents(); |
294 | mFilter->apply(&el); | 309 | mFilter->apply(&el); |
295 | return el; | 310 | return el; |
296 | } | 311 | } |
297 | 312 | ||
298 | 313 | ||
299 | bool Calendar::addIncidence(Incidence *i) | 314 | bool Calendar::addIncidence(Incidence *i) |
300 | { | 315 | { |
301 | Incidence::AddVisitor<Calendar> v(this); | 316 | Incidence::AddVisitor<Calendar> v(this); |
302 | 317 | ||
303 | return i->accept(v); | 318 | return i->accept(v); |
304 | } | 319 | } |
305 | void Calendar::deleteIncidence(Incidence *in) | 320 | void Calendar::deleteIncidence(Incidence *in) |
306 | { | 321 | { |
307 | if ( in->type() == "Event" ) | 322 | if ( in->type() == "Event" ) |
308 | deleteEvent( (Event*) in ); | 323 | deleteEvent( (Event*) in ); |
309 | else if ( in->type() =="Todo" ) | 324 | else if ( in->type() =="Todo" ) |
310 | deleteTodo( (Todo*) in); | 325 | deleteTodo( (Todo*) in); |
311 | else if ( in->type() =="Journal" ) | 326 | else if ( in->type() =="Journal" ) |
312 | deleteJournal( (Journal*) in ); | 327 | deleteJournal( (Journal*) in ); |
313 | } | 328 | } |
314 | 329 | ||
315 | Incidence* Calendar::incidence( const QString& uid ) | 330 | Incidence* Calendar::incidence( const QString& uid ) |
316 | { | 331 | { |
317 | Incidence* i; | 332 | Incidence* i; |
318 | 333 | ||
319 | if( (i = todo( uid )) != 0 ) | 334 | if( (i = todo( uid )) != 0 ) |
320 | return i; | 335 | return i; |
321 | if( (i = event( uid )) != 0 ) | 336 | if( (i = event( uid )) != 0 ) |
322 | return i; | 337 | return i; |
323 | if( (i = journal( uid )) != 0 ) | 338 | if( (i = journal( uid )) != 0 ) |
324 | return i; | 339 | return i; |
325 | 340 | ||
326 | return 0; | 341 | return 0; |
327 | } | 342 | } |
328 | 343 | ||
329 | QPtrList<Todo> Calendar::todos() | 344 | QPtrList<Todo> Calendar::todos() |
330 | { | 345 | { |
331 | QPtrList<Todo> tl = rawTodos(); | 346 | QPtrList<Todo> tl = rawTodos(); |
332 | mFilter->apply( &tl ); | 347 | mFilter->apply( &tl ); |
333 | return tl; | 348 | return tl; |
334 | } | 349 | } |
335 | 350 | ||
336 | // When this is called, the todo have already been added to the calendar. | 351 | // When this is called, the todo have already been added to the calendar. |
337 | // This method is only about linking related todos | 352 | // This method is only about linking related todos |
338 | void Calendar::setupRelations( Incidence *incidence ) | 353 | void Calendar::setupRelations( Incidence *incidence ) |
339 | { | 354 | { |
340 | QString uid = incidence->uid(); | 355 | QString uid = incidence->uid(); |
341 | //qDebug("Calendar::setupRelations "); | 356 | //qDebug("Calendar::setupRelations "); |
342 | // First, go over the list of orphans and see if this is their parent | 357 | // First, go over the list of orphans and see if this is their parent |
343 | while( Incidence* i = mOrphans[ uid ] ) { | 358 | while( Incidence* i = mOrphans[ uid ] ) { |
344 | mOrphans.remove( uid ); | 359 | mOrphans.remove( uid ); |
345 | i->setRelatedTo( incidence ); | 360 | i->setRelatedTo( incidence ); |
346 | incidence->addRelation( i ); | 361 | incidence->addRelation( i ); |
347 | mOrphanUids.remove( i->uid() ); | 362 | mOrphanUids.remove( i->uid() ); |
348 | } | 363 | } |
349 | 364 | ||
350 | // Now see about this incidences parent | 365 | // Now see about this incidences parent |
351 | if( !incidence->relatedTo() && !incidence->relatedToUid().isEmpty() ) { | 366 | if( !incidence->relatedTo() && !incidence->relatedToUid().isEmpty() ) { |
352 | // This incidence has a uid it is related to, but is not registered to it yet | 367 | // This incidence has a uid it is related to, but is not registered to it yet |
353 | // Try to find it | 368 | // Try to find it |
354 | Incidence* parent = this->incidence( incidence->relatedToUid() ); | 369 | Incidence* parent = this->incidence( incidence->relatedToUid() ); |
355 | if( parent ) { | 370 | if( parent ) { |
356 | // Found it | 371 | // Found it |
357 | incidence->setRelatedTo( parent ); | 372 | incidence->setRelatedTo( parent ); |
358 | parent->addRelation( incidence ); | 373 | parent->addRelation( incidence ); |
359 | } else { | 374 | } else { |
360 | // Not found, put this in the mOrphans list | 375 | // Not found, put this in the mOrphans list |
361 | mOrphans.insert( incidence->relatedToUid(), incidence ); | 376 | mOrphans.insert( incidence->relatedToUid(), incidence ); |
362 | mOrphanUids.insert( incidence->uid(), incidence ); | 377 | mOrphanUids.insert( incidence->uid(), incidence ); |
363 | } | 378 | } |
364 | } | 379 | } |
365 | } | 380 | } |
366 | 381 | ||
367 | // If a task with subtasks is deleted, move it's subtasks to the orphans list | 382 | // If a task with subtasks is deleted, move it's subtasks to the orphans list |
368 | void Calendar::removeRelations( Incidence *incidence ) | 383 | void Calendar::removeRelations( Incidence *incidence ) |
369 | { | 384 | { |
370 | // qDebug("Calendar::removeRelations "); | 385 | // qDebug("Calendar::removeRelations "); |
371 | QString uid = incidence->uid(); | 386 | QString uid = incidence->uid(); |
372 | 387 | ||
373 | QPtrList<Incidence> relations = incidence->relations(); | 388 | QPtrList<Incidence> relations = incidence->relations(); |
374 | for( Incidence* i = relations.first(); i; i = relations.next() ) | 389 | for( Incidence* i = relations.first(); i; i = relations.next() ) |
375 | if( !mOrphanUids.find( i->uid() ) ) { | 390 | if( !mOrphanUids.find( i->uid() ) ) { |
376 | mOrphans.insert( uid, i ); | 391 | mOrphans.insert( uid, i ); |
377 | mOrphanUids.insert( i->uid(), i ); | 392 | mOrphanUids.insert( i->uid(), i ); |
378 | i->setRelatedTo( 0 ); | 393 | i->setRelatedTo( 0 ); |
379 | i->setRelatedToUid( uid ); | 394 | i->setRelatedToUid( uid ); |
380 | } | 395 | } |
381 | 396 | ||
382 | // If this incidence is related to something else, tell that about it | 397 | // If this incidence is related to something else, tell that about it |
383 | if( incidence->relatedTo() ) | 398 | if( incidence->relatedTo() ) |
384 | incidence->relatedTo()->removeRelation( incidence ); | 399 | incidence->relatedTo()->removeRelation( incidence ); |
385 | 400 | ||
386 | // Remove this one from the orphans list | 401 | // Remove this one from the orphans list |
387 | if( mOrphanUids.remove( uid ) ) | 402 | if( mOrphanUids.remove( uid ) ) |
388 | // This incidence is located in the orphans list - it should be removed | 403 | // This incidence is located in the orphans list - it should be removed |
389 | if( !( incidence->relatedTo() != 0 && mOrphans.remove( incidence->relatedTo()->uid() ) ) ) { | 404 | if( !( incidence->relatedTo() != 0 && mOrphans.remove( incidence->relatedTo()->uid() ) ) ) { |
390 | // Removing wasn't that easy | 405 | // Removing wasn't that easy |
391 | for( QDictIterator<Incidence> it( mOrphans ); it.current(); ++it ) { | 406 | for( QDictIterator<Incidence> it( mOrphans ); it.current(); ++it ) { |
392 | if( it.current()->uid() == uid ) { | 407 | if( it.current()->uid() == uid ) { |
393 | mOrphans.remove( it.currentKey() ); | 408 | mOrphans.remove( it.currentKey() ); |
394 | break; | 409 | break; |
395 | } | 410 | } |
396 | } | 411 | } |
397 | } | 412 | } |
398 | } | 413 | } |
399 | 414 | ||
400 | void Calendar::registerObserver( Observer *observer ) | 415 | void Calendar::registerObserver( Observer *observer ) |
401 | { | 416 | { |
402 | mObserver = observer; | 417 | mObserver = observer; |
403 | mNewObserver = true; | 418 | mNewObserver = true; |
404 | } | 419 | } |
405 | 420 | ||
406 | void Calendar::setModified( bool modified ) | 421 | void Calendar::setModified( bool modified ) |
407 | { | 422 | { |
408 | if ( mObserver ) mObserver->calendarModified( modified, this ); | 423 | if ( mObserver ) mObserver->calendarModified( modified, this ); |
409 | if ( modified != mModified || mNewObserver ) { | 424 | if ( modified != mModified || mNewObserver ) { |
410 | mNewObserver = false; | 425 | mNewObserver = false; |
411 | // if ( mObserver ) mObserver->calendarModified( modified, this ); | 426 | // if ( mObserver ) mObserver->calendarModified( modified, this ); |
412 | mModified = modified; | 427 | mModified = modified; |
413 | } | 428 | } |
414 | } | 429 | } |
415 | 430 | ||
416 | void Calendar::setLoadedProductId( const QString &id ) | 431 | void Calendar::setLoadedProductId( const QString &id ) |
417 | { | 432 | { |
418 | mLoadedProductId = id; | 433 | mLoadedProductId = id; |
419 | } | 434 | } |
420 | 435 | ||
421 | QString Calendar::loadedProductId() | 436 | QString Calendar::loadedProductId() |
422 | { | 437 | { |
423 | return mLoadedProductId; | 438 | return mLoadedProductId; |
424 | } | 439 | } |
425 | 440 | ||
426 | //#include "calendar.moc" | 441 | //#include "calendar.moc" |
diff --git a/libkcal/calendar.h b/libkcal/calendar.h index 4a3223c..06a911c 100644 --- a/libkcal/calendar.h +++ b/libkcal/calendar.h | |||
@@ -1,350 +1,351 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | Copyright (c) 1998 Preston Brown | 3 | Copyright (c) 1998 Preston Brown |
4 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 4 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
5 | 5 | ||
6 | This library is free software; you can redistribute it and/or | 6 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Library General Public | 7 | modify it under the terms of the GNU Library General Public |
8 | License as published by the Free Software Foundation; either | 8 | License as published by the Free Software Foundation; either |
9 | version 2 of the License, or (at your option) any later version. | 9 | version 2 of the License, or (at your option) any later version. |
10 | 10 | ||
11 | This library is distributed in the hope that it will be useful, | 11 | This library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Library General Public License for more details. | 14 | Library General Public License for more details. |
15 | 15 | ||
16 | You should have received a copy of the GNU Library General Public License | 16 | You should have received a copy of the GNU Library General Public License |
17 | along with this library; see the file COPYING.LIB. If not, write to | 17 | along with this library; see the file COPYING.LIB. If not, write to |
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
19 | Boston, MA 02111-1307, USA. | 19 | Boston, MA 02111-1307, USA. |
20 | */ | 20 | */ |
21 | 21 | ||
22 | #ifndef CALENDAR_H | 22 | #ifndef CALENDAR_H |
23 | #define CALENDAR_H | 23 | #define CALENDAR_H |
24 | 24 | ||
25 | #include <qobject.h> | 25 | #include <qobject.h> |
26 | #include <qstring.h> | 26 | #include <qstring.h> |
27 | #include <qdatetime.h> | 27 | #include <qdatetime.h> |
28 | #include <qptrlist.h> | 28 | #include <qptrlist.h> |
29 | #include <qdict.h> | 29 | #include <qdict.h> |
30 | 30 | ||
31 | #include "customproperties.h" | 31 | #include "customproperties.h" |
32 | #include "event.h" | 32 | #include "event.h" |
33 | #include "todo.h" | 33 | #include "todo.h" |
34 | #include "journal.h" | 34 | #include "journal.h" |
35 | 35 | ||
36 | #define _TIME_ZONE "-0500" /* hardcoded, overridden in config file. */ | 36 | #define _TIME_ZONE "-0500" /* hardcoded, overridden in config file. */ |
37 | 37 | ||
38 | class KConfig; | 38 | class KConfig; |
39 | 39 | ||
40 | namespace KCal { | 40 | namespace KCal { |
41 | 41 | ||
42 | class CalFilter; | 42 | class CalFilter; |
43 | 43 | ||
44 | /** | 44 | /** |
45 | This is the main "calendar" object class for KOrganizer. It holds | 45 | This is the main "calendar" object class for KOrganizer. It holds |
46 | information like all appointments/events, user information, etc. etc. | 46 | information like all appointments/events, user information, etc. etc. |
47 | one calendar is associated with each CalendarView (@see calendarview.h). | 47 | one calendar is associated with each CalendarView (@see calendarview.h). |
48 | This is an abstract base class defining the interface to a calendar. It is | 48 | This is an abstract base class defining the interface to a calendar. It is |
49 | implemented by subclasses like @see CalendarLocal, which use different | 49 | implemented by subclasses like @see CalendarLocal, which use different |
50 | methods to store and access the data. | 50 | methods to store and access the data. |
51 | 51 | ||
52 | Ownership of events etc. is handled by the following policy: As soon as an | 52 | Ownership of events etc. is handled by the following policy: As soon as an |
53 | event (or any other subclass of IncidenceBase) object is added to the | 53 | event (or any other subclass of IncidenceBase) object is added to the |
54 | Calendar by addEvent() it is owned by the Calendar object. The Calendar takes | 54 | Calendar by addEvent() it is owned by the Calendar object. The Calendar takes |
55 | care of deleting it. All Events returned by the query functions are returned | 55 | care of deleting it. All Events returned by the query functions are returned |
56 | as pointers, that means all changes to the returned events are immediately | 56 | as pointers, that means all changes to the returned events are immediately |
57 | visible in the Calendar. You shouldn't delete any Event object you get from | 57 | visible in the Calendar. You shouldn't delete any Event object you get from |
58 | Calendar. | 58 | Calendar. |
59 | */ | 59 | */ |
60 | class Calendar : public QObject, public CustomProperties, | 60 | class Calendar : public QObject, public CustomProperties, |
61 | public IncidenceBase::Observer | 61 | public IncidenceBase::Observer |
62 | { | 62 | { |
63 | Q_OBJECT | 63 | Q_OBJECT |
64 | public: | 64 | public: |
65 | Calendar(); | 65 | Calendar(); |
66 | Calendar(const QString &timeZoneId); | 66 | Calendar(const QString &timeZoneId); |
67 | virtual ~Calendar(); | 67 | virtual ~Calendar(); |
68 | void deleteIncidence(Incidence *in); | 68 | void deleteIncidence(Incidence *in); |
69 | void resetTempSyncStat(); | ||
69 | /** | 70 | /** |
70 | Clears out the current calendar, freeing all used memory etc. | 71 | Clears out the current calendar, freeing all used memory etc. |
71 | */ | 72 | */ |
72 | virtual void close() = 0; | 73 | virtual void close() = 0; |
73 | 74 | ||
74 | /** | 75 | /** |
75 | Sync changes in memory to persistant storage. | 76 | Sync changes in memory to persistant storage. |
76 | */ | 77 | */ |
77 | virtual void save() = 0; | 78 | virtual void save() = 0; |
78 | virtual QPtrList<Event> getExternLastSyncEvents() = 0; | 79 | virtual QPtrList<Event> getExternLastSyncEvents() = 0; |
79 | virtual bool isSaving() { return false; } | 80 | virtual bool isSaving() { return false; } |
80 | 81 | ||
81 | /** | 82 | /** |
82 | Return the owner of the calendar's full name. | 83 | Return the owner of the calendar's full name. |
83 | */ | 84 | */ |
84 | const QString &getOwner() const; | 85 | const QString &getOwner() const; |
85 | /** | 86 | /** |
86 | Set the owner of the calendar. Should be owner's full name. | 87 | Set the owner of the calendar. Should be owner's full name. |
87 | */ | 88 | */ |
88 | void setOwner( const QString &os ); | 89 | void setOwner( const QString &os ); |
89 | /** | 90 | /** |
90 | Return the email address of the calendar owner. | 91 | Return the email address of the calendar owner. |
91 | */ | 92 | */ |
92 | const QString &getEmail(); | 93 | const QString &getEmail(); |
93 | /** | 94 | /** |
94 | Set the email address of the calendar owner. | 95 | Set the email address of the calendar owner. |
95 | */ | 96 | */ |
96 | void setEmail( const QString & ); | 97 | void setEmail( const QString & ); |
97 | 98 | ||
98 | /** | 99 | /** |
99 | Set time zone from a timezone string (e.g. -2:00) | 100 | Set time zone from a timezone string (e.g. -2:00) |
100 | */ | 101 | */ |
101 | void setTimeZone( const QString &tz ); | 102 | void setTimeZone( const QString &tz ); |
102 | /** | 103 | /** |
103 | Set time zone from a minutes value (e.g. -60) | 104 | Set time zone from a minutes value (e.g. -60) |
104 | */ | 105 | */ |
105 | void setTimeZone( int tz ); | 106 | void setTimeZone( int tz ); |
106 | /** | 107 | /** |
107 | Return time zone as offest in minutes. | 108 | Return time zone as offest in minutes. |
108 | */ | 109 | */ |
109 | int getTimeZone() const; | 110 | int getTimeZone() const; |
110 | /** | 111 | /** |
111 | Compute an ISO 8601 format string from the time zone. | 112 | Compute an ISO 8601 format string from the time zone. |
112 | */ | 113 | */ |
113 | QString getTimeZoneStr() const; | 114 | QString getTimeZoneStr() const; |
114 | /** | 115 | /** |
115 | Set time zone id (see /usr/share/zoneinfo/zone.tab for list of legal | 116 | Set time zone id (see /usr/share/zoneinfo/zone.tab for list of legal |
116 | values). | 117 | values). |
117 | */ | 118 | */ |
118 | void setTimeZoneId( const QString & ); | 119 | void setTimeZoneId( const QString & ); |
119 | /** | 120 | /** |
120 | Return time zone id. | 121 | Return time zone id. |
121 | */ | 122 | */ |
122 | QString timeZoneId() const; | 123 | QString timeZoneId() const; |
123 | /** | 124 | /** |
124 | Use local time, not UTC or a time zone. | 125 | Use local time, not UTC or a time zone. |
125 | */ | 126 | */ |
126 | void setLocalTime(); | 127 | void setLocalTime(); |
127 | /** | 128 | /** |
128 | Return whether local time is being used. | 129 | Return whether local time is being used. |
129 | */ | 130 | */ |
130 | bool isLocalTime() const; | 131 | bool isLocalTime() const; |
131 | 132 | ||
132 | /** | 133 | /** |
133 | Add an incidence to calendar. | 134 | Add an incidence to calendar. |
134 | 135 | ||
135 | @return true on success, false on error. | 136 | @return true on success, false on error. |
136 | */ | 137 | */ |
137 | virtual bool addIncidence( Incidence * ); | 138 | virtual bool addIncidence( Incidence * ); |
138 | /** | 139 | /** |
139 | Return filtered list of all incidences of this calendar. | 140 | Return filtered list of all incidences of this calendar. |
140 | */ | 141 | */ |
141 | virtual QPtrList<Incidence> incidences(); | 142 | virtual QPtrList<Incidence> incidences(); |
142 | 143 | ||
143 | /** | 144 | /** |
144 | Return unfiltered list of all incidences of this calendar. | 145 | Return unfiltered list of all incidences of this calendar. |
145 | */ | 146 | */ |
146 | virtual QPtrList<Incidence> rawIncidences(); | 147 | virtual QPtrList<Incidence> rawIncidences(); |
147 | 148 | ||
148 | /** | 149 | /** |
149 | Adds a Event to this calendar object. | 150 | Adds a Event to this calendar object. |
150 | @param anEvent a pointer to the event to add | 151 | @param anEvent a pointer to the event to add |
151 | 152 | ||
152 | @return true on success, false on error. | 153 | @return true on success, false on error. |
153 | */ | 154 | */ |
154 | virtual bool addEventNoDup( Event *event ) = 0; | 155 | virtual bool addEventNoDup( Event *event ) = 0; |
155 | virtual bool addAnniversaryNoDup( Event *event ) = 0; | 156 | virtual bool addAnniversaryNoDup( Event *event ) = 0; |
156 | virtual bool addEvent( Event *anEvent ) = 0; | 157 | virtual bool addEvent( Event *anEvent ) = 0; |
157 | /** | 158 | /** |
158 | Delete event from calendar. | 159 | Delete event from calendar. |
159 | */ | 160 | */ |
160 | virtual void deleteEvent( Event * ) = 0; | 161 | virtual void deleteEvent( Event * ) = 0; |
161 | /** | 162 | /** |
162 | Retrieves an event on the basis of the unique string ID. | 163 | Retrieves an event on the basis of the unique string ID. |
163 | */ | 164 | */ |
164 | virtual Event *event( const QString &UniqueStr ) = 0; | 165 | virtual Event *event( const QString &UniqueStr ) = 0; |
165 | virtual Event *event( QString, QString ) = 0; | 166 | virtual Event *event( QString, QString ) = 0; |
166 | /** | 167 | /** |
167 | Builds and then returns a list of all events that match for the | 168 | Builds and then returns a list of all events that match for the |
168 | date specified. useful for dayView, etc. etc. | 169 | date specified. useful for dayView, etc. etc. |
169 | The calendar filter is applied. | 170 | The calendar filter is applied. |
170 | */ | 171 | */ |
171 | QPtrList<Event> events( const QDate &date, bool sorted = false); | 172 | QPtrList<Event> events( const QDate &date, bool sorted = false); |
172 | /** | 173 | /** |
173 | Get events, which occur on the given date. | 174 | Get events, which occur on the given date. |
174 | The calendar filter is applied. | 175 | The calendar filter is applied. |
175 | */ | 176 | */ |
176 | QPtrList<Event> events( const QDateTime &qdt ); | 177 | QPtrList<Event> events( const QDateTime &qdt ); |
177 | /** | 178 | /** |
178 | Get events in a range of dates. If inclusive is set to true, only events | 179 | Get events in a range of dates. If inclusive is set to true, only events |
179 | are returned, which are completely included in the range. | 180 | are returned, which are completely included in the range. |
180 | The calendar filter is applied. | 181 | The calendar filter is applied. |
181 | */ | 182 | */ |
182 | QPtrList<Event> events( const QDate &start, const QDate &end, | 183 | QPtrList<Event> events( const QDate &start, const QDate &end, |
183 | bool inclusive = false); | 184 | bool inclusive = false); |
184 | /** | 185 | /** |
185 | Return filtered list of all events in calendar. | 186 | Return filtered list of all events in calendar. |
186 | */ | 187 | */ |
187 | virtual QPtrList<Event> events(); | 188 | virtual QPtrList<Event> events(); |
188 | /** | 189 | /** |
189 | Return unfiltered list of all events in calendar. | 190 | Return unfiltered list of all events in calendar. |
190 | */ | 191 | */ |
191 | virtual QPtrList<Event> rawEvents() = 0; | 192 | virtual QPtrList<Event> rawEvents() = 0; |
192 | 193 | ||
193 | /** | 194 | /** |
194 | Add a todo to the todolist. | 195 | Add a todo to the todolist. |
195 | 196 | ||
196 | @return true on success, false on error. | 197 | @return true on success, false on error. |
197 | */ | 198 | */ |
198 | virtual bool addTodo( Todo *todo ) = 0; | 199 | virtual bool addTodo( Todo *todo ) = 0; |
199 | virtual bool addTodoNoDup( Todo *todo ) = 0; | 200 | virtual bool addTodoNoDup( Todo *todo ) = 0; |
200 | /** | 201 | /** |
201 | Remove a todo from the todolist. | 202 | Remove a todo from the todolist. |
202 | */ | 203 | */ |
203 | virtual void deleteTodo( Todo * ) = 0; | 204 | virtual void deleteTodo( Todo * ) = 0; |
204 | virtual void deleteJournal( Journal * ) = 0; | 205 | virtual void deleteJournal( Journal * ) = 0; |
205 | /** | 206 | /** |
206 | Return filterd list of todos. | 207 | Return filterd list of todos. |
207 | */ | 208 | */ |
208 | virtual QPtrList<Todo> todos(); | 209 | virtual QPtrList<Todo> todos(); |
209 | /** | 210 | /** |
210 | Searches todolist for an event with this unique string identifier, | 211 | Searches todolist for an event with this unique string identifier, |
211 | returns a pointer or null. | 212 | returns a pointer or null. |
212 | */ | 213 | */ |
213 | virtual Todo *todo( const QString &uid ) = 0; | 214 | virtual Todo *todo( const QString &uid ) = 0; |
214 | virtual Todo *todo( QString, QString ) = 0; | 215 | virtual Todo *todo( QString, QString ) = 0; |
215 | /** | 216 | /** |
216 | Returns list of todos due on the specified date. | 217 | Returns list of todos due on the specified date. |
217 | */ | 218 | */ |
218 | virtual QPtrList<Todo> todos( const QDate &date ) = 0; | 219 | virtual QPtrList<Todo> todos( const QDate &date ) = 0; |
219 | /** | 220 | /** |
220 | Return unfiltered list of todos. | 221 | Return unfiltered list of todos. |
221 | */ | 222 | */ |
222 | virtual QPtrList<Todo> rawTodos() = 0; | 223 | virtual QPtrList<Todo> rawTodos() = 0; |
223 | 224 | ||
224 | /** | 225 | /** |
225 | Add a Journal entry to calendar. | 226 | Add a Journal entry to calendar. |
226 | 227 | ||
227 | @return true on success, false on error. | 228 | @return true on success, false on error. |
228 | */ | 229 | */ |
229 | virtual bool addJournal( Journal * ) = 0; | 230 | virtual bool addJournal( Journal * ) = 0; |
230 | /** | 231 | /** |
231 | Return Journal for given date. | 232 | Return Journal for given date. |
232 | */ | 233 | */ |
233 | virtual Journal *journal( const QDate & ) = 0; | 234 | virtual Journal *journal( const QDate & ) = 0; |
234 | /** | 235 | /** |
235 | Return Journal with given UID. | 236 | Return Journal with given UID. |
236 | */ | 237 | */ |
237 | virtual Journal *journal( const QString &UID ) = 0; | 238 | virtual Journal *journal( const QString &UID ) = 0; |
238 | /** | 239 | /** |
239 | Return list of all Journal entries. | 240 | Return list of all Journal entries. |
240 | */ | 241 | */ |
241 | virtual QPtrList<Journal> journals() = 0; | 242 | virtual QPtrList<Journal> journals() = 0; |
242 | 243 | ||
243 | /** | 244 | /** |
244 | Searches all incidence types for an incidence with this unique | 245 | Searches all incidence types for an incidence with this unique |
245 | string identifier, returns a pointer or null. | 246 | string identifier, returns a pointer or null. |
246 | */ | 247 | */ |
247 | Incidence* incidence( const QString&UID ); | 248 | Incidence* incidence( const QString&UID ); |
248 | 249 | ||
249 | /** | 250 | /** |
250 | Setup relations for an incidence. | 251 | Setup relations for an incidence. |
251 | */ | 252 | */ |
252 | virtual void setupRelations( Incidence * ); | 253 | virtual void setupRelations( Incidence * ); |
253 | /** | 254 | /** |
254 | Remove all relations to an incidence | 255 | Remove all relations to an incidence |
255 | */ | 256 | */ |
256 | virtual void removeRelations( Incidence * ); | 257 | virtual void removeRelations( Incidence * ); |
257 | 258 | ||
258 | /** | 259 | /** |
259 | Set calendar filter, which filters events for the events() functions. | 260 | Set calendar filter, which filters events for the events() functions. |
260 | The Filter object is owned by the caller. | 261 | The Filter object is owned by the caller. |
261 | */ | 262 | */ |
262 | void setFilter( CalFilter * ); | 263 | void setFilter( CalFilter * ); |
263 | /** | 264 | /** |
264 | Return calendar filter. | 265 | Return calendar filter. |
265 | */ | 266 | */ |
266 | CalFilter *filter(); | 267 | CalFilter *filter(); |
267 | virtual QDateTime nextAlarm( int daysTo ) = 0; | 268 | virtual QDateTime nextAlarm( int daysTo ) = 0; |
268 | virtual QString nextSummary( ) const = 0; | 269 | virtual QString nextSummary( ) const = 0; |
269 | virtual void reInitAlarmSettings() = 0; | 270 | virtual void reInitAlarmSettings() = 0; |
270 | virtual QDateTime nextAlarmEventDateTime() const = 0; | 271 | virtual QDateTime nextAlarmEventDateTime() const = 0; |
271 | virtual void checkAlarmForIncidence( Incidence *, bool ) = 0; | 272 | virtual void checkAlarmForIncidence( Incidence *, bool ) = 0; |
272 | /** | 273 | /** |
273 | Return all alarms, which ocur in the given time interval. | 274 | Return all alarms, which ocur in the given time interval. |
274 | */ | 275 | */ |
275 | virtual Alarm::List alarms( const QDateTime &from, | 276 | virtual Alarm::List alarms( const QDateTime &from, |
276 | const QDateTime &to ) = 0; | 277 | const QDateTime &to ) = 0; |
277 | 278 | ||
278 | class Observer { | 279 | class Observer { |
279 | public: | 280 | public: |
280 | virtual void calendarModified( bool, Calendar * ) = 0; | 281 | virtual void calendarModified( bool, Calendar * ) = 0; |
281 | }; | 282 | }; |
282 | 283 | ||
283 | void registerObserver( Observer * ); | 284 | void registerObserver( Observer * ); |
284 | 285 | ||
285 | void setModified( bool ); | 286 | void setModified( bool ); |
286 | 287 | ||
287 | /** | 288 | /** |
288 | Set product id returned by loadedProductId(). This function is only | 289 | Set product id returned by loadedProductId(). This function is only |
289 | useful for the calendar loading code. | 290 | useful for the calendar loading code. |
290 | */ | 291 | */ |
291 | void setLoadedProductId( const QString & ); | 292 | void setLoadedProductId( const QString & ); |
292 | /** | 293 | /** |
293 | Return product id taken from file that has been loaded. Returns | 294 | Return product id taken from file that has been loaded. Returns |
294 | QString::null, if no calendar has been loaded. | 295 | QString::null, if no calendar has been loaded. |
295 | */ | 296 | */ |
296 | QString loadedProductId(); | 297 | QString loadedProductId(); |
297 | 298 | ||
298 | signals: | 299 | signals: |
299 | void calendarChanged(); | 300 | void calendarChanged(); |
300 | void calendarSaved(); | 301 | void calendarSaved(); |
301 | void calendarLoaded(); | 302 | void calendarLoaded(); |
302 | void addAlarm(const QDateTime &qdt, const QString ¬i ); | 303 | void addAlarm(const QDateTime &qdt, const QString ¬i ); |
303 | void removeAlarm(const QDateTime &qdt, const QString ¬i ); | 304 | void removeAlarm(const QDateTime &qdt, const QString ¬i ); |
304 | 305 | ||
305 | protected: | 306 | protected: |
306 | /** | 307 | /** |
307 | Get unfiltered events, which occur on the given date. | 308 | Get unfiltered events, which occur on the given date. |
308 | */ | 309 | */ |
309 | virtual QPtrList<Event> rawEventsForDate( const QDateTime &qdt ) = 0; | 310 | virtual QPtrList<Event> rawEventsForDate( const QDateTime &qdt ) = 0; |
310 | /** | 311 | /** |
311 | Get unfiltered events, which occur on the given date. | 312 | Get unfiltered events, which occur on the given date. |
312 | */ | 313 | */ |
313 | virtual QPtrList<Event> rawEventsForDate( const QDate &date, | 314 | virtual QPtrList<Event> rawEventsForDate( const QDate &date, |
314 | bool sorted = false ) = 0; | 315 | bool sorted = false ) = 0; |
315 | /** | 316 | /** |
316 | Get events in a range of dates. If inclusive is set to true, only events | 317 | Get events in a range of dates. If inclusive is set to true, only events |
317 | are returned, which are completely included in the range. | 318 | are returned, which are completely included in the range. |
318 | */ | 319 | */ |
319 | virtual QPtrList<Event> rawEvents( const QDate &start, const QDate &end, | 320 | virtual QPtrList<Event> rawEvents( const QDate &start, const QDate &end, |
320 | bool inclusive = false ) = 0; | 321 | bool inclusive = false ) = 0; |
321 | Incidence *mNextAlarmIncidence; | 322 | Incidence *mNextAlarmIncidence; |
322 | 323 | ||
323 | private: | 324 | private: |
324 | void init(); | 325 | void init(); |
325 | 326 | ||
326 | QString mOwner; // who the calendar belongs to | 327 | QString mOwner; // who the calendar belongs to |
327 | QString mOwnerEmail; // email address of the owner | 328 | QString mOwnerEmail; // email address of the owner |
328 | int mTimeZone; // timezone OFFSET from GMT (MINUTES) | 329 | int mTimeZone; // timezone OFFSET from GMT (MINUTES) |
329 | bool mLocalTime; // use local time, not UTC or a time zone | 330 | bool mLocalTime; // use local time, not UTC or a time zone |
330 | 331 | ||
331 | CalFilter *mFilter; | 332 | CalFilter *mFilter; |
332 | CalFilter *mDefaultFilter; | 333 | CalFilter *mDefaultFilter; |
333 | 334 | ||
334 | QString mTimeZoneId; | 335 | QString mTimeZoneId; |
335 | 336 | ||
336 | Observer *mObserver; | 337 | Observer *mObserver; |
337 | bool mNewObserver; | 338 | bool mNewObserver; |
338 | 339 | ||
339 | bool mModified; | 340 | bool mModified; |
340 | 341 | ||
341 | QString mLoadedProductId; | 342 | QString mLoadedProductId; |
342 | 343 | ||
343 | // This list is used to put together related todos | 344 | // This list is used to put together related todos |
344 | QDict<Incidence> mOrphans; | 345 | QDict<Incidence> mOrphans; |
345 | QDict<Incidence> mOrphanUids; | 346 | QDict<Incidence> mOrphanUids; |
346 | }; | 347 | }; |
347 | 348 | ||
348 | } | 349 | } |
349 | 350 | ||
350 | #endif | 351 | #endif |
diff --git a/libkcal/incidencebase.cpp b/libkcal/incidencebase.cpp index 15c4fa8..64a343c 100644 --- a/libkcal/incidencebase.cpp +++ b/libkcal/incidencebase.cpp | |||
@@ -1,406 +1,407 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | #include <kglobal.h> | 21 | #include <kglobal.h> |
22 | #include <klocale.h> | 22 | #include <klocale.h> |
23 | #include <kdebug.h> | 23 | #include <kdebug.h> |
24 | #include <kidmanager.h> | 24 | #include <kidmanager.h> |
25 | 25 | ||
26 | #include "calformat.h" | 26 | #include "calformat.h" |
27 | #include "syncdefines.h" | ||
27 | 28 | ||
28 | #include "incidencebase.h" | 29 | #include "incidencebase.h" |
29 | 30 | ||
30 | using namespace KCal; | 31 | using namespace KCal; |
31 | 32 | ||
32 | IncidenceBase::IncidenceBase() : | 33 | IncidenceBase::IncidenceBase() : |
33 | mReadOnly(false), mFloats(true), mDuration(0), mHasDuration(false), | 34 | mReadOnly(false), mFloats(true), mDuration(0), mHasDuration(false), |
34 | mPilotId(0), mSyncStatus(SYNCMOD) | 35 | mPilotId(0), mSyncStatus(SYNCMOD) |
35 | { | 36 | { |
36 | setUid(CalFormat::createUniqueId()); | 37 | setUid(CalFormat::createUniqueId()); |
37 | mOrganizer = ""; | 38 | mOrganizer = ""; |
38 | mFloats = false; | 39 | mFloats = false; |
39 | mDuration = 0; | 40 | mDuration = 0; |
40 | mHasDuration = false; | 41 | mHasDuration = false; |
41 | mPilotId = 0; | 42 | mPilotId = 0; |
42 | mExternalId = ":"; | 43 | mExternalId = ":"; |
43 | mTempSyncStat = 0; | 44 | mTempSyncStat = SYNC_TEMPSTATE_INITIAL; |
44 | mSyncStatus = 0; | 45 | mSyncStatus = 0; |
45 | mAttendees.setAutoDelete( true ); | 46 | mAttendees.setAutoDelete( true ); |
46 | } | 47 | } |
47 | 48 | ||
48 | IncidenceBase::IncidenceBase(const IncidenceBase &i) : | 49 | IncidenceBase::IncidenceBase(const IncidenceBase &i) : |
49 | CustomProperties( i ) | 50 | CustomProperties( i ) |
50 | { | 51 | { |
51 | mReadOnly = i.mReadOnly; | 52 | mReadOnly = i.mReadOnly; |
52 | mDtStart = i.mDtStart; | 53 | mDtStart = i.mDtStart; |
53 | mDuration = i.mDuration; | 54 | mDuration = i.mDuration; |
54 | mHasDuration = i.mHasDuration; | 55 | mHasDuration = i.mHasDuration; |
55 | mOrganizer = i.mOrganizer; | 56 | mOrganizer = i.mOrganizer; |
56 | mUid = i.mUid; | 57 | mUid = i.mUid; |
57 | QPtrList<Attendee> attendees = i.attendees(); | 58 | QPtrList<Attendee> attendees = i.attendees(); |
58 | for( Attendee *a = attendees.first(); a; a = attendees.next() ) { | 59 | for( Attendee *a = attendees.first(); a; a = attendees.next() ) { |
59 | mAttendees.append( new Attendee( *a ) ); | 60 | mAttendees.append( new Attendee( *a ) ); |
60 | } | 61 | } |
61 | mFloats = i.mFloats; | 62 | mFloats = i.mFloats; |
62 | mLastModified = i.mLastModified; | 63 | mLastModified = i.mLastModified; |
63 | mPilotId = i.mPilotId; | 64 | mPilotId = i.mPilotId; |
64 | mTempSyncStat = i.mTempSyncStat; | 65 | mTempSyncStat = i.mTempSyncStat; |
65 | mSyncStatus = i.mSyncStatus; | 66 | mSyncStatus = i.mSyncStatus; |
66 | mExternalId = i.mExternalId; | 67 | mExternalId = i.mExternalId; |
67 | // The copied object is a new one, so it isn't observed by the observer | 68 | // The copied object is a new one, so it isn't observed by the observer |
68 | // of the original object. | 69 | // of the original object. |
69 | mObservers.clear(); | 70 | mObservers.clear(); |
70 | 71 | ||
71 | mAttendees.setAutoDelete( true ); | 72 | mAttendees.setAutoDelete( true ); |
72 | } | 73 | } |
73 | 74 | ||
74 | IncidenceBase::~IncidenceBase() | 75 | IncidenceBase::~IncidenceBase() |
75 | { | 76 | { |
76 | } | 77 | } |
77 | 78 | ||
78 | 79 | ||
79 | bool KCal::operator==( const IncidenceBase& i1, const IncidenceBase& i2 ) | 80 | bool KCal::operator==( const IncidenceBase& i1, const IncidenceBase& i2 ) |
80 | { | 81 | { |
81 | // do not compare mSyncStatus and mExternalId | 82 | // do not compare mSyncStatus and mExternalId |
82 | if( i1.attendees().count() != i2.attendees().count() ) { | 83 | if( i1.attendees().count() != i2.attendees().count() ) { |
83 | return false; // no need to check further | 84 | return false; // no need to check further |
84 | } | 85 | } |
85 | if ( i1.attendees().count() > 0 ) { | 86 | if ( i1.attendees().count() > 0 ) { |
86 | Attendee * a1 = i1.attendees().first(), *a2 =i2.attendees().first() ; | 87 | Attendee * a1 = i1.attendees().first(), *a2 =i2.attendees().first() ; |
87 | while ( a1 ) { | 88 | while ( a1 ) { |
88 | if ( !( (*a1) == (*a2)) ) | 89 | if ( !( (*a1) == (*a2)) ) |
89 | { | 90 | { |
90 | //qDebug("Attendee not equal "); | 91 | //qDebug("Attendee not equal "); |
91 | return false; | 92 | return false; |
92 | } | 93 | } |
93 | a1 = i1.attendees().next(); | 94 | a1 = i1.attendees().next(); |
94 | a2 = i2.attendees().next(); | 95 | a2 = i2.attendees().next(); |
95 | } | 96 | } |
96 | } | 97 | } |
97 | //if ( i1.dtStart() != i2.dtStart() ) | 98 | //if ( i1.dtStart() != i2.dtStart() ) |
98 | // return false; | 99 | // return false; |
99 | #if 0 | 100 | #if 0 |
100 | qDebug("1 %d ",i1.doesFloat() == i2.doesFloat() ); | 101 | qDebug("1 %d ",i1.doesFloat() == i2.doesFloat() ); |
101 | qDebug("1 %d ",i1.duration() == i2.duration() ); | 102 | qDebug("1 %d ",i1.duration() == i2.duration() ); |
102 | qDebug("3 %d ",i1.hasDuration() == i2.hasDuration() ); | 103 | qDebug("3 %d ",i1.hasDuration() == i2.hasDuration() ); |
103 | qDebug("1 %d ",i1.pilotId() == i2.pilotId() ); | 104 | qDebug("1 %d ",i1.pilotId() == i2.pilotId() ); |
104 | qDebug("1 %d %d %d",i1.syncStatus() == i2.syncStatus() , i1.syncStatus(),i2.syncStatus() ); | 105 | qDebug("1 %d %d %d",i1.syncStatus() == i2.syncStatus() , i1.syncStatus(),i2.syncStatus() ); |
105 | qDebug("6 %d ",i1.organizer() == i2.organizer() ); | 106 | qDebug("6 %d ",i1.organizer() == i2.organizer() ); |
106 | 107 | ||
107 | #endif | 108 | #endif |
108 | return ( i1.organizer() == i2.organizer() && | 109 | return ( i1.organizer() == i2.organizer() && |
109 | // i1.uid() == i2.uid() && | 110 | // i1.uid() == i2.uid() && |
110 | // Don't compare lastModified, otherwise the operator is not | 111 | // Don't compare lastModified, otherwise the operator is not |
111 | // of much use. We are not comparing for identity, after all. | 112 | // of much use. We are not comparing for identity, after all. |
112 | i1.doesFloat() == i2.doesFloat() && | 113 | i1.doesFloat() == i2.doesFloat() && |
113 | i1.duration() == i2.duration() && | 114 | i1.duration() == i2.duration() && |
114 | i1.hasDuration() == i2.hasDuration() && | 115 | i1.hasDuration() == i2.hasDuration() && |
115 | i1.pilotId() == i2.pilotId() );// && i1.syncStatus() == i2.syncStatus() ); | 116 | i1.pilotId() == i2.pilotId() );// && i1.syncStatus() == i2.syncStatus() ); |
116 | // no need to compare mObserver | 117 | // no need to compare mObserver |
117 | } | 118 | } |
118 | 119 | ||
119 | 120 | ||
120 | QDateTime IncidenceBase::getEvenTime( QDateTime dt ) | 121 | QDateTime IncidenceBase::getEvenTime( QDateTime dt ) |
121 | { | 122 | { |
122 | QTime t = dt.time(); | 123 | QTime t = dt.time(); |
123 | dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); | 124 | dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); |
124 | return dt; | 125 | return dt; |
125 | } | 126 | } |
126 | 127 | ||
127 | 128 | ||
128 | void IncidenceBase::setUid(const QString &uid) | 129 | void IncidenceBase::setUid(const QString &uid) |
129 | { | 130 | { |
130 | mUid = uid; | 131 | mUid = uid; |
131 | updated(); | 132 | updated(); |
132 | } | 133 | } |
133 | 134 | ||
134 | QString IncidenceBase::uid() const | 135 | QString IncidenceBase::uid() const |
135 | { | 136 | { |
136 | return mUid; | 137 | return mUid; |
137 | } | 138 | } |
138 | 139 | ||
139 | void IncidenceBase::setLastModified(const QDateTime &lm) | 140 | void IncidenceBase::setLastModified(const QDateTime &lm) |
140 | { | 141 | { |
141 | // DON'T! updated() because we call this from | 142 | // DON'T! updated() because we call this from |
142 | // Calendar::updateEvent(). | 143 | // Calendar::updateEvent(). |
143 | mLastModified = getEvenTime(lm); | 144 | mLastModified = getEvenTime(lm); |
144 | //qDebug("IncidenceBase::setLastModified %s ",lm.toString().latin1()); | 145 | //qDebug("IncidenceBase::setLastModified %s ",lm.toString().latin1()); |
145 | } | 146 | } |
146 | 147 | ||
147 | QDateTime IncidenceBase::lastModified() const | 148 | QDateTime IncidenceBase::lastModified() const |
148 | { | 149 | { |
149 | return mLastModified; | 150 | return mLastModified; |
150 | } | 151 | } |
151 | 152 | ||
152 | void IncidenceBase::setOrganizer(const QString &o) | 153 | void IncidenceBase::setOrganizer(const QString &o) |
153 | { | 154 | { |
154 | // we don't check for readonly here, because it is | 155 | // we don't check for readonly here, because it is |
155 | // possible that by setting the organizer we are changing | 156 | // possible that by setting the organizer we are changing |
156 | // the event's readonly status... | 157 | // the event's readonly status... |
157 | mOrganizer = o; | 158 | mOrganizer = o; |
158 | if (mOrganizer.left(7).upper() == "MAILTO:") | 159 | if (mOrganizer.left(7).upper() == "MAILTO:") |
159 | mOrganizer = mOrganizer.remove(0,7); | 160 | mOrganizer = mOrganizer.remove(0,7); |
160 | 161 | ||
161 | updated(); | 162 | updated(); |
162 | } | 163 | } |
163 | 164 | ||
164 | QString IncidenceBase::organizer() const | 165 | QString IncidenceBase::organizer() const |
165 | { | 166 | { |
166 | return mOrganizer; | 167 | return mOrganizer; |
167 | } | 168 | } |
168 | 169 | ||
169 | void IncidenceBase::setReadOnly( bool readOnly ) | 170 | void IncidenceBase::setReadOnly( bool readOnly ) |
170 | { | 171 | { |
171 | mReadOnly = readOnly; | 172 | mReadOnly = readOnly; |
172 | } | 173 | } |
173 | 174 | ||
174 | void IncidenceBase::setDtStart(const QDateTime &dtStart) | 175 | void IncidenceBase::setDtStart(const QDateTime &dtStart) |
175 | { | 176 | { |
176 | // if (mReadOnly) return; | 177 | // if (mReadOnly) return; |
177 | mDtStart = getEvenTime(dtStart); | 178 | mDtStart = getEvenTime(dtStart); |
178 | updated(); | 179 | updated(); |
179 | } | 180 | } |
180 | 181 | ||
181 | QDateTime IncidenceBase::dtStart() const | 182 | QDateTime IncidenceBase::dtStart() const |
182 | { | 183 | { |
183 | return mDtStart; | 184 | return mDtStart; |
184 | } | 185 | } |
185 | 186 | ||
186 | QString IncidenceBase::dtStartTimeStr() const | 187 | QString IncidenceBase::dtStartTimeStr() const |
187 | { | 188 | { |
188 | return KGlobal::locale()->formatTime(dtStart().time()); | 189 | return KGlobal::locale()->formatTime(dtStart().time()); |
189 | } | 190 | } |
190 | 191 | ||
191 | QString IncidenceBase::dtStartDateStr(bool shortfmt) const | 192 | QString IncidenceBase::dtStartDateStr(bool shortfmt) const |
192 | { | 193 | { |
193 | return KGlobal::locale()->formatDate(dtStart().date(),shortfmt); | 194 | return KGlobal::locale()->formatDate(dtStart().date(),shortfmt); |
194 | } | 195 | } |
195 | 196 | ||
196 | QString IncidenceBase::dtStartStr(bool shortfmt) const | 197 | QString IncidenceBase::dtStartStr(bool shortfmt) const |
197 | { | 198 | { |
198 | return KGlobal::locale()->formatDateTime(dtStart(), shortfmt); | 199 | return KGlobal::locale()->formatDateTime(dtStart(), shortfmt); |
199 | } | 200 | } |
200 | 201 | ||
201 | 202 | ||
202 | bool IncidenceBase::doesFloat() const | 203 | bool IncidenceBase::doesFloat() const |
203 | { | 204 | { |
204 | return mFloats; | 205 | return mFloats; |
205 | } | 206 | } |
206 | 207 | ||
207 | void IncidenceBase::setFloats(bool f) | 208 | void IncidenceBase::setFloats(bool f) |
208 | { | 209 | { |
209 | if (mReadOnly) return; | 210 | if (mReadOnly) return; |
210 | mFloats = f; | 211 | mFloats = f; |
211 | updated(); | 212 | updated(); |
212 | } | 213 | } |
213 | 214 | ||
214 | 215 | ||
215 | void IncidenceBase::addAttendee(Attendee *a, bool doupdate) | 216 | void IncidenceBase::addAttendee(Attendee *a, bool doupdate) |
216 | { | 217 | { |
217 | if (mReadOnly) return; | 218 | if (mReadOnly) return; |
218 | if (a->name().left(7).upper() == "MAILTO:") | 219 | if (a->name().left(7).upper() == "MAILTO:") |
219 | a->setName(a->name().remove(0,7)); | 220 | a->setName(a->name().remove(0,7)); |
220 | 221 | ||
221 | mAttendees.append(a); | 222 | mAttendees.append(a); |
222 | if (doupdate) updated(); | 223 | if (doupdate) updated(); |
223 | } | 224 | } |
224 | 225 | ||
225 | #if 0 | 226 | #if 0 |
226 | void IncidenceBase::removeAttendee(Attendee *a) | 227 | void IncidenceBase::removeAttendee(Attendee *a) |
227 | { | 228 | { |
228 | if (mReadOnly) return; | 229 | if (mReadOnly) return; |
229 | mAttendees.removeRef(a); | 230 | mAttendees.removeRef(a); |
230 | updated(); | 231 | updated(); |
231 | } | 232 | } |
232 | 233 | ||
233 | void IncidenceBase::removeAttendee(const char *n) | 234 | void IncidenceBase::removeAttendee(const char *n) |
234 | { | 235 | { |
235 | Attendee *a; | 236 | Attendee *a; |
236 | 237 | ||
237 | if (mReadOnly) return; | 238 | if (mReadOnly) return; |
238 | for (a = mAttendees.first(); a; a = mAttendees.next()) | 239 | for (a = mAttendees.first(); a; a = mAttendees.next()) |
239 | if (a->getName() == n) { | 240 | if (a->getName() == n) { |
240 | mAttendees.remove(); | 241 | mAttendees.remove(); |
241 | break; | 242 | break; |
242 | } | 243 | } |
243 | } | 244 | } |
244 | #endif | 245 | #endif |
245 | 246 | ||
246 | void IncidenceBase::clearAttendees() | 247 | void IncidenceBase::clearAttendees() |
247 | { | 248 | { |
248 | if (mReadOnly) return; | 249 | if (mReadOnly) return; |
249 | mAttendees.clear(); | 250 | mAttendees.clear(); |
250 | } | 251 | } |
251 | 252 | ||
252 | #if 0 | 253 | #if 0 |
253 | Attendee *IncidenceBase::getAttendee(const char *n) const | 254 | Attendee *IncidenceBase::getAttendee(const char *n) const |
254 | { | 255 | { |
255 | QPtrListIterator<Attendee> qli(mAttendees); | 256 | QPtrListIterator<Attendee> qli(mAttendees); |
256 | 257 | ||
257 | qli.toFirst(); | 258 | qli.toFirst(); |
258 | while (qli) { | 259 | while (qli) { |
259 | if (qli.current()->getName() == n) | 260 | if (qli.current()->getName() == n) |
260 | return qli.current(); | 261 | return qli.current(); |
261 | ++qli; | 262 | ++qli; |
262 | } | 263 | } |
263 | return 0L; | 264 | return 0L; |
264 | } | 265 | } |
265 | #endif | 266 | #endif |
266 | 267 | ||
267 | Attendee *IncidenceBase::attendeeByMail(const QString &email) | 268 | Attendee *IncidenceBase::attendeeByMail(const QString &email) |
268 | { | 269 | { |
269 | QPtrListIterator<Attendee> qli(mAttendees); | 270 | QPtrListIterator<Attendee> qli(mAttendees); |
270 | 271 | ||
271 | qli.toFirst(); | 272 | qli.toFirst(); |
272 | while (qli) { | 273 | while (qli) { |
273 | if (qli.current()->email() == email) | 274 | if (qli.current()->email() == email) |
274 | return qli.current(); | 275 | return qli.current(); |
275 | ++qli; | 276 | ++qli; |
276 | } | 277 | } |
277 | return 0L; | 278 | return 0L; |
278 | } | 279 | } |
279 | 280 | ||
280 | Attendee *IncidenceBase::attendeeByMails(const QStringList &emails, const QString& email) | 281 | Attendee *IncidenceBase::attendeeByMails(const QStringList &emails, const QString& email) |
281 | { | 282 | { |
282 | QPtrListIterator<Attendee> qli(mAttendees); | 283 | QPtrListIterator<Attendee> qli(mAttendees); |
283 | 284 | ||
284 | QStringList mails = emails; | 285 | QStringList mails = emails; |
285 | if (!email.isEmpty()) { | 286 | if (!email.isEmpty()) { |
286 | mails.append(email); | 287 | mails.append(email); |
287 | } | 288 | } |
288 | qli.toFirst(); | 289 | qli.toFirst(); |
289 | while (qli) { | 290 | while (qli) { |
290 | for ( QStringList::Iterator it = mails.begin(); it != mails.end(); ++it ) { | 291 | for ( QStringList::Iterator it = mails.begin(); it != mails.end(); ++it ) { |
291 | if (qli.current()->email() == *it) | 292 | if (qli.current()->email() == *it) |
292 | return qli.current(); | 293 | return qli.current(); |
293 | } | 294 | } |
294 | 295 | ||
295 | ++qli; | 296 | ++qli; |
296 | } | 297 | } |
297 | return 0L; | 298 | return 0L; |
298 | } | 299 | } |
299 | 300 | ||
300 | void IncidenceBase::setDuration(int seconds) | 301 | void IncidenceBase::setDuration(int seconds) |
301 | { | 302 | { |
302 | mDuration = seconds; | 303 | mDuration = seconds; |
303 | setHasDuration(true); | 304 | setHasDuration(true); |
304 | } | 305 | } |
305 | 306 | ||
306 | int IncidenceBase::duration() const | 307 | int IncidenceBase::duration() const |
307 | { | 308 | { |
308 | return mDuration; | 309 | return mDuration; |
309 | } | 310 | } |
310 | 311 | ||
311 | void IncidenceBase::setHasDuration(bool b) | 312 | void IncidenceBase::setHasDuration(bool b) |
312 | { | 313 | { |
313 | mHasDuration = b; | 314 | mHasDuration = b; |
314 | } | 315 | } |
315 | 316 | ||
316 | bool IncidenceBase::hasDuration() const | 317 | bool IncidenceBase::hasDuration() const |
317 | { | 318 | { |
318 | return mHasDuration; | 319 | return mHasDuration; |
319 | } | 320 | } |
320 | 321 | ||
321 | void IncidenceBase::setSyncStatus(int stat) | 322 | void IncidenceBase::setSyncStatus(int stat) |
322 | { | 323 | { |
323 | if (mReadOnly) return; | 324 | if (mReadOnly) return; |
324 | mSyncStatus = stat; | 325 | mSyncStatus = stat; |
325 | } | 326 | } |
326 | 327 | ||
327 | int IncidenceBase::syncStatus() const | 328 | int IncidenceBase::syncStatus() const |
328 | { | 329 | { |
329 | return mSyncStatus; | 330 | return mSyncStatus; |
330 | } | 331 | } |
331 | 332 | ||
332 | void IncidenceBase::setPilotId( int id ) | 333 | void IncidenceBase::setPilotId( int id ) |
333 | { | 334 | { |
334 | if (mReadOnly) return; | 335 | if (mReadOnly) return; |
335 | mPilotId = id; | 336 | mPilotId = id; |
336 | } | 337 | } |
337 | 338 | ||
338 | int IncidenceBase::pilotId() const | 339 | int IncidenceBase::pilotId() const |
339 | { | 340 | { |
340 | return mPilotId; | 341 | return mPilotId; |
341 | } | 342 | } |
342 | 343 | ||
343 | int IncidenceBase::tempSyncStat() const | 344 | int IncidenceBase::tempSyncStat() const |
344 | { | 345 | { |
345 | return mTempSyncStat; | 346 | return mTempSyncStat; |
346 | } | 347 | } |
347 | void IncidenceBase::setTempSyncStat( int id ) | 348 | void IncidenceBase::setTempSyncStat( int id ) |
348 | { | 349 | { |
349 | if (mReadOnly) return; | 350 | if (mReadOnly) return; |
350 | mTempSyncStat = id; | 351 | mTempSyncStat = id; |
351 | } | 352 | } |
352 | 353 | ||
353 | void IncidenceBase::removeID(const QString &prof) | 354 | void IncidenceBase::removeID(const QString &prof) |
354 | { | 355 | { |
355 | mExternalId = KIdManager::removeId ( mExternalId, prof); | 356 | mExternalId = KIdManager::removeId ( mExternalId, prof); |
356 | 357 | ||
357 | } | 358 | } |
358 | void IncidenceBase::setID( const QString & prof , const QString & id ) | 359 | void IncidenceBase::setID( const QString & prof , const QString & id ) |
359 | { | 360 | { |
360 | mExternalId = KIdManager::setId ( mExternalId, prof, id ); | 361 | mExternalId = KIdManager::setId ( mExternalId, prof, id ); |
361 | } | 362 | } |
362 | QString IncidenceBase::getID( const QString & prof) | 363 | QString IncidenceBase::getID( const QString & prof) |
363 | { | 364 | { |
364 | return KIdManager::getId ( mExternalId, prof ); | 365 | return KIdManager::getId ( mExternalId, prof ); |
365 | } | 366 | } |
366 | 367 | ||
367 | // example :Sharp_DTM;22;23566:TP;-1;8654:TPP;18;0: | 368 | // example :Sharp_DTM;22;23566:TP;-1;8654:TPP;18;0: |
368 | // format name;III;JJJ: III >= 0, may be -1. JJJ always >= 0 | 369 | // format name;III;JJJ: III >= 0, may be -1. JJJ always >= 0 |
369 | void IncidenceBase::setCsum( const QString & prof , const QString & id ) | 370 | void IncidenceBase::setCsum( const QString & prof , const QString & id ) |
370 | { | 371 | { |
371 | mExternalId = KIdManager::setCsum ( mExternalId, prof, id ); | 372 | mExternalId = KIdManager::setCsum ( mExternalId, prof, id ); |
372 | } | 373 | } |
373 | QString IncidenceBase::getCsum( const QString & prof) | 374 | QString IncidenceBase::getCsum( const QString & prof) |
374 | { | 375 | { |
375 | return KIdManager::getCsum ( mExternalId, prof ); | 376 | return KIdManager::getCsum ( mExternalId, prof ); |
376 | } | 377 | } |
377 | 378 | ||
378 | void IncidenceBase::setIDStr( const QString & s ) | 379 | void IncidenceBase::setIDStr( const QString & s ) |
379 | { | 380 | { |
380 | if (mReadOnly) return; | 381 | if (mReadOnly) return; |
381 | mExternalId = s; | 382 | mExternalId = s; |
382 | } | 383 | } |
383 | 384 | ||
384 | QString IncidenceBase::IDStr() const | 385 | QString IncidenceBase::IDStr() const |
385 | { | 386 | { |
386 | return mExternalId ; | 387 | return mExternalId ; |
387 | } | 388 | } |
388 | void IncidenceBase::registerObserver( IncidenceBase::Observer *observer ) | 389 | void IncidenceBase::registerObserver( IncidenceBase::Observer *observer ) |
389 | { | 390 | { |
390 | if( !mObservers.contains(observer) ) mObservers.append( observer ); | 391 | if( !mObservers.contains(observer) ) mObservers.append( observer ); |
391 | } | 392 | } |
392 | 393 | ||
393 | void IncidenceBase::unRegisterObserver( IncidenceBase::Observer *observer ) | 394 | void IncidenceBase::unRegisterObserver( IncidenceBase::Observer *observer ) |
394 | { | 395 | { |
395 | mObservers.remove( observer ); | 396 | mObservers.remove( observer ); |
396 | } | 397 | } |
397 | 398 | ||
398 | void IncidenceBase::updated() | 399 | void IncidenceBase::updated() |
399 | { | 400 | { |
400 | QPtrListIterator<Observer> it(mObservers); | 401 | QPtrListIterator<Observer> it(mObservers); |
401 | while( it.current() ) { | 402 | while( it.current() ) { |
402 | Observer *o = it.current(); | 403 | Observer *o = it.current(); |
403 | ++it; | 404 | ++it; |
404 | o->incidenceUpdated( this ); | 405 | o->incidenceUpdated( this ); |
405 | } | 406 | } |
406 | } | 407 | } |
diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp index e6d4879..6bbc0a3 100644 --- a/libkcal/phoneformat.cpp +++ b/libkcal/phoneformat.cpp | |||
@@ -1,1266 +1,1427 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | 3 | ||
4 | Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> | 4 | Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> |
5 | 5 | ||
6 | This library is free software; you can redistribute it and/or | 6 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Library General Public | 7 | modify it under the terms of the GNU Library General Public |
8 | License as published by the Free Software Foundation; either | 8 | License as published by the Free Software Foundation; either |
9 | version 2 of the License, or (at your option) any later version. | 9 | version 2 of the License, or (at your option) any later version. |
10 | 10 | ||
11 | This library is distributed in the hope that it will be useful, | 11 | This library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Library General Public License for more details. | 14 | Library General Public License for more details. |
15 | 15 | ||
16 | You should have received a copy of the GNU Library General Public License | 16 | You should have received a copy of the GNU Library General Public License |
17 | along with this library; see the file COPYING.LIB. If not, write to | 17 | along with this library; see the file COPYING.LIB. If not, write to |
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
19 | Boston, MA 02111-1307, USA. | 19 | Boston, MA 02111-1307, USA. |
20 | */ | 20 | */ |
21 | 21 | ||
22 | #include <qdatetime.h> | 22 | #include <qdatetime.h> |
23 | #include <qstring.h> | 23 | #include <qstring.h> |
24 | #include <qapplication.h> | 24 | #include <qapplication.h> |
25 | #include <qptrlist.h> | 25 | #include <qptrlist.h> |
26 | #include <qregexp.h> | 26 | #include <qregexp.h> |
27 | #include <qmessagebox.h> | 27 | #include <qmessagebox.h> |
28 | #include <qclipboard.h> | 28 | #include <qclipboard.h> |
29 | #include <qfile.h> | 29 | #include <qfile.h> |
30 | #include <qtextstream.h> | 30 | #include <qtextstream.h> |
31 | #include <qtextcodec.h> | 31 | #include <qtextcodec.h> |
32 | #include <qxml.h> | 32 | #include <qxml.h> |
33 | #include <qlabel.h> | 33 | #include <qlabel.h> |
34 | 34 | ||
35 | #include <kdebug.h> | 35 | #include <kdebug.h> |
36 | #include <klocale.h> | 36 | #include <klocale.h> |
37 | #include <kglobal.h> | 37 | #include <kglobal.h> |
38 | 38 | ||
39 | #include "calendar.h" | 39 | #include "calendar.h" |
40 | #include "alarm.h" | 40 | #include "alarm.h" |
41 | #include "recurrence.h" | 41 | #include "recurrence.h" |
42 | #include "calendarlocal.h" | 42 | #include "calendarlocal.h" |
43 | 43 | ||
44 | #include "phoneformat.h" | 44 | #include "phoneformat.h" |
45 | #include "syncdefines.h" | 45 | #include "syncdefines.h" |
46 | 46 | ||
47 | using namespace KCal; | 47 | using namespace KCal; |
48 | 48 | ||
49 | class PhoneParser : public QObject | 49 | class PhoneParser : public QObject |
50 | { | 50 | { |
51 | public: | 51 | public: |
52 | PhoneParser( Calendar *calendar, QString profileName ) : mCalendar( calendar ), mProfileName ( profileName ) { | 52 | PhoneParser( Calendar *calendar, QString profileName ) : mCalendar( calendar ), mProfileName ( profileName ) { |
53 | ; | 53 | ; |
54 | } | 54 | } |
55 | bool readTodo( Calendar *existingCalendar,GSM_ToDoEntry *ToDo, GSM_StateMachine* s) | 55 | bool readTodo( Calendar *existingCalendar,GSM_ToDoEntry *ToDo, GSM_StateMachine* s) |
56 | { | 56 | { |
57 | 57 | ||
58 | int id = ToDo->Location; | 58 | int id = ToDo->Location; |
59 | Todo *todo; | 59 | Todo *todo; |
60 | todo = existingCalendar->todo( mProfileName ,QString::number( id ) ); | 60 | todo = existingCalendar->todo( mProfileName ,QString::number( id ) ); |
61 | if (todo ) | 61 | if (todo ) |
62 | todo = (Todo *)todo->clone(); | 62 | todo = (Todo *)todo->clone(); |
63 | else | 63 | else |
64 | todo = new Todo; | 64 | todo = new Todo; |
65 | todo->setID( mProfileName,QString::number( id ) ); | 65 | todo->setID( mProfileName,QString::number( id ) ); |
66 | todo->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL ); | 66 | todo->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL ); |
67 | int priority; | 67 | int priority; |
68 | switch (ToDo->Priority) { | 68 | switch (ToDo->Priority) { |
69 | case GSM_Priority_Low : priority = 1; break; | 69 | case GSM_Priority_Low : priority = 5; break; |
70 | case GSM_Priority_Medium : priority = 3; break; | 70 | case GSM_Priority_Medium : priority = 3; break; |
71 | case GSM_Priority_High : priority = 5; break; | 71 | case GSM_Priority_High : priority = 1; break; |
72 | default :priority = 3 ;break; | 72 | default :priority = 3 ;break; |
73 | } | 73 | } |
74 | todo->setPriority( priority ); | 74 | todo->setPriority( priority ); |
75 | GSM_Phone_Functions*Phone; | 75 | GSM_Phone_Functions*Phone; |
76 | Phone=s->Phone.Functions; | 76 | Phone=s->Phone.Functions; |
77 | int j; | 77 | int j; |
78 | GSM_DateTime* dtp; | 78 | GSM_DateTime* dtp; |
79 | bool alarm = false; | 79 | bool alarm = false; |
80 | QDateTime alarmDt; | 80 | QDateTime alarmDt; |
81 | GSM_Category Category; | 81 | GSM_Category Category; |
82 | int error; | 82 | int error; |
83 | for (j=0;j<ToDo->EntriesNum;j++) { | 83 | for (j=0;j<ToDo->EntriesNum;j++) { |
84 | 84 | ||
85 | //qDebug(" for todo %d",ToDo->Location ); | 85 | //qDebug(" for todo %d",ToDo->Location ); |
86 | switch (ToDo->Entries[j].EntryType) { | 86 | switch (ToDo->Entries[j].EntryType) { |
87 | case TODO_END_DATETIME: | 87 | case TODO_END_DATETIME: |
88 | dtp = &ToDo->Entries[j].Date ; | 88 | dtp = &ToDo->Entries[j].Date ; |
89 | todo->setDtDue (fromGSM ( dtp )); | 89 | todo->setDtDue (fromGSM ( dtp )); |
90 | break; | 90 | break; |
91 | case TODO_COMPLETED: | 91 | case TODO_COMPLETED: |
92 | if ( ToDo->Entries[j].Number == 1 ) { | 92 | if ( ToDo->Entries[j].Number == 1 ) { |
93 | todo->setCompleted( true ); | 93 | todo->setCompleted( true ); |
94 | } | 94 | } |
95 | else { | 95 | else { |
96 | todo->setCompleted( false ); | 96 | todo->setCompleted( false ); |
97 | } | 97 | } |
98 | break; | 98 | break; |
99 | case TODO_ALARM_DATETIME: | 99 | case TODO_ALARM_DATETIME: |
100 | dtp = &ToDo->Entries[j].Date ; | 100 | dtp = &ToDo->Entries[j].Date ; |
101 | alarm = true; | 101 | alarm = true; |
102 | alarmDt = fromGSM ( dtp ); | 102 | alarmDt = fromGSM ( dtp ); |
103 | break; | 103 | break; |
104 | case TODO_SILENT_ALARM_DATETIME: | 104 | case TODO_SILENT_ALARM_DATETIME: |
105 | dtp = &ToDo->Entries[j].Date ; | 105 | dtp = &ToDo->Entries[j].Date ; |
106 | alarm = true; | 106 | alarm = true; |
107 | alarmDt = fromGSM ( dtp ); | 107 | alarmDt = fromGSM ( dtp ); |
108 | break; | 108 | break; |
109 | case TODO_TEXT: | 109 | case TODO_TEXT: |
110 | //qDebug(" text *%s* ", (const char*) DecodeUnicodeConsole(ToDo->Entries[j].Text )); | 110 | //qDebug(" text *%s* ", (const char*) DecodeUnicodeConsole(ToDo->Entries[j].Text )); |
111 | todo->setSummary( QString::fromUtf8 ( (const char*)DecodeUnicodeConsole(ToDo->Entries[j].Text ))); | 111 | todo->setSummary( QString::fromUtf8 ( (const char*)DecodeUnicodeConsole(ToDo->Entries[j].Text ))); |
112 | break; | 112 | break; |
113 | case TODO_PRIVATE: | 113 | case TODO_PRIVATE: |
114 | if ( ToDo->Entries[j].Number == 1 ) | 114 | if ( ToDo->Entries[j].Number == 1 ) |
115 | todo->setSecrecy( Incidence::SecrecyPrivate ); | 115 | todo->setSecrecy( Incidence::SecrecyPrivate ); |
116 | else | 116 | else |
117 | todo->setSecrecy( Incidence::SecrecyPublic ); | 117 | todo->setSecrecy( Incidence::SecrecyPublic ); |
118 | break; | 118 | break; |
119 | case TODO_CATEGORY: | 119 | case TODO_CATEGORY: |
120 | Category.Location = ToDo->Entries[j].Number; | 120 | Category.Location = ToDo->Entries[j].Number; |
121 | Category.Type = Category_ToDo; | 121 | Category.Type = Category_ToDo; |
122 | error=Phone->GetCategory(s, &Category); | 122 | error=Phone->GetCategory(s, &Category); |
123 | if (error == ERR_NONE) { | 123 | if (error == ERR_NONE) { |
124 | QStringList cat = todo->categories(); | 124 | QStringList cat = todo->categories(); |
125 | QString nCat = QString ( (const char*)Category.Name ); | 125 | QString nCat = QString ( (const char*)Category.Name ); |
126 | if ( !nCat.isEmpty() ) | 126 | if ( !nCat.isEmpty() ) |
127 | if ( !cat.contains( nCat )) { | 127 | if ( !cat.contains( nCat )) { |
128 | cat << nCat; | 128 | cat << nCat; |
129 | todo->setCategories( cat ); | 129 | todo->setCategories( cat ); |
130 | } | 130 | } |
131 | } | 131 | } |
132 | break; | 132 | break; |
133 | case TODO_CONTACTID: | 133 | case TODO_CONTACTID: |
134 | #if 0 | 134 | #if 0 |
135 | // not supported | 135 | // not supported |
136 | entry.Location = ToDo->Entries[j].Number; | 136 | entry.Location = ToDo->Entries[j].Number; |
137 | entry.MemoryType = MEM_ME; | 137 | entry.MemoryType = MEM_ME; |
138 | error=Phone->GetMemory(s, &entry); | 138 | error=Phone->GetMemory(s, &entry); |
139 | if (error == ERR_NONE) { | 139 | if (error == ERR_NONE) { |
140 | name = GSM_PhonebookGetEntryName(&entry); | 140 | name = GSM_PhonebookGetEntryName(&entry); |
141 | if (name != NULL) { | 141 | if (name != NULL) { |
142 | printmsg("Contact ID : \"%s\" (%d)\n", DecodeUnicodeConsole(name), ToDo->Entries[j].Number); | 142 | printmsg("Contact ID : \"%s\" (%d)\n", DecodeUnicodeConsole(name), ToDo->Entries[j].Number); |
143 | } else { | 143 | } else { |
144 | printmsg("Contact ID : %d\n",ToDo->Entries[j].Number); | 144 | printmsg("Contact ID : %d\n",ToDo->Entries[j].Number); |
145 | } | 145 | } |
146 | } else { | 146 | } else { |
147 | printmsg("Contact : %d\n",ToDo->Entries[j].Number); | 147 | printmsg("Contact : %d\n",ToDo->Entries[j].Number); |
148 | } | 148 | } |
149 | #endif | 149 | #endif |
150 | break; | 150 | break; |
151 | case TODO_PHONE: | 151 | case TODO_PHONE: |
152 | #if 0 | 152 | #if 0 |
153 | // not supported | 153 | // not supported |
154 | printmsg("Phone : \"%s\"\n",DecodeUnicodeConsole(ToDo->Entries[j].Text)); | 154 | printmsg("Phone : \"%s\"\n",DecodeUnicodeConsole(ToDo->Entries[j].Text)); |
155 | #endif | 155 | #endif |
156 | break; | 156 | break; |
157 | } | 157 | } |
158 | } | 158 | } |
159 | QString alarmString = "na"; | 159 | QString alarmString = "na"; |
160 | if ( alarm ) { | 160 | if ( alarm ) { |
161 | Alarm *alarm; | 161 | Alarm *alarm; |
162 | if ( todo->alarms().count() > 0 ) | 162 | if ( todo->alarms().count() > 0 ) |
163 | alarm = todo->alarms().first(); | 163 | alarm = todo->alarms().first(); |
164 | else { | 164 | else { |
165 | alarm = new Alarm( todo ); | 165 | alarm = new Alarm( todo ); |
166 | todo->addAlarm( alarm ); | 166 | todo->addAlarm( alarm ); |
167 | } | 167 | } |
168 | alarm->setType( Alarm::Audio ); | 168 | alarm->setType( Alarm::Audio ); |
169 | alarm->setEnabled( true ); | 169 | alarm->setEnabled( true ); |
170 | int alarmOffset = alarmDt.secsTo( todo->dtStart() ); | 170 | int alarmOffset = alarmDt.secsTo( todo->dtStart() ); |
171 | alarm->setStartOffset( -alarmOffset ); | 171 | alarm->setStartOffset( -alarmOffset ); |
172 | alarmString = QString::number( alarmOffset ); | 172 | alarmString = QString::number( alarmOffset ); |
173 | } else { | 173 | } else { |
174 | Alarm *alarm; | 174 | Alarm *alarm; |
175 | if ( todo->alarms().count() > 0 ) { | 175 | if ( todo->alarms().count() > 0 ) { |
176 | alarm = todo->alarms().first(); | 176 | alarm = todo->alarms().first(); |
177 | alarm->setType( Alarm::Audio ); | 177 | alarm->setType( Alarm::Audio ); |
178 | alarm->setStartOffset( -60*15 ); | 178 | alarm->setStartOffset( -60*15 ); |
179 | alarm->setEnabled( false ); | 179 | alarm->setEnabled( false ); |
180 | } | 180 | } |
181 | } | 181 | } |
182 | // csum ***************************************** | 182 | // csum ***************************************** |
183 | uint cSum; | 183 | uint cSum; |
184 | cSum = PhoneFormat::getCsumTodo( todo ); | 184 | cSum = PhoneFormat::getCsumTodo( todo ); |
185 | todo->setCsum( mProfileName, QString::number( cSum )); | 185 | todo->setCsum( mProfileName, QString::number( cSum )); |
186 | todo->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); | 186 | todo->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); |
187 | mCalendar->addTodo( todo); | 187 | mCalendar->addTodo( todo); |
188 | 188 | ||
189 | return true; | 189 | return true; |
190 | } | 190 | } |
191 | bool readEvent( Calendar *existingCalendar, GSM_CalendarEntry*Note) | 191 | bool readEvent( Calendar *existingCalendar, GSM_CalendarEntry*Note) |
192 | { | 192 | { |
193 | 193 | ||
194 | int id = Note->Location; | 194 | int id = Note->Location; |
195 | Event *event; | 195 | Event *event; |
196 | event = existingCalendar->event( mProfileName ,QString::number( id ) ); | 196 | event = existingCalendar->event( mProfileName ,QString::number( id ) ); |
197 | if ( event ) | 197 | if ( event ) |
198 | event = (Event*)event->clone(); | 198 | event = (Event*)event->clone(); |
199 | else | 199 | else |
200 | event = new Event; | 200 | event = new Event; |
201 | event->setID( mProfileName,QString::number( id ) ); | 201 | event->setID( mProfileName,QString::number( id ) ); |
202 | event->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL ); | 202 | event->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL ); |
203 | 203 | ||
204 | 204 | ||
205 | int i = 0; | 205 | int i = 0; |
206 | bool repeating = false; | 206 | bool repeating = false; |
207 | int repeat_dayofweek = -1; | 207 | int repeat_dayofweek = -1; |
208 | int repeat_day = -1; | 208 | int repeat_day = -1; |
209 | int repeat_weekofmonth = -1; | 209 | int repeat_weekofmonth = -1; |
210 | int repeat_month = -1; | 210 | int repeat_month = -1; |
211 | int repeat_frequency = -1; | 211 | int repeat_frequency = -1; |
212 | int rec_type = -1; | 212 | int rec_type = -1; |
213 | GSM_DateTime repeat_startdate = {0,0,0,0,0,0,0}; | 213 | GSM_DateTime repeat_startdate = {0,0,0,0,0,0,0}; |
214 | GSM_DateTime repeat_stopdate = {0,0,0,0,0,0,0}; | 214 | GSM_DateTime repeat_stopdate = {0,0,0,0,0,0,0}; |
215 | GSM_DateTime* dtp; | 215 | GSM_DateTime* dtp; |
216 | bool alarm = false; | 216 | bool alarm = false; |
217 | QDateTime alarmDt; | 217 | QDateTime alarmDt; |
218 | repeat_startdate.Day= 0; | 218 | repeat_startdate.Day= 0; |
219 | repeat_stopdate.Day = 0; | 219 | repeat_stopdate.Day = 0; |
220 | for (i=0;i<Note->EntriesNum;i++) { | 220 | for (i=0;i<Note->EntriesNum;i++) { |
221 | 221 | ||
222 | //qDebug(" for ev"); | 222 | //qDebug(" for ev"); |
223 | switch (Note->Entries[i].EntryType) { | 223 | switch (Note->Entries[i].EntryType) { |
224 | case CAL_START_DATETIME: | 224 | case CAL_START_DATETIME: |
225 | dtp = &Note->Entries[i].Date ; | 225 | dtp = &Note->Entries[i].Date ; |
226 | if ( dtp->Hour > 24 ) { | 226 | if ( dtp->Hour > 24 ) { |
227 | event->setFloats( true ); | 227 | event->setFloats( true ); |
228 | event->setDtStart( QDateTime (datefromGSM ( dtp ), QTime(0,0,0 ))); | 228 | event->setDtStart( QDateTime (datefromGSM ( dtp ), QTime(0,0,0 ))); |
229 | } else { | 229 | } else { |
230 | event->setDtStart (fromGSM ( dtp )); | 230 | event->setDtStart (fromGSM ( dtp )); |
231 | 231 | ||
232 | } | 232 | } |
233 | //Note->Entries[i].Date.Hour = 5; | ||
233 | break; | 234 | break; |
234 | case CAL_END_DATETIME: | 235 | case CAL_END_DATETIME: |
235 | dtp = &Note->Entries[i].Date ; | 236 | dtp = &Note->Entries[i].Date ; |
236 | if ( dtp->Hour > 24 ) { | 237 | if ( dtp->Hour > 24 ) { |
237 | event->setFloats( true ); | 238 | event->setFloats( true ); |
238 | event->setDtEnd( QDateTime (datefromGSM ( dtp ), QTime(0,0,0 ))); | 239 | event->setDtEnd( QDateTime (datefromGSM ( dtp ), QTime(0,0,0 ))); |
239 | } else { | 240 | } else { |
240 | event->setDtEnd (fromGSM ( dtp )); | 241 | event->setDtEnd (fromGSM ( dtp )); |
241 | } | 242 | } |
242 | break; | 243 | break; |
243 | case CAL_ALARM_DATETIME: | 244 | case CAL_ALARM_DATETIME: |
244 | dtp = &Note->Entries[i].Date ; | 245 | dtp = &Note->Entries[i].Date ; |
245 | alarm = true; | 246 | alarm = true; |
246 | alarmDt = fromGSM ( dtp ); | 247 | alarmDt = fromGSM ( dtp ); |
247 | break; | 248 | break; |
248 | case CAL_SILENT_ALARM_DATETIME: | 249 | case CAL_SILENT_ALARM_DATETIME: |
249 | dtp = &Note->Entries[i].Date ; | 250 | dtp = &Note->Entries[i].Date ; |
250 | alarm = true; | 251 | alarm = true; |
251 | alarmDt = fromGSM ( dtp ); | 252 | alarmDt = fromGSM ( dtp ); |
252 | break; | 253 | break; |
253 | case CAL_RECURRANCE: | 254 | case CAL_RECURRANCE: |
254 | rec_type = Note->Entries[i].Number; | 255 | rec_type = Note->Entries[i].Number; |
255 | //printmsg("Repeat : %d day%s\n",Note->Entries[i].Number/24,((Note->Entries[i].Number/24)>1) ? "s":"" ); | 256 | //printmsg("Repeat : %d day%s\n",Note->Entries[i].Number/24,((Note->Entries[i].Number/24)>1) ? "s":"" ); |
256 | break; | 257 | break; |
257 | case CAL_TEXT: | 258 | case CAL_TEXT: |
258 | //qDebug(" ev text %s", DecodeUnicodeConsole(Note->Entries[i].Text) ); | 259 | //qDebug(" ev text %s", DecodeUnicodeConsole(Note->Entries[i].Text) ); |
259 | event->setSummary( QString::fromUtf8 ( (const char*)DecodeUnicodeConsole( Note->Entries[i].Text ))); | 260 | event->setSummary( QString::fromUtf8 ( (const char*)DecodeUnicodeConsole( Note->Entries[i].Text ))); |
260 | break; | 261 | break; |
261 | case CAL_LOCATION: | 262 | case CAL_LOCATION: |
262 | event->setLocation(QString::fromUtf8 ((const char*) DecodeUnicodeConsole(Note->Entries[i].Text) )); | 263 | event->setLocation(QString::fromUtf8 ((const char*) DecodeUnicodeConsole(Note->Entries[i].Text) )); |
263 | break; | 264 | break; |
264 | case CAL_PHONE: | 265 | case CAL_PHONE: |
265 | //printmsg("Phone : \"%s\"\n",DecodeUnicodeConsole(Note->Entries[i].Text)); | 266 | //printmsg("Phone : \"%s\"\n",DecodeUnicodeConsole(Note->Entries[i].Text)); |
266 | break; | 267 | break; |
267 | case CAL_PRIVATE: | 268 | case CAL_PRIVATE: |
268 | if ( Note->Entries[i].Number == 1 ) | 269 | if ( Note->Entries[i].Number == 1 ) |
269 | event->setSecrecy( Incidence::SecrecyPrivate ); | 270 | event->setSecrecy( Incidence::SecrecyPrivate ); |
270 | else | 271 | else |
271 | event->setSecrecy( Incidence::SecrecyPublic ); | 272 | event->setSecrecy( Incidence::SecrecyPublic ); |
272 | 273 | ||
273 | break; | 274 | break; |
274 | case CAL_CONTACTID: | 275 | case CAL_CONTACTID: |
275 | #if 0 | 276 | #if 0 |
276 | entry.Location = Note->Entries[i].Number; | 277 | entry.Location = Note->Entries[i].Number; |
277 | entry.MemoryType = MEM_ME; | 278 | entry.MemoryType = MEM_ME; |
278 | error=Phone->GetMemory(&s, &entry); | 279 | error=Phone->GetMemory(&s, &entry); |
279 | if (error == ERR_NONE) { | 280 | if (error == ERR_NONE) { |
280 | name = GSM_PhonebookGetEntryName(&entry); | 281 | name = GSM_PhonebookGetEntryName(&entry); |
281 | if (name != NULL) { | 282 | if (name != NULL) { |
282 | //printmsg("Contact ID : \"%s\" (%d)\n", DecodeUnicodeConsole(name), Note->Entries[i].Number); | 283 | //printmsg("Contact ID : \"%s\" (%d)\n", DecodeUnicodeConsole(name), Note->Entries[i].Number); |
283 | } else { | 284 | } else { |
284 | //printmsg("Contact ID : %d\n",Note->Entries[i].Number); | 285 | //printmsg("Contact ID : %d\n",Note->Entries[i].Number); |
285 | } | 286 | } |
286 | } else { | 287 | } else { |
287 | //printmsg("Contact ID : %d\n",Note->Entries[i].Number); | 288 | //printmsg("Contact ID : %d\n",Note->Entries[i].Number); |
288 | } | 289 | } |
289 | #endif | 290 | #endif |
290 | break; | 291 | break; |
291 | case CAL_REPEAT_DAYOFWEEK: | 292 | case CAL_REPEAT_DAYOFWEEK: |
292 | repeat_dayofweek = Note->Entries[i].Number; | 293 | repeat_dayofweek = Note->Entries[i].Number; |
293 | repeating = true; | 294 | repeating = true; |
294 | break; | 295 | break; |
295 | case CAL_REPEAT_DAY: | 296 | case CAL_REPEAT_DAY: |
296 | repeat_day = Note->Entries[i].Number; | 297 | repeat_day = Note->Entries[i].Number; |
297 | repeating = true; | 298 | repeating = true; |
298 | break; | 299 | break; |
299 | case CAL_REPEAT_WEEKOFMONTH: | 300 | case CAL_REPEAT_WEEKOFMONTH: |
300 | repeat_weekofmonth = Note->Entries[i].Number; | 301 | repeat_weekofmonth = Note->Entries[i].Number; |
301 | repeating = true; | 302 | repeating = true; |
302 | break; | 303 | break; |
303 | case CAL_REPEAT_MONTH: | 304 | case CAL_REPEAT_MONTH: |
304 | repeat_month = Note->Entries[i].Number; | 305 | repeat_month = Note->Entries[i].Number; |
305 | repeating = true; | 306 | repeating = true; |
306 | break; | 307 | break; |
307 | case CAL_REPEAT_FREQUENCY: | 308 | case CAL_REPEAT_FREQUENCY: |
308 | repeat_frequency = Note->Entries[i].Number; | 309 | repeat_frequency = Note->Entries[i].Number; |
309 | repeating = true; | 310 | repeating = true; |
310 | break; | 311 | break; |
311 | case CAL_REPEAT_STARTDATE: | 312 | case CAL_REPEAT_STARTDATE: |
312 | repeat_startdate = Note->Entries[i].Date; | 313 | repeat_startdate = Note->Entries[i].Date; |
313 | repeating = true; | 314 | repeating = true; |
314 | break; | 315 | break; |
315 | case CAL_REPEAT_STOPDATE: | 316 | case CAL_REPEAT_STOPDATE: |
316 | repeat_stopdate = Note->Entries[i].Date; | 317 | repeat_stopdate = Note->Entries[i].Date; |
317 | repeating = true; | 318 | repeating = true; |
318 | break; | 319 | break; |
319 | } | 320 | } |
320 | } | 321 | } |
321 | #if 0 | 322 | #if 0 |
322 | event->setDescription( attList[4] ); | 323 | event->setDescription( attList[4] ); |
323 | bool repeating = false; | 324 | bool repeating = false; |
324 | int repeat_dayofweek = -1; | 325 | int repeat_dayofweek = -1; |
325 | int repeat_day = -1; | 326 | int repeat_day = -1; |
326 | int repeat_weekofmonth = -1; | 327 | int repeat_weekofmonth = -1; |
327 | int repeat_month = -1; | 328 | int repeat_month = -1; |
328 | int repeat_frequency = -1; | 329 | int repeat_frequency = -1; |
329 | GSM_DateTime repeat_startdate = {0,0,0,0,0,0,0}; | 330 | GSM_DateTime repeat_startdate = {0,0,0,0,0,0,0}; |
330 | GSM_DateTime repeat_stopdate = {0,0,0,0,0,0,0}; | 331 | GSM_DateTime repeat_stopdate = {0,0,0,0,0,0,0}; |
331 | 332 | ||
332 | #endif | 333 | #endif |
333 | 334 | ||
334 | QString recurString = "no"; | 335 | QString recurString = "no"; |
335 | if ( repeating && repeat_frequency != -1) { | 336 | if ( repeating && repeat_frequency != -1) { |
336 | recurString = "y"; | 337 | recurString = "y"; |
337 | if ( repeat_dayofweek >= 0 ) | 338 | if ( repeat_dayofweek >= 0 ) |
338 | recurString += "dow" + QString::number (repeat_dayofweek); | 339 | recurString += "dow" + QString::number (repeat_dayofweek); |
339 | if ( repeat_day >= 0 ) | 340 | if ( repeat_day >= 0 ) |
340 | recurString += "d" + QString::number (repeat_day); | 341 | recurString += "d" + QString::number (repeat_day); |
341 | if ( repeat_weekofmonth >= 0 ) | 342 | if ( repeat_weekofmonth >= 0 ) |
342 | recurString += "w" + QString::number (repeat_weekofmonth); | 343 | recurString += "w" + QString::number (repeat_weekofmonth); |
343 | if ( repeat_month >= 0 ) | 344 | if ( repeat_month >= 0 ) |
344 | recurString += "m" + QString::number ( repeat_month ); | 345 | recurString += "m" + QString::number ( repeat_month ); |
345 | if ( repeat_frequency >= 0 ) | 346 | if ( repeat_frequency >= 0 ) |
346 | recurString += "f" + QString::number (repeat_frequency ); | 347 | recurString += "f" + QString::number (repeat_frequency ); |
347 | 348 | ||
348 | int rtype = 0; | 349 | int rtype = 0; |
349 | // qDebug("recurs "); | 350 | // qDebug("recurs "); |
350 | QDate startDate, endDate; | 351 | QDate startDate, endDate; |
351 | if ( repeat_startdate.Day > 0 ) { | 352 | if ( repeat_startdate.Day > 0 ) { |
352 | startDate = datefromGSM ( &repeat_startdate ); | 353 | startDate = datefromGSM ( &repeat_startdate ); |
353 | event->setDtStart(QDateTime ( startDate, event->dtStart().time())); | 354 | event->setDtStart(QDateTime ( startDate, event->dtStart().time())); |
354 | } else { | 355 | } else { |
355 | startDate = event->dtStart().date(); | 356 | startDate = event->dtStart().date(); |
356 | } | 357 | } |
357 | int freq = repeat_frequency; | 358 | int freq = repeat_frequency; |
358 | bool hasEndDate = false; | 359 | bool hasEndDate = false; |
359 | if ( repeat_stopdate.Day > 0 ) { | 360 | if ( repeat_stopdate.Day > 0 ) { |
360 | endDate = datefromGSM ( &repeat_stopdate ); | 361 | endDate = datefromGSM ( &repeat_stopdate ); |
361 | hasEndDate = true; | 362 | hasEndDate = true; |
362 | } | 363 | } |
363 | 364 | ||
364 | uint weekDaysNum = repeat_dayofweek ; | 365 | uint weekDaysNum = repeat_dayofweek ; |
365 | // 1 == monday, 7 == sunday | 366 | // 1 == monday, 7 == sunday |
366 | QBitArray weekDays( 7 ); | 367 | QBitArray weekDays( 7 ); |
367 | int i; | 368 | int i; |
368 | int bb = 1; | 369 | int bb = 1; |
369 | for( i = 1; i <= 7; ++i ) { | 370 | for( i = 1; i <= 7; ++i ) { |
370 | weekDays.setBit( i - 1, ( bb & weekDaysNum )); | 371 | weekDays.setBit( i - 1, ( bb & weekDaysNum )); |
371 | bb = 2 << (i-1); | 372 | bb = 2 << (i-1); |
372 | //qDebug(" %d bit %d ",i-1,weekDays.at(i-1) ); | 373 | //qDebug(" %d bit %d ",i-1,weekDays.at(i-1) ); |
373 | } | 374 | } |
374 | // qDebug("next "); | 375 | // qDebug("next "); |
375 | int pos = 0; | 376 | int pos = 0; |
376 | Recurrence *r = event->recurrence(); | 377 | Recurrence *r = event->recurrence(); |
377 | /* | 378 | /* |
378 | 0 daily; | 379 | 0 daily; |
379 | 1 weekly;x | 380 | 1 weekly;x |
380 | 2 monthpos;x | 381 | 2 monthpos;x |
381 | 3 monthlyday; | 382 | 3 monthlyday; |
382 | 4 rYearlyMont | 383 | 4 rYearlyMont |
383 | bool repeating = false; | 384 | bool repeating = false; |
384 | int repeat_dayofweek = -1; | 385 | int repeat_dayofweek = -1; |
385 | int repeat_day = -1; | 386 | int repeat_day = -1; |
386 | int repeat_weekofmonth = -1; | 387 | int repeat_weekofmonth = -1; |
387 | int repeat_month = -1; | 388 | int repeat_month = -1; |
388 | int repeat_frequency = -1; | 389 | int repeat_frequency = -1; |
389 | */ | 390 | */ |
390 | int dayOfWeek = startDate.dayOfWeek(); | 391 | int dayOfWeek = startDate.dayOfWeek(); |
391 | if ( repeat_weekofmonth >= 0 ) { | 392 | if ( repeat_weekofmonth >= 0 ) { |
392 | rtype = 2; // ************************ 2 MonthlyPos | 393 | rtype = 2; // ************************ 2 MonthlyPos |
393 | pos = repeat_weekofmonth; | 394 | pos = repeat_weekofmonth; |
394 | if ( repeat_dayofweek >= 0 ) | 395 | if ( repeat_dayofweek >= 0 ) |
395 | dayOfWeek = repeat_dayofweek; | 396 | dayOfWeek = repeat_dayofweek; |
396 | if (repeat_month > 0) { | 397 | if (repeat_month > 0) { |
397 | if ( repeat_month != event->dtStart().date().month() ) { | 398 | if ( repeat_month != event->dtStart().date().month() ) { |
398 | QDate date (event->dtStart().date().year(),repeat_month,event->dtStart().date().day() ); | 399 | QDate date (event->dtStart().date().year(),repeat_month,event->dtStart().date().day() ); |
399 | event->setDtStart(QDateTime ( date , event->dtStart().time()) ); | 400 | event->setDtStart(QDateTime ( date , event->dtStart().time()) ); |
400 | } | 401 | } |
401 | if ( freq == 1 ) | 402 | if ( freq == 1 ) |
402 | freq = 12; | 403 | freq = 12; |
403 | } | 404 | } |
404 | } else if ( repeat_dayofweek >= 0 ) { | 405 | } else if ( repeat_dayofweek >= 0 ) { |
405 | rtype = 1;// ************************ 1 Weekly | 406 | rtype = 1;// ************************ 1 Weekly |
406 | } else if ( repeat_day >= 0 ) { | 407 | } else if ( repeat_day >= 0 ) { |
407 | if ( repeat_month > 0) { | 408 | if ( repeat_month > 0) { |
408 | rtype = 4; | 409 | rtype = 4; |
409 | } else { | 410 | } else { |
410 | rtype = 3; | 411 | rtype = 3; |
411 | } | 412 | } |
412 | } else { | 413 | } else { |
413 | rtype = 0 ; | 414 | rtype = 0 ; |
414 | } | 415 | } |
415 | 416 | ||
416 | if ( rtype == 0 ) { | 417 | if ( rtype == 0 ) { |
417 | if ( hasEndDate ) r->setDaily( freq, endDate ); | 418 | if ( hasEndDate ) r->setDaily( freq, endDate ); |
418 | else r->setDaily( freq, -1 ); | 419 | else r->setDaily( freq, -1 ); |
419 | } else if ( rtype == 1 ) { | 420 | } else if ( rtype == 1 ) { |
420 | if ( hasEndDate ) r->setWeekly( freq, weekDays, endDate ); | 421 | if ( hasEndDate ) r->setWeekly( freq, weekDays, endDate ); |
421 | else r->setWeekly( freq, weekDays, -1 ); | 422 | else r->setWeekly( freq, weekDays, -1 ); |
422 | } else if ( rtype == 3 ) { | 423 | } else if ( rtype == 3 ) { |
423 | if ( hasEndDate ) | 424 | if ( hasEndDate ) |
424 | r->setMonthly( Recurrence::rMonthlyDay, freq, endDate ); | 425 | r->setMonthly( Recurrence::rMonthlyDay, freq, endDate ); |
425 | else | 426 | else |
426 | r->setMonthly( Recurrence::rMonthlyDay, freq, -1 ); | 427 | r->setMonthly( Recurrence::rMonthlyDay, freq, -1 ); |
427 | r->addMonthlyDay( startDate.day() ); | 428 | r->addMonthlyDay( startDate.day() ); |
428 | } else if ( rtype == 2 ) { | 429 | } else if ( rtype == 2 ) { |
429 | if ( hasEndDate ) | 430 | if ( hasEndDate ) |
430 | r->setMonthly( Recurrence::rMonthlyPos, freq, endDate ); | 431 | r->setMonthly( Recurrence::rMonthlyPos, freq, endDate ); |
431 | else | 432 | else |
432 | r->setMonthly( Recurrence::rMonthlyPos, freq, -1 ); | 433 | r->setMonthly( Recurrence::rMonthlyPos, freq, -1 ); |
433 | QBitArray days( 7 ); | 434 | QBitArray days( 7 ); |
434 | days.fill( false ); | 435 | days.fill( false ); |
435 | days.setBit( dayOfWeek - 1 ); | 436 | days.setBit( dayOfWeek - 1 ); |
436 | r->addMonthlyPos( pos, days ); | 437 | r->addMonthlyPos( pos, days ); |
437 | } else if ( rtype == 4 ) { | 438 | } else if ( rtype == 4 ) { |
438 | if ( hasEndDate ) | 439 | if ( hasEndDate ) |
439 | r->setYearly( Recurrence::rYearlyMonth, freq, endDate ); | 440 | r->setYearly( Recurrence::rYearlyMonth, freq, endDate ); |
440 | else | 441 | else |
441 | r->setYearly( Recurrence::rYearlyMonth, freq, -1 ); | 442 | r->setYearly( Recurrence::rYearlyMonth, freq, -1 ); |
442 | r->addYearlyNum( startDate.month() ); | 443 | r->addYearlyNum( startDate.month() ); |
443 | } | 444 | } |
444 | } else { | 445 | } else { |
445 | event->recurrence()->unsetRecurs(); | 446 | event->recurrence()->unsetRecurs(); |
446 | } | 447 | } |
447 | 448 | ||
448 | QStringList categoryList; | 449 | QStringList categoryList; |
449 | categoryList << getCategory( Note ); | 450 | categoryList << getCategory( Note ); |
450 | event->setCategories( categoryList ); | 451 | event->setCategories( categoryList ); |
451 | // strange 0 semms to mean: alarm enabled | 452 | // strange 0 semms to mean: alarm enabled |
452 | if ( alarm ) { | 453 | if ( alarm ) { |
453 | Alarm *alarm; | 454 | Alarm *alarm; |
454 | if ( event->alarms().count() > 0 ) | 455 | if ( event->alarms().count() > 0 ) |
455 | alarm = event->alarms().first(); | 456 | alarm = event->alarms().first(); |
456 | else { | 457 | else { |
457 | alarm = new Alarm( event ); | 458 | alarm = new Alarm( event ); |
458 | event->addAlarm( alarm ); | 459 | event->addAlarm( alarm ); |
459 | } | 460 | } |
460 | alarm->setType( Alarm::Audio ); | 461 | alarm->setType( Alarm::Audio ); |
461 | alarm->setEnabled( true ); | 462 | alarm->setEnabled( true ); |
462 | int alarmOffset = alarmDt.secsTo( event->dtStart() ); | 463 | int alarmOffset = alarmDt.secsTo( event->dtStart() ); |
463 | alarm->setStartOffset( -alarmOffset ); | 464 | alarm->setStartOffset( -alarmOffset ); |
464 | } else { | 465 | } else { |
465 | Alarm *alarm; | 466 | Alarm *alarm; |
466 | if ( event->alarms().count() > 0 ) { | 467 | if ( event->alarms().count() > 0 ) { |
467 | alarm = event->alarms().first(); | 468 | alarm = event->alarms().first(); |
468 | alarm->setType( Alarm::Audio ); | 469 | alarm->setType( Alarm::Audio ); |
469 | alarm->setStartOffset( -60*15 ); | 470 | alarm->setStartOffset( -60*15 ); |
470 | alarm->setEnabled( false ); | 471 | alarm->setEnabled( false ); |
471 | } | 472 | } |
472 | } | 473 | } |
473 | // csum ***************************************** | 474 | // csum ***************************************** |
474 | 475 | ||
475 | uint cSum; | 476 | uint cSum; |
476 | cSum = PhoneFormat::getCsumEvent( event ); | 477 | cSum = PhoneFormat::getCsumEvent( event ); |
477 | event->setCsum( mProfileName, QString::number( cSum )); | 478 | event->setCsum( mProfileName, QString::number( cSum )); |
478 | event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); | 479 | event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); |
479 | mCalendar->addEvent( event); | 480 | mCalendar->addEvent( event); |
480 | 481 | ||
481 | return true; | 482 | return true; |
482 | } | 483 | } |
483 | 484 | ||
484 | 485 | ||
485 | QDateTime fromGSM ( GSM_DateTime*dtp, bool useTz = true ) { | 486 | QDateTime fromGSM ( GSM_DateTime*dtp, bool useTz = true ) { |
486 | QDateTime dt; | 487 | QDateTime dt; |
487 | int y,m,t,h,min,sec; | 488 | int y,m,t,h,min,sec; |
488 | y = dtp->Year; | 489 | y = dtp->Year; |
489 | m = dtp->Month; | 490 | m = dtp->Month; |
490 | t = dtp->Day; | 491 | t = dtp->Day; |
491 | h = dtp->Hour; | 492 | h = dtp->Hour; |
492 | min = dtp->Minute; | 493 | min = dtp->Minute; |
493 | sec = dtp->Second; | 494 | sec = dtp->Second; |
494 | dt = QDateTime(QDate(y,m,t), QTime(h,min,sec)); | 495 | dt = QDateTime(QDate(y,m,t), QTime(h,min,sec)); |
495 | // dtp->Timezone: offset in hours | 496 | // dtp->Timezone: offset in hours |
496 | int offset = KGlobal::locale()->localTimeOffset( dt ); | 497 | int offset = KGlobal::locale()->localTimeOffset( dt ); |
497 | if ( useTz ) | 498 | if ( useTz ) |
498 | dt = dt.addSecs ( offset*60); | 499 | dt = dt.addSecs ( offset*60); |
499 | return dt; | 500 | return dt; |
500 | 501 | ||
501 | } | 502 | } |
502 | 503 | ||
503 | static QString dtToString( const QDateTime& dti, bool useTZ = false ) | 504 | static QString dtToString( const QDateTime& dti, bool useTZ = false ) |
504 | { | 505 | { |
505 | QString datestr; | 506 | QString datestr; |
506 | QString timestr; | 507 | QString timestr; |
507 | int offset = KGlobal::locale()->localTimeOffset( dti ); | 508 | int offset = KGlobal::locale()->localTimeOffset( dti ); |
508 | QDateTime dt; | 509 | QDateTime dt; |
509 | if (useTZ) | 510 | if (useTZ) |
510 | dt = dti.addSecs ( -(offset*60)); | 511 | dt = dti.addSecs ( -(offset*60)); |
511 | else | 512 | else |
512 | dt = dti; | 513 | dt = dti; |
513 | if(dt.date().isValid()){ | 514 | if(dt.date().isValid()){ |
514 | const QDate& date = dt.date(); | 515 | const QDate& date = dt.date(); |
515 | datestr.sprintf("%04d%02d%02d", | 516 | datestr.sprintf("%04d%02d%02d", |
516 | date.year(), date.month(), date.day()); | 517 | date.year(), date.month(), date.day()); |
517 | } | 518 | } |
518 | if(dt.time().isValid()){ | 519 | if(dt.time().isValid()){ |
519 | const QTime& time = dt.time(); | 520 | const QTime& time = dt.time(); |
520 | timestr.sprintf("T%02d%02d%02d", | 521 | timestr.sprintf("T%02d%02d%02d", |
521 | time.hour(), time.minute(), time.second()); | 522 | time.hour(), time.minute(), time.second()); |
522 | } | 523 | } |
523 | return datestr + timestr; | 524 | return datestr + timestr; |
524 | } | 525 | } |
525 | QDate datefromGSM ( GSM_DateTime*dtp ) { | 526 | QDate datefromGSM ( GSM_DateTime*dtp ) { |
526 | return QDate ( dtp->Year, dtp->Month, dtp->Day ); | 527 | return QDate ( dtp->Year, dtp->Month, dtp->Day ); |
527 | } | 528 | } |
528 | QString getCategory( GSM_CalendarEntry*Note) | 529 | QString getCategory( GSM_CalendarEntry*Note) |
529 | { | 530 | { |
530 | QString CATEGORY; | 531 | QString CATEGORY; |
531 | switch (Note->Type) { | 532 | switch (Note->Type) { |
532 | case GSM_CAL_REMINDER : CATEGORY = QString("Reminder"); break; | 533 | case GSM_CAL_REMINDER : CATEGORY = QString("Reminder"); break; |
533 | case GSM_CAL_CALL : CATEGORY = QString("Call"); break; | 534 | case GSM_CAL_CALL : CATEGORY = QString("Call"); break; |
534 | case GSM_CAL_MEETING : CATEGORY = QString("Meeting"); break; | 535 | case GSM_CAL_MEETING : CATEGORY = QString("Meeting"); break; |
535 | case GSM_CAL_BIRTHDAY : CATEGORY = QString("Birthday"); break; | 536 | case GSM_CAL_BIRTHDAY : CATEGORY = QString("Birthday"); break; |
536 | case GSM_CAL_MEMO : CATEGORY = QString("Memo"); break; | 537 | case GSM_CAL_MEMO : CATEGORY = QString("Memo"); break; |
537 | case GSM_CAL_TRAVEL : CATEGORY = QString("Travel"); break; | 538 | case GSM_CAL_TRAVEL : CATEGORY = QString("Travel"); break; |
538 | case GSM_CAL_VACATION : CATEGORY = QString("Vacation"); break; | 539 | case GSM_CAL_VACATION : CATEGORY = QString("Vacation"); break; |
539 | case GSM_CAL_ALARM : CATEGORY = QString("Alarm"); break; | 540 | case GSM_CAL_ALARM : CATEGORY = QString("Alarm"); break; |
540 | case GSM_CAL_DAILY_ALARM : CATEGORY = QString("Daily alarm"); break; | 541 | case GSM_CAL_DAILY_ALARM : CATEGORY = QString("Daily alarm"); break; |
541 | case GSM_CAL_T_ATHL : CATEGORY = QString("Training/Athletism"); break; | 542 | case GSM_CAL_T_ATHL : CATEGORY = QString("Training/Athletism"); break; |
542 | case GSM_CAL_T_BALL : CATEGORY = QString("Training/Ball Games"); break; | 543 | case GSM_CAL_T_BALL : CATEGORY = QString("Training/Ball Games"); break; |
543 | case GSM_CAL_T_CYCL : CATEGORY = QString("Training/Cycling"); break; | 544 | case GSM_CAL_T_CYCL : CATEGORY = QString("Training/Cycling"); break; |
544 | case GSM_CAL_T_BUDO : CATEGORY = QString("Training/Budo"); break; | 545 | case GSM_CAL_T_BUDO : CATEGORY = QString("Training/Budo"); break; |
545 | case GSM_CAL_T_DANC : CATEGORY = QString("Training/Dance"); break; | 546 | case GSM_CAL_T_DANC : CATEGORY = QString("Training/Dance"); break; |
546 | case GSM_CAL_T_EXTR : CATEGORY = QString("Training/Extreme Sports"); break; | 547 | case GSM_CAL_T_EXTR : CATEGORY = QString("Training/Extreme Sports"); break; |
547 | case GSM_CAL_T_FOOT : CATEGORY = QString("Training/Football"); break; | 548 | case GSM_CAL_T_FOOT : CATEGORY = QString("Training/Football"); break; |
548 | case GSM_CAL_T_GOLF : CATEGORY = QString("Training/Golf"); break; | 549 | case GSM_CAL_T_GOLF : CATEGORY = QString("Training/Golf"); break; |
549 | case GSM_CAL_T_GYM : CATEGORY = QString("Training/Gym"); break; | 550 | case GSM_CAL_T_GYM : CATEGORY = QString("Training/Gym"); break; |
550 | case GSM_CAL_T_HORS : CATEGORY = QString("Training/Horse Races"); break; | 551 | case GSM_CAL_T_HORS : CATEGORY = QString("Training/Horse Races"); break; |
551 | case GSM_CAL_T_HOCK : CATEGORY = QString("Training/Hockey"); break; | 552 | case GSM_CAL_T_HOCK : CATEGORY = QString("Training/Hockey"); break; |
552 | case GSM_CAL_T_RACE : CATEGORY = QString("Training/Races"); break; | 553 | case GSM_CAL_T_RACE : CATEGORY = QString("Training/Races"); break; |
553 | case GSM_CAL_T_RUGB : CATEGORY = QString("Training/Rugby"); break; | 554 | case GSM_CAL_T_RUGB : CATEGORY = QString("Training/Rugby"); break; |
554 | case GSM_CAL_T_SAIL : CATEGORY = QString("Training/Sailing"); break; | 555 | case GSM_CAL_T_SAIL : CATEGORY = QString("Training/Sailing"); break; |
555 | case GSM_CAL_T_STRE : CATEGORY = QString("Training/Street Games"); break; | 556 | case GSM_CAL_T_STRE : CATEGORY = QString("Training/Street Games"); break; |
556 | case GSM_CAL_T_SWIM : CATEGORY = QString("Training/Swimming"); break; | 557 | case GSM_CAL_T_SWIM : CATEGORY = QString("Training/Swimming"); break; |
557 | case GSM_CAL_T_TENN : CATEGORY = QString("Training/Tennis"); break; | 558 | case GSM_CAL_T_TENN : CATEGORY = QString("Training/Tennis"); break; |
558 | case GSM_CAL_T_TRAV : CATEGORY = QString("Training/Travels"); break; | 559 | case GSM_CAL_T_TRAV : CATEGORY = QString("Training/Travels"); break; |
559 | case GSM_CAL_T_WINT : CATEGORY = QString("Training/Winter Games"); break; | 560 | case GSM_CAL_T_WINT : CATEGORY = QString("Training/Winter Games"); break; |
560 | default : CATEGORY = QString(""); | 561 | default : CATEGORY = QString(""); |
561 | } | 562 | } |
562 | 563 | ||
563 | return CATEGORY; | 564 | return CATEGORY; |
564 | } | 565 | } |
565 | 566 | ||
566 | protected: | 567 | protected: |
567 | private: | 568 | private: |
568 | Calendar *mCalendar; | 569 | Calendar *mCalendar; |
569 | QString mProfileName ; | 570 | QString mProfileName ; |
570 | }; | 571 | }; |
571 | 572 | ||
572 | 573 | ||
573 | PhoneFormat::PhoneFormat(QString profileName, QString device,QString connection, QString model ) | 574 | PhoneFormat::PhoneFormat(QString profileName, QString device,QString connection, QString model ) |
574 | { | 575 | { |
575 | mProfileName = profileName; | 576 | mProfileName = profileName; |
576 | mDevice = device; | 577 | mDevice = device; |
577 | mConnection = connection; | 578 | mConnection = connection; |
578 | mModel = model; | 579 | mModel = model; |
579 | } | 580 | } |
580 | 581 | ||
581 | PhoneFormat::~PhoneFormat() | 582 | PhoneFormat::~PhoneFormat() |
582 | { | 583 | { |
583 | } | 584 | } |
584 | int PhoneFormat::initDevice(GSM_StateMachine *s) | 585 | int PhoneFormat::initDevice(GSM_StateMachine *s) |
585 | { | 586 | { |
586 | GSM_ReadConfig(NULL, &s->Config[0], 0); | 587 | GSM_ReadConfig(NULL, &s->Config[0], 0); |
587 | s->ConfigNum = 1; | 588 | s->ConfigNum = 1; |
588 | GSM_Config *cfg = &s->Config[0]; | 589 | GSM_Config *cfg = &s->Config[0]; |
589 | if ( ! mConnection.isEmpty() ) { | 590 | if ( ! mConnection.isEmpty() ) { |
590 | cfg->Connection = strdup(mConnection.latin1()); | 591 | cfg->Connection = strdup(mConnection.latin1()); |
591 | cfg->DefaultConnection = false; | 592 | cfg->DefaultConnection = false; |
592 | qDebug("Connection set %s ", cfg->Connection ); | 593 | qDebug("Connection set %s ", cfg->Connection ); |
593 | 594 | ||
594 | } | 595 | } |
595 | if ( ! mDevice.isEmpty() ) { | 596 | if ( ! mDevice.isEmpty() ) { |
596 | cfg->Device = strdup(mDevice.latin1()); | 597 | cfg->Device = strdup(mDevice.latin1()); |
597 | cfg->DefaultDevice = false; | 598 | cfg->DefaultDevice = false; |
598 | qDebug("Device set %s ", cfg->Device); | 599 | qDebug("Device set %s ", cfg->Device); |
599 | 600 | ||
600 | } | 601 | } |
601 | if ( ! mModel.isEmpty() ) { | 602 | if ( ! mModel.isEmpty() ) { |
602 | strcpy(cfg->Model,mModel.latin1() ); | 603 | strcpy(cfg->Model,mModel.latin1() ); |
603 | cfg->DefaultModel = false; | 604 | cfg->DefaultModel = false; |
604 | qDebug("Model set %s ",cfg->Model ); | 605 | qDebug("Model set %s ",cfg->Model ); |
605 | } | 606 | } |
606 | int error=GSM_InitConnection(s,3); | 607 | int error=GSM_InitConnection(s,3); |
607 | return error; | 608 | return error; |
608 | } | 609 | } |
609 | ulong PhoneFormat::getCsumTodo( Todo* todo ) | 610 | ulong PhoneFormat::getCsumTodo( Todo* todo ) |
610 | { | 611 | { |
611 | QStringList attList; | 612 | QStringList attList; |
612 | if ( todo->hasDueDate() ) | 613 | if ( todo->hasDueDate() ) |
613 | attList << PhoneParser::dtToString ( todo->dtDue() ); | 614 | attList << PhoneParser::dtToString ( todo->dtDue() ); |
614 | attList << todo->summary(); | 615 | attList << todo->summary(); |
615 | QString completedString = "no"; | 616 | QString completedString = "no"; |
616 | if ( todo->isCompleted() ) | 617 | if ( todo->isCompleted() ) |
617 | completedString = "yes"; | 618 | completedString = "yes"; |
618 | attList << completedString; | 619 | attList << completedString; |
619 | attList << QString::number( todo->priority() ); | 620 | attList << QString::number( todo->priority() ); |
620 | QString alarmString = "na"; | 621 | QString alarmString = "na"; |
621 | Alarm *alarm; | 622 | Alarm *alarm; |
622 | if ( todo->alarms().count() > 0 ) { | 623 | if ( todo->alarms().count() > 0 ) { |
623 | alarm = todo->alarms().first(); | 624 | alarm = todo->alarms().first(); |
624 | if ( alarm->enabled() ) { | 625 | if ( alarm->enabled() ) { |
625 | alarmString = QString::number(alarm->startOffset().asSeconds() ); | 626 | alarmString = QString::number(alarm->startOffset().asSeconds() ); |
626 | } | 627 | } |
627 | } | 628 | } |
628 | attList << alarmString; | 629 | attList << alarmString; |
629 | attList << todo->categoriesStr(); | 630 | attList << todo->categoriesStr(); |
630 | attList << todo->secrecyStr(); | 631 | attList << todo->secrecyStr(); |
631 | return PhoneFormat::getCsum(attList ); | 632 | return PhoneFormat::getCsum(attList ); |
632 | 633 | ||
633 | } | 634 | } |
634 | ulong PhoneFormat::getCsumEvent( Event* event ) | 635 | ulong PhoneFormat::getCsumEvent( Event* event ) |
635 | { | 636 | { |
636 | QStringList attList; | 637 | QStringList attList; |
637 | attList << PhoneParser::dtToString ( event->dtStart() ); | 638 | attList << PhoneParser::dtToString ( event->dtStart() ); |
638 | attList << PhoneParser::dtToString ( event->dtEnd() ); | 639 | attList << PhoneParser::dtToString ( event->dtEnd() ); |
639 | attList << event->summary(); | 640 | attList << event->summary(); |
640 | attList << event->location(); | 641 | attList << event->location(); |
641 | QString alarmString = "na"; | 642 | QString alarmString = "na"; |
642 | Alarm *alarm; | 643 | Alarm *alarm; |
643 | if ( event->alarms().count() > 0 ) { | 644 | if ( event->alarms().count() > 0 ) { |
644 | alarm = event->alarms().first(); | 645 | alarm = event->alarms().first(); |
645 | if ( alarm->enabled() ) { | 646 | if ( alarm->enabled() ) { |
646 | alarmString = QString::number( alarm->startOffset().asSeconds() ); | 647 | alarmString = QString::number( alarm->startOffset().asSeconds() ); |
647 | } | 648 | } |
648 | } | 649 | } |
649 | attList << alarmString; | 650 | attList << alarmString; |
650 | Recurrence* rec = event->recurrence(); | 651 | Recurrence* rec = event->recurrence(); |
651 | QStringList list; | 652 | QStringList list; |
652 | bool writeEndDate = false; | 653 | bool writeEndDate = false; |
653 | switch ( rec->doesRecur() ) | 654 | switch ( rec->doesRecur() ) |
654 | { | 655 | { |
655 | case Recurrence::rDaily: // 0 | 656 | case Recurrence::rDaily: // 0 |
656 | list.append( "0" ); | 657 | list.append( "0" ); |
657 | list.append( QString::number( rec->frequency() ));//12 | 658 | list.append( QString::number( rec->frequency() ));//12 |
658 | list.append( "0" ); | 659 | list.append( "0" ); |
659 | list.append( "0" ); | 660 | list.append( "0" ); |
660 | writeEndDate = true; | 661 | writeEndDate = true; |
661 | break; | 662 | break; |
662 | case Recurrence::rWeekly:// 1 | 663 | case Recurrence::rWeekly:// 1 |
663 | list.append( "1" ); | 664 | list.append( "1" ); |
664 | list.append( QString::number( rec->frequency()) );//12 | 665 | list.append( QString::number( rec->frequency()) );//12 |
665 | list.append( "0" ); | 666 | list.append( "0" ); |
666 | { | 667 | { |
667 | int days = 0; | 668 | int days = 0; |
668 | QBitArray weekDays = rec->days(); | 669 | QBitArray weekDays = rec->days(); |
669 | int i; | 670 | int i; |
670 | for( i = 1; i <= 7; ++i ) { | 671 | for( i = 1; i <= 7; ++i ) { |
671 | if ( weekDays[i-1] ) { | 672 | if ( weekDays[i-1] ) { |
672 | days += 1 << (i-1); | 673 | days += 1 << (i-1); |
673 | } | 674 | } |
674 | } | 675 | } |
675 | list.append( QString::number( days ) ); | 676 | list.append( QString::number( days ) ); |
676 | } | 677 | } |
677 | //pending weekdays | 678 | //pending weekdays |
678 | writeEndDate = true; | 679 | writeEndDate = true; |
679 | 680 | ||
680 | break; | 681 | break; |
681 | case Recurrence::rMonthlyPos:// 2 | 682 | case Recurrence::rMonthlyPos:// 2 |
682 | list.append( "2" ); | 683 | list.append( "2" ); |
683 | list.append( QString::number( rec->frequency()) );//12 | 684 | list.append( QString::number( rec->frequency()) );//12 |
684 | 685 | ||
685 | writeEndDate = true; | 686 | writeEndDate = true; |
686 | { | 687 | { |
687 | int count = 1; | 688 | int count = 1; |
688 | QPtrList<Recurrence::rMonthPos> rmp; | 689 | QPtrList<Recurrence::rMonthPos> rmp; |
689 | rmp = rec->monthPositions(); | 690 | rmp = rec->monthPositions(); |
690 | if ( rmp.first()->negative ) | 691 | if ( rmp.first()->negative ) |
691 | count = 5 - rmp.first()->rPos - 1; | 692 | count = 5 - rmp.first()->rPos - 1; |
692 | else | 693 | else |
693 | count = rmp.first()->rPos - 1; | 694 | count = rmp.first()->rPos - 1; |
694 | list.append( QString::number( count ) ); | 695 | list.append( QString::number( count ) ); |
695 | 696 | ||
696 | } | 697 | } |
697 | 698 | ||
698 | list.append( "0" ); | 699 | list.append( "0" ); |
699 | break; | 700 | break; |
700 | case Recurrence::rMonthlyDay:// 3 | 701 | case Recurrence::rMonthlyDay:// 3 |
701 | list.append( "3" ); | 702 | list.append( "3" ); |
702 | list.append( QString::number( rec->frequency()) );//12 | 703 | list.append( QString::number( rec->frequency()) );//12 |
703 | list.append( "0" ); | 704 | list.append( "0" ); |
704 | list.append( "0" ); | 705 | list.append( "0" ); |
705 | writeEndDate = true; | 706 | writeEndDate = true; |
706 | break; | 707 | break; |
707 | case Recurrence::rYearlyMonth://4 | 708 | case Recurrence::rYearlyMonth://4 |
708 | list.append( "4" ); | 709 | list.append( "4" ); |
709 | list.append( QString::number( rec->frequency()) );//12 | 710 | list.append( QString::number( rec->frequency()) );//12 |
710 | list.append( "0" ); | 711 | list.append( "0" ); |
711 | list.append( "0" ); | 712 | list.append( "0" ); |
712 | writeEndDate = true; | 713 | writeEndDate = true; |
713 | break; | 714 | break; |
714 | 715 | ||
715 | default: | 716 | default: |
716 | list.append( "255" ); | 717 | list.append( "255" ); |
717 | list.append( QString() ); | 718 | list.append( QString() ); |
718 | list.append( "0" ); | 719 | list.append( "0" ); |
719 | list.append( QString() ); | 720 | list.append( QString() ); |
720 | list.append( "0" ); | 721 | list.append( "0" ); |
721 | list.append( "20991231T000000" ); | 722 | list.append( "20991231T000000" ); |
722 | break; | 723 | break; |
723 | } | 724 | } |
724 | if ( writeEndDate ) { | 725 | if ( writeEndDate ) { |
725 | 726 | ||
726 | if ( rec->endDate().isValid() ) { // 15 + 16 | 727 | if ( rec->endDate().isValid() ) { // 15 + 16 |
727 | list.append( "1" ); | 728 | list.append( "1" ); |
728 | list.append( PhoneParser::dtToString( rec->endDate()) ); | 729 | list.append( PhoneParser::dtToString( rec->endDate()) ); |
729 | } else { | 730 | } else { |
730 | list.append( "0" ); | 731 | list.append( "0" ); |
731 | list.append( "20991231T000000" ); | 732 | list.append( "20991231T000000" ); |
732 | } | 733 | } |
733 | 734 | ||
734 | } | 735 | } |
735 | attList << list.join(""); | 736 | attList << list.join(""); |
736 | attList << event->categoriesStr(); | 737 | attList << event->categoriesStr(); |
737 | attList << event->secrecyStr(); | 738 | attList << event->secrecyStr(); |
738 | return PhoneFormat::getCsum(attList ); | 739 | return PhoneFormat::getCsum(attList ); |
739 | } | 740 | } |
740 | ulong PhoneFormat::getCsum( const QStringList & attList) | 741 | ulong PhoneFormat::getCsum( const QStringList & attList) |
741 | { | 742 | { |
742 | int max = attList.count() -1; | 743 | int max = attList.count() -1; |
743 | ulong cSum = 0; | 744 | ulong cSum = 0; |
744 | int j,k,i; | 745 | int j,k,i; |
745 | int add; | 746 | int add; |
746 | for ( i = 1; i < max ; ++i ) { | 747 | for ( i = 1; i < max ; ++i ) { |
747 | QString s = attList[i]; | 748 | QString s = attList[i]; |
748 | if ( ! s.isEmpty() ){ | 749 | if ( ! s.isEmpty() ){ |
749 | j = s.length(); | 750 | j = s.length(); |
750 | for ( k = 0; k < j; ++k ) { | 751 | for ( k = 0; k < j; ++k ) { |
751 | int mul = k +1; | 752 | int mul = k +1; |
752 | add = s[k].unicode (); | 753 | add = s[k].unicode (); |
753 | if ( k < 16 ) | 754 | if ( k < 16 ) |
754 | mul = mul * mul; | 755 | mul = mul * mul; |
755 | add = add * mul *i*i*i; | 756 | add = add * mul *i*i*i; |
756 | cSum += add; | 757 | cSum += add; |
757 | } | 758 | } |
758 | } | 759 | } |
759 | } | 760 | } |
760 | return cSum; | 761 | return cSum; |
761 | 762 | ||
762 | } | 763 | } |
763 | //extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum); | 764 | //extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum); |
764 | #include <stdlib.h> | 765 | #include <stdlib.h> |
765 | #define DEBUGMODE false | 766 | #define DEBUGMODE false |
766 | bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal) | 767 | bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal) |
767 | { | 768 | { |
768 | GSM_StateMachines; | 769 | GSM_StateMachines; |
769 | qDebug(" load "); | 770 | qDebug(" load "); |
770 | s.opened = false; | 771 | s.opened = false; |
771 | s.msg = NULL; | 772 | s.msg = NULL; |
772 | s.ConfigNum = 0; | 773 | s.ConfigNum = 0; |
773 | QLabel status ( i18n("Reading data. Opening device ..."), 0 ); | 774 | QLabel status ( i18n("Opening device ..."), 0 ); |
774 | int w = status.sizeHint().width()+20 ; | 775 | int w = status.sizeHint().width()+20 ; |
775 | if ( w < 200 ) w = 200; | 776 | if ( w < 200 ) w = 230; |
776 | int h = status.sizeHint().height()+20 ; | 777 | int h = status.sizeHint().height()+20 ; |
777 | int dw = QApplication::desktop()->width(); | 778 | int dw = QApplication::desktop()->width(); |
778 | int dh = QApplication::desktop()->height(); | 779 | int dh = QApplication::desktop()->height(); |
779 | status.setCaption(i18n("Reading Phone Data") ); | 780 | status.setCaption(i18n("Reading phone...") ); |
780 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 781 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
781 | status.show(); | 782 | status.show(); |
782 | status.raise(); | 783 | status.raise(); |
783 | qApp->processEvents(); | 784 | qApp->processEvents(); |
784 | #if 0 | 785 | #if 0 |
785 | static char*cp; | 786 | static char*cp; |
786 | static INI_Section *cfg = NULL; | 787 | static INI_Section *cfg = NULL; |
787 | cfg=GSM_FindGammuRC(); | 788 | cfg=GSM_FindGammuRC(); |
788 | int i; | 789 | int i; |
789 | for (i = 0; i <= MAX_CONFIG_NUM; i++) { | 790 | for (i = 0; i <= MAX_CONFIG_NUM; i++) { |
790 | if (cfg!=NULL) { | 791 | if (cfg!=NULL) { |
791 | cp = (char *)INI_GetValue(cfg, (unsigned char*) "gammu", (unsigned char*)"gammucoding", false); | 792 | cp = (char *)INI_GetValue(cfg, (unsigned char*) "gammu", (unsigned char*)"gammucoding", false); |
792 | if (cp) di.coding = cp; | 793 | if (cp) di.coding = cp; |
793 | 794 | ||
794 | s.Config[i].Localize = (char *)INI_GetValue(cfg, (unsigned char*) "gammu", (unsigned char*) "gammuloc", false); | 795 | s.Config[i].Localize = (char *)INI_GetValue(cfg, (unsigned char*) "gammu", (unsigned char*) "gammuloc", false); |
795 | if (s.Config[i].Localize) { | 796 | if (s.Config[i].Localize) { |
796 | s.msg=INI_ReadFile(s.Config[i].Localize, true); | 797 | s.msg=INI_ReadFile(s.Config[i].Localize, true); |
797 | } else { | 798 | } else { |
798 | #if !defined(WIN32) && defined(LOCALE_PATH) | 799 | #if !defined(WIN32) && defined(LOCALE_PATH) |
799 | locale = setlocale(LC_MESSAGES, NULL); | 800 | locale = setlocale(LC_MESSAGES, NULL); |
800 | if (locale != NULL) { | 801 | if (locale != NULL) { |
801 | snprintf(locale_file, 200, "%s/gammu_%c%c.txt", | 802 | snprintf(locale_file, 200, "%s/gammu_%c%c.txt", |
802 | LOCALE_PATH, | 803 | LOCALE_PATH, |
803 | tolower(locale[0]), | 804 | tolower(locale[0]), |
804 | tolower(locale[1])); | 805 | tolower(locale[1])); |
805 | s.msg = INI_ReadFile(locale_file, true); | 806 | s.msg = INI_ReadFile(locale_file, true); |
806 | } | 807 | } |
807 | #endif | 808 | #endif |
808 | } | 809 | } |
809 | } | 810 | } |
810 | 811 | ||
811 | /* Wanted user specific configuration? */ | 812 | /* Wanted user specific configuration? */ |
812 | 813 | ||
813 | if (!GSM_ReadConfig(cfg, &s.Config[i], i) && i != 0) break; | 814 | if (!GSM_ReadConfig(cfg, &s.Config[i], i) && i != 0) break; |
814 | 815 | ||
815 | s.ConfigNum++; | 816 | s.ConfigNum++; |
816 | 817 | ||
817 | /* We want to use only one file descriptor for global and state machine debug output */ | 818 | /* We want to use only one file descriptor for global and state machine debug output */ |
818 | s.Config[i].UseGlobalDebugFile = true; | 819 | s.Config[i].UseGlobalDebugFile = true; |
819 | 820 | ||
820 | 821 | ||
821 | 822 | ||
822 | /* We wanted to read just user specified configuration. */ | 823 | /* We wanted to read just user specified configuration. */ |
823 | {break;} | 824 | {break;} |
824 | } | 825 | } |
825 | 826 | ||
826 | #endif | 827 | #endif |
827 | int error=initDevice(&s); | 828 | int error=initDevice(&s); |
828 | qDebug("GSM Init %d (no error is %d)", error, ERR_NONE); | 829 | qDebug("GSM Init %d (no error is %d)", error, ERR_NONE); |
829 | if ( error != ERR_NONE ) | 830 | if ( error != ERR_NONE ) |
830 | return false; | 831 | return false; |
831 | GSM_Phone_Functions*Phone; | 832 | GSM_Phone_Functions*Phone; |
832 | GSM_CalendarEntrynote; | 833 | GSM_CalendarEntrynote; |
833 | bool start = true; | 834 | bool start = true; |
834 | Phone=s.Phone.Functions; | 835 | Phone=s.Phone.Functions; |
835 | bool gshutdown = false; | 836 | bool gshutdown = false; |
836 | PhoneParser handler( calendar, mProfileName ); | 837 | PhoneParser handler( calendar, mProfileName ); |
837 | int ccc = 0; | 838 | int ccc = 0; |
838 | QString message = i18n("Processing event # "); | 839 | QString message = i18n(" Reading event # "); |
839 | int procCount = 0; | 840 | int procCount = 0; |
840 | qDebug("Debug: only 10 calender items are downloaded "); | 841 | qDebug("Debug: only 10 calender items are downloaded "); |
841 | while (!gshutdown && ccc++ < 10) { | 842 | while (!gshutdown && ccc++ < 10) { |
842 | status.setText ( message + QString::number ( ++procCount ) ); | 843 | status.setText ( message + QString::number ( ++procCount ) ); |
843 | qApp->processEvents(); | 844 | qApp->processEvents(); |
844 | qDebug("readEvent %d ", ccc); | 845 | qDebug("readEvent %d ", ccc); |
845 | error=Phone->GetNextCalendar(&s,¬e,start); | 846 | error=Phone->GetNextCalendar(&s,¬e,start); |
846 | if (error == ERR_EMPTY) break; | 847 | if (error == ERR_EMPTY) break; |
847 | start = false; | 848 | start = false; |
848 | handler.readEvent( existingCal, ¬e ); | 849 | handler.readEvent( existingCal, ¬e ); |
850 | qDebug("Org loc %d ",note.Location); | ||
851 | //note.Location = 0; | ||
852 | error=Phone->SetCalendar(&s,¬e); | ||
853 | qDebug("new loc %d ",note.Location); | ||
849 | } | 854 | } |
850 | 855 | ||
851 | start = true; | 856 | start = true; |
852 | GSM_ToDoEntry ToDo; | 857 | GSM_ToDoEntry ToDo; |
853 | ccc = 0; | 858 | ccc = 0; |
854 | message = i18n("Processing todo # "); | 859 | message = i18n(" Reading todo # "); |
855 | procCount = 0; | 860 | procCount = 0; |
856 | while (!gshutdown) { | 861 | while (!gshutdown && ccc++ < 10) { |
857 | status.setText ( message + QString::number ( ++procCount ) ); | 862 | status.setText ( message + QString::number ( ++procCount ) ); |
858 | qApp->processEvents(); | 863 | qApp->processEvents(); |
859 | error = Phone->GetNextToDo(&s, &ToDo, start); | 864 | error = Phone->GetNextToDo(&s, &ToDo, start); |
860 | if (error == ERR_EMPTY) break; | 865 | if (error == ERR_EMPTY) break; |
861 | start = false; | 866 | start = false; |
862 | qDebug("ReadTodo %d ", ++ccc); | 867 | qDebug("ReadTodo %d ", ccc); |
863 | handler.readTodo( existingCal, &ToDo, &s); | 868 | handler.readTodo( existingCal, &ToDo, &s); |
864 | 869 | ||
865 | } | 870 | } |
866 | 871 | ||
867 | error=GSM_TerminateConnection(&s); | 872 | error=GSM_TerminateConnection(&s); |
868 | 873 | ||
869 | return true; | 874 | return true; |
870 | } | 875 | } |
871 | void PhoneFormat::event2GSM( Event* ev, GSM_CalendarEntry*Note ) | 876 | #include <qcstring.h> |
877 | void PhoneFormat::event2GSM( Calendar *cal,Event* ev, GSM_CalendarEntry*Note ) | ||
872 | { | 878 | { |
873 | QString eText = vfconverter.eventToString( ev ); | 879 | QString eText = vfconverter.eventToString( ev, cal ); |
874 | int pos = 0; | 880 | int pos = 0; |
875 | GSM_ToDoEntry dummy; | 881 | GSM_ToDoEntry dummy; |
876 | GSM_DecodeVCALENDAR_VTODO( (unsigned char*)eText.latin1(), &pos, Note , &dummy, Nokia_VCalendar, Nokia_VToDo ); | 882 | qDebug( "Convert event"); |
883 | QByteArray ba; | ||
884 | QDataStream s ( ba, IO_WriteOnly ); | ||
885 | s << eText.utf8(); | ||
886 | GSM_DecodeVCALENDAR_VTODO( (unsigned char*) ba.data(), &pos, Note , &dummy, Nokia_VCalendar, Nokia_VToDo ); | ||
887 | qDebug( "Convert event done"); | ||
888 | Note->Location = 0; | ||
889 | QString loc = ev->getID(mProfileName); | ||
890 | if ( !loc.isEmpty() ){ | ||
891 | Note->Location = loc.toInt(); | ||
892 | } | ||
893 | |||
877 | } | 894 | } |
878 | void PhoneFormat::todo2GSM( Todo* todo, GSM_ToDoEntry *gsmTodo ) | 895 | void PhoneFormat::todo2GSM( Calendar *cal, Todo* todo, GSM_ToDoEntry *gsmTodo ) |
879 | { | 896 | { |
880 | QString tText = vfconverter.todoToString( todo ); | 897 | qDebug( "Convert todo1"); |
898 | QString tText = vfconverter.todoToString( todo, cal ); | ||
881 | int pos = 0; | 899 | int pos = 0; |
882 | GSM_CalendarEntry dummy; | 900 | GSM_CalendarEntry dummy; |
883 | GSM_DecodeVCALENDAR_VTODO( (unsigned char*)tText.latin1(), &pos, &dummy, gsmTodo, Nokia_VCalendar, Nokia_VToDo ); | 901 | QByteArray ba; |
902 | QDataStream s ( ba, IO_WriteOnly ); | ||
903 | s << tText.utf8(); | ||
904 | GSM_DecodeVCALENDAR_VTODO( (unsigned char*) ba.data(), &pos, &dummy, gsmTodo, Nokia_VCalendar, Nokia_VToDo ); | ||
905 | qDebug( "Convert todo done "); | ||
906 | gsmTodo->Location = 0; | ||
907 | QString loc = todo->getID(mProfileName); | ||
908 | if ( !loc.isEmpty() ){ | ||
909 | gsmTodo->Location = loc.toInt(); | ||
910 | } | ||
911 | |||
884 | } | 912 | } |
885 | void PhoneFormat::afterSave( Incidence* inc) | 913 | void PhoneFormat::afterSave( Incidence* inc) |
886 | { | 914 | { |
887 | uint csum; | 915 | uint csum; |
888 | if ( inc->type() == "Event") | 916 | if ( inc->type() == "Event") |
889 | csum = PhoneFormat::getCsumEvent( (Event*) inc ); | 917 | csum = PhoneFormat::getCsumEvent( (Event*) inc ); |
890 | else | 918 | else |
891 | csum = PhoneFormat::getCsumTodo( (Todo*) inc ); | 919 | csum = PhoneFormat::getCsumTodo( (Todo*) inc ); |
892 | inc->setCsum( mProfileName, QString::number( csum )); | 920 | inc->setCsum( mProfileName, QString::number( csum )); |
893 | inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 921 | inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); |
894 | 922 | ||
895 | } | 923 | } |
896 | bool PhoneFormat::save( Calendar *calendar) | 924 | bool PhoneFormat::save( Calendar *calendar) |
897 | { | 925 | { |
926 | return true; | ||
898 | GSM_StateMachines; | 927 | GSM_StateMachines; |
899 | qDebug(" save "); | 928 | qDebug(" save "); |
900 | s.opened = false; | 929 | s.opened = false; |
901 | s.msg = NULL; | 930 | s.msg = NULL; |
902 | s.ConfigNum = 0; | 931 | s.ConfigNum = 0; |
903 | QLabel status ( i18n("Writing data. Opening device ..."), 0 ); | 932 | QLabel status ( i18n(" Opening device ..."), 0 ); |
904 | int w = status.sizeHint().width()+20 ; | 933 | int w = status.sizeHint().width()+20 ; |
905 | if ( w < 200 ) w = 200; | 934 | if ( w < 200 ) w = 230; |
906 | int h = status.sizeHint().height()+20 ; | 935 | int h = status.sizeHint().height()+20 ; |
907 | int dw = QApplication::desktop()->width(); | 936 | int dw = QApplication::desktop()->width(); |
908 | int dh = QApplication::desktop()->height(); | 937 | int dh = QApplication::desktop()->height(); |
909 | status.setCaption(i18n("Writing Phone Data") ); | 938 | status.setCaption(i18n("Writing to phone...") ); |
910 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 939 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
911 | status.show(); | 940 | status.show(); |
912 | status.raise(); | 941 | status.raise(); |
913 | qApp->processEvents(); | 942 | qApp->processEvents(); |
914 | 943 | ||
915 | int error=initDevice(&s); | 944 | int error=initDevice(&s); |
916 | qDebug("GSM Init %d (no error is %d)", error, ERR_NONE); | 945 | qDebug("GSM Init %d (no error is %d)", error, ERR_NONE); |
917 | if ( error != ERR_NONE ) | 946 | if ( error != ERR_NONE ) |
918 | return false; | 947 | return false; |
919 | GSM_Phone_Functions*Phone; | 948 | GSM_Phone_Functions*Phone; |
920 | GSM_CalendarEntryNote; | 949 | GSM_CalendarEntryNote; |
921 | bool start = true; | 950 | bool start = true; |
922 | Phone=s.Phone.Functions; | 951 | Phone=s.Phone.Functions; |
923 | bool gshutdown = false; | 952 | bool gshutdown = false; |
924 | QPtrList<Event> er = calendar->rawEvents(); | 953 | QPtrList<Event> er = calendar->rawEvents(); |
925 | Event* ev = er.first(); | 954 | Event* ev = er.first(); |
926 | QString message = i18n("Processing event # "); | 955 | QString message = i18n(" Processing event # "); |
927 | int procCount = 0; | 956 | int procCount = 0; |
928 | while ( ev ) { | 957 | bool planB = true;// false; |
929 | //qDebug("i %d ", ++i); | 958 | while ( ev && ! planB) { |
930 | if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { // event was changed during sync or is a new one | 959 | if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { // event was changed during sync or is a new one |
931 | 960 | ||
932 | status.setText ( message + QString::number ( ++procCount ) ); | 961 | status.setText ( message + QString::number ( ++procCount ) ); |
933 | qApp->processEvents(); | 962 | qApp->processEvents(); |
934 | event2GSM( ev, &Note ); | 963 | qDebug("event1 %d ", procCount); |
964 | event2GSM( calendar, ev, &Note ); | ||
935 | if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete | 965 | if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete |
936 | error = Phone->DeleteCalendar(&s, &Note); | 966 | error = Phone->DeleteCalendar(&s, &Note); |
967 | if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { | ||
968 | planB = true; | ||
969 | qDebug(" e delete planB %d ", error); | ||
970 | break; | ||
971 | } | ||
937 | } | 972 | } |
938 | else if ( ev->getID(mProfileName).isEmpty() ) { // add new | 973 | else if ( ev->getID(mProfileName).isEmpty() ) { // add new |
939 | // we have to do this later after deleting | 974 | // we have to do this later after deleting |
940 | 975 | ||
941 | } | 976 | } |
942 | else { // change existing | 977 | else { // change existing |
943 | error = Phone->SetCalendar(&s, &Note); | 978 | error = Phone->SetCalendar(&s, &Note); |
979 | if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { | ||
980 | planB = true; | ||
981 | qDebug(" e change planB %d ", error); | ||
982 | break; | ||
983 | } | ||
984 | qDebug("Change Calendar. Location %d status: %d",Note.Location, error ); | ||
944 | } | 985 | } |
945 | } | 986 | } |
946 | ev = er.next(); | 987 | ev = er.next(); |
947 | } | 988 | } |
948 | ev = er.first(); | 989 | ev = er.first(); |
949 | // pending get empty slots | 990 | // pending get empty slots |
950 | while ( ev ) { | 991 | int loc = 0; |
992 | while ( ev && ! planB) { | ||
951 | if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL && ev->tempSyncStat() != SYNC_TEMPSTATE_DELETE) { | 993 | if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL && ev->tempSyncStat() != SYNC_TEMPSTATE_DELETE) { |
994 | qDebug("event2 %d ", procCount); | ||
952 | if ( ev->getID(mProfileName).isEmpty() ) { | 995 | if ( ev->getID(mProfileName).isEmpty() ) { |
953 | status.setText ( message + QString::number ( ++procCount ) ); | 996 | status.setText ( message + QString::number ( ++procCount ) ); |
954 | qApp->processEvents(); | 997 | qApp->processEvents(); |
955 | //int newID ;//= pending | 998 | //int newID ;//= pending |
956 | //ev->setID(mProfileName, QString::number( newID )); | 999 | //ev->setID(mProfileName, QString::number( newID )); |
957 | event2GSM( ev, &Note ); | 1000 | event2GSM( calendar, ev, &Note ); |
958 | Note.Location = 0; | 1001 | ++loc; |
1002 | Note.Location = loc; | ||
959 | error = Phone->AddCalendar(&s, &Note); | 1003 | error = Phone->AddCalendar(&s, &Note); |
1004 | if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { | ||
1005 | planB = true; | ||
1006 | qDebug(" e add planB %d ", error); | ||
1007 | break; | ||
1008 | } | ||
960 | ev->setID( mProfileName, QString::number( Note.Location ) ); | 1009 | ev->setID( mProfileName, QString::number( Note.Location ) ); |
961 | qDebug("New Calendar. Location %d ",Note.Location ); | 1010 | qDebug("New Calendar. Location %d stat %d %d",Note.Location ,error, ERR_UNKNOWN); |
962 | afterSave( ev ); | 1011 | afterSave( ev ); |
963 | } else { | 1012 | } else { |
964 | afterSave( ev ); // setting temp sync stat for changed items | 1013 | afterSave( ev ); // setting temp sync stat for changed items |
965 | } | 1014 | } |
966 | } | 1015 | } |
967 | ev = er.next(); | 1016 | ev = er.next(); |
968 | } | 1017 | } |
1018 | |||
1019 | |||
1020 | if ( planB ) { | ||
1021 | qDebug("delete all calendar..."); | ||
1022 | status.setText ( i18n("Deleting all calendar...")); | ||
1023 | qApp->processEvents(); | ||
1024 | error=Phone->DeleteAllCalendar(&s); | ||
1025 | if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { | ||
1026 | message = i18n(" Deleting event # "); | ||
1027 | procCount = 0; | ||
1028 | while (1) { | ||
1029 | status.setText ( message + QString::number ( ++procCount ) ); | ||
1030 | qApp->processEvents(); | ||
1031 | qDebug("deleting event ... %d", procCount); | ||
1032 | error = Phone->GetNextCalendar(&s,&Note,true); | ||
1033 | if (error != ERR_NONE) break; | ||
1034 | error = Phone->DeleteCalendar(&s,&Note); | ||
1035 | } | ||
1036 | qDebug("deleting calendar ... finished"); | ||
1037 | } else { | ||
1038 | status.setText ( i18n("All calendar deleted!")); | ||
1039 | qDebug("all cal deleted"); | ||
1040 | } | ||
1041 | bool planC = false; | ||
1042 | ev = er.first(); | ||
1043 | procCount = 0; | ||
1044 | message = i18n(" Writing event # "); | ||
1045 | while ( ev && ! planC) { | ||
1046 | status.setText ( message + QString::number ( ++procCount ) ); | ||
1047 | qApp->processEvents(); | ||
1048 | event2GSM( calendar, ev, &Note ); | ||
1049 | Note.Location = procCount; | ||
1050 | error=Phone->AddCalendar(&s,&Note); | ||
1051 | if (error != ERR_NONE ) { | ||
1052 | // we have currently no planC :-( | ||
1053 | // planC = true; | ||
1054 | //qDebug("add planC %d ", error); | ||
1055 | //break; | ||
1056 | // we remove the ID such that this todo is not deleted after next sync | ||
1057 | ev->removeID(mProfileName); | ||
1058 | ev->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | ||
1059 | qDebug("error :cal adding loc %d planB stat %d ", Note.Location ,error); | ||
1060 | } else { | ||
1061 | qDebug("cal adding loc %d planB stat %d ", Note.Location ,error); | ||
1062 | ev->setID(mProfileName, QString::number( Note.Location )); | ||
1063 | afterSave( ev ); | ||
1064 | } | ||
1065 | ev = er.next(); | ||
1066 | } | ||
1067 | if ( planC ) { | ||
1068 | qDebug("writing cal went wrong..."); | ||
1069 | |||
1070 | // we have currently no planC :-( | ||
1071 | } | ||
1072 | } | ||
969 | GSM_ToDoEntry ToDoEntry; | 1073 | GSM_ToDoEntry ToDoEntry; |
970 | QPtrList<Todo> tl = calendar->rawTodos(); | 1074 | QPtrList<Todo> tl = calendar->rawTodos(); |
971 | Todo* to = tl.first(); | 1075 | Todo* to = tl.first(); |
972 | 1076 | ||
973 | message = i18n("Processing todo # "); | 1077 | message = i18n(" Processing todo # "); |
974 | procCount = 0; | 1078 | procCount = 0; |
975 | while ( to ) { | 1079 | planB = false; |
1080 | while ( to && ! planB ) { | ||
976 | if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { | 1081 | if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { |
1082 | qDebug("todo3 %d ", procCount); | ||
977 | status.setText ( message + QString::number ( ++procCount ) ); | 1083 | status.setText ( message + QString::number ( ++procCount ) ); |
978 | qApp->processEvents(); | 1084 | qApp->processEvents(); |
979 | todo2GSM( to, &ToDoEntry ); | 1085 | qDebug("todo5 %d ", procCount); |
1086 | todo2GSM( calendar, to, &ToDoEntry ); | ||
980 | if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete | 1087 | if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete |
981 | error=Phone->DeleteToDo(&s,&ToDoEntry); | 1088 | error=Phone->DeleteToDo(&s,&ToDoEntry); |
1089 | if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { | ||
1090 | planB = true; | ||
1091 | qDebug("delete planB %d ", error); | ||
1092 | } | ||
982 | } | 1093 | } |
983 | else if ( to->getID("Sharp_DTM").isEmpty() ) { // add new | 1094 | else if ( to->getID(mProfileName).isEmpty() ) { // add new |
984 | ; | 1095 | ; |
985 | } | 1096 | } |
986 | else { // change existing | 1097 | else { // change existing |
987 | error=Phone->SetToDo(&s,&ToDoEntry); | 1098 | error=Phone->SetToDo(&s,&ToDoEntry); |
1099 | if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { | ||
1100 | planB = true; | ||
1101 | qDebug("set planB %d ", error); | ||
1102 | } | ||
1103 | qDebug("Old Todo. Location %d %d",ToDoEntry.Location , error ); | ||
988 | } | 1104 | } |
989 | } | 1105 | } |
990 | to = tl.next(); | 1106 | to = tl.next(); |
991 | } | 1107 | } |
992 | 1108 | ||
993 | // pending get empty slots | 1109 | // pending get empty slots |
994 | to = tl.first(); | 1110 | to = tl.first(); |
995 | while ( to ) { | 1111 | while ( to && ! planB ) { |
1112 | qDebug("todo2 %d ", procCount); | ||
996 | if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL && to->tempSyncStat() != SYNC_TEMPSTATE_DELETE) { | 1113 | if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL && to->tempSyncStat() != SYNC_TEMPSTATE_DELETE) { |
1114 | qDebug("todo4 %d ", procCount); | ||
997 | if ( to->getID(mProfileName).isEmpty() ) { | 1115 | if ( to->getID(mProfileName).isEmpty() ) { |
998 | status.setText ( message + QString::number ( ++procCount ) ); | 1116 | status.setText ( message + QString::number ( ++procCount ) ); |
999 | qApp->processEvents(); | 1117 | qApp->processEvents(); |
1000 | //int newID ;//= pending | 1118 | //int newID ;//= pending |
1001 | //to->setID(mProfileName, QString::number( newID )); | 1119 | //to->setID(mProfileName, QString::number( newID )); |
1002 | todo2GSM( to, &ToDoEntry ); | 1120 | todo2GSM( calendar,to, &ToDoEntry ); |
1003 | ToDoEntry.Location = 0; | 1121 | ToDoEntry.Location = 0; |
1004 | error=Phone->AddToDo(&s,&ToDoEntry); | 1122 | error=Phone->AddToDo(&s,&ToDoEntry); |
1123 | if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { | ||
1124 | planB = true; | ||
1125 | qDebug("new planB %d ", error); | ||
1126 | } | ||
1005 | to->setID(mProfileName, QString::number( ToDoEntry.Location )); | 1127 | to->setID(mProfileName, QString::number( ToDoEntry.Location )); |
1006 | afterSave( to ); | 1128 | afterSave( to ); |
1007 | qDebug("New Todo. Location %d ",ToDoEntry.Location ); | 1129 | qDebug("New Todo. Location %d %d",ToDoEntry.Location, error ); |
1008 | } else { | 1130 | } else { |
1009 | afterSave( to ); | 1131 | afterSave( to ); |
1010 | } | 1132 | } |
1011 | } | 1133 | } |
1012 | to = tl.next(); | 1134 | to = tl.next(); |
1013 | } | 1135 | } |
1136 | if ( planB ) { | ||
1137 | qDebug("delete all ..."); | ||
1138 | error=Phone->DeleteAllToDo(&s); | ||
1139 | if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { | ||
1140 | while (1) { | ||
1141 | qDebug("deleting todo ..."); | ||
1142 | error = Phone->GetNextToDo(&s,&ToDoEntry,true); | ||
1143 | if (error != ERR_NONE) break; | ||
1144 | error = Phone->DeleteToDo(&s,&ToDoEntry); | ||
1145 | } | ||
1146 | qDebug("deleting todo ... finished"); | ||
1147 | } else { | ||
1148 | qDebug("all todo deleted"); | ||
1149 | } | ||
1150 | bool planC = false; | ||
1151 | to = tl.first(); | ||
1152 | while ( to && ! planC ) { | ||
1153 | todo2GSM( calendar,to, &ToDoEntry ); | ||
1154 | ToDoEntry.Location = 0; | ||
1155 | error=Phone->AddToDo(&s,&ToDoEntry); | ||
1156 | if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { | ||
1157 | // we have currently no planC :-( | ||
1158 | // planC = true; | ||
1159 | //qDebug("add planC %d ", error); | ||
1160 | //break; | ||
1161 | // we remove the ID such that this todo is not deleted after next sync | ||
1162 | to->removeID(mProfileName); | ||
1163 | to->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | ||
1164 | } else { | ||
1165 | qDebug("adding %d planB %d ", ToDoEntry.Location ,error); | ||
1166 | to->setID(mProfileName, QString::number( ToDoEntry.Location )); | ||
1167 | afterSave( to ); | ||
1168 | } | ||
1169 | to = tl.next(); | ||
1170 | } | ||
1171 | if ( planC ) { | ||
1172 | // we have currently no planC :-( | ||
1173 | } | ||
1174 | } | ||
1014 | return true; | 1175 | return true; |
1015 | } | 1176 | } |
1016 | QString PhoneFormat::dtToGSM( const QDateTime& dti, bool useTZ ) | 1177 | QString PhoneFormat::dtToGSM( const QDateTime& dti, bool useTZ ) |
1017 | { | 1178 | { |
1018 | QString datestr; | 1179 | QString datestr; |
1019 | QString timestr; | 1180 | QString timestr; |
1020 | int offset = KGlobal::locale()->localTimeOffset( dti ); | 1181 | int offset = KGlobal::locale()->localTimeOffset( dti ); |
1021 | QDateTime dt; | 1182 | QDateTime dt; |
1022 | if (useTZ) | 1183 | if (useTZ) |
1023 | dt = dti.addSecs ( -(offset*60)); | 1184 | dt = dti.addSecs ( -(offset*60)); |
1024 | else | 1185 | else |
1025 | dt = dti; | 1186 | dt = dti; |
1026 | if(dt.date().isValid()){ | 1187 | if(dt.date().isValid()){ |
1027 | const QDate& date = dt.date(); | 1188 | const QDate& date = dt.date(); |
1028 | datestr.sprintf("%04d%02d%02d", | 1189 | datestr.sprintf("%04d%02d%02d", |
1029 | date.year(), date.month(), date.day()); | 1190 | date.year(), date.month(), date.day()); |
1030 | } | 1191 | } |
1031 | if(dt.time().isValid()){ | 1192 | if(dt.time().isValid()){ |
1032 | const QTime& time = dt.time(); | 1193 | const QTime& time = dt.time(); |
1033 | timestr.sprintf("T%02d%02d%02d", | 1194 | timestr.sprintf("T%02d%02d%02d", |
1034 | time.hour(), time.minute(), time.second()); | 1195 | time.hour(), time.minute(), time.second()); |
1035 | } | 1196 | } |
1036 | return datestr + timestr; | 1197 | return datestr + timestr; |
1037 | } | 1198 | } |
1038 | QString PhoneFormat::getEventString( Event* event ) | 1199 | QString PhoneFormat::getEventString( Event* event ) |
1039 | { | 1200 | { |
1040 | #if 0 | 1201 | #if 0 |
1041 | QStringList list; | 1202 | QStringList list; |
1042 | list.append( QString::number(event->zaurusId() ) ); | 1203 | list.append( QString::number(event->zaurusId() ) ); |
1043 | list.append( event->categories().join(",") ); | 1204 | list.append( event->categories().join(",") ); |
1044 | if ( !event->summary().isEmpty() ) | 1205 | if ( !event->summary().isEmpty() ) |
1045 | list.append( event->summary() ); | 1206 | list.append( event->summary() ); |
1046 | else | 1207 | else |
1047 | list.append("" ); | 1208 | list.append("" ); |
1048 | if ( !event->location().isEmpty() ) | 1209 | if ( !event->location().isEmpty() ) |
1049 | list.append( event->location() ); | 1210 | list.append( event->location() ); |
1050 | else | 1211 | else |
1051 | list.append("" ); | 1212 | list.append("" ); |
1052 | if ( !event->description().isEmpty() ) | 1213 | if ( !event->description().isEmpty() ) |
1053 | list.append( event->description() ); | 1214 | list.append( event->description() ); |
1054 | else | 1215 | else |
1055 | list.append( "" ); | 1216 | list.append( "" ); |
1056 | if ( event->doesFloat () ) { | 1217 | if ( event->doesFloat () ) { |
1057 | list.append( dtToString( QDateTime(event->dtStart().date(), QTime(0,0,0)), false )); | 1218 | list.append( dtToString( QDateTime(event->dtStart().date(), QTime(0,0,0)), false )); |
1058 | list.append( dtToString( QDateTime(event->dtEnd().date(),QTime(23,59,59)), false )); //6 | 1219 | list.append( dtToString( QDateTime(event->dtEnd().date(),QTime(23,59,59)), false )); //6 |
1059 | list.append( "1" ); | 1220 | list.append( "1" ); |
1060 | 1221 | ||
1061 | } | 1222 | } |
1062 | else { | 1223 | else { |
1063 | list.append( dtToString( event->dtStart()) ); | 1224 | list.append( dtToString( event->dtStart()) ); |
1064 | list.append( dtToString( event->dtEnd()) ); //6 | 1225 | list.append( dtToString( event->dtEnd()) ); //6 |
1065 | list.append( "0" ); | 1226 | list.append( "0" ); |
1066 | } | 1227 | } |
1067 | bool noAlarm = true; | 1228 | bool noAlarm = true; |
1068 | if ( event->alarms().count() > 0 ) { | 1229 | if ( event->alarms().count() > 0 ) { |
1069 | Alarm * al = event->alarms().first(); | 1230 | Alarm * al = event->alarms().first(); |
1070 | if ( al->enabled() ) { | 1231 | if ( al->enabled() ) { |
1071 | noAlarm = false; | 1232 | noAlarm = false; |
1072 | list.append( "0" ); // yes, 0 == alarm | 1233 | list.append( "0" ); // yes, 0 == alarm |
1073 | list.append( QString::number( al->startOffset().asSeconds()/(-60) ) ); | 1234 | list.append( QString::number( al->startOffset().asSeconds()/(-60) ) ); |
1074 | if ( al->type() == Alarm::Audio ) | 1235 | if ( al->type() == Alarm::Audio ) |
1075 | list.append( "1" ); // type audio | 1236 | list.append( "1" ); // type audio |
1076 | else | 1237 | else |
1077 | list.append( "0" ); // type silent | 1238 | list.append( "0" ); // type silent |
1078 | } | 1239 | } |
1079 | } | 1240 | } |
1080 | if ( noAlarm ) { | 1241 | if ( noAlarm ) { |
1081 | list.append( "1" ); // yes, 1 == no alarm | 1242 | list.append( "1" ); // yes, 1 == no alarm |
1082 | list.append( "0" ); // no alarm offset | 1243 | list.append( "0" ); // no alarm offset |
1083 | list.append( "1" ); // type | 1244 | list.append( "1" ); // type |
1084 | } | 1245 | } |
1085 | // next is: 11 | 1246 | // next is: 11 |
1086 | // next is: 11-16 are recurrence | 1247 | // next is: 11-16 are recurrence |
1087 | Recurrence* rec = event->recurrence(); | 1248 | Recurrence* rec = event->recurrence(); |
1088 | 1249 | ||
1089 | bool writeEndDate = false; | 1250 | bool writeEndDate = false; |
1090 | switch ( rec->doesRecur() ) | 1251 | switch ( rec->doesRecur() ) |
1091 | { | 1252 | { |
1092 | case Recurrence::rDaily: // 0 | 1253 | case Recurrence::rDaily: // 0 |
1093 | list.append( "0" ); | 1254 | list.append( "0" ); |
1094 | list.append( QString::number( rec->frequency() ));//12 | 1255 | list.append( QString::number( rec->frequency() ));//12 |
1095 | list.append( "0" ); | 1256 | list.append( "0" ); |
1096 | list.append( "0" ); | 1257 | list.append( "0" ); |
1097 | writeEndDate = true; | 1258 | writeEndDate = true; |
1098 | break; | 1259 | break; |
1099 | case Recurrence::rWeekly:// 1 | 1260 | case Recurrence::rWeekly:// 1 |
1100 | list.append( "1" ); | 1261 | list.append( "1" ); |
1101 | list.append( QString::number( rec->frequency()) );//12 | 1262 | list.append( QString::number( rec->frequency()) );//12 |
1102 | list.append( "0" ); | 1263 | list.append( "0" ); |
1103 | { | 1264 | { |
1104 | int days = 0; | 1265 | int days = 0; |
1105 | QBitArray weekDays = rec->days(); | 1266 | QBitArray weekDays = rec->days(); |
1106 | int i; | 1267 | int i; |
1107 | for( i = 1; i <= 7; ++i ) { | 1268 | for( i = 1; i <= 7; ++i ) { |
1108 | if ( weekDays[i-1] ) { | 1269 | if ( weekDays[i-1] ) { |
1109 | days += 1 << (i-1); | 1270 | days += 1 << (i-1); |
1110 | } | 1271 | } |
1111 | } | 1272 | } |
1112 | list.append( QString::number( days ) ); | 1273 | list.append( QString::number( days ) ); |
1113 | } | 1274 | } |
1114 | //pending weekdays | 1275 | //pending weekdays |
1115 | writeEndDate = true; | 1276 | writeEndDate = true; |
1116 | 1277 | ||
1117 | break; | 1278 | break; |
1118 | case Recurrence::rMonthlyPos:// 2 | 1279 | case Recurrence::rMonthlyPos:// 2 |
1119 | list.append( "2" ); | 1280 | list.append( "2" ); |
1120 | list.append( QString::number( rec->frequency()) );//12 | 1281 | list.append( QString::number( rec->frequency()) );//12 |
1121 | 1282 | ||
1122 | writeEndDate = true; | 1283 | writeEndDate = true; |
1123 | { | 1284 | { |
1124 | int count = 1; | 1285 | int count = 1; |
1125 | QPtrList<Recurrence::rMonthPos> rmp; | 1286 | QPtrList<Recurrence::rMonthPos> rmp; |
1126 | rmp = rec->monthPositions(); | 1287 | rmp = rec->monthPositions(); |
1127 | if ( rmp.first()->negative ) | 1288 | if ( rmp.first()->negative ) |
1128 | count = 5 - rmp.first()->rPos - 1; | 1289 | count = 5 - rmp.first()->rPos - 1; |
1129 | else | 1290 | else |
1130 | count = rmp.first()->rPos - 1; | 1291 | count = rmp.first()->rPos - 1; |
1131 | list.append( QString::number( count ) ); | 1292 | list.append( QString::number( count ) ); |
1132 | 1293 | ||
1133 | } | 1294 | } |
1134 | 1295 | ||
1135 | list.append( "0" ); | 1296 | list.append( "0" ); |
1136 | break; | 1297 | break; |
1137 | case Recurrence::rMonthlyDay:// 3 | 1298 | case Recurrence::rMonthlyDay:// 3 |
1138 | list.append( "3" ); | 1299 | list.append( "3" ); |
1139 | list.append( QString::number( rec->frequency()) );//12 | 1300 | list.append( QString::number( rec->frequency()) );//12 |
1140 | list.append( "0" ); | 1301 | list.append( "0" ); |
1141 | list.append( "0" ); | 1302 | list.append( "0" ); |
1142 | writeEndDate = true; | 1303 | writeEndDate = true; |
1143 | break; | 1304 | break; |
1144 | case Recurrence::rYearlyMonth://4 | 1305 | case Recurrence::rYearlyMonth://4 |
1145 | list.append( "4" ); | 1306 | list.append( "4" ); |
1146 | list.append( QString::number( rec->frequency()) );//12 | 1307 | list.append( QString::number( rec->frequency()) );//12 |
1147 | list.append( "0" ); | 1308 | list.append( "0" ); |
1148 | list.append( "0" ); | 1309 | list.append( "0" ); |
1149 | writeEndDate = true; | 1310 | writeEndDate = true; |
1150 | break; | 1311 | break; |
1151 | 1312 | ||
1152 | default: | 1313 | default: |
1153 | list.append( "255" ); | 1314 | list.append( "255" ); |
1154 | list.append( QString() ); | 1315 | list.append( QString() ); |
1155 | list.append( "0" ); | 1316 | list.append( "0" ); |
1156 | list.append( QString() ); | 1317 | list.append( QString() ); |
1157 | list.append( "0" ); | 1318 | list.append( "0" ); |
1158 | list.append( "20991231T000000" ); | 1319 | list.append( "20991231T000000" ); |
1159 | break; | 1320 | break; |
1160 | } | 1321 | } |
1161 | if ( writeEndDate ) { | 1322 | if ( writeEndDate ) { |
1162 | 1323 | ||
1163 | if ( rec->endDate().isValid() ) { // 15 + 16 | 1324 | if ( rec->endDate().isValid() ) { // 15 + 16 |
1164 | list.append( "1" ); | 1325 | list.append( "1" ); |
1165 | list.append( dtToString( rec->endDate()) ); | 1326 | list.append( dtToString( rec->endDate()) ); |
1166 | } else { | 1327 | } else { |
1167 | list.append( "0" ); | 1328 | list.append( "0" ); |
1168 | list.append( "20991231T000000" ); | 1329 | list.append( "20991231T000000" ); |
1169 | } | 1330 | } |
1170 | 1331 | ||
1171 | } | 1332 | } |
1172 | if ( event->doesFloat () ) { | 1333 | if ( event->doesFloat () ) { |
1173 | list.append( dtToString( event->dtStart(), false ).left( 8 )); | 1334 | list.append( dtToString( event->dtStart(), false ).left( 8 )); |
1174 | list.append( dtToString( event->dtEnd(), false ).left( 8 )); //6 | 1335 | list.append( dtToString( event->dtEnd(), false ).left( 8 )); //6 |
1175 | 1336 | ||
1176 | } | 1337 | } |
1177 | else { | 1338 | else { |
1178 | list.append( QString() ); | 1339 | list.append( QString() ); |
1179 | list.append( QString() ); | 1340 | list.append( QString() ); |
1180 | 1341 | ||
1181 | } | 1342 | } |
1182 | if (event->dtStart().date() == event->dtEnd().date() ) | 1343 | if (event->dtStart().date() == event->dtEnd().date() ) |
1183 | list.append( "0" ); | 1344 | list.append( "0" ); |
1184 | else | 1345 | else |
1185 | list.append( "1" ); | 1346 | list.append( "1" ); |
1186 | 1347 | ||
1187 | 1348 | ||
1188 | for(QStringList::Iterator it=list.begin(); | 1349 | for(QStringList::Iterator it=list.begin(); |
1189 | it!=list.end(); ++it){ | 1350 | it!=list.end(); ++it){ |
1190 | QString& s = (*it); | 1351 | QString& s = (*it); |
1191 | s.replace(QRegExp("\""), "\"\""); | 1352 | s.replace(QRegExp("\""), "\"\""); |
1192 | if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){ | 1353 | if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){ |
1193 | s.prepend('\"'); | 1354 | s.prepend('\"'); |
1194 | s.append('\"'); | 1355 | s.append('\"'); |
1195 | } else if(s.isEmpty() && !s.isNull()){ | 1356 | } else if(s.isEmpty() && !s.isNull()){ |
1196 | s = "\"\""; | 1357 | s = "\"\""; |
1197 | } | 1358 | } |
1198 | } | 1359 | } |
1199 | return list.join(","); | 1360 | return list.join(","); |
1200 | #endif | 1361 | #endif |
1201 | return QString(); | 1362 | return QString(); |
1202 | 1363 | ||
1203 | } | 1364 | } |
1204 | QString PhoneFormat::getTodoString( Todo* todo ) | 1365 | QString PhoneFormat::getTodoString( Todo* todo ) |
1205 | { | 1366 | { |
1206 | #if 0 | 1367 | #if 0 |
1207 | QStringList list; | 1368 | QStringList list; |
1208 | list.append( QString::number( todo->zaurusId() ) ); | 1369 | list.append( QString::number( todo->zaurusId() ) ); |
1209 | list.append( todo->categories().join(",") ); | 1370 | list.append( todo->categories().join(",") ); |
1210 | 1371 | ||
1211 | if ( todo->hasStartDate() ) { | 1372 | if ( todo->hasStartDate() ) { |
1212 | list.append( dtToString( todo->dtStart()) ); | 1373 | list.append( dtToString( todo->dtStart()) ); |
1213 | } else | 1374 | } else |
1214 | list.append( QString() ); | 1375 | list.append( QString() ); |
1215 | 1376 | ||
1216 | if ( todo->hasDueDate() ) { | 1377 | if ( todo->hasDueDate() ) { |
1217 | QTime tim; | 1378 | QTime tim; |
1218 | if ( todo->doesFloat()) { | 1379 | if ( todo->doesFloat()) { |
1219 | list.append( dtToString( QDateTime(todo->dtDue().date(),QTime( 0,0,0 )), false)) ; | 1380 | list.append( dtToString( QDateTime(todo->dtDue().date(),QTime( 0,0,0 )), false)) ; |
1220 | } else { | 1381 | } else { |
1221 | list.append( dtToString(todo->dtDue() ) ); | 1382 | list.append( dtToString(todo->dtDue() ) ); |
1222 | } | 1383 | } |
1223 | } else | 1384 | } else |
1224 | list.append( QString() ); | 1385 | list.append( QString() ); |
1225 | 1386 | ||
1226 | if ( todo->isCompleted() ) { | 1387 | if ( todo->isCompleted() ) { |
1227 | list.append( dtToString( todo->completed()) ); | 1388 | list.append( dtToString( todo->completed()) ); |
1228 | list.append( "0" ); // yes 0 == completed | 1389 | list.append( "0" ); // yes 0 == completed |
1229 | } else { | 1390 | } else { |
1230 | list.append( dtToString( todo->completed()) ); | 1391 | list.append( dtToString( todo->completed()) ); |
1231 | list.append( "1" ); | 1392 | list.append( "1" ); |
1232 | } | 1393 | } |
1233 | list.append( QString::number( todo->priority() )); | 1394 | list.append( QString::number( todo->priority() )); |
1234 | if( ! todo->summary().isEmpty() ) | 1395 | if( ! todo->summary().isEmpty() ) |
1235 | list.append( todo->summary() ); | 1396 | list.append( todo->summary() ); |
1236 | else | 1397 | else |
1237 | list.append( "" ); | 1398 | list.append( "" ); |
1238 | if (! todo->description().isEmpty() ) | 1399 | if (! todo->description().isEmpty() ) |
1239 | list.append( todo->description() ); | 1400 | list.append( todo->description() ); |
1240 | else | 1401 | else |
1241 | list.append( "" ); | 1402 | list.append( "" ); |
1242 | for(QStringList::Iterator it=list.begin(); | 1403 | for(QStringList::Iterator it=list.begin(); |
1243 | it!=list.end(); ++it){ | 1404 | it!=list.end(); ++it){ |
1244 | QString& s = (*it); | 1405 | QString& s = (*it); |
1245 | s.replace(QRegExp("\""), "\"\""); | 1406 | s.replace(QRegExp("\""), "\"\""); |
1246 | if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){ | 1407 | if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){ |
1247 | s.prepend('\"'); | 1408 | s.prepend('\"'); |
1248 | s.append('\"'); | 1409 | s.append('\"'); |
1249 | } else if(s.isEmpty() && !s.isNull()){ | 1410 | } else if(s.isEmpty() && !s.isNull()){ |
1250 | s = "\"\""; | 1411 | s = "\"\""; |
1251 | } | 1412 | } |
1252 | } | 1413 | } |
1253 | return list.join(","); | 1414 | return list.join(","); |
1254 | #endif | 1415 | #endif |
1255 | return QString(); | 1416 | return QString(); |
1256 | } | 1417 | } |
1257 | 1418 | ||
1258 | 1419 | ||
1259 | QString PhoneFormat::toString( Calendar * ) | 1420 | QString PhoneFormat::toString( Calendar * ) |
1260 | { | 1421 | { |
1261 | return QString::null; | 1422 | return QString::null; |
1262 | } | 1423 | } |
1263 | bool PhoneFormat::fromString( Calendar *calendar, const QString & text) | 1424 | bool PhoneFormat::fromString( Calendar *calendar, const QString & text) |
1264 | { | 1425 | { |
1265 | return false; | 1426 | return false; |
1266 | } | 1427 | } |
diff --git a/libkcal/phoneformat.h b/libkcal/phoneformat.h index 33b2091..2c2e51c 100644 --- a/libkcal/phoneformat.h +++ b/libkcal/phoneformat.h | |||
@@ -1,67 +1,67 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | 3 | ||
4 | Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> | 4 | Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> |
5 | 5 | ||
6 | This library is free software; you can redistribute it and/or | 6 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Library General Public | 7 | modify it under the terms of the GNU Library General Public |
8 | License as published by the Free Software Foundation; either | 8 | License as published by the Free Software Foundation; either |
9 | version 2 of the License, or (at your option) any later version. | 9 | version 2 of the License, or (at your option) any later version. |
10 | 10 | ||
11 | This library is distributed in the hope that it will be useful, | 11 | This library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Library General Public License for more details. | 14 | Library General Public License for more details. |
15 | 15 | ||
16 | You should have received a copy of the GNU Library General Public License | 16 | You should have received a copy of the GNU Library General Public License |
17 | along with this library; see the file COPYING.LIB. If not, write to | 17 | along with this library; see the file COPYING.LIB. If not, write to |
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
19 | Boston, MA 02111-1307, USA. | 19 | Boston, MA 02111-1307, USA. |
20 | */ | 20 | */ |
21 | #ifndef PHONEFORMAT_H | 21 | #ifndef PHONEFORMAT_H |
22 | #define PHONEFORMAT_H | 22 | #define PHONEFORMAT_H |
23 | 23 | ||
24 | #include <qstring.h> | 24 | #include <qstring.h> |
25 | 25 | ||
26 | #include "scheduler.h" | 26 | #include "scheduler.h" |
27 | 27 | ||
28 | #include "vcalformat.h" | 28 | #include "vcalformat.h" |
29 | #include "calformat.h" | 29 | #include "calformat.h" |
30 | extern "C" { | 30 | extern "C" { |
31 | #include "../gammu/emb/common/gammu.h" | 31 | #include "../gammu/emb/common/gammu.h" |
32 | } | 32 | } |
33 | namespace KCal { | 33 | namespace KCal { |
34 | 34 | ||
35 | /** | 35 | /** |
36 | This class implements the calendar format used by Phone. | 36 | This class implements the calendar format used by Phone. |
37 | */ | 37 | */ |
38 | class Event; | 38 | class Event; |
39 | class Todo; | 39 | class Todo; |
40 | class PhoneFormat : public QObject { | 40 | class PhoneFormat : public QObject { |
41 | public: | 41 | public: |
42 | /** Create new iCalendar format. */ | 42 | /** Create new iCalendar format. */ |
43 | PhoneFormat(QString profileName, QString device,QString connection, QString model); | 43 | PhoneFormat(QString profileName, QString device,QString connection, QString model); |
44 | virtual ~PhoneFormat(); | 44 | virtual ~PhoneFormat(); |
45 | 45 | ||
46 | bool load( Calendar * ,Calendar * ); | 46 | bool load( Calendar * ,Calendar * ); |
47 | bool save( Calendar * ); | 47 | bool save( Calendar * ); |
48 | bool fromString( Calendar *, const QString & ); | 48 | bool fromString( Calendar *, const QString & ); |
49 | QString toString( Calendar * ); | 49 | QString toString( Calendar * ); |
50 | static ulong getCsum( const QStringList & ); | 50 | static ulong getCsum( const QStringList & ); |
51 | static ulong getCsumTodo( Todo* to ); | 51 | static ulong getCsumTodo( Todo* to ); |
52 | static ulong getCsumEvent( Event* ev ); | 52 | static ulong getCsumEvent( Event* ev ); |
53 | private: | 53 | private: |
54 | VCalFormat vfconverter; | 54 | VCalFormat vfconverter; |
55 | void event2GSM( Event* ev, GSM_CalendarEntry*Note ); | 55 | void event2GSM( Calendar *, Event* ev, GSM_CalendarEntry*Note ); |
56 | void todo2GSM( Todo* ev, GSM_ToDoEntry *ToDo ); | 56 | void todo2GSM( Calendar *, Todo* ev, GSM_ToDoEntry *ToDo ); |
57 | int initDevice(GSM_StateMachine *s); | 57 | int initDevice(GSM_StateMachine *s); |
58 | QString getEventString( Event* ); | 58 | QString getEventString( Event* ); |
59 | QString getTodoString( Todo* ); | 59 | QString getTodoString( Todo* ); |
60 | QString dtToGSM( const QDateTime& dt, bool useTZ = true ); | 60 | QString dtToGSM( const QDateTime& dt, bool useTZ = true ); |
61 | QString mProfileName, mDevice, mConnection, mModel; | 61 | QString mProfileName, mDevice, mConnection, mModel; |
62 | void afterSave( Incidence* ); | 62 | void afterSave( Incidence* ); |
63 | }; | 63 | }; |
64 | 64 | ||
65 | } | 65 | } |
66 | 66 | ||
67 | #endif | 67 | #endif |
diff --git a/libkcal/vcalformat.cpp b/libkcal/vcalformat.cpp index 1167e58..076cd3f 100644 --- a/libkcal/vcalformat.cpp +++ b/libkcal/vcalformat.cpp | |||
@@ -1,947 +1,950 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | Copyright (c) 1998 Preston Brwon | 3 | Copyright (c) 1998 Preston Brwon |
4 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 4 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
5 | 5 | ||
6 | This library is free software; you can redistribute it and/or | 6 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Library General Public | 7 | modify it under the terms of the GNU Library General Public |
8 | License as published by the Free Software Foundation; either | 8 | License as published by the Free Software Foundation; either |
9 | version 2 of the License, or (at your option) any later version. | 9 | version 2 of the License, or (at your option) any later version. |
10 | 10 | ||
11 | This library is distributed in the hope that it will be useful, | 11 | This library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Library General Public License for more details. | 14 | Library General Public License for more details. |
15 | 15 | ||
16 | You should have received a copy of the GNU Library General Public License | 16 | You should have received a copy of the GNU Library General Public License |
17 | along with this library; see the file COPYING.LIB. If not, write to | 17 | along with this library; see the file COPYING.LIB. If not, write to |
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
19 | Boston, MA 02111-1307, USA. | 19 | Boston, MA 02111-1307, USA. |
20 | */ | 20 | */ |
21 | 21 | ||
22 | #include <qapplication.h> | 22 | #include <qapplication.h> |
23 | #include <qdatetime.h> | 23 | #include <qdatetime.h> |
24 | #include <qstring.h> | 24 | #include <qstring.h> |
25 | #include <qptrlist.h> | 25 | #include <qptrlist.h> |
26 | #include <qregexp.h> | 26 | #include <qregexp.h> |
27 | #include <qclipboard.h> | 27 | #include <qclipboard.h> |
28 | #include <qdialog.h> | 28 | #include <qdialog.h> |
29 | #include <qfile.h> | 29 | #include <qfile.h> |
30 | 30 | ||
31 | #include <kdebug.h> | 31 | #include <kdebug.h> |
32 | #include <kmessagebox.h> | 32 | #include <kmessagebox.h> |
33 | #include <kiconloader.h> | 33 | #include <kiconloader.h> |
34 | #include <klocale.h> | 34 | #include <klocale.h> |
35 | 35 | ||
36 | #include "vcc.h" | 36 | #include "vcc.h" |
37 | #include "vobject.h" | 37 | #include "vobject.h" |
38 | 38 | ||
39 | #include "vcaldrag.h" | 39 | #include "vcaldrag.h" |
40 | #include "calendar.h" | 40 | #include "calendar.h" |
41 | 41 | ||
42 | #include "vcalformat.h" | 42 | #include "vcalformat.h" |
43 | 43 | ||
44 | using namespace KCal; | 44 | using namespace KCal; |
45 | 45 | ||
46 | VCalFormat::VCalFormat() | 46 | VCalFormat::VCalFormat() |
47 | { | 47 | { |
48 | mCalendar = 0; | ||
48 | } | 49 | } |
49 | 50 | ||
50 | VCalFormat::~VCalFormat() | 51 | VCalFormat::~VCalFormat() |
51 | { | 52 | { |
52 | } | 53 | } |
53 | 54 | ||
54 | bool VCalFormat::load(Calendar *calendar, const QString &fileName) | 55 | bool VCalFormat::load(Calendar *calendar, const QString &fileName) |
55 | { | 56 | { |
56 | mCalendar = calendar; | 57 | mCalendar = calendar; |
57 | 58 | ||
58 | clearException(); | 59 | clearException(); |
59 | 60 | ||
60 | kdDebug(5800) << "VCalFormat::load() " << fileName << endl; | 61 | kdDebug(5800) << "VCalFormat::load() " << fileName << endl; |
61 | 62 | ||
62 | VObject *vcal = 0; | 63 | VObject *vcal = 0; |
63 | 64 | ||
64 | // this is not necessarily only 1 vcal. Could be many vcals, or include | 65 | // this is not necessarily only 1 vcal. Could be many vcals, or include |
65 | // a vcard... | 66 | // a vcard... |
66 | vcal = Parse_MIME_FromFileName(const_cast<char *>(QFile::encodeName(fileName).data())); | 67 | vcal = Parse_MIME_FromFileName(const_cast<char *>(QFile::encodeName(fileName).data())); |
67 | 68 | ||
68 | if (!vcal) { | 69 | if (!vcal) { |
69 | setException(new ErrorFormat(ErrorFormat::CalVersionUnknown)); | 70 | setException(new ErrorFormat(ErrorFormat::CalVersionUnknown)); |
70 | return FALSE; | 71 | return FALSE; |
71 | } | 72 | } |
72 | 73 | ||
73 | // any other top-level calendar stuff should be added/initialized here | 74 | // any other top-level calendar stuff should be added/initialized here |
74 | 75 | ||
75 | // put all vobjects into their proper places | 76 | // put all vobjects into their proper places |
76 | populate(vcal); | 77 | populate(vcal); |
77 | 78 | ||
78 | // clean up from vcal API stuff | 79 | // clean up from vcal API stuff |
79 | cleanVObjects(vcal); | 80 | cleanVObjects(vcal); |
80 | cleanStrTbl(); | 81 | cleanStrTbl(); |
81 | 82 | ||
82 | return true; | 83 | return true; |
83 | } | 84 | } |
84 | 85 | ||
85 | 86 | ||
86 | bool VCalFormat::save(Calendar *calendar, const QString &fileName) | 87 | bool VCalFormat::save(Calendar *calendar, const QString &fileName) |
87 | { | 88 | { |
88 | mCalendar = calendar; | 89 | mCalendar = calendar; |
89 | 90 | ||
90 | QString tmpStr; | 91 | QString tmpStr; |
91 | VObject *vcal, *vo; | 92 | VObject *vcal, *vo; |
92 | 93 | ||
93 | kdDebug(5800) << "VCalFormat::save(): " << fileName << endl; | 94 | kdDebug(5800) << "VCalFormat::save(): " << fileName << endl; |
94 | 95 | ||
95 | vcal = newVObject(VCCalProp); | 96 | vcal = newVObject(VCCalProp); |
96 | 97 | ||
97 | // addPropValue(vcal,VCLocationProp, "0.0"); | 98 | // addPropValue(vcal,VCLocationProp, "0.0"); |
98 | addPropValue(vcal,VCProdIdProp, productId()); | 99 | addPropValue(vcal,VCProdIdProp, productId()); |
99 | tmpStr = mCalendar->getTimeZoneStr(); | 100 | tmpStr = mCalendar->getTimeZoneStr(); |
100 | //qDebug("mCalendar->getTimeZoneStr() %s",tmpStr.latin1() ); | 101 | //qDebug("mCalendar->getTimeZoneStr() %s",tmpStr.latin1() ); |
101 | addPropValue(vcal,VCTimeZoneProp, tmpStr.local8Bit()); | 102 | addPropValue(vcal,VCTimeZoneProp, tmpStr.local8Bit()); |
102 | addPropValue(vcal,VCVersionProp, _VCAL_VERSION); | 103 | addPropValue(vcal,VCVersionProp, _VCAL_VERSION); |
103 | 104 | ||
104 | // TODO STUFF | 105 | // TODO STUFF |
105 | QPtrList<Todo> todoList = mCalendar->rawTodos(); | 106 | QPtrList<Todo> todoList = mCalendar->rawTodos(); |
106 | QPtrListIterator<Todo> qlt(todoList); | 107 | QPtrListIterator<Todo> qlt(todoList); |
107 | for (; qlt.current(); ++qlt) { | 108 | for (; qlt.current(); ++qlt) { |
108 | vo = eventToVTodo(qlt.current()); | 109 | vo = eventToVTodo(qlt.current()); |
109 | addVObjectProp(vcal, vo); | 110 | addVObjectProp(vcal, vo); |
110 | } | 111 | } |
111 | 112 | ||
112 | // EVENT STUFF | 113 | // EVENT STUFF |
113 | QPtrList<Event> events = mCalendar->rawEvents(); | 114 | QPtrList<Event> events = mCalendar->rawEvents(); |
114 | Event *ev; | 115 | Event *ev; |
115 | for(ev=events.first();ev;ev=events.next()) { | 116 | for(ev=events.first();ev;ev=events.next()) { |
116 | vo = eventToVEvent(ev); | 117 | vo = eventToVEvent(ev); |
117 | addVObjectProp(vcal, vo); | 118 | addVObjectProp(vcal, vo); |
118 | } | 119 | } |
119 | 120 | ||
120 | writeVObjectToFile(QFile::encodeName(fileName).data() ,vcal); | 121 | writeVObjectToFile(QFile::encodeName(fileName).data() ,vcal); |
121 | cleanVObjects(vcal); | 122 | cleanVObjects(vcal); |
122 | cleanStrTbl(); | 123 | cleanStrTbl(); |
123 | 124 | ||
124 | if (QFile::exists(fileName)) { | 125 | if (QFile::exists(fileName)) { |
125 | kdDebug(5800) << "No error" << endl; | 126 | kdDebug(5800) << "No error" << endl; |
126 | return true; | 127 | return true; |
127 | } else { | 128 | } else { |
128 | kdDebug(5800) << "Error" << endl; | 129 | kdDebug(5800) << "Error" << endl; |
129 | return false; // error | 130 | return false; // error |
130 | } | 131 | } |
131 | } | 132 | } |
132 | 133 | ||
133 | bool VCalFormat::fromString( Calendar *calendar, const QString &text ) | 134 | bool VCalFormat::fromString( Calendar *calendar, const QString &text ) |
134 | { | 135 | { |
135 | // TODO: Factor out VCalFormat::fromString() | 136 | // TODO: Factor out VCalFormat::fromString() |
136 | 137 | ||
137 | QCString data = text.utf8(); | 138 | QCString data = text.utf8(); |
138 | 139 | ||
139 | if ( !data.size() ) return false; | 140 | if ( !data.size() ) return false; |
140 | 141 | ||
141 | VObject *vcal = Parse_MIME( data.data(), data.size()); | 142 | VObject *vcal = Parse_MIME( data.data(), data.size()); |
142 | if ( !vcal ) return false; | 143 | if ( !vcal ) return false; |
143 | 144 | ||
144 | VObjectIterator i; | 145 | VObjectIterator i; |
145 | VObject *curvo; | 146 | VObject *curvo; |
146 | initPropIterator( &i, vcal ); | 147 | initPropIterator( &i, vcal ); |
147 | 148 | ||
148 | // we only take the first object. TODO: parse all incidences. | 149 | // we only take the first object. TODO: parse all incidences. |
149 | do { | 150 | do { |
150 | curvo = nextVObject( &i ); | 151 | curvo = nextVObject( &i ); |
151 | } while ( strcmp( vObjectName( curvo ), VCEventProp ) && | 152 | } while ( strcmp( vObjectName( curvo ), VCEventProp ) && |
152 | strcmp( vObjectName( curvo ), VCTodoProp ) ); | 153 | strcmp( vObjectName( curvo ), VCTodoProp ) ); |
153 | 154 | ||
154 | if ( strcmp( vObjectName( curvo ), VCEventProp ) == 0 ) { | 155 | if ( strcmp( vObjectName( curvo ), VCEventProp ) == 0 ) { |
155 | Event *event = VEventToEvent( curvo ); | 156 | Event *event = VEventToEvent( curvo ); |
156 | calendar->addEvent( event ); | 157 | calendar->addEvent( event ); |
157 | } else { | 158 | } else { |
158 | kdDebug(5800) << "VCalFormat::fromString(): Unknown object type." << endl; | 159 | kdDebug(5800) << "VCalFormat::fromString(): Unknown object type." << endl; |
159 | deleteVObject( vcal ); | 160 | deleteVObject( vcal ); |
160 | return false; | 161 | return false; |
161 | } | 162 | } |
162 | 163 | ||
163 | deleteVObject( vcal ); | 164 | deleteVObject( vcal ); |
164 | 165 | ||
165 | return true; | 166 | return true; |
166 | } | 167 | } |
167 | 168 | ||
168 | QString VCalFormat::eventToString( Event * event) | 169 | QString VCalFormat::eventToString( Event * event, Calendar *calendar) |
169 | { | 170 | { |
170 | if ( !event ) return QString::null; | 171 | if ( !event ) return QString::null; |
172 | mCalendar = calendar; | ||
171 | VObject *vevent = eventToVEvent( event ); | 173 | VObject *vevent = eventToVEvent( event ); |
172 | char *buf = writeMemVObject( 0, 0, vevent ); | 174 | char *buf = writeMemVObject( 0, 0, vevent ); |
173 | QString result( buf ); | 175 | QString result( buf ); |
174 | cleanVObject( vevent ); | 176 | cleanVObject( vevent ); |
175 | return result; | 177 | return result; |
176 | } | 178 | } |
177 | QString VCalFormat::todoToString( Todo * todo ) | 179 | QString VCalFormat::todoToString( Todo * todo, Calendar *calendar ) |
178 | { | 180 | { |
179 | if ( !todo ) return QString::null; | 181 | if ( !todo ) return QString::null; |
182 | mCalendar = calendar; | ||
180 | VObject *vevent = eventToVTodo( todo ); | 183 | VObject *vevent = eventToVTodo( todo ); |
181 | char *buf = writeMemVObject( 0, 0, vevent ); | 184 | char *buf = writeMemVObject( 0, 0, vevent ); |
182 | QString result( buf ); | 185 | QString result( buf ); |
183 | cleanVObject( vevent ); | 186 | cleanVObject( vevent ); |
184 | return result; | 187 | return result; |
185 | } | 188 | } |
186 | 189 | ||
187 | QString VCalFormat::toString( Calendar *calendar ) | 190 | QString VCalFormat::toString( Calendar *calendar ) |
188 | { | 191 | { |
189 | // TODO: Factor out VCalFormat::asString() | 192 | // TODO: Factor out VCalFormat::asString() |
190 | 193 | ||
191 | VObject *vcal = newVObject(VCCalProp); | 194 | VObject *vcal = newVObject(VCCalProp); |
192 | 195 | ||
193 | addPropValue( vcal, VCProdIdProp, CalFormat::productId() ); | 196 | addPropValue( vcal, VCProdIdProp, CalFormat::productId() ); |
194 | QString tmpStr = mCalendar->getTimeZoneStr(); | 197 | QString tmpStr = mCalendar->getTimeZoneStr(); |
195 | addPropValue( vcal, VCTimeZoneProp, tmpStr.local8Bit() ); | 198 | addPropValue( vcal, VCTimeZoneProp, tmpStr.local8Bit() ); |
196 | addPropValue( vcal, VCVersionProp, _VCAL_VERSION ); | 199 | addPropValue( vcal, VCVersionProp, _VCAL_VERSION ); |
197 | 200 | ||
198 | // TODO: Use all data. | 201 | // TODO: Use all data. |
199 | QPtrList<Event> events = calendar->events(); | 202 | QPtrList<Event> events = calendar->events(); |
200 | Event *event = events.first(); | 203 | Event *event = events.first(); |
201 | if ( !event ) return QString::null; | 204 | if ( !event ) return QString::null; |
202 | 205 | ||
203 | VObject *vevent = eventToVEvent( event ); | 206 | VObject *vevent = eventToVEvent( event ); |
204 | 207 | ||
205 | addVObjectProp( vcal, vevent ); | 208 | addVObjectProp( vcal, vevent ); |
206 | 209 | ||
207 | char *buf = writeMemVObject( 0, 0, vcal ); | 210 | char *buf = writeMemVObject( 0, 0, vcal ); |
208 | 211 | ||
209 | QString result( buf ); | 212 | QString result( buf ); |
210 | 213 | ||
211 | cleanVObject( vcal ); | 214 | cleanVObject( vcal ); |
212 | 215 | ||
213 | return result; | 216 | return result; |
214 | } | 217 | } |
215 | 218 | ||
216 | VObject *VCalFormat::eventToVTodo(const Todo *anEvent) | 219 | VObject *VCalFormat::eventToVTodo(const Todo *anEvent) |
217 | { | 220 | { |
218 | VObject *vtodo; | 221 | VObject *vtodo; |
219 | QString tmpStr; | 222 | QString tmpStr; |
220 | QStringList tmpStrList; | 223 | QStringList tmpStrList; |
221 | 224 | ||
222 | vtodo = newVObject(VCTodoProp); | 225 | vtodo = newVObject(VCTodoProp); |
223 | 226 | ||
224 | // due date | 227 | // due date |
225 | if (anEvent->hasDueDate()) { | 228 | if (anEvent->hasDueDate()) { |
226 | tmpStr = qDateTimeToISO(anEvent->dtDue(), | 229 | tmpStr = qDateTimeToISO(anEvent->dtDue(), |
227 | !anEvent->doesFloat()); | 230 | !anEvent->doesFloat()); |
228 | addPropValue(vtodo, VCDueProp, tmpStr.local8Bit()); | 231 | addPropValue(vtodo, VCDueProp, tmpStr.local8Bit()); |
229 | } | 232 | } |
230 | 233 | ||
231 | // start date | 234 | // start date |
232 | if (anEvent->hasStartDate()) { | 235 | if (anEvent->hasStartDate()) { |
233 | tmpStr = qDateTimeToISO(anEvent->dtStart(), | 236 | tmpStr = qDateTimeToISO(anEvent->dtStart(), |
234 | !anEvent->doesFloat()); | 237 | !anEvent->doesFloat()); |
235 | addPropValue(vtodo, VCDTstartProp, tmpStr.local8Bit()); | 238 | addPropValue(vtodo, VCDTstartProp, tmpStr.local8Bit()); |
236 | } | 239 | } |
237 | 240 | ||
238 | // creation date | 241 | // creation date |
239 | tmpStr = qDateTimeToISO(anEvent->created()); | 242 | tmpStr = qDateTimeToISO(anEvent->created()); |
240 | addPropValue(vtodo, VCDCreatedProp, tmpStr.local8Bit()); | 243 | addPropValue(vtodo, VCDCreatedProp, tmpStr.local8Bit()); |
241 | 244 | ||
242 | // unique id | 245 | // unique id |
243 | addPropValue(vtodo, VCUniqueStringProp, | 246 | addPropValue(vtodo, VCUniqueStringProp, |
244 | anEvent->uid().local8Bit()); | 247 | anEvent->uid().local8Bit()); |
245 | 248 | ||
246 | // revision | 249 | // revision |
247 | tmpStr.sprintf("%i", anEvent->revision()); | 250 | tmpStr.sprintf("%i", anEvent->revision()); |
248 | addPropValue(vtodo, VCSequenceProp, tmpStr.local8Bit()); | 251 | addPropValue(vtodo, VCSequenceProp, tmpStr.local8Bit()); |
249 | 252 | ||
250 | // last modification date | 253 | // last modification date |
251 | tmpStr = qDateTimeToISO(anEvent->lastModified()); | 254 | tmpStr = qDateTimeToISO(anEvent->lastModified()); |
252 | addPropValue(vtodo, VCLastModifiedProp, tmpStr.local8Bit()); | 255 | addPropValue(vtodo, VCLastModifiedProp, tmpStr.local8Bit()); |
253 | 256 | ||
254 | // organizer stuff | 257 | // organizer stuff |
255 | tmpStr = "MAILTO:" + anEvent->organizer(); | 258 | tmpStr = "MAILTO:" + anEvent->organizer(); |
256 | addPropValue(vtodo, ICOrganizerProp, tmpStr.local8Bit()); | 259 | addPropValue(vtodo, ICOrganizerProp, tmpStr.local8Bit()); |
257 | 260 | ||
258 | // attendees | 261 | // attendees |
259 | if (anEvent->attendeeCount() != 0) { | 262 | if (anEvent->attendeeCount() != 0) { |
260 | QPtrList<Attendee> al = anEvent->attendees(); | 263 | QPtrList<Attendee> al = anEvent->attendees(); |
261 | QPtrListIterator<Attendee> ai(al); | 264 | QPtrListIterator<Attendee> ai(al); |
262 | Attendee *curAttendee; | 265 | Attendee *curAttendee; |
263 | 266 | ||
264 | for (; ai.current(); ++ai) { | 267 | for (; ai.current(); ++ai) { |
265 | curAttendee = ai.current(); | 268 | curAttendee = ai.current(); |
266 | if (!curAttendee->email().isEmpty() && | 269 | if (!curAttendee->email().isEmpty() && |
267 | !curAttendee->name().isEmpty()) | 270 | !curAttendee->name().isEmpty()) |
268 | tmpStr = "MAILTO:" + curAttendee->name() + " <" + | 271 | tmpStr = "MAILTO:" + curAttendee->name() + " <" + |
269 | curAttendee->email() + ">"; | 272 | curAttendee->email() + ">"; |
270 | else if (curAttendee->name().isEmpty()) | 273 | else if (curAttendee->name().isEmpty()) |
271 | tmpStr = "MAILTO: " + curAttendee->email(); | 274 | tmpStr = "MAILTO: " + curAttendee->email(); |
272 | else if (curAttendee->email().isEmpty()) | 275 | else if (curAttendee->email().isEmpty()) |
273 | tmpStr = "MAILTO: " + curAttendee->name(); | 276 | tmpStr = "MAILTO: " + curAttendee->name(); |
274 | else if (curAttendee->name().isEmpty() && | 277 | else if (curAttendee->name().isEmpty() && |
275 | curAttendee->email().isEmpty()) | 278 | curAttendee->email().isEmpty()) |
276 | kdDebug(5800) << "warning! this Event has an attendee w/o name or email!" << endl; | 279 | kdDebug(5800) << "warning! this Event has an attendee w/o name or email!" << endl; |
277 | VObject *aProp = addPropValue(vtodo, VCAttendeeProp, tmpStr.local8Bit()); | 280 | VObject *aProp = addPropValue(vtodo, VCAttendeeProp, tmpStr.local8Bit()); |
278 | addPropValue(aProp, VCRSVPProp, curAttendee->RSVP() ? "TRUE" : "FALSE"); | 281 | addPropValue(aProp, VCRSVPProp, curAttendee->RSVP() ? "TRUE" : "FALSE"); |
279 | addPropValue(aProp, VCStatusProp, writeStatus(curAttendee->status())); | 282 | addPropValue(aProp, VCStatusProp, writeStatus(curAttendee->status())); |
280 | } | 283 | } |
281 | } | 284 | } |
282 | 285 | ||
283 | // description BL: | 286 | // description BL: |
284 | if (!anEvent->description().isEmpty()) { | 287 | if (!anEvent->description().isEmpty()) { |
285 | VObject *d = addPropValue(vtodo, VCDescriptionProp, | 288 | VObject *d = addPropValue(vtodo, VCDescriptionProp, |
286 | anEvent->description().local8Bit()); | 289 | anEvent->description().local8Bit()); |
287 | if (anEvent->description().find('\n') != -1) | 290 | if (anEvent->description().find('\n') != -1) |
288 | addProp(d, VCQuotedPrintableProp); | 291 | addProp(d, VCQuotedPrintableProp); |
289 | } | 292 | } |
290 | 293 | ||
291 | // summary | 294 | // summary |
292 | if (!anEvent->summary().isEmpty()) | 295 | if (!anEvent->summary().isEmpty()) |
293 | addPropValue(vtodo, VCSummaryProp, anEvent->summary().local8Bit()); | 296 | addPropValue(vtodo, VCSummaryProp, anEvent->summary().local8Bit()); |
294 | 297 | ||
295 | if (!anEvent->location().isEmpty()) | 298 | if (!anEvent->location().isEmpty()) |
296 | addPropValue(vtodo, VCLocationProp, anEvent->location().local8Bit()); | 299 | addPropValue(vtodo, VCLocationProp, anEvent->location().local8Bit()); |
297 | 300 | ||
298 | // completed | 301 | // completed |
299 | // status | 302 | // status |
300 | // backward compatibility, KOrganizer used to interpret only these two values | 303 | // backward compatibility, KOrganizer used to interpret only these two values |
301 | addPropValue(vtodo, VCStatusProp, anEvent->isCompleted() ? "COMPLETED" : | 304 | addPropValue(vtodo, VCStatusProp, anEvent->isCompleted() ? "COMPLETED" : |
302 | "NEEDS_ACTION"); | 305 | "NEEDS_ACTION"); |
303 | // completion date | 306 | // completion date |
304 | if (anEvent->hasCompletedDate()) { | 307 | if (anEvent->hasCompletedDate()) { |
305 | tmpStr = qDateTimeToISO(anEvent->completed()); | 308 | tmpStr = qDateTimeToISO(anEvent->completed()); |
306 | addPropValue(vtodo, VCCompletedProp, tmpStr.local8Bit()); | 309 | addPropValue(vtodo, VCCompletedProp, tmpStr.local8Bit()); |
307 | } | 310 | } |
308 | 311 | ||
309 | // priority | 312 | // priority |
310 | tmpStr.sprintf("%i",anEvent->priority()); | 313 | tmpStr.sprintf("%i",anEvent->priority()); |
311 | addPropValue(vtodo, VCPriorityProp, tmpStr.local8Bit()); | 314 | addPropValue(vtodo, VCPriorityProp, tmpStr.local8Bit()); |
312 | 315 | ||
313 | // related event | 316 | // related event |
314 | if (anEvent->relatedTo()) { | 317 | if (anEvent->relatedTo()) { |
315 | addPropValue(vtodo, VCRelatedToProp, | 318 | addPropValue(vtodo, VCRelatedToProp, |
316 | anEvent->relatedTo()->uid().local8Bit()); | 319 | anEvent->relatedTo()->uid().local8Bit()); |
317 | } | 320 | } |
318 | 321 | ||
319 | // categories | 322 | // categories |
320 | tmpStrList = anEvent->categories(); | 323 | tmpStrList = anEvent->categories(); |
321 | tmpStr = ""; | 324 | tmpStr = ""; |
322 | QString catStr; | 325 | QString catStr; |
323 | for ( QStringList::Iterator it = tmpStrList.begin(); | 326 | for ( QStringList::Iterator it = tmpStrList.begin(); |
324 | it != tmpStrList.end(); | 327 | it != tmpStrList.end(); |
325 | ++it ) { | 328 | ++it ) { |
326 | catStr = *it; | 329 | catStr = *it; |
327 | if (catStr[0] == ' ') | 330 | if (catStr[0] == ' ') |
328 | tmpStr += catStr.mid(1); | 331 | tmpStr += catStr.mid(1); |
329 | else | 332 | else |
330 | tmpStr += catStr; | 333 | tmpStr += catStr; |
331 | // this must be a ';' character as the vCalendar specification requires! | 334 | // this must be a ';' character as the vCalendar specification requires! |
332 | // vcc.y has been hacked to translate the ';' to a ',' when the vcal is | 335 | // vcc.y has been hacked to translate the ';' to a ',' when the vcal is |
333 | // read in. | 336 | // read in. |
334 | tmpStr += ";"; | 337 | tmpStr += ";"; |
335 | } | 338 | } |
336 | if (!tmpStr.isEmpty()) { | 339 | if (!tmpStr.isEmpty()) { |
337 | tmpStr.truncate(tmpStr.length()-1); | 340 | tmpStr.truncate(tmpStr.length()-1); |
338 | addPropValue(vtodo, VCCategoriesProp, tmpStr.local8Bit()); | 341 | addPropValue(vtodo, VCCategoriesProp, tmpStr.local8Bit()); |
339 | } | 342 | } |
340 | 343 | ||
341 | // alarm stuff | 344 | // alarm stuff |
342 | kdDebug(5800) << "vcalformat::eventToVTodo was called" << endl; | 345 | kdDebug(5800) << "vcalformat::eventToVTodo was called" << endl; |
343 | QPtrList<Alarm> alarms = anEvent->alarms(); | 346 | QPtrList<Alarm> alarms = anEvent->alarms(); |
344 | Alarm* alarm; | 347 | Alarm* alarm; |
345 | for (alarm = alarms.first(); alarm; alarm = alarms.next()) { | 348 | for (alarm = alarms.first(); alarm; alarm = alarms.next()) { |
346 | if (alarm->enabled()) { | 349 | if (alarm->enabled()) { |
347 | VObject *a = addProp(vtodo, VCDAlarmProp); | 350 | VObject *a = addProp(vtodo, VCDAlarmProp); |
348 | tmpStr = qDateTimeToISO(alarm->time()); | 351 | tmpStr = qDateTimeToISO(alarm->time()); |
349 | addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); | 352 | addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); |
350 | addPropValue(a, VCRepeatCountProp, "1"); | 353 | addPropValue(a, VCRepeatCountProp, "1"); |
351 | addPropValue(a, VCDisplayStringProp, "beep!"); | 354 | addPropValue(a, VCDisplayStringProp, "beep!"); |
352 | if (alarm->type() == Alarm::Audio) { | 355 | if (alarm->type() == Alarm::Audio) { |
353 | a = addProp(vtodo, VCAAlarmProp); | 356 | a = addProp(vtodo, VCAAlarmProp); |
354 | addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); | 357 | addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); |
355 | addPropValue(a, VCRepeatCountProp, "1"); | 358 | addPropValue(a, VCRepeatCountProp, "1"); |
356 | addPropValue(a, VCAudioContentProp, QFile::encodeName(alarm->audioFile())); | 359 | addPropValue(a, VCAudioContentProp, QFile::encodeName(alarm->audioFile())); |
357 | } | 360 | } |
358 | else if (alarm->type() == Alarm::Procedure) { | 361 | else if (alarm->type() == Alarm::Procedure) { |
359 | a = addProp(vtodo, VCPAlarmProp); | 362 | a = addProp(vtodo, VCPAlarmProp); |
360 | addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); | 363 | addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); |
361 | addPropValue(a, VCRepeatCountProp, "1"); | 364 | addPropValue(a, VCRepeatCountProp, "1"); |
362 | addPropValue(a, VCProcedureNameProp, QFile::encodeName(alarm->programFile())); | 365 | addPropValue(a, VCProcedureNameProp, QFile::encodeName(alarm->programFile())); |
363 | } | 366 | } |
364 | } | 367 | } |
365 | } | 368 | } |
366 | 369 | ||
367 | if (anEvent->pilotId()) { | 370 | if (anEvent->pilotId()) { |
368 | // pilot sync stuff | 371 | // pilot sync stuff |
369 | tmpStr.sprintf("%i",anEvent->pilotId()); | 372 | tmpStr.sprintf("%i",anEvent->pilotId()); |
370 | addPropValue(vtodo, XPilotIdProp, tmpStr.local8Bit()); | 373 | addPropValue(vtodo, XPilotIdProp, tmpStr.local8Bit()); |
371 | tmpStr.sprintf("%i",anEvent->syncStatus()); | 374 | tmpStr.sprintf("%i",anEvent->syncStatus()); |
372 | addPropValue(vtodo, XPilotStatusProp, tmpStr.local8Bit()); | 375 | addPropValue(vtodo, XPilotStatusProp, tmpStr.local8Bit()); |
373 | } | 376 | } |
374 | 377 | ||
375 | return vtodo; | 378 | return vtodo; |
376 | } | 379 | } |
377 | 380 | ||
378 | VObject* VCalFormat::eventToVEvent(const Event *anEvent) | 381 | VObject* VCalFormat::eventToVEvent(const Event *anEvent) |
379 | { | 382 | { |
380 | VObject *vevent; | 383 | VObject *vevent; |
381 | QString tmpStr; | 384 | QString tmpStr; |
382 | QStringList tmpStrList; | 385 | QStringList tmpStrList; |
383 | 386 | ||
384 | vevent = newVObject(VCEventProp); | 387 | vevent = newVObject(VCEventProp); |
385 | 388 | ||
386 | // start and end time | 389 | // start and end time |
387 | tmpStr = qDateTimeToISO(anEvent->dtStart(), | 390 | tmpStr = qDateTimeToISO(anEvent->dtStart(), |
388 | !anEvent->doesFloat()); | 391 | !anEvent->doesFloat()); |
389 | addPropValue(vevent, VCDTstartProp, tmpStr.local8Bit()); | 392 | addPropValue(vevent, VCDTstartProp, tmpStr.local8Bit()); |
390 | 393 | ||
391 | // events that have time associated but take up no time should | 394 | // events that have time associated but take up no time should |
392 | // not have both DTSTART and DTEND. | 395 | // not have both DTSTART and DTEND. |
393 | if (anEvent->dtStart() != anEvent->dtEnd()) { | 396 | if (anEvent->dtStart() != anEvent->dtEnd()) { |
394 | tmpStr = qDateTimeToISO(anEvent->dtEnd(), | 397 | tmpStr = qDateTimeToISO(anEvent->dtEnd(), |
395 | !anEvent->doesFloat()); | 398 | !anEvent->doesFloat()); |
396 | addPropValue(vevent, VCDTendProp, tmpStr.local8Bit()); | 399 | addPropValue(vevent, VCDTendProp, tmpStr.local8Bit()); |
397 | } | 400 | } |
398 | 401 | ||
399 | // creation date | 402 | // creation date |
400 | tmpStr = qDateTimeToISO(anEvent->created()); | 403 | tmpStr = qDateTimeToISO(anEvent->created()); |
401 | addPropValue(vevent, VCDCreatedProp, tmpStr.local8Bit()); | 404 | addPropValue(vevent, VCDCreatedProp, tmpStr.local8Bit()); |
402 | 405 | ||
403 | // unique id | 406 | // unique id |
404 | addPropValue(vevent, VCUniqueStringProp, | 407 | addPropValue(vevent, VCUniqueStringProp, |
405 | anEvent->uid().local8Bit()); | 408 | anEvent->uid().local8Bit()); |
406 | 409 | ||
407 | // revision | 410 | // revision |
408 | tmpStr.sprintf("%i", anEvent->revision()); | 411 | tmpStr.sprintf("%i", anEvent->revision()); |
409 | addPropValue(vevent, VCSequenceProp, tmpStr.local8Bit()); | 412 | addPropValue(vevent, VCSequenceProp, tmpStr.local8Bit()); |
410 | 413 | ||
411 | // last modification date | 414 | // last modification date |
412 | tmpStr = qDateTimeToISO(anEvent->lastModified()); | 415 | tmpStr = qDateTimeToISO(anEvent->lastModified()); |
413 | addPropValue(vevent, VCLastModifiedProp, tmpStr.local8Bit()); | 416 | addPropValue(vevent, VCLastModifiedProp, tmpStr.local8Bit()); |
414 | 417 | ||
415 | // attendee and organizer stuff | 418 | // attendee and organizer stuff |
416 | tmpStr = "MAILTO:" + anEvent->organizer(); | 419 | tmpStr = "MAILTO:" + anEvent->organizer(); |
417 | addPropValue(vevent, ICOrganizerProp, tmpStr.local8Bit()); | 420 | addPropValue(vevent, ICOrganizerProp, tmpStr.local8Bit()); |
418 | 421 | ||
419 | if (anEvent->attendeeCount() != 0) { | 422 | if (anEvent->attendeeCount() != 0) { |
420 | QPtrList<Attendee> al = anEvent->attendees(); | 423 | QPtrList<Attendee> al = anEvent->attendees(); |
421 | QPtrListIterator<Attendee> ai(al); | 424 | QPtrListIterator<Attendee> ai(al); |
422 | Attendee *curAttendee; | 425 | Attendee *curAttendee; |
423 | 426 | ||
424 | // TODO: Put this functionality into Attendee class | 427 | // TODO: Put this functionality into Attendee class |
425 | for (; ai.current(); ++ai) { | 428 | for (; ai.current(); ++ai) { |
426 | curAttendee = ai.current(); | 429 | curAttendee = ai.current(); |
427 | if (!curAttendee->email().isEmpty() && | 430 | if (!curAttendee->email().isEmpty() && |
428 | !curAttendee->name().isEmpty()) | 431 | !curAttendee->name().isEmpty()) |
429 | tmpStr = "MAILTO:" + curAttendee->name() + " <" + | 432 | tmpStr = "MAILTO:" + curAttendee->name() + " <" + |
430 | curAttendee->email() + ">"; | 433 | curAttendee->email() + ">"; |
431 | else if (curAttendee->name().isEmpty()) | 434 | else if (curAttendee->name().isEmpty()) |
432 | tmpStr = "MAILTO: " + curAttendee->email(); | 435 | tmpStr = "MAILTO: " + curAttendee->email(); |
433 | else if (curAttendee->email().isEmpty()) | 436 | else if (curAttendee->email().isEmpty()) |
434 | tmpStr = "MAILTO: " + curAttendee->name(); | 437 | tmpStr = "MAILTO: " + curAttendee->name(); |
435 | else if (curAttendee->name().isEmpty() && | 438 | else if (curAttendee->name().isEmpty() && |
436 | curAttendee->email().isEmpty()) | 439 | curAttendee->email().isEmpty()) |
437 | kdDebug(5800) << "warning! this Event has an attendee w/o name or email!" << endl; | 440 | kdDebug(5800) << "warning! this Event has an attendee w/o name or email!" << endl; |
438 | VObject *aProp = addPropValue(vevent, VCAttendeeProp, tmpStr.local8Bit()); | 441 | VObject *aProp = addPropValue(vevent, VCAttendeeProp, tmpStr.local8Bit()); |
439 | addPropValue(aProp, VCRSVPProp, curAttendee->RSVP() ? "TRUE" : "FALSE");; | 442 | addPropValue(aProp, VCRSVPProp, curAttendee->RSVP() ? "TRUE" : "FALSE");; |
440 | addPropValue(aProp, VCStatusProp, writeStatus(curAttendee->status())); | 443 | addPropValue(aProp, VCStatusProp, writeStatus(curAttendee->status())); |
441 | } | 444 | } |
442 | } | 445 | } |
443 | 446 | ||
444 | // recurrence rule stuff | 447 | // recurrence rule stuff |
445 | if (anEvent->recurrence()->doesRecur()) { | 448 | if (anEvent->recurrence()->doesRecur()) { |
446 | // some more variables | 449 | // some more variables |
447 | QPtrList<Recurrence::rMonthPos> tmpPositions; | 450 | QPtrList<Recurrence::rMonthPos> tmpPositions; |
448 | QPtrList<int> tmpDays; | 451 | QPtrList<int> tmpDays; |
449 | int *tmpDay; | 452 | int *tmpDay; |
450 | Recurrence::rMonthPos *tmpPos; | 453 | Recurrence::rMonthPos *tmpPos; |
451 | QString tmpStr2; | 454 | QString tmpStr2; |
452 | int i; | 455 | int i; |
453 | 456 | ||
454 | switch(anEvent->recurrence()->doesRecur()) { | 457 | switch(anEvent->recurrence()->doesRecur()) { |
455 | case Recurrence::rDaily: | 458 | case Recurrence::rDaily: |
456 | tmpStr.sprintf("D%i ",anEvent->recurrence()->frequency()); | 459 | tmpStr.sprintf("D%i ",anEvent->recurrence()->frequency()); |
457 | // if (anEvent->rDuration > 0) | 460 | // if (anEvent->rDuration > 0) |
458 | //tmpStr += "#"; | 461 | //tmpStr += "#"; |
459 | break; | 462 | break; |
460 | case Recurrence::rWeekly: | 463 | case Recurrence::rWeekly: |
461 | tmpStr.sprintf("W%i ",anEvent->recurrence()->frequency()); | 464 | tmpStr.sprintf("W%i ",anEvent->recurrence()->frequency()); |
462 | for (i = 0; i < 7; i++) { | 465 | for (i = 0; i < 7; i++) { |
463 | if (anEvent->recurrence()->days().testBit(i)) | 466 | if (anEvent->recurrence()->days().testBit(i)) |
464 | tmpStr += dayFromNum(i); | 467 | tmpStr += dayFromNum(i); |
465 | } | 468 | } |
466 | break; | 469 | break; |
467 | case Recurrence::rMonthlyPos: | 470 | case Recurrence::rMonthlyPos: |
468 | tmpStr.sprintf("MP%i ", anEvent->recurrence()->frequency()); | 471 | tmpStr.sprintf("MP%i ", anEvent->recurrence()->frequency()); |
469 | // write out all rMonthPos's | 472 | // write out all rMonthPos's |
470 | tmpPositions = anEvent->recurrence()->monthPositions(); | 473 | tmpPositions = anEvent->recurrence()->monthPositions(); |
471 | for (tmpPos = tmpPositions.first(); | 474 | for (tmpPos = tmpPositions.first(); |
472 | tmpPos; | 475 | tmpPos; |
473 | tmpPos = tmpPositions.next()) { | 476 | tmpPos = tmpPositions.next()) { |
474 | 477 | ||
475 | tmpStr2.sprintf("%i", tmpPos->rPos); | 478 | tmpStr2.sprintf("%i", tmpPos->rPos); |
476 | if (tmpPos->negative) | 479 | if (tmpPos->negative) |
477 | tmpStr2 += "- "; | 480 | tmpStr2 += "- "; |
478 | else | 481 | else |
479 | tmpStr2 += "+ "; | 482 | tmpStr2 += "+ "; |
480 | tmpStr += tmpStr2; | 483 | tmpStr += tmpStr2; |
481 | for (i = 0; i < 7; i++) { | 484 | for (i = 0; i < 7; i++) { |
482 | if (tmpPos->rDays.testBit(i)) | 485 | if (tmpPos->rDays.testBit(i)) |
483 | tmpStr += dayFromNum(i); | 486 | tmpStr += dayFromNum(i); |
484 | } | 487 | } |
485 | } // loop for all rMonthPos's | 488 | } // loop for all rMonthPos's |
486 | break; | 489 | break; |
487 | case Recurrence::rMonthlyDay: | 490 | case Recurrence::rMonthlyDay: |
488 | tmpStr.sprintf("MD%i ", anEvent->recurrence()->frequency()); | 491 | tmpStr.sprintf("MD%i ", anEvent->recurrence()->frequency()); |
489 | // write out all rMonthDays; | 492 | // write out all rMonthDays; |
490 | tmpDays = anEvent->recurrence()->monthDays(); | 493 | tmpDays = anEvent->recurrence()->monthDays(); |
491 | for (tmpDay = tmpDays.first(); | 494 | for (tmpDay = tmpDays.first(); |
492 | tmpDay; | 495 | tmpDay; |
493 | tmpDay = tmpDays.next()) { | 496 | tmpDay = tmpDays.next()) { |
494 | tmpStr2.sprintf("%i ", *tmpDay); | 497 | tmpStr2.sprintf("%i ", *tmpDay); |
495 | tmpStr += tmpStr2; | 498 | tmpStr += tmpStr2; |
496 | } | 499 | } |
497 | break; | 500 | break; |
498 | case Recurrence::rYearlyMonth: | 501 | case Recurrence::rYearlyMonth: |
499 | tmpStr.sprintf("YM%i ", anEvent->recurrence()->frequency()); | 502 | tmpStr.sprintf("YM%i ", anEvent->recurrence()->frequency()); |
500 | // write out all the rYearNums; | 503 | // write out all the rYearNums; |
501 | tmpDays = anEvent->recurrence()->yearNums(); | 504 | tmpDays = anEvent->recurrence()->yearNums(); |
502 | for (tmpDay = tmpDays.first(); | 505 | for (tmpDay = tmpDays.first(); |
503 | tmpDay; | 506 | tmpDay; |
504 | tmpDay = tmpDays.next()) { | 507 | tmpDay = tmpDays.next()) { |
505 | tmpStr2.sprintf("%i ", *tmpDay); | 508 | tmpStr2.sprintf("%i ", *tmpDay); |
506 | tmpStr += tmpStr2; | 509 | tmpStr += tmpStr2; |
507 | } | 510 | } |
508 | break; | 511 | break; |
509 | case Recurrence::rYearlyDay: | 512 | case Recurrence::rYearlyDay: |
510 | tmpStr.sprintf("YD%i ", anEvent->recurrence()->frequency()); | 513 | tmpStr.sprintf("YD%i ", anEvent->recurrence()->frequency()); |
511 | // write out all the rYearNums; | 514 | // write out all the rYearNums; |
512 | tmpDays = anEvent->recurrence()->yearNums(); | 515 | tmpDays = anEvent->recurrence()->yearNums(); |
513 | for (tmpDay = tmpDays.first(); | 516 | for (tmpDay = tmpDays.first(); |
514 | tmpDay; | 517 | tmpDay; |
515 | tmpDay = tmpDays.next()) { | 518 | tmpDay = tmpDays.next()) { |
516 | tmpStr2.sprintf("%i ", *tmpDay); | 519 | tmpStr2.sprintf("%i ", *tmpDay); |
517 | tmpStr += tmpStr2; | 520 | tmpStr += tmpStr2; |
518 | } | 521 | } |
519 | break; | 522 | break; |
520 | default: | 523 | default: |
521 | kdDebug(5800) << "ERROR, it should never get here in eventToVEvent!" << endl; | 524 | kdDebug(5800) << "ERROR, it should never get here in eventToVEvent!" << endl; |
522 | break; | 525 | break; |
523 | } // switch | 526 | } // switch |
524 | 527 | ||
525 | if (anEvent->recurrence()->duration() > 0) { | 528 | if (anEvent->recurrence()->duration() > 0) { |
526 | tmpStr2.sprintf("#%i",anEvent->recurrence()->duration()); | 529 | tmpStr2.sprintf("#%i",anEvent->recurrence()->duration()); |
527 | tmpStr += tmpStr2; | 530 | tmpStr += tmpStr2; |
528 | } else if (anEvent->recurrence()->duration() == -1) { | 531 | } else if (anEvent->recurrence()->duration() == -1) { |
529 | tmpStr += "#0"; // defined as repeat forever | 532 | tmpStr += "#0"; // defined as repeat forever |
530 | } else { | 533 | } else { |
531 | tmpStr += qDateTimeToISO(anEvent->recurrence()->endDate(), FALSE); | 534 | tmpStr += qDateTimeToISO(anEvent->recurrence()->endDate(), FALSE); |
532 | } | 535 | } |
533 | addPropValue(vevent,VCRRuleProp, tmpStr.local8Bit()); | 536 | addPropValue(vevent,VCRRuleProp, tmpStr.local8Bit()); |
534 | 537 | ||
535 | } // event repeats | 538 | } // event repeats |
536 | 539 | ||
537 | // exceptions to recurrence | 540 | // exceptions to recurrence |
538 | DateList dateList = anEvent->exDates(); | 541 | DateList dateList = anEvent->exDates(); |
539 | DateList::ConstIterator it; | 542 | DateList::ConstIterator it; |
540 | QString tmpStr2; | 543 | QString tmpStr2; |
541 | 544 | ||
542 | for (it = dateList.begin(); it != dateList.end(); ++it) { | 545 | for (it = dateList.begin(); it != dateList.end(); ++it) { |
543 | tmpStr = qDateToISO(*it) + ";"; | 546 | tmpStr = qDateToISO(*it) + ";"; |
544 | tmpStr2 += tmpStr; | 547 | tmpStr2 += tmpStr; |
545 | } | 548 | } |
546 | if (!tmpStr2.isEmpty()) { | 549 | if (!tmpStr2.isEmpty()) { |
547 | tmpStr2.truncate(tmpStr2.length()-1); | 550 | tmpStr2.truncate(tmpStr2.length()-1); |
548 | addPropValue(vevent, VCExpDateProp, tmpStr2.local8Bit()); | 551 | addPropValue(vevent, VCExpDateProp, tmpStr2.local8Bit()); |
549 | } | 552 | } |
550 | 553 | ||
551 | // description | 554 | // description |
552 | if (!anEvent->description().isEmpty()) { | 555 | if (!anEvent->description().isEmpty()) { |
553 | VObject *d = addPropValue(vevent, VCDescriptionProp, | 556 | VObject *d = addPropValue(vevent, VCDescriptionProp, |
554 | anEvent->description().local8Bit()); | 557 | anEvent->description().local8Bit()); |
555 | if (anEvent->description().find('\n') != -1) | 558 | if (anEvent->description().find('\n') != -1) |
556 | addProp(d, VCQuotedPrintableProp); | 559 | addProp(d, VCQuotedPrintableProp); |
557 | } | 560 | } |
558 | 561 | ||
559 | // summary | 562 | // summary |
560 | if (!anEvent->summary().isEmpty()) | 563 | if (!anEvent->summary().isEmpty()) |
561 | addPropValue(vevent, VCSummaryProp, anEvent->summary().local8Bit()); | 564 | addPropValue(vevent, VCSummaryProp, anEvent->summary().local8Bit()); |
562 | 565 | ||
563 | if (!anEvent->location().isEmpty()) | 566 | if (!anEvent->location().isEmpty()) |
564 | addPropValue(vevent, VCLocationProp, anEvent->location().local8Bit()); | 567 | addPropValue(vevent, VCLocationProp, anEvent->location().local8Bit()); |
565 | 568 | ||
566 | // status | 569 | // status |
567 | // TODO: define Event status | 570 | // TODO: define Event status |
568 | // addPropValue(vevent, VCStatusProp, anEvent->statusStr().local8Bit()); | 571 | // addPropValue(vevent, VCStatusProp, anEvent->statusStr().local8Bit()); |
569 | 572 | ||
570 | // secrecy | 573 | // secrecy |
571 | const char *text = 0; | 574 | const char *text = 0; |
572 | switch (anEvent->secrecy()) { | 575 | switch (anEvent->secrecy()) { |
573 | case Incidence::SecrecyPublic: | 576 | case Incidence::SecrecyPublic: |
574 | text = "PUBLIC"; | 577 | text = "PUBLIC"; |
575 | break; | 578 | break; |
576 | case Incidence::SecrecyPrivate: | 579 | case Incidence::SecrecyPrivate: |
577 | text = "PRIVATE"; | 580 | text = "PRIVATE"; |
578 | break; | 581 | break; |
579 | case Incidence::SecrecyConfidential: | 582 | case Incidence::SecrecyConfidential: |
580 | text = "CONFIDENTIAL"; | 583 | text = "CONFIDENTIAL"; |
581 | break; | 584 | break; |
582 | } | 585 | } |
583 | if (text) { | 586 | if (text) { |
584 | addPropValue(vevent, VCClassProp, text); | 587 | addPropValue(vevent, VCClassProp, text); |
585 | } | 588 | } |
586 | 589 | ||
587 | // categories | 590 | // categories |
588 | tmpStrList = anEvent->categories(); | 591 | tmpStrList = anEvent->categories(); |
589 | tmpStr = ""; | 592 | tmpStr = ""; |
590 | QString catStr; | 593 | QString catStr; |
591 | for ( QStringList::Iterator it = tmpStrList.begin(); | 594 | for ( QStringList::Iterator it = tmpStrList.begin(); |
592 | it != tmpStrList.end(); | 595 | it != tmpStrList.end(); |
593 | ++it ) { | 596 | ++it ) { |
594 | catStr = *it; | 597 | catStr = *it; |
595 | if (catStr[0] == ' ') | 598 | if (catStr[0] == ' ') |
596 | tmpStr += catStr.mid(1); | 599 | tmpStr += catStr.mid(1); |
597 | else | 600 | else |
598 | tmpStr += catStr; | 601 | tmpStr += catStr; |
599 | // this must be a ';' character as the vCalendar specification requires! | 602 | // this must be a ';' character as the vCalendar specification requires! |
600 | // vcc.y has been hacked to translate the ';' to a ',' when the vcal is | 603 | // vcc.y has been hacked to translate the ';' to a ',' when the vcal is |
601 | // read in. | 604 | // read in. |
602 | tmpStr += ";"; | 605 | tmpStr += ";"; |
603 | } | 606 | } |
604 | if (!tmpStr.isEmpty()) { | 607 | if (!tmpStr.isEmpty()) { |
605 | tmpStr.truncate(tmpStr.length()-1); | 608 | tmpStr.truncate(tmpStr.length()-1); |
606 | addPropValue(vevent, VCCategoriesProp, tmpStr.local8Bit()); | 609 | addPropValue(vevent, VCCategoriesProp, tmpStr.local8Bit()); |
607 | } | 610 | } |
608 | 611 | ||
609 | // attachments | 612 | // attachments |
610 | // TODO: handle binary attachments! | 613 | // TODO: handle binary attachments! |
611 | QPtrList<Attachment> attachments = anEvent->attachments(); | 614 | QPtrList<Attachment> attachments = anEvent->attachments(); |
612 | for ( Attachment *at = attachments.first(); at; at = attachments.next() ) | 615 | for ( Attachment *at = attachments.first(); at; at = attachments.next() ) |
613 | addPropValue(vevent, VCAttachProp, at->uri().local8Bit()); | 616 | addPropValue(vevent, VCAttachProp, at->uri().local8Bit()); |
614 | 617 | ||
615 | // resources | 618 | // resources |
616 | tmpStrList = anEvent->resources(); | 619 | tmpStrList = anEvent->resources(); |
617 | tmpStr = tmpStrList.join(";"); | 620 | tmpStr = tmpStrList.join(";"); |
618 | if (!tmpStr.isEmpty()) | 621 | if (!tmpStr.isEmpty()) |
619 | addPropValue(vevent, VCResourcesProp, tmpStr.local8Bit()); | 622 | addPropValue(vevent, VCResourcesProp, tmpStr.local8Bit()); |
620 | 623 | ||
621 | // alarm stuff | 624 | // alarm stuff |
622 | QPtrList<Alarm> alarms = anEvent->alarms(); | 625 | QPtrList<Alarm> alarms = anEvent->alarms(); |
623 | Alarm* alarm; | 626 | Alarm* alarm; |
624 | for (alarm = alarms.first(); alarm; alarm = alarms.next()) { | 627 | for (alarm = alarms.first(); alarm; alarm = alarms.next()) { |
625 | if (alarm->enabled()) { | 628 | if (alarm->enabled()) { |
626 | VObject *a = addProp(vevent, VCDAlarmProp); | 629 | VObject *a = addProp(vevent, VCDAlarmProp); |
627 | tmpStr = qDateTimeToISO(alarm->time()); | 630 | tmpStr = qDateTimeToISO(alarm->time()); |
628 | addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); | 631 | addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); |
629 | addPropValue(a, VCRepeatCountProp, "1"); | 632 | addPropValue(a, VCRepeatCountProp, "1"); |
630 | addPropValue(a, VCDisplayStringProp, "beep!"); | 633 | addPropValue(a, VCDisplayStringProp, "beep!"); |
631 | if (alarm->type() == Alarm::Audio) { | 634 | if (alarm->type() == Alarm::Audio) { |
632 | a = addProp(vevent, VCAAlarmProp); | 635 | a = addProp(vevent, VCAAlarmProp); |
633 | addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); | 636 | addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); |
634 | addPropValue(a, VCRepeatCountProp, "1"); | 637 | addPropValue(a, VCRepeatCountProp, "1"); |
635 | addPropValue(a, VCAudioContentProp, QFile::encodeName(alarm->audioFile())); | 638 | addPropValue(a, VCAudioContentProp, QFile::encodeName(alarm->audioFile())); |
636 | } | 639 | } |
637 | if (alarm->type() == Alarm::Procedure) { | 640 | if (alarm->type() == Alarm::Procedure) { |
638 | a = addProp(vevent, VCPAlarmProp); | 641 | a = addProp(vevent, VCPAlarmProp); |
639 | addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); | 642 | addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); |
640 | addPropValue(a, VCRepeatCountProp, "1"); | 643 | addPropValue(a, VCRepeatCountProp, "1"); |
641 | addPropValue(a, VCProcedureNameProp, QFile::encodeName(alarm->programFile())); | 644 | addPropValue(a, VCProcedureNameProp, QFile::encodeName(alarm->programFile())); |
642 | } | 645 | } |
643 | } | 646 | } |
644 | } | 647 | } |
645 | 648 | ||
646 | // priority | 649 | // priority |
647 | tmpStr.sprintf("%i",anEvent->priority()); | 650 | tmpStr.sprintf("%i",anEvent->priority()); |
648 | addPropValue(vevent, VCPriorityProp, tmpStr.local8Bit()); | 651 | addPropValue(vevent, VCPriorityProp, tmpStr.local8Bit()); |
649 | 652 | ||
650 | // transparency | 653 | // transparency |
651 | tmpStr.sprintf("%i",anEvent->transparency()); | 654 | tmpStr.sprintf("%i",anEvent->transparency()); |
652 | addPropValue(vevent, VCTranspProp, tmpStr.local8Bit()); | 655 | addPropValue(vevent, VCTranspProp, tmpStr.local8Bit()); |
653 | 656 | ||
654 | // related event | 657 | // related event |
655 | if (anEvent->relatedTo()) { | 658 | if (anEvent->relatedTo()) { |
656 | addPropValue(vevent, VCRelatedToProp, | 659 | addPropValue(vevent, VCRelatedToProp, |
657 | anEvent->relatedTo()->uid().local8Bit()); | 660 | anEvent->relatedTo()->uid().local8Bit()); |
658 | } | 661 | } |
659 | 662 | ||
660 | if (anEvent->pilotId()) { | 663 | if (anEvent->pilotId()) { |
661 | // pilot sync stuff | 664 | // pilot sync stuff |
662 | tmpStr.sprintf("%i",anEvent->pilotId()); | 665 | tmpStr.sprintf("%i",anEvent->pilotId()); |
663 | addPropValue(vevent, XPilotIdProp, tmpStr.local8Bit()); | 666 | addPropValue(vevent, XPilotIdProp, tmpStr.local8Bit()); |
664 | tmpStr.sprintf("%i",anEvent->syncStatus()); | 667 | tmpStr.sprintf("%i",anEvent->syncStatus()); |
665 | addPropValue(vevent, XPilotStatusProp, tmpStr.local8Bit()); | 668 | addPropValue(vevent, XPilotStatusProp, tmpStr.local8Bit()); |
666 | } | 669 | } |
667 | 670 | ||
668 | return vevent; | 671 | return vevent; |
669 | } | 672 | } |
670 | 673 | ||
671 | Todo *VCalFormat::VTodoToEvent(VObject *vtodo) | 674 | Todo *VCalFormat::VTodoToEvent(VObject *vtodo) |
672 | { | 675 | { |
673 | VObject *vo; | 676 | VObject *vo; |
674 | VObjectIterator voi; | 677 | VObjectIterator voi; |
675 | char *s; | 678 | char *s; |
676 | 679 | ||
677 | Todo *anEvent = new Todo; | 680 | Todo *anEvent = new Todo; |
678 | 681 | ||
679 | // creation date | 682 | // creation date |
680 | if ((vo = isAPropertyOf(vtodo, VCDCreatedProp)) != 0) { | 683 | if ((vo = isAPropertyOf(vtodo, VCDCreatedProp)) != 0) { |
681 | anEvent->setCreated(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); | 684 | anEvent->setCreated(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); |
682 | deleteStr(s); | 685 | deleteStr(s); |
683 | } | 686 | } |
684 | 687 | ||
685 | // unique id | 688 | // unique id |
686 | vo = isAPropertyOf(vtodo, VCUniqueStringProp); | 689 | vo = isAPropertyOf(vtodo, VCUniqueStringProp); |
687 | // while the UID property is preferred, it is not required. We'll use the | 690 | // while the UID property is preferred, it is not required. We'll use the |
688 | // default Event UID if none is given. | 691 | // default Event UID if none is given. |
689 | if (vo) { | 692 | if (vo) { |
690 | anEvent->setUid(s = fakeCString(vObjectUStringZValue(vo))); | 693 | anEvent->setUid(s = fakeCString(vObjectUStringZValue(vo))); |
691 | deleteStr(s); | 694 | deleteStr(s); |
692 | } | 695 | } |
693 | 696 | ||
694 | // last modification date | 697 | // last modification date |
695 | if ((vo = isAPropertyOf(vtodo, VCLastModifiedProp)) != 0) { | 698 | if ((vo = isAPropertyOf(vtodo, VCLastModifiedProp)) != 0) { |
696 | anEvent->setLastModified(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); | 699 | anEvent->setLastModified(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); |
697 | deleteStr(s); | 700 | deleteStr(s); |
698 | } | 701 | } |
699 | else | 702 | else |
700 | anEvent->setLastModified(QDateTime(QDate::currentDate(), | 703 | anEvent->setLastModified(QDateTime(QDate::currentDate(), |
701 | QTime::currentTime())); | 704 | QTime::currentTime())); |
702 | 705 | ||
703 | // organizer | 706 | // organizer |
704 | // if our extension property for the event's ORGANIZER exists, add it. | 707 | // if our extension property for the event's ORGANIZER exists, add it. |
705 | if ((vo = isAPropertyOf(vtodo, ICOrganizerProp)) != 0) { | 708 | if ((vo = isAPropertyOf(vtodo, ICOrganizerProp)) != 0) { |
706 | anEvent->setOrganizer(s = fakeCString(vObjectUStringZValue(vo))); | 709 | anEvent->setOrganizer(s = fakeCString(vObjectUStringZValue(vo))); |
707 | deleteStr(s); | 710 | deleteStr(s); |
708 | } else { | 711 | } else { |
709 | anEvent->setOrganizer(mCalendar->getEmail()); | 712 | anEvent->setOrganizer(mCalendar->getEmail()); |
710 | } | 713 | } |
711 | 714 | ||
712 | // attendees. | 715 | // attendees. |
713 | initPropIterator(&voi, vtodo); | 716 | initPropIterator(&voi, vtodo); |
714 | while (moreIteration(&voi)) { | 717 | while (moreIteration(&voi)) { |
715 | vo = nextVObject(&voi); | 718 | vo = nextVObject(&voi); |
716 | if (strcmp(vObjectName(vo), VCAttendeeProp) == 0) { | 719 | if (strcmp(vObjectName(vo), VCAttendeeProp) == 0) { |
717 | Attendee *a; | 720 | Attendee *a; |
718 | VObject *vp; | 721 | VObject *vp; |
719 | s = fakeCString(vObjectUStringZValue(vo)); | 722 | s = fakeCString(vObjectUStringZValue(vo)); |
720 | QString tmpStr = QString::fromLocal8Bit(s); | 723 | QString tmpStr = QString::fromLocal8Bit(s); |
721 | deleteStr(s); | 724 | deleteStr(s); |
722 | tmpStr = tmpStr.simplifyWhiteSpace(); | 725 | tmpStr = tmpStr.simplifyWhiteSpace(); |
723 | int emailPos1, emailPos2; | 726 | int emailPos1, emailPos2; |
724 | if ((emailPos1 = tmpStr.find('<')) > 0) { | 727 | if ((emailPos1 = tmpStr.find('<')) > 0) { |
725 | // both email address and name | 728 | // both email address and name |
726 | emailPos2 = tmpStr.findRev('>'); | 729 | emailPos2 = tmpStr.findRev('>'); |
727 | a = new Attendee(tmpStr.left(emailPos1 - 1), | 730 | a = new Attendee(tmpStr.left(emailPos1 - 1), |
728 | tmpStr.mid(emailPos1 + 1, | 731 | tmpStr.mid(emailPos1 + 1, |
729 | emailPos2 - (emailPos1 + 1))); | 732 | emailPos2 - (emailPos1 + 1))); |
730 | } else if (tmpStr.find('@') > 0) { | 733 | } else if (tmpStr.find('@') > 0) { |
731 | // just an email address | 734 | // just an email address |
732 | a = new Attendee(0, tmpStr); | 735 | a = new Attendee(0, tmpStr); |
733 | } else { | 736 | } else { |
734 | // just a name | 737 | // just a name |
735 | QString email = tmpStr.replace( QRegExp(" "), "." ); | 738 | QString email = tmpStr.replace( QRegExp(" "), "." ); |
736 | a = new Attendee(tmpStr,email); | 739 | a = new Attendee(tmpStr,email); |
737 | } | 740 | } |
738 | 741 | ||
739 | // is there an RSVP property? | 742 | // is there an RSVP property? |
740 | if ((vp = isAPropertyOf(vo, VCRSVPProp)) != 0) | 743 | if ((vp = isAPropertyOf(vo, VCRSVPProp)) != 0) |
741 | a->setRSVP(vObjectStringZValue(vp)); | 744 | a->setRSVP(vObjectStringZValue(vp)); |
742 | // is there a status property? | 745 | // is there a status property? |
743 | if ((vp = isAPropertyOf(vo, VCStatusProp)) != 0) | 746 | if ((vp = isAPropertyOf(vo, VCStatusProp)) != 0) |
744 | a->setStatus(readStatus(vObjectStringZValue(vp))); | 747 | a->setStatus(readStatus(vObjectStringZValue(vp))); |
745 | // add the attendee | 748 | // add the attendee |
746 | anEvent->addAttendee(a); | 749 | anEvent->addAttendee(a); |
747 | } | 750 | } |
748 | } | 751 | } |
749 | 752 | ||
750 | // description for todo | 753 | // description for todo |
751 | if ((vo = isAPropertyOf(vtodo, VCDescriptionProp)) != 0) { | 754 | if ((vo = isAPropertyOf(vtodo, VCDescriptionProp)) != 0) { |
752 | s = fakeCString(vObjectUStringZValue(vo)); | 755 | s = fakeCString(vObjectUStringZValue(vo)); |
753 | anEvent->setDescription(QString::fromLocal8Bit(s)); | 756 | anEvent->setDescription(QString::fromLocal8Bit(s)); |
754 | deleteStr(s); | 757 | deleteStr(s); |
755 | } | 758 | } |
756 | 759 | ||
757 | // summary | 760 | // summary |
758 | if ((vo = isAPropertyOf(vtodo, VCSummaryProp))) { | 761 | if ((vo = isAPropertyOf(vtodo, VCSummaryProp))) { |
759 | s = fakeCString(vObjectUStringZValue(vo)); | 762 | s = fakeCString(vObjectUStringZValue(vo)); |
760 | anEvent->setSummary(QString::fromLocal8Bit(s)); | 763 | anEvent->setSummary(QString::fromLocal8Bit(s)); |
761 | deleteStr(s); | 764 | deleteStr(s); |
762 | } | 765 | } |
763 | if ((vo = isAPropertyOf(vtodo, VCLocationProp))) { | 766 | if ((vo = isAPropertyOf(vtodo, VCLocationProp))) { |
764 | s = fakeCString(vObjectUStringZValue(vo)); | 767 | s = fakeCString(vObjectUStringZValue(vo)); |
765 | anEvent->setLocation(QString::fromLocal8Bit(s)); | 768 | anEvent->setLocation(QString::fromLocal8Bit(s)); |
766 | deleteStr(s); | 769 | deleteStr(s); |
767 | } | 770 | } |
768 | 771 | ||
769 | 772 | ||
770 | // completed | 773 | // completed |
771 | // was: status | 774 | // was: status |
772 | if ((vo = isAPropertyOf(vtodo, VCStatusProp)) != 0) { | 775 | if ((vo = isAPropertyOf(vtodo, VCStatusProp)) != 0) { |
773 | s = fakeCString(vObjectUStringZValue(vo)); | 776 | s = fakeCString(vObjectUStringZValue(vo)); |
774 | if (strcmp(s,"COMPLETED") == 0) { | 777 | if (strcmp(s,"COMPLETED") == 0) { |
775 | anEvent->setCompleted(true); | 778 | anEvent->setCompleted(true); |
776 | } else { | 779 | } else { |
777 | anEvent->setCompleted(false); | 780 | anEvent->setCompleted(false); |
778 | } | 781 | } |
779 | deleteStr(s); | 782 | deleteStr(s); |
780 | } | 783 | } |
781 | else | 784 | else |
782 | anEvent->setCompleted(false); | 785 | anEvent->setCompleted(false); |
783 | 786 | ||
784 | // completion date | 787 | // completion date |
785 | if ((vo = isAPropertyOf(vtodo, VCCompletedProp)) != 0) { | 788 | if ((vo = isAPropertyOf(vtodo, VCCompletedProp)) != 0) { |
786 | anEvent->setCompleted(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); | 789 | anEvent->setCompleted(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); |
787 | deleteStr(s); | 790 | deleteStr(s); |
788 | } | 791 | } |
789 | 792 | ||
790 | // priority | 793 | // priority |
791 | if ((vo = isAPropertyOf(vtodo, VCPriorityProp))) { | 794 | if ((vo = isAPropertyOf(vtodo, VCPriorityProp))) { |
792 | anEvent->setPriority(atoi(s = fakeCString(vObjectUStringZValue(vo)))); | 795 | anEvent->setPriority(atoi(s = fakeCString(vObjectUStringZValue(vo)))); |
793 | deleteStr(s); | 796 | deleteStr(s); |
794 | } | 797 | } |
795 | 798 | ||
796 | // due date | 799 | // due date |
797 | if ((vo = isAPropertyOf(vtodo, VCDueProp)) != 0) { | 800 | if ((vo = isAPropertyOf(vtodo, VCDueProp)) != 0) { |
798 | anEvent->setDtDue(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); | 801 | anEvent->setDtDue(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); |
799 | deleteStr(s); | 802 | deleteStr(s); |
800 | anEvent->setHasDueDate(true); | 803 | anEvent->setHasDueDate(true); |
801 | } else { | 804 | } else { |
802 | anEvent->setHasDueDate(false); | 805 | anEvent->setHasDueDate(false); |
803 | } | 806 | } |
804 | 807 | ||
805 | // start time | 808 | // start time |
806 | if ((vo = isAPropertyOf(vtodo, VCDTstartProp)) != 0) { | 809 | if ((vo = isAPropertyOf(vtodo, VCDTstartProp)) != 0) { |
807 | anEvent->setDtStart(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); | 810 | anEvent->setDtStart(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); |
808 | // kdDebug(5800) << "s is " << // s << ", ISO is " << ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo))).toString() << endl; | 811 | // kdDebug(5800) << "s is " << // s << ", ISO is " << ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo))).toString() << endl; |
809 | deleteStr(s); | 812 | deleteStr(s); |
810 | anEvent->setHasStartDate(true); | 813 | anEvent->setHasStartDate(true); |
811 | } else { | 814 | } else { |
812 | anEvent->setHasStartDate(false); | 815 | anEvent->setHasStartDate(false); |
813 | } | 816 | } |
814 | 817 | ||
815 | /* alarm stuff */ | 818 | /* alarm stuff */ |
816 | //kdDebug(5800) << "vcalformat::VTodoToEvent called" << endl; | 819 | //kdDebug(5800) << "vcalformat::VTodoToEvent called" << endl; |
817 | if ((vo = isAPropertyOf(vtodo, VCDAlarmProp))) { | 820 | if ((vo = isAPropertyOf(vtodo, VCDAlarmProp))) { |
818 | Alarm* alarm = anEvent->newAlarm(); | 821 | Alarm* alarm = anEvent->newAlarm(); |
819 | VObject *a; | 822 | VObject *a; |
820 | if ((a = isAPropertyOf(vo, VCRunTimeProp))) { | 823 | if ((a = isAPropertyOf(vo, VCRunTimeProp))) { |
821 | alarm->setTime(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(a)))); | 824 | alarm->setTime(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(a)))); |
822 | deleteStr(s); | 825 | deleteStr(s); |
823 | } | 826 | } |
824 | alarm->setEnabled(true); | 827 | alarm->setEnabled(true); |
825 | if ((vo = isAPropertyOf(vtodo, VCPAlarmProp))) { | 828 | if ((vo = isAPropertyOf(vtodo, VCPAlarmProp))) { |
826 | if ((a = isAPropertyOf(vo, VCProcedureNameProp))) { | 829 | if ((a = isAPropertyOf(vo, VCProcedureNameProp))) { |
827 | s = fakeCString(vObjectUStringZValue(a)); | 830 | s = fakeCString(vObjectUStringZValue(a)); |
828 | alarm->setProcedureAlarm(QFile::decodeName(s)); | 831 | alarm->setProcedureAlarm(QFile::decodeName(s)); |
829 | deleteStr(s); | 832 | deleteStr(s); |
830 | } | 833 | } |
831 | } | 834 | } |
832 | if ((vo = isAPropertyOf(vtodo, VCAAlarmProp))) { | 835 | if ((vo = isAPropertyOf(vtodo, VCAAlarmProp))) { |
833 | if ((a = isAPropertyOf(vo, VCAudioContentProp))) { | 836 | if ((a = isAPropertyOf(vo, VCAudioContentProp))) { |
834 | s = fakeCString(vObjectUStringZValue(a)); | 837 | s = fakeCString(vObjectUStringZValue(a)); |
835 | alarm->setAudioAlarm(QFile::decodeName(s)); | 838 | alarm->setAudioAlarm(QFile::decodeName(s)); |
836 | deleteStr(s); | 839 | deleteStr(s); |
837 | } | 840 | } |
838 | } | 841 | } |
839 | } | 842 | } |
840 | 843 | ||
841 | // related todo | 844 | // related todo |
842 | if ((vo = isAPropertyOf(vtodo, VCRelatedToProp)) != 0) { | 845 | if ((vo = isAPropertyOf(vtodo, VCRelatedToProp)) != 0) { |
843 | anEvent->setRelatedToUid(s = fakeCString(vObjectUStringZValue(vo))); | 846 | anEvent->setRelatedToUid(s = fakeCString(vObjectUStringZValue(vo))); |
844 | deleteStr(s); | 847 | deleteStr(s); |
845 | mTodosRelate.append(anEvent); | 848 | mTodosRelate.append(anEvent); |
846 | } | 849 | } |
847 | 850 | ||
848 | // categories | 851 | // categories |
849 | QStringList tmpStrList; | 852 | QStringList tmpStrList; |
850 | int index1 = 0; | 853 | int index1 = 0; |
851 | int index2 = 0; | 854 | int index2 = 0; |
852 | if ((vo = isAPropertyOf(vtodo, VCCategoriesProp)) != 0) { | 855 | if ((vo = isAPropertyOf(vtodo, VCCategoriesProp)) != 0) { |
853 | s = fakeCString(vObjectUStringZValue(vo)); | 856 | s = fakeCString(vObjectUStringZValue(vo)); |
854 | QString categories = QString::fromLocal8Bit(s); | 857 | QString categories = QString::fromLocal8Bit(s); |
855 | deleteStr(s); | 858 | deleteStr(s); |
856 | //const char* category; | 859 | //const char* category; |
857 | QString category; | 860 | QString category; |
858 | while ((index2 = categories.find(',', index1)) != -1) { | 861 | while ((index2 = categories.find(',', index1)) != -1) { |
859 | //category = (const char *) categories.mid(index1, (index2 - index1)); | 862 | //category = (const char *) categories.mid(index1, (index2 - index1)); |
860 | category = categories.mid(index1, (index2 - index1)); | 863 | category = categories.mid(index1, (index2 - index1)); |
861 | tmpStrList.append(category); | 864 | tmpStrList.append(category); |
862 | index1 = index2+1; | 865 | index1 = index2+1; |
863 | } | 866 | } |
864 | // get last category | 867 | // get last category |
865 | category = categories.mid(index1, (categories.length()-index1)); | 868 | category = categories.mid(index1, (categories.length()-index1)); |
866 | tmpStrList.append(category); | 869 | tmpStrList.append(category); |
867 | anEvent->setCategories(tmpStrList); | 870 | anEvent->setCategories(tmpStrList); |
868 | } | 871 | } |
869 | 872 | ||
870 | /* PILOT SYNC STUFF */ | 873 | /* PILOT SYNC STUFF */ |
871 | if ((vo = isAPropertyOf(vtodo, XPilotIdProp))) { | 874 | if ((vo = isAPropertyOf(vtodo, XPilotIdProp))) { |
872 | anEvent->setPilotId(atoi(s = fakeCString(vObjectUStringZValue(vo)))); | 875 | anEvent->setPilotId(atoi(s = fakeCString(vObjectUStringZValue(vo)))); |
873 | deleteStr(s); | 876 | deleteStr(s); |
874 | } | 877 | } |
875 | else | 878 | else |
876 | anEvent->setPilotId(0); | 879 | anEvent->setPilotId(0); |
877 | 880 | ||
878 | if ((vo = isAPropertyOf(vtodo, XPilotStatusProp))) { | 881 | if ((vo = isAPropertyOf(vtodo, XPilotStatusProp))) { |
879 | anEvent->setSyncStatus(atoi(s = fakeCString(vObjectUStringZValue(vo)))); | 882 | anEvent->setSyncStatus(atoi(s = fakeCString(vObjectUStringZValue(vo)))); |
880 | deleteStr(s); | 883 | deleteStr(s); |
881 | } | 884 | } |
882 | else | 885 | else |
883 | anEvent->setSyncStatus(Event::SYNCMOD); | 886 | anEvent->setSyncStatus(Event::SYNCMOD); |
884 | 887 | ||
885 | return anEvent; | 888 | return anEvent; |
886 | } | 889 | } |
887 | 890 | ||
888 | Event* VCalFormat::VEventToEvent(VObject *vevent) | 891 | Event* VCalFormat::VEventToEvent(VObject *vevent) |
889 | { | 892 | { |
890 | VObject *vo; | 893 | VObject *vo; |
891 | VObjectIterator voi; | 894 | VObjectIterator voi; |
892 | char *s; | 895 | char *s; |
893 | 896 | ||
894 | Event *anEvent = new Event; | 897 | Event *anEvent = new Event; |
895 | 898 | ||
896 | // creation date | 899 | // creation date |
897 | if ((vo = isAPropertyOf(vevent, VCDCreatedProp)) != 0) { | 900 | if ((vo = isAPropertyOf(vevent, VCDCreatedProp)) != 0) { |
898 | anEvent->setCreated(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); | 901 | anEvent->setCreated(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); |
899 | deleteStr(s); | 902 | deleteStr(s); |
900 | } | 903 | } |
901 | 904 | ||
902 | // unique id | 905 | // unique id |
903 | vo = isAPropertyOf(vevent, VCUniqueStringProp); | 906 | vo = isAPropertyOf(vevent, VCUniqueStringProp); |
904 | // while the UID property is preferred, it is not required. We'll use the | 907 | // while the UID property is preferred, it is not required. We'll use the |
905 | // default Event UID if none is given. | 908 | // default Event UID if none is given. |
906 | if (vo) { | 909 | if (vo) { |
907 | anEvent->setUid(s = fakeCString(vObjectUStringZValue(vo))); | 910 | anEvent->setUid(s = fakeCString(vObjectUStringZValue(vo))); |
908 | deleteStr(s); | 911 | deleteStr(s); |
909 | } | 912 | } |
910 | 913 | ||
911 | // revision | 914 | // revision |
912 | // again NSCAL doesn't give us much to work with, so we improvise... | 915 | // again NSCAL doesn't give us much to work with, so we improvise... |
913 | if ((vo = isAPropertyOf(vevent, VCSequenceProp)) != 0) { | 916 | if ((vo = isAPropertyOf(vevent, VCSequenceProp)) != 0) { |
914 | anEvent->setRevision(atoi(s = fakeCString(vObjectUStringZValue(vo)))); | 917 | anEvent->setRevision(atoi(s = fakeCString(vObjectUStringZValue(vo)))); |
915 | deleteStr(s); | 918 | deleteStr(s); |
916 | } | 919 | } |
917 | else | 920 | else |
918 | anEvent->setRevision(0); | 921 | anEvent->setRevision(0); |
919 | 922 | ||
920 | // last modification date | 923 | // last modification date |
921 | if ((vo = isAPropertyOf(vevent, VCLastModifiedProp)) != 0) { | 924 | if ((vo = isAPropertyOf(vevent, VCLastModifiedProp)) != 0) { |
922 | anEvent->setLastModified(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); | 925 | anEvent->setLastModified(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); |
923 | deleteStr(s); | 926 | deleteStr(s); |
924 | } | 927 | } |
925 | else | 928 | else |
926 | anEvent->setLastModified(QDateTime(QDate::currentDate(), | 929 | anEvent->setLastModified(QDateTime(QDate::currentDate(), |
927 | QTime::currentTime())); | 930 | QTime::currentTime())); |
928 | 931 | ||
929 | // organizer | 932 | // organizer |
930 | // if our extension property for the event's ORGANIZER exists, add it. | 933 | // if our extension property for the event's ORGANIZER exists, add it. |
931 | if ((vo = isAPropertyOf(vevent, ICOrganizerProp)) != 0) { | 934 | if ((vo = isAPropertyOf(vevent, ICOrganizerProp)) != 0) { |
932 | anEvent->setOrganizer(s = fakeCString(vObjectUStringZValue(vo))); | 935 | anEvent->setOrganizer(s = fakeCString(vObjectUStringZValue(vo))); |
933 | deleteStr(s); | 936 | deleteStr(s); |
934 | } else { | 937 | } else { |
935 | anEvent->setOrganizer(mCalendar->getEmail()); | 938 | anEvent->setOrganizer(mCalendar->getEmail()); |
936 | } | 939 | } |
937 | 940 | ||
938 | // deal with attendees. | 941 | // deal with attendees. |
939 | initPropIterator(&voi, vevent); | 942 | initPropIterator(&voi, vevent); |
940 | while (moreIteration(&voi)) { | 943 | while (moreIteration(&voi)) { |
941 | vo = nextVObject(&voi); | 944 | vo = nextVObject(&voi); |
942 | if (strcmp(vObjectName(vo), VCAttendeeProp) == 0) { | 945 | if (strcmp(vObjectName(vo), VCAttendeeProp) == 0) { |
943 | Attendee *a; | 946 | Attendee *a; |
944 | VObject *vp; | 947 | VObject *vp; |
945 | s = fakeCString(vObjectUStringZValue(vo)); | 948 | s = fakeCString(vObjectUStringZValue(vo)); |
946 | QString tmpStr = QString::fromLocal8Bit(s); | 949 | QString tmpStr = QString::fromLocal8Bit(s); |
947 | deleteStr(s); | 950 | deleteStr(s); |
diff --git a/libkcal/vcalformat.h b/libkcal/vcalformat.h index 8490125..7b9ca26 100644 --- a/libkcal/vcalformat.h +++ b/libkcal/vcalformat.h | |||
@@ -1,110 +1,110 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | Copyright (c) 1998 Preston Brown | 3 | Copyright (c) 1998 Preston Brown |
4 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 4 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
5 | 5 | ||
6 | This library is free software; you can redistribute it and/or | 6 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Library General Public | 7 | modify it under the terms of the GNU Library General Public |
8 | License as published by the Free Software Foundation; either | 8 | License as published by the Free Software Foundation; either |
9 | version 2 of the License, or (at your option) any later version. | 9 | version 2 of the License, or (at your option) any later version. |
10 | 10 | ||
11 | This library is distributed in the hope that it will be useful, | 11 | This library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Library General Public License for more details. | 14 | Library General Public License for more details. |
15 | 15 | ||
16 | You should have received a copy of the GNU Library General Public License | 16 | You should have received a copy of the GNU Library General Public License |
17 | along with this library; see the file COPYING.LIB. If not, write to | 17 | along with this library; see the file COPYING.LIB. If not, write to |
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
19 | Boston, MA 02111-1307, USA. | 19 | Boston, MA 02111-1307, USA. |
20 | */ | 20 | */ |
21 | 21 | ||
22 | #ifndef _VCALFORMAT_H | 22 | #ifndef _VCALFORMAT_H |
23 | #define _VCALFORMAT_H | 23 | #define _VCALFORMAT_H |
24 | 24 | ||
25 | #include "calformat.h" | 25 | #include "calformat.h" |
26 | 26 | ||
27 | #define _VCAL_VERSION "1.0" | 27 | #define _VCAL_VERSION "1.0" |
28 | 28 | ||
29 | class VObject; | 29 | class VObject; |
30 | 30 | ||
31 | namespace KCal { | 31 | namespace KCal { |
32 | 32 | ||
33 | /** | 33 | /** |
34 | This class implements the vCalendar format. It provides methods for | 34 | This class implements the vCalendar format. It provides methods for |
35 | loading/saving/converting vCalendar format data into the internal KOrganizer | 35 | loading/saving/converting vCalendar format data into the internal KOrganizer |
36 | representation as Calendar and Events. | 36 | representation as Calendar and Events. |
37 | 37 | ||
38 | @short vCalendar format implementation | 38 | @short vCalendar format implementation |
39 | */ | 39 | */ |
40 | class VCalFormat : public CalFormat { | 40 | class VCalFormat : public CalFormat { |
41 | public: | 41 | public: |
42 | VCalFormat(); | 42 | VCalFormat(); |
43 | virtual ~VCalFormat(); | 43 | virtual ~VCalFormat(); |
44 | 44 | ||
45 | /** loads a calendar on disk in vCalendar format into the current calendar. | 45 | /** loads a calendar on disk in vCalendar format into the current calendar. |
46 | * any information already present is lost. Returns TRUE if successful, | 46 | * any information already present is lost. Returns TRUE if successful, |
47 | * else returns FALSE. | 47 | * else returns FALSE. |
48 | * @param fileName the name of the calendar on disk. | 48 | * @param fileName the name of the calendar on disk. |
49 | */ | 49 | */ |
50 | bool load(Calendar *,const QString &fileName); | 50 | bool load(Calendar *,const QString &fileName); |
51 | /** writes out the calendar to disk in vCalendar format. Returns true if | 51 | /** writes out the calendar to disk in vCalendar format. Returns true if |
52 | * successful and false on error. | 52 | * successful and false on error. |
53 | * @param fileName the name of the file | 53 | * @param fileName the name of the file |
54 | */ | 54 | */ |
55 | bool save(Calendar *,const QString &fileName); | 55 | bool save(Calendar *,const QString &fileName); |
56 | 56 | ||
57 | /** | 57 | /** |
58 | Parse string and populate calendar with that information. | 58 | Parse string and populate calendar with that information. |
59 | */ | 59 | */ |
60 | bool fromString( Calendar *, const QString & ); | 60 | bool fromString( Calendar *, const QString & ); |
61 | /** | 61 | /** |
62 | Return calendar information as string. | 62 | Return calendar information as string. |
63 | */ | 63 | */ |
64 | QString toString( Calendar * ); | 64 | QString toString( Calendar * ); |
65 | QString eventToString( Event * ); | 65 | QString eventToString( Event *, Calendar *calendar ); |
66 | QString todoToString( Todo * ); | 66 | QString todoToString( Todo * ,Calendar *calendar ); |
67 | 67 | ||
68 | protected: | 68 | protected: |
69 | /** translates a VObject of the TODO type into a Event */ | 69 | /** translates a VObject of the TODO type into a Event */ |
70 | Todo *VTodoToEvent(VObject *vtodo); | 70 | Todo *VTodoToEvent(VObject *vtodo); |
71 | /** translates a VObject into a Event and returns a pointer to it. */ | 71 | /** translates a VObject into a Event and returns a pointer to it. */ |
72 | Event *VEventToEvent(VObject *vevent); | 72 | Event *VEventToEvent(VObject *vevent); |
73 | /** translate a Event into a VTodo-type VObject and return pointer */ | 73 | /** translate a Event into a VTodo-type VObject and return pointer */ |
74 | VObject *eventToVTodo(const Todo *anEvent); | 74 | VObject *eventToVTodo(const Todo *anEvent); |
75 | /** translate a Event into a VObject and returns a pointer to it. */ | 75 | /** translate a Event into a VObject and returns a pointer to it. */ |
76 | VObject* eventToVEvent(const Event *anEvent); | 76 | VObject* eventToVEvent(const Event *anEvent); |
77 | 77 | ||
78 | /** takes a QDate and returns a string in the format YYYYMMDDTHHMMSS */ | 78 | /** takes a QDate and returns a string in the format YYYYMMDDTHHMMSS */ |
79 | QString qDateToISO(const QDate &); | 79 | QString qDateToISO(const QDate &); |
80 | /** takes a QDateTime and returns a string in format YYYYMMDDTHHMMSS */ | 80 | /** takes a QDateTime and returns a string in format YYYYMMDDTHHMMSS */ |
81 | QString qDateTimeToISO(const QDateTime &, bool zulu=TRUE); | 81 | QString qDateTimeToISO(const QDateTime &, bool zulu=TRUE); |
82 | /** takes a string in the format YYYYMMDDTHHMMSS and returns a | 82 | /** takes a string in the format YYYYMMDDTHHMMSS and returns a |
83 | * valid QDateTime. */ | 83 | * valid QDateTime. */ |
84 | QDateTime ISOToQDateTime(const QString & dtStr); | 84 | QDateTime ISOToQDateTime(const QString & dtStr); |
85 | /** takes a string in the format YYYYMMDD and returns a | 85 | /** takes a string in the format YYYYMMDD and returns a |
86 | * valid QDate. */ | 86 | * valid QDate. */ |
87 | QDate ISOToQDate(const QString & dtStr); | 87 | QDate ISOToQDate(const QString & dtStr); |
88 | /** takes a vCalendar tree of VObjects, and puts all of them that have | 88 | /** takes a vCalendar tree of VObjects, and puts all of them that have |
89 | * the "event" property into the dictionary, todos in the todo-list, etc. */ | 89 | * the "event" property into the dictionary, todos in the todo-list, etc. */ |
90 | void populate(VObject *vcal); | 90 | void populate(VObject *vcal); |
91 | 91 | ||
92 | /** takes a number 0 - 6 and returns the two letter string of that day, | 92 | /** takes a number 0 - 6 and returns the two letter string of that day, |
93 | * i.e. MO, TU, WE, etc. */ | 93 | * i.e. MO, TU, WE, etc. */ |
94 | const char *dayFromNum(int day); | 94 | const char *dayFromNum(int day); |
95 | /** the reverse of the above function. */ | 95 | /** the reverse of the above function. */ |
96 | int numFromDay(const QString &day); | 96 | int numFromDay(const QString &day); |
97 | 97 | ||
98 | Attendee::PartStat readStatus(const char *s) const; | 98 | Attendee::PartStat readStatus(const char *s) const; |
99 | QCString writeStatus(Attendee::PartStat status) const; | 99 | QCString writeStatus(Attendee::PartStat status) const; |
100 | 100 | ||
101 | private: | 101 | private: |
102 | Calendar *mCalendar; | 102 | Calendar *mCalendar; |
103 | 103 | ||
104 | QPtrList<Event> mEventsRelate; // events with relations | 104 | QPtrList<Event> mEventsRelate; // events with relations |
105 | QPtrList<Todo> mTodosRelate; // todos with relations | 105 | QPtrList<Todo> mTodosRelate; // todos with relations |
106 | }; | 106 | }; |
107 | 107 | ||
108 | } | 108 | } |
109 | 109 | ||
110 | #endif | 110 | #endif |