author | zautrix <zautrix> | 2004-09-12 17:18:27 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-09-12 17:18:27 (UTC) |
commit | bc4153a99e205f43d0144e2e910730dd1a14d402 (patch) (unidiff) | |
tree | 16aeb28cd765539bac6e85e714478f31a7b93bac /libkcal | |
parent | a222c2f7369eeefd19454c973c0cc48300f72bec (diff) | |
download | kdepimpi-bc4153a99e205f43d0144e2e910730dd1a14d402.zip kdepimpi-bc4153a99e205f43d0144e2e910730dd1a14d402.tar.gz kdepimpi-bc4153a99e205f43d0144e2e910730dd1a14d402.tar.bz2 |
added missing sync featute
-rw-r--r-- | libkcal/phoneformat.cpp | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp index ef69bce..6d0da5c 100644 --- a/libkcal/phoneformat.cpp +++ b/libkcal/phoneformat.cpp | |||
@@ -86,551 +86,552 @@ PhoneFormat::PhoneFormat(QString profileName, QString device,QString connection, | |||
86 | mProfileName = profileName; | 86 | mProfileName = profileName; |
87 | mDevice = device; | 87 | mDevice = device; |
88 | mConnection = connection; | 88 | mConnection = connection; |
89 | mModel = model; | 89 | mModel = model; |
90 | } | 90 | } |
91 | 91 | ||
92 | PhoneFormat::~PhoneFormat() | 92 | PhoneFormat::~PhoneFormat() |
93 | { | 93 | { |
94 | } | 94 | } |
95 | #if 0 | 95 | #if 0 |
96 | int PhoneFormat::initDevice(GSM_StateMachine *s) | 96 | int PhoneFormat::initDevice(GSM_StateMachine *s) |
97 | { | 97 | { |
98 | GSM_ReadConfig(NULL, &s->Config[0], 0); | 98 | GSM_ReadConfig(NULL, &s->Config[0], 0); |
99 | s->ConfigNum = 1; | 99 | s->ConfigNum = 1; |
100 | GSM_Config *cfg = &s->Config[0]; | 100 | GSM_Config *cfg = &s->Config[0]; |
101 | if ( ! mConnection.isEmpty() ) { | 101 | if ( ! mConnection.isEmpty() ) { |
102 | cfg->Connection = strdup(mConnection.latin1()); | 102 | cfg->Connection = strdup(mConnection.latin1()); |
103 | cfg->DefaultConnection = false; | 103 | cfg->DefaultConnection = false; |
104 | qDebug("Connection set %s ", cfg->Connection ); | 104 | qDebug("Connection set %s ", cfg->Connection ); |
105 | 105 | ||
106 | } | 106 | } |
107 | if ( ! mDevice.isEmpty() ) { | 107 | if ( ! mDevice.isEmpty() ) { |
108 | cfg->Device = strdup(mDevice.latin1()); | 108 | cfg->Device = strdup(mDevice.latin1()); |
109 | cfg->DefaultDevice = false; | 109 | cfg->DefaultDevice = false; |
110 | qDebug("Device set %s ", cfg->Device); | 110 | qDebug("Device set %s ", cfg->Device); |
111 | 111 | ||
112 | } | 112 | } |
113 | if ( ! mModel.isEmpty() ) { | 113 | if ( ! mModel.isEmpty() ) { |
114 | strcpy(cfg->Model,mModel.latin1() ); | 114 | strcpy(cfg->Model,mModel.latin1() ); |
115 | cfg->DefaultModel = false; | 115 | cfg->DefaultModel = false; |
116 | qDebug("Model set %s ",cfg->Model ); | 116 | qDebug("Model set %s ",cfg->Model ); |
117 | } | 117 | } |
118 | int error=GSM_InitConnection(s,3); | 118 | int error=GSM_InitConnection(s,3); |
119 | return error; | 119 | return error; |
120 | } | 120 | } |
121 | #endif | 121 | #endif |
122 | ulong PhoneFormat::getCsumTodo( Todo* todo ) | 122 | ulong PhoneFormat::getCsumTodo( Todo* todo ) |
123 | { | 123 | { |
124 | QStringList attList; | 124 | QStringList attList; |
125 | if ( todo->hasDueDate() ) | 125 | if ( todo->hasDueDate() ) |
126 | attList << PhoneParser::dtToString ( todo->dtDue() ); | 126 | attList << PhoneParser::dtToString ( todo->dtDue() ); |
127 | attList << todo->summary(); | 127 | attList << todo->summary(); |
128 | QString completedString = "no"; | 128 | QString completedString = "no"; |
129 | if ( todo->isCompleted() ) | 129 | if ( todo->isCompleted() ) |
130 | completedString = "yes"; | 130 | completedString = "yes"; |
131 | attList << completedString; | 131 | attList << completedString; |
132 | int prio = todo->priority(); | 132 | int prio = todo->priority(); |
133 | if( prio == 2 ) prio = 1; | 133 | if( prio == 2 ) prio = 1; |
134 | if (prio == 4 ) prio = 5 ; | 134 | if (prio == 4 ) prio = 5 ; |
135 | attList << QString::number( prio ); | 135 | attList << QString::number( prio ); |
136 | QString alarmString = "na"; | 136 | QString alarmString = "na"; |
137 | Alarm *alarm; | 137 | Alarm *alarm; |
138 | if ( todo->alarms().count() > 0 ) { | 138 | if ( todo->alarms().count() > 0 ) { |
139 | alarm = todo->alarms().first(); | 139 | alarm = todo->alarms().first(); |
140 | if ( alarm->enabled() ) { | 140 | if ( alarm->enabled() ) { |
141 | alarmString = QString::number(alarm->startOffset().asSeconds() ); | 141 | alarmString = QString::number(alarm->startOffset().asSeconds() ); |
142 | } | 142 | } |
143 | } | 143 | } |
144 | attList << alarmString; | 144 | attList << alarmString; |
145 | attList << todo->categoriesStr(); | 145 | attList << todo->categoriesStr(); |
146 | attList << todo->secrecyStr(); | 146 | attList << todo->secrecyStr(); |
147 | return PhoneFormat::getCsum(attList ); | 147 | return PhoneFormat::getCsum(attList ); |
148 | 148 | ||
149 | } | 149 | } |
150 | ulong PhoneFormat::getCsumEvent( Event* event ) | 150 | ulong PhoneFormat::getCsumEvent( Event* event ) |
151 | { | 151 | { |
152 | QStringList attList; | 152 | QStringList attList; |
153 | attList << PhoneParser::dtToString ( event->dtStart() ); | 153 | attList << PhoneParser::dtToString ( event->dtStart() ); |
154 | attList << PhoneParser::dtToString ( event->dtEnd() ); | 154 | attList << PhoneParser::dtToString ( event->dtEnd() ); |
155 | attList << event->summary(); | 155 | attList << event->summary(); |
156 | attList << event->location(); | 156 | attList << event->location(); |
157 | QString alarmString = "na"; | 157 | QString alarmString = "na"; |
158 | Alarm *alarm; | 158 | Alarm *alarm; |
159 | if ( event->alarms().count() > 0 ) { | 159 | if ( event->alarms().count() > 0 ) { |
160 | alarm = event->alarms().first(); | 160 | alarm = event->alarms().first(); |
161 | if ( alarm->enabled() ) { | 161 | if ( alarm->enabled() ) { |
162 | alarmString = QString::number( alarm->startOffset().asSeconds() ); | 162 | alarmString = QString::number( alarm->startOffset().asSeconds() ); |
163 | } | 163 | } |
164 | } | 164 | } |
165 | attList << alarmString; | 165 | attList << alarmString; |
166 | Recurrence* rec = event->recurrence(); | 166 | Recurrence* rec = event->recurrence(); |
167 | QStringList list; | 167 | QStringList list; |
168 | bool writeEndDate = false; | 168 | bool writeEndDate = false; |
169 | switch ( rec->doesRecur() ) | 169 | switch ( rec->doesRecur() ) |
170 | { | 170 | { |
171 | case Recurrence::rDaily: // 0 | 171 | case Recurrence::rDaily: // 0 |
172 | list.append( "0" ); | 172 | list.append( "0" ); |
173 | list.append( QString::number( rec->frequency() ));//12 | 173 | list.append( QString::number( rec->frequency() ));//12 |
174 | list.append( "0" ); | 174 | list.append( "0" ); |
175 | list.append( "0" ); | 175 | list.append( "0" ); |
176 | writeEndDate = true; | 176 | writeEndDate = true; |
177 | break; | 177 | break; |
178 | case Recurrence::rWeekly:// 1 | 178 | case Recurrence::rWeekly:// 1 |
179 | list.append( "1" ); | 179 | list.append( "1" ); |
180 | list.append( QString::number( rec->frequency()) );//12 | 180 | list.append( QString::number( rec->frequency()) );//12 |
181 | list.append( "0" ); | 181 | list.append( "0" ); |
182 | { | 182 | { |
183 | int days = 0; | 183 | int days = 0; |
184 | QBitArray weekDays = rec->days(); | 184 | QBitArray weekDays = rec->days(); |
185 | int i; | 185 | int i; |
186 | for( i = 1; i <= 7; ++i ) { | 186 | for( i = 1; i <= 7; ++i ) { |
187 | if ( weekDays[i-1] ) { | 187 | if ( weekDays[i-1] ) { |
188 | days += 1 << (i-1); | 188 | days += 1 << (i-1); |
189 | } | 189 | } |
190 | } | 190 | } |
191 | list.append( QString::number( days ) ); | 191 | list.append( QString::number( days ) ); |
192 | } | 192 | } |
193 | //pending weekdays | 193 | //pending weekdays |
194 | writeEndDate = true; | 194 | writeEndDate = true; |
195 | 195 | ||
196 | break; | 196 | break; |
197 | case Recurrence::rMonthlyPos:// 2 | 197 | case Recurrence::rMonthlyPos:// 2 |
198 | list.append( "2" ); | 198 | list.append( "2" ); |
199 | list.append( QString::number( rec->frequency()) );//12 | 199 | list.append( QString::number( rec->frequency()) );//12 |
200 | 200 | ||
201 | writeEndDate = true; | 201 | writeEndDate = true; |
202 | { | 202 | { |
203 | int count = 1; | 203 | int count = 1; |
204 | QPtrList<Recurrence::rMonthPos> rmp; | 204 | QPtrList<Recurrence::rMonthPos> rmp; |
205 | rmp = rec->monthPositions(); | 205 | rmp = rec->monthPositions(); |
206 | if ( rmp.first()->negative ) | 206 | if ( rmp.first()->negative ) |
207 | count = 5 - rmp.first()->rPos - 1; | 207 | count = 5 - rmp.first()->rPos - 1; |
208 | else | 208 | else |
209 | count = rmp.first()->rPos - 1; | 209 | count = rmp.first()->rPos - 1; |
210 | list.append( QString::number( count ) ); | 210 | list.append( QString::number( count ) ); |
211 | 211 | ||
212 | } | 212 | } |
213 | 213 | ||
214 | list.append( "0" ); | 214 | list.append( "0" ); |
215 | break; | 215 | break; |
216 | case Recurrence::rMonthlyDay:// 3 | 216 | case Recurrence::rMonthlyDay:// 3 |
217 | list.append( "3" ); | 217 | list.append( "3" ); |
218 | list.append( QString::number( rec->frequency()) );//12 | 218 | list.append( QString::number( rec->frequency()) );//12 |
219 | list.append( "0" ); | 219 | list.append( "0" ); |
220 | list.append( "0" ); | 220 | list.append( "0" ); |
221 | writeEndDate = true; | 221 | writeEndDate = true; |
222 | break; | 222 | break; |
223 | case Recurrence::rYearlyMonth://4 | 223 | case Recurrence::rYearlyMonth://4 |
224 | list.append( "4" ); | 224 | list.append( "4" ); |
225 | list.append( QString::number( rec->frequency()) );//12 | 225 | list.append( QString::number( rec->frequency()) );//12 |
226 | list.append( "0" ); | 226 | list.append( "0" ); |
227 | list.append( "0" ); | 227 | list.append( "0" ); |
228 | writeEndDate = true; | 228 | writeEndDate = true; |
229 | break; | 229 | break; |
230 | 230 | ||
231 | default: | 231 | default: |
232 | list.append( "255" ); | 232 | list.append( "255" ); |
233 | list.append( QString() ); | 233 | list.append( QString() ); |
234 | list.append( "0" ); | 234 | list.append( "0" ); |
235 | list.append( QString() ); | 235 | list.append( QString() ); |
236 | list.append( "0" ); | 236 | list.append( "0" ); |
237 | list.append( "20991231T000000" ); | 237 | list.append( "20991231T000000" ); |
238 | break; | 238 | break; |
239 | } | 239 | } |
240 | if ( writeEndDate ) { | 240 | if ( writeEndDate ) { |
241 | 241 | ||
242 | if ( rec->endDate().isValid() ) { // 15 + 16 | 242 | if ( rec->endDate().isValid() ) { // 15 + 16 |
243 | list.append( "1" ); | 243 | list.append( "1" ); |
244 | list.append( PhoneParser::dtToString( rec->endDate()) ); | 244 | list.append( PhoneParser::dtToString( rec->endDate()) ); |
245 | } else { | 245 | } else { |
246 | list.append( "0" ); | 246 | list.append( "0" ); |
247 | list.append( "20991231T000000" ); | 247 | list.append( "20991231T000000" ); |
248 | } | 248 | } |
249 | 249 | ||
250 | } | 250 | } |
251 | attList << list.join(""); | 251 | attList << list.join(""); |
252 | attList << event->categoriesStr(); | 252 | attList << event->categoriesStr(); |
253 | //qDebug("csum cat %s", event->categoriesStr().latin1()); | 253 | //qDebug("csum cat %s", event->categoriesStr().latin1()); |
254 | 254 | ||
255 | attList << event->secrecyStr(); | 255 | attList << event->secrecyStr(); |
256 | return PhoneFormat::getCsum(attList ); | 256 | return PhoneFormat::getCsum(attList ); |
257 | } | 257 | } |
258 | ulong PhoneFormat::getCsum( const QStringList & attList) | 258 | ulong PhoneFormat::getCsum( const QStringList & attList) |
259 | { | 259 | { |
260 | int max = attList.count(); | 260 | int max = attList.count(); |
261 | ulong cSum = 0; | 261 | ulong cSum = 0; |
262 | int j,k,i; | 262 | int j,k,i; |
263 | int add; | 263 | int add; |
264 | for ( i = 0; i < max ; ++i ) { | 264 | for ( i = 0; i < max ; ++i ) { |
265 | QString s = attList[i]; | 265 | QString s = attList[i]; |
266 | if ( ! s.isEmpty() ){ | 266 | if ( ! s.isEmpty() ){ |
267 | j = s.length(); | 267 | j = s.length(); |
268 | for ( k = 0; k < j; ++k ) { | 268 | for ( k = 0; k < j; ++k ) { |
269 | int mul = k +1; | 269 | int mul = k +1; |
270 | add = s[k].unicode (); | 270 | add = s[k].unicode (); |
271 | if ( k < 16 ) | 271 | if ( k < 16 ) |
272 | mul = mul * mul; | 272 | mul = mul * mul; |
273 | int ii = i+1; | 273 | int ii = i+1; |
274 | add = add * mul *ii*ii*ii; | 274 | add = add * mul *ii*ii*ii; |
275 | cSum += add; | 275 | cSum += add; |
276 | } | 276 | } |
277 | } | 277 | } |
278 | if ( i == 0 ) | ||
279 | qDebug("csum: i == 0 %d ", cSum); | ||
280 | 278 | ||
281 | } | 279 | } |
282 | QString dump = attList.join(","); | 280 | QString dump = attList.join(","); |
283 | qDebug("csum: %d %s", cSum,dump.latin1()); | 281 | qDebug("csum: %d %s", cSum,dump.latin1()); |
284 | 282 | ||
285 | return cSum; | 283 | return cSum; |
286 | 284 | ||
287 | } | 285 | } |
288 | //extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum); | 286 | //extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum); |
289 | #include <stdlib.h> | 287 | #include <stdlib.h> |
290 | #define DEBUGMODE false | 288 | #define DEBUGMODE false |
291 | bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal) | 289 | bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal) |
292 | { | 290 | { |
293 | 291 | ||
294 | QString fileName; | 292 | QString fileName; |
295 | #ifdef _WIN32_ | 293 | #ifdef _WIN32_ |
296 | fileName = locateLocal("data", "korganizer") + "\\tempfile.vcs"; | 294 | fileName = locateLocal("data", "korganizer") + "\\tempfile.vcs"; |
297 | #else | 295 | #else |
298 | fileName = "/tmp/kdepimtemp.vcs"; | 296 | fileName = "/tmp/kdepimtemp.vcs"; |
299 | #endif | 297 | #endif |
300 | QString command ="./kammu --backup " + fileName + " -yes" ; | 298 | QString command ="./kammu --backup " + fileName + " -yes" ; |
301 | int ret = system ( command.latin1() ); | 299 | int ret = system ( command.latin1() ); |
302 | if ( ret != 0 ) { | 300 | if ( ret != 0 ) { |
303 | qDebug("Error::command returned %d", ret); | 301 | qDebug("Error::command returned %d", ret); |
304 | return false; | 302 | return false; |
305 | } | 303 | } |
306 | qDebug("Command returned %d", ret); | 304 | qDebug("Command returned %d", ret); |
307 | VCalFormat vfload; | 305 | VCalFormat vfload; |
308 | vfload.setLocalTime ( true ); | 306 | vfload.setLocalTime ( true ); |
309 | qDebug("loading file ..."); | 307 | qDebug("loading file ..."); |
310 | 308 | ||
311 | if ( ! vfload.load( calendar, fileName ) ) | 309 | if ( ! vfload.load( calendar, fileName ) ) |
312 | return false; | 310 | return false; |
313 | QPtrList<Event> er = calendar->rawEvents(); | 311 | QPtrList<Event> er = calendar->rawEvents(); |
314 | Event* ev = er.first(); | 312 | Event* ev = er.first(); |
315 | qDebug("reading events... "); | 313 | qDebug("reading events... "); |
316 | while ( ev ) { | 314 | while ( ev ) { |
317 | QStringList cat = ev->categories(); | 315 | QStringList cat = ev->categories(); |
318 | if ( cat.contains( "MeetingDEF" )) { | 316 | if ( cat.contains( "MeetingDEF" )) { |
319 | ev->setCategories( QStringList() ); | 317 | ev->setCategories( QStringList() ); |
320 | } | 318 | } |
321 | int id = ev->pilotId(); | 319 | int id = ev->pilotId(); |
322 | Event *event; | 320 | Event *event; |
323 | event = existingCal->event( mProfileName ,QString::number( id ) ); | 321 | event = existingCal->event( mProfileName ,QString::number( id ) ); |
324 | if ( event ) { | 322 | if ( event ) { |
325 | event = (Event*)event->clone(); | 323 | event = (Event*)event->clone(); |
326 | copyEvent( event, ev ); | 324 | copyEvent( event, ev ); |
327 | calendar->deleteEvent( ev ); | 325 | calendar->deleteEvent( ev ); |
328 | calendar->addEvent( event); | 326 | calendar->addEvent( event); |
329 | } | 327 | } |
330 | else | 328 | else |
331 | event = ev; | 329 | event = ev; |
332 | uint cSum; | 330 | uint cSum; |
333 | cSum = PhoneFormat::getCsumEvent( event ); | 331 | cSum = PhoneFormat::getCsumEvent( event ); |
334 | event->setCsum( mProfileName, QString::number( cSum )); | 332 | event->setCsum( mProfileName, QString::number( cSum )); |
335 | event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); | 333 | event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); |
336 | event->setID( mProfileName,QString::number( id ) ); | 334 | event->setID( mProfileName,QString::number( id ) ); |
337 | ev = er.next(); | 335 | ev = er.next(); |
338 | } | 336 | } |
339 | { | 337 | { |
340 | qDebug("reading todos... "); | 338 | qDebug("reading todos... "); |
341 | QPtrList<Todo> tr = calendar->rawTodos(); | 339 | QPtrList<Todo> tr = calendar->rawTodos(); |
342 | Todo* ev = tr.first(); | 340 | Todo* ev = tr.first(); |
343 | while ( ev ) { | 341 | while ( ev ) { |
344 | 342 | ||
345 | QStringList cat = ev->categories(); | 343 | QStringList cat = ev->categories(); |
346 | if ( cat.contains( "MeetingDEF" )) { | 344 | if ( cat.contains( "MeetingDEF" )) { |
347 | ev->setCategories( QStringList() ); | 345 | ev->setCategories( QStringList() ); |
348 | } | 346 | } |
349 | int id = ev->pilotId(); | 347 | int id = ev->pilotId(); |
350 | Todo *event; | 348 | Todo *event; |
351 | event = existingCal->todo( mProfileName ,QString::number( id ) ); | 349 | event = existingCal->todo( mProfileName ,QString::number( id ) ); |
352 | if ( event ) { | 350 | if ( event ) { |
353 | qDebug("copy todo %s ", event->summary().latin1()); | 351 | qDebug("copy todo %s ", event->summary().latin1()); |
354 | 352 | ||
355 | event = (Todo*)event->clone(); | 353 | event = (Todo*)event->clone(); |
356 | copyTodo( event, ev ); | 354 | copyTodo( event, ev ); |
357 | calendar->deleteTodo( ev ); | 355 | calendar->deleteTodo( ev ); |
358 | calendar->addTodo( event); | 356 | calendar->addTodo( event); |
359 | } | 357 | } |
360 | else | 358 | else |
361 | event = ev; | 359 | event = ev; |
362 | uint cSum; | 360 | uint cSum; |
363 | cSum = PhoneFormat::getCsumTodo( event ); | 361 | cSum = PhoneFormat::getCsumTodo( event ); |
364 | event->setCsum( mProfileName, QString::number( cSum )); | 362 | event->setCsum( mProfileName, QString::number( cSum )); |
365 | event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); | 363 | event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); |
366 | event->setID( mProfileName,QString::number( id ) ); | 364 | event->setID( mProfileName,QString::number( id ) ); |
367 | ev = tr.next(); | 365 | ev = tr.next(); |
368 | } | 366 | } |
369 | } | 367 | } |
370 | return true; | 368 | return true; |
371 | } | 369 | } |
372 | void PhoneFormat::copyEvent( Event* to, Event* from ) | 370 | void PhoneFormat::copyEvent( Event* to, Event* from ) |
373 | { | 371 | { |
374 | if ( from->dtStart().isValid() ) | 372 | if ( from->dtStart().isValid() ) |
375 | to->setDtStart( from->dtStart() ); | 373 | to->setDtStart( from->dtStart() ); |
376 | if ( from->dtEnd().isValid() ) | 374 | if ( from->dtEnd().isValid() ) |
377 | to->setDtEnd( from->dtEnd() ); | 375 | to->setDtEnd( from->dtEnd() ); |
378 | if ( !from->location().isEmpty() ) | 376 | if ( !from->location().isEmpty() ) |
379 | to->setLocation( from->location() ); | 377 | to->setLocation( from->location() ); |
380 | if ( !from->description().isEmpty() ) | 378 | if ( !from->description().isEmpty() ) |
381 | to->setDescription( from->description() ); | 379 | to->setDescription( from->description() ); |
382 | if ( !from->summary().isEmpty() ) | 380 | if ( !from->summary().isEmpty() ) |
383 | to->setSummary( from->summary() ); | 381 | to->setSummary( from->summary() ); |
384 | 382 | ||
385 | QPtrListIterator<Alarm> it( from->alarms() ); | 383 | QPtrListIterator<Alarm> it( from->alarms() ); |
386 | if ( it.current() ) | 384 | if ( it.current() ) |
387 | to->clearAlarms(); | 385 | to->clearAlarms(); |
388 | const Alarm *a; | 386 | const Alarm *a; |
389 | while( (a = it.current()) ) { | 387 | while( (a = it.current()) ) { |
390 | Alarm *b = new Alarm( *a ); | 388 | Alarm *b = new Alarm( *a ); |
391 | b->setParent( to ); | 389 | b->setParent( to ); |
392 | to->addAlarm( b ); | 390 | to->addAlarm( b ); |
393 | ++it; | 391 | ++it; |
394 | } | 392 | } |
395 | QStringList cat = to->categories(); | 393 | QStringList cat = to->categories(); |
396 | QStringList catFrom = from->categories(); | 394 | QStringList catFrom = from->categories(); |
397 | QString nCat; | 395 | QString nCat; |
398 | int iii; | 396 | int iii; |
399 | for ( iii = 0; iii < catFrom.count();++iii ) { | 397 | for ( iii = 0; iii < catFrom.count();++iii ) { |
400 | nCat = catFrom[iii]; | 398 | nCat = catFrom[iii]; |
401 | if ( !nCat.isEmpty() ) | 399 | if ( !nCat.isEmpty() ) |
402 | if ( !cat.contains( nCat )) { | 400 | if ( !cat.contains( nCat )) { |
403 | cat << nCat; | 401 | cat << nCat; |
404 | } | 402 | } |
405 | } | 403 | } |
406 | to->setCategories( cat ); | 404 | to->setCategories( cat ); |
407 | Recurrence * r = new Recurrence( *from->recurrence(),to); | 405 | Recurrence * r = new Recurrence( *from->recurrence(),to); |
408 | to->setRecurrence( r ) ; | 406 | to->setRecurrence( r ) ; |
409 | 407 | ||
410 | 408 | ||
411 | } | 409 | } |
412 | void PhoneFormat::copyTodo( Todo* to, Todo* from ) | 410 | void PhoneFormat::copyTodo( Todo* to, Todo* from ) |
413 | { | 411 | { |
414 | if ( from->dtStart().isValid() ) | 412 | if ( from->dtStart().isValid() ) |
415 | to->setDtStart( from->dtStart() ); | 413 | to->setDtStart( from->dtStart() ); |
416 | if ( from->dtDue().isValid() ) | 414 | if ( from->dtDue().isValid() ) |
417 | to->setDtDue( from->dtDue() ); | 415 | to->setDtDue( from->dtDue() ); |
418 | if ( !from->location().isEmpty() ) | 416 | if ( !from->location().isEmpty() ) |
419 | to->setLocation( from->location() ); | 417 | to->setLocation( from->location() ); |
420 | if ( !from->description().isEmpty() ) | 418 | if ( !from->description().isEmpty() ) |
421 | to->setDescription( from->description() ); | 419 | to->setDescription( from->description() ); |
422 | if ( !from->summary().isEmpty() ) | 420 | if ( !from->summary().isEmpty() ) |
423 | to->setSummary( from->summary() ); | 421 | to->setSummary( from->summary() ); |
424 | 422 | ||
425 | QPtrListIterator<Alarm> it( from->alarms() ); | 423 | QPtrListIterator<Alarm> it( from->alarms() ); |
426 | if ( it.current() ) | 424 | if ( it.current() ) |
427 | to->clearAlarms(); | 425 | to->clearAlarms(); |
428 | const Alarm *a; | 426 | const Alarm *a; |
429 | while( (a = it.current()) ) { | 427 | while( (a = it.current()) ) { |
430 | Alarm *b = new Alarm( *a ); | 428 | Alarm *b = new Alarm( *a ); |
431 | b->setParent( to ); | 429 | b->setParent( to ); |
432 | to->addAlarm( b ); | 430 | to->addAlarm( b ); |
433 | ++it; | 431 | ++it; |
434 | } | 432 | } |
435 | QStringList cat = to->categories(); | 433 | QStringList cat = to->categories(); |
436 | QStringList catFrom = from->categories(); | 434 | QStringList catFrom = from->categories(); |
437 | QString nCat; | 435 | QString nCat; |
438 | int iii; | 436 | int iii; |
439 | for ( iii = 0; iii < catFrom.count();++iii ) { | 437 | for ( iii = 0; iii < catFrom.count();++iii ) { |
440 | nCat = catFrom[iii]; | 438 | nCat = catFrom[iii]; |
441 | if ( !nCat.isEmpty() ) | 439 | if ( !nCat.isEmpty() ) |
442 | if ( !cat.contains( nCat )) { | 440 | if ( !cat.contains( nCat )) { |
443 | cat << nCat; | 441 | cat << nCat; |
444 | } | 442 | } |
445 | } | 443 | } |
446 | to->setCategories( cat ); | 444 | to->setCategories( cat ); |
447 | if ( from->isCompleted() ) { | 445 | if ( from->isCompleted() ) { |
448 | to->setCompleted( true ); | 446 | to->setCompleted( true ); |
449 | if( from->completed().isValid() ) | 447 | if( from->completed().isValid() ) |
450 | to->setCompleted( from->completed() ); | 448 | to->setCompleted( from->completed() ); |
451 | } else { | 449 | } else { |
452 | // set percentcomplete only, if to->isCompleted() | 450 | // set percentcomplete only, if to->isCompleted() |
453 | if ( to->isCompleted() ) | 451 | if ( to->isCompleted() ) |
454 | to->setPercentComplete(from->percentComplete()); | 452 | to->setPercentComplete(from->percentComplete()); |
455 | } | 453 | } |
456 | if( to->priority() == 2 && from->priority() == 1 ) | 454 | if( to->priority() == 2 && from->priority() == 1 ) |
457 | ; //skip | 455 | ; //skip |
458 | else if (to->priority() == 4 && from->priority() == 5 ) | 456 | else if (to->priority() == 4 && from->priority() == 5 ) |
459 | ; | 457 | ; |
460 | else | 458 | else |
461 | to->setPriority(from->priority()); | 459 | to->setPriority(from->priority()); |
462 | 460 | ||
463 | } | 461 | } |
464 | #include <qcstring.h> | 462 | #include <qcstring.h> |
465 | 463 | ||
466 | void PhoneFormat::afterSave( Incidence* inc) | 464 | void PhoneFormat::afterSave( Incidence* inc) |
467 | { | 465 | { |
468 | uint csum; | 466 | uint csum; |
469 | inc->removeID( mProfileName ); | 467 | inc->removeID( mProfileName ); |
470 | #if 0 | ||
471 | if ( inc->type() == "Event") | 468 | if ( inc->type() == "Event") |
472 | csum = PhoneFormat::getCsumEvent( (Event*) inc ); | 469 | csum = PhoneFormat::getCsumEvent( (Event*) inc ); |
473 | else | 470 | else |
474 | csum = PhoneFormat::getCsumTodo( (Todo*) inc ); | 471 | csum = PhoneFormat::getCsumTodo( (Todo*) inc ); |
475 | inc->setCsum( mProfileName, QString::number( csum )); | 472 | inc->setCsum( mProfileName, QString::number( csum )); |
476 | #endif | 473 | |
477 | inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 474 | inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); |
478 | 475 | ||
479 | } | 476 | } |
480 | bool PhoneFormat::save( Calendar *calendar) | 477 | bool PhoneFormat::save( Calendar *calendar) |
481 | { | 478 | { |
482 | QLabel status ( i18n(" Opening device ..."), 0 ); | 479 | QLabel status ( i18n(" Opening device ..."), 0 ); |
483 | int w = status.sizeHint().width()+20 ; | 480 | int w = status.sizeHint().width()+20 ; |
484 | if ( w < 200 ) w = 230; | 481 | if ( w < 200 ) w = 230; |
485 | int h = status.sizeHint().height()+20 ; | 482 | int h = status.sizeHint().height()+20 ; |
486 | int dw = QApplication::desktop()->width(); | 483 | int dw = QApplication::desktop()->width(); |
487 | int dh = QApplication::desktop()->height(); | 484 | int dh = QApplication::desktop()->height(); |
488 | status.setCaption(i18n("Writing to phone...") ); | 485 | status.setCaption(i18n("Writing to phone...") ); |
489 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 486 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
490 | status.show(); | 487 | status.show(); |
491 | status.raise(); | 488 | status.raise(); |
492 | qApp->processEvents(); | 489 | qApp->processEvents(); |
493 | QString message; | 490 | QString message; |
494 | #ifdef _WIN32_ | 491 | #ifdef _WIN32_ |
495 | QString fileName = locateLocal("data", "korganizer") + "\\tempfile.vcs"; | 492 | QString fileName = locateLocal("data", "korganizer") + "\\tempfile.vcs"; |
496 | #else | 493 | #else |
497 | QString fileName = "/tmp/kdepimtemp.vcs"; | 494 | QString fileName = "/tmp/kdepimtemp.vcs"; |
498 | #endif | 495 | #endif |
499 | 496 | ||
500 | // 1 remove events which should be deleted | 497 | // 1 remove events which should be deleted |
501 | QPtrList<Event> er = calendar->rawEvents(); | 498 | QPtrList<Event> er = calendar->rawEvents(); |
502 | Event* ev = er.first(); | 499 | Event* ev = er.first(); |
503 | while ( ev ) { | 500 | while ( ev ) { |
504 | if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { | 501 | if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { |
505 | calendar->deleteEvent( ev ); | 502 | calendar->deleteEvent( ev ); |
506 | } else { | 503 | } else { |
507 | 504 | ||
508 | } | 505 | } |
509 | ev = er.next(); | 506 | ev = er.next(); |
510 | } | 507 | } |
511 | // 2 remove todos which should be deleted | 508 | // 2 remove todos which should be deleted |
512 | QPtrList<Todo> tl = calendar->rawTodos(); | 509 | QPtrList<Todo> tl = calendar->rawTodos(); |
513 | Todo* to = tl.first(); | 510 | Todo* to = tl.first(); |
514 | while ( to ) { | 511 | while ( to ) { |
515 | if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { | 512 | if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { |
516 | calendar->deleteTodo( to ); | 513 | calendar->deleteTodo( to ); |
517 | } | 514 | } else { |
515 | if ( to->isCompleted()) { | ||
516 | calendar->deleteTodo( to ); | ||
517 | } | ||
518 | } | ||
518 | to = tl.next(); | 519 | to = tl.next(); |
519 | } | 520 | } |
520 | // 3 save file | 521 | // 3 save file |
521 | VCalFormat vfsave; | 522 | VCalFormat vfsave; |
522 | vfsave.setLocalTime ( true ); | 523 | vfsave.setLocalTime ( true ); |
523 | if ( ! vfsave.save( calendar, fileName ) ) | 524 | if ( ! vfsave.save( calendar, fileName ) ) |
524 | return false; | 525 | return false; |
525 | // 4 call kammu | 526 | // 4 call kammu |
526 | QString command ="./kammu --restore " + fileName ; | 527 | QString command ="./kammu --restore " + fileName ; |
527 | int ret; | 528 | int ret; |
528 | while ( (ret = system ( command.latin1())) != 0 ) { | 529 | while ( (ret = system ( command.latin1())) != 0 ) { |
529 | qDebug("Error S::command returned %d. asking users", ret); | 530 | qDebug("Error S::command returned %d. asking users", ret); |
530 | int retval = KMessageBox::warningContinueCancel(0, | 531 | int retval = KMessageBox::warningContinueCancel(0, |
531 | i18n("Error accessing device!\nPlease turn on connection\nand retry!"),i18n("KO/Pi phone sync"),i18n("Retry"),i18n("Cancel")); | 532 | i18n("Error accessing device!\nPlease turn on connection\nand retry!"),i18n("KO/Pi phone sync"),i18n("Retry"),i18n("Cancel")); |
532 | if ( retval != KMessageBox::Continue ) | 533 | if ( retval != KMessageBox::Continue ) |
533 | return false; | 534 | return false; |
534 | } | 535 | } |
535 | if ( ret != 0 ) { | 536 | if ( ret != 0 ) { |
536 | qDebug("Error S::command returned %d", ret); | 537 | qDebug("Error S::command returned %d", ret); |
537 | return false; | 538 | return false; |
538 | } | 539 | } |
539 | // 5 reread data | 540 | // 5 reread data |
540 | message = i18n(" Rereading all data ... "); | 541 | message = i18n(" Rereading all data ... "); |
541 | status.setText ( message ); | 542 | status.setText ( message ); |
542 | qApp->processEvents(); | 543 | qApp->processEvents(); |
543 | CalendarLocal* calendarTemp = new CalendarLocal(); | 544 | CalendarLocal* calendarTemp = new CalendarLocal(); |
544 | calendarTemp->setTimeZoneId( calendar->timeZoneId()); | 545 | calendarTemp->setTimeZoneId( calendar->timeZoneId()); |
545 | if ( ! load( calendarTemp,calendar) ){ | 546 | if ( ! load( calendarTemp,calendar) ){ |
546 | qDebug("error reloading calendar "); | 547 | qDebug("error reloading calendar "); |
547 | delete calendarTemp; | 548 | delete calendarTemp; |
548 | return false; | 549 | return false; |
549 | } | 550 | } |
550 | // 6 compare data | 551 | // 6 compare data |
551 | 552 | ||
552 | //algo 6 compare event | 553 | //algo 6 compare event |
553 | er = calendar->rawEvents(); | 554 | er = calendar->rawEvents(); |
554 | ev = er.first(); | 555 | ev = er.first(); |
555 | message = i18n(" Comparing event # "); | 556 | message = i18n(" Comparing event # "); |
556 | QPtrList<Event> er1 = calendarTemp->rawEvents(); | 557 | QPtrList<Event> er1 = calendarTemp->rawEvents(); |
557 | Event* ev1; | 558 | Event* ev1; |
558 | int procCount = 0; | 559 | int procCount = 0; |
559 | while ( ev ) { | 560 | while ( ev ) { |
560 | //qDebug("event new ID %s",ev->summary().latin1()); | 561 | //qDebug("event new ID %s",ev->summary().latin1()); |
561 | status.setText ( message + QString::number ( ++procCount ) ); | 562 | status.setText ( message + QString::number ( ++procCount ) ); |
562 | qApp->processEvents(); | 563 | qApp->processEvents(); |
563 | uint csum; | 564 | uint csum; |
564 | csum = PhoneFormat::getCsumEvent( ev ); | 565 | csum = PhoneFormat::getCsumEvent( ev ); |
565 | QString cSum = QString::number( csum ); | 566 | QString cSum = QString::number( csum ); |
566 | ev->setCsum( mProfileName, cSum ); | 567 | //ev->setCsum( mProfileName, cSum ); |
567 | //qDebug("Event cSum %s ", cSum.latin1()); | 568 | //qDebug("Event cSum %s ", cSum.latin1()); |
568 | ev1 = er1.first(); | 569 | ev1 = er1.first(); |
569 | while ( ev1 ) { | 570 | while ( ev1 ) { |
570 | if ( ev1->getCsum( mProfileName ) == cSum ) { | 571 | if ( ev1->getCsum( mProfileName ) == cSum ) { |
571 | er1.remove( ev1 ); | 572 | er1.remove( ev1 ); |
572 | afterSave( ev ); | 573 | afterSave( ev ); |
573 | ev->setID(mProfileName, ev1->getID(mProfileName) ); | 574 | ev->setID(mProfileName, ev1->getID(mProfileName) ); |
574 | //qDebug("Event found on phone for %s ", ev->summary().latin1()); | 575 | //qDebug("Event found on phone for %s ", ev->summary().latin1()); |
575 | 576 | ||
576 | break; | 577 | break; |
577 | } | 578 | } |
578 | ev1 = er1.next(); | 579 | ev1 = er1.next(); |
579 | } | 580 | } |
580 | if ( ! ev1 ) { | 581 | if ( ! ev1 ) { |
581 | ev->removeID(mProfileName); | 582 | ev->removeID(mProfileName); |
582 | qDebug("ERROR: No event found on phone for %s ", ev->summary().latin1()); | 583 | qDebug("ERROR: No event found on phone for %s ", ev->summary().latin1()); |
583 | } | 584 | } |
584 | 585 | ||
585 | 586 | ||
586 | ev = er.next(); | 587 | ev = er.next(); |
587 | } | 588 | } |
588 | //algo 6 compare todo | 589 | //algo 6 compare todo |
589 | tl = calendar->rawTodos(); | 590 | tl = calendar->rawTodos(); |
590 | to = tl.first(); | 591 | to = tl.first(); |
591 | procCount = 0; | 592 | procCount = 0; |
592 | QPtrList<Todo> tl1 = calendarTemp->rawTodos(); | 593 | QPtrList<Todo> tl1 = calendarTemp->rawTodos(); |
593 | Todo* to1 ; | 594 | Todo* to1 ; |
594 | message = i18n(" Comparing todo # "); | 595 | message = i18n(" Comparing todo # "); |
595 | while ( to ) { | 596 | while ( to ) { |
596 | qDebug("todo2 %d ", procCount); | 597 | qDebug("todo2 %d ", procCount); |
597 | status.setText ( message + QString::number ( ++procCount ) ); | 598 | status.setText ( message + QString::number ( ++procCount ) ); |
598 | qApp->processEvents(); | 599 | qApp->processEvents(); |
599 | uint csum; | 600 | uint csum; |
600 | csum = PhoneFormat::getCsumTodo( to ); | 601 | csum = PhoneFormat::getCsumTodo( to ); |
601 | QString cSum = QString::number( csum ); | 602 | QString cSum = QString::number( csum ); |
602 | to->setCsum( mProfileName, cSum ); | 603 | //to->setCsum( mProfileName, cSum ); |
603 | qDebug("Todo cSum %s ", cSum.latin1()); | 604 | qDebug("Todo cSum %s ", cSum.latin1()); |
604 | Todo* to1 = tl1.first(); | 605 | Todo* to1 = tl1.first(); |
605 | while ( to1 ) { | 606 | while ( to1 ) { |
606 | if ( to1->getCsum( mProfileName ) == cSum ) { | 607 | if ( to1->getCsum( mProfileName ) == cSum ) { |
607 | tl1.remove( to1 ); | 608 | tl1.remove( to1 ); |
608 | afterSave( to ); | 609 | afterSave( to ); |
609 | to->setID(mProfileName, to1->getID(mProfileName) ); | 610 | to->setID(mProfileName, to1->getID(mProfileName) ); |
610 | break; | 611 | break; |
611 | } | 612 | } |
612 | to1 = tl1.next(); | 613 | to1 = tl1.next(); |
613 | } | 614 | } |
614 | if ( ! to1 ) { | 615 | if ( ! to1 ) { |
615 | to->removeID(mProfileName); | 616 | to->removeID(mProfileName); |
616 | qDebug("ERROR: No todo found on phone for %s ", to->summary().latin1()); | 617 | qDebug("ERROR: No todo found on phone for %s ", to->summary().latin1()); |
617 | } | 618 | } |
618 | 619 | ||
619 | to = tl.next(); | 620 | to = tl.next(); |
620 | } | 621 | } |
621 | delete calendarTemp; | 622 | delete calendarTemp; |
622 | return true; | 623 | return true; |
623 | 624 | ||
624 | 625 | ||
625 | 626 | ||
626 | } | 627 | } |
627 | 628 | ||
628 | 629 | ||
629 | QString PhoneFormat::toString( Calendar * ) | 630 | QString PhoneFormat::toString( Calendar * ) |
630 | { | 631 | { |
631 | return QString::null; | 632 | return QString::null; |
632 | } | 633 | } |
633 | bool PhoneFormat::fromString( Calendar *calendar, const QString & text) | 634 | bool PhoneFormat::fromString( Calendar *calendar, const QString & text) |
634 | { | 635 | { |
635 | return false; | 636 | return false; |
636 | } | 637 | } |