-rw-r--r-- | libkcal/incidence.cpp | 5 | ||||
-rw-r--r-- | libkcal/incidence.h | 2 | ||||
-rw-r--r-- | libkcal/phoneformat.cpp | 1464 | ||||
-rw-r--r-- | libkcal/phoneformat.h | 14 | ||||
-rw-r--r-- | libkcal/vcalformat.cpp | 5 | ||||
-rw-r--r-- | libkcal/vcalformat.h | 5 |
6 files changed, 194 insertions, 1301 deletions
diff --git a/libkcal/incidence.cpp b/libkcal/incidence.cpp index d9bda64..56c9801 100644 --- a/libkcal/incidence.cpp +++ b/libkcal/incidence.cpp | |||
@@ -1,594 +1,599 @@ | |||
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 | 24 | ||
25 | #include "calformat.h" | 25 | #include "calformat.h" |
26 | 26 | ||
27 | #include "incidence.h" | 27 | #include "incidence.h" |
28 | #include "todo.h" | 28 | #include "todo.h" |
29 | 29 | ||
30 | using namespace KCal; | 30 | using namespace KCal; |
31 | 31 | ||
32 | Incidence::Incidence() : | 32 | Incidence::Incidence() : |
33 | IncidenceBase(), | 33 | IncidenceBase(), |
34 | mRelatedTo(0), mSecrecy(SecrecyPublic), mPriority(3) | 34 | mRelatedTo(0), mSecrecy(SecrecyPublic), mPriority(3) |
35 | { | 35 | { |
36 | mRecurrence = new Recurrence(this); | 36 | mRecurrence = new Recurrence(this); |
37 | mCancelled = false; | 37 | mCancelled = false; |
38 | recreate(); | 38 | recreate(); |
39 | mHasStartDate = true; | 39 | mHasStartDate = true; |
40 | mAlarms.setAutoDelete(true); | 40 | mAlarms.setAutoDelete(true); |
41 | mAttachments.setAutoDelete(true); | 41 | mAttachments.setAutoDelete(true); |
42 | } | 42 | } |
43 | 43 | ||
44 | Incidence::Incidence( const Incidence &i ) : IncidenceBase( i ) | 44 | Incidence::Incidence( const Incidence &i ) : IncidenceBase( i ) |
45 | { | 45 | { |
46 | // TODO: reenable attributes currently commented out. | 46 | // TODO: reenable attributes currently commented out. |
47 | mRevision = i.mRevision; | 47 | mRevision = i.mRevision; |
48 | mCreated = i.mCreated; | 48 | mCreated = i.mCreated; |
49 | mDescription = i.mDescription; | 49 | mDescription = i.mDescription; |
50 | mSummary = i.mSummary; | 50 | mSummary = i.mSummary; |
51 | mCategories = i.mCategories; | 51 | mCategories = i.mCategories; |
52 | // Incidence *mRelatedTo; Incidence *mRelatedTo; | 52 | // Incidence *mRelatedTo; Incidence *mRelatedTo; |
53 | mRelatedTo = 0; | 53 | mRelatedTo = 0; |
54 | mRelatedToUid = i.mRelatedToUid; | 54 | mRelatedToUid = i.mRelatedToUid; |
55 | // QPtrList<Incidence> mRelations; QPtrList<Incidence> mRelations; | 55 | // QPtrList<Incidence> mRelations; QPtrList<Incidence> mRelations; |
56 | mExDates = i.mExDates; | 56 | mExDates = i.mExDates; |
57 | mAttachments = i.mAttachments; | 57 | mAttachments = i.mAttachments; |
58 | mResources = i.mResources; | 58 | mResources = i.mResources; |
59 | mSecrecy = i.mSecrecy; | 59 | mSecrecy = i.mSecrecy; |
60 | mPriority = i.mPriority; | 60 | mPriority = i.mPriority; |
61 | mLocation = i.mLocation; | 61 | mLocation = i.mLocation; |
62 | mCancelled = i.mCancelled; | 62 | mCancelled = i.mCancelled; |
63 | mHasStartDate = i.mHasStartDate; | 63 | mHasStartDate = i.mHasStartDate; |
64 | QPtrListIterator<Alarm> it( i.mAlarms ); | 64 | QPtrListIterator<Alarm> it( i.mAlarms ); |
65 | const Alarm *a; | 65 | const Alarm *a; |
66 | while( (a = it.current()) ) { | 66 | while( (a = it.current()) ) { |
67 | Alarm *b = new Alarm( *a ); | 67 | Alarm *b = new Alarm( *a ); |
68 | b->setParent( this ); | 68 | b->setParent( this ); |
69 | mAlarms.append( b ); | 69 | mAlarms.append( b ); |
70 | 70 | ||
71 | ++it; | 71 | ++it; |
72 | } | 72 | } |
73 | mAlarms.setAutoDelete(true); | 73 | mAlarms.setAutoDelete(true); |
74 | 74 | ||
75 | mRecurrence = new Recurrence( *(i.mRecurrence), this ); | 75 | mRecurrence = new Recurrence( *(i.mRecurrence), this ); |
76 | } | 76 | } |
77 | 77 | ||
78 | Incidence::~Incidence() | 78 | Incidence::~Incidence() |
79 | { | 79 | { |
80 | 80 | ||
81 | Incidence *ev; | 81 | Incidence *ev; |
82 | QPtrList<Incidence> Relations = relations(); | 82 | QPtrList<Incidence> Relations = relations(); |
83 | for (ev=Relations.first();ev;ev=Relations.next()) { | 83 | for (ev=Relations.first();ev;ev=Relations.next()) { |
84 | if (ev->relatedTo() == this) ev->setRelatedTo(0); | 84 | if (ev->relatedTo() == this) ev->setRelatedTo(0); |
85 | } | 85 | } |
86 | if (relatedTo()) relatedTo()->removeRelation(this); | 86 | if (relatedTo()) relatedTo()->removeRelation(this); |
87 | delete mRecurrence; | 87 | delete mRecurrence; |
88 | 88 | ||
89 | } | 89 | } |
90 | 90 | ||
91 | bool Incidence::cancelled() const | 91 | bool Incidence::cancelled() const |
92 | { | 92 | { |
93 | return mCancelled; | 93 | return mCancelled; |
94 | } | 94 | } |
95 | void Incidence::setCancelled( bool b ) | 95 | void Incidence::setCancelled( bool b ) |
96 | { | 96 | { |
97 | mCancelled = b; | 97 | mCancelled = b; |
98 | updated(); | 98 | updated(); |
99 | } | 99 | } |
100 | bool Incidence::hasStartDate() const | 100 | bool Incidence::hasStartDate() const |
101 | { | 101 | { |
102 | return mHasStartDate; | 102 | return mHasStartDate; |
103 | } | 103 | } |
104 | 104 | ||
105 | void Incidence::setHasStartDate(bool f) | 105 | void Incidence::setHasStartDate(bool f) |
106 | { | 106 | { |
107 | if (mReadOnly) return; | 107 | if (mReadOnly) return; |
108 | mHasStartDate = f; | 108 | mHasStartDate = f; |
109 | updated(); | 109 | updated(); |
110 | } | 110 | } |
111 | 111 | ||
112 | // A string comparison that considers that null and empty are the same | 112 | // A string comparison that considers that null and empty are the same |
113 | static bool stringCompare( const QString& s1, const QString& s2 ) | 113 | static bool stringCompare( const QString& s1, const QString& s2 ) |
114 | { | 114 | { |
115 | if ( s1.isEmpty() && s2.isEmpty() ) | 115 | if ( s1.isEmpty() && s2.isEmpty() ) |
116 | return true; | 116 | return true; |
117 | return s1 == s2; | 117 | return s1 == s2; |
118 | } | 118 | } |
119 | 119 | ||
120 | bool KCal::operator==( const Incidence& i1, const Incidence& i2 ) | 120 | bool KCal::operator==( const Incidence& i1, const Incidence& i2 ) |
121 | { | 121 | { |
122 | 122 | ||
123 | if( i1.alarms().count() != i2.alarms().count() ) { | 123 | if( i1.alarms().count() != i2.alarms().count() ) { |
124 | return false; // no need to check further | 124 | return false; // no need to check further |
125 | } | 125 | } |
126 | if ( i1.alarms().count() > 0 ) { | 126 | if ( i1.alarms().count() > 0 ) { |
127 | if ( !( *(i1.alarms().first()) == *(i2.alarms().first())) ) | 127 | if ( !( *(i1.alarms().first()) == *(i2.alarms().first())) ) |
128 | { | 128 | { |
129 | qDebug("alarm not equal "); | 129 | qDebug("alarm not equal "); |
130 | return false; | 130 | return false; |
131 | } | 131 | } |
132 | } | 132 | } |
133 | #if 0 | 133 | #if 0 |
134 | QPtrListIterator<Alarm> a1( i1.alarms() ); | 134 | QPtrListIterator<Alarm> a1( i1.alarms() ); |
135 | QPtrListIterator<Alarm> a2( i2.alarms() ); | 135 | QPtrListIterator<Alarm> a2( i2.alarms() ); |
136 | for( ; a1.current() && a2.current(); ++a1, ++a2 ) { | 136 | for( ; a1.current() && a2.current(); ++a1, ++a2 ) { |
137 | if( *a1.current() == *a2.current() ) { | 137 | if( *a1.current() == *a2.current() ) { |
138 | continue; | 138 | continue; |
139 | } | 139 | } |
140 | else { | 140 | else { |
141 | return false; | 141 | return false; |
142 | } | 142 | } |
143 | } | 143 | } |
144 | #endif | 144 | #endif |
145 | 145 | ||
146 | if ( ! operator==( (const IncidenceBase&)i1, (const IncidenceBase&)i2 ) ) | 146 | if ( ! operator==( (const IncidenceBase&)i1, (const IncidenceBase&)i2 ) ) |
147 | return false; | 147 | return false; |
148 | if ( i1.hasStartDate() == i2.hasStartDate() ) { | 148 | if ( i1.hasStartDate() == i2.hasStartDate() ) { |
149 | if ( i1.hasStartDate() ) { | 149 | if ( i1.hasStartDate() ) { |
150 | if ( i1.dtStart() != i2.dtStart() ) | 150 | if ( i1.dtStart() != i2.dtStart() ) |
151 | return false; | 151 | return false; |
152 | } | 152 | } |
153 | } else { | 153 | } else { |
154 | return false; | 154 | return false; |
155 | } | 155 | } |
156 | if (!( *i1.recurrence() == *i2.recurrence()) ) { | 156 | if (!( *i1.recurrence() == *i2.recurrence()) ) { |
157 | qDebug("recurrence is NOT equal "); | 157 | qDebug("recurrence is NOT equal "); |
158 | return false; | 158 | return false; |
159 | } | 159 | } |
160 | return | 160 | return |
161 | // i1.created() == i2.created() && | 161 | // i1.created() == i2.created() && |
162 | stringCompare( i1.description(), i2.description() ) && | 162 | stringCompare( i1.description(), i2.description() ) && |
163 | stringCompare( i1.summary(), i2.summary() ) && | 163 | stringCompare( i1.summary(), i2.summary() ) && |
164 | i1.categories() == i2.categories() && | 164 | i1.categories() == i2.categories() && |
165 | // no need to compare mRelatedTo | 165 | // no need to compare mRelatedTo |
166 | stringCompare( i1.relatedToUid(), i2.relatedToUid() ) && | 166 | stringCompare( i1.relatedToUid(), i2.relatedToUid() ) && |
167 | // i1.relations() == i2.relations() && | 167 | // i1.relations() == i2.relations() && |
168 | i1.exDates() == i2.exDates() && | 168 | i1.exDates() == i2.exDates() && |
169 | i1.attachments() == i2.attachments() && | 169 | i1.attachments() == i2.attachments() && |
170 | i1.resources() == i2.resources() && | 170 | i1.resources() == i2.resources() && |
171 | i1.secrecy() == i2.secrecy() && | 171 | i1.secrecy() == i2.secrecy() && |
172 | i1.priority() == i2.priority() && | 172 | i1.priority() == i2.priority() && |
173 | stringCompare( i1.location(), i2.location() ); | 173 | stringCompare( i1.location(), i2.location() ); |
174 | } | 174 | } |
175 | 175 | ||
176 | 176 | ||
177 | void Incidence::recreate() | 177 | void Incidence::recreate() |
178 | { | 178 | { |
179 | setCreated(QDateTime::currentDateTime()); | 179 | setCreated(QDateTime::currentDateTime()); |
180 | 180 | ||
181 | setUid(CalFormat::createUniqueId()); | 181 | setUid(CalFormat::createUniqueId()); |
182 | 182 | ||
183 | setRevision(0); | 183 | setRevision(0); |
184 | 184 | ||
185 | setLastModified(QDateTime::currentDateTime()); | 185 | setLastModified(QDateTime::currentDateTime()); |
186 | } | 186 | } |
187 | 187 | ||
188 | void Incidence::setReadOnly( bool readOnly ) | 188 | void Incidence::setReadOnly( bool readOnly ) |
189 | { | 189 | { |
190 | IncidenceBase::setReadOnly( readOnly ); | 190 | IncidenceBase::setReadOnly( readOnly ); |
191 | recurrence()->setRecurReadOnly( readOnly); | 191 | recurrence()->setRecurReadOnly( readOnly); |
192 | } | 192 | } |
193 | 193 | ||
194 | void Incidence::setCreated(QDateTime created) | 194 | void Incidence::setCreated(QDateTime created) |
195 | { | 195 | { |
196 | if (mReadOnly) return; | 196 | if (mReadOnly) return; |
197 | mCreated = getEvenTime(created); | 197 | mCreated = getEvenTime(created); |
198 | } | 198 | } |
199 | 199 | ||
200 | QDateTime Incidence::created() const | 200 | QDateTime Incidence::created() const |
201 | { | 201 | { |
202 | return mCreated; | 202 | return mCreated; |
203 | } | 203 | } |
204 | 204 | ||
205 | void Incidence::setRevision(int rev) | 205 | void Incidence::setRevision(int rev) |
206 | { | 206 | { |
207 | if (mReadOnly) return; | 207 | if (mReadOnly) return; |
208 | mRevision = rev; | 208 | mRevision = rev; |
209 | 209 | ||
210 | updated(); | 210 | updated(); |
211 | } | 211 | } |
212 | 212 | ||
213 | int Incidence::revision() const | 213 | int Incidence::revision() const |
214 | { | 214 | { |
215 | return mRevision; | 215 | return mRevision; |
216 | } | 216 | } |
217 | 217 | ||
218 | void Incidence::setDtStart(const QDateTime &dtStart) | 218 | void Incidence::setDtStart(const QDateTime &dtStart) |
219 | { | 219 | { |
220 | 220 | ||
221 | QDateTime dt = getEvenTime(dtStart); | 221 | QDateTime dt = getEvenTime(dtStart); |
222 | recurrence()->setRecurStart( dt); | 222 | recurrence()->setRecurStart( dt); |
223 | IncidenceBase::setDtStart( dt ); | 223 | IncidenceBase::setDtStart( dt ); |
224 | } | 224 | } |
225 | 225 | ||
226 | void Incidence::setDescription(const QString &description) | 226 | void Incidence::setDescription(const QString &description) |
227 | { | 227 | { |
228 | if (mReadOnly) return; | 228 | if (mReadOnly) return; |
229 | mDescription = description; | 229 | mDescription = description; |
230 | updated(); | 230 | updated(); |
231 | } | 231 | } |
232 | 232 | ||
233 | QString Incidence::description() const | 233 | QString Incidence::description() const |
234 | { | 234 | { |
235 | return mDescription; | 235 | return mDescription; |
236 | } | 236 | } |
237 | 237 | ||
238 | 238 | ||
239 | void Incidence::setSummary(const QString &summary) | 239 | void Incidence::setSummary(const QString &summary) |
240 | { | 240 | { |
241 | if (mReadOnly) return; | 241 | if (mReadOnly) return; |
242 | mSummary = summary; | 242 | mSummary = summary; |
243 | updated(); | 243 | updated(); |
244 | } | 244 | } |
245 | 245 | ||
246 | QString Incidence::summary() const | 246 | QString Incidence::summary() const |
247 | { | 247 | { |
248 | return mSummary; | 248 | return mSummary; |
249 | } | 249 | } |
250 | 250 | ||
251 | void Incidence::setCategories(const QStringList &categories) | 251 | void Incidence::setCategories(const QStringList &categories) |
252 | { | 252 | { |
253 | if (mReadOnly) return; | 253 | if (mReadOnly) return; |
254 | mCategories = categories; | 254 | mCategories = categories; |
255 | updated(); | 255 | updated(); |
256 | } | 256 | } |
257 | 257 | ||
258 | // TODO: remove setCategories(QString) function | 258 | // TODO: remove setCategories(QString) function |
259 | void Incidence::setCategories(const QString &catStr) | 259 | void Incidence::setCategories(const QString &catStr) |
260 | { | 260 | { |
261 | if (mReadOnly) return; | 261 | if (mReadOnly) return; |
262 | mCategories.clear(); | 262 | mCategories.clear(); |
263 | 263 | ||
264 | if (catStr.isEmpty()) return; | 264 | if (catStr.isEmpty()) return; |
265 | 265 | ||
266 | mCategories = QStringList::split(",",catStr); | 266 | mCategories = QStringList::split(",",catStr); |
267 | 267 | ||
268 | QStringList::Iterator it; | 268 | QStringList::Iterator it; |
269 | for(it = mCategories.begin();it != mCategories.end(); ++it) { | 269 | for(it = mCategories.begin();it != mCategories.end(); ++it) { |
270 | *it = (*it).stripWhiteSpace(); | 270 | *it = (*it).stripWhiteSpace(); |
271 | } | 271 | } |
272 | 272 | ||
273 | updated(); | 273 | updated(); |
274 | } | 274 | } |
275 | 275 | ||
276 | QStringList Incidence::categories() const | 276 | QStringList Incidence::categories() const |
277 | { | 277 | { |
278 | return mCategories; | 278 | return mCategories; |
279 | } | 279 | } |
280 | 280 | ||
281 | QString Incidence::categoriesStr() | 281 | QString Incidence::categoriesStr() |
282 | { | 282 | { |
283 | return mCategories.join(","); | 283 | return mCategories.join(","); |
284 | } | 284 | } |
285 | 285 | ||
286 | void Incidence::setRelatedToUid(const QString &relatedToUid) | 286 | void Incidence::setRelatedToUid(const QString &relatedToUid) |
287 | { | 287 | { |
288 | if (mReadOnly) return; | 288 | if (mReadOnly) return; |
289 | mRelatedToUid = relatedToUid; | 289 | mRelatedToUid = relatedToUid; |
290 | } | 290 | } |
291 | 291 | ||
292 | QString Incidence::relatedToUid() const | 292 | QString Incidence::relatedToUid() const |
293 | { | 293 | { |
294 | return mRelatedToUid; | 294 | return mRelatedToUid; |
295 | } | 295 | } |
296 | 296 | ||
297 | void Incidence::setRelatedTo(Incidence *relatedTo) | 297 | void Incidence::setRelatedTo(Incidence *relatedTo) |
298 | { | 298 | { |
299 | //qDebug("Incidence::setRelatedTo %d ", relatedTo); | 299 | //qDebug("Incidence::setRelatedTo %d ", relatedTo); |
300 | //qDebug("setRelatedTo(Incidence *relatedTo) %s %s", summary().latin1(), relatedTo->summary().latin1() ); | 300 | //qDebug("setRelatedTo(Incidence *relatedTo) %s %s", summary().latin1(), relatedTo->summary().latin1() ); |
301 | if (mReadOnly || mRelatedTo == relatedTo) return; | 301 | if (mReadOnly || mRelatedTo == relatedTo) return; |
302 | if(mRelatedTo) { | 302 | if(mRelatedTo) { |
303 | // updated(); | 303 | // updated(); |
304 | mRelatedTo->removeRelation(this); | 304 | mRelatedTo->removeRelation(this); |
305 | } | 305 | } |
306 | mRelatedTo = relatedTo; | 306 | mRelatedTo = relatedTo; |
307 | if (mRelatedTo) mRelatedTo->addRelation(this); | 307 | if (mRelatedTo) mRelatedTo->addRelation(this); |
308 | } | 308 | } |
309 | 309 | ||
310 | Incidence *Incidence::relatedTo() const | 310 | Incidence *Incidence::relatedTo() const |
311 | { | 311 | { |
312 | return mRelatedTo; | 312 | return mRelatedTo; |
313 | } | 313 | } |
314 | 314 | ||
315 | QPtrList<Incidence> Incidence::relations() const | 315 | QPtrList<Incidence> Incidence::relations() const |
316 | { | 316 | { |
317 | return mRelations; | 317 | return mRelations; |
318 | } | 318 | } |
319 | 319 | ||
320 | void Incidence::addRelation(Incidence *event) | 320 | void Incidence::addRelation(Incidence *event) |
321 | { | 321 | { |
322 | if( mRelations.findRef( event ) == -1 ) { | 322 | if( mRelations.findRef( event ) == -1 ) { |
323 | mRelations.append(event); | 323 | mRelations.append(event); |
324 | //updated(); | 324 | //updated(); |
325 | } | 325 | } |
326 | } | 326 | } |
327 | 327 | ||
328 | void Incidence::removeRelation(Incidence *event) | 328 | void Incidence::removeRelation(Incidence *event) |
329 | { | 329 | { |
330 | 330 | ||
331 | mRelations.removeRef(event); | 331 | mRelations.removeRef(event); |
332 | 332 | ||
333 | // if (event->getRelatedTo() == this) event->setRelatedTo(0); | 333 | // if (event->getRelatedTo() == this) event->setRelatedTo(0); |
334 | } | 334 | } |
335 | 335 | ||
336 | bool Incidence::recursOn(const QDate &qd) const | 336 | bool Incidence::recursOn(const QDate &qd) const |
337 | { | 337 | { |
338 | if (recurrence()->recursOnPure(qd) && !isException(qd)) return true; | 338 | if (recurrence()->recursOnPure(qd) && !isException(qd)) return true; |
339 | else return false; | 339 | else return false; |
340 | } | 340 | } |
341 | 341 | ||
342 | void Incidence::setExDates(const DateList &exDates) | 342 | void Incidence::setExDates(const DateList &exDates) |
343 | { | 343 | { |
344 | if (mReadOnly) return; | 344 | if (mReadOnly) return; |
345 | mExDates = exDates; | 345 | mExDates = exDates; |
346 | 346 | ||
347 | recurrence()->setRecurExDatesCount(mExDates.count()); | 347 | recurrence()->setRecurExDatesCount(mExDates.count()); |
348 | 348 | ||
349 | updated(); | 349 | updated(); |
350 | } | 350 | } |
351 | 351 | ||
352 | void Incidence::addExDate(const QDate &date) | 352 | void Incidence::addExDate(const QDate &date) |
353 | { | 353 | { |
354 | if (mReadOnly) return; | 354 | if (mReadOnly) return; |
355 | mExDates.append(date); | 355 | mExDates.append(date); |
356 | 356 | ||
357 | recurrence()->setRecurExDatesCount(mExDates.count()); | 357 | recurrence()->setRecurExDatesCount(mExDates.count()); |
358 | 358 | ||
359 | updated(); | 359 | updated(); |
360 | } | 360 | } |
361 | 361 | ||
362 | DateList Incidence::exDates() const | 362 | DateList Incidence::exDates() const |
363 | { | 363 | { |
364 | return mExDates; | 364 | return mExDates; |
365 | } | 365 | } |
366 | 366 | ||
367 | bool Incidence::isException(const QDate &date) const | 367 | bool Incidence::isException(const QDate &date) const |
368 | { | 368 | { |
369 | DateList::ConstIterator it; | 369 | DateList::ConstIterator it; |
370 | for( it = mExDates.begin(); it != mExDates.end(); ++it ) { | 370 | for( it = mExDates.begin(); it != mExDates.end(); ++it ) { |
371 | if ( (*it) == date ) { | 371 | if ( (*it) == date ) { |
372 | return true; | 372 | return true; |
373 | } | 373 | } |
374 | } | 374 | } |
375 | 375 | ||
376 | return false; | 376 | return false; |
377 | } | 377 | } |
378 | 378 | ||
379 | void Incidence::addAttachment(Attachment *attachment) | 379 | void Incidence::addAttachment(Attachment *attachment) |
380 | { | 380 | { |
381 | if (mReadOnly || !attachment) return; | 381 | if (mReadOnly || !attachment) return; |
382 | mAttachments.append(attachment); | 382 | mAttachments.append(attachment); |
383 | updated(); | 383 | updated(); |
384 | } | 384 | } |
385 | 385 | ||
386 | void Incidence::deleteAttachment(Attachment *attachment) | 386 | void Incidence::deleteAttachment(Attachment *attachment) |
387 | { | 387 | { |
388 | mAttachments.removeRef(attachment); | 388 | mAttachments.removeRef(attachment); |
389 | } | 389 | } |
390 | 390 | ||
391 | void Incidence::deleteAttachments(const QString& mime) | 391 | void Incidence::deleteAttachments(const QString& mime) |
392 | { | 392 | { |
393 | Attachment *at = mAttachments.first(); | 393 | Attachment *at = mAttachments.first(); |
394 | while (at) { | 394 | while (at) { |
395 | if (at->mimeType() == mime) | 395 | if (at->mimeType() == mime) |
396 | mAttachments.remove(); | 396 | mAttachments.remove(); |
397 | else | 397 | else |
398 | at = mAttachments.next(); | 398 | at = mAttachments.next(); |
399 | } | 399 | } |
400 | } | 400 | } |
401 | 401 | ||
402 | QPtrList<Attachment> Incidence::attachments() const | 402 | QPtrList<Attachment> Incidence::attachments() const |
403 | { | 403 | { |
404 | return mAttachments; | 404 | return mAttachments; |
405 | } | 405 | } |
406 | 406 | ||
407 | QPtrList<Attachment> Incidence::attachments(const QString& mime) const | 407 | QPtrList<Attachment> Incidence::attachments(const QString& mime) const |
408 | { | 408 | { |
409 | QPtrList<Attachment> attachments; | 409 | QPtrList<Attachment> attachments; |
410 | QPtrListIterator<Attachment> it( mAttachments ); | 410 | QPtrListIterator<Attachment> it( mAttachments ); |
411 | Attachment *at; | 411 | Attachment *at; |
412 | while ( (at = it.current()) ) { | 412 | while ( (at = it.current()) ) { |
413 | if (at->mimeType() == mime) | 413 | if (at->mimeType() == mime) |
414 | attachments.append(at); | 414 | attachments.append(at); |
415 | ++it; | 415 | ++it; |
416 | } | 416 | } |
417 | 417 | ||
418 | return attachments; | 418 | return attachments; |
419 | } | 419 | } |
420 | 420 | ||
421 | void Incidence::setResources(const QStringList &resources) | 421 | void Incidence::setResources(const QStringList &resources) |
422 | { | 422 | { |
423 | if (mReadOnly) return; | 423 | if (mReadOnly) return; |
424 | mResources = resources; | 424 | mResources = resources; |
425 | updated(); | 425 | updated(); |
426 | } | 426 | } |
427 | 427 | ||
428 | QStringList Incidence::resources() const | 428 | QStringList Incidence::resources() const |
429 | { | 429 | { |
430 | return mResources; | 430 | return mResources; |
431 | } | 431 | } |
432 | 432 | ||
433 | 433 | ||
434 | void Incidence::setPriority(int priority) | 434 | void Incidence::setPriority(int priority) |
435 | { | 435 | { |
436 | if (mReadOnly) return; | 436 | if (mReadOnly) return; |
437 | mPriority = priority; | 437 | mPriority = priority; |
438 | updated(); | 438 | updated(); |
439 | } | 439 | } |
440 | 440 | ||
441 | int Incidence::priority() const | 441 | int Incidence::priority() const |
442 | { | 442 | { |
443 | return mPriority; | 443 | return mPriority; |
444 | } | 444 | } |
445 | 445 | ||
446 | void Incidence::setSecrecy(int sec) | 446 | void Incidence::setSecrecy(int sec) |
447 | { | 447 | { |
448 | if (mReadOnly) return; | 448 | if (mReadOnly) return; |
449 | mSecrecy = sec; | 449 | mSecrecy = sec; |
450 | updated(); | 450 | updated(); |
451 | } | 451 | } |
452 | 452 | ||
453 | int Incidence::secrecy() const | 453 | int Incidence::secrecy() const |
454 | { | 454 | { |
455 | return mSecrecy; | 455 | return mSecrecy; |
456 | } | 456 | } |
457 | 457 | ||
458 | QString Incidence::secrecyStr() const | 458 | QString Incidence::secrecyStr() const |
459 | { | 459 | { |
460 | return secrecyName(mSecrecy); | 460 | return secrecyName(mSecrecy); |
461 | } | 461 | } |
462 | 462 | ||
463 | QString Incidence::secrecyName(int secrecy) | 463 | QString Incidence::secrecyName(int secrecy) |
464 | { | 464 | { |
465 | switch (secrecy) { | 465 | switch (secrecy) { |
466 | case SecrecyPublic: | 466 | case SecrecyPublic: |
467 | return i18n("Public"); | 467 | return i18n("Public"); |
468 | break; | 468 | break; |
469 | case SecrecyPrivate: | 469 | case SecrecyPrivate: |
470 | return i18n("Private"); | 470 | return i18n("Private"); |
471 | break; | 471 | break; |
472 | case SecrecyConfidential: | 472 | case SecrecyConfidential: |
473 | return i18n("Confidential"); | 473 | return i18n("Confidential"); |
474 | break; | 474 | break; |
475 | default: | 475 | default: |
476 | return i18n("Undefined"); | 476 | return i18n("Undefined"); |
477 | break; | 477 | break; |
478 | } | 478 | } |
479 | } | 479 | } |
480 | 480 | ||
481 | QStringList Incidence::secrecyList() | 481 | QStringList Incidence::secrecyList() |
482 | { | 482 | { |
483 | QStringList list; | 483 | QStringList list; |
484 | list << secrecyName(SecrecyPublic); | 484 | list << secrecyName(SecrecyPublic); |
485 | list << secrecyName(SecrecyPrivate); | 485 | list << secrecyName(SecrecyPrivate); |
486 | list << secrecyName(SecrecyConfidential); | 486 | list << secrecyName(SecrecyConfidential); |
487 | 487 | ||
488 | return list; | 488 | return list; |
489 | } | 489 | } |
490 | 490 | ||
491 | 491 | ||
492 | QPtrList<Alarm> Incidence::alarms() const | 492 | QPtrList<Alarm> Incidence::alarms() const |
493 | { | 493 | { |
494 | return mAlarms; | 494 | return mAlarms; |
495 | } | 495 | } |
496 | 496 | ||
497 | Alarm* Incidence::newAlarm() | 497 | Alarm* Incidence::newAlarm() |
498 | { | 498 | { |
499 | Alarm* alarm = new Alarm(this); | 499 | Alarm* alarm = new Alarm(this); |
500 | mAlarms.append(alarm); | 500 | mAlarms.append(alarm); |
501 | // updated(); | 501 | // updated(); |
502 | return alarm; | 502 | return alarm; |
503 | } | 503 | } |
504 | 504 | ||
505 | void Incidence::addAlarm(Alarm *alarm) | 505 | void Incidence::addAlarm(Alarm *alarm) |
506 | { | 506 | { |
507 | mAlarms.append(alarm); | 507 | mAlarms.append(alarm); |
508 | updated(); | 508 | updated(); |
509 | } | 509 | } |
510 | 510 | ||
511 | void Incidence::removeAlarm(Alarm *alarm) | 511 | void Incidence::removeAlarm(Alarm *alarm) |
512 | { | 512 | { |
513 | mAlarms.removeRef(alarm); | 513 | mAlarms.removeRef(alarm); |
514 | updated(); | 514 | updated(); |
515 | } | 515 | } |
516 | 516 | ||
517 | void Incidence::clearAlarms() | 517 | void Incidence::clearAlarms() |
518 | { | 518 | { |
519 | mAlarms.clear(); | 519 | mAlarms.clear(); |
520 | updated(); | 520 | updated(); |
521 | } | 521 | } |
522 | 522 | ||
523 | bool Incidence::isAlarmEnabled() const | 523 | bool Incidence::isAlarmEnabled() const |
524 | { | 524 | { |
525 | Alarm* alarm; | 525 | Alarm* alarm; |
526 | for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { | 526 | for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { |
527 | if (alarm->enabled()) | 527 | if (alarm->enabled()) |
528 | return true; | 528 | return true; |
529 | } | 529 | } |
530 | return false; | 530 | return false; |
531 | } | 531 | } |
532 | 532 | ||
533 | Recurrence *Incidence::recurrence() const | 533 | Recurrence *Incidence::recurrence() const |
534 | { | 534 | { |
535 | return mRecurrence; | 535 | return mRecurrence; |
536 | } | 536 | } |
537 | void Incidence::setRecurrence( Recurrence * r) | ||
538 | { | ||
539 | delete mRecurrence; | ||
540 | mRecurrence = r; | ||
541 | } | ||
537 | 542 | ||
538 | void Incidence::setLocation(const QString &location) | 543 | void Incidence::setLocation(const QString &location) |
539 | { | 544 | { |
540 | if (mReadOnly) return; | 545 | if (mReadOnly) return; |
541 | mLocation = location; | 546 | mLocation = location; |
542 | updated(); | 547 | updated(); |
543 | } | 548 | } |
544 | 549 | ||
545 | QString Incidence::location() const | 550 | QString Incidence::location() const |
546 | { | 551 | { |
547 | return mLocation; | 552 | return mLocation; |
548 | } | 553 | } |
549 | 554 | ||
550 | ushort Incidence::doesRecur() const | 555 | ushort Incidence::doesRecur() const |
551 | { | 556 | { |
552 | if ( mRecurrence ) return mRecurrence->doesRecur(); | 557 | if ( mRecurrence ) return mRecurrence->doesRecur(); |
553 | else return Recurrence::rNone; | 558 | else return Recurrence::rNone; |
554 | } | 559 | } |
555 | 560 | ||
556 | QDateTime Incidence::getNextOccurence( const QDateTime& dt, bool* ok ) const | 561 | QDateTime Incidence::getNextOccurence( const QDateTime& dt, bool* ok ) const |
557 | { | 562 | { |
558 | QDateTime incidenceStart = dt; | 563 | QDateTime incidenceStart = dt; |
559 | *ok = false; | 564 | *ok = false; |
560 | if ( doesRecur() ) { | 565 | if ( doesRecur() ) { |
561 | bool last; | 566 | bool last; |
562 | recurrence()->getPreviousDateTime( incidenceStart , &last ); | 567 | recurrence()->getPreviousDateTime( incidenceStart , &last ); |
563 | int count = 0; | 568 | int count = 0; |
564 | if ( !last ) { | 569 | if ( !last ) { |
565 | while ( !last ) { | 570 | while ( !last ) { |
566 | ++count; | 571 | ++count; |
567 | incidenceStart = recurrence()->getNextDateTime( incidenceStart, &last ); | 572 | incidenceStart = recurrence()->getNextDateTime( incidenceStart, &last ); |
568 | if ( recursOn( incidenceStart.date() ) ) { | 573 | if ( recursOn( incidenceStart.date() ) ) { |
569 | last = true; // exit while llop | 574 | last = true; // exit while llop |
570 | } else { | 575 | } else { |
571 | if ( last ) { // no alarm on last recurrence | 576 | if ( last ) { // no alarm on last recurrence |
572 | return QDateTime (); | 577 | return QDateTime (); |
573 | } | 578 | } |
574 | int year = incidenceStart.date().year(); | 579 | int year = incidenceStart.date().year(); |
575 | // workaround for bug in recurrence | 580 | // workaround for bug in recurrence |
576 | if ( count == 100 || year < 1980 || year > 5000 ) { | 581 | if ( count == 100 || year < 1980 || year > 5000 ) { |
577 | return QDateTime (); | 582 | return QDateTime (); |
578 | } | 583 | } |
579 | incidenceStart = incidenceStart.addSecs( 1 ); | 584 | incidenceStart = incidenceStart.addSecs( 1 ); |
580 | } | 585 | } |
581 | } | 586 | } |
582 | } else { | 587 | } else { |
583 | return QDateTime (); | 588 | return QDateTime (); |
584 | } | 589 | } |
585 | } else { | 590 | } else { |
586 | if ( hasStartDate () ) { | 591 | if ( hasStartDate () ) { |
587 | incidenceStart = dtStart(); | 592 | incidenceStart = dtStart(); |
588 | 593 | ||
589 | } | 594 | } |
590 | } | 595 | } |
591 | if ( incidenceStart > dt ) | 596 | if ( incidenceStart > dt ) |
592 | *ok = true; | 597 | *ok = true; |
593 | return incidenceStart; | 598 | return incidenceStart; |
594 | } | 599 | } |
diff --git a/libkcal/incidence.h b/libkcal/incidence.h index d1972cb..7dc6f10 100644 --- a/libkcal/incidence.h +++ b/libkcal/incidence.h | |||
@@ -1,298 +1,298 @@ | |||
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 | #ifndef INCIDENCE_H | 20 | #ifndef INCIDENCE_H |
21 | #define INCIDENCE_H | 21 | #define INCIDENCE_H |
22 | // | 22 | // |
23 | // Incidence - base class of calendaring components | 23 | // Incidence - base class of calendaring components |
24 | // | 24 | // |
25 | 25 | ||
26 | #include <qdatetime.h> | 26 | #include <qdatetime.h> |
27 | #include <qstringlist.h> | 27 | #include <qstringlist.h> |
28 | #include <qvaluelist.h> | 28 | #include <qvaluelist.h> |
29 | 29 | ||
30 | #include "recurrence.h" | 30 | #include "recurrence.h" |
31 | #include "alarm.h" | 31 | #include "alarm.h" |
32 | #include "attachment.h" | 32 | #include "attachment.h" |
33 | #include "listbase.h" | 33 | #include "listbase.h" |
34 | #include "incidencebase.h" | 34 | #include "incidencebase.h" |
35 | 35 | ||
36 | namespace KCal { | 36 | namespace KCal { |
37 | 37 | ||
38 | class Event; | 38 | class Event; |
39 | class Todo; | 39 | class Todo; |
40 | class Journal; | 40 | class Journal; |
41 | 41 | ||
42 | /** | 42 | /** |
43 | This class provides the base class common to all calendar components. | 43 | This class provides the base class common to all calendar components. |
44 | */ | 44 | */ |
45 | class Incidence : public IncidenceBase | 45 | class Incidence : public IncidenceBase |
46 | { | 46 | { |
47 | public: | 47 | public: |
48 | /** | 48 | /** |
49 | This class provides the interface for a visitor of calendar components. It | 49 | This class provides the interface for a visitor of calendar components. It |
50 | serves as base class for concrete visitors, which implement certain actions on | 50 | serves as base class for concrete visitors, which implement certain actions on |
51 | calendar components. It allows to add functions, which operate on the concrete | 51 | calendar components. It allows to add functions, which operate on the concrete |
52 | types of calendar components, without changing the calendar component classes. | 52 | types of calendar components, without changing the calendar component classes. |
53 | */ | 53 | */ |
54 | class Visitor | 54 | class Visitor |
55 | { | 55 | { |
56 | public: | 56 | public: |
57 | /** Destruct Incidence::Visitor */ | 57 | /** Destruct Incidence::Visitor */ |
58 | virtual ~Visitor() {} | 58 | virtual ~Visitor() {} |
59 | 59 | ||
60 | /** | 60 | /** |
61 | Reimplement this function in your concrete subclass of IncidenceVisitor to perform actions | 61 | Reimplement this function in your concrete subclass of IncidenceVisitor to perform actions |
62 | on an Event object. | 62 | on an Event object. |
63 | */ | 63 | */ |
64 | virtual bool visit(Event *) { return false; } | 64 | virtual bool visit(Event *) { return false; } |
65 | /** | 65 | /** |
66 | Reimplement this function in your concrete subclass of IncidenceVisitor to perform actions | 66 | Reimplement this function in your concrete subclass of IncidenceVisitor to perform actions |
67 | on an Todo object. | 67 | on an Todo object. |
68 | */ | 68 | */ |
69 | virtual bool visit(Todo *) { return false; } | 69 | virtual bool visit(Todo *) { return false; } |
70 | /** | 70 | /** |
71 | Reimplement this function in your concrete subclass of IncidenceVisitor to perform actions | 71 | Reimplement this function in your concrete subclass of IncidenceVisitor to perform actions |
72 | on an Journal object. | 72 | on an Journal object. |
73 | */ | 73 | */ |
74 | virtual bool visit(Journal *) { return false; } | 74 | virtual bool visit(Journal *) { return false; } |
75 | 75 | ||
76 | protected: | 76 | protected: |
77 | /** Constructor is protected to prevent direct creation of visitor base class. */ | 77 | /** Constructor is protected to prevent direct creation of visitor base class. */ |
78 | Visitor() {} | 78 | Visitor() {} |
79 | }; | 79 | }; |
80 | 80 | ||
81 | /** | 81 | /** |
82 | This class implements a visitor for adding an Incidence to a resource | 82 | This class implements a visitor for adding an Incidence to a resource |
83 | supporting addEvent(), addTodo() and addJournal() calls. | 83 | supporting addEvent(), addTodo() and addJournal() calls. |
84 | */ | 84 | */ |
85 | template<class T> | 85 | template<class T> |
86 | class AddVisitor : public Visitor | 86 | class AddVisitor : public Visitor |
87 | { | 87 | { |
88 | public: | 88 | public: |
89 | AddVisitor( T *r ) : mResource( r ) {} | 89 | AddVisitor( T *r ) : mResource( r ) {} |
90 | bool visit( Event *e ) { return mResource->addEvent( e ); } | 90 | bool visit( Event *e ) { return mResource->addEvent( e ); } |
91 | bool visit( Todo *t ) { return mResource->addTodo( t ); } | 91 | bool visit( Todo *t ) { return mResource->addTodo( t ); } |
92 | bool visit( Journal *j ) { return mResource->addJournal( j ); } | 92 | bool visit( Journal *j ) { return mResource->addJournal( j ); } |
93 | 93 | ||
94 | private: | 94 | private: |
95 | T *mResource; | 95 | T *mResource; |
96 | }; | 96 | }; |
97 | 97 | ||
98 | /** enumeration for describing an event's secrecy. */ | 98 | /** enumeration for describing an event's secrecy. */ |
99 | enum { SecrecyPublic = 0, SecrecyPrivate = 1, SecrecyConfidential = 2 }; | 99 | enum { SecrecyPublic = 0, SecrecyPrivate = 1, SecrecyConfidential = 2 }; |
100 | typedef ListBase<Incidence> List; | 100 | typedef ListBase<Incidence> List; |
101 | Incidence(); | 101 | Incidence(); |
102 | Incidence(const Incidence &); | 102 | Incidence(const Incidence &); |
103 | ~Incidence(); | 103 | ~Incidence(); |
104 | 104 | ||
105 | /** | 105 | /** |
106 | Accept IncidenceVisitor. A class taking part in the visitor mechanism has to | 106 | Accept IncidenceVisitor. A class taking part in the visitor mechanism has to |
107 | provide this implementation: | 107 | provide this implementation: |
108 | <pre> | 108 | <pre> |
109 | bool accept(Visitor &v) { return v.visit(this); } | 109 | bool accept(Visitor &v) { return v.visit(this); } |
110 | </pre> | 110 | </pre> |
111 | */ | 111 | */ |
112 | virtual bool accept(Visitor &) { return false; } | 112 | virtual bool accept(Visitor &) { return false; } |
113 | 113 | ||
114 | virtual Incidence *clone() = 0; | 114 | virtual Incidence *clone() = 0; |
115 | 115 | ||
116 | virtual QDateTime getNextAlarmDateTime( bool * ok, int * offset ) const = 0; | 116 | virtual QDateTime getNextAlarmDateTime( bool * ok, int * offset ) const = 0; |
117 | void setReadOnly( bool ); | 117 | void setReadOnly( bool ); |
118 | 118 | ||
119 | /** | 119 | /** |
120 | Recreate event. The event is made a new unique event, but already stored | 120 | Recreate event. The event is made a new unique event, but already stored |
121 | event information is preserved. Sets uniquie id, creation date, last | 121 | event information is preserved. Sets uniquie id, creation date, last |
122 | modification date and revision number. | 122 | modification date and revision number. |
123 | */ | 123 | */ |
124 | void recreate(); | 124 | void recreate(); |
125 | 125 | ||
126 | /** set creation date */ | 126 | /** set creation date */ |
127 | void setCreated(QDateTime); | 127 | void setCreated(QDateTime); |
128 | /** return time and date of creation. */ | 128 | /** return time and date of creation. */ |
129 | QDateTime created() const; | 129 | QDateTime created() const; |
130 | 130 | ||
131 | /** set the number of revisions this event has seen */ | 131 | /** set the number of revisions this event has seen */ |
132 | void setRevision(int rev); | 132 | void setRevision(int rev); |
133 | /** return the number of revisions this event has seen */ | 133 | /** return the number of revisions this event has seen */ |
134 | int revision() const; | 134 | int revision() const; |
135 | 135 | ||
136 | /** Set starting date/time. */ | 136 | /** Set starting date/time. */ |
137 | virtual void setDtStart(const QDateTime &dtStart); | 137 | virtual void setDtStart(const QDateTime &dtStart); |
138 | /** Return the incidence's ending date/time as a QDateTime. */ | 138 | /** Return the incidence's ending date/time as a QDateTime. */ |
139 | virtual QDateTime dtEnd() const { return QDateTime(); } | 139 | virtual QDateTime dtEnd() const { return QDateTime(); } |
140 | 140 | ||
141 | /** sets the event's lengthy description. */ | 141 | /** sets the event's lengthy description. */ |
142 | void setDescription(const QString &description); | 142 | void setDescription(const QString &description); |
143 | /** returns a reference to the event's description. */ | 143 | /** returns a reference to the event's description. */ |
144 | QString description() const; | 144 | QString description() const; |
145 | 145 | ||
146 | /** sets the event's short summary. */ | 146 | /** sets the event's short summary. */ |
147 | void setSummary(const QString &summary); | 147 | void setSummary(const QString &summary); |
148 | /** returns a reference to the event's summary. */ | 148 | /** returns a reference to the event's summary. */ |
149 | QString summary() const; | 149 | QString summary() const; |
150 | 150 | ||
151 | /** set event's applicable categories */ | 151 | /** set event's applicable categories */ |
152 | void setCategories(const QStringList &categories); | 152 | void setCategories(const QStringList &categories); |
153 | /** set event's categories based on a comma delimited string */ | 153 | /** set event's categories based on a comma delimited string */ |
154 | void setCategories(const QString &catStr); | 154 | void setCategories(const QString &catStr); |
155 | /** return categories in a list */ | 155 | /** return categories in a list */ |
156 | QStringList categories() const; | 156 | QStringList categories() const; |
157 | /** return categories as a comma separated string */ | 157 | /** return categories as a comma separated string */ |
158 | QString categoriesStr(); | 158 | QString categoriesStr(); |
159 | 159 | ||
160 | /** point at some other event to which the event relates. This function should | 160 | /** point at some other event to which the event relates. This function should |
161 | * only be used when constructing a calendar before the related Event | 161 | * only be used when constructing a calendar before the related Event |
162 | * exists. */ | 162 | * exists. */ |
163 | void setRelatedToUid(const QString &); | 163 | void setRelatedToUid(const QString &); |
164 | /** what event does this one relate to? This function should | 164 | /** what event does this one relate to? This function should |
165 | * only be used when constructing a calendar before the related Event | 165 | * only be used when constructing a calendar before the related Event |
166 | * exists. */ | 166 | * exists. */ |
167 | QString relatedToUid() const; | 167 | QString relatedToUid() const; |
168 | /** point at some other event to which the event relates */ | 168 | /** point at some other event to which the event relates */ |
169 | void setRelatedTo(Incidence *relatedTo); | 169 | void setRelatedTo(Incidence *relatedTo); |
170 | /** what event does this one relate to? */ | 170 | /** what event does this one relate to? */ |
171 | Incidence *relatedTo() const; | 171 | Incidence *relatedTo() const; |
172 | /** All events that are related to this event */ | 172 | /** All events that are related to this event */ |
173 | QPtrList<Incidence> relations() const; | 173 | QPtrList<Incidence> relations() const; |
174 | /** Add an event which is related to this event */ | 174 | /** Add an event which is related to this event */ |
175 | void addRelation(Incidence *); | 175 | void addRelation(Incidence *); |
176 | /** Remove event that is related to this event */ | 176 | /** Remove event that is related to this event */ |
177 | void removeRelation(Incidence *); | 177 | void removeRelation(Incidence *); |
178 | 178 | ||
179 | /** returns the list of dates which are exceptions to the recurrence rule */ | 179 | /** returns the list of dates which are exceptions to the recurrence rule */ |
180 | DateList exDates() const; | 180 | DateList exDates() const; |
181 | /** sets the list of dates which are exceptions to the recurrence rule */ | 181 | /** sets the list of dates which are exceptions to the recurrence rule */ |
182 | void setExDates(const DateList &_exDates); | 182 | void setExDates(const DateList &_exDates); |
183 | void setExDates(const char *dates); | 183 | void setExDates(const char *dates); |
184 | /** Add a date to the list of exceptions of the recurrence rule. */ | 184 | /** Add a date to the list of exceptions of the recurrence rule. */ |
185 | void addExDate(const QDate &date); | 185 | void addExDate(const QDate &date); |
186 | 186 | ||
187 | /** returns true if there is an exception for this date in the recurrence | 187 | /** returns true if there is an exception for this date in the recurrence |
188 | rule set, or false otherwise. */ | 188 | rule set, or false otherwise. */ |
189 | bool isException(const QDate &qd) const; | 189 | bool isException(const QDate &qd) const; |
190 | 190 | ||
191 | /** add attachment to this event */ | 191 | /** add attachment to this event */ |
192 | void addAttachment(Attachment *attachment); | 192 | void addAttachment(Attachment *attachment); |
193 | /** remove and delete a specific attachment */ | 193 | /** remove and delete a specific attachment */ |
194 | void deleteAttachment(Attachment *attachment); | 194 | void deleteAttachment(Attachment *attachment); |
195 | /** remove and delete all attachments with this mime type */ | 195 | /** remove and delete all attachments with this mime type */ |
196 | void deleteAttachments(const QString& mime); | 196 | void deleteAttachments(const QString& mime); |
197 | /** return list of all associated attachments */ | 197 | /** return list of all associated attachments */ |
198 | QPtrList<Attachment> attachments() const; | 198 | QPtrList<Attachment> attachments() const; |
199 | /** find a list of attachments with this mime type */ | 199 | /** find a list of attachments with this mime type */ |
200 | QPtrList<Attachment> attachments(const QString& mime) const; | 200 | QPtrList<Attachment> attachments(const QString& mime) const; |
201 | 201 | ||
202 | /** sets the event's status the value specified. See the enumeration | 202 | /** sets the event's status the value specified. See the enumeration |
203 | * above for possible values. */ | 203 | * above for possible values. */ |
204 | void setSecrecy(int); | 204 | void setSecrecy(int); |
205 | /** return the event's secrecy. */ | 205 | /** return the event's secrecy. */ |
206 | int secrecy() const; | 206 | int secrecy() const; |
207 | /** return the event's secrecy in string format. */ | 207 | /** return the event's secrecy in string format. */ |
208 | QString secrecyStr() const; | 208 | QString secrecyStr() const; |
209 | /** return list of all availbale secrecy classes */ | 209 | /** return list of all availbale secrecy classes */ |
210 | static QStringList secrecyList(); | 210 | static QStringList secrecyList(); |
211 | /** return human-readable name of secrecy class */ | 211 | /** return human-readable name of secrecy class */ |
212 | static QString secrecyName(int); | 212 | static QString secrecyName(int); |
213 | 213 | ||
214 | /** returns TRUE if the date specified is one on which the event will | 214 | /** returns TRUE if the date specified is one on which the event will |
215 | * recur. */ | 215 | * recur. */ |
216 | bool recursOn(const QDate &qd) const; | 216 | bool recursOn(const QDate &qd) const; |
217 | 217 | ||
218 | // VEVENT and VTODO, but not VJOURNAL (move to EventBase class?): | 218 | // VEVENT and VTODO, but not VJOURNAL (move to EventBase class?): |
219 | 219 | ||
220 | /** set resources used, such as Office, Car, etc. */ | 220 | /** set resources used, such as Office, Car, etc. */ |
221 | void setResources(const QStringList &resources); | 221 | void setResources(const QStringList &resources); |
222 | /** return list of current resources */ | 222 | /** return list of current resources */ |
223 | QStringList resources() const; | 223 | QStringList resources() const; |
224 | 224 | ||
225 | /** set the event's priority, 0 is undefined, 1 highest (decreasing order) */ | 225 | /** set the event's priority, 0 is undefined, 1 highest (decreasing order) */ |
226 | void setPriority(int priority); | 226 | void setPriority(int priority); |
227 | /** get the event's priority */ | 227 | /** get the event's priority */ |
228 | int priority() const; | 228 | int priority() const; |
229 | 229 | ||
230 | /** All alarms that are associated with this incidence */ | 230 | /** All alarms that are associated with this incidence */ |
231 | QPtrList<Alarm> alarms() const; | 231 | QPtrList<Alarm> alarms() const; |
232 | /** Create a new alarm which is associated with this incidence */ | 232 | /** Create a new alarm which is associated with this incidence */ |
233 | Alarm* newAlarm(); | 233 | Alarm* newAlarm(); |
234 | /** Add an alarm which is associated with this incidence */ | 234 | /** Add an alarm which is associated with this incidence */ |
235 | void addAlarm(Alarm*); | 235 | void addAlarm(Alarm*); |
236 | /** Remove an alarm that is associated with this incidence */ | 236 | /** Remove an alarm that is associated with this incidence */ |
237 | void removeAlarm(Alarm*); | 237 | void removeAlarm(Alarm*); |
238 | /** Remove all alarms that are associated with this incidence */ | 238 | /** Remove all alarms that are associated with this incidence */ |
239 | void clearAlarms(); | 239 | void clearAlarms(); |
240 | /** return whether any alarm associated with this incidence is enabled */ | 240 | /** return whether any alarm associated with this incidence is enabled */ |
241 | bool isAlarmEnabled() const; | 241 | bool isAlarmEnabled() const; |
242 | 242 | ||
243 | /** | 243 | /** |
244 | Return the recurrence rule associated with this incidence. If there is | 244 | Return the recurrence rule associated with this incidence. If there is |
245 | none, returns an appropriate (non-0) object. | 245 | none, returns an appropriate (non-0) object. |
246 | */ | 246 | */ |
247 | Recurrence *recurrence() const; | 247 | Recurrence *recurrence() const; |
248 | 248 | void setRecurrence(Recurrence * r); | |
249 | /** | 249 | /** |
250 | Forward to Recurrence::doesRecur(). | 250 | Forward to Recurrence::doesRecur(). |
251 | */ | 251 | */ |
252 | ushort doesRecur() const; | 252 | ushort doesRecur() const; |
253 | 253 | ||
254 | /** set the event's/todo's location. Do _not_ use it with journal */ | 254 | /** set the event's/todo's location. Do _not_ use it with journal */ |
255 | void setLocation(const QString &location); | 255 | void setLocation(const QString &location); |
256 | /** return the event's/todo's location. Do _not_ use it with journal */ | 256 | /** return the event's/todo's location. Do _not_ use it with journal */ |
257 | QString location() const; | 257 | QString location() const; |
258 | /** returns TRUE or FALSE depending on whether the todo has a start date */ | 258 | /** returns TRUE or FALSE depending on whether the todo has a start date */ |
259 | bool hasStartDate() const; | 259 | bool hasStartDate() const; |
260 | /** sets the event's hasStartDate value. */ | 260 | /** sets the event's hasStartDate value. */ |
261 | void setHasStartDate(bool f); | 261 | void setHasStartDate(bool f); |
262 | QDateTime getNextOccurence( const QDateTime& dt, bool* yes ) const; | 262 | QDateTime getNextOccurence( const QDateTime& dt, bool* yes ) const; |
263 | bool cancelled() const; | 263 | bool cancelled() const; |
264 | void setCancelled( bool b ); | 264 | void setCancelled( bool b ); |
265 | 265 | ||
266 | protected: | 266 | protected: |
267 | QPtrList<Alarm> mAlarms; | 267 | QPtrList<Alarm> mAlarms; |
268 | private: | 268 | private: |
269 | int mRevision; | 269 | int mRevision; |
270 | bool mCancelled; | 270 | bool mCancelled; |
271 | 271 | ||
272 | // base components of jounal, event and todo | 272 | // base components of jounal, event and todo |
273 | QDateTime mCreated; | 273 | QDateTime mCreated; |
274 | QString mDescription; | 274 | QString mDescription; |
275 | QString mSummary; | 275 | QString mSummary; |
276 | QStringList mCategories; | 276 | QStringList mCategories; |
277 | Incidence *mRelatedTo; | 277 | Incidence *mRelatedTo; |
278 | QString mRelatedToUid; | 278 | QString mRelatedToUid; |
279 | QPtrList<Incidence> mRelations; | 279 | QPtrList<Incidence> mRelations; |
280 | DateList mExDates; | 280 | DateList mExDates; |
281 | QPtrList<Attachment> mAttachments; | 281 | QPtrList<Attachment> mAttachments; |
282 | QStringList mResources; | 282 | QStringList mResources; |
283 | bool mHasStartDate; // if todo has associated start date | 283 | bool mHasStartDate; // if todo has associated start date |
284 | 284 | ||
285 | int mSecrecy; | 285 | int mSecrecy; |
286 | int mPriority; // 1 = highest, 2 = less, etc. | 286 | int mPriority; // 1 = highest, 2 = less, etc. |
287 | 287 | ||
288 | //QPtrList<Alarm> mAlarms; | 288 | //QPtrList<Alarm> mAlarms; |
289 | Recurrence *mRecurrence; | 289 | Recurrence *mRecurrence; |
290 | 290 | ||
291 | QString mLocation; | 291 | QString mLocation; |
292 | }; | 292 | }; |
293 | 293 | ||
294 | bool operator==( const Incidence&, const Incidence& ); | 294 | bool operator==( const Incidence&, const Incidence& ); |
295 | 295 | ||
296 | } | 296 | } |
297 | 297 | ||
298 | #endif | 298 | #endif |
diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp index 1769b37..0bc9125 100644 --- a/libkcal/phoneformat.cpp +++ b/libkcal/phoneformat.cpp | |||
@@ -1,1691 +1,581 @@ | |||
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) 2004 Lutz Rogowski <rogowski@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 | |||
49 | class PhoneParser : public QObject | 48 | class PhoneParser : public QObject |
50 | { | 49 | { |
51 | public: | 50 | public: |
52 | PhoneParser( Calendar *calendar, QString profileName ) : mCalendar( calendar ), mProfileName ( profileName ) { | 51 | PhoneParser( ) { |
53 | ; | 52 | ; |
54 | } | 53 | } |
55 | bool readTodo( Calendar *existingCalendar,GSM_ToDoEntry *ToDo, GSM_StateMachine* s) | 54 | |
56 | { | ||
57 | |||
58 | int id = ToDo->Location; | ||
59 | Todo *todo; | ||
60 | todo = existingCalendar->todo( mProfileName ,QString::number( id ) ); | ||
61 | if (todo ) | ||
62 | todo = (Todo *)todo->clone(); | ||
63 | else | ||
64 | todo = new Todo; | ||
65 | todo->setID( mProfileName,QString::number( id ) ); | ||
66 | todo->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL ); | ||
67 | int priority; | ||
68 | switch (ToDo->Priority) { | ||
69 | case GSM_Priority_Low : priority = 5; break; | ||
70 | case GSM_Priority_Medium : priority = 3; break; | ||
71 | case GSM_Priority_High : priority = 1; break; | ||
72 | default :priority = 3 ;break; | ||
73 | } | ||
74 | todo->setPriority( priority ); | ||
75 | GSM_Phone_Functions*Phone; | ||
76 | Phone=s->Phone.Functions; | ||
77 | int j; | ||
78 | GSM_DateTime* dtp; | ||
79 | bool alarm = false; | ||
80 | QDateTime alarmDt; | ||
81 | GSM_Category Category; | ||
82 | int error; | ||
83 | for (j=0;j<ToDo->EntriesNum;j++) { | ||
84 | |||
85 | //qDebug(" for todo %d",ToDo->Location ); | ||
86 | switch (ToDo->Entries[j].EntryType) { | ||
87 | case TODO_END_DATETIME: | ||
88 | dtp = &ToDo->Entries[j].Date ; | ||
89 | todo->setDtDue (fromGSM ( dtp )); | ||
90 | break; | ||
91 | case TODO_COMPLETED: | ||
92 | if ( ToDo->Entries[j].Number == 1 ) { | ||
93 | todo->setCompleted( true ); | ||
94 | } | ||
95 | else { | ||
96 | todo->setCompleted( false ); | ||
97 | } | ||
98 | break; | ||
99 | case TODO_ALARM_DATETIME: | ||
100 | dtp = &ToDo->Entries[j].Date ; | ||
101 | alarm = true; | ||
102 | alarmDt = fromGSM ( dtp ); | ||
103 | break; | ||
104 | case TODO_SILENT_ALARM_DATETIME: | ||
105 | dtp = &ToDo->Entries[j].Date ; | ||
106 | alarm = true; | ||
107 | alarmDt = fromGSM ( dtp ); | ||
108 | break; | ||
109 | case TODO_TEXT: | ||
110 | //qDebug(" text *%s* ", (const char*) DecodeUnicodeConsole(ToDo->Entries[j].Text )); | ||
111 | todo->setSummary( QString::fromUtf8 ( (const char*)DecodeUnicodeConsole(ToDo->Entries[j].Text ))); | ||
112 | break; | ||
113 | case TODO_PRIVATE: | ||
114 | if ( ToDo->Entries[j].Number == 1 ) | ||
115 | todo->setSecrecy( Incidence::SecrecyPrivate ); | ||
116 | else | ||
117 | todo->setSecrecy( Incidence::SecrecyPublic ); | ||
118 | break; | ||
119 | case TODO_CATEGORY: | ||
120 | Category.Location = ToDo->Entries[j].Number; | ||
121 | Category.Type = Category_ToDo; | ||
122 | error=Phone->GetCategory(s, &Category); | ||
123 | if (error == ERR_NONE) { | ||
124 | QStringList cat = todo->categories(); | ||
125 | QString nCat = QString ( (const char*)Category.Name ); | ||
126 | if ( !nCat.isEmpty() ) | ||
127 | if ( !cat.contains( nCat )) { | ||
128 | cat << nCat; | ||
129 | todo->setCategories( cat ); | ||
130 | } | ||
131 | } | ||
132 | break; | ||
133 | case TODO_CONTACTID: | ||
134 | #if 0 | ||
135 | // not supported | ||
136 | entry.Location = ToDo->Entries[j].Number; | ||
137 | entry.MemoryType = MEM_ME; | ||
138 | error=Phone->GetMemory(s, &entry); | ||
139 | if (error == ERR_NONE) { | ||
140 | name = GSM_PhonebookGetEntryName(&entry); | ||
141 | if (name != NULL) { | ||
142 | printmsg("Contact ID : \"%s\" (%d)\n", DecodeUnicodeConsole(name), ToDo->Entries[j].Number); | ||
143 | } else { | ||
144 | printmsg("Contact ID : %d\n",ToDo->Entries[j].Number); | ||
145 | } | ||
146 | } else { | ||
147 | printmsg("Contact : %d\n",ToDo->Entries[j].Number); | ||
148 | } | ||
149 | #endif | ||
150 | break; | ||
151 | case TODO_PHONE: | ||
152 | #if 0 | ||
153 | // not supported | ||
154 | printmsg("Phone : \"%s\"\n",DecodeUnicodeConsole(ToDo->Entries[j].Text)); | ||
155 | #endif | ||
156 | break; | ||
157 | } | ||
158 | } | ||
159 | QString alarmString = "na"; | ||
160 | if ( alarm ) { | ||
161 | Alarm *alarm; | ||
162 | if ( todo->alarms().count() > 0 ) | ||
163 | alarm = todo->alarms().first(); | ||
164 | else { | ||
165 | alarm = new Alarm( todo ); | ||
166 | todo->addAlarm( alarm ); | ||
167 | } | ||
168 | alarm->setType( Alarm::Audio ); | ||
169 | alarm->setEnabled( true ); | ||
170 | int alarmOffset = alarmDt.secsTo( todo->dtStart() ); | ||
171 | alarm->setStartOffset( -alarmOffset ); | ||
172 | alarmString = QString::number( alarmOffset ); | ||
173 | } else { | ||
174 | Alarm *alarm; | ||
175 | if ( todo->alarms().count() > 0 ) { | ||
176 | alarm = todo->alarms().first(); | ||
177 | alarm->setType( Alarm::Audio ); | ||
178 | alarm->setStartOffset( -60*15 ); | ||
179 | alarm->setEnabled( false ); | ||
180 | } | ||
181 | } | ||
182 | // csum ***************************************** | ||
183 | uint cSum; | ||
184 | cSum = PhoneFormat::getCsumTodo( todo ); | ||
185 | todo->setCsum( mProfileName, QString::number( cSum )); | ||
186 | todo->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); | ||
187 | mCalendar->addTodo( todo); | ||
188 | |||
189 | return true; | ||
190 | } | ||
191 | bool readEvent( Calendar *existingCalendar, GSM_CalendarEntry*Note) | ||
192 | { | ||
193 | |||
194 | int id = Note->Location; | ||
195 | Event *event; | ||
196 | event = existingCalendar->event( mProfileName ,QString::number( id ) ); | ||
197 | if ( event ) | ||
198 | event = (Event*)event->clone(); | ||
199 | else | ||
200 | event = new Event; | ||
201 | event->setID( mProfileName,QString::number( id ) ); | ||
202 | event->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL ); | ||
203 | |||
204 | |||
205 | int i = 0; | ||
206 | bool repeating = false; | ||
207 | int repeat_dayofweek = -1; | ||
208 | int repeat_day = -1; | ||
209 | int repeat_weekofmonth = -1; | ||
210 | int repeat_month = -1; | ||
211 | int repeat_frequency = -1; | ||
212 | int rec_type = -1; | ||
213 | GSM_DateTime repeat_startdate = {0,0,0,0,0,0,0}; | ||
214 | GSM_DateTime repeat_stopdate = {0,0,0,0,0,0,0}; | ||
215 | GSM_DateTime* dtp; | ||
216 | bool alarm = false; | ||
217 | QDateTime alarmDt; | ||
218 | repeat_startdate.Day= 0; | ||
219 | repeat_stopdate.Day = 0; | ||
220 | for (i=0;i<Note->EntriesNum;i++) { | ||
221 | |||
222 | //qDebug(" for ev"); | ||
223 | switch (Note->Entries[i].EntryType) { | ||
224 | case CAL_START_DATETIME: | ||
225 | dtp = &Note->Entries[i].Date ; | ||
226 | if ( dtp->Hour > 24 ) { | ||
227 | event->setFloats( true ); | ||
228 | event->setDtStart( QDateTime (datefromGSM ( dtp ), QTime(0,0,0 ))); | ||
229 | } else { | ||
230 | event->setDtStart (fromGSM ( dtp )); | ||
231 | |||
232 | } | ||
233 | //Note->Entries[i].Date.Hour = 5; | ||
234 | break; | ||
235 | case CAL_END_DATETIME: | ||
236 | dtp = &Note->Entries[i].Date ; | ||
237 | if ( dtp->Hour > 24 ) { | ||
238 | event->setFloats( true ); | ||
239 | event->setDtEnd( QDateTime (datefromGSM ( dtp ), QTime(0,0,0 ))); | ||
240 | } else { | ||
241 | event->setDtEnd (fromGSM ( dtp )); | ||
242 | } | ||
243 | break; | ||
244 | case CAL_ALARM_DATETIME: | ||
245 | dtp = &Note->Entries[i].Date ; | ||
246 | alarm = true; | ||
247 | alarmDt = fromGSM ( dtp ); | ||
248 | break; | ||
249 | case CAL_SILENT_ALARM_DATETIME: | ||
250 | dtp = &Note->Entries[i].Date ; | ||
251 | alarm = true; | ||
252 | alarmDt = fromGSM ( dtp ); | ||
253 | break; | ||
254 | case CAL_RECURRANCE: | ||
255 | rec_type = Note->Entries[i].Number; | ||
256 | //printmsg("Repeat : %d day%s\n",Note->Entries[i].Number/24,((Note->Entries[i].Number/24)>1) ? "s":"" ); | ||
257 | break; | ||
258 | case CAL_TEXT: | ||
259 | //qDebug(" ev text %s", DecodeUnicodeConsole(Note->Entries[i].Text) ); | ||
260 | event->setSummary( QString::fromUtf8 ( (const char*)DecodeUnicodeConsole( Note->Entries[i].Text ))); | ||
261 | break; | ||
262 | case CAL_LOCATION: | ||
263 | event->setLocation(QString::fromUtf8 ((const char*) DecodeUnicodeConsole(Note->Entries[i].Text) )); | ||
264 | break; | ||
265 | case CAL_PHONE: | ||
266 | //printmsg("Phone : \"%s\"\n",DecodeUnicodeConsole(Note->Entries[i].Text)); | ||
267 | break; | ||
268 | case CAL_PRIVATE: | ||
269 | if ( Note->Entries[i].Number == 1 ) | ||
270 | event->setSecrecy( Incidence::SecrecyPrivate ); | ||
271 | else | ||
272 | event->setSecrecy( Incidence::SecrecyPublic ); | ||
273 | |||
274 | break; | ||
275 | case CAL_CONTACTID: | ||
276 | #if 0 | ||
277 | entry.Location = Note->Entries[i].Number; | ||
278 | entry.MemoryType = MEM_ME; | ||
279 | error=Phone->GetMemory(&s, &entry); | ||
280 | if (error == ERR_NONE) { | ||
281 | name = GSM_PhonebookGetEntryName(&entry); | ||
282 | if (name != NULL) { | ||
283 | //printmsg("Contact ID : \"%s\" (%d)\n", DecodeUnicodeConsole(name), Note->Entries[i].Number); | ||
284 | } else { | ||
285 | //printmsg("Contact ID : %d\n",Note->Entries[i].Number); | ||
286 | } | ||
287 | } else { | ||
288 | //printmsg("Contact ID : %d\n",Note->Entries[i].Number); | ||
289 | } | ||
290 | #endif | ||
291 | break; | ||
292 | case CAL_REPEAT_DAYOFWEEK: | ||
293 | repeat_dayofweek = Note->Entries[i].Number; | ||
294 | repeating = true; | ||
295 | break; | ||
296 | case CAL_REPEAT_DAY: | ||
297 | repeat_day = Note->Entries[i].Number; | ||
298 | repeating = true; | ||
299 | break; | ||
300 | case CAL_REPEAT_WEEKOFMONTH: | ||
301 | repeat_weekofmonth = Note->Entries[i].Number; | ||
302 | repeating = true; | ||
303 | break; | ||
304 | case CAL_REPEAT_MONTH: | ||
305 | repeat_month = Note->Entries[i].Number; | ||
306 | repeating = true; | ||
307 | break; | ||
308 | case CAL_REPEAT_FREQUENCY: | ||
309 | repeat_frequency = Note->Entries[i].Number; | ||
310 | repeating = true; | ||
311 | break; | ||
312 | case CAL_REPEAT_STARTDATE: | ||
313 | repeat_startdate = Note->Entries[i].Date; | ||
314 | repeating = true; | ||
315 | break; | ||
316 | case CAL_REPEAT_STOPDATE: | ||
317 | repeat_stopdate = Note->Entries[i].Date; | ||
318 | repeating = true; | ||
319 | break; | ||
320 | } | ||
321 | } | ||
322 | #if 0 | ||
323 | event->setDescription( attList[4] ); | ||
324 | bool repeating = false; | ||
325 | int repeat_dayofweek = -1; | ||
326 | int repeat_day = -1; | ||
327 | int repeat_weekofmonth = -1; | ||
328 | int repeat_month = -1; | ||
329 | int repeat_frequency = -1; | ||
330 | GSM_DateTime repeat_startdate = {0,0,0,0,0,0,0}; | ||
331 | GSM_DateTime repeat_stopdate = {0,0,0,0,0,0,0}; | ||
332 | |||
333 | #endif | ||
334 | |||
335 | QString recurString = "no"; | ||
336 | if ( repeating && repeat_frequency != -1) { | ||
337 | recurString = "y"; | ||
338 | if ( repeat_dayofweek >= 0 ) | ||
339 | recurString += "dow" + QString::number (repeat_dayofweek); | ||
340 | if ( repeat_day >= 0 ) | ||
341 | recurString += "d" + QString::number (repeat_day); | ||
342 | if ( repeat_weekofmonth >= 0 ) | ||
343 | recurString += "w" + QString::number (repeat_weekofmonth); | ||
344 | if ( repeat_month >= 0 ) | ||
345 | recurString += "m" + QString::number ( repeat_month ); | ||
346 | if ( repeat_frequency >= 0 ) | ||
347 | recurString += "f" + QString::number (repeat_frequency ); | ||
348 | |||
349 | int rtype = 0; | ||
350 | // qDebug("recurs "); | ||
351 | QDate startDate, endDate; | ||
352 | if ( repeat_startdate.Day > 0 ) { | ||
353 | startDate = datefromGSM ( &repeat_startdate ); | ||
354 | event->setDtStart(QDateTime ( startDate, event->dtStart().time())); | ||
355 | } else { | ||
356 | startDate = event->dtStart().date(); | ||
357 | } | ||
358 | int freq = repeat_frequency; | ||
359 | bool hasEndDate = false; | ||
360 | if ( repeat_stopdate.Day > 0 ) { | ||
361 | endDate = datefromGSM ( &repeat_stopdate ); | ||
362 | hasEndDate = true; | ||
363 | } | ||
364 | |||
365 | uint weekDaysNum = repeat_dayofweek ; | ||
366 | // 1 == monday, 7 == sunday | ||
367 | QBitArray weekDays( 7 ); | ||
368 | int i; | ||
369 | int bb = 1; | ||
370 | for( i = 1; i <= 7; ++i ) { | ||
371 | weekDays.setBit( i - 1, ( bb & weekDaysNum )); | ||
372 | bb = 2 << (i-1); | ||
373 | //qDebug(" %d bit %d ",i-1,weekDays.at(i-1) ); | ||
374 | } | ||
375 | // qDebug("next "); | ||
376 | int pos = 0; | ||
377 | Recurrence *r = event->recurrence(); | ||
378 | /* | ||
379 | 0 daily; | ||
380 | 1 weekly;x | ||
381 | 2 monthpos;x | ||
382 | 3 monthlyday; | ||
383 | 4 rYearlyMont | ||
384 | bool repeating = false; | ||
385 | int repeat_dayofweek = -1; | ||
386 | int repeat_day = -1; | ||
387 | int repeat_weekofmonth = -1; | ||
388 | int repeat_month = -1; | ||
389 | int repeat_frequency = -1; | ||
390 | */ | ||
391 | int dayOfWeek = startDate.dayOfWeek(); | ||
392 | if ( repeat_weekofmonth >= 0 ) { | ||
393 | rtype = 2; // ************************ 2 MonthlyPos | ||
394 | pos = repeat_weekofmonth; | ||
395 | if ( repeat_dayofweek >= 0 ) | ||
396 | dayOfWeek = repeat_dayofweek; | ||
397 | if (repeat_month > 0) { | ||
398 | if ( repeat_month != event->dtStart().date().month() ) { | ||
399 | QDate date (event->dtStart().date().year(),repeat_month,event->dtStart().date().day() ); | ||
400 | event->setDtStart(QDateTime ( date , event->dtStart().time()) ); | ||
401 | } | ||
402 | if ( freq == 1 ) | ||
403 | freq = 12; | ||
404 | } | ||
405 | } else if ( repeat_dayofweek >= 0 ) { | ||
406 | rtype = 1;// ************************ 1 Weekly | ||
407 | } else if ( repeat_day >= 0 ) { | ||
408 | if ( repeat_month > 0) { | ||
409 | rtype = 4; | ||
410 | } else { | ||
411 | rtype = 3; | ||
412 | } | ||
413 | } else { | ||
414 | rtype = 0 ; | ||
415 | } | ||
416 | |||
417 | if ( rtype == 0 ) { | ||
418 | if ( hasEndDate ) r->setDaily( freq, endDate ); | ||
419 | else r->setDaily( freq, -1 ); | ||
420 | } else if ( rtype == 1 ) { | ||
421 | if ( hasEndDate ) r->setWeekly( freq, weekDays, endDate ); | ||
422 | else r->setWeekly( freq, weekDays, -1 ); | ||
423 | } else if ( rtype == 3 ) { | ||
424 | if ( hasEndDate ) | ||
425 | r->setMonthly( Recurrence::rMonthlyDay, freq, endDate ); | ||
426 | else | ||
427 | r->setMonthly( Recurrence::rMonthlyDay, freq, -1 ); | ||
428 | r->addMonthlyDay( startDate.day() ); | ||
429 | } else if ( rtype == 2 ) { | ||
430 | if ( hasEndDate ) | ||
431 | r->setMonthly( Recurrence::rMonthlyPos, freq, endDate ); | ||
432 | else | ||
433 | r->setMonthly( Recurrence::rMonthlyPos, freq, -1 ); | ||
434 | QBitArray days( 7 ); | ||
435 | days.fill( false ); | ||
436 | days.setBit( dayOfWeek - 1 ); | ||
437 | r->addMonthlyPos( pos, days ); | ||
438 | } else if ( rtype == 4 ) { | ||
439 | if ( hasEndDate ) | ||
440 | r->setYearly( Recurrence::rYearlyMonth, freq, endDate ); | ||
441 | else | ||
442 | r->setYearly( Recurrence::rYearlyMonth, freq, -1 ); | ||
443 | r->addYearlyNum( startDate.month() ); | ||
444 | } | ||
445 | } else { | ||
446 | event->recurrence()->unsetRecurs(); | ||
447 | } | ||
448 | |||
449 | QStringList cat = event->categories(); | ||
450 | QString nCat = getCategory( Note ); | ||
451 | |||
452 | if ( !nCat.isEmpty() ) | ||
453 | if ( !cat.contains( nCat )) { | ||
454 | cat << nCat; | ||
455 | event->setCategories( cat ); | ||
456 | } | ||
457 | |||
458 | if ( alarm ) { | ||
459 | Alarm *alarm; | ||
460 | if ( event->alarms().count() > 0 ) | ||
461 | alarm = event->alarms().first(); | ||
462 | else { | ||
463 | alarm = new Alarm( event ); | ||
464 | event->addAlarm( alarm ); | ||
465 | } | ||
466 | alarm->setType( Alarm::Audio ); | ||
467 | alarm->setEnabled( true ); | ||
468 | int alarmOffset = alarmDt.secsTo( event->dtStart() ); | ||
469 | alarm->setStartOffset( -alarmOffset ); | ||
470 | } else { | ||
471 | Alarm *alarm; | ||
472 | if ( event->alarms().count() > 0 ) { | ||
473 | alarm = event->alarms().first(); | ||
474 | alarm->setType( Alarm::Audio ); | ||
475 | alarm->setStartOffset( -60*15 ); | ||
476 | alarm->setEnabled( false ); | ||
477 | } | ||
478 | } | ||
479 | // csum ***************************************** | ||
480 | |||
481 | uint cSum; | ||
482 | cSum = PhoneFormat::getCsumEvent( event ); | ||
483 | event->setCsum( mProfileName, QString::number( cSum )); | ||
484 | event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); | ||
485 | mCalendar->addEvent( event); | ||
486 | |||
487 | return true; | ||
488 | } | ||
489 | |||
490 | |||
491 | QDateTime fromGSM ( GSM_DateTime*dtp, bool useTz = false ) { | ||
492 | QDateTime dt; | ||
493 | int y,m,t,h,min,sec; | ||
494 | y = dtp->Year; | ||
495 | m = dtp->Month; | ||
496 | t = dtp->Day; | ||
497 | h = dtp->Hour; | ||
498 | min = dtp->Minute; | ||
499 | sec = dtp->Second; | ||
500 | dt = QDateTime(QDate(y,m,t), QTime(h,min,sec)); | ||
501 | // dtp->Timezone: offset in hours | ||
502 | int offset = KGlobal::locale()->localTimeOffset( dt ); | ||
503 | if ( useTz ) | ||
504 | dt = dt.addSecs ( offset*60); | ||
505 | return dt; | ||
506 | |||
507 | } | ||
508 | |||
509 | static QString dtToString( const QDateTime& dti, bool useTZ = false ) | 55 | static QString dtToString( const QDateTime& dti, bool useTZ = false ) |
510 | { | 56 | { |
511 | QString datestr; | 57 | QString datestr; |
512 | QString timestr; | 58 | QString timestr; |
513 | int offset = KGlobal::locale()->localTimeOffset( dti ); | 59 | int offset = KGlobal::locale()->localTimeOffset( dti ); |
514 | QDateTime dt; | 60 | QDateTime dt; |
515 | if (useTZ) | 61 | if (useTZ) |
516 | dt = dti.addSecs ( -(offset*60)); | 62 | dt = dti.addSecs ( -(offset*60)); |
517 | else | 63 | else |
518 | dt = dti; | 64 | dt = dti; |
519 | if(dt.date().isValid()){ | 65 | if(dt.date().isValid()){ |
520 | const QDate& date = dt.date(); | 66 | const QDate& date = dt.date(); |
521 | datestr.sprintf("%04d%02d%02d", | 67 | datestr.sprintf("%04d%02d%02d", |
522 | date.year(), date.month(), date.day()); | 68 | date.year(), date.month(), date.day()); |
523 | } | 69 | } |
524 | if(dt.time().isValid()){ | 70 | if(dt.time().isValid()){ |
525 | const QTime& time = dt.time(); | 71 | const QTime& time = dt.time(); |
526 | timestr.sprintf("T%02d%02d%02d", | 72 | timestr.sprintf("T%02d%02d%02d", |
527 | time.hour(), time.minute(), time.second()); | 73 | time.hour(), time.minute(), time.second()); |
528 | } | 74 | } |
529 | return datestr + timestr; | 75 | return datestr + timestr; |
530 | } | 76 | } |
531 | QDate datefromGSM ( GSM_DateTime*dtp ) { | ||
532 | return QDate ( dtp->Year, dtp->Month, dtp->Day ); | ||
533 | } | ||
534 | QString getCategory( GSM_CalendarEntry*Note) | ||
535 | { | ||
536 | QString CATEGORY; | ||
537 | switch (Note->Type) { | ||
538 | case GSM_CAL_REMINDER : CATEGORY = QString("Reminder"); break; | ||
539 | case GSM_CAL_CALL : CATEGORY = QString("Call"); break; | ||
540 | //case GSM_CAL_MEETING : CATEGORY = QString("Meeting"); break; | ||
541 | case GSM_CAL_BIRTHDAY : CATEGORY = QString("Birthday"); break; | ||
542 | case GSM_CAL_MEMO : CATEGORY = QString("Memo"); break; | ||
543 | case GSM_CAL_TRAVEL : CATEGORY = QString("Travel"); break; | ||
544 | case GSM_CAL_VACATION : CATEGORY = QString("Vacation"); break; | ||
545 | case GSM_CAL_ALARM : CATEGORY = QString("Alarm"); break; | ||
546 | case GSM_CAL_DAILY_ALARM : CATEGORY = QString("Daily alarm"); break; | ||
547 | case GSM_CAL_T_ATHL : CATEGORY = QString("Training/Athletism"); break; | ||
548 | case GSM_CAL_T_BALL : CATEGORY = QString("Training/Ball Games"); break; | ||
549 | case GSM_CAL_T_CYCL : CATEGORY = QString("Training/Cycling"); break; | ||
550 | case GSM_CAL_T_BUDO : CATEGORY = QString("Training/Budo"); break; | ||
551 | case GSM_CAL_T_DANC : CATEGORY = QString("Training/Dance"); break; | ||
552 | case GSM_CAL_T_EXTR : CATEGORY = QString("Training/Extreme Sports"); break; | ||
553 | case GSM_CAL_T_FOOT : CATEGORY = QString("Training/Football"); break; | ||
554 | case GSM_CAL_T_GOLF : CATEGORY = QString("Training/Golf"); break; | ||
555 | case GSM_CAL_T_GYM : CATEGORY = QString("Training/Gym"); break; | ||
556 | case GSM_CAL_T_HORS : CATEGORY = QString("Training/Horse Races"); break; | ||
557 | case GSM_CAL_T_HOCK : CATEGORY = QString("Training/Hockey"); break; | ||
558 | case GSM_CAL_T_RACE : CATEGORY = QString("Training/Races"); break; | ||
559 | case GSM_CAL_T_RUGB : CATEGORY = QString("Training/Rugby"); break; | ||
560 | case GSM_CAL_T_SAIL : CATEGORY = QString("Training/Sailing"); break; | ||
561 | case GSM_CAL_T_STRE : CATEGORY = QString("Training/Street Games"); break; | ||
562 | case GSM_CAL_T_SWIM : CATEGORY = QString("Training/Swimming"); break; | ||
563 | case GSM_CAL_T_TENN : CATEGORY = QString("Training/Tennis"); break; | ||
564 | case GSM_CAL_T_TRAV : CATEGORY = QString("Training/Travels"); break; | ||
565 | case GSM_CAL_T_WINT : CATEGORY = QString("Training/Winter Games"); break; | ||
566 | default : CATEGORY = QString(""); | ||
567 | } | ||
568 | 77 | ||
569 | return CATEGORY; | ||
570 | } | ||
571 | 78 | ||
572 | protected: | ||
573 | private: | ||
574 | Calendar *mCalendar; | ||
575 | QString mProfileName ; | ||
576 | }; | 79 | }; |
577 | 80 | ||
81 | |||
578 | 82 | ||
579 | PhoneFormat::PhoneFormat(QString profileName, QString device,QString connection, QString model ) | 83 | PhoneFormat::PhoneFormat(QString profileName, QString device,QString connection, QString model ) |
580 | { | 84 | { |
581 | mProfileName = profileName; | 85 | mProfileName = profileName; |
582 | mDevice = device; | 86 | mDevice = device; |
583 | mConnection = connection; | 87 | mConnection = connection; |
584 | mModel = model; | 88 | mModel = model; |
585 | } | 89 | } |
586 | 90 | ||
587 | PhoneFormat::~PhoneFormat() | 91 | PhoneFormat::~PhoneFormat() |
588 | { | 92 | { |
589 | } | 93 | } |
94 | #if 0 | ||
590 | int PhoneFormat::initDevice(GSM_StateMachine *s) | 95 | int PhoneFormat::initDevice(GSM_StateMachine *s) |
591 | { | 96 | { |
592 | GSM_ReadConfig(NULL, &s->Config[0], 0); | 97 | GSM_ReadConfig(NULL, &s->Config[0], 0); |
593 | s->ConfigNum = 1; | 98 | s->ConfigNum = 1; |
594 | GSM_Config *cfg = &s->Config[0]; | 99 | GSM_Config *cfg = &s->Config[0]; |
595 | if ( ! mConnection.isEmpty() ) { | 100 | if ( ! mConnection.isEmpty() ) { |
596 | cfg->Connection = strdup(mConnection.latin1()); | 101 | cfg->Connection = strdup(mConnection.latin1()); |
597 | cfg->DefaultConnection = false; | 102 | cfg->DefaultConnection = false; |
598 | qDebug("Connection set %s ", cfg->Connection ); | 103 | qDebug("Connection set %s ", cfg->Connection ); |
599 | 104 | ||
600 | } | 105 | } |
601 | if ( ! mDevice.isEmpty() ) { | 106 | if ( ! mDevice.isEmpty() ) { |
602 | cfg->Device = strdup(mDevice.latin1()); | 107 | cfg->Device = strdup(mDevice.latin1()); |
603 | cfg->DefaultDevice = false; | 108 | cfg->DefaultDevice = false; |
604 | qDebug("Device set %s ", cfg->Device); | 109 | qDebug("Device set %s ", cfg->Device); |
605 | 110 | ||
606 | } | 111 | } |
607 | if ( ! mModel.isEmpty() ) { | 112 | if ( ! mModel.isEmpty() ) { |
608 | strcpy(cfg->Model,mModel.latin1() ); | 113 | strcpy(cfg->Model,mModel.latin1() ); |
609 | cfg->DefaultModel = false; | 114 | cfg->DefaultModel = false; |
610 | qDebug("Model set %s ",cfg->Model ); | 115 | qDebug("Model set %s ",cfg->Model ); |
611 | } | 116 | } |
612 | int error=GSM_InitConnection(s,3); | 117 | int error=GSM_InitConnection(s,3); |
613 | return error; | 118 | return error; |
614 | } | 119 | } |
120 | #endif | ||
615 | ulong PhoneFormat::getCsumTodo( Todo* todo ) | 121 | ulong PhoneFormat::getCsumTodo( Todo* todo ) |
616 | { | 122 | { |
617 | QStringList attList; | 123 | QStringList attList; |
618 | if ( todo->hasDueDate() ) | 124 | if ( todo->hasDueDate() ) |
619 | attList << PhoneParser::dtToString ( todo->dtDue() ); | 125 | attList << PhoneParser::dtToString ( todo->dtDue() ); |
620 | attList << todo->summary(); | 126 | attList << todo->summary(); |
621 | QString completedString = "no"; | 127 | QString completedString = "no"; |
622 | if ( todo->isCompleted() ) | 128 | if ( todo->isCompleted() ) |
623 | completedString = "yes"; | 129 | completedString = "yes"; |
624 | attList << completedString; | 130 | attList << completedString; |
625 | attList << QString::number( todo->priority() ); | 131 | attList << QString::number( todo->priority() ); |
626 | QString alarmString = "na"; | 132 | QString alarmString = "na"; |
627 | Alarm *alarm; | 133 | Alarm *alarm; |
628 | if ( todo->alarms().count() > 0 ) { | 134 | if ( todo->alarms().count() > 0 ) { |
629 | alarm = todo->alarms().first(); | 135 | alarm = todo->alarms().first(); |
630 | if ( alarm->enabled() ) { | 136 | if ( alarm->enabled() ) { |
631 | alarmString = QString::number(alarm->startOffset().asSeconds() ); | 137 | alarmString = QString::number(alarm->startOffset().asSeconds() ); |
632 | } | 138 | } |
633 | } | 139 | } |
634 | attList << alarmString; | 140 | attList << alarmString; |
635 | attList << todo->categoriesStr(); | 141 | attList << todo->categoriesStr(); |
636 | attList << todo->secrecyStr(); | 142 | attList << todo->secrecyStr(); |
637 | return PhoneFormat::getCsum(attList ); | 143 | return PhoneFormat::getCsum(attList ); |
638 | 144 | ||
639 | } | 145 | } |
640 | ulong PhoneFormat::getCsumEvent( Event* event ) | 146 | ulong PhoneFormat::getCsumEvent( Event* event ) |
641 | { | 147 | { |
642 | QStringList attList; | 148 | QStringList attList; |
643 | attList << PhoneParser::dtToString ( event->dtStart() ); | 149 | attList << PhoneParser::dtToString ( event->dtStart() ); |
644 | attList << PhoneParser::dtToString ( event->dtEnd() ); | 150 | attList << PhoneParser::dtToString ( event->dtEnd() ); |
645 | attList << event->summary(); | 151 | attList << event->summary(); |
646 | attList << event->location(); | 152 | attList << event->location(); |
647 | QString alarmString = "na"; | 153 | QString alarmString = "na"; |
648 | Alarm *alarm; | 154 | Alarm *alarm; |
649 | if ( event->alarms().count() > 0 ) { | 155 | if ( event->alarms().count() > 0 ) { |
650 | alarm = event->alarms().first(); | 156 | alarm = event->alarms().first(); |
651 | if ( alarm->enabled() ) { | 157 | if ( alarm->enabled() ) { |
652 | alarmString = QString::number( alarm->startOffset().asSeconds() ); | 158 | alarmString = QString::number( alarm->startOffset().asSeconds() ); |
653 | } | 159 | } |
654 | } | 160 | } |
655 | attList << alarmString; | 161 | attList << alarmString; |
656 | Recurrence* rec = event->recurrence(); | 162 | Recurrence* rec = event->recurrence(); |
657 | QStringList list; | 163 | QStringList list; |
658 | bool writeEndDate = false; | 164 | bool writeEndDate = false; |
659 | switch ( rec->doesRecur() ) | 165 | switch ( rec->doesRecur() ) |
660 | { | 166 | { |
661 | case Recurrence::rDaily: // 0 | 167 | case Recurrence::rDaily: // 0 |
662 | list.append( "0" ); | 168 | list.append( "0" ); |
663 | list.append( QString::number( rec->frequency() ));//12 | 169 | list.append( QString::number( rec->frequency() ));//12 |
664 | list.append( "0" ); | 170 | list.append( "0" ); |
665 | list.append( "0" ); | 171 | list.append( "0" ); |
666 | writeEndDate = true; | 172 | writeEndDate = true; |
667 | break; | 173 | break; |
668 | case Recurrence::rWeekly:// 1 | 174 | case Recurrence::rWeekly:// 1 |
669 | list.append( "1" ); | 175 | list.append( "1" ); |
670 | list.append( QString::number( rec->frequency()) );//12 | 176 | list.append( QString::number( rec->frequency()) );//12 |
671 | list.append( "0" ); | 177 | list.append( "0" ); |
672 | { | 178 | { |
673 | int days = 0; | 179 | int days = 0; |
674 | QBitArray weekDays = rec->days(); | 180 | QBitArray weekDays = rec->days(); |
675 | int i; | 181 | int i; |
676 | for( i = 1; i <= 7; ++i ) { | 182 | for( i = 1; i <= 7; ++i ) { |
677 | if ( weekDays[i-1] ) { | 183 | if ( weekDays[i-1] ) { |
678 | days += 1 << (i-1); | 184 | days += 1 << (i-1); |
679 | } | 185 | } |
680 | } | 186 | } |
681 | list.append( QString::number( days ) ); | 187 | list.append( QString::number( days ) ); |
682 | } | 188 | } |
683 | //pending weekdays | 189 | //pending weekdays |
684 | writeEndDate = true; | 190 | writeEndDate = true; |
685 | 191 | ||
686 | break; | 192 | break; |
687 | case Recurrence::rMonthlyPos:// 2 | 193 | case Recurrence::rMonthlyPos:// 2 |
688 | list.append( "2" ); | 194 | list.append( "2" ); |
689 | list.append( QString::number( rec->frequency()) );//12 | 195 | list.append( QString::number( rec->frequency()) );//12 |
690 | 196 | ||
691 | writeEndDate = true; | 197 | writeEndDate = true; |
692 | { | 198 | { |
693 | int count = 1; | 199 | int count = 1; |
694 | QPtrList<Recurrence::rMonthPos> rmp; | 200 | QPtrList<Recurrence::rMonthPos> rmp; |
695 | rmp = rec->monthPositions(); | 201 | rmp = rec->monthPositions(); |
696 | if ( rmp.first()->negative ) | 202 | if ( rmp.first()->negative ) |
697 | count = 5 - rmp.first()->rPos - 1; | 203 | count = 5 - rmp.first()->rPos - 1; |
698 | else | 204 | else |
699 | count = rmp.first()->rPos - 1; | 205 | count = rmp.first()->rPos - 1; |
700 | list.append( QString::number( count ) ); | 206 | list.append( QString::number( count ) ); |
701 | 207 | ||
702 | } | 208 | } |
703 | 209 | ||
704 | list.append( "0" ); | 210 | list.append( "0" ); |
705 | break; | 211 | break; |
706 | case Recurrence::rMonthlyDay:// 3 | 212 | case Recurrence::rMonthlyDay:// 3 |
707 | list.append( "3" ); | 213 | list.append( "3" ); |
708 | list.append( QString::number( rec->frequency()) );//12 | 214 | list.append( QString::number( rec->frequency()) );//12 |
709 | list.append( "0" ); | 215 | list.append( "0" ); |
710 | list.append( "0" ); | 216 | list.append( "0" ); |
711 | writeEndDate = true; | 217 | writeEndDate = true; |
712 | break; | 218 | break; |
713 | case Recurrence::rYearlyMonth://4 | 219 | case Recurrence::rYearlyMonth://4 |
714 | list.append( "4" ); | 220 | list.append( "4" ); |
715 | list.append( QString::number( rec->frequency()) );//12 | 221 | list.append( QString::number( rec->frequency()) );//12 |
716 | list.append( "0" ); | 222 | list.append( "0" ); |
717 | list.append( "0" ); | 223 | list.append( "0" ); |
718 | writeEndDate = true; | 224 | writeEndDate = true; |
719 | break; | 225 | break; |
720 | 226 | ||
721 | default: | 227 | default: |
722 | list.append( "255" ); | 228 | list.append( "255" ); |
723 | list.append( QString() ); | 229 | list.append( QString() ); |
724 | list.append( "0" ); | 230 | list.append( "0" ); |
725 | list.append( QString() ); | 231 | list.append( QString() ); |
726 | list.append( "0" ); | 232 | list.append( "0" ); |
727 | list.append( "20991231T000000" ); | 233 | list.append( "20991231T000000" ); |
728 | break; | 234 | break; |
729 | } | 235 | } |
730 | if ( writeEndDate ) { | 236 | if ( writeEndDate ) { |
731 | 237 | ||
732 | if ( rec->endDate().isValid() ) { // 15 + 16 | 238 | if ( rec->endDate().isValid() ) { // 15 + 16 |
733 | list.append( "1" ); | 239 | list.append( "1" ); |
734 | list.append( PhoneParser::dtToString( rec->endDate()) ); | 240 | list.append( PhoneParser::dtToString( rec->endDate()) ); |
735 | } else { | 241 | } else { |
736 | list.append( "0" ); | 242 | list.append( "0" ); |
737 | list.append( "20991231T000000" ); | 243 | list.append( "20991231T000000" ); |
738 | } | 244 | } |
739 | 245 | ||
740 | } | 246 | } |
741 | attList << list.join(""); | 247 | attList << list.join(""); |
742 | attList << event->categoriesStr(); | 248 | attList << event->categoriesStr(); |
743 | attList << event->secrecyStr(); | 249 | attList << event->secrecyStr(); |
744 | return PhoneFormat::getCsum(attList ); | 250 | return PhoneFormat::getCsum(attList ); |
745 | } | 251 | } |
746 | ulong PhoneFormat::getCsum( const QStringList & attList) | 252 | ulong PhoneFormat::getCsum( const QStringList & attList) |
747 | { | 253 | { |
748 | int max = attList.count() -1; | 254 | int max = attList.count() -1; |
749 | ulong cSum = 0; | 255 | ulong cSum = 0; |
750 | int j,k,i; | 256 | int j,k,i; |
751 | int add; | 257 | int add; |
752 | for ( i = 1; i < max ; ++i ) { | 258 | for ( i = 1; i < max ; ++i ) { |
753 | QString s = attList[i]; | 259 | QString s = attList[i]; |
754 | if ( ! s.isEmpty() ){ | 260 | if ( ! s.isEmpty() ){ |
755 | j = s.length(); | 261 | j = s.length(); |
756 | for ( k = 0; k < j; ++k ) { | 262 | for ( k = 0; k < j; ++k ) { |
757 | int mul = k +1; | 263 | int mul = k +1; |
758 | add = s[k].unicode (); | 264 | add = s[k].unicode (); |
759 | if ( k < 16 ) | 265 | if ( k < 16 ) |
760 | mul = mul * mul; | 266 | mul = mul * mul; |
761 | add = add * mul *i*i*i; | 267 | add = add * mul *i*i*i; |
762 | cSum += add; | 268 | cSum += add; |
763 | } | 269 | } |
764 | } | 270 | } |
765 | } | 271 | } |
766 | return cSum; | 272 | return cSum; |
767 | 273 | ||
768 | } | 274 | } |
769 | //extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum); | 275 | //extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum); |
770 | #include <stdlib.h> | 276 | #include <stdlib.h> |
771 | #define DEBUGMODE false | 277 | #define DEBUGMODE false |
772 | bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal) | 278 | bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal) |
773 | { | 279 | { |
774 | GSM_StateMachines; | ||
775 | qDebug(" load "); | ||
776 | s.opened = false; | ||
777 | s.msg = NULL; | ||
778 | s.ConfigNum = 0; | ||
779 | QLabel status ( i18n("Opening device ..."), 0 ); | ||
780 | int w = status.sizeHint().width()+20 ; | ||
781 | if ( w < 200 ) w = 230; | ||
782 | int h = status.sizeHint().height()+20 ; | ||
783 | int dw = QApplication::desktop()->width(); | ||
784 | int dh = QApplication::desktop()->height(); | ||
785 | status.setCaption(i18n("Reading phone...") ); | ||
786 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | ||
787 | status.show(); | ||
788 | status.raise(); | ||
789 | qApp->processEvents(); | ||
790 | 280 | ||
791 | int error=initDevice(&s); | 281 | QString fileName; |
792 | qDebug("GSM Init %d (no error is %d)", error, ERR_NONE); | 282 | #ifdef _WIN32_ |
793 | if ( error != ERR_NONE ) | 283 | fileName = locateLocal("data", "korganizer") + "\\tempfile.vcs"; |
284 | #else | ||
285 | fileName = "/tmp/kdepimtemp.vcs"; | ||
286 | #endif | ||
287 | QString command ="./kammu --backup " + fileName + " -yes"; | ||
288 | int ret = system ( command.latin1() ); | ||
289 | if ( ret != 0 ) | ||
794 | return false; | 290 | return false; |
795 | GSM_Phone_Functions*Phone; | 291 | VCalFormat vfload; |
796 | GSM_CalendarEntrynote; | 292 | vfload.setLocalTime ( true ); |
797 | bool start = true; | 293 | if ( ! vfload.load( calendar, fileName ) ) |
798 | Phone=s.Phone.Functions; | 294 | return false; |
799 | bool gshutdown = false; | 295 | QPtrList<Event> er = calendar->rawEvents(); |
800 | PhoneParser handler( calendar, mProfileName ); | 296 | Event* ev = er.first(); |
801 | int ccc = 0; | 297 | while ( ev ) { |
802 | QString message = i18n(" Reading event # "); | 298 | int id = ev->pilotId(); |
803 | int procCount = 0; | 299 | Event *event; |
804 | qDebug("Debug: only 10 calender items are downloaded "); | 300 | event = existingCal->event( mProfileName ,QString::number( id ) ); |
805 | while (!gshutdown && ccc++ < 10) { | 301 | if ( event ) { |
806 | status.setText ( message + QString::number ( ++procCount ) ); | 302 | event = (Event*)event->clone(); |
807 | qApp->processEvents(); | 303 | copyEvent( event, ev ); |
808 | qDebug("readEvent %d ", ccc); | 304 | calendar->deleteEvent( ev ); |
809 | error=Phone->GetNextCalendar(&s,¬e,start); | 305 | calendar->addEvent( event); |
810 | if (error == ERR_EMPTY) break; | 306 | } |
811 | start = false; | 307 | else |
812 | handler.readEvent( existingCal, ¬e ); | 308 | event = ev; |
813 | qDebug("Org loc %d ",note.Location); | 309 | uint cSum; |
814 | //note.Location = 0; | 310 | cSum = PhoneFormat::getCsumEvent( event ); |
815 | error=Phone->SetCalendar(&s,¬e); | 311 | event->setCsum( mProfileName, QString::number( cSum )); |
816 | qDebug("new loc %d ",note.Location); | 312 | event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); |
313 | event->setID( mProfileName,QString::number( id ) ); | ||
314 | ev = er.next(); | ||
315 | } | ||
316 | { | ||
317 | QPtrList<Todo> tr = calendar->rawTodos(); | ||
318 | Todo* ev = tr.first(); | ||
319 | while ( ev ) { | ||
320 | |||
321 | QStringList cat = ev->categories(); | ||
322 | if ( cat.contains( "MeetingDEF" )) { | ||
323 | ev->setCategories( QStringList() ); | ||
324 | } | ||
325 | int id = ev->pilotId(); | ||
326 | Todo *event; | ||
327 | event = existingCal->todo( mProfileName ,QString::number( id ) ); | ||
328 | if ( event ) { | ||
329 | event = (Todo*)event->clone(); | ||
330 | copyTodo( event, ev ); | ||
331 | calendar->deleteTodo( ev ); | ||
332 | calendar->addTodo( event); | ||
333 | } | ||
334 | else | ||
335 | event = ev; | ||
336 | uint cSum; | ||
337 | cSum = PhoneFormat::getCsumTodo( event ); | ||
338 | event->setCsum( mProfileName, QString::number( cSum )); | ||
339 | event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); | ||
340 | event->setID( mProfileName,QString::number( id ) ); | ||
341 | ev = tr.next(); | ||
342 | } | ||
817 | } | 343 | } |
818 | |||
819 | start = true; | ||
820 | GSM_ToDoEntry ToDo; | ||
821 | ccc = 0; | ||
822 | message = i18n(" Reading todo # "); | ||
823 | procCount = 0; | ||
824 | while (!gshutdown && ccc++ < 10) { | ||
825 | status.setText ( message + QString::number ( ++procCount ) ); | ||
826 | qApp->processEvents(); | ||
827 | error = Phone->GetNextToDo(&s, &ToDo, start); | ||
828 | if (error == ERR_EMPTY) break; | ||
829 | start = false; | ||
830 | qDebug("ReadTodo %d ", ccc); | ||
831 | handler.readTodo( existingCal, &ToDo, &s); | ||
832 | |||
833 | } | ||
834 | |||
835 | error=GSM_TerminateConnection(&s); | ||
836 | |||
837 | return true; | 344 | return true; |
838 | } | 345 | } |
839 | #include <qcstring.h> | 346 | void PhoneFormat::copyEvent( Event* to, Event* from ) |
840 | void PhoneFormat::event2GSM( Calendar *cal,Event* ev, GSM_CalendarEntry*Note ) | ||
841 | { | 347 | { |
842 | QString eText = vfconverter.eventToString( ev, cal ); | 348 | if ( from->dtStart().isValid() ) |
843 | int pos = 0; | 349 | to->setDtStart( from->dtStart() ); |
844 | GSM_ToDoEntry dummy; | 350 | if ( from->dtEnd().isValid() ) |
845 | qDebug( "Convert event"); | 351 | to->setDtEnd( from->dtEnd() ); |
846 | QByteArray ba; | 352 | if ( !from->location().isEmpty() ) |
847 | QDataStream s ( ba, IO_WriteOnly ); | 353 | to->setLocation( from->location() ); |
848 | s << eText.utf8(); | 354 | if ( !from->description().isEmpty() ) |
849 | GSM_DecodeVCALENDAR_VTODO( (unsigned char*) ba.data(), &pos, Note , &dummy, Nokia_VCalendar, Nokia_VToDo ); | 355 | to->setDescription( from->description() ); |
850 | qDebug( "Convert event done"); | 356 | if ( !from->summary().isEmpty() ) |
851 | Note->Location = 0; | 357 | to->setSummary( from->summary() ); |
852 | QString loc = ev->getID(mProfileName); | 358 | |
853 | if ( !loc.isEmpty() ){ | 359 | QPtrListIterator<Alarm> it( from->alarms() ); |
854 | Note->Location = loc.toInt(); | 360 | to->clearAlarms(); |
361 | const Alarm *a; | ||
362 | while( (a = it.current()) ) { | ||
363 | Alarm *b = new Alarm( *a ); | ||
364 | b->setParent( to ); | ||
365 | to->addAlarm( b ); | ||
366 | ++it; | ||
367 | } | ||
368 | QStringList cat = to->categories(); | ||
369 | QStringList catFrom = from->categories(); | ||
370 | QString nCat; | ||
371 | int iii; | ||
372 | for ( iii = 0; iii < catFrom.count();++iii ) { | ||
373 | nCat = catFrom[iii]; | ||
374 | if ( !nCat.isEmpty() ) | ||
375 | if ( !cat.contains( nCat )) { | ||
376 | cat << nCat; | ||
377 | } | ||
855 | } | 378 | } |
379 | to->setCategories( cat ); | ||
380 | Recurrence * r = new Recurrence( *from->recurrence(),to); | ||
381 | to->setRecurrence( r ) ; | ||
382 | |||
856 | 383 | ||
857 | } | 384 | } |
858 | void PhoneFormat::todo2GSM( Calendar *cal, Todo* todo, GSM_ToDoEntry *gsmTodo ) | 385 | void PhoneFormat::copyTodo( Todo* to, Todo* from ) |
859 | { | 386 | { |
860 | qDebug( "Convert todo1"); | 387 | if ( from->dtStart().isValid() ) |
861 | QString tText = vfconverter.todoToString( todo, cal ); | 388 | to->setDtStart( from->dtStart() ); |
862 | int pos = 0; | 389 | if ( from->dtDue().isValid() ) |
863 | GSM_CalendarEntry dummy; | 390 | to->setDtDue( from->dtDue() ); |
864 | QByteArray ba; | 391 | if ( !from->location().isEmpty() ) |
865 | QDataStream s ( ba, IO_WriteOnly ); | 392 | to->setLocation( from->location() ); |
866 | s << tText.utf8(); | 393 | if ( !from->description().isEmpty() ) |
867 | GSM_DecodeVCALENDAR_VTODO( (unsigned char*) ba.data(), &pos, &dummy, gsmTodo, Nokia_VCalendar, Nokia_VToDo ); | 394 | to->setDescription( from->description() ); |
868 | qDebug( "Convert todo done "); | 395 | if ( !from->summary().isEmpty() ) |
869 | gsmTodo->Location = 0; | 396 | to->setSummary( from->summary() ); |
870 | QString loc = todo->getID(mProfileName); | 397 | |
871 | if ( !loc.isEmpty() ){ | 398 | QPtrListIterator<Alarm> it( from->alarms() ); |
872 | gsmTodo->Location = loc.toInt(); | 399 | to->clearAlarms(); |
400 | const Alarm *a; | ||
401 | while( (a = it.current()) ) { | ||
402 | Alarm *b = new Alarm( *a ); | ||
403 | b->setParent( to ); | ||
404 | to->addAlarm( b ); | ||
405 | ++it; | ||
406 | } | ||
407 | QStringList cat = to->categories(); | ||
408 | QStringList catFrom = from->categories(); | ||
409 | QString nCat; | ||
410 | int iii; | ||
411 | for ( iii = 0; iii < catFrom.count();++iii ) { | ||
412 | nCat = catFrom[iii]; | ||
413 | if ( !nCat.isEmpty() ) | ||
414 | if ( !cat.contains( nCat )) { | ||
415 | cat << nCat; | ||
416 | } | ||
873 | } | 417 | } |
874 | 418 | to->setCategories( cat ); | |
419 | if ( from->isCompleted() ) { | ||
420 | to->setCompleted( true ); | ||
421 | if( from->completed().isValid() ) | ||
422 | to->setCompleted( from->completed() ); | ||
423 | } else { | ||
424 | // set percentcomplete only, if to->isCompleted() | ||
425 | if ( to->isCompleted() ) | ||
426 | to->setPercentComplete(from->percentComplete()); | ||
427 | } | ||
428 | to->setPriority(from->priority()); | ||
429 | |||
875 | } | 430 | } |
431 | #include <qcstring.h> | ||
432 | |||
876 | void PhoneFormat::afterSave( Incidence* inc) | 433 | void PhoneFormat::afterSave( Incidence* inc) |
877 | { | 434 | { |
878 | uint csum; | 435 | uint csum; |
879 | inc->removeID( mProfileName ); | 436 | inc->removeID( mProfileName ); |
880 | if ( inc->type() == "Event") | 437 | if ( inc->type() == "Event") |
881 | csum = PhoneFormat::getCsumEvent( (Event*) inc ); | 438 | csum = PhoneFormat::getCsumEvent( (Event*) inc ); |
882 | else | 439 | else |
883 | csum = PhoneFormat::getCsumTodo( (Todo*) inc ); | 440 | csum = PhoneFormat::getCsumTodo( (Todo*) inc ); |
884 | inc->setCsum( mProfileName, QString::number( csum )); | 441 | inc->setCsum( mProfileName, QString::number( csum )); |
885 | inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 442 | inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); |
886 | 443 | ||
887 | } | 444 | } |
888 | bool PhoneFormat::save( Calendar *calendar) | 445 | bool PhoneFormat::save( Calendar *calendar) |
889 | { | 446 | { |
890 | |||
891 | GSM_StateMachines; | ||
892 | qDebug(" save "); | ||
893 | s.opened = false; | ||
894 | s.msg = NULL; | ||
895 | s.ConfigNum = 0; | ||
896 | QLabel status ( i18n(" Opening device ..."), 0 ); | 447 | QLabel status ( i18n(" Opening device ..."), 0 ); |
897 | int w = status.sizeHint().width()+20 ; | 448 | int w = status.sizeHint().width()+20 ; |
898 | if ( w < 200 ) w = 230; | 449 | if ( w < 200 ) w = 230; |
899 | int h = status.sizeHint().height()+20 ; | 450 | int h = status.sizeHint().height()+20 ; |
900 | int dw = QApplication::desktop()->width(); | 451 | int dw = QApplication::desktop()->width(); |
901 | int dh = QApplication::desktop()->height(); | 452 | int dh = QApplication::desktop()->height(); |
902 | status.setCaption(i18n("Writing to phone...") ); | 453 | status.setCaption(i18n("Writing to phone...") ); |
903 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 454 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
904 | status.show(); | 455 | status.show(); |
905 | status.raise(); | 456 | status.raise(); |
906 | qApp->processEvents(); | 457 | qApp->processEvents(); |
907 | 458 | QString message; | |
908 | int error=initDevice(&s); | ||
909 | qDebug("GSM Init %d (no error is %d)", error, ERR_NONE); | ||
910 | if ( error != ERR_NONE ) | ||
911 | return false; | ||
912 | GSM_Phone_Functions*Phone; | ||
913 | GSM_CalendarEntryNote; | ||
914 | bool start = true; | ||
915 | Phone=s.Phone.Functions; | ||
916 | bool gshutdown = false; | ||
917 | QPtrList<Event> er = calendar->rawEvents(); | ||
918 | Event* ev = er.first(); | ||
919 | QString message = i18n(" Deleting event # "); | ||
920 | int procCount = 0; | ||
921 | int diffProc = 0; | ||
922 | bool setPossible = true; | ||
923 | #ifdef _WIN32_ | 459 | #ifdef _WIN32_ |
924 | QString fileName = locateLocal("data", "korganizer") + "\\tempfile.vcs"; | 460 | QString fileName = locateLocal("data", "korganizer") + "\\tempfile.vcs"; |
925 | #else | 461 | #else |
926 | QString fileName = "/tmp/kdepimtemp.vcs"; | 462 | QString fileName = "/tmp/kdepimtemp.vcs"; |
927 | #endif | 463 | #endif |
928 | //algo 1 delete event | ||
929 | while ( ev ) { | ||
930 | if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { // event was changed during sync or is a new one | ||
931 | |||
932 | status.setText ( message + QString::number ( ++procCount ) ); | ||
933 | qApp->processEvents(); | ||
934 | qDebug("del event1 %d ", procCount); | ||
935 | //event2GSM( calendar, ev, &Note ); | ||
936 | if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete | ||
937 | 464 | ||
938 | QString loc = ev->getID(mProfileName); | 465 | // 1 remove events which should be deleted |
939 | if ( !loc.isEmpty() ){ | 466 | QPtrList<Event> er = calendar->rawEvents(); |
940 | Note.Location = loc.toInt(); | 467 | Event* ev = er.first(); |
941 | } else { | 468 | while ( ev ) { |
942 | qDebug("error: loc is empty "); | 469 | if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { |
943 | } | 470 | calendar->deleteEvent( ev ); |
944 | error = Phone->DeleteCalendar(&s, &Note); | 471 | } else { |
945 | if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { | ||
946 | qDebug(" e error delete1 planB %d ", error); | ||
947 | break; | ||
948 | } | ||
949 | } | ||
950 | else if ( ev->getID(mProfileName).isEmpty() ) { // add new | ||
951 | // we have to do this later after deleting | ||
952 | |||
953 | } | ||
954 | else { // change existing | ||
955 | 472 | ||
956 | QString loc = ev->getID(mProfileName); | 473 | } |
957 | if ( !loc.isEmpty() ){ | ||
958 | Note.Location = loc.toInt(); | ||
959 | } else { | ||
960 | qDebug("error3: loc is empty "); | ||
961 | } | ||
962 | error = Phone->DeleteCalendar(&s, &Note); | ||
963 | if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { | ||
964 | qDebug(" e error delete2 planB %d ", error); | ||
965 | break; | ||
966 | } | ||
967 | ev->removeID( mProfileName ); | ||
968 | } | ||
969 | } | ||
970 | ev = er.next(); | 474 | ev = er.next(); |
971 | } | 475 | } |
972 | //algo 1 delete todo | 476 | // 2 remove todos which should be deleted |
973 | GSM_ToDoEntry ToDoEntry; | ||
974 | QPtrList<Todo> tl = calendar->rawTodos(); | 477 | QPtrList<Todo> tl = calendar->rawTodos(); |
975 | Todo* to = tl.first(); | 478 | Todo* to = tl.first(); |
976 | message = i18n(" Deleting todo # "); | ||
977 | procCount = 0; | ||
978 | while ( to ) { | 479 | while ( to ) { |
979 | if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { | 480 | if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { |
980 | qDebug("todo3 %d ", procCount); | 481 | calendar->deleteTodo( to ); |
981 | status.setText ( message + QString::number ( ++procCount ) ); | ||
982 | qApp->processEvents(); | ||
983 | qDebug("todo5 %d ", procCount); | ||
984 | // todo2GSM( calendar, to, &ToDoEntry ); | ||
985 | QString loc = to->getID(mProfileName); | ||
986 | if ( !loc.isEmpty() ){ | ||
987 | ToDoEntry.Location = loc.toInt(); | ||
988 | } else { | ||
989 | qDebug("error2: loc is empty "); | ||
990 | } | ||
991 | if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete | ||
992 | error=Phone->DeleteToDo(&s,&ToDoEntry); | ||
993 | if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { | ||
994 | qDebug("delete planB %d ", error); | ||
995 | } | ||
996 | } | ||
997 | else if ( to->getID(mProfileName).isEmpty() ) { // add new | ||
998 | ; | ||
999 | } | ||
1000 | else { // change existing | ||
1001 | error=Phone->DeleteToDo(&s,&ToDoEntry); | ||
1002 | if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { | ||
1003 | qDebug("set planB %d ", error); | ||
1004 | } | ||
1005 | to->removeID( mProfileName ); | ||
1006 | } | ||
1007 | } | 482 | } |
1008 | to = tl.next(); | 483 | to = tl.next(); |
1009 | } | 484 | } |
1010 | //algo 2 add event | 485 | // 3 save file |
1011 | ev = er.first(); | 486 | VCalFormat vfsave; |
1012 | QString filec; | 487 | vfsave.setLocalTime ( true ); |
1013 | message = i18n(" Preparing event # "); | 488 | if ( ! vfsave.save( calendar, fileName ) ) |
1014 | procCount = 0; | ||
1015 | while ( ev ) { | ||
1016 | if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL && ev->tempSyncStat() != SYNC_TEMPSTATE_DELETE) { | ||
1017 | if ( ev->getID(mProfileName).isEmpty() ) { | ||
1018 | status.setText ( message + QString::number ( ++procCount ) ); | ||
1019 | qApp->processEvents(); | ||
1020 | filec += vfconverter.eventToString( ev, calendar )+ "\n"; | ||
1021 | afterSave ( ev ); | ||
1022 | |||
1023 | } | ||
1024 | } | ||
1025 | ev = er.next(); | ||
1026 | } | ||
1027 | //algo 2 add todo | ||
1028 | to = tl.first(); | ||
1029 | procCount = 0; | ||
1030 | message = i18n(" Preparing todo # "); | ||
1031 | while ( to ) { | ||
1032 | qDebug("todo2 %d ", procCount); | ||
1033 | if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL && to->tempSyncStat() != SYNC_TEMPSTATE_DELETE) { | ||
1034 | qDebug("todo4 %d ", procCount); | ||
1035 | if ( to->getID(mProfileName).isEmpty() ) { | ||
1036 | status.setText ( message + QString::number ( ++procCount ) ); | ||
1037 | qApp->processEvents(); | ||
1038 | filec += vfconverter.todoToString( to, calendar )+ "\n"; | ||
1039 | afterSave ( to ); | ||
1040 | } | ||
1041 | } | ||
1042 | to = tl.next(); | ||
1043 | } | ||
1044 | if ( filec.isEmpty() ) { | ||
1045 | qDebug("Nothing to write back.Finished. "); | ||
1046 | error=GSM_TerminateConnection(&s); | ||
1047 | return true; | ||
1048 | } | ||
1049 | //algo 3 saving file | ||
1050 | message = i18n(" Saving temp file ... "); | ||
1051 | status.setText ( message ); | ||
1052 | qApp->processEvents(); | ||
1053 | QFile file( fileName ); | ||
1054 | if (!file.open( IO_WriteOnly ) ) { | ||
1055 | qDebug("error open file "); | ||
1056 | error=GSM_TerminateConnection(&s); | ||
1057 | return false; | 489 | return false; |
1058 | } | 490 | // 4 call kammu |
1059 | QTextStream ts( &file ); | 491 | QString command ="./kammu --restore " + fileName ; |
1060 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 492 | int ret = system ( command.latin1() ); |
1061 | ts << filec ; | 493 | if ( ret != 0 ) |
1062 | file.close(); | 494 | return false; |
1063 | 495 | // 5 reread data | |
1064 | |||
1065 | message = i18n(" Parsing temp file ... "); | ||
1066 | status.setText ( message ); | ||
1067 | qApp->processEvents(); | ||
1068 | GSM_Backup Backup; | ||
1069 | error=GSM_ReadBackupFile( (char*) fileName.latin1() ,&Backup); | ||
1070 | qDebug("Read file result %d ",error ); | ||
1071 | //algo 4 writing event | ||
1072 | int max, i; | ||
1073 | procCount = 0; | ||
1074 | message = i18n(" Writing event # "); | ||
1075 | if (Backup.Calendar[0] != NULL) { | ||
1076 | max = 0; | ||
1077 | while (Backup.Calendar[max]!=NULL) max++; | ||
1078 | |||
1079 | GSM_DateTime*dtp; | ||
1080 | |||
1081 | for (i=0;i<max;i++) { | ||
1082 | status.setText ( message + QString::number ( ++procCount ) ); | ||
1083 | qApp->processEvents(); | ||
1084 | Note = *Backup.Calendar[i]; | ||
1085 | |||
1086 | #if 0 | ||
1087 | int j; | ||
1088 | for (j=0;j<Note.EntriesNum;j++) { | ||
1089 | //qDebug(" for ev"); | ||
1090 | switch (Note.Entries[j].EntryType) { | ||
1091 | case CAL_START_DATETIME: | ||
1092 | //Note->Entries[i].Date.Hour = 5; | ||
1093 | dtp = &Note.Entries[j].Date; | ||
1094 | qDebug("start event %d %d %d - %d %d %d", dtp->Year, dtp->Month, dtp->Day, dtp->Hour, dtp->Minute, dtp->Second ); | ||
1095 | break; | ||
1096 | case CAL_END_DATETIME: | ||
1097 | dtp = &Note.Entries[j].Date; | ||
1098 | qDebug("end event %d %d %d - %d %d %d", dtp->Year, dtp->Month, dtp->Day, dtp->Hour, dtp->Minute, dtp->Second ); | ||
1099 | break; | ||
1100 | } | ||
1101 | } | ||
1102 | int type = Note.Type; | ||
1103 | qDebug(" event type %d - %d %d - %d %d %d",type, GSM_CAL_CALL , GSM_CAL_MEETING ,GSM_CAL_BIRTHDAY, GSM_CAL_MEMO ,GSM_CAL_ALARM ); | ||
1104 | #endif | ||
1105 | |||
1106 | Note.Type = GSM_CAL_MEETING; | ||
1107 | // pending: fix in gammu GSM_ReadBackupFile the type settings | ||
1108 | int loc = Note.Location; | ||
1109 | Note.Location = 0; | ||
1110 | error=Phone->AddCalendar(&s,&Note); | ||
1111 | qDebug("add event %d %d %d", error, Note.Location, loc ); | ||
1112 | } | ||
1113 | } | ||
1114 | //algo 4 writing todo | ||
1115 | procCount = 0; | ||
1116 | message = i18n(" Writing todo # "); | ||
1117 | if (Backup.ToDo[0] != NULL) { | ||
1118 | max = 0; | ||
1119 | while (Backup.ToDo[max]!=NULL) max++; | ||
1120 | for (i=0;i<max;i++) { | ||
1121 | status.setText ( message + QString::number ( ++procCount ) ); | ||
1122 | qApp->processEvents(); | ||
1123 | ToDoEntry = *Backup.ToDo[i]; | ||
1124 | error = Phone->AddToDo(&s,&ToDoEntry); | ||
1125 | qDebug("add todo %d ", error); | ||
1126 | } | ||
1127 | } | ||
1128 | //algo 5 reread | ||
1129 | message = i18n(" Rereading all data ... "); | 496 | message = i18n(" Rereading all data ... "); |
1130 | status.setText ( message ); | 497 | status.setText ( message ); |
1131 | qApp->processEvents(); | 498 | qApp->processEvents(); |
1132 | error=GSM_TerminateConnection(&s); | ||
1133 | CalendarLocal* calendarTemp = new CalendarLocal(); | 499 | CalendarLocal* calendarTemp = new CalendarLocal(); |
1134 | calendarTemp->setTimeZoneId( calendar->timeZoneId()); | 500 | calendarTemp->setTimeZoneId( calendar->timeZoneId()); |
1135 | if ( ! load( calendarTemp,calendar) ){ | 501 | if ( ! load( calendarTemp,calendar) ){ |
1136 | qDebug("error reloading calendar "); | 502 | qDebug("error reloading calendar "); |
1137 | delete calendarTemp; | 503 | delete calendarTemp; |
1138 | return false; | 504 | return false; |
1139 | } | 505 | } |
506 | // 6 compare data | ||
1140 | 507 | ||
1141 | 508 | //algo 6 compare event | |
1142 | //algo 6 compare event | 509 | er = calendar->rawEvents(); |
1143 | ev = er.first(); | 510 | ev = er.first(); |
1144 | message = i18n(" Comparing event # "); | 511 | message = i18n(" Comparing event # "); |
1145 | QPtrList<Event> er1 = calendarTemp->rawEvents(); | 512 | QPtrList<Event> er1 = calendarTemp->rawEvents(); |
1146 | Event* ev1; | 513 | Event* ev1; |
1147 | procCount = 0; | 514 | int procCount = 0; |
1148 | while ( ev ) { | 515 | while ( ev ) { |
1149 | if ( ev->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID) { | ||
1150 | qDebug("event new ID "); | 516 | qDebug("event new ID "); |
1151 | status.setText ( message + QString::number ( ++procCount ) ); | 517 | status.setText ( message + QString::number ( ++procCount ) ); |
1152 | qApp->processEvents(); | 518 | qApp->processEvents(); |
1153 | QString cSum = ev->getCsum(mProfileName); | 519 | QString cSum = ev->getCsum(mProfileName); |
1154 | ev1 = er1.first(); | 520 | ev1 = er1.first(); |
1155 | while ( ev1 ) { | 521 | while ( ev1 ) { |
1156 | if ( ev1->getCsum( mProfileName ) == cSum ) { | 522 | if ( ev1->getCsum( mProfileName ) == cSum ) { |
1157 | er1.remove( ev1 ); | 523 | er1.remove( ev1 ); |
524 | afterSave( ev ); | ||
1158 | ev->setID(mProfileName, ev1->getID(mProfileName) ); | 525 | ev->setID(mProfileName, ev1->getID(mProfileName) ); |
1159 | break; | 526 | break; |
1160 | } | 527 | } |
1161 | ev1 = er1.next(); | 528 | ev1 = er1.next(); |
1162 | } | 529 | } |
1163 | if ( ! ev1 ) { | 530 | if ( ! ev1 ) { |
1164 | ev->removeID(mProfileName); | 531 | ev->removeID(mProfileName); |
1165 | qDebug("ERROR: No event found on phone for %s ", ev->summary().latin1()); | 532 | qDebug("ERROR: No event found on phone for %s ", ev->summary().latin1()); |
1166 | qDebug("Probably writing back of events not supported "); | ||
1167 | } | 533 | } |
1168 | 534 | ||
1169 | } | 535 | |
1170 | ev = er.next(); | 536 | ev = er.next(); |
1171 | } | 537 | } |
1172 | //algo 6 compare todo | 538 | //algo 6 compare todo |
1173 | to = tl.first(); | 539 | to = tl.first(); |
1174 | procCount = 0; | 540 | procCount = 0; |
1175 | QPtrList<Todo> tl1 = calendarTemp->rawTodos(); | 541 | QPtrList<Todo> tl1 = calendarTemp->rawTodos(); |
1176 | Todo* to1 ; | 542 | Todo* to1 ; |
1177 | message = i18n(" Comparing todo # "); | 543 | message = i18n(" Comparing todo # "); |
1178 | while ( to ) { | 544 | while ( to ) { |
1179 | qDebug("todo2 %d ", procCount); | 545 | qDebug("todo2 %d ", procCount); |
1180 | if ( to->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID) { | ||
1181 | status.setText ( message + QString::number ( ++procCount ) ); | 546 | status.setText ( message + QString::number ( ++procCount ) ); |
1182 | qApp->processEvents(); | 547 | qApp->processEvents(); |
1183 | QString cSum = to->getCsum(mProfileName); | 548 | QString cSum = to->getCsum(mProfileName); |
1184 | Todo* to1 = tl1.first(); | 549 | Todo* to1 = tl1.first(); |
1185 | while ( to1 ) { | 550 | while ( to1 ) { |
1186 | if ( to1->getCsum( mProfileName ) == cSum ) { | 551 | if ( to1->getCsum( mProfileName ) == cSum ) { |
1187 | tl1.remove( to1 ); | 552 | tl1.remove( to1 ); |
553 | afterSave( to ); | ||
1188 | to->setID(mProfileName, to1->getID(mProfileName) ); | 554 | to->setID(mProfileName, to1->getID(mProfileName) ); |
1189 | break; | 555 | break; |
1190 | } | 556 | } |
1191 | to1 = tl1.next(); | 557 | to1 = tl1.next(); |
1192 | } | 558 | } |
1193 | if ( ! to1 ) { | 559 | if ( ! to1 ) { |
1194 | to->removeID(mProfileName); | 560 | to->removeID(mProfileName); |
1195 | qDebug("ERROR: No todo found on phone for %s ", to->summary().latin1()); | 561 | qDebug("ERROR: No todo found on phone for %s ", to->summary().latin1()); |
1196 | qDebug("Probably writing back of todos not supported "); | ||
1197 | } | 562 | } |
1198 | } | 563 | |
1199 | to = tl.next(); | 564 | to = tl.next(); |
1200 | } | 565 | } |
1201 | delete calendarTemp; | 566 | delete calendarTemp; |
1202 | return true; | 567 | return true; |
1203 | // ******************************************************************* | ||
1204 | // ******************************************************************* | ||
1205 | // ******************************************************************* | ||
1206 | #if 0 | ||
1207 | while ( ev && ! planB) { | ||
1208 | if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { // event was changed during sync or is a new one | ||
1209 | |||
1210 | status.setText ( message + QString::number ( ++procCount ) ); | ||
1211 | qApp->processEvents(); | ||
1212 | qDebug("event1 %d ", procCount); | ||
1213 | event2GSM( calendar, ev, &Note ); | ||
1214 | if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete | ||
1215 | error = Phone->DeleteCalendar(&s, &Note); | ||
1216 | if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { | ||
1217 | planB = true; | ||
1218 | qDebug(" e delete1 planB %d ", error); | ||
1219 | break; | ||
1220 | } | ||
1221 | } | ||
1222 | else if ( ev->getID(mProfileName).isEmpty() ) { // add new | ||
1223 | // we have to do this later after deleting | ||
1224 | |||
1225 | } | ||
1226 | else { // change existing | ||
1227 | if ( setPossible ) { | ||
1228 | error = Phone->SetCalendar(&s, &Note); | ||
1229 | if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { | ||
1230 | setPossible = false; | ||
1231 | ++diffProc; | ||
1232 | qDebug("Set cal not supported %d ", error); | ||
1233 | break; | ||
1234 | } | ||
1235 | } | ||
1236 | if ( ! setPossible) { | ||
1237 | ++diffProc; | ||
1238 | error = Phone->DeleteCalendar(&s, &Note); | ||
1239 | if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { | ||
1240 | planB = true; | ||
1241 | qDebug(" e delete2 planB %d ", error); | ||
1242 | break; | ||
1243 | } | ||
1244 | ev->removeID( mProfileName ); | ||
1245 | } | ||
1246 | qDebug("Change Calendar. Location %d status: %d",Note.Location, error ); | ||
1247 | } | ||
1248 | } | ||
1249 | ev = er.next(); | ||
1250 | } | ||
1251 | ev = er.first(); | ||
1252 | // pending get empty slots | ||
1253 | int loc = 0; | ||
1254 | procCount -= diffProc; | ||
1255 | while ( ev && ! planB) { | ||
1256 | if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL && ev->tempSyncStat() != SYNC_TEMPSTATE_DELETE) { | ||
1257 | qDebug("event2 %d ", procCount); | ||
1258 | if ( ev->getID(mProfileName).isEmpty() ) { | ||
1259 | status.setText ( message + QString::number ( ++procCount ) ); | ||
1260 | qApp->processEvents(); | ||
1261 | //int newID ;//= pending | ||
1262 | //ev->setID(mProfileName, QString::number( newID )); | ||
1263 | event2GSM( calendar, ev, &Note ); | ||
1264 | ++loc; | ||
1265 | Note.Location = loc; | ||
1266 | error = Phone->AddCalendar(&s, &Note); | ||
1267 | if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { | ||
1268 | planB = true; | ||
1269 | qDebug(" e add planB %d ", error); | ||
1270 | break; | ||
1271 | } | ||
1272 | ev->setID( mProfileName, QString::number( Note.Location ) ); | ||
1273 | qDebug("New Calendar. Location %d stat %d %d",Note.Location ,error, ERR_UNKNOWN); | ||
1274 | afterSave( ev ); | ||
1275 | } else { | ||
1276 | afterSave( ev ); // setting temp sync stat for changed items | ||
1277 | } | ||
1278 | } | ||
1279 | ev = er.next(); | ||
1280 | } | ||
1281 | 568 | ||
1282 | 569 | ||
1283 | if ( planB ) { | ||
1284 | qDebug("delete all calendar..."); | ||
1285 | status.setText ( i18n("Deleting all calendar...")); | ||
1286 | qApp->processEvents(); | ||
1287 | error=Phone->DeleteAllCalendar(&s); | ||
1288 | if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { | ||
1289 | message = i18n(" Deleting event # "); | ||
1290 | procCount = 0; | ||
1291 | while (1) { | ||
1292 | status.setText ( message + QString::number ( ++procCount ) ); | ||
1293 | qApp->processEvents(); | ||
1294 | qDebug("deleting event ... %d", procCount); | ||
1295 | error = Phone->GetNextCalendar(&s,&Note,true); | ||
1296 | if (error != ERR_NONE) break; | ||
1297 | error = Phone->DeleteCalendar(&s,&Note); | ||
1298 | } | ||
1299 | qDebug("deleting calendar ... finished"); | ||
1300 | } else { | ||
1301 | status.setText ( i18n("All calendar deleted!")); | ||
1302 | qDebug("all cal deleted"); | ||
1303 | } | ||
1304 | bool planC = false; | ||
1305 | ev = er.first(); | ||
1306 | procCount = 0; | ||
1307 | message = i18n(" Writing event # "); | ||
1308 | while ( ev && ! planC) { | ||
1309 | status.setText ( message + QString::number ( ++procCount ) ); | ||
1310 | qApp->processEvents(); | ||
1311 | event2GSM( calendar, ev, &Note ); | ||
1312 | Note.Location = procCount; | ||
1313 | error=Phone->AddCalendar(&s,&Note); | ||
1314 | if (error != ERR_NONE ) { | ||
1315 | // we have currently no planC :-( | ||
1316 | // planC = true; | ||
1317 | //qDebug("add planC %d ", error); | ||
1318 | //break; | ||
1319 | // we remove the ID such that this todo is not deleted after next sync | ||
1320 | ev->removeID(mProfileName); | ||
1321 | ev->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | ||
1322 | qDebug("error :cal adding loc %d planB stat %d ", Note.Location ,error); | ||
1323 | } else { | ||
1324 | qDebug("cal adding loc %d planB stat %d ", Note.Location ,error); | ||
1325 | ev->setID(mProfileName, QString::number( Note.Location )); | ||
1326 | afterSave( ev ); | ||
1327 | } | ||
1328 | ev = er.next(); | ||
1329 | } | ||
1330 | if ( planC ) { | ||
1331 | qDebug("writing cal went wrong..."); | ||
1332 | 570 | ||
1333 | // we have currently no planC :-( | ||
1334 | } | ||
1335 | } | ||
1336 | GSM_ToDoEntry ToDoEntry; | ||
1337 | QPtrList<Todo> tl = calendar->rawTodos(); | ||
1338 | Todo* to = tl.first(); | ||
1339 | |||
1340 | message = i18n(" Processing todo # "); | ||
1341 | procCount = 0; | ||
1342 | planB = false; | ||
1343 | while ( to && ! planB ) { | ||
1344 | if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { | ||
1345 | qDebug("todo3 %d ", procCount); | ||
1346 | status.setText ( message + QString::number ( ++procCount ) ); | ||
1347 | qApp->processEvents(); | ||
1348 | qDebug("todo5 %d ", procCount); | ||
1349 | todo2GSM( calendar, to, &ToDoEntry ); | ||
1350 | if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete | ||
1351 | error=Phone->DeleteToDo(&s,&ToDoEntry); | ||
1352 | if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { | ||
1353 | planB = true; | ||
1354 | qDebug("delete planB %d ", error); | ||
1355 | } | ||
1356 | } | ||
1357 | else if ( to->getID(mProfileName).isEmpty() ) { // add new | ||
1358 | ; | ||
1359 | } | ||
1360 | else { // change existing | ||
1361 | error=Phone->SetToDo(&s,&ToDoEntry); | ||
1362 | if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { | ||
1363 | planB = true; | ||
1364 | qDebug("set planB %d ", error); | ||
1365 | } | ||
1366 | qDebug("Old Todo. Location %d %d",ToDoEntry.Location , error ); | ||
1367 | } | ||
1368 | } | ||
1369 | to = tl.next(); | ||
1370 | } | ||
1371 | |||
1372 | // pending get empty slots | ||
1373 | to = tl.first(); | ||
1374 | while ( to && ! planB ) { | ||
1375 | qDebug("todo2 %d ", procCount); | ||
1376 | if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL && to->tempSyncStat() != SYNC_TEMPSTATE_DELETE) { | ||
1377 | qDebug("todo4 %d ", procCount); | ||
1378 | if ( to->getID(mProfileName).isEmpty() ) { | ||
1379 | status.setText ( message + QString::number ( ++procCount ) ); | ||
1380 | qApp->processEvents(); | ||
1381 | //int newID ;//= pending | ||
1382 | //to->setID(mProfileName, QString::number( newID )); | ||
1383 | todo2GSM( calendar,to, &ToDoEntry ); | ||
1384 | ToDoEntry.Location = 0; | ||
1385 | error=Phone->AddToDo(&s,&ToDoEntry); | ||
1386 | if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { | ||
1387 | planB = true; | ||
1388 | qDebug("new planB %d ", error); | ||
1389 | } | ||
1390 | to->setID(mProfileName, QString::number( ToDoEntry.Location )); | ||
1391 | afterSave( to ); | ||
1392 | qDebug("New Todo. Location %d %d",ToDoEntry.Location, error ); | ||
1393 | } else { | ||
1394 | afterSave( to ); | ||
1395 | } | ||
1396 | } | ||
1397 | to = tl.next(); | ||
1398 | } | ||
1399 | if ( planB ) { | ||
1400 | qDebug("delete all ..."); | ||
1401 | error=Phone->DeleteAllToDo(&s); | ||
1402 | if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { | ||
1403 | while (1) { | ||
1404 | qDebug("deleting todo ..."); | ||
1405 | error = Phone->GetNextToDo(&s,&ToDoEntry,true); | ||
1406 | if (error != ERR_NONE) break; | ||
1407 | error = Phone->DeleteToDo(&s,&ToDoEntry); | ||
1408 | } | ||
1409 | qDebug("deleting todo ... finished"); | ||
1410 | } else { | ||
1411 | qDebug("all todo deleted"); | ||
1412 | } | ||
1413 | bool planC = false; | ||
1414 | to = tl.first(); | ||
1415 | while ( to && ! planC ) { | ||
1416 | todo2GSM( calendar,to, &ToDoEntry ); | ||
1417 | ToDoEntry.Location = 0; | ||
1418 | error=Phone->AddToDo(&s,&ToDoEntry); | ||
1419 | if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { | ||
1420 | // we have currently no planC :-( | ||
1421 | // planC = true; | ||
1422 | //qDebug("add planC %d ", error); | ||
1423 | //break; | ||
1424 | // we remove the ID such that this todo is not deleted after next sync | ||
1425 | to->removeID(mProfileName); | ||
1426 | to->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | ||
1427 | } else { | ||
1428 | qDebug("adding %d planB %d ", ToDoEntry.Location ,error); | ||
1429 | to->setID(mProfileName, QString::number( ToDoEntry.Location )); | ||
1430 | afterSave( to ); | ||
1431 | } | ||
1432 | to = tl.next(); | ||
1433 | } | ||
1434 | if ( planC ) { | ||
1435 | // we have currently no planC :-( | ||
1436 | } | ||
1437 | } | ||
1438 | return true; | ||
1439 | #endif | ||
1440 | } | ||
1441 | QString PhoneFormat::dtToGSM( const QDateTime& dti, bool useTZ ) | ||
1442 | { | ||
1443 | QString datestr; | ||
1444 | QString timestr; | ||
1445 | int offset = KGlobal::locale()->localTimeOffset( dti ); | ||
1446 | QDateTime dt; | ||
1447 | if (useTZ) | ||
1448 | dt = dti.addSecs ( -(offset*60)); | ||
1449 | else | ||
1450 | dt = dti; | ||
1451 | if(dt.date().isValid()){ | ||
1452 | const QDate& date = dt.date(); | ||
1453 | datestr.sprintf("%04d%02d%02d", | ||
1454 | date.year(), date.month(), date.day()); | ||
1455 | } | ||
1456 | if(dt.time().isValid()){ | ||
1457 | const QTime& time = dt.time(); | ||
1458 | timestr.sprintf("T%02d%02d%02d", | ||
1459 | time.hour(), time.minute(), time.second()); | ||
1460 | } | ||
1461 | return datestr + timestr; | ||
1462 | } | ||
1463 | QString PhoneFormat::getEventString( Event* event ) | ||
1464 | { | ||
1465 | #if 0 | ||
1466 | QStringList list; | ||
1467 | list.append( QString::number(event->zaurusId() ) ); | ||
1468 | list.append( event->categories().join(",") ); | ||
1469 | if ( !event->summary().isEmpty() ) | ||
1470 | list.append( event->summary() ); | ||
1471 | else | ||
1472 | list.append("" ); | ||
1473 | if ( !event->location().isEmpty() ) | ||
1474 | list.append( event->location() ); | ||
1475 | else | ||
1476 | list.append("" ); | ||
1477 | if ( !event->description().isEmpty() ) | ||
1478 | list.append( event->description() ); | ||
1479 | else | ||
1480 | list.append( "" ); | ||
1481 | if ( event->doesFloat () ) { | ||
1482 | list.append( dtToString( QDateTime(event->dtStart().date(), QTime(0,0,0)), false )); | ||
1483 | list.append( dtToString( QDateTime(event->dtEnd().date(),QTime(23,59,59)), false )); //6 | ||
1484 | list.append( "1" ); | ||
1485 | |||
1486 | } | ||
1487 | else { | ||
1488 | list.append( dtToString( event->dtStart()) ); | ||
1489 | list.append( dtToString( event->dtEnd()) ); //6 | ||
1490 | list.append( "0" ); | ||
1491 | } | ||
1492 | bool noAlarm = true; | ||
1493 | if ( event->alarms().count() > 0 ) { | ||
1494 | Alarm * al = event->alarms().first(); | ||
1495 | if ( al->enabled() ) { | ||
1496 | noAlarm = false; | ||
1497 | list.append( "0" ); // yes, 0 == alarm | ||
1498 | list.append( QString::number( al->startOffset().asSeconds()/(-60) ) ); | ||
1499 | if ( al->type() == Alarm::Audio ) | ||
1500 | list.append( "1" ); // type audio | ||
1501 | else | ||
1502 | list.append( "0" ); // type silent | ||
1503 | } | ||
1504 | } | ||
1505 | if ( noAlarm ) { | ||
1506 | list.append( "1" ); // yes, 1 == no alarm | ||
1507 | list.append( "0" ); // no alarm offset | ||
1508 | list.append( "1" ); // type | ||
1509 | } | ||
1510 | // next is: 11 | ||
1511 | // next is: 11-16 are recurrence | ||
1512 | Recurrence* rec = event->recurrence(); | ||
1513 | |||
1514 | bool writeEndDate = false; | ||
1515 | switch ( rec->doesRecur() ) | ||
1516 | { | ||
1517 | case Recurrence::rDaily: // 0 | ||
1518 | list.append( "0" ); | ||
1519 | list.append( QString::number( rec->frequency() ));//12 | ||
1520 | list.append( "0" ); | ||
1521 | list.append( "0" ); | ||
1522 | writeEndDate = true; | ||
1523 | break; | ||
1524 | case Recurrence::rWeekly:// 1 | ||
1525 | list.append( "1" ); | ||
1526 | list.append( QString::number( rec->frequency()) );//12 | ||
1527 | list.append( "0" ); | ||
1528 | { | ||
1529 | int days = 0; | ||
1530 | QBitArray weekDays = rec->days(); | ||
1531 | int i; | ||
1532 | for( i = 1; i <= 7; ++i ) { | ||
1533 | if ( weekDays[i-1] ) { | ||
1534 | days += 1 << (i-1); | ||
1535 | } | ||
1536 | } | ||
1537 | list.append( QString::number( days ) ); | ||
1538 | } | ||
1539 | //pending weekdays | ||
1540 | writeEndDate = true; | ||
1541 | |||
1542 | break; | ||
1543 | case Recurrence::rMonthlyPos:// 2 | ||
1544 | list.append( "2" ); | ||
1545 | list.append( QString::number( rec->frequency()) );//12 | ||
1546 | |||
1547 | writeEndDate = true; | ||
1548 | { | ||
1549 | int count = 1; | ||
1550 | QPtrList<Recurrence::rMonthPos> rmp; | ||
1551 | rmp = rec->monthPositions(); | ||
1552 | if ( rmp.first()->negative ) | ||
1553 | count = 5 - rmp.first()->rPos - 1; | ||
1554 | else | ||
1555 | count = rmp.first()->rPos - 1; | ||
1556 | list.append( QString::number( count ) ); | ||
1557 | |||
1558 | } | ||
1559 | |||
1560 | list.append( "0" ); | ||
1561 | break; | ||
1562 | case Recurrence::rMonthlyDay:// 3 | ||
1563 | list.append( "3" ); | ||
1564 | list.append( QString::number( rec->frequency()) );//12 | ||
1565 | list.append( "0" ); | ||
1566 | list.append( "0" ); | ||
1567 | writeEndDate = true; | ||
1568 | break; | ||
1569 | case Recurrence::rYearlyMonth://4 | ||
1570 | list.append( "4" ); | ||
1571 | list.append( QString::number( rec->frequency()) );//12 | ||
1572 | list.append( "0" ); | ||
1573 | list.append( "0" ); | ||
1574 | writeEndDate = true; | ||
1575 | break; | ||
1576 | |||
1577 | default: | ||
1578 | list.append( "255" ); | ||
1579 | list.append( QString() ); | ||
1580 | list.append( "0" ); | ||
1581 | list.append( QString() ); | ||
1582 | list.append( "0" ); | ||
1583 | list.append( "20991231T000000" ); | ||
1584 | break; | ||
1585 | } | ||
1586 | if ( writeEndDate ) { | ||
1587 | |||
1588 | if ( rec->endDate().isValid() ) { // 15 + 16 | ||
1589 | list.append( "1" ); | ||
1590 | list.append( dtToString( rec->endDate()) ); | ||
1591 | } else { | ||
1592 | list.append( "0" ); | ||
1593 | list.append( "20991231T000000" ); | ||
1594 | } | ||
1595 | |||
1596 | } | ||
1597 | if ( event->doesFloat () ) { | ||
1598 | list.append( dtToString( event->dtStart(), false ).left( 8 )); | ||
1599 | list.append( dtToString( event->dtEnd(), false ).left( 8 )); //6 | ||
1600 | |||
1601 | } | ||
1602 | else { | ||
1603 | list.append( QString() ); | ||
1604 | list.append( QString() ); | ||
1605 | |||
1606 | } | ||
1607 | if (event->dtStart().date() == event->dtEnd().date() ) | ||
1608 | list.append( "0" ); | ||
1609 | else | ||
1610 | list.append( "1" ); | ||
1611 | |||
1612 | |||
1613 | for(QStringList::Iterator it=list.begin(); | ||
1614 | it!=list.end(); ++it){ | ||
1615 | QString& s = (*it); | ||
1616 | s.replace(QRegExp("\""), "\"\""); | ||
1617 | if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){ | ||
1618 | s.prepend('\"'); | ||
1619 | s.append('\"'); | ||
1620 | } else if(s.isEmpty() && !s.isNull()){ | ||
1621 | s = "\"\""; | ||
1622 | } | ||
1623 | } | ||
1624 | return list.join(","); | ||
1625 | #endif | ||
1626 | return QString(); | ||
1627 | |||
1628 | } | ||
1629 | QString PhoneFormat::getTodoString( Todo* todo ) | ||
1630 | { | ||
1631 | #if 0 | ||
1632 | QStringList list; | ||
1633 | list.append( QString::number( todo->zaurusId() ) ); | ||
1634 | list.append( todo->categories().join(",") ); | ||
1635 | |||
1636 | if ( todo->hasStartDate() ) { | ||
1637 | list.append( dtToString( todo->dtStart()) ); | ||
1638 | } else | ||
1639 | list.append( QString() ); | ||
1640 | |||
1641 | if ( todo->hasDueDate() ) { | ||
1642 | QTime tim; | ||
1643 | if ( todo->doesFloat()) { | ||
1644 | list.append( dtToString( QDateTime(todo->dtDue().date(),QTime( 0,0,0 )), false)) ; | ||
1645 | } else { | ||
1646 | list.append( dtToString(todo->dtDue() ) ); | ||
1647 | } | ||
1648 | } else | ||
1649 | list.append( QString() ); | ||
1650 | |||
1651 | if ( todo->isCompleted() ) { | ||
1652 | list.append( dtToString( todo->completed()) ); | ||
1653 | list.append( "0" ); // yes 0 == completed | ||
1654 | } else { | ||
1655 | list.append( dtToString( todo->completed()) ); | ||
1656 | list.append( "1" ); | ||
1657 | } | ||
1658 | list.append( QString::number( todo->priority() )); | ||
1659 | if( ! todo->summary().isEmpty() ) | ||
1660 | list.append( todo->summary() ); | ||
1661 | else | ||
1662 | list.append( "" ); | ||
1663 | if (! todo->description().isEmpty() ) | ||
1664 | list.append( todo->description() ); | ||
1665 | else | ||
1666 | list.append( "" ); | ||
1667 | for(QStringList::Iterator it=list.begin(); | ||
1668 | it!=list.end(); ++it){ | ||
1669 | QString& s = (*it); | ||
1670 | s.replace(QRegExp("\""), "\"\""); | ||
1671 | if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){ | ||
1672 | s.prepend('\"'); | ||
1673 | s.append('\"'); | ||
1674 | } else if(s.isEmpty() && !s.isNull()){ | ||
1675 | s = "\"\""; | ||
1676 | } | ||
1677 | } | ||
1678 | return list.join(","); | ||
1679 | #endif | ||
1680 | return QString(); | ||
1681 | } | 571 | } |
1682 | 572 | ||
1683 | 573 | ||
1684 | QString PhoneFormat::toString( Calendar * ) | 574 | QString PhoneFormat::toString( Calendar * ) |
1685 | { | 575 | { |
1686 | return QString::null; | 576 | return QString::null; |
1687 | } | 577 | } |
1688 | bool PhoneFormat::fromString( Calendar *calendar, const QString & text) | 578 | bool PhoneFormat::fromString( Calendar *calendar, const QString & text) |
1689 | { | 579 | { |
1690 | return false; | 580 | return false; |
1691 | } | 581 | } |
diff --git a/libkcal/phoneformat.h b/libkcal/phoneformat.h index 2c2e51c..8286098 100644 --- a/libkcal/phoneformat.h +++ b/libkcal/phoneformat.h | |||
@@ -1,67 +1,61 @@ | |||
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 | |
31 | #include "../gammu/emb/common/gammu.h" | ||
32 | } | ||
33 | namespace KCal { | 31 | namespace KCal { |
34 | 32 | ||
35 | /** | 33 | /** |
36 | This class implements the calendar format used by Phone. | 34 | This class implements the calendar format used by Phone. |
37 | */ | 35 | */ |
38 | class Event; | 36 | class Event; |
39 | class Todo; | 37 | class Todo; |
40 | class PhoneFormat : public QObject { | 38 | class PhoneFormat : public QObject { |
41 | public: | 39 | public: |
42 | /** Create new iCalendar format. */ | 40 | /** Create new iCalendar format. */ |
43 | PhoneFormat(QString profileName, QString device,QString connection, QString model); | 41 | PhoneFormat(QString profileName, QString device,QString connection, QString model); |
44 | virtual ~PhoneFormat(); | 42 | virtual ~PhoneFormat(); |
45 | 43 | ||
46 | bool load( Calendar * ,Calendar * ); | 44 | bool load( Calendar * ,Calendar * ); |
47 | bool save( Calendar * ); | 45 | bool save( Calendar * ); |
48 | bool fromString( Calendar *, const QString & ); | 46 | bool fromString( Calendar *, const QString & ); |
49 | QString toString( Calendar * ); | 47 | QString toString( Calendar * ); |
50 | static ulong getCsum( const QStringList & ); | 48 | static ulong getCsum( const QStringList & ); |
51 | static ulong getCsumTodo( Todo* to ); | 49 | static ulong getCsumTodo( Todo* to ); |
52 | static ulong getCsumEvent( Event* ev ); | 50 | static ulong getCsumEvent( Event* ev ); |
53 | private: | 51 | private: |
54 | VCalFormat vfconverter; | 52 | void copyEvent( Event* to, Event* from ); |
55 | void event2GSM( Calendar *, Event* ev, GSM_CalendarEntry*Note ); | 53 | void copyTodo( Todo* to, Todo* from ); |
56 | void todo2GSM( Calendar *, Todo* ev, GSM_ToDoEntry *ToDo ); | 54 | //int initDevice(GSM_StateMachine *s); |
57 | int initDevice(GSM_StateMachine *s); | ||
58 | QString getEventString( Event* ); | ||
59 | QString getTodoString( Todo* ); | ||
60 | QString dtToGSM( const QDateTime& dt, bool useTZ = true ); | ||
61 | QString mProfileName, mDevice, mConnection, mModel; | 55 | QString mProfileName, mDevice, mConnection, mModel; |
62 | void afterSave( Incidence* ); | 56 | void afterSave( Incidence* ); |
63 | }; | 57 | }; |
64 | 58 | ||
65 | } | 59 | } |
66 | 60 | ||
67 | #endif | 61 | #endif |
diff --git a/libkcal/vcalformat.cpp b/libkcal/vcalformat.cpp index 0ebd7d1..4727a7a 100644 --- a/libkcal/vcalformat.cpp +++ b/libkcal/vcalformat.cpp | |||
@@ -1,1714 +1,1717 @@ | |||
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 <kglobal.h> | 32 | #include <kglobal.h> |
33 | #include <kmessagebox.h> | 33 | #include <kmessagebox.h> |
34 | #include <kiconloader.h> | 34 | #include <kiconloader.h> |
35 | #include <klocale.h> | 35 | #include <klocale.h> |
36 | 36 | ||
37 | #include "vcc.h" | 37 | #include "vcc.h" |
38 | #include "vobject.h" | 38 | #include "vobject.h" |
39 | 39 | ||
40 | #include "vcaldrag.h" | 40 | #include "vcaldrag.h" |
41 | #include "calendar.h" | 41 | #include "calendar.h" |
42 | 42 | ||
43 | #include "vcalformat.h" | 43 | #include "vcalformat.h" |
44 | 44 | ||
45 | using namespace KCal; | 45 | using namespace KCal; |
46 | 46 | ||
47 | VCalFormat::VCalFormat() | 47 | VCalFormat::VCalFormat() |
48 | { | 48 | { |
49 | mCalendar = 0; | 49 | mCalendar = 0; |
50 | useLocalTime = false; | 50 | useLocalTime = false; |
51 | } | 51 | } |
52 | 52 | ||
53 | VCalFormat::~VCalFormat() | 53 | VCalFormat::~VCalFormat() |
54 | { | 54 | { |
55 | } | 55 | } |
56 | 56 | ||
57 | void VCalFormat::setLocalTime ( bool b ) | ||
58 | { | ||
59 | useLocalTime = b; | ||
60 | } | ||
57 | bool VCalFormat::load(Calendar *calendar, const QString &fileName) | 61 | bool VCalFormat::load(Calendar *calendar, const QString &fileName) |
58 | { | 62 | { |
59 | mCalendar = calendar; | 63 | mCalendar = calendar; |
60 | |||
61 | clearException(); | 64 | clearException(); |
62 | 65 | ||
63 | kdDebug(5800) << "VCalFormat::load() " << fileName << endl; | 66 | kdDebug(5800) << "VCalFormat::load() " << fileName << endl; |
64 | 67 | ||
65 | VObject *vcal = 0; | 68 | VObject *vcal = 0; |
66 | 69 | ||
67 | // this is not necessarily only 1 vcal. Could be many vcals, or include | 70 | // this is not necessarily only 1 vcal. Could be many vcals, or include |
68 | // a vcard... | 71 | // a vcard... |
69 | vcal = Parse_MIME_FromFileName(const_cast<char *>(QFile::encodeName(fileName).data())); | 72 | vcal = Parse_MIME_FromFileName(const_cast<char *>(QFile::encodeName(fileName).data())); |
70 | 73 | ||
71 | if (!vcal) { | 74 | if (!vcal) { |
72 | setException(new ErrorFormat(ErrorFormat::CalVersionUnknown)); | 75 | setException(new ErrorFormat(ErrorFormat::CalVersionUnknown)); |
73 | return FALSE; | 76 | return FALSE; |
74 | } | 77 | } |
75 | 78 | ||
76 | // any other top-level calendar stuff should be added/initialized here | 79 | // any other top-level calendar stuff should be added/initialized here |
77 | 80 | ||
78 | // put all vobjects into their proper places | 81 | // put all vobjects into their proper places |
79 | populate(vcal); | 82 | populate(vcal); |
80 | 83 | ||
81 | // clean up from vcal API stuff | 84 | // clean up from vcal API stuff |
82 | cleanVObjects(vcal); | 85 | cleanVObjects(vcal); |
83 | cleanStrTbl(); | 86 | cleanStrTbl(); |
84 | 87 | ||
85 | return true; | 88 | return true; |
86 | } | 89 | } |
87 | 90 | ||
88 | 91 | ||
89 | bool VCalFormat::save(Calendar *calendar, const QString &fileName) | 92 | bool VCalFormat::save(Calendar *calendar, const QString &fileName) |
90 | { | 93 | { |
91 | mCalendar = calendar; | 94 | mCalendar = calendar; |
92 | 95 | ||
93 | QString tmpStr; | 96 | QString tmpStr; |
94 | VObject *vcal, *vo; | 97 | VObject *vcal, *vo; |
95 | 98 | ||
96 | kdDebug(5800) << "VCalFormat::save(): " << fileName << endl; | 99 | kdDebug(5800) << "VCalFormat::save(): " << fileName << endl; |
97 | 100 | ||
98 | vcal = newVObject(VCCalProp); | 101 | vcal = newVObject(VCCalProp); |
99 | 102 | ||
100 | // addPropValue(vcal,VCLocationProp, "0.0"); | 103 | // addPropValue(vcal,VCLocationProp, "0.0"); |
101 | addPropValue(vcal,VCProdIdProp, productId()); | 104 | addPropValue(vcal,VCProdIdProp, productId()); |
102 | tmpStr = mCalendar->getTimeZoneStr(); | 105 | tmpStr = mCalendar->getTimeZoneStr(); |
103 | //qDebug("mCalendar->getTimeZoneStr() %s",tmpStr.latin1() ); | 106 | //qDebug("mCalendar->getTimeZoneStr() %s",tmpStr.latin1() ); |
104 | addPropValue(vcal,VCTimeZoneProp, tmpStr.local8Bit()); | 107 | addPropValue(vcal,VCTimeZoneProp, tmpStr.local8Bit()); |
105 | addPropValue(vcal,VCVersionProp, _VCAL_VERSION); | 108 | addPropValue(vcal,VCVersionProp, _VCAL_VERSION); |
106 | 109 | ||
107 | // TODO STUFF | 110 | // TODO STUFF |
108 | QPtrList<Todo> todoList = mCalendar->rawTodos(); | 111 | QPtrList<Todo> todoList = mCalendar->rawTodos(); |
109 | QPtrListIterator<Todo> qlt(todoList); | 112 | QPtrListIterator<Todo> qlt(todoList); |
110 | for (; qlt.current(); ++qlt) { | 113 | for (; qlt.current(); ++qlt) { |
111 | vo = eventToVTodo(qlt.current()); | 114 | vo = eventToVTodo(qlt.current()); |
112 | addVObjectProp(vcal, vo); | 115 | addVObjectProp(vcal, vo); |
113 | } | 116 | } |
114 | 117 | ||
115 | // EVENT STUFF | 118 | // EVENT STUFF |
116 | QPtrList<Event> events = mCalendar->rawEvents(); | 119 | QPtrList<Event> events = mCalendar->rawEvents(); |
117 | Event *ev; | 120 | Event *ev; |
118 | for(ev=events.first();ev;ev=events.next()) { | 121 | for(ev=events.first();ev;ev=events.next()) { |
119 | vo = eventToVEvent(ev); | 122 | vo = eventToVEvent(ev); |
120 | addVObjectProp(vcal, vo); | 123 | addVObjectProp(vcal, vo); |
121 | } | 124 | } |
122 | 125 | ||
123 | writeVObjectToFile(QFile::encodeName(fileName).data() ,vcal); | 126 | writeVObjectToFile(QFile::encodeName(fileName).data() ,vcal); |
124 | cleanVObjects(vcal); | 127 | cleanVObjects(vcal); |
125 | cleanStrTbl(); | 128 | cleanStrTbl(); |
126 | 129 | ||
127 | if (QFile::exists(fileName)) { | 130 | if (QFile::exists(fileName)) { |
128 | kdDebug(5800) << "No error" << endl; | 131 | kdDebug(5800) << "No error" << endl; |
129 | return true; | 132 | return true; |
130 | } else { | 133 | } else { |
131 | kdDebug(5800) << "Error" << endl; | 134 | kdDebug(5800) << "Error" << endl; |
132 | return false; // error | 135 | return false; // error |
133 | } | 136 | } |
134 | } | 137 | } |
135 | 138 | ||
136 | bool VCalFormat::fromString( Calendar *calendar, const QString &text ) | 139 | bool VCalFormat::fromString( Calendar *calendar, const QString &text ) |
137 | { | 140 | { |
138 | // TODO: Factor out VCalFormat::fromString() | 141 | // TODO: Factor out VCalFormat::fromString() |
139 | 142 | ||
140 | QCString data = text.utf8(); | 143 | QCString data = text.utf8(); |
141 | 144 | ||
142 | if ( !data.size() ) return false; | 145 | if ( !data.size() ) return false; |
143 | 146 | ||
144 | VObject *vcal = Parse_MIME( data.data(), data.size()); | 147 | VObject *vcal = Parse_MIME( data.data(), data.size()); |
145 | if ( !vcal ) return false; | 148 | if ( !vcal ) return false; |
146 | 149 | ||
147 | VObjectIterator i; | 150 | VObjectIterator i; |
148 | VObject *curvo; | 151 | VObject *curvo; |
149 | initPropIterator( &i, vcal ); | 152 | initPropIterator( &i, vcal ); |
150 | 153 | ||
151 | // we only take the first object. TODO: parse all incidences. | 154 | // we only take the first object. TODO: parse all incidences. |
152 | do { | 155 | do { |
153 | curvo = nextVObject( &i ); | 156 | curvo = nextVObject( &i ); |
154 | } while ( strcmp( vObjectName( curvo ), VCEventProp ) && | 157 | } while ( strcmp( vObjectName( curvo ), VCEventProp ) && |
155 | strcmp( vObjectName( curvo ), VCTodoProp ) ); | 158 | strcmp( vObjectName( curvo ), VCTodoProp ) ); |
156 | 159 | ||
157 | if ( strcmp( vObjectName( curvo ), VCEventProp ) == 0 ) { | 160 | if ( strcmp( vObjectName( curvo ), VCEventProp ) == 0 ) { |
158 | Event *event = VEventToEvent( curvo ); | 161 | Event *event = VEventToEvent( curvo ); |
159 | calendar->addEvent( event ); | 162 | calendar->addEvent( event ); |
160 | } else { | 163 | } else { |
161 | kdDebug(5800) << "VCalFormat::fromString(): Unknown object type." << endl; | 164 | kdDebug(5800) << "VCalFormat::fromString(): Unknown object type." << endl; |
162 | deleteVObject( vcal ); | 165 | deleteVObject( vcal ); |
163 | return false; | 166 | return false; |
164 | } | 167 | } |
165 | 168 | ||
166 | deleteVObject( vcal ); | 169 | deleteVObject( vcal ); |
167 | 170 | ||
168 | return true; | 171 | return true; |
169 | } | 172 | } |
170 | 173 | ||
171 | QString VCalFormat::eventToString( Event * event, Calendar *calendar, bool useLocal) | 174 | QString VCalFormat::eventToString( Event * event, Calendar *calendar, bool useLocal) |
172 | { | 175 | { |
173 | 176 | ||
174 | if ( !event ) return QString::null; | 177 | if ( !event ) return QString::null; |
175 | bool useL = useLocalTime; | 178 | bool useL = useLocalTime; |
176 | useLocalTime = useLocal; | 179 | useLocalTime = useLocal; |
177 | mCalendar = calendar; | 180 | mCalendar = calendar; |
178 | VObject *vevent = eventToVEvent( event ); | 181 | VObject *vevent = eventToVEvent( event ); |
179 | char *buf = writeMemVObject( 0, 0, vevent ); | 182 | char *buf = writeMemVObject( 0, 0, vevent ); |
180 | QString result( buf ); | 183 | QString result( buf ); |
181 | cleanVObject( vevent ); | 184 | cleanVObject( vevent ); |
182 | useLocalTime = useL; | 185 | useLocalTime = useL; |
183 | return result; | 186 | return result; |
184 | } | 187 | } |
185 | QString VCalFormat::todoToString( Todo * todo, Calendar *calendar, bool useLocal ) | 188 | QString VCalFormat::todoToString( Todo * todo, Calendar *calendar, bool useLocal ) |
186 | { | 189 | { |
187 | 190 | ||
188 | if ( !todo ) return QString::null; | 191 | if ( !todo ) return QString::null; |
189 | bool useL = useLocalTime; | 192 | bool useL = useLocalTime; |
190 | useLocalTime = useLocal; | 193 | useLocalTime = useLocal; |
191 | mCalendar = calendar; | 194 | mCalendar = calendar; |
192 | VObject *vevent = eventToVTodo( todo ); | 195 | VObject *vevent = eventToVTodo( todo ); |
193 | char *buf = writeMemVObject( 0, 0, vevent ); | 196 | char *buf = writeMemVObject( 0, 0, vevent ); |
194 | QString result( buf ); | 197 | QString result( buf ); |
195 | cleanVObject( vevent ); | 198 | cleanVObject( vevent ); |
196 | useLocalTime = useL; | 199 | useLocalTime = useL; |
197 | return result; | 200 | return result; |
198 | } | 201 | } |
199 | 202 | ||
200 | QString VCalFormat::toString( Calendar *calendar ) | 203 | QString VCalFormat::toString( Calendar *calendar ) |
201 | { | 204 | { |
202 | // TODO: Factor out VCalFormat::asString() | 205 | // TODO: Factor out VCalFormat::asString() |
203 | 206 | ||
204 | VObject *vcal = newVObject(VCCalProp); | 207 | VObject *vcal = newVObject(VCCalProp); |
205 | 208 | ||
206 | addPropValue( vcal, VCProdIdProp, CalFormat::productId() ); | 209 | addPropValue( vcal, VCProdIdProp, CalFormat::productId() ); |
207 | QString tmpStr = mCalendar->getTimeZoneStr(); | 210 | QString tmpStr = mCalendar->getTimeZoneStr(); |
208 | addPropValue( vcal, VCTimeZoneProp, tmpStr.local8Bit() ); | 211 | addPropValue( vcal, VCTimeZoneProp, tmpStr.local8Bit() ); |
209 | addPropValue( vcal, VCVersionProp, _VCAL_VERSION ); | 212 | addPropValue( vcal, VCVersionProp, _VCAL_VERSION ); |
210 | 213 | ||
211 | // TODO: Use all data. | 214 | // TODO: Use all data. |
212 | QPtrList<Event> events = calendar->events(); | 215 | QPtrList<Event> events = calendar->events(); |
213 | Event *event = events.first(); | 216 | Event *event = events.first(); |
214 | if ( !event ) return QString::null; | 217 | if ( !event ) return QString::null; |
215 | 218 | ||
216 | VObject *vevent = eventToVEvent( event ); | 219 | VObject *vevent = eventToVEvent( event ); |
217 | 220 | ||
218 | addVObjectProp( vcal, vevent ); | 221 | addVObjectProp( vcal, vevent ); |
219 | 222 | ||
220 | char *buf = writeMemVObject( 0, 0, vcal ); | 223 | char *buf = writeMemVObject( 0, 0, vcal ); |
221 | 224 | ||
222 | QString result( buf ); | 225 | QString result( buf ); |
223 | 226 | ||
224 | cleanVObject( vcal ); | 227 | cleanVObject( vcal ); |
225 | 228 | ||
226 | return result; | 229 | return result; |
227 | } | 230 | } |
228 | 231 | ||
229 | VObject *VCalFormat::eventToVTodo(const Todo *anEvent) | 232 | VObject *VCalFormat::eventToVTodo(const Todo *anEvent) |
230 | { | 233 | { |
231 | VObject *vtodo; | 234 | VObject *vtodo; |
232 | QString tmpStr; | 235 | QString tmpStr; |
233 | QStringList tmpStrList; | 236 | QStringList tmpStrList; |
234 | 237 | ||
235 | vtodo = newVObject(VCTodoProp); | 238 | vtodo = newVObject(VCTodoProp); |
236 | 239 | ||
237 | // due date | 240 | // due date |
238 | if (anEvent->hasDueDate()) { | 241 | if (anEvent->hasDueDate()) { |
239 | tmpStr = qDateTimeToISO(anEvent->dtDue(), | 242 | tmpStr = qDateTimeToISO(anEvent->dtDue(), |
240 | !anEvent->doesFloat()); | 243 | !anEvent->doesFloat()); |
241 | addPropValue(vtodo, VCDueProp, tmpStr.local8Bit()); | 244 | addPropValue(vtodo, VCDueProp, tmpStr.local8Bit()); |
242 | } | 245 | } |
243 | 246 | ||
244 | // start date | 247 | // start date |
245 | if (anEvent->hasStartDate()) { | 248 | if (anEvent->hasStartDate()) { |
246 | tmpStr = qDateTimeToISO(anEvent->dtStart(), | 249 | tmpStr = qDateTimeToISO(anEvent->dtStart(), |
247 | !anEvent->doesFloat()); | 250 | !anEvent->doesFloat()); |
248 | addPropValue(vtodo, VCDTstartProp, tmpStr.local8Bit()); | 251 | addPropValue(vtodo, VCDTstartProp, tmpStr.local8Bit()); |
249 | } | 252 | } |
250 | 253 | ||
251 | // creation date | 254 | // creation date |
252 | tmpStr = qDateTimeToISO(anEvent->created()); | 255 | tmpStr = qDateTimeToISO(anEvent->created()); |
253 | addPropValue(vtodo, VCDCreatedProp, tmpStr.local8Bit()); | 256 | addPropValue(vtodo, VCDCreatedProp, tmpStr.local8Bit()); |
254 | 257 | ||
255 | // unique id | 258 | // unique id |
256 | addPropValue(vtodo, VCUniqueStringProp, | 259 | addPropValue(vtodo, VCUniqueStringProp, |
257 | anEvent->uid().local8Bit()); | 260 | anEvent->uid().local8Bit()); |
258 | 261 | ||
259 | // revision | 262 | // revision |
260 | tmpStr.sprintf("%i", anEvent->revision()); | 263 | tmpStr.sprintf("%i", anEvent->revision()); |
261 | addPropValue(vtodo, VCSequenceProp, tmpStr.local8Bit()); | 264 | addPropValue(vtodo, VCSequenceProp, tmpStr.local8Bit()); |
262 | 265 | ||
263 | // last modification date | 266 | // last modification date |
264 | tmpStr = qDateTimeToISO(anEvent->lastModified()); | 267 | tmpStr = qDateTimeToISO(anEvent->lastModified()); |
265 | addPropValue(vtodo, VCLastModifiedProp, tmpStr.local8Bit()); | 268 | addPropValue(vtodo, VCLastModifiedProp, tmpStr.local8Bit()); |
266 | 269 | ||
267 | // organizer stuff | 270 | // organizer stuff |
268 | tmpStr = "MAILTO:" + anEvent->organizer(); | 271 | tmpStr = "MAILTO:" + anEvent->organizer(); |
269 | addPropValue(vtodo, ICOrganizerProp, tmpStr.local8Bit()); | 272 | addPropValue(vtodo, ICOrganizerProp, tmpStr.local8Bit()); |
270 | 273 | ||
271 | // attendees | 274 | // attendees |
272 | if (anEvent->attendeeCount() != 0) { | 275 | if (anEvent->attendeeCount() != 0) { |
273 | QPtrList<Attendee> al = anEvent->attendees(); | 276 | QPtrList<Attendee> al = anEvent->attendees(); |
274 | QPtrListIterator<Attendee> ai(al); | 277 | QPtrListIterator<Attendee> ai(al); |
275 | Attendee *curAttendee; | 278 | Attendee *curAttendee; |
276 | 279 | ||
277 | for (; ai.current(); ++ai) { | 280 | for (; ai.current(); ++ai) { |
278 | curAttendee = ai.current(); | 281 | curAttendee = ai.current(); |
279 | if (!curAttendee->email().isEmpty() && | 282 | if (!curAttendee->email().isEmpty() && |
280 | !curAttendee->name().isEmpty()) | 283 | !curAttendee->name().isEmpty()) |
281 | tmpStr = "MAILTO:" + curAttendee->name() + " <" + | 284 | tmpStr = "MAILTO:" + curAttendee->name() + " <" + |
282 | curAttendee->email() + ">"; | 285 | curAttendee->email() + ">"; |
283 | else if (curAttendee->name().isEmpty()) | 286 | else if (curAttendee->name().isEmpty()) |
284 | tmpStr = "MAILTO: " + curAttendee->email(); | 287 | tmpStr = "MAILTO: " + curAttendee->email(); |
285 | else if (curAttendee->email().isEmpty()) | 288 | else if (curAttendee->email().isEmpty()) |
286 | tmpStr = "MAILTO: " + curAttendee->name(); | 289 | tmpStr = "MAILTO: " + curAttendee->name(); |
287 | else if (curAttendee->name().isEmpty() && | 290 | else if (curAttendee->name().isEmpty() && |
288 | curAttendee->email().isEmpty()) | 291 | curAttendee->email().isEmpty()) |
289 | kdDebug(5800) << "warning! this Event has an attendee w/o name or email!" << endl; | 292 | kdDebug(5800) << "warning! this Event has an attendee w/o name or email!" << endl; |
290 | VObject *aProp = addPropValue(vtodo, VCAttendeeProp, tmpStr.local8Bit()); | 293 | VObject *aProp = addPropValue(vtodo, VCAttendeeProp, tmpStr.local8Bit()); |
291 | addPropValue(aProp, VCRSVPProp, curAttendee->RSVP() ? "TRUE" : "FALSE"); | 294 | addPropValue(aProp, VCRSVPProp, curAttendee->RSVP() ? "TRUE" : "FALSE"); |
292 | addPropValue(aProp, VCStatusProp, writeStatus(curAttendee->status())); | 295 | addPropValue(aProp, VCStatusProp, writeStatus(curAttendee->status())); |
293 | } | 296 | } |
294 | } | 297 | } |
295 | 298 | ||
296 | // description BL: | 299 | // description BL: |
297 | if (!anEvent->description().isEmpty()) { | 300 | if (!anEvent->description().isEmpty()) { |
298 | VObject *d = addPropValue(vtodo, VCDescriptionProp, | 301 | VObject *d = addPropValue(vtodo, VCDescriptionProp, |
299 | anEvent->description().local8Bit()); | 302 | anEvent->description().local8Bit()); |
300 | if (anEvent->description().find('\n') != -1) | 303 | if (anEvent->description().find('\n') != -1) |
301 | addProp(d, VCQuotedPrintableProp); | 304 | addProp(d, VCQuotedPrintableProp); |
302 | } | 305 | } |
303 | 306 | ||
304 | // summary | 307 | // summary |
305 | if (!anEvent->summary().isEmpty()) | 308 | if (!anEvent->summary().isEmpty()) |
306 | addPropValue(vtodo, VCSummaryProp, anEvent->summary().local8Bit()); | 309 | addPropValue(vtodo, VCSummaryProp, anEvent->summary().local8Bit()); |
307 | 310 | ||
308 | if (!anEvent->location().isEmpty()) | 311 | if (!anEvent->location().isEmpty()) |
309 | addPropValue(vtodo, VCLocationProp, anEvent->location().local8Bit()); | 312 | addPropValue(vtodo, VCLocationProp, anEvent->location().local8Bit()); |
310 | 313 | ||
311 | // completed | 314 | // completed |
312 | // status | 315 | // status |
313 | // backward compatibility, KOrganizer used to interpret only these two values | 316 | // backward compatibility, KOrganizer used to interpret only these two values |
314 | addPropValue(vtodo, VCStatusProp, anEvent->isCompleted() ? "COMPLETED" : | 317 | addPropValue(vtodo, VCStatusProp, anEvent->isCompleted() ? "COMPLETED" : |
315 | "NEEDS_ACTION"); | 318 | "NEEDS_ACTION"); |
316 | // completion date | 319 | // completion date |
317 | if (anEvent->hasCompletedDate()) { | 320 | if (anEvent->hasCompletedDate()) { |
318 | tmpStr = qDateTimeToISO(anEvent->completed()); | 321 | tmpStr = qDateTimeToISO(anEvent->completed()); |
319 | addPropValue(vtodo, VCCompletedProp, tmpStr.local8Bit()); | 322 | addPropValue(vtodo, VCCompletedProp, tmpStr.local8Bit()); |
320 | } | 323 | } |
321 | 324 | ||
322 | // priority | 325 | // priority |
323 | tmpStr.sprintf("%i",anEvent->priority()); | 326 | tmpStr.sprintf("%i",anEvent->priority()); |
324 | addPropValue(vtodo, VCPriorityProp, tmpStr.local8Bit()); | 327 | addPropValue(vtodo, VCPriorityProp, tmpStr.local8Bit()); |
325 | 328 | ||
326 | // related event | 329 | // related event |
327 | if (anEvent->relatedTo()) { | 330 | if (anEvent->relatedTo()) { |
328 | addPropValue(vtodo, VCRelatedToProp, | 331 | addPropValue(vtodo, VCRelatedToProp, |
329 | anEvent->relatedTo()->uid().local8Bit()); | 332 | anEvent->relatedTo()->uid().local8Bit()); |
330 | } | 333 | } |
331 | 334 | ||
332 | // categories | 335 | // categories |
333 | tmpStrList = anEvent->categories(); | 336 | tmpStrList = anEvent->categories(); |
334 | tmpStr = ""; | 337 | tmpStr = ""; |
335 | QString catStr; | 338 | QString catStr; |
336 | for ( QStringList::Iterator it = tmpStrList.begin(); | 339 | for ( QStringList::Iterator it = tmpStrList.begin(); |
337 | it != tmpStrList.end(); | 340 | it != tmpStrList.end(); |
338 | ++it ) { | 341 | ++it ) { |
339 | catStr = *it; | 342 | catStr = *it; |
340 | if (catStr[0] == ' ') | 343 | if (catStr[0] == ' ') |
341 | tmpStr += catStr.mid(1); | 344 | tmpStr += catStr.mid(1); |
342 | else | 345 | else |
343 | tmpStr += catStr; | 346 | tmpStr += catStr; |
344 | // this must be a ';' character as the vCalendar specification requires! | 347 | // this must be a ';' character as the vCalendar specification requires! |
345 | // vcc.y has been hacked to translate the ';' to a ',' when the vcal is | 348 | // vcc.y has been hacked to translate the ';' to a ',' when the vcal is |
346 | // read in. | 349 | // read in. |
347 | tmpStr += ";"; | 350 | tmpStr += ";"; |
348 | } | 351 | } |
349 | if (!tmpStr.isEmpty()) { | 352 | if (!tmpStr.isEmpty()) { |
350 | tmpStr.truncate(tmpStr.length()-1); | 353 | tmpStr.truncate(tmpStr.length()-1); |
351 | addPropValue(vtodo, VCCategoriesProp, tmpStr.local8Bit()); | 354 | addPropValue(vtodo, VCCategoriesProp, tmpStr.local8Bit()); |
352 | } | 355 | } |
353 | 356 | ||
354 | // alarm stuff | 357 | // alarm stuff |
355 | kdDebug(5800) << "vcalformat::eventToVTodo was called" << endl; | 358 | kdDebug(5800) << "vcalformat::eventToVTodo was called" << endl; |
356 | QPtrList<Alarm> alarms = anEvent->alarms(); | 359 | QPtrList<Alarm> alarms = anEvent->alarms(); |
357 | Alarm* alarm; | 360 | Alarm* alarm; |
358 | for (alarm = alarms.first(); alarm; alarm = alarms.next()) { | 361 | for (alarm = alarms.first(); alarm; alarm = alarms.next()) { |
359 | if (alarm->enabled()) { | 362 | if (alarm->enabled()) { |
360 | VObject *a; | 363 | VObject *a; |
361 | tmpStr = qDateTimeToISO(alarm->time()); | 364 | tmpStr = qDateTimeToISO(alarm->time()); |
362 | if (alarm->type() == Alarm::Audio) { | 365 | if (alarm->type() == Alarm::Audio) { |
363 | a = addProp(vtodo, VCAAlarmProp); | 366 | a = addProp(vtodo, VCAAlarmProp); |
364 | addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); | 367 | addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); |
365 | addPropValue(a, VCRepeatCountProp, "1"); | 368 | addPropValue(a, VCRepeatCountProp, "1"); |
366 | addPropValue(a, VCAudioContentProp, QFile::encodeName(alarm->audioFile())); | 369 | addPropValue(a, VCAudioContentProp, QFile::encodeName(alarm->audioFile())); |
367 | } | 370 | } |
368 | else if (alarm->type() == Alarm::Procedure) { | 371 | else if (alarm->type() == Alarm::Procedure) { |
369 | a = addProp(vtodo, VCPAlarmProp); | 372 | a = addProp(vtodo, VCPAlarmProp); |
370 | addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); | 373 | addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); |
371 | addPropValue(a, VCRepeatCountProp, "1"); | 374 | addPropValue(a, VCRepeatCountProp, "1"); |
372 | addPropValue(a, VCProcedureNameProp, QFile::encodeName(alarm->programFile())); | 375 | addPropValue(a, VCProcedureNameProp, QFile::encodeName(alarm->programFile())); |
373 | } else { | 376 | } else { |
374 | a = addProp(vtodo, VCDAlarmProp); | 377 | a = addProp(vtodo, VCDAlarmProp); |
375 | addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); | 378 | addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); |
376 | addPropValue(a, VCRepeatCountProp, "1"); | 379 | addPropValue(a, VCRepeatCountProp, "1"); |
377 | addPropValue(a, VCDisplayStringProp, "beep!"); | 380 | addPropValue(a, VCDisplayStringProp, "beep!"); |
378 | } | 381 | } |
379 | } | 382 | } |
380 | } | 383 | } |
381 | 384 | ||
382 | if (anEvent->pilotId()) { | 385 | if (anEvent->pilotId()) { |
383 | // pilot sync stuff | 386 | // pilot sync stuff |
384 | tmpStr.sprintf("%i",anEvent->pilotId()); | 387 | tmpStr.sprintf("%i",anEvent->pilotId()); |
385 | addPropValue(vtodo, XPilotIdProp, tmpStr.local8Bit()); | 388 | addPropValue(vtodo, XPilotIdProp, tmpStr.local8Bit()); |
386 | tmpStr.sprintf("%i",anEvent->syncStatus()); | 389 | tmpStr.sprintf("%i",anEvent->syncStatus()); |
387 | addPropValue(vtodo, XPilotStatusProp, tmpStr.local8Bit()); | 390 | addPropValue(vtodo, XPilotStatusProp, tmpStr.local8Bit()); |
388 | } | 391 | } |
389 | 392 | ||
390 | return vtodo; | 393 | return vtodo; |
391 | } | 394 | } |
392 | 395 | ||
393 | VObject* VCalFormat::eventToVEvent(const Event *anEvent) | 396 | VObject* VCalFormat::eventToVEvent(const Event *anEvent) |
394 | { | 397 | { |
395 | VObject *vevent; | 398 | VObject *vevent; |
396 | QString tmpStr; | 399 | QString tmpStr; |
397 | QStringList tmpStrList; | 400 | QStringList tmpStrList; |
398 | 401 | ||
399 | vevent = newVObject(VCEventProp); | 402 | vevent = newVObject(VCEventProp); |
400 | 403 | ||
401 | // start and end time | 404 | // start and end time |
402 | tmpStr = qDateTimeToISO(anEvent->dtStart(), | 405 | tmpStr = qDateTimeToISO(anEvent->dtStart(), |
403 | !anEvent->doesFloat()); | 406 | !anEvent->doesFloat()); |
404 | addPropValue(vevent, VCDTstartProp, tmpStr.local8Bit()); | 407 | addPropValue(vevent, VCDTstartProp, tmpStr.local8Bit()); |
405 | 408 | ||
406 | // events that have time associated but take up no time should | 409 | // events that have time associated but take up no time should |
407 | // not have both DTSTART and DTEND. | 410 | // not have both DTSTART and DTEND. |
408 | if (anEvent->dtStart() != anEvent->dtEnd()) { | 411 | if (anEvent->dtStart() != anEvent->dtEnd()) { |
409 | tmpStr = qDateTimeToISO(anEvent->dtEnd(), | 412 | tmpStr = qDateTimeToISO(anEvent->dtEnd(), |
410 | !anEvent->doesFloat()); | 413 | !anEvent->doesFloat()); |
411 | addPropValue(vevent, VCDTendProp, tmpStr.local8Bit()); | 414 | addPropValue(vevent, VCDTendProp, tmpStr.local8Bit()); |
412 | } | 415 | } |
413 | 416 | ||
414 | // creation date | 417 | // creation date |
415 | tmpStr = qDateTimeToISO(anEvent->created()); | 418 | tmpStr = qDateTimeToISO(anEvent->created()); |
416 | addPropValue(vevent, VCDCreatedProp, tmpStr.local8Bit()); | 419 | addPropValue(vevent, VCDCreatedProp, tmpStr.local8Bit()); |
417 | 420 | ||
418 | // unique id | 421 | // unique id |
419 | addPropValue(vevent, VCUniqueStringProp, | 422 | addPropValue(vevent, VCUniqueStringProp, |
420 | anEvent->uid().local8Bit()); | 423 | anEvent->uid().local8Bit()); |
421 | 424 | ||
422 | // revision | 425 | // revision |
423 | tmpStr.sprintf("%i", anEvent->revision()); | 426 | tmpStr.sprintf("%i", anEvent->revision()); |
424 | addPropValue(vevent, VCSequenceProp, tmpStr.local8Bit()); | 427 | addPropValue(vevent, VCSequenceProp, tmpStr.local8Bit()); |
425 | 428 | ||
426 | // last modification date | 429 | // last modification date |
427 | tmpStr = qDateTimeToISO(anEvent->lastModified()); | 430 | tmpStr = qDateTimeToISO(anEvent->lastModified()); |
428 | addPropValue(vevent, VCLastModifiedProp, tmpStr.local8Bit()); | 431 | addPropValue(vevent, VCLastModifiedProp, tmpStr.local8Bit()); |
429 | 432 | ||
430 | // attendee and organizer stuff | 433 | // attendee and organizer stuff |
431 | tmpStr = "MAILTO:" + anEvent->organizer(); | 434 | tmpStr = "MAILTO:" + anEvent->organizer(); |
432 | addPropValue(vevent, ICOrganizerProp, tmpStr.local8Bit()); | 435 | addPropValue(vevent, ICOrganizerProp, tmpStr.local8Bit()); |
433 | 436 | ||
434 | if (anEvent->attendeeCount() != 0) { | 437 | if (anEvent->attendeeCount() != 0) { |
435 | QPtrList<Attendee> al = anEvent->attendees(); | 438 | QPtrList<Attendee> al = anEvent->attendees(); |
436 | QPtrListIterator<Attendee> ai(al); | 439 | QPtrListIterator<Attendee> ai(al); |
437 | Attendee *curAttendee; | 440 | Attendee *curAttendee; |
438 | 441 | ||
439 | // TODO: Put this functionality into Attendee class | 442 | // TODO: Put this functionality into Attendee class |
440 | for (; ai.current(); ++ai) { | 443 | for (; ai.current(); ++ai) { |
441 | curAttendee = ai.current(); | 444 | curAttendee = ai.current(); |
442 | if (!curAttendee->email().isEmpty() && | 445 | if (!curAttendee->email().isEmpty() && |
443 | !curAttendee->name().isEmpty()) | 446 | !curAttendee->name().isEmpty()) |
444 | tmpStr = "MAILTO:" + curAttendee->name() + " <" + | 447 | tmpStr = "MAILTO:" + curAttendee->name() + " <" + |
445 | curAttendee->email() + ">"; | 448 | curAttendee->email() + ">"; |
446 | else if (curAttendee->name().isEmpty()) | 449 | else if (curAttendee->name().isEmpty()) |
447 | tmpStr = "MAILTO: " + curAttendee->email(); | 450 | tmpStr = "MAILTO: " + curAttendee->email(); |
448 | else if (curAttendee->email().isEmpty()) | 451 | else if (curAttendee->email().isEmpty()) |
449 | tmpStr = "MAILTO: " + curAttendee->name(); | 452 | tmpStr = "MAILTO: " + curAttendee->name(); |
450 | else if (curAttendee->name().isEmpty() && | 453 | else if (curAttendee->name().isEmpty() && |
451 | curAttendee->email().isEmpty()) | 454 | curAttendee->email().isEmpty()) |
452 | kdDebug(5800) << "warning! this Event has an attendee w/o name or email!" << endl; | 455 | kdDebug(5800) << "warning! this Event has an attendee w/o name or email!" << endl; |
453 | VObject *aProp = addPropValue(vevent, VCAttendeeProp, tmpStr.local8Bit()); | 456 | VObject *aProp = addPropValue(vevent, VCAttendeeProp, tmpStr.local8Bit()); |
454 | addPropValue(aProp, VCRSVPProp, curAttendee->RSVP() ? "TRUE" : "FALSE");; | 457 | addPropValue(aProp, VCRSVPProp, curAttendee->RSVP() ? "TRUE" : "FALSE");; |
455 | addPropValue(aProp, VCStatusProp, writeStatus(curAttendee->status())); | 458 | addPropValue(aProp, VCStatusProp, writeStatus(curAttendee->status())); |
456 | } | 459 | } |
457 | } | 460 | } |
458 | 461 | ||
459 | // recurrence rule stuff | 462 | // recurrence rule stuff |
460 | if (anEvent->recurrence()->doesRecur()) { | 463 | if (anEvent->recurrence()->doesRecur()) { |
461 | // some more variables | 464 | // some more variables |
462 | QPtrList<Recurrence::rMonthPos> tmpPositions; | 465 | QPtrList<Recurrence::rMonthPos> tmpPositions; |
463 | QPtrList<int> tmpDays; | 466 | QPtrList<int> tmpDays; |
464 | int *tmpDay; | 467 | int *tmpDay; |
465 | Recurrence::rMonthPos *tmpPos; | 468 | Recurrence::rMonthPos *tmpPos; |
466 | QString tmpStr2; | 469 | QString tmpStr2; |
467 | int i; | 470 | int i; |
468 | 471 | ||
469 | switch(anEvent->recurrence()->doesRecur()) { | 472 | switch(anEvent->recurrence()->doesRecur()) { |
470 | case Recurrence::rDaily: | 473 | case Recurrence::rDaily: |
471 | tmpStr.sprintf("D%i ",anEvent->recurrence()->frequency()); | 474 | tmpStr.sprintf("D%i ",anEvent->recurrence()->frequency()); |
472 | // if (anEvent->rDuration > 0) | 475 | // if (anEvent->rDuration > 0) |
473 | //tmpStr += "#"; | 476 | //tmpStr += "#"; |
474 | break; | 477 | break; |
475 | case Recurrence::rWeekly: | 478 | case Recurrence::rWeekly: |
476 | tmpStr.sprintf("W%i ",anEvent->recurrence()->frequency()); | 479 | tmpStr.sprintf("W%i ",anEvent->recurrence()->frequency()); |
477 | for (i = 0; i < 7; i++) { | 480 | for (i = 0; i < 7; i++) { |
478 | if (anEvent->recurrence()->days().testBit(i)) | 481 | if (anEvent->recurrence()->days().testBit(i)) |
479 | tmpStr += dayFromNum(i); | 482 | tmpStr += dayFromNum(i); |
480 | } | 483 | } |
481 | break; | 484 | break; |
482 | case Recurrence::rMonthlyPos: | 485 | case Recurrence::rMonthlyPos: |
483 | tmpStr.sprintf("MP%i ", anEvent->recurrence()->frequency()); | 486 | tmpStr.sprintf("MP%i ", anEvent->recurrence()->frequency()); |
484 | // write out all rMonthPos's | 487 | // write out all rMonthPos's |
485 | tmpPositions = anEvent->recurrence()->monthPositions(); | 488 | tmpPositions = anEvent->recurrence()->monthPositions(); |
486 | for (tmpPos = tmpPositions.first(); | 489 | for (tmpPos = tmpPositions.first(); |
487 | tmpPos; | 490 | tmpPos; |
488 | tmpPos = tmpPositions.next()) { | 491 | tmpPos = tmpPositions.next()) { |
489 | 492 | ||
490 | tmpStr2.sprintf("%i", tmpPos->rPos); | 493 | tmpStr2.sprintf("%i", tmpPos->rPos); |
491 | if (tmpPos->negative) | 494 | if (tmpPos->negative) |
492 | tmpStr2 += "- "; | 495 | tmpStr2 += "- "; |
493 | else | 496 | else |
494 | tmpStr2 += "+ "; | 497 | tmpStr2 += "+ "; |
495 | tmpStr += tmpStr2; | 498 | tmpStr += tmpStr2; |
496 | for (i = 0; i < 7; i++) { | 499 | for (i = 0; i < 7; i++) { |
497 | if (tmpPos->rDays.testBit(i)) | 500 | if (tmpPos->rDays.testBit(i)) |
498 | tmpStr += dayFromNum(i); | 501 | tmpStr += dayFromNum(i); |
499 | } | 502 | } |
500 | } // loop for all rMonthPos's | 503 | } // loop for all rMonthPos's |
501 | break; | 504 | break; |
502 | case Recurrence::rMonthlyDay: | 505 | case Recurrence::rMonthlyDay: |
503 | tmpStr.sprintf("MD%i ", anEvent->recurrence()->frequency()); | 506 | tmpStr.sprintf("MD%i ", anEvent->recurrence()->frequency()); |
504 | // write out all rMonthDays; | 507 | // write out all rMonthDays; |
505 | tmpDays = anEvent->recurrence()->monthDays(); | 508 | tmpDays = anEvent->recurrence()->monthDays(); |
506 | for (tmpDay = tmpDays.first(); | 509 | for (tmpDay = tmpDays.first(); |
507 | tmpDay; | 510 | tmpDay; |
508 | tmpDay = tmpDays.next()) { | 511 | tmpDay = tmpDays.next()) { |
509 | tmpStr2.sprintf("%i ", *tmpDay); | 512 | tmpStr2.sprintf("%i ", *tmpDay); |
510 | tmpStr += tmpStr2; | 513 | tmpStr += tmpStr2; |
511 | } | 514 | } |
512 | break; | 515 | break; |
513 | case Recurrence::rYearlyMonth: | 516 | case Recurrence::rYearlyMonth: |
514 | tmpStr.sprintf("YM%i ", anEvent->recurrence()->frequency()); | 517 | tmpStr.sprintf("YM%i ", anEvent->recurrence()->frequency()); |
515 | // write out all the rYearNums; | 518 | // write out all the rYearNums; |
516 | tmpDays = anEvent->recurrence()->yearNums(); | 519 | tmpDays = anEvent->recurrence()->yearNums(); |
517 | for (tmpDay = tmpDays.first(); | 520 | for (tmpDay = tmpDays.first(); |
518 | tmpDay; | 521 | tmpDay; |
519 | tmpDay = tmpDays.next()) { | 522 | tmpDay = tmpDays.next()) { |
520 | tmpStr2.sprintf("%i ", *tmpDay); | 523 | tmpStr2.sprintf("%i ", *tmpDay); |
521 | tmpStr += tmpStr2; | 524 | tmpStr += tmpStr2; |
522 | } | 525 | } |
523 | break; | 526 | break; |
524 | case Recurrence::rYearlyDay: | 527 | case Recurrence::rYearlyDay: |
525 | tmpStr.sprintf("YD%i ", anEvent->recurrence()->frequency()); | 528 | tmpStr.sprintf("YD%i ", anEvent->recurrence()->frequency()); |
526 | // write out all the rYearNums; | 529 | // write out all the rYearNums; |
527 | tmpDays = anEvent->recurrence()->yearNums(); | 530 | tmpDays = anEvent->recurrence()->yearNums(); |
528 | for (tmpDay = tmpDays.first(); | 531 | for (tmpDay = tmpDays.first(); |
529 | tmpDay; | 532 | tmpDay; |
530 | tmpDay = tmpDays.next()) { | 533 | tmpDay = tmpDays.next()) { |
531 | tmpStr2.sprintf("%i ", *tmpDay); | 534 | tmpStr2.sprintf("%i ", *tmpDay); |
532 | tmpStr += tmpStr2; | 535 | tmpStr += tmpStr2; |
533 | } | 536 | } |
534 | break; | 537 | break; |
535 | default: | 538 | default: |
536 | kdDebug(5800) << "ERROR, it should never get here in eventToVEvent!" << endl; | 539 | kdDebug(5800) << "ERROR, it should never get here in eventToVEvent!" << endl; |
537 | break; | 540 | break; |
538 | } // switch | 541 | } // switch |
539 | 542 | ||
540 | if (anEvent->recurrence()->duration() > 0) { | 543 | if (anEvent->recurrence()->duration() > 0) { |
541 | tmpStr2.sprintf("#%i",anEvent->recurrence()->duration()); | 544 | tmpStr2.sprintf("#%i",anEvent->recurrence()->duration()); |
542 | tmpStr += tmpStr2; | 545 | tmpStr += tmpStr2; |
543 | } else if (anEvent->recurrence()->duration() == -1) { | 546 | } else if (anEvent->recurrence()->duration() == -1) { |
544 | tmpStr += "#0"; // defined as repeat forever | 547 | tmpStr += "#0"; // defined as repeat forever |
545 | } else { | 548 | } else { |
546 | tmpStr += qDateTimeToISO(anEvent->recurrence()->endDate(), FALSE); | 549 | tmpStr += qDateTimeToISO(anEvent->recurrence()->endDate(), FALSE); |
547 | } | 550 | } |
548 | addPropValue(vevent,VCRRuleProp, tmpStr.local8Bit()); | 551 | addPropValue(vevent,VCRRuleProp, tmpStr.local8Bit()); |
549 | 552 | ||
550 | } // event repeats | 553 | } // event repeats |
551 | 554 | ||
552 | // exceptions to recurrence | 555 | // exceptions to recurrence |
553 | DateList dateList = anEvent->exDates(); | 556 | DateList dateList = anEvent->exDates(); |
554 | DateList::ConstIterator it; | 557 | DateList::ConstIterator it; |
555 | QString tmpStr2; | 558 | QString tmpStr2; |
556 | 559 | ||
557 | for (it = dateList.begin(); it != dateList.end(); ++it) { | 560 | for (it = dateList.begin(); it != dateList.end(); ++it) { |
558 | tmpStr = qDateToISO(*it) + ";"; | 561 | tmpStr = qDateToISO(*it) + ";"; |
559 | tmpStr2 += tmpStr; | 562 | tmpStr2 += tmpStr; |
560 | } | 563 | } |
561 | if (!tmpStr2.isEmpty()) { | 564 | if (!tmpStr2.isEmpty()) { |
562 | tmpStr2.truncate(tmpStr2.length()-1); | 565 | tmpStr2.truncate(tmpStr2.length()-1); |
563 | addPropValue(vevent, VCExpDateProp, tmpStr2.local8Bit()); | 566 | addPropValue(vevent, VCExpDateProp, tmpStr2.local8Bit()); |
564 | } | 567 | } |
565 | 568 | ||
566 | // description | 569 | // description |
567 | if (!anEvent->description().isEmpty()) { | 570 | if (!anEvent->description().isEmpty()) { |
568 | VObject *d = addPropValue(vevent, VCDescriptionProp, | 571 | VObject *d = addPropValue(vevent, VCDescriptionProp, |
569 | anEvent->description().local8Bit()); | 572 | anEvent->description().local8Bit()); |
570 | if (anEvent->description().find('\n') != -1) | 573 | if (anEvent->description().find('\n') != -1) |
571 | addProp(d, VCQuotedPrintableProp); | 574 | addProp(d, VCQuotedPrintableProp); |
572 | } | 575 | } |
573 | 576 | ||
574 | // summary | 577 | // summary |
575 | if (!anEvent->summary().isEmpty()) | 578 | if (!anEvent->summary().isEmpty()) |
576 | addPropValue(vevent, VCSummaryProp, anEvent->summary().local8Bit()); | 579 | addPropValue(vevent, VCSummaryProp, anEvent->summary().local8Bit()); |
577 | 580 | ||
578 | if (!anEvent->location().isEmpty()) | 581 | if (!anEvent->location().isEmpty()) |
579 | addPropValue(vevent, VCLocationProp, anEvent->location().local8Bit()); | 582 | addPropValue(vevent, VCLocationProp, anEvent->location().local8Bit()); |
580 | 583 | ||
581 | // status | 584 | // status |
582 | // TODO: define Event status | 585 | // TODO: define Event status |
583 | // addPropValue(vevent, VCStatusProp, anEvent->statusStr().local8Bit()); | 586 | // addPropValue(vevent, VCStatusProp, anEvent->statusStr().local8Bit()); |
584 | 587 | ||
585 | // secrecy | 588 | // secrecy |
586 | const char *text = 0; | 589 | const char *text = 0; |
587 | switch (anEvent->secrecy()) { | 590 | switch (anEvent->secrecy()) { |
588 | case Incidence::SecrecyPublic: | 591 | case Incidence::SecrecyPublic: |
589 | text = "PUBLIC"; | 592 | text = "PUBLIC"; |
590 | break; | 593 | break; |
591 | case Incidence::SecrecyPrivate: | 594 | case Incidence::SecrecyPrivate: |
592 | text = "PRIVATE"; | 595 | text = "PRIVATE"; |
593 | break; | 596 | break; |
594 | case Incidence::SecrecyConfidential: | 597 | case Incidence::SecrecyConfidential: |
595 | text = "CONFIDENTIAL"; | 598 | text = "CONFIDENTIAL"; |
596 | break; | 599 | break; |
597 | } | 600 | } |
598 | if (text) { | 601 | if (text) { |
599 | addPropValue(vevent, VCClassProp, text); | 602 | addPropValue(vevent, VCClassProp, text); |
600 | } | 603 | } |
601 | 604 | ||
602 | // categories | 605 | // categories |
603 | tmpStrList = anEvent->categories(); | 606 | tmpStrList = anEvent->categories(); |
604 | tmpStr = ""; | 607 | tmpStr = ""; |
605 | QString catStr; | 608 | QString catStr; |
606 | for ( QStringList::Iterator it = tmpStrList.begin(); | 609 | for ( QStringList::Iterator it = tmpStrList.begin(); |
607 | it != tmpStrList.end(); | 610 | it != tmpStrList.end(); |
608 | ++it ) { | 611 | ++it ) { |
609 | catStr = *it; | 612 | catStr = *it; |
610 | if (catStr[0] == ' ') | 613 | if (catStr[0] == ' ') |
611 | tmpStr += catStr.mid(1); | 614 | tmpStr += catStr.mid(1); |
612 | else | 615 | else |
613 | tmpStr += catStr; | 616 | tmpStr += catStr; |
614 | // this must be a ';' character as the vCalendar specification requires! | 617 | // this must be a ';' character as the vCalendar specification requires! |
615 | // vcc.y has been hacked to translate the ';' to a ',' when the vcal is | 618 | // vcc.y has been hacked to translate the ';' to a ',' when the vcal is |
616 | // read in. | 619 | // read in. |
617 | tmpStr += ";"; | 620 | tmpStr += ";"; |
618 | } | 621 | } |
619 | if (!tmpStr.isEmpty()) { | 622 | if (!tmpStr.isEmpty()) { |
620 | tmpStr.truncate(tmpStr.length()-1); | 623 | tmpStr.truncate(tmpStr.length()-1); |
621 | addPropValue(vevent, VCCategoriesProp, tmpStr.local8Bit()); | 624 | addPropValue(vevent, VCCategoriesProp, tmpStr.local8Bit()); |
622 | } | 625 | } |
623 | 626 | ||
624 | // attachments | 627 | // attachments |
625 | // TODO: handle binary attachments! | 628 | // TODO: handle binary attachments! |
626 | QPtrList<Attachment> attachments = anEvent->attachments(); | 629 | QPtrList<Attachment> attachments = anEvent->attachments(); |
627 | for ( Attachment *at = attachments.first(); at; at = attachments.next() ) | 630 | for ( Attachment *at = attachments.first(); at; at = attachments.next() ) |
628 | addPropValue(vevent, VCAttachProp, at->uri().local8Bit()); | 631 | addPropValue(vevent, VCAttachProp, at->uri().local8Bit()); |
629 | 632 | ||
630 | // resources | 633 | // resources |
631 | tmpStrList = anEvent->resources(); | 634 | tmpStrList = anEvent->resources(); |
632 | tmpStr = tmpStrList.join(";"); | 635 | tmpStr = tmpStrList.join(";"); |
633 | if (!tmpStr.isEmpty()) | 636 | if (!tmpStr.isEmpty()) |
634 | addPropValue(vevent, VCResourcesProp, tmpStr.local8Bit()); | 637 | addPropValue(vevent, VCResourcesProp, tmpStr.local8Bit()); |
635 | 638 | ||
636 | // alarm stuff | 639 | // alarm stuff |
637 | QPtrList<Alarm> alarms = anEvent->alarms(); | 640 | QPtrList<Alarm> alarms = anEvent->alarms(); |
638 | Alarm* alarm; | 641 | Alarm* alarm; |
639 | for (alarm = alarms.first(); alarm; alarm = alarms.next()) { | 642 | for (alarm = alarms.first(); alarm; alarm = alarms.next()) { |
640 | if (alarm->enabled()) { | 643 | if (alarm->enabled()) { |
641 | VObject *a ; | 644 | VObject *a ; |
642 | tmpStr = qDateTimeToISO(alarm->time()); | 645 | tmpStr = qDateTimeToISO(alarm->time()); |
643 | if (alarm->type() == Alarm::Audio) { | 646 | if (alarm->type() == Alarm::Audio) { |
644 | a = addProp(vevent, VCAAlarmProp); | 647 | a = addProp(vevent, VCAAlarmProp); |
645 | addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); | 648 | addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); |
646 | addPropValue(a, VCRepeatCountProp, "1"); | 649 | addPropValue(a, VCRepeatCountProp, "1"); |
647 | addPropValue(a, VCAudioContentProp, QFile::encodeName(alarm->audioFile())); | 650 | addPropValue(a, VCAudioContentProp, QFile::encodeName(alarm->audioFile())); |
648 | } | 651 | } |
649 | if (alarm->type() == Alarm::Procedure) { | 652 | if (alarm->type() == Alarm::Procedure) { |
650 | a = addProp(vevent, VCPAlarmProp); | 653 | a = addProp(vevent, VCPAlarmProp); |
651 | addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); | 654 | addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); |
652 | addPropValue(a, VCRepeatCountProp, "1"); | 655 | addPropValue(a, VCRepeatCountProp, "1"); |
653 | addPropValue(a, VCProcedureNameProp, QFile::encodeName(alarm->programFile())); | 656 | addPropValue(a, VCProcedureNameProp, QFile::encodeName(alarm->programFile())); |
654 | } else { | 657 | } else { |
655 | a = addProp(vevent, VCDAlarmProp); | 658 | a = addProp(vevent, VCDAlarmProp); |
656 | addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); | 659 | addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); |
657 | addPropValue(a, VCRepeatCountProp, "1"); | 660 | addPropValue(a, VCRepeatCountProp, "1"); |
658 | addPropValue(a, VCDisplayStringProp, "beep!"); | 661 | addPropValue(a, VCDisplayStringProp, "beep!"); |
659 | 662 | ||
660 | } | 663 | } |
661 | } | 664 | } |
662 | } | 665 | } |
663 | 666 | ||
664 | // priority | 667 | // priority |
665 | tmpStr.sprintf("%i",anEvent->priority()); | 668 | tmpStr.sprintf("%i",anEvent->priority()); |
666 | addPropValue(vevent, VCPriorityProp, tmpStr.local8Bit()); | 669 | addPropValue(vevent, VCPriorityProp, tmpStr.local8Bit()); |
667 | 670 | ||
668 | // transparency | 671 | // transparency |
669 | tmpStr.sprintf("%i",anEvent->transparency()); | 672 | tmpStr.sprintf("%i",anEvent->transparency()); |
670 | addPropValue(vevent, VCTranspProp, tmpStr.local8Bit()); | 673 | addPropValue(vevent, VCTranspProp, tmpStr.local8Bit()); |
671 | 674 | ||
672 | // related event | 675 | // related event |
673 | if (anEvent->relatedTo()) { | 676 | if (anEvent->relatedTo()) { |
674 | addPropValue(vevent, VCRelatedToProp, | 677 | addPropValue(vevent, VCRelatedToProp, |
675 | anEvent->relatedTo()->uid().local8Bit()); | 678 | anEvent->relatedTo()->uid().local8Bit()); |
676 | } | 679 | } |
677 | 680 | ||
678 | if (anEvent->pilotId()) { | 681 | if (anEvent->pilotId()) { |
679 | // pilot sync stuff | 682 | // pilot sync stuff |
680 | tmpStr.sprintf("%i",anEvent->pilotId()); | 683 | tmpStr.sprintf("%i",anEvent->pilotId()); |
681 | addPropValue(vevent, XPilotIdProp, tmpStr.local8Bit()); | 684 | addPropValue(vevent, XPilotIdProp, tmpStr.local8Bit()); |
682 | tmpStr.sprintf("%i",anEvent->syncStatus()); | 685 | tmpStr.sprintf("%i",anEvent->syncStatus()); |
683 | addPropValue(vevent, XPilotStatusProp, tmpStr.local8Bit()); | 686 | addPropValue(vevent, XPilotStatusProp, tmpStr.local8Bit()); |
684 | } | 687 | } |
685 | 688 | ||
686 | return vevent; | 689 | return vevent; |
687 | } | 690 | } |
688 | 691 | ||
689 | Todo *VCalFormat::VTodoToEvent(VObject *vtodo) | 692 | Todo *VCalFormat::VTodoToEvent(VObject *vtodo) |
690 | { | 693 | { |
691 | VObject *vo; | 694 | VObject *vo; |
692 | VObjectIterator voi; | 695 | VObjectIterator voi; |
693 | char *s; | 696 | char *s; |
694 | 697 | ||
695 | Todo *anEvent = new Todo; | 698 | Todo *anEvent = new Todo; |
696 | 699 | ||
697 | // creation date | 700 | // creation date |
698 | if ((vo = isAPropertyOf(vtodo, VCDCreatedProp)) != 0) { | 701 | if ((vo = isAPropertyOf(vtodo, VCDCreatedProp)) != 0) { |
699 | anEvent->setCreated(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); | 702 | anEvent->setCreated(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); |
700 | deleteStr(s); | 703 | deleteStr(s); |
701 | } | 704 | } |
702 | 705 | ||
703 | // unique id | 706 | // unique id |
704 | vo = isAPropertyOf(vtodo, VCUniqueStringProp); | 707 | vo = isAPropertyOf(vtodo, VCUniqueStringProp); |
705 | // while the UID property is preferred, it is not required. We'll use the | 708 | // while the UID property is preferred, it is not required. We'll use the |
706 | // default Event UID if none is given. | 709 | // default Event UID if none is given. |
707 | if (vo) { | 710 | if (vo) { |
708 | anEvent->setUid(s = fakeCString(vObjectUStringZValue(vo))); | 711 | anEvent->setUid(s = fakeCString(vObjectUStringZValue(vo))); |
709 | deleteStr(s); | 712 | deleteStr(s); |
710 | } | 713 | } |
711 | 714 | ||
712 | // last modification date | 715 | // last modification date |
713 | if ((vo = isAPropertyOf(vtodo, VCLastModifiedProp)) != 0) { | 716 | if ((vo = isAPropertyOf(vtodo, VCLastModifiedProp)) != 0) { |
714 | anEvent->setLastModified(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); | 717 | anEvent->setLastModified(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); |
715 | deleteStr(s); | 718 | deleteStr(s); |
716 | } | 719 | } |
717 | else | 720 | else |
718 | anEvent->setLastModified(QDateTime(QDate::currentDate(), | 721 | anEvent->setLastModified(QDateTime(QDate::currentDate(), |
719 | QTime::currentTime())); | 722 | QTime::currentTime())); |
720 | 723 | ||
721 | // organizer | 724 | // organizer |
722 | // if our extension property for the event's ORGANIZER exists, add it. | 725 | // if our extension property for the event's ORGANIZER exists, add it. |
723 | if ((vo = isAPropertyOf(vtodo, ICOrganizerProp)) != 0) { | 726 | if ((vo = isAPropertyOf(vtodo, ICOrganizerProp)) != 0) { |
724 | anEvent->setOrganizer(s = fakeCString(vObjectUStringZValue(vo))); | 727 | anEvent->setOrganizer(s = fakeCString(vObjectUStringZValue(vo))); |
725 | deleteStr(s); | 728 | deleteStr(s); |
726 | } else { | 729 | } else { |
727 | anEvent->setOrganizer(mCalendar->getEmail()); | 730 | anEvent->setOrganizer(mCalendar->getEmail()); |
728 | } | 731 | } |
729 | 732 | ||
730 | // attendees. | 733 | // attendees. |
731 | initPropIterator(&voi, vtodo); | 734 | initPropIterator(&voi, vtodo); |
732 | while (moreIteration(&voi)) { | 735 | while (moreIteration(&voi)) { |
733 | vo = nextVObject(&voi); | 736 | vo = nextVObject(&voi); |
734 | if (strcmp(vObjectName(vo), VCAttendeeProp) == 0) { | 737 | if (strcmp(vObjectName(vo), VCAttendeeProp) == 0) { |
735 | Attendee *a; | 738 | Attendee *a; |
736 | VObject *vp; | 739 | VObject *vp; |
737 | s = fakeCString(vObjectUStringZValue(vo)); | 740 | s = fakeCString(vObjectUStringZValue(vo)); |
738 | QString tmpStr = QString::fromLocal8Bit(s); | 741 | QString tmpStr = QString::fromLocal8Bit(s); |
739 | deleteStr(s); | 742 | deleteStr(s); |
740 | tmpStr = tmpStr.simplifyWhiteSpace(); | 743 | tmpStr = tmpStr.simplifyWhiteSpace(); |
741 | int emailPos1, emailPos2; | 744 | int emailPos1, emailPos2; |
742 | if ((emailPos1 = tmpStr.find('<')) > 0) { | 745 | if ((emailPos1 = tmpStr.find('<')) > 0) { |
743 | // both email address and name | 746 | // both email address and name |
744 | emailPos2 = tmpStr.findRev('>'); | 747 | emailPos2 = tmpStr.findRev('>'); |
745 | a = new Attendee(tmpStr.left(emailPos1 - 1), | 748 | a = new Attendee(tmpStr.left(emailPos1 - 1), |
746 | tmpStr.mid(emailPos1 + 1, | 749 | tmpStr.mid(emailPos1 + 1, |
747 | emailPos2 - (emailPos1 + 1))); | 750 | emailPos2 - (emailPos1 + 1))); |
748 | } else if (tmpStr.find('@') > 0) { | 751 | } else if (tmpStr.find('@') > 0) { |
749 | // just an email address | 752 | // just an email address |
750 | a = new Attendee(0, tmpStr); | 753 | a = new Attendee(0, tmpStr); |
751 | } else { | 754 | } else { |
752 | // just a name | 755 | // just a name |
753 | QString email = tmpStr.replace( QRegExp(" "), "." ); | 756 | QString email = tmpStr.replace( QRegExp(" "), "." ); |
754 | a = new Attendee(tmpStr,email); | 757 | a = new Attendee(tmpStr,email); |
755 | } | 758 | } |
756 | 759 | ||
757 | // is there an RSVP property? | 760 | // is there an RSVP property? |
758 | if ((vp = isAPropertyOf(vo, VCRSVPProp)) != 0) | 761 | if ((vp = isAPropertyOf(vo, VCRSVPProp)) != 0) |
759 | a->setRSVP(vObjectStringZValue(vp)); | 762 | a->setRSVP(vObjectStringZValue(vp)); |
760 | // is there a status property? | 763 | // is there a status property? |
761 | if ((vp = isAPropertyOf(vo, VCStatusProp)) != 0) | 764 | if ((vp = isAPropertyOf(vo, VCStatusProp)) != 0) |
762 | a->setStatus(readStatus(vObjectStringZValue(vp))); | 765 | a->setStatus(readStatus(vObjectStringZValue(vp))); |
763 | // add the attendee | 766 | // add the attendee |
764 | anEvent->addAttendee(a); | 767 | anEvent->addAttendee(a); |
765 | } | 768 | } |
766 | } | 769 | } |
767 | 770 | ||
768 | // description for todo | 771 | // description for todo |
769 | if ((vo = isAPropertyOf(vtodo, VCDescriptionProp)) != 0) { | 772 | if ((vo = isAPropertyOf(vtodo, VCDescriptionProp)) != 0) { |
770 | s = fakeCString(vObjectUStringZValue(vo)); | 773 | s = fakeCString(vObjectUStringZValue(vo)); |
771 | anEvent->setDescription(QString::fromLocal8Bit(s)); | 774 | anEvent->setDescription(QString::fromLocal8Bit(s)); |
772 | deleteStr(s); | 775 | deleteStr(s); |
773 | } | 776 | } |
774 | 777 | ||
775 | // summary | 778 | // summary |
776 | if ((vo = isAPropertyOf(vtodo, VCSummaryProp))) { | 779 | if ((vo = isAPropertyOf(vtodo, VCSummaryProp))) { |
777 | s = fakeCString(vObjectUStringZValue(vo)); | 780 | s = fakeCString(vObjectUStringZValue(vo)); |
778 | anEvent->setSummary(QString::fromLocal8Bit(s)); | 781 | anEvent->setSummary(QString::fromLocal8Bit(s)); |
779 | deleteStr(s); | 782 | deleteStr(s); |
780 | } | 783 | } |
781 | if ((vo = isAPropertyOf(vtodo, VCLocationProp))) { | 784 | if ((vo = isAPropertyOf(vtodo, VCLocationProp))) { |
782 | s = fakeCString(vObjectUStringZValue(vo)); | 785 | s = fakeCString(vObjectUStringZValue(vo)); |
783 | anEvent->setLocation(QString::fromLocal8Bit(s)); | 786 | anEvent->setLocation(QString::fromLocal8Bit(s)); |
784 | deleteStr(s); | 787 | deleteStr(s); |
785 | } | 788 | } |
786 | 789 | ||
787 | 790 | ||
788 | // completed | 791 | // completed |
789 | // was: status | 792 | // was: status |
790 | if ((vo = isAPropertyOf(vtodo, VCStatusProp)) != 0) { | 793 | if ((vo = isAPropertyOf(vtodo, VCStatusProp)) != 0) { |
791 | s = fakeCString(vObjectUStringZValue(vo)); | 794 | s = fakeCString(vObjectUStringZValue(vo)); |
792 | if (strcmp(s,"COMPLETED") == 0) { | 795 | if (strcmp(s,"COMPLETED") == 0) { |
793 | anEvent->setCompleted(true); | 796 | anEvent->setCompleted(true); |
794 | } else { | 797 | } else { |
795 | anEvent->setCompleted(false); | 798 | anEvent->setCompleted(false); |
796 | } | 799 | } |
797 | deleteStr(s); | 800 | deleteStr(s); |
798 | } | 801 | } |
799 | else | 802 | else |
800 | anEvent->setCompleted(false); | 803 | anEvent->setCompleted(false); |
801 | 804 | ||
802 | // completion date | 805 | // completion date |
803 | if ((vo = isAPropertyOf(vtodo, VCCompletedProp)) != 0) { | 806 | if ((vo = isAPropertyOf(vtodo, VCCompletedProp)) != 0) { |
804 | anEvent->setCompleted(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); | 807 | anEvent->setCompleted(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); |
805 | deleteStr(s); | 808 | deleteStr(s); |
806 | } | 809 | } |
807 | 810 | ||
808 | // priority | 811 | // priority |
809 | if ((vo = isAPropertyOf(vtodo, VCPriorityProp))) { | 812 | if ((vo = isAPropertyOf(vtodo, VCPriorityProp))) { |
810 | anEvent->setPriority(atoi(s = fakeCString(vObjectUStringZValue(vo)))); | 813 | anEvent->setPriority(atoi(s = fakeCString(vObjectUStringZValue(vo)))); |
811 | deleteStr(s); | 814 | deleteStr(s); |
812 | } | 815 | } |
813 | 816 | ||
814 | // due date | 817 | // due date |
815 | if ((vo = isAPropertyOf(vtodo, VCDueProp)) != 0) { | 818 | if ((vo = isAPropertyOf(vtodo, VCDueProp)) != 0) { |
816 | anEvent->setDtDue(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); | 819 | anEvent->setDtDue(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); |
817 | deleteStr(s); | 820 | deleteStr(s); |
818 | anEvent->setHasDueDate(true); | 821 | anEvent->setHasDueDate(true); |
819 | } else { | 822 | } else { |
820 | anEvent->setHasDueDate(false); | 823 | anEvent->setHasDueDate(false); |
821 | } | 824 | } |
822 | 825 | ||
823 | // start time | 826 | // start time |
824 | if ((vo = isAPropertyOf(vtodo, VCDTstartProp)) != 0) { | 827 | if ((vo = isAPropertyOf(vtodo, VCDTstartProp)) != 0) { |
825 | anEvent->setDtStart(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); | 828 | anEvent->setDtStart(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); |
826 | // kdDebug(5800) << "s is " << // s << ", ISO is " << ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo))).toString() << endl; | 829 | // kdDebug(5800) << "s is " << // s << ", ISO is " << ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo))).toString() << endl; |
827 | deleteStr(s); | 830 | deleteStr(s); |
828 | anEvent->setHasStartDate(true); | 831 | anEvent->setHasStartDate(true); |
829 | } else { | 832 | } else { |
830 | anEvent->setHasStartDate(false); | 833 | anEvent->setHasStartDate(false); |
831 | } | 834 | } |
832 | 835 | ||
833 | /* alarm stuff */ | 836 | /* alarm stuff */ |
834 | //kdDebug(5800) << "vcalformat::VTodoToEvent called" << endl; | 837 | //kdDebug(5800) << "vcalformat::VTodoToEvent called" << endl; |
835 | if ((vo = isAPropertyOf(vtodo, VCDAlarmProp))) { | 838 | if ((vo = isAPropertyOf(vtodo, VCDAlarmProp))) { |
836 | Alarm* alarm = anEvent->newAlarm(); | 839 | Alarm* alarm = anEvent->newAlarm(); |
837 | VObject *a; | 840 | VObject *a; |
838 | if ((a = isAPropertyOf(vo, VCRunTimeProp))) { | 841 | if ((a = isAPropertyOf(vo, VCRunTimeProp))) { |
839 | alarm->setTime(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(a)))); | 842 | alarm->setTime(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(a)))); |
840 | deleteStr(s); | 843 | deleteStr(s); |
841 | } | 844 | } |
842 | alarm->setEnabled(true); | 845 | alarm->setEnabled(true); |
843 | if ((vo = isAPropertyOf(vtodo, VCPAlarmProp))) { | 846 | if ((vo = isAPropertyOf(vtodo, VCPAlarmProp))) { |
844 | if ((a = isAPropertyOf(vo, VCProcedureNameProp))) { | 847 | if ((a = isAPropertyOf(vo, VCProcedureNameProp))) { |
845 | s = fakeCString(vObjectUStringZValue(a)); | 848 | s = fakeCString(vObjectUStringZValue(a)); |
846 | alarm->setProcedureAlarm(QFile::decodeName(s)); | 849 | alarm->setProcedureAlarm(QFile::decodeName(s)); |
847 | deleteStr(s); | 850 | deleteStr(s); |
848 | } | 851 | } |
849 | } | 852 | } |
850 | if ((vo = isAPropertyOf(vtodo, VCAAlarmProp))) { | 853 | if ((vo = isAPropertyOf(vtodo, VCAAlarmProp))) { |
851 | if ((a = isAPropertyOf(vo, VCAudioContentProp))) { | 854 | if ((a = isAPropertyOf(vo, VCAudioContentProp))) { |
852 | s = fakeCString(vObjectUStringZValue(a)); | 855 | s = fakeCString(vObjectUStringZValue(a)); |
853 | alarm->setAudioAlarm(QFile::decodeName(s)); | 856 | alarm->setAudioAlarm(QFile::decodeName(s)); |
854 | deleteStr(s); | 857 | deleteStr(s); |
855 | } | 858 | } |
856 | } | 859 | } |
857 | } | 860 | } |
858 | 861 | ||
859 | // related todo | 862 | // related todo |
860 | if ((vo = isAPropertyOf(vtodo, VCRelatedToProp)) != 0) { | 863 | if ((vo = isAPropertyOf(vtodo, VCRelatedToProp)) != 0) { |
861 | anEvent->setRelatedToUid(s = fakeCString(vObjectUStringZValue(vo))); | 864 | anEvent->setRelatedToUid(s = fakeCString(vObjectUStringZValue(vo))); |
862 | deleteStr(s); | 865 | deleteStr(s); |
863 | mTodosRelate.append(anEvent); | 866 | mTodosRelate.append(anEvent); |
864 | } | 867 | } |
865 | 868 | ||
866 | // categories | 869 | // categories |
867 | QStringList tmpStrList; | 870 | QStringList tmpStrList; |
868 | int index1 = 0; | 871 | int index1 = 0; |
869 | int index2 = 0; | 872 | int index2 = 0; |
870 | if ((vo = isAPropertyOf(vtodo, VCCategoriesProp)) != 0) { | 873 | if ((vo = isAPropertyOf(vtodo, VCCategoriesProp)) != 0) { |
871 | s = fakeCString(vObjectUStringZValue(vo)); | 874 | s = fakeCString(vObjectUStringZValue(vo)); |
872 | QString categories = QString::fromLocal8Bit(s); | 875 | QString categories = QString::fromLocal8Bit(s); |
873 | deleteStr(s); | 876 | deleteStr(s); |
874 | //const char* category; | 877 | //const char* category; |
875 | QString category; | 878 | QString category; |
876 | while ((index2 = categories.find(',', index1)) != -1) { | 879 | while ((index2 = categories.find(',', index1)) != -1) { |
877 | //category = (const char *) categories.mid(index1, (index2 - index1)); | 880 | //category = (const char *) categories.mid(index1, (index2 - index1)); |
878 | category = categories.mid(index1, (index2 - index1)); | 881 | category = categories.mid(index1, (index2 - index1)); |
879 | tmpStrList.append(category); | 882 | tmpStrList.append(category); |
880 | index1 = index2+1; | 883 | index1 = index2+1; |
881 | } | 884 | } |
882 | // get last category | 885 | // get last category |
883 | category = categories.mid(index1, (categories.length()-index1)); | 886 | category = categories.mid(index1, (categories.length()-index1)); |
884 | tmpStrList.append(category); | 887 | tmpStrList.append(category); |
885 | anEvent->setCategories(tmpStrList); | 888 | anEvent->setCategories(tmpStrList); |
886 | } | 889 | } |
887 | 890 | ||
888 | /* PILOT SYNC STUFF */ | 891 | /* PILOT SYNC STUFF */ |
889 | if ((vo = isAPropertyOf(vtodo, XPilotIdProp))) { | 892 | if ((vo = isAPropertyOf(vtodo, XPilotIdProp))) { |
890 | anEvent->setPilotId(atoi(s = fakeCString(vObjectUStringZValue(vo)))); | 893 | anEvent->setPilotId(atoi(s = fakeCString(vObjectUStringZValue(vo)))); |
891 | deleteStr(s); | 894 | deleteStr(s); |
892 | } | 895 | } |
893 | else | 896 | else |
894 | anEvent->setPilotId(0); | 897 | anEvent->setPilotId(0); |
895 | 898 | ||
896 | if ((vo = isAPropertyOf(vtodo, XPilotStatusProp))) { | 899 | if ((vo = isAPropertyOf(vtodo, XPilotStatusProp))) { |
897 | anEvent->setSyncStatus(atoi(s = fakeCString(vObjectUStringZValue(vo)))); | 900 | anEvent->setSyncStatus(atoi(s = fakeCString(vObjectUStringZValue(vo)))); |
898 | deleteStr(s); | 901 | deleteStr(s); |
899 | } | 902 | } |
900 | else | 903 | else |
901 | anEvent->setSyncStatus(Event::SYNCMOD); | 904 | anEvent->setSyncStatus(Event::SYNCMOD); |
902 | 905 | ||
903 | return anEvent; | 906 | return anEvent; |
904 | } | 907 | } |
905 | 908 | ||
906 | Event* VCalFormat::VEventToEvent(VObject *vevent) | 909 | Event* VCalFormat::VEventToEvent(VObject *vevent) |
907 | { | 910 | { |
908 | VObject *vo; | 911 | VObject *vo; |
909 | VObjectIterator voi; | 912 | VObjectIterator voi; |
910 | char *s; | 913 | char *s; |
911 | 914 | ||
912 | Event *anEvent = new Event; | 915 | Event *anEvent = new Event; |
913 | 916 | ||
914 | // creation date | 917 | // creation date |
915 | if ((vo = isAPropertyOf(vevent, VCDCreatedProp)) != 0) { | 918 | if ((vo = isAPropertyOf(vevent, VCDCreatedProp)) != 0) { |
916 | anEvent->setCreated(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); | 919 | anEvent->setCreated(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); |
917 | deleteStr(s); | 920 | deleteStr(s); |
918 | } | 921 | } |
919 | 922 | ||
920 | // unique id | 923 | // unique id |
921 | vo = isAPropertyOf(vevent, VCUniqueStringProp); | 924 | vo = isAPropertyOf(vevent, VCUniqueStringProp); |
922 | // while the UID property is preferred, it is not required. We'll use the | 925 | // while the UID property is preferred, it is not required. We'll use the |
923 | // default Event UID if none is given. | 926 | // default Event UID if none is given. |
924 | if (vo) { | 927 | if (vo) { |
925 | anEvent->setUid(s = fakeCString(vObjectUStringZValue(vo))); | 928 | anEvent->setUid(s = fakeCString(vObjectUStringZValue(vo))); |
926 | deleteStr(s); | 929 | deleteStr(s); |
927 | } | 930 | } |
928 | 931 | ||
929 | // revision | 932 | // revision |
930 | // again NSCAL doesn't give us much to work with, so we improvise... | 933 | // again NSCAL doesn't give us much to work with, so we improvise... |
931 | if ((vo = isAPropertyOf(vevent, VCSequenceProp)) != 0) { | 934 | if ((vo = isAPropertyOf(vevent, VCSequenceProp)) != 0) { |
932 | anEvent->setRevision(atoi(s = fakeCString(vObjectUStringZValue(vo)))); | 935 | anEvent->setRevision(atoi(s = fakeCString(vObjectUStringZValue(vo)))); |
933 | deleteStr(s); | 936 | deleteStr(s); |
934 | } | 937 | } |
935 | else | 938 | else |
936 | anEvent->setRevision(0); | 939 | anEvent->setRevision(0); |
937 | 940 | ||
938 | // last modification date | 941 | // last modification date |
939 | if ((vo = isAPropertyOf(vevent, VCLastModifiedProp)) != 0) { | 942 | if ((vo = isAPropertyOf(vevent, VCLastModifiedProp)) != 0) { |
940 | anEvent->setLastModified(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); | 943 | anEvent->setLastModified(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); |
941 | deleteStr(s); | 944 | deleteStr(s); |
942 | } | 945 | } |
943 | else | 946 | else |
944 | anEvent->setLastModified(QDateTime(QDate::currentDate(), | 947 | anEvent->setLastModified(QDateTime(QDate::currentDate(), |
945 | QTime::currentTime())); | 948 | QTime::currentTime())); |
946 | 949 | ||
947 | // organizer | 950 | // organizer |
948 | // if our extension property for the event's ORGANIZER exists, add it. | 951 | // if our extension property for the event's ORGANIZER exists, add it. |
949 | if ((vo = isAPropertyOf(vevent, ICOrganizerProp)) != 0) { | 952 | if ((vo = isAPropertyOf(vevent, ICOrganizerProp)) != 0) { |
950 | anEvent->setOrganizer(s = fakeCString(vObjectUStringZValue(vo))); | 953 | anEvent->setOrganizer(s = fakeCString(vObjectUStringZValue(vo))); |
951 | deleteStr(s); | 954 | deleteStr(s); |
952 | } else { | 955 | } else { |
953 | anEvent->setOrganizer(mCalendar->getEmail()); | 956 | anEvent->setOrganizer(mCalendar->getEmail()); |
954 | } | 957 | } |
955 | 958 | ||
956 | // deal with attendees. | 959 | // deal with attendees. |
957 | initPropIterator(&voi, vevent); | 960 | initPropIterator(&voi, vevent); |
958 | while (moreIteration(&voi)) { | 961 | while (moreIteration(&voi)) { |
959 | vo = nextVObject(&voi); | 962 | vo = nextVObject(&voi); |
960 | if (strcmp(vObjectName(vo), VCAttendeeProp) == 0) { | 963 | if (strcmp(vObjectName(vo), VCAttendeeProp) == 0) { |
961 | Attendee *a; | 964 | Attendee *a; |
962 | VObject *vp; | 965 | VObject *vp; |
963 | s = fakeCString(vObjectUStringZValue(vo)); | 966 | s = fakeCString(vObjectUStringZValue(vo)); |
964 | QString tmpStr = QString::fromLocal8Bit(s); | 967 | QString tmpStr = QString::fromLocal8Bit(s); |
965 | deleteStr(s); | 968 | deleteStr(s); |
966 | tmpStr = tmpStr.simplifyWhiteSpace(); | 969 | tmpStr = tmpStr.simplifyWhiteSpace(); |
967 | int emailPos1, emailPos2; | 970 | int emailPos1, emailPos2; |
968 | if ((emailPos1 = tmpStr.find('<')) > 0) { | 971 | if ((emailPos1 = tmpStr.find('<')) > 0) { |
969 | // both email address and name | 972 | // both email address and name |
970 | emailPos2 = tmpStr.findRev('>'); | 973 | emailPos2 = tmpStr.findRev('>'); |
971 | a = new Attendee(tmpStr.left(emailPos1 - 1), | 974 | a = new Attendee(tmpStr.left(emailPos1 - 1), |
972 | tmpStr.mid(emailPos1 + 1, | 975 | tmpStr.mid(emailPos1 + 1, |
973 | emailPos2 - (emailPos1 + 1))); | 976 | emailPos2 - (emailPos1 + 1))); |
974 | } else if (tmpStr.find('@') > 0) { | 977 | } else if (tmpStr.find('@') > 0) { |
975 | // just an email address | 978 | // just an email address |
976 | a = new Attendee(0, tmpStr); | 979 | a = new Attendee(0, tmpStr); |
977 | } else { | 980 | } else { |
978 | // just a name | 981 | // just a name |
979 | QString email = tmpStr.replace( QRegExp(" "), "." ); | 982 | QString email = tmpStr.replace( QRegExp(" "), "." ); |
980 | a = new Attendee(tmpStr,email); | 983 | a = new Attendee(tmpStr,email); |
981 | } | 984 | } |
982 | 985 | ||
983 | // is there an RSVP property? | 986 | // is there an RSVP property? |
984 | if ((vp = isAPropertyOf(vo, VCRSVPProp)) != 0) | 987 | if ((vp = isAPropertyOf(vo, VCRSVPProp)) != 0) |
985 | a->setRSVP(vObjectStringZValue(vp)); | 988 | a->setRSVP(vObjectStringZValue(vp)); |
986 | // is there a status property? | 989 | // is there a status property? |
987 | if ((vp = isAPropertyOf(vo, VCStatusProp)) != 0) | 990 | if ((vp = isAPropertyOf(vo, VCStatusProp)) != 0) |
988 | a->setStatus(readStatus(vObjectStringZValue(vp))); | 991 | a->setStatus(readStatus(vObjectStringZValue(vp))); |
989 | // add the attendee | 992 | // add the attendee |
990 | anEvent->addAttendee(a); | 993 | anEvent->addAttendee(a); |
991 | } | 994 | } |
992 | } | 995 | } |
993 | 996 | ||
994 | // This isn't strictly true. An event that doesn't have a start time | 997 | // This isn't strictly true. An event that doesn't have a start time |
995 | // or an end time doesn't "float", it has an anchor in time but it doesn't | 998 | // or an end time doesn't "float", it has an anchor in time but it doesn't |
996 | // "take up" any time. | 999 | // "take up" any time. |
997 | /*if ((isAPropertyOf(vevent, VCDTstartProp) == 0) || | 1000 | /*if ((isAPropertyOf(vevent, VCDTstartProp) == 0) || |
998 | (isAPropertyOf(vevent, VCDTendProp) == 0)) { | 1001 | (isAPropertyOf(vevent, VCDTendProp) == 0)) { |
999 | anEvent->setFloats(TRUE); | 1002 | anEvent->setFloats(TRUE); |
1000 | } else { | 1003 | } else { |
1001 | }*/ | 1004 | }*/ |
1002 | 1005 | ||
1003 | anEvent->setFloats(FALSE); | 1006 | anEvent->setFloats(FALSE); |
1004 | 1007 | ||
1005 | // start time | 1008 | // start time |
1006 | if ((vo = isAPropertyOf(vevent, VCDTstartProp)) != 0) { | 1009 | if ((vo = isAPropertyOf(vevent, VCDTstartProp)) != 0) { |
1007 | anEvent->setDtStart(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); | 1010 | anEvent->setDtStart(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); |
1008 | // kdDebug(5800) << "s is " << // s << ", ISO is " << ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo))).toString() << endl; | 1011 | // kdDebug(5800) << "s is " << // s << ", ISO is " << ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo))).toString() << endl; |
1009 | deleteStr(s); | 1012 | deleteStr(s); |
1010 | if (anEvent->dtStart().time().isNull()) | 1013 | if (anEvent->dtStart().time().isNull()) |
1011 | anEvent->setFloats(TRUE); | 1014 | anEvent->setFloats(TRUE); |
1012 | } | 1015 | } |
1013 | 1016 | ||
1014 | // stop time | 1017 | // stop time |
1015 | if ((vo = isAPropertyOf(vevent, VCDTendProp)) != 0) { | 1018 | if ((vo = isAPropertyOf(vevent, VCDTendProp)) != 0) { |
1016 | anEvent->setDtEnd(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); | 1019 | anEvent->setDtEnd(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); |
1017 | deleteStr(s); | 1020 | deleteStr(s); |
1018 | if (anEvent->dtEnd().time().isNull()) | 1021 | if (anEvent->dtEnd().time().isNull()) |
1019 | anEvent->setFloats(TRUE); | 1022 | anEvent->setFloats(TRUE); |
1020 | } | 1023 | } |
1021 | 1024 | ||
1022 | // at this point, there should be at least a start or end time. | 1025 | // at this point, there should be at least a start or end time. |
1023 | // fix up for events that take up no time but have a time associated | 1026 | // fix up for events that take up no time but have a time associated |
1024 | if (!(vo = isAPropertyOf(vevent, VCDTstartProp))) | 1027 | if (!(vo = isAPropertyOf(vevent, VCDTstartProp))) |
1025 | anEvent->setDtStart(anEvent->dtEnd()); | 1028 | anEvent->setDtStart(anEvent->dtEnd()); |
1026 | if (!(vo = isAPropertyOf(vevent, VCDTendProp))) | 1029 | if (!(vo = isAPropertyOf(vevent, VCDTendProp))) |
1027 | anEvent->setDtEnd(anEvent->dtStart()); | 1030 | anEvent->setDtEnd(anEvent->dtStart()); |
1028 | 1031 | ||
1029 | /////////////////////////////////////////////////////////////////////////// | 1032 | /////////////////////////////////////////////////////////////////////////// |
1030 | 1033 | ||
1031 | // repeat stuff | 1034 | // repeat stuff |
1032 | if ((vo = isAPropertyOf(vevent, VCRRuleProp)) != 0) { | 1035 | if ((vo = isAPropertyOf(vevent, VCRRuleProp)) != 0) { |
1033 | QString tmpStr = (s = fakeCString(vObjectUStringZValue(vo))); | 1036 | QString tmpStr = (s = fakeCString(vObjectUStringZValue(vo))); |
1034 | deleteStr(s); | 1037 | deleteStr(s); |
1035 | tmpStr.simplifyWhiteSpace(); | 1038 | tmpStr.simplifyWhiteSpace(); |
1036 | tmpStr = tmpStr.upper(); | 1039 | tmpStr = tmpStr.upper(); |
1037 | 1040 | ||
1038 | /********************************* DAILY ******************************/ | 1041 | /********************************* DAILY ******************************/ |
1039 | if (tmpStr.left(1) == "D") { | 1042 | if (tmpStr.left(1) == "D") { |
1040 | int index = tmpStr.find(' '); | 1043 | int index = tmpStr.find(' '); |
1041 | int rFreq = tmpStr.mid(1, (index-1)).toInt(); | 1044 | int rFreq = tmpStr.mid(1, (index-1)).toInt(); |
1042 | index = tmpStr.findRev(' ') + 1; // advance to last field | 1045 | index = tmpStr.findRev(' ') + 1; // advance to last field |
1043 | if (tmpStr.mid(index,1) == "#") index++; | 1046 | if (tmpStr.mid(index,1) == "#") index++; |
1044 | if (tmpStr.find('T', index) != -1) { | 1047 | if (tmpStr.find('T', index) != -1) { |
1045 | QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length()-index))).date(); | 1048 | QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length()-index))).date(); |
1046 | anEvent->recurrence()->setDaily(rFreq, rEndDate); | 1049 | anEvent->recurrence()->setDaily(rFreq, rEndDate); |
1047 | } else { | 1050 | } else { |
1048 | int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt(); | 1051 | int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt(); |
1049 | if (rDuration == 0) // VEvents set this to 0 forever, we use -1 | 1052 | if (rDuration == 0) // VEvents set this to 0 forever, we use -1 |
1050 | anEvent->recurrence()->setDaily(rFreq, -1); | 1053 | anEvent->recurrence()->setDaily(rFreq, -1); |
1051 | else | 1054 | else |
1052 | anEvent->recurrence()->setDaily(rFreq, rDuration); | 1055 | anEvent->recurrence()->setDaily(rFreq, rDuration); |
1053 | } | 1056 | } |
1054 | } | 1057 | } |
1055 | /********************************* WEEKLY ******************************/ | 1058 | /********************************* WEEKLY ******************************/ |
1056 | else if (tmpStr.left(1) == "W") { | 1059 | else if (tmpStr.left(1) == "W") { |
1057 | int index = tmpStr.find(' '); | 1060 | int index = tmpStr.find(' '); |
1058 | int last = tmpStr.findRev(' ') + 1; | 1061 | int last = tmpStr.findRev(' ') + 1; |
1059 | int rFreq = tmpStr.mid(1, (index-1)).toInt(); | 1062 | int rFreq = tmpStr.mid(1, (index-1)).toInt(); |
1060 | index += 1; // advance to beginning of stuff after freq | 1063 | index += 1; // advance to beginning of stuff after freq |
1061 | QBitArray qba(7); | 1064 | QBitArray qba(7); |
1062 | QString dayStr; | 1065 | QString dayStr; |
1063 | if( index == last ) { | 1066 | if( index == last ) { |
1064 | // e.g. W1 #0 | 1067 | // e.g. W1 #0 |
1065 | qba.setBit(anEvent->dtStart().date().dayOfWeek() - 1); | 1068 | qba.setBit(anEvent->dtStart().date().dayOfWeek() - 1); |
1066 | } | 1069 | } |
1067 | else { | 1070 | else { |
1068 | // e.g. W1 SU #0 | 1071 | // e.g. W1 SU #0 |
1069 | while (index < last) { | 1072 | while (index < last) { |
1070 | dayStr = tmpStr.mid(index, 3); | 1073 | dayStr = tmpStr.mid(index, 3); |
1071 | int dayNum = numFromDay(dayStr); | 1074 | int dayNum = numFromDay(dayStr); |
1072 | qba.setBit(dayNum); | 1075 | qba.setBit(dayNum); |
1073 | index += 3; // advance to next day, or possibly "#" | 1076 | index += 3; // advance to next day, or possibly "#" |
1074 | } | 1077 | } |
1075 | } | 1078 | } |
1076 | index = last; if (tmpStr.mid(index,1) == "#") index++; | 1079 | index = last; if (tmpStr.mid(index,1) == "#") index++; |
1077 | if (tmpStr.find('T', index) != -1) { | 1080 | if (tmpStr.find('T', index) != -1) { |
1078 | QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length()-index))).date(); | 1081 | QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length()-index))).date(); |
1079 | anEvent->recurrence()->setWeekly(rFreq, qba, rEndDate); | 1082 | anEvent->recurrence()->setWeekly(rFreq, qba, rEndDate); |
1080 | } else { | 1083 | } else { |
1081 | int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt(); | 1084 | int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt(); |
1082 | if (rDuration == 0) | 1085 | if (rDuration == 0) |
1083 | anEvent->recurrence()->setWeekly(rFreq, qba, -1); | 1086 | anEvent->recurrence()->setWeekly(rFreq, qba, -1); |
1084 | else | 1087 | else |
1085 | anEvent->recurrence()->setWeekly(rFreq, qba, rDuration); | 1088 | anEvent->recurrence()->setWeekly(rFreq, qba, rDuration); |
1086 | } | 1089 | } |
1087 | } | 1090 | } |
1088 | /**************************** MONTHLY-BY-POS ***************************/ | 1091 | /**************************** MONTHLY-BY-POS ***************************/ |
1089 | else if (tmpStr.left(2) == "MP") { | 1092 | else if (tmpStr.left(2) == "MP") { |
1090 | int index = tmpStr.find(' '); | 1093 | int index = tmpStr.find(' '); |
1091 | int last = tmpStr.findRev(' ') + 1; | 1094 | int last = tmpStr.findRev(' ') + 1; |
1092 | int rFreq = tmpStr.mid(2, (index-1)).toInt(); | 1095 | int rFreq = tmpStr.mid(2, (index-1)).toInt(); |
1093 | index += 1; // advance to beginning of stuff after freq | 1096 | index += 1; // advance to beginning of stuff after freq |
1094 | QBitArray qba(7); | 1097 | QBitArray qba(7); |
1095 | short tmpPos; | 1098 | short tmpPos; |
1096 | if( index == last ) { | 1099 | if( index == last ) { |
1097 | // e.g. MP1 #0 | 1100 | // e.g. MP1 #0 |
1098 | tmpPos = anEvent->dtStart().date().day()/7 + 1; | 1101 | tmpPos = anEvent->dtStart().date().day()/7 + 1; |
1099 | if( tmpPos == 5 ) | 1102 | if( tmpPos == 5 ) |
1100 | tmpPos = -1; | 1103 | tmpPos = -1; |
1101 | qba.setBit(anEvent->dtStart().date().dayOfWeek() - 1); | 1104 | qba.setBit(anEvent->dtStart().date().dayOfWeek() - 1); |
1102 | anEvent->recurrence()->addMonthlyPos(tmpPos, qba); | 1105 | anEvent->recurrence()->addMonthlyPos(tmpPos, qba); |
1103 | } | 1106 | } |
1104 | else { | 1107 | else { |
1105 | // e.g. MP1 1+ SU #0 | 1108 | // e.g. MP1 1+ SU #0 |
1106 | while (index < last) { | 1109 | while (index < last) { |
1107 | tmpPos = tmpStr.mid(index,1).toShort(); | 1110 | tmpPos = tmpStr.mid(index,1).toShort(); |
1108 | index += 1; | 1111 | index += 1; |
1109 | if (tmpStr.mid(index,1) == "-") | 1112 | if (tmpStr.mid(index,1) == "-") |
1110 | // convert tmpPos to negative | 1113 | // convert tmpPos to negative |
1111 | tmpPos = 0 - tmpPos; | 1114 | tmpPos = 0 - tmpPos; |
1112 | index += 2; // advance to day(s) | 1115 | index += 2; // advance to day(s) |
1113 | while (numFromDay(tmpStr.mid(index,3)) >= 0) { | 1116 | while (numFromDay(tmpStr.mid(index,3)) >= 0) { |
1114 | int dayNum = numFromDay(tmpStr.mid(index,3)); | 1117 | int dayNum = numFromDay(tmpStr.mid(index,3)); |
1115 | qba.setBit(dayNum); | 1118 | qba.setBit(dayNum); |
1116 | index += 3; // advance to next day, or possibly pos or "#" | 1119 | index += 3; // advance to next day, or possibly pos or "#" |
1117 | } | 1120 | } |
1118 | anEvent->recurrence()->addMonthlyPos(tmpPos, qba); | 1121 | anEvent->recurrence()->addMonthlyPos(tmpPos, qba); |
1119 | qba.detach(); | 1122 | qba.detach(); |
1120 | qba.fill(FALSE); // clear out | 1123 | qba.fill(FALSE); // clear out |
1121 | } // while != "#" | 1124 | } // while != "#" |
1122 | } | 1125 | } |
1123 | index = last; if (tmpStr.mid(index,1) == "#") index++; | 1126 | index = last; if (tmpStr.mid(index,1) == "#") index++; |
1124 | if (tmpStr.find('T', index) != -1) { | 1127 | if (tmpStr.find('T', index) != -1) { |
1125 | QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length() - | 1128 | QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length() - |
1126 | index))).date(); | 1129 | index))).date(); |
1127 | anEvent->recurrence()->setMonthly(Recurrence::rMonthlyPos, rFreq, rEndDate); | 1130 | anEvent->recurrence()->setMonthly(Recurrence::rMonthlyPos, rFreq, rEndDate); |
1128 | } else { | 1131 | } else { |
1129 | int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt(); | 1132 | int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt(); |
1130 | if (rDuration == 0) | 1133 | if (rDuration == 0) |
1131 | anEvent->recurrence()->setMonthly(Recurrence::rMonthlyPos, rFreq, -1); | 1134 | anEvent->recurrence()->setMonthly(Recurrence::rMonthlyPos, rFreq, -1); |
1132 | else | 1135 | else |
1133 | anEvent->recurrence()->setMonthly(Recurrence::rMonthlyPos, rFreq, rDuration); | 1136 | anEvent->recurrence()->setMonthly(Recurrence::rMonthlyPos, rFreq, rDuration); |
1134 | } | 1137 | } |
1135 | } | 1138 | } |
1136 | 1139 | ||
1137 | /**************************** MONTHLY-BY-DAY ***************************/ | 1140 | /**************************** MONTHLY-BY-DAY ***************************/ |
1138 | else if (tmpStr.left(2) == "MD") { | 1141 | else if (tmpStr.left(2) == "MD") { |
1139 | int index = tmpStr.find(' '); | 1142 | int index = tmpStr.find(' '); |
1140 | int last = tmpStr.findRev(' ') + 1; | 1143 | int last = tmpStr.findRev(' ') + 1; |
1141 | int rFreq = tmpStr.mid(2, (index-1)).toInt(); | 1144 | int rFreq = tmpStr.mid(2, (index-1)).toInt(); |
1142 | index += 1; | 1145 | index += 1; |
1143 | short tmpDay; | 1146 | short tmpDay; |
1144 | if( index == last ) { | 1147 | if( index == last ) { |
1145 | // e.g. MD1 #0 | 1148 | // e.g. MD1 #0 |
1146 | tmpDay = anEvent->dtStart().date().day(); | 1149 | tmpDay = anEvent->dtStart().date().day(); |
1147 | anEvent->recurrence()->addMonthlyDay(tmpDay); | 1150 | anEvent->recurrence()->addMonthlyDay(tmpDay); |
1148 | } | 1151 | } |
1149 | else { | 1152 | else { |
1150 | // e.g. MD1 3 #0 | 1153 | // e.g. MD1 3 #0 |
1151 | while (index < last) { | 1154 | while (index < last) { |
1152 | int index2 = tmpStr.find(' ', index); | 1155 | int index2 = tmpStr.find(' ', index); |
1153 | tmpDay = tmpStr.mid(index, (index2-index)).toShort(); | 1156 | tmpDay = tmpStr.mid(index, (index2-index)).toShort(); |
1154 | index = index2-1; | 1157 | index = index2-1; |
1155 | if (tmpStr.mid(index, 1) == "-") | 1158 | if (tmpStr.mid(index, 1) == "-") |
1156 | tmpDay = 0 - tmpDay; | 1159 | tmpDay = 0 - tmpDay; |
1157 | index += 2; // advance the index; | 1160 | index += 2; // advance the index; |
1158 | anEvent->recurrence()->addMonthlyDay(tmpDay); | 1161 | anEvent->recurrence()->addMonthlyDay(tmpDay); |
1159 | } // while != # | 1162 | } // while != # |
1160 | } | 1163 | } |
1161 | index = last; if (tmpStr.mid(index,1) == "#") index++; | 1164 | index = last; if (tmpStr.mid(index,1) == "#") index++; |
1162 | if (tmpStr.find('T', index) != -1) { | 1165 | if (tmpStr.find('T', index) != -1) { |
1163 | QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length()-index))).date(); | 1166 | QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length()-index))).date(); |
1164 | anEvent->recurrence()->setMonthly(Recurrence::rMonthlyDay, rFreq, rEndDate); | 1167 | anEvent->recurrence()->setMonthly(Recurrence::rMonthlyDay, rFreq, rEndDate); |
1165 | } else { | 1168 | } else { |
1166 | int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt(); | 1169 | int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt(); |
1167 | if (rDuration == 0) | 1170 | if (rDuration == 0) |
1168 | anEvent->recurrence()->setMonthly(Recurrence::rMonthlyDay, rFreq, -1); | 1171 | anEvent->recurrence()->setMonthly(Recurrence::rMonthlyDay, rFreq, -1); |
1169 | else | 1172 | else |
1170 | anEvent->recurrence()->setMonthly(Recurrence::rMonthlyDay, rFreq, rDuration); | 1173 | anEvent->recurrence()->setMonthly(Recurrence::rMonthlyDay, rFreq, rDuration); |
1171 | } | 1174 | } |
1172 | } | 1175 | } |
1173 | 1176 | ||
1174 | /*********************** YEARLY-BY-MONTH *******************************/ | 1177 | /*********************** YEARLY-BY-MONTH *******************************/ |
1175 | else if (tmpStr.left(2) == "YM") { | 1178 | else if (tmpStr.left(2) == "YM") { |
1176 | int index = tmpStr.find(' '); | 1179 | int index = tmpStr.find(' '); |
1177 | int last = tmpStr.findRev(' ') + 1; | 1180 | int last = tmpStr.findRev(' ') + 1; |
1178 | int rFreq = tmpStr.mid(2, (index-1)).toInt(); | 1181 | int rFreq = tmpStr.mid(2, (index-1)).toInt(); |
1179 | index += 1; | 1182 | index += 1; |
1180 | short tmpMonth; | 1183 | short tmpMonth; |
1181 | if( index == last ) { | 1184 | if( index == last ) { |
1182 | // e.g. YM1 #0 | 1185 | // e.g. YM1 #0 |
1183 | tmpMonth = anEvent->dtStart().date().month(); | 1186 | tmpMonth = anEvent->dtStart().date().month(); |
1184 | anEvent->recurrence()->addYearlyNum(tmpMonth); | 1187 | anEvent->recurrence()->addYearlyNum(tmpMonth); |
1185 | } | 1188 | } |
1186 | else { | 1189 | else { |
1187 | // e.g. YM1 3 #0 | 1190 | // e.g. YM1 3 #0 |
1188 | while (index < last) { | 1191 | while (index < last) { |
1189 | int index2 = tmpStr.find(' ', index); | 1192 | int index2 = tmpStr.find(' ', index); |
1190 | tmpMonth = tmpStr.mid(index, (index2-index)).toShort(); | 1193 | tmpMonth = tmpStr.mid(index, (index2-index)).toShort(); |
1191 | index = index2+1; | 1194 | index = index2+1; |
1192 | anEvent->recurrence()->addYearlyNum(tmpMonth); | 1195 | anEvent->recurrence()->addYearlyNum(tmpMonth); |
1193 | } // while != # | 1196 | } // while != # |
1194 | } | 1197 | } |
1195 | index = last; if (tmpStr.mid(index,1) == "#") index++; | 1198 | index = last; if (tmpStr.mid(index,1) == "#") index++; |
1196 | if (tmpStr.find('T', index) != -1) { | 1199 | if (tmpStr.find('T', index) != -1) { |
1197 | QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length()-index))).date(); | 1200 | QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length()-index))).date(); |
1198 | anEvent->recurrence()->setYearly(Recurrence::rYearlyMonth, rFreq, rEndDate); | 1201 | anEvent->recurrence()->setYearly(Recurrence::rYearlyMonth, rFreq, rEndDate); |
1199 | } else { | 1202 | } else { |
1200 | int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt(); | 1203 | int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt(); |
1201 | if (rDuration == 0) | 1204 | if (rDuration == 0) |
1202 | anEvent->recurrence()->setYearly(Recurrence::rYearlyMonth, rFreq, -1); | 1205 | anEvent->recurrence()->setYearly(Recurrence::rYearlyMonth, rFreq, -1); |
1203 | else | 1206 | else |
1204 | anEvent->recurrence()->setYearly(Recurrence::rYearlyMonth, rFreq, rDuration); | 1207 | anEvent->recurrence()->setYearly(Recurrence::rYearlyMonth, rFreq, rDuration); |
1205 | } | 1208 | } |
1206 | } | 1209 | } |
1207 | 1210 | ||
1208 | /*********************** YEARLY-BY-DAY *********************************/ | 1211 | /*********************** YEARLY-BY-DAY *********************************/ |
1209 | else if (tmpStr.left(2) == "YD") { | 1212 | else if (tmpStr.left(2) == "YD") { |
1210 | int index = tmpStr.find(' '); | 1213 | int index = tmpStr.find(' '); |
1211 | int last = tmpStr.findRev(' ') + 1; | 1214 | int last = tmpStr.findRev(' ') + 1; |
1212 | int rFreq = tmpStr.mid(2, (index-1)).toInt(); | 1215 | int rFreq = tmpStr.mid(2, (index-1)).toInt(); |
1213 | index += 1; | 1216 | index += 1; |
1214 | short tmpDay; | 1217 | short tmpDay; |
1215 | if( index == last ) { | 1218 | if( index == last ) { |
1216 | // e.g. YD1 #0 | 1219 | // e.g. YD1 #0 |
1217 | tmpDay = anEvent->dtStart().date().dayOfYear(); | 1220 | tmpDay = anEvent->dtStart().date().dayOfYear(); |
1218 | anEvent->recurrence()->addYearlyNum(tmpDay); | 1221 | anEvent->recurrence()->addYearlyNum(tmpDay); |
1219 | } | 1222 | } |
1220 | else { | 1223 | else { |
1221 | // e.g. YD1 123 #0 | 1224 | // e.g. YD1 123 #0 |
1222 | while (index < last) { | 1225 | while (index < last) { |
1223 | int index2 = tmpStr.find(' ', index); | 1226 | int index2 = tmpStr.find(' ', index); |
1224 | tmpDay = tmpStr.mid(index, (index2-index)).toShort(); | 1227 | tmpDay = tmpStr.mid(index, (index2-index)).toShort(); |
1225 | index = index2+1; | 1228 | index = index2+1; |
1226 | anEvent->recurrence()->addYearlyNum(tmpDay); | 1229 | anEvent->recurrence()->addYearlyNum(tmpDay); |
1227 | } // while != # | 1230 | } // while != # |
1228 | } | 1231 | } |
1229 | index = last; if (tmpStr.mid(index,1) == "#") index++; | 1232 | index = last; if (tmpStr.mid(index,1) == "#") index++; |
1230 | if (tmpStr.find('T', index) != -1) { | 1233 | if (tmpStr.find('T', index) != -1) { |
1231 | QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length()-index))).date(); | 1234 | QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length()-index))).date(); |
1232 | anEvent->recurrence()->setYearly(Recurrence::rYearlyDay, rFreq, rEndDate); | 1235 | anEvent->recurrence()->setYearly(Recurrence::rYearlyDay, rFreq, rEndDate); |
1233 | } else { | 1236 | } else { |
1234 | int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt(); | 1237 | int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt(); |
1235 | if (rDuration == 0) | 1238 | if (rDuration == 0) |
1236 | anEvent->recurrence()->setYearly(Recurrence::rYearlyDay, rFreq, -1); | 1239 | anEvent->recurrence()->setYearly(Recurrence::rYearlyDay, rFreq, -1); |
1237 | else | 1240 | else |
1238 | anEvent->recurrence()->setYearly(Recurrence::rYearlyDay, rFreq, rDuration); | 1241 | anEvent->recurrence()->setYearly(Recurrence::rYearlyDay, rFreq, rDuration); |
1239 | } | 1242 | } |
1240 | } else { | 1243 | } else { |
1241 | kdDebug(5800) << "we don't understand this type of recurrence!" << endl; | 1244 | kdDebug(5800) << "we don't understand this type of recurrence!" << endl; |
1242 | } // if | 1245 | } // if |
1243 | } // repeats | 1246 | } // repeats |
1244 | 1247 | ||
1245 | 1248 | ||
1246 | // recurrence exceptions | 1249 | // recurrence exceptions |
1247 | if ((vo = isAPropertyOf(vevent, VCExpDateProp)) != 0) { | 1250 | if ((vo = isAPropertyOf(vevent, VCExpDateProp)) != 0) { |
1248 | s = fakeCString(vObjectUStringZValue(vo)); | 1251 | s = fakeCString(vObjectUStringZValue(vo)); |
1249 | QStringList exDates = QStringList::split(",",s); | 1252 | QStringList exDates = QStringList::split(",",s); |
1250 | QStringList::ConstIterator it; | 1253 | QStringList::ConstIterator it; |
1251 | for(it = exDates.begin(); it != exDates.end(); ++it ) { | 1254 | for(it = exDates.begin(); it != exDates.end(); ++it ) { |
1252 | anEvent->addExDate(ISOToQDate(*it)); | 1255 | anEvent->addExDate(ISOToQDate(*it)); |
1253 | } | 1256 | } |
1254 | deleteStr(s); | 1257 | deleteStr(s); |
1255 | } | 1258 | } |
1256 | 1259 | ||
1257 | // summary | 1260 | // summary |
1258 | if ((vo = isAPropertyOf(vevent, VCSummaryProp))) { | 1261 | if ((vo = isAPropertyOf(vevent, VCSummaryProp))) { |
1259 | s = fakeCString(vObjectUStringZValue(vo)); | 1262 | s = fakeCString(vObjectUStringZValue(vo)); |
1260 | anEvent->setSummary(QString::fromLocal8Bit(s)); | 1263 | anEvent->setSummary(QString::fromLocal8Bit(s)); |
1261 | deleteStr(s); | 1264 | deleteStr(s); |
1262 | } | 1265 | } |
1263 | if ((vo = isAPropertyOf(vevent, VCLocationProp))) { | 1266 | if ((vo = isAPropertyOf(vevent, VCLocationProp))) { |
1264 | s = fakeCString(vObjectUStringZValue(vo)); | 1267 | s = fakeCString(vObjectUStringZValue(vo)); |
1265 | anEvent->setLocation(QString::fromLocal8Bit(s)); | 1268 | anEvent->setLocation(QString::fromLocal8Bit(s)); |
1266 | deleteStr(s); | 1269 | deleteStr(s); |
1267 | } | 1270 | } |
1268 | 1271 | ||
1269 | // description | 1272 | // description |
1270 | if ((vo = isAPropertyOf(vevent, VCDescriptionProp)) != 0) { | 1273 | if ((vo = isAPropertyOf(vevent, VCDescriptionProp)) != 0) { |
1271 | s = fakeCString(vObjectUStringZValue(vo)); | 1274 | s = fakeCString(vObjectUStringZValue(vo)); |
1272 | if (!anEvent->description().isEmpty()) { | 1275 | if (!anEvent->description().isEmpty()) { |
1273 | anEvent->setDescription(anEvent->description() + "\n" + | 1276 | anEvent->setDescription(anEvent->description() + "\n" + |
1274 | QString::fromLocal8Bit(s)); | 1277 | QString::fromLocal8Bit(s)); |
1275 | } else { | 1278 | } else { |
1276 | anEvent->setDescription(QString::fromLocal8Bit(s)); | 1279 | anEvent->setDescription(QString::fromLocal8Bit(s)); |
1277 | } | 1280 | } |
1278 | deleteStr(s); | 1281 | deleteStr(s); |
1279 | } | 1282 | } |
1280 | 1283 | ||
1281 | // some stupid vCal exporters ignore the standard and use Description | 1284 | // some stupid vCal exporters ignore the standard and use Description |
1282 | // instead of Summary for the default field. Correct for this. | 1285 | // instead of Summary for the default field. Correct for this. |
1283 | if (anEvent->summary().isEmpty() && | 1286 | if (anEvent->summary().isEmpty() && |
1284 | !(anEvent->description().isEmpty())) { | 1287 | !(anEvent->description().isEmpty())) { |
1285 | QString tmpStr = anEvent->description().simplifyWhiteSpace(); | 1288 | QString tmpStr = anEvent->description().simplifyWhiteSpace(); |
1286 | anEvent->setDescription(""); | 1289 | anEvent->setDescription(""); |
1287 | anEvent->setSummary(tmpStr); | 1290 | anEvent->setSummary(tmpStr); |
1288 | } | 1291 | } |
1289 | 1292 | ||
1290 | #if 0 | 1293 | #if 0 |
1291 | // status | 1294 | // status |
1292 | if ((vo = isAPropertyOf(vevent, VCStatusProp)) != 0) { | 1295 | if ((vo = isAPropertyOf(vevent, VCStatusProp)) != 0) { |
1293 | QString tmpStr(s = fakeCString(vObjectUStringZValue(vo))); | 1296 | QString tmpStr(s = fakeCString(vObjectUStringZValue(vo))); |
1294 | deleteStr(s); | 1297 | deleteStr(s); |
1295 | // TODO: Define Event status | 1298 | // TODO: Define Event status |
1296 | // anEvent->setStatus(tmpStr); | 1299 | // anEvent->setStatus(tmpStr); |
1297 | } | 1300 | } |
1298 | else | 1301 | else |
1299 | // anEvent->setStatus("NEEDS ACTION"); | 1302 | // anEvent->setStatus("NEEDS ACTION"); |
1300 | #endif | 1303 | #endif |
1301 | 1304 | ||
1302 | // secrecy | 1305 | // secrecy |
1303 | int secrecy = Incidence::SecrecyPublic; | 1306 | int secrecy = Incidence::SecrecyPublic; |
1304 | if ((vo = isAPropertyOf(vevent, VCClassProp)) != 0) { | 1307 | if ((vo = isAPropertyOf(vevent, VCClassProp)) != 0) { |
1305 | s = fakeCString(vObjectUStringZValue(vo)); | 1308 | s = fakeCString(vObjectUStringZValue(vo)); |
1306 | if (strcmp(s,"PRIVATE") == 0) { | 1309 | if (strcmp(s,"PRIVATE") == 0) { |
1307 | secrecy = Incidence::SecrecyPrivate; | 1310 | secrecy = Incidence::SecrecyPrivate; |
1308 | } else if (strcmp(s,"CONFIDENTIAL") == 0) { | 1311 | } else if (strcmp(s,"CONFIDENTIAL") == 0) { |
1309 | secrecy = Incidence::SecrecyConfidential; | 1312 | secrecy = Incidence::SecrecyConfidential; |
1310 | } | 1313 | } |
1311 | deleteStr(s); | 1314 | deleteStr(s); |
1312 | } | 1315 | } |
1313 | anEvent->setSecrecy(secrecy); | 1316 | anEvent->setSecrecy(secrecy); |
1314 | 1317 | ||
1315 | // categories | 1318 | // categories |
1316 | QStringList tmpStrList; | 1319 | QStringList tmpStrList; |
1317 | int index1 = 0; | 1320 | int index1 = 0; |
1318 | int index2 = 0; | 1321 | int index2 = 0; |
1319 | if ((vo = isAPropertyOf(vevent, VCCategoriesProp)) != 0) { | 1322 | if ((vo = isAPropertyOf(vevent, VCCategoriesProp)) != 0) { |
1320 | s = fakeCString(vObjectUStringZValue(vo)); | 1323 | s = fakeCString(vObjectUStringZValue(vo)); |
1321 | QString categories = QString::fromLocal8Bit(s); | 1324 | QString categories = QString::fromLocal8Bit(s); |
1322 | deleteStr(s); | 1325 | deleteStr(s); |
1323 | //const char* category; | 1326 | //const char* category; |
1324 | QString category; | 1327 | QString category; |
1325 | while ((index2 = categories.find(',', index1)) != -1) { | 1328 | while ((index2 = categories.find(',', index1)) != -1) { |
1326 | //category = (const char *) categories.mid(index1, (index2 - index1)); | 1329 | //category = (const char *) categories.mid(index1, (index2 - index1)); |
1327 | category = categories.mid(index1, (index2 - index1)); | 1330 | category = categories.mid(index1, (index2 - index1)); |
1328 | tmpStrList.append(category); | 1331 | tmpStrList.append(category); |
1329 | index1 = index2+1; | 1332 | index1 = index2+1; |
1330 | } | 1333 | } |
1331 | // get last category | 1334 | // get last category |
1332 | category = categories.mid(index1, (categories.length()-index1)); | 1335 | category = categories.mid(index1, (categories.length()-index1)); |
1333 | tmpStrList.append(category); | 1336 | tmpStrList.append(category); |
1334 | anEvent->setCategories(tmpStrList); | 1337 | anEvent->setCategories(tmpStrList); |
1335 | } | 1338 | } |
1336 | 1339 | ||
1337 | // attachments | 1340 | // attachments |
1338 | tmpStrList.clear(); | 1341 | tmpStrList.clear(); |
1339 | initPropIterator(&voi, vevent); | 1342 | initPropIterator(&voi, vevent); |
1340 | while (moreIteration(&voi)) { | 1343 | while (moreIteration(&voi)) { |
1341 | vo = nextVObject(&voi); | 1344 | vo = nextVObject(&voi); |
1342 | if (strcmp(vObjectName(vo), VCAttachProp) == 0) { | 1345 | if (strcmp(vObjectName(vo), VCAttachProp) == 0) { |
1343 | s = fakeCString(vObjectUStringZValue(vo)); | 1346 | s = fakeCString(vObjectUStringZValue(vo)); |
1344 | anEvent->addAttachment(new Attachment(QString(s))); | 1347 | anEvent->addAttachment(new Attachment(QString(s))); |
1345 | deleteStr(s); | 1348 | deleteStr(s); |
1346 | } | 1349 | } |
1347 | } | 1350 | } |
1348 | 1351 | ||
1349 | // resources | 1352 | // resources |
1350 | if ((vo = isAPropertyOf(vevent, VCResourcesProp)) != 0) { | 1353 | if ((vo = isAPropertyOf(vevent, VCResourcesProp)) != 0) { |
1351 | QString resources = (s = fakeCString(vObjectUStringZValue(vo))); | 1354 | QString resources = (s = fakeCString(vObjectUStringZValue(vo))); |
1352 | deleteStr(s); | 1355 | deleteStr(s); |
1353 | tmpStrList.clear(); | 1356 | tmpStrList.clear(); |
1354 | index1 = 0; | 1357 | index1 = 0; |
1355 | index2 = 0; | 1358 | index2 = 0; |
1356 | QString resource; | 1359 | QString resource; |
1357 | while ((index2 = resources.find(';', index1)) != -1) { | 1360 | while ((index2 = resources.find(';', index1)) != -1) { |
1358 | resource = resources.mid(index1, (index2 - index1)); | 1361 | resource = resources.mid(index1, (index2 - index1)); |
1359 | tmpStrList.append(resource); | 1362 | tmpStrList.append(resource); |
1360 | index1 = index2; | 1363 | index1 = index2; |
1361 | } | 1364 | } |
1362 | anEvent->setResources(tmpStrList); | 1365 | anEvent->setResources(tmpStrList); |
1363 | } | 1366 | } |
1364 | 1367 | ||
1365 | /* alarm stuff */ | 1368 | /* alarm stuff */ |
1366 | if ((vo = isAPropertyOf(vevent, VCDAlarmProp))) { | 1369 | if ((vo = isAPropertyOf(vevent, VCDAlarmProp))) { |
1367 | Alarm* alarm = anEvent->newAlarm(); | 1370 | Alarm* alarm = anEvent->newAlarm(); |
1368 | VObject *a; | 1371 | VObject *a; |
1369 | if ((a = isAPropertyOf(vo, VCRunTimeProp))) { | 1372 | if ((a = isAPropertyOf(vo, VCRunTimeProp))) { |
1370 | alarm->setTime(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(a)))); | 1373 | alarm->setTime(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(a)))); |
1371 | deleteStr(s); | 1374 | deleteStr(s); |
1372 | } | 1375 | } |
1373 | alarm->setEnabled(true); | 1376 | alarm->setEnabled(true); |
1374 | if ((vo = isAPropertyOf(vevent, VCPAlarmProp))) { | 1377 | if ((vo = isAPropertyOf(vevent, VCPAlarmProp))) { |
1375 | if ((a = isAPropertyOf(vo, VCProcedureNameProp))) { | 1378 | if ((a = isAPropertyOf(vo, VCProcedureNameProp))) { |
1376 | s = fakeCString(vObjectUStringZValue(a)); | 1379 | s = fakeCString(vObjectUStringZValue(a)); |
1377 | alarm->setProcedureAlarm(QFile::decodeName(s)); | 1380 | alarm->setProcedureAlarm(QFile::decodeName(s)); |
1378 | deleteStr(s); | 1381 | deleteStr(s); |
1379 | } | 1382 | } |
1380 | } | 1383 | } |
1381 | if ((vo = isAPropertyOf(vevent, VCAAlarmProp))) { | 1384 | if ((vo = isAPropertyOf(vevent, VCAAlarmProp))) { |
1382 | if ((a = isAPropertyOf(vo, VCAudioContentProp))) { | 1385 | if ((a = isAPropertyOf(vo, VCAudioContentProp))) { |
1383 | s = fakeCString(vObjectUStringZValue(a)); | 1386 | s = fakeCString(vObjectUStringZValue(a)); |
1384 | alarm->setAudioAlarm(QFile::decodeName(s)); | 1387 | alarm->setAudioAlarm(QFile::decodeName(s)); |
1385 | deleteStr(s); | 1388 | deleteStr(s); |
1386 | } | 1389 | } |
1387 | } | 1390 | } |
1388 | } | 1391 | } |
1389 | 1392 | ||
1390 | // priority | 1393 | // priority |
1391 | if ((vo = isAPropertyOf(vevent, VCPriorityProp))) { | 1394 | if ((vo = isAPropertyOf(vevent, VCPriorityProp))) { |
1392 | anEvent->setPriority(atoi(s = fakeCString(vObjectUStringZValue(vo)))); | 1395 | anEvent->setPriority(atoi(s = fakeCString(vObjectUStringZValue(vo)))); |
1393 | deleteStr(s); | 1396 | deleteStr(s); |
1394 | } | 1397 | } |
1395 | 1398 | ||
1396 | // transparency | 1399 | // transparency |
1397 | if ((vo = isAPropertyOf(vevent, VCTranspProp)) != 0) { | 1400 | if ((vo = isAPropertyOf(vevent, VCTranspProp)) != 0) { |
1398 | int i = atoi(s = fakeCString(vObjectUStringZValue(vo))); | 1401 | int i = atoi(s = fakeCString(vObjectUStringZValue(vo))); |
1399 | anEvent->setTransparency( i == 1 ? Event::Transparent : Event::Opaque ); | 1402 | anEvent->setTransparency( i == 1 ? Event::Transparent : Event::Opaque ); |
1400 | deleteStr(s); | 1403 | deleteStr(s); |
1401 | } | 1404 | } |
1402 | 1405 | ||
1403 | // related event | 1406 | // related event |
1404 | if ((vo = isAPropertyOf(vevent, VCRelatedToProp)) != 0) { | 1407 | if ((vo = isAPropertyOf(vevent, VCRelatedToProp)) != 0) { |
1405 | anEvent->setRelatedToUid(s = fakeCString(vObjectUStringZValue(vo))); | 1408 | anEvent->setRelatedToUid(s = fakeCString(vObjectUStringZValue(vo))); |
1406 | deleteStr(s); | 1409 | deleteStr(s); |
1407 | mEventsRelate.append(anEvent); | 1410 | mEventsRelate.append(anEvent); |
1408 | } | 1411 | } |
1409 | 1412 | ||
1410 | /* PILOT SYNC STUFF */ | 1413 | /* PILOT SYNC STUFF */ |
1411 | if ((vo = isAPropertyOf(vevent, XPilotIdProp))) { | 1414 | if ((vo = isAPropertyOf(vevent, XPilotIdProp))) { |
1412 | anEvent->setPilotId(atoi(s = fakeCString(vObjectUStringZValue(vo)))); | 1415 | anEvent->setPilotId(atoi(s = fakeCString(vObjectUStringZValue(vo)))); |
1413 | deleteStr(s); | 1416 | deleteStr(s); |
1414 | } | 1417 | } |
1415 | else | 1418 | else |
1416 | anEvent->setPilotId(0); | 1419 | anEvent->setPilotId(0); |
1417 | 1420 | ||
1418 | if ((vo = isAPropertyOf(vevent, XPilotStatusProp))) { | 1421 | if ((vo = isAPropertyOf(vevent, XPilotStatusProp))) { |
1419 | anEvent->setSyncStatus(atoi(s = fakeCString(vObjectUStringZValue(vo)))); | 1422 | anEvent->setSyncStatus(atoi(s = fakeCString(vObjectUStringZValue(vo)))); |
1420 | deleteStr(s); | 1423 | deleteStr(s); |
1421 | } | 1424 | } |
1422 | else | 1425 | else |
1423 | anEvent->setSyncStatus(Event::SYNCMOD); | 1426 | anEvent->setSyncStatus(Event::SYNCMOD); |
1424 | 1427 | ||
1425 | return anEvent; | 1428 | return anEvent; |
1426 | } | 1429 | } |
1427 | 1430 | ||
1428 | 1431 | ||
1429 | QString VCalFormat::qDateToISO(const QDate &qd) | 1432 | QString VCalFormat::qDateToISO(const QDate &qd) |
1430 | { | 1433 | { |
1431 | QString tmpStr; | 1434 | QString tmpStr; |
1432 | 1435 | ||
1433 | ASSERT(qd.isValid()); | 1436 | ASSERT(qd.isValid()); |
1434 | 1437 | ||
1435 | tmpStr.sprintf("%.2d%.2d%.2d", | 1438 | tmpStr.sprintf("%.2d%.2d%.2d", |
1436 | qd.year(), qd.month(), qd.day()); | 1439 | qd.year(), qd.month(), qd.day()); |
1437 | return tmpStr; | 1440 | return tmpStr; |
1438 | 1441 | ||
1439 | } | 1442 | } |
1440 | 1443 | ||
1441 | QString VCalFormat::qDateTimeToISO(const QDateTime &qdt, bool zulu) | 1444 | QString VCalFormat::qDateTimeToISO(const QDateTime &qdt, bool zulu) |
1442 | { | 1445 | { |
1443 | QString tmpStr; | 1446 | QString tmpStr; |
1444 | 1447 | ||
1445 | ASSERT(qdt.date().isValid()); | 1448 | ASSERT(qdt.date().isValid()); |
1446 | ASSERT(qdt.time().isValid()); | 1449 | ASSERT(qdt.time().isValid()); |
1447 | if (zulu && !useLocalTime ) { | 1450 | if (zulu && !useLocalTime ) { |
1448 | QDateTime tmpDT = qdt.addSecs ( -KGlobal::locale()->localTimeOffset( qdt )*60); | 1451 | QDateTime tmpDT = qdt.addSecs ( -KGlobal::locale()->localTimeOffset( qdt )*60); |
1449 | tmpStr.sprintf("%.2d%.2d%.2dT%.2d%.2d%.2dZ", | 1452 | tmpStr.sprintf("%.2d%.2d%.2dT%.2d%.2d%.2dZ", |
1450 | tmpDT.date().year(), tmpDT.date().month(), | 1453 | tmpDT.date().year(), tmpDT.date().month(), |
1451 | tmpDT.date().day(), tmpDT.time().hour(), | 1454 | tmpDT.date().day(), tmpDT.time().hour(), |
1452 | tmpDT.time().minute(), tmpDT.time().second()); | 1455 | tmpDT.time().minute(), tmpDT.time().second()); |
1453 | } else { | 1456 | } else { |
1454 | tmpStr.sprintf("%.2d%.2d%.2dT%.2d%.2d%.2d", | 1457 | tmpStr.sprintf("%.2d%.2d%.2dT%.2d%.2d%.2d", |
1455 | qdt.date().year(), qdt.date().month(), | 1458 | qdt.date().year(), qdt.date().month(), |
1456 | qdt.date().day(), qdt.time().hour(), | 1459 | qdt.date().day(), qdt.time().hour(), |
1457 | qdt.time().minute(), qdt.time().second()); | 1460 | qdt.time().minute(), qdt.time().second()); |
1458 | } | 1461 | } |
1459 | return tmpStr; | 1462 | return tmpStr; |
1460 | } | 1463 | } |
1461 | 1464 | ||
1462 | QDateTime VCalFormat::ISOToQDateTime(const QString & dtStr) | 1465 | QDateTime VCalFormat::ISOToQDateTime(const QString & dtStr) |
1463 | { | 1466 | { |
1464 | QDate tmpDate; | 1467 | QDate tmpDate; |
1465 | QTime tmpTime; | 1468 | QTime tmpTime; |
1466 | QString tmpStr; | 1469 | QString tmpStr; |
1467 | int year, month, day, hour, minute, second; | 1470 | int year, month, day, hour, minute, second; |
1468 | 1471 | ||
1469 | tmpStr = dtStr; | 1472 | tmpStr = dtStr; |
1470 | year = tmpStr.left(4).toInt(); | 1473 | year = tmpStr.left(4).toInt(); |
1471 | month = tmpStr.mid(4,2).toInt(); | 1474 | month = tmpStr.mid(4,2).toInt(); |
1472 | day = tmpStr.mid(6,2).toInt(); | 1475 | day = tmpStr.mid(6,2).toInt(); |
1473 | hour = tmpStr.mid(9,2).toInt(); | 1476 | hour = tmpStr.mid(9,2).toInt(); |
1474 | minute = tmpStr.mid(11,2).toInt(); | 1477 | minute = tmpStr.mid(11,2).toInt(); |
1475 | second = tmpStr.mid(13,2).toInt(); | 1478 | second = tmpStr.mid(13,2).toInt(); |
1476 | tmpDate.setYMD(year, month, day); | 1479 | tmpDate.setYMD(year, month, day); |
1477 | tmpTime.setHMS(hour, minute, second); | 1480 | tmpTime.setHMS(hour, minute, second); |
1478 | 1481 | ||
1479 | ASSERT(tmpDate.isValid()); | 1482 | ASSERT(tmpDate.isValid()); |
1480 | ASSERT(tmpTime.isValid()); | 1483 | ASSERT(tmpTime.isValid()); |
1481 | QDateTime tmpDT(tmpDate, tmpTime); | 1484 | QDateTime tmpDT(tmpDate, tmpTime); |
1482 | // correct for GMT if string is in Zulu format | 1485 | // correct for GMT if string is in Zulu format |
1483 | if (dtStr.at(dtStr.length()-1) == 'Z') | 1486 | if (dtStr.at(dtStr.length()-1) == 'Z') |
1484 | tmpDT = tmpDT.addSecs(60*mCalendar->getTimeZone()); | 1487 | tmpDT = tmpDT.addSecs(60*mCalendar->getTimeZone()); |
1485 | return tmpDT; | 1488 | return tmpDT; |
1486 | } | 1489 | } |
1487 | 1490 | ||
1488 | QDate VCalFormat::ISOToQDate(const QString &dateStr) | 1491 | QDate VCalFormat::ISOToQDate(const QString &dateStr) |
1489 | { | 1492 | { |
1490 | int year, month, day; | 1493 | int year, month, day; |
1491 | 1494 | ||
1492 | year = dateStr.left(4).toInt(); | 1495 | year = dateStr.left(4).toInt(); |
1493 | month = dateStr.mid(4,2).toInt(); | 1496 | month = dateStr.mid(4,2).toInt(); |
1494 | day = dateStr.mid(6,2).toInt(); | 1497 | day = dateStr.mid(6,2).toInt(); |
1495 | 1498 | ||
1496 | return(QDate(year, month, day)); | 1499 | return(QDate(year, month, day)); |
1497 | } | 1500 | } |
1498 | 1501 | ||
1499 | // take a raw vcalendar (i.e. from a file on disk, clipboard, etc. etc. | 1502 | // take a raw vcalendar (i.e. from a file on disk, clipboard, etc. etc. |
1500 | // and break it down from it's tree-like format into the dictionary format | 1503 | // and break it down from it's tree-like format into the dictionary format |
1501 | // that is used internally in the VCalFormat. | 1504 | // that is used internally in the VCalFormat. |
1502 | void VCalFormat::populate(VObject *vcal) | 1505 | void VCalFormat::populate(VObject *vcal) |
1503 | { | 1506 | { |
1504 | // this function will populate the caldict dictionary and other event | 1507 | // this function will populate the caldict dictionary and other event |
1505 | // lists. It turns vevents into Events and then inserts them. | 1508 | // lists. It turns vevents into Events and then inserts them. |
1506 | 1509 | ||
1507 | VObjectIterator i; | 1510 | VObjectIterator i; |
1508 | VObject *curVO, *curVOProp; | 1511 | VObject *curVO, *curVOProp; |
1509 | Event *anEvent; | 1512 | Event *anEvent; |
1510 | 1513 | ||
1511 | if ((curVO = isAPropertyOf(vcal, ICMethodProp)) != 0) { | 1514 | if ((curVO = isAPropertyOf(vcal, ICMethodProp)) != 0) { |
1512 | char *methodType = 0; | 1515 | char *methodType = 0; |
1513 | methodType = fakeCString(vObjectUStringZValue(curVO)); | 1516 | methodType = fakeCString(vObjectUStringZValue(curVO)); |
1514 | kdDebug() << "This calendar is an iTIP transaction of type '" | 1517 | kdDebug() << "This calendar is an iTIP transaction of type '" |
1515 | << methodType << "'" << endl; | 1518 | << methodType << "'" << endl; |
1516 | delete methodType; | 1519 | delete methodType; |
1517 | } | 1520 | } |
1518 | 1521 | ||
1519 | // warn the user that we might have trouble reading non-known calendar. | 1522 | // warn the user that we might have trouble reading non-known calendar. |
1520 | if ((curVO = isAPropertyOf(vcal, VCProdIdProp)) != 0) { | 1523 | if ((curVO = isAPropertyOf(vcal, VCProdIdProp)) != 0) { |
1521 | char *s = fakeCString(vObjectUStringZValue(curVO)); | 1524 | char *s = fakeCString(vObjectUStringZValue(curVO)); |
1522 | if (strcmp(productId().local8Bit(), s) != 0) | 1525 | if (strcmp(productId().local8Bit(), s) != 0) |
1523 | kdDebug() << "This vCalendar file was not created by KOrganizer " | 1526 | kdDebug() << "This vCalendar file was not created by KOrganizer " |
1524 | "or any other product we support. Loading anyway..." << endl; | 1527 | "or any other product we support. Loading anyway..." << endl; |
1525 | mLoadedProductId = s; | 1528 | mLoadedProductId = s; |
1526 | deleteStr(s); | 1529 | deleteStr(s); |
1527 | } | 1530 | } |
1528 | 1531 | ||
1529 | // warn the user we might have trouble reading this unknown version. | 1532 | // warn the user we might have trouble reading this unknown version. |
1530 | if ((curVO = isAPropertyOf(vcal, VCVersionProp)) != 0) { | 1533 | if ((curVO = isAPropertyOf(vcal, VCVersionProp)) != 0) { |
1531 | char *s = fakeCString(vObjectUStringZValue(curVO)); | 1534 | char *s = fakeCString(vObjectUStringZValue(curVO)); |
1532 | if (strcmp(_VCAL_VERSION, s) != 0) | 1535 | if (strcmp(_VCAL_VERSION, s) != 0) |
1533 | kdDebug() << "This vCalendar file has version " << s | 1536 | kdDebug() << "This vCalendar file has version " << s |
1534 | << "We only support " << _VCAL_VERSION << endl; | 1537 | << "We only support " << _VCAL_VERSION << endl; |
1535 | deleteStr(s); | 1538 | deleteStr(s); |
1536 | } | 1539 | } |
1537 | 1540 | ||
1538 | // set the time zone | 1541 | // set the time zone |
1539 | if ((curVO = isAPropertyOf(vcal, VCTimeZoneProp)) != 0) { | 1542 | if ((curVO = isAPropertyOf(vcal, VCTimeZoneProp)) != 0) { |
1540 | char *s = fakeCString(vObjectUStringZValue(curVO)); | 1543 | char *s = fakeCString(vObjectUStringZValue(curVO)); |
1541 | mCalendar->setTimeZone(s); | 1544 | mCalendar->setTimeZone(s); |
1542 | deleteStr(s); | 1545 | deleteStr(s); |
1543 | } | 1546 | } |
1544 | 1547 | ||
1545 | 1548 | ||
1546 | // Store all events with a relatedTo property in a list for post-processing | 1549 | // Store all events with a relatedTo property in a list for post-processing |
1547 | mEventsRelate.clear(); | 1550 | mEventsRelate.clear(); |
1548 | mTodosRelate.clear(); | 1551 | mTodosRelate.clear(); |
1549 | 1552 | ||
1550 | initPropIterator(&i, vcal); | 1553 | initPropIterator(&i, vcal); |
1551 | 1554 | ||
1552 | // go through all the vobjects in the vcal | 1555 | // go through all the vobjects in the vcal |
1553 | while (moreIteration(&i)) { | 1556 | while (moreIteration(&i)) { |
1554 | curVO = nextVObject(&i); | 1557 | curVO = nextVObject(&i); |
1555 | 1558 | ||
1556 | /************************************************************************/ | 1559 | /************************************************************************/ |
1557 | 1560 | ||
1558 | // now, check to see that the object is an event or todo. | 1561 | // now, check to see that the object is an event or todo. |
1559 | if (strcmp(vObjectName(curVO), VCEventProp) == 0) { | 1562 | if (strcmp(vObjectName(curVO), VCEventProp) == 0) { |
1560 | 1563 | ||
1561 | if ((curVOProp = isAPropertyOf(curVO, XPilotStatusProp)) != 0) { | 1564 | if ((curVOProp = isAPropertyOf(curVO, XPilotStatusProp)) != 0) { |
1562 | char *s; | 1565 | char *s; |
1563 | s = fakeCString(vObjectUStringZValue(curVOProp)); | 1566 | s = fakeCString(vObjectUStringZValue(curVOProp)); |
1564 | // check to see if event was deleted by the kpilot conduit | 1567 | // check to see if event was deleted by the kpilot conduit |
1565 | if (atoi(s) == Event::SYNCDEL) { | 1568 | if (atoi(s) == Event::SYNCDEL) { |
1566 | deleteStr(s); | 1569 | deleteStr(s); |
1567 | kdDebug(5800) << "skipping pilot-deleted event" << endl; | 1570 | kdDebug(5800) << "skipping pilot-deleted event" << endl; |
1568 | goto SKIP; | 1571 | goto SKIP; |
1569 | } | 1572 | } |
1570 | deleteStr(s); | 1573 | deleteStr(s); |
1571 | } | 1574 | } |
1572 | 1575 | ||
1573 | // this code checks to see if we are trying to read in an event | 1576 | // this code checks to see if we are trying to read in an event |
1574 | // that we already find to be in the calendar. If we find this | 1577 | // that we already find to be in the calendar. If we find this |
1575 | // to be the case, we skip the event. | 1578 | // to be the case, we skip the event. |
1576 | if ((curVOProp = isAPropertyOf(curVO, VCUniqueStringProp)) != 0) { | 1579 | if ((curVOProp = isAPropertyOf(curVO, VCUniqueStringProp)) != 0) { |
1577 | char *s = fakeCString(vObjectUStringZValue(curVOProp)); | 1580 | char *s = fakeCString(vObjectUStringZValue(curVOProp)); |
1578 | QString tmpStr(s); | 1581 | QString tmpStr(s); |
1579 | deleteStr(s); | 1582 | deleteStr(s); |
1580 | 1583 | ||
1581 | if (mCalendar->event(tmpStr)) { | 1584 | if (mCalendar->event(tmpStr)) { |
1582 | goto SKIP; | 1585 | goto SKIP; |
1583 | } | 1586 | } |
1584 | if (mCalendar->todo(tmpStr)) { | 1587 | if (mCalendar->todo(tmpStr)) { |
1585 | goto SKIP; | 1588 | goto SKIP; |
1586 | } | 1589 | } |
1587 | } | 1590 | } |
1588 | 1591 | ||
1589 | if ((!(curVOProp = isAPropertyOf(curVO, VCDTstartProp))) && | 1592 | if ((!(curVOProp = isAPropertyOf(curVO, VCDTstartProp))) && |
1590 | (!(curVOProp = isAPropertyOf(curVO, VCDTendProp)))) { | 1593 | (!(curVOProp = isAPropertyOf(curVO, VCDTendProp)))) { |
1591 | kdDebug(5800) << "found a VEvent with no DTSTART and no DTEND! Skipping..." << endl; | 1594 | kdDebug(5800) << "found a VEvent with no DTSTART and no DTEND! Skipping..." << endl; |
1592 | goto SKIP; | 1595 | goto SKIP; |
1593 | } | 1596 | } |
1594 | 1597 | ||
1595 | anEvent = VEventToEvent(curVO); | 1598 | anEvent = VEventToEvent(curVO); |
1596 | // we now use addEvent instead of insertEvent so that the | 1599 | // we now use addEvent instead of insertEvent so that the |
1597 | // signal/slot get connected. | 1600 | // signal/slot get connected. |
1598 | if (anEvent) { | 1601 | if (anEvent) { |
1599 | if ( !anEvent->dtStart().isValid() || !anEvent->dtEnd().isValid() ) { | 1602 | if ( !anEvent->dtStart().isValid() || !anEvent->dtEnd().isValid() ) { |
1600 | kdDebug() << "VCalFormat::populate(): Event has invalid dates." | 1603 | kdDebug() << "VCalFormat::populate(): Event has invalid dates." |
1601 | << endl; | 1604 | << endl; |
1602 | } else { | 1605 | } else { |
1603 | mCalendar->addEvent(anEvent); | 1606 | mCalendar->addEvent(anEvent); |
1604 | } | 1607 | } |
1605 | } else { | 1608 | } else { |
1606 | // some sort of error must have occurred while in translation. | 1609 | // some sort of error must have occurred while in translation. |
1607 | goto SKIP; | 1610 | goto SKIP; |
1608 | } | 1611 | } |
1609 | } else if (strcmp(vObjectName(curVO), VCTodoProp) == 0) { | 1612 | } else if (strcmp(vObjectName(curVO), VCTodoProp) == 0) { |
1610 | Todo *aTodo = VTodoToEvent(curVO); | 1613 | Todo *aTodo = VTodoToEvent(curVO); |
1611 | mCalendar->addTodo(aTodo); | 1614 | mCalendar->addTodo(aTodo); |
1612 | } else if ((strcmp(vObjectName(curVO), VCVersionProp) == 0) || | 1615 | } else if ((strcmp(vObjectName(curVO), VCVersionProp) == 0) || |
1613 | (strcmp(vObjectName(curVO), VCProdIdProp) == 0) || | 1616 | (strcmp(vObjectName(curVO), VCProdIdProp) == 0) || |
1614 | (strcmp(vObjectName(curVO), VCTimeZoneProp) == 0)) { | 1617 | (strcmp(vObjectName(curVO), VCTimeZoneProp) == 0)) { |
1615 | // do nothing, we know these properties and we want to skip them. | 1618 | // do nothing, we know these properties and we want to skip them. |
1616 | // we have either already processed them or are ignoring them. | 1619 | // we have either already processed them or are ignoring them. |
1617 | ; | 1620 | ; |
1618 | } else { | 1621 | } else { |
1619 | kdDebug(5800) << "Ignoring unknown vObject \"" << vObjectName(curVO) << "\"" << endl; | 1622 | kdDebug(5800) << "Ignoring unknown vObject \"" << vObjectName(curVO) << "\"" << endl; |
1620 | } | 1623 | } |
1621 | SKIP: | 1624 | SKIP: |
1622 | ; | 1625 | ; |
1623 | } // while | 1626 | } // while |
1624 | 1627 | ||
1625 | // Post-Process list of events with relations, put Event objects in relation | 1628 | // Post-Process list of events with relations, put Event objects in relation |
1626 | Event *ev; | 1629 | Event *ev; |
1627 | for ( ev=mEventsRelate.first(); ev != 0; ev=mEventsRelate.next() ) { | 1630 | for ( ev=mEventsRelate.first(); ev != 0; ev=mEventsRelate.next() ) { |
1628 | ev->setRelatedTo(mCalendar->event(ev->relatedToUid())); | 1631 | ev->setRelatedTo(mCalendar->event(ev->relatedToUid())); |
1629 | } | 1632 | } |
1630 | Todo *todo; | 1633 | Todo *todo; |
1631 | for ( todo=mTodosRelate.first(); todo != 0; todo=mTodosRelate.next() ) { | 1634 | for ( todo=mTodosRelate.first(); todo != 0; todo=mTodosRelate.next() ) { |
1632 | todo->setRelatedTo(mCalendar->todo(todo->relatedToUid())); | 1635 | todo->setRelatedTo(mCalendar->todo(todo->relatedToUid())); |
1633 | } | 1636 | } |
1634 | } | 1637 | } |
1635 | 1638 | ||
1636 | const char *VCalFormat::dayFromNum(int day) | 1639 | const char *VCalFormat::dayFromNum(int day) |
1637 | { | 1640 | { |
1638 | const char *days[7] = { "MO ", "TU ", "WE ", "TH ", "FR ", "SA ", "SU " }; | 1641 | const char *days[7] = { "MO ", "TU ", "WE ", "TH ", "FR ", "SA ", "SU " }; |
1639 | 1642 | ||
1640 | return days[day]; | 1643 | return days[day]; |
1641 | } | 1644 | } |
1642 | 1645 | ||
1643 | int VCalFormat::numFromDay(const QString &day) | 1646 | int VCalFormat::numFromDay(const QString &day) |
1644 | { | 1647 | { |
1645 | if (day == "MO ") return 0; | 1648 | if (day == "MO ") return 0; |
1646 | if (day == "TU ") return 1; | 1649 | if (day == "TU ") return 1; |
1647 | if (day == "WE ") return 2; | 1650 | if (day == "WE ") return 2; |
1648 | if (day == "TH ") return 3; | 1651 | if (day == "TH ") return 3; |
1649 | if (day == "FR ") return 4; | 1652 | if (day == "FR ") return 4; |
1650 | if (day == "SA ") return 5; | 1653 | if (day == "SA ") return 5; |
1651 | if (day == "SU ") return 6; | 1654 | if (day == "SU ") return 6; |
1652 | 1655 | ||
1653 | return -1; // something bad happened. :) | 1656 | return -1; // something bad happened. :) |
1654 | } | 1657 | } |
1655 | 1658 | ||
1656 | Attendee::PartStat VCalFormat::readStatus(const char *s) const | 1659 | Attendee::PartStat VCalFormat::readStatus(const char *s) const |
1657 | { | 1660 | { |
1658 | QString statStr = s; | 1661 | QString statStr = s; |
1659 | statStr = statStr.upper(); | 1662 | statStr = statStr.upper(); |
1660 | Attendee::PartStat status; | 1663 | Attendee::PartStat status; |
1661 | 1664 | ||
1662 | if (statStr == "X-ACTION") | 1665 | if (statStr == "X-ACTION") |
1663 | status = Attendee::NeedsAction; | 1666 | status = Attendee::NeedsAction; |
1664 | else if (statStr == "NEEDS ACTION") | 1667 | else if (statStr == "NEEDS ACTION") |
1665 | status = Attendee::NeedsAction; | 1668 | status = Attendee::NeedsAction; |
1666 | else if (statStr== "ACCEPTED") | 1669 | else if (statStr== "ACCEPTED") |
1667 | status = Attendee::Accepted; | 1670 | status = Attendee::Accepted; |
1668 | else if (statStr== "SENT") | 1671 | else if (statStr== "SENT") |
1669 | status = Attendee::NeedsAction; | 1672 | status = Attendee::NeedsAction; |
1670 | else if (statStr== "TENTATIVE") | 1673 | else if (statStr== "TENTATIVE") |
1671 | status = Attendee::Tentative; | 1674 | status = Attendee::Tentative; |
1672 | else if (statStr== "CONFIRMED") | 1675 | else if (statStr== "CONFIRMED") |
1673 | status = Attendee::Accepted; | 1676 | status = Attendee::Accepted; |
1674 | else if (statStr== "DECLINED") | 1677 | else if (statStr== "DECLINED") |
1675 | status = Attendee::Declined; | 1678 | status = Attendee::Declined; |
1676 | else if (statStr== "COMPLETED") | 1679 | else if (statStr== "COMPLETED") |
1677 | status = Attendee::Completed; | 1680 | status = Attendee::Completed; |
1678 | else if (statStr== "DELEGATED") | 1681 | else if (statStr== "DELEGATED") |
1679 | status = Attendee::Delegated; | 1682 | status = Attendee::Delegated; |
1680 | else { | 1683 | else { |
1681 | kdDebug(5800) << "error setting attendee mStatus, unknown mStatus!" << endl; | 1684 | kdDebug(5800) << "error setting attendee mStatus, unknown mStatus!" << endl; |
1682 | status = Attendee::NeedsAction; | 1685 | status = Attendee::NeedsAction; |
1683 | } | 1686 | } |
1684 | 1687 | ||
1685 | return status; | 1688 | return status; |
1686 | } | 1689 | } |
1687 | 1690 | ||
1688 | QCString VCalFormat::writeStatus(Attendee::PartStat status) const | 1691 | QCString VCalFormat::writeStatus(Attendee::PartStat status) const |
1689 | { | 1692 | { |
1690 | switch(status) { | 1693 | switch(status) { |
1691 | default: | 1694 | default: |
1692 | case Attendee::NeedsAction: | 1695 | case Attendee::NeedsAction: |
1693 | return "NEEDS ACTION"; | 1696 | return "NEEDS ACTION"; |
1694 | break; | 1697 | break; |
1695 | case Attendee::Accepted: | 1698 | case Attendee::Accepted: |
1696 | return "ACCEPTED"; | 1699 | return "ACCEPTED"; |
1697 | break; | 1700 | break; |
1698 | case Attendee::Declined: | 1701 | case Attendee::Declined: |
1699 | return "DECLINED"; | 1702 | return "DECLINED"; |
1700 | break; | 1703 | break; |
1701 | case Attendee::Tentative: | 1704 | case Attendee::Tentative: |
1702 | return "TENTATIVE"; | 1705 | return "TENTATIVE"; |
1703 | break; | 1706 | break; |
1704 | case Attendee::Delegated: | 1707 | case Attendee::Delegated: |
1705 | return "DELEGATED"; | 1708 | return "DELEGATED"; |
1706 | break; | 1709 | break; |
1707 | case Attendee::Completed: | 1710 | case Attendee::Completed: |
1708 | return "COMPLETED"; | 1711 | return "COMPLETED"; |
1709 | break; | 1712 | break; |
1710 | case Attendee::InProcess: | 1713 | case Attendee::InProcess: |
1711 | return "NEEDS ACTION"; | 1714 | return "NEEDS ACTION"; |
1712 | break; | 1715 | break; |
1713 | } | 1716 | } |
1714 | } | 1717 | } |
diff --git a/libkcal/vcalformat.h b/libkcal/vcalformat.h index 848be78..5bef7ed 100644 --- a/libkcal/vcalformat.h +++ b/libkcal/vcalformat.h | |||
@@ -1,111 +1,112 @@ | |||
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 | void setLocalTime ( bool ); | ||
64 | QString toString( Calendar * ); | 65 | QString toString( Calendar * ); |
65 | QString eventToString( Event *, Calendar *calendar, bool useLocalTime = true ); | 66 | QString eventToString( Event *, Calendar *calendar, bool useLocalTime = true ); |
66 | QString todoToString( Todo * ,Calendar *calendar, bool useLocalTime = true ); | 67 | QString todoToString( Todo * ,Calendar *calendar, bool useLocalTime = true ); |
67 | 68 | ||
68 | protected: | 69 | protected: |
69 | /** translates a VObject of the TODO type into a Event */ | 70 | /** translates a VObject of the TODO type into a Event */ |
70 | Todo *VTodoToEvent(VObject *vtodo); | 71 | Todo *VTodoToEvent(VObject *vtodo); |
71 | /** translates a VObject into a Event and returns a pointer to it. */ | 72 | /** translates a VObject into a Event and returns a pointer to it. */ |
72 | Event *VEventToEvent(VObject *vevent); | 73 | Event *VEventToEvent(VObject *vevent); |
73 | /** translate a Event into a VTodo-type VObject and return pointer */ | 74 | /** translate a Event into a VTodo-type VObject and return pointer */ |
74 | VObject *eventToVTodo(const Todo *anEvent); | 75 | VObject *eventToVTodo(const Todo *anEvent); |
75 | /** translate a Event into a VObject and returns a pointer to it. */ | 76 | /** translate a Event into a VObject and returns a pointer to it. */ |
76 | VObject* eventToVEvent(const Event *anEvent); | 77 | VObject* eventToVEvent(const Event *anEvent); |
77 | 78 | ||
78 | /** takes a QDate and returns a string in the format YYYYMMDDTHHMMSS */ | 79 | /** takes a QDate and returns a string in the format YYYYMMDDTHHMMSS */ |
79 | QString qDateToISO(const QDate &); | 80 | QString qDateToISO(const QDate &); |
80 | /** takes a QDateTime and returns a string in format YYYYMMDDTHHMMSS */ | 81 | /** takes a QDateTime and returns a string in format YYYYMMDDTHHMMSS */ |
81 | QString qDateTimeToISO(const QDateTime &, bool zulu=TRUE); | 82 | QString qDateTimeToISO(const QDateTime &, bool zulu=TRUE); |
82 | /** takes a string in the format YYYYMMDDTHHMMSS and returns a | 83 | /** takes a string in the format YYYYMMDDTHHMMSS and returns a |
83 | * valid QDateTime. */ | 84 | * valid QDateTime. */ |
84 | QDateTime ISOToQDateTime(const QString & dtStr); | 85 | QDateTime ISOToQDateTime(const QString & dtStr); |
85 | /** takes a string in the format YYYYMMDD and returns a | 86 | /** takes a string in the format YYYYMMDD and returns a |
86 | * valid QDate. */ | 87 | * valid QDate. */ |
87 | QDate ISOToQDate(const QString & dtStr); | 88 | QDate ISOToQDate(const QString & dtStr); |
88 | /** takes a vCalendar tree of VObjects, and puts all of them that have | 89 | /** 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. */ | 90 | * the "event" property into the dictionary, todos in the todo-list, etc. */ |
90 | void populate(VObject *vcal); | 91 | void populate(VObject *vcal); |
91 | 92 | ||
92 | /** takes a number 0 - 6 and returns the two letter string of that day, | 93 | /** takes a number 0 - 6 and returns the two letter string of that day, |
93 | * i.e. MO, TU, WE, etc. */ | 94 | * i.e. MO, TU, WE, etc. */ |
94 | const char *dayFromNum(int day); | 95 | const char *dayFromNum(int day); |
95 | /** the reverse of the above function. */ | 96 | /** the reverse of the above function. */ |
96 | int numFromDay(const QString &day); | 97 | int numFromDay(const QString &day); |
97 | 98 | ||
98 | Attendee::PartStat readStatus(const char *s) const; | 99 | Attendee::PartStat readStatus(const char *s) const; |
99 | QCString writeStatus(Attendee::PartStat status) const; | 100 | QCString writeStatus(Attendee::PartStat status) const; |
100 | 101 | ||
101 | private: | 102 | private: |
102 | Calendar *mCalendar; | 103 | Calendar *mCalendar; |
103 | bool useLocalTime; | 104 | bool useLocalTime; |
104 | 105 | ||
105 | QPtrList<Event> mEventsRelate; // events with relations | 106 | QPtrList<Event> mEventsRelate; // events with relations |
106 | QPtrList<Todo> mTodosRelate; // todos with relations | 107 | QPtrList<Todo> mTodosRelate; // todos with relations |
107 | }; | 108 | }; |
108 | 109 | ||
109 | } | 110 | } |
110 | 111 | ||
111 | #endif | 112 | #endif |