author | zautrix <zautrix> | 2004-09-12 15:24:11 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-09-12 15:24:11 (UTC) |
commit | a222c2f7369eeefd19454c973c0cc48300f72bec (patch) (unidiff) | |
tree | 6f01a5922ea622add6960f3fad703e8e8f099caa /libkcal/phoneformat.cpp | |
parent | b2dede5d5735e2b4ab5afd51cf6a2c46d9be9b26 (diff) | |
download | kdepimpi-a222c2f7369eeefd19454c973c0cc48300f72bec.zip kdepimpi-a222c2f7369eeefd19454c973c0cc48300f72bec.tar.gz kdepimpi-a222c2f7369eeefd19454c973c0cc48300f72bec.tar.bz2 |
many phone sync fixes
-rw-r--r-- | libkcal/phoneformat.cpp | 42 |
1 files changed, 29 insertions, 13 deletions
diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp index 6df639f..ef69bce 100644 --- a/libkcal/phoneformat.cpp +++ b/libkcal/phoneformat.cpp | |||
@@ -84,97 +84,100 @@ public: | |||
84 | PhoneFormat::PhoneFormat(QString profileName, QString device,QString connection, QString model ) | 84 | PhoneFormat::PhoneFormat(QString profileName, QString device,QString connection, QString model ) |
85 | { | 85 | { |
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 | attList << QString::number( todo->priority() ); | 132 | int prio = todo->priority(); |
133 | if( prio == 2 ) prio = 1; | ||
134 | if (prio == 4 ) prio = 5 ; | ||
135 | attList << QString::number( prio ); | ||
133 | QString alarmString = "na"; | 136 | QString alarmString = "na"; |
134 | Alarm *alarm; | 137 | Alarm *alarm; |
135 | if ( todo->alarms().count() > 0 ) { | 138 | if ( todo->alarms().count() > 0 ) { |
136 | alarm = todo->alarms().first(); | 139 | alarm = todo->alarms().first(); |
137 | if ( alarm->enabled() ) { | 140 | if ( alarm->enabled() ) { |
138 | alarmString = QString::number(alarm->startOffset().asSeconds() ); | 141 | alarmString = QString::number(alarm->startOffset().asSeconds() ); |
139 | } | 142 | } |
140 | } | 143 | } |
141 | attList << alarmString; | 144 | attList << alarmString; |
142 | attList << todo->categoriesStr(); | 145 | attList << todo->categoriesStr(); |
143 | attList << todo->secrecyStr(); | 146 | attList << todo->secrecyStr(); |
144 | return PhoneFormat::getCsum(attList ); | 147 | return PhoneFormat::getCsum(attList ); |
145 | 148 | ||
146 | } | 149 | } |
147 | ulong PhoneFormat::getCsumEvent( Event* event ) | 150 | ulong PhoneFormat::getCsumEvent( Event* event ) |
148 | { | 151 | { |
149 | QStringList attList; | 152 | QStringList attList; |
150 | attList << PhoneParser::dtToString ( event->dtStart() ); | 153 | attList << PhoneParser::dtToString ( event->dtStart() ); |
151 | attList << PhoneParser::dtToString ( event->dtEnd() ); | 154 | attList << PhoneParser::dtToString ( event->dtEnd() ); |
152 | attList << event->summary(); | 155 | attList << event->summary(); |
153 | attList << event->location(); | 156 | attList << event->location(); |
154 | QString alarmString = "na"; | 157 | QString alarmString = "na"; |
155 | Alarm *alarm; | 158 | Alarm *alarm; |
156 | if ( event->alarms().count() > 0 ) { | 159 | if ( event->alarms().count() > 0 ) { |
157 | alarm = event->alarms().first(); | 160 | alarm = event->alarms().first(); |
158 | if ( alarm->enabled() ) { | 161 | if ( alarm->enabled() ) { |
159 | alarmString = QString::number( alarm->startOffset().asSeconds() ); | 162 | alarmString = QString::number( alarm->startOffset().asSeconds() ); |
160 | } | 163 | } |
161 | } | 164 | } |
162 | attList << alarmString; | 165 | attList << alarmString; |
163 | Recurrence* rec = event->recurrence(); | 166 | Recurrence* rec = event->recurrence(); |
164 | QStringList list; | 167 | QStringList list; |
165 | bool writeEndDate = false; | 168 | bool writeEndDate = false; |
166 | switch ( rec->doesRecur() ) | 169 | switch ( rec->doesRecur() ) |
167 | { | 170 | { |
168 | case Recurrence::rDaily: // 0 | 171 | case Recurrence::rDaily: // 0 |
169 | list.append( "0" ); | 172 | list.append( "0" ); |
170 | list.append( QString::number( rec->frequency() ));//12 | 173 | list.append( QString::number( rec->frequency() ));//12 |
171 | list.append( "0" ); | 174 | list.append( "0" ); |
172 | list.append( "0" ); | 175 | list.append( "0" ); |
173 | writeEndDate = true; | 176 | writeEndDate = true; |
174 | break; | 177 | break; |
175 | case Recurrence::rWeekly:// 1 | 178 | case Recurrence::rWeekly:// 1 |
176 | list.append( "1" ); | 179 | list.append( "1" ); |
177 | list.append( QString::number( rec->frequency()) );//12 | 180 | list.append( QString::number( rec->frequency()) );//12 |
178 | list.append( "0" ); | 181 | list.append( "0" ); |
179 | { | 182 | { |
180 | int days = 0; | 183 | int days = 0; |
@@ -209,350 +212,363 @@ ulong PhoneFormat::getCsumEvent( Event* event ) | |||
209 | } | 212 | } |
210 | 213 | ||
211 | list.append( "0" ); | 214 | list.append( "0" ); |
212 | break; | 215 | break; |
213 | case Recurrence::rMonthlyDay:// 3 | 216 | case Recurrence::rMonthlyDay:// 3 |
214 | list.append( "3" ); | 217 | list.append( "3" ); |
215 | list.append( QString::number( rec->frequency()) );//12 | 218 | list.append( QString::number( rec->frequency()) );//12 |
216 | list.append( "0" ); | 219 | list.append( "0" ); |
217 | list.append( "0" ); | 220 | list.append( "0" ); |
218 | writeEndDate = true; | 221 | writeEndDate = true; |
219 | break; | 222 | break; |
220 | case Recurrence::rYearlyMonth://4 | 223 | case Recurrence::rYearlyMonth://4 |
221 | list.append( "4" ); | 224 | list.append( "4" ); |
222 | list.append( QString::number( rec->frequency()) );//12 | 225 | list.append( QString::number( rec->frequency()) );//12 |
223 | list.append( "0" ); | 226 | list.append( "0" ); |
224 | list.append( "0" ); | 227 | list.append( "0" ); |
225 | writeEndDate = true; | 228 | writeEndDate = true; |
226 | break; | 229 | break; |
227 | 230 | ||
228 | default: | 231 | default: |
229 | list.append( "255" ); | 232 | list.append( "255" ); |
230 | list.append( QString() ); | 233 | list.append( QString() ); |
231 | list.append( "0" ); | 234 | list.append( "0" ); |
232 | list.append( QString() ); | 235 | list.append( QString() ); |
233 | list.append( "0" ); | 236 | list.append( "0" ); |
234 | list.append( "20991231T000000" ); | 237 | list.append( "20991231T000000" ); |
235 | break; | 238 | break; |
236 | } | 239 | } |
237 | if ( writeEndDate ) { | 240 | if ( writeEndDate ) { |
238 | 241 | ||
239 | if ( rec->endDate().isValid() ) { // 15 + 16 | 242 | if ( rec->endDate().isValid() ) { // 15 + 16 |
240 | list.append( "1" ); | 243 | list.append( "1" ); |
241 | list.append( PhoneParser::dtToString( rec->endDate()) ); | 244 | list.append( PhoneParser::dtToString( rec->endDate()) ); |
242 | } else { | 245 | } else { |
243 | list.append( "0" ); | 246 | list.append( "0" ); |
244 | list.append( "20991231T000000" ); | 247 | list.append( "20991231T000000" ); |
245 | } | 248 | } |
246 | 249 | ||
247 | } | 250 | } |
248 | attList << list.join(""); | 251 | attList << list.join(""); |
249 | attList << event->categoriesStr(); | 252 | attList << event->categoriesStr(); |
250 | //qDebug("csum cat %s", event->categoriesStr().latin1()); | 253 | //qDebug("csum cat %s", event->categoriesStr().latin1()); |
251 | 254 | ||
252 | attList << event->secrecyStr(); | 255 | attList << event->secrecyStr(); |
253 | return PhoneFormat::getCsum(attList ); | 256 | return PhoneFormat::getCsum(attList ); |
254 | } | 257 | } |
255 | ulong PhoneFormat::getCsum( const QStringList & attList) | 258 | ulong PhoneFormat::getCsum( const QStringList & attList) |
256 | { | 259 | { |
257 | int max = attList.count() -1; | 260 | int max = attList.count(); |
258 | ulong cSum = 0; | 261 | ulong cSum = 0; |
259 | int j,k,i; | 262 | int j,k,i; |
260 | int add; | 263 | int add; |
261 | for ( i = 1; i < max ; ++i ) { | 264 | for ( i = 0; i < max ; ++i ) { |
262 | QString s = attList[i]; | 265 | QString s = attList[i]; |
263 | if ( ! s.isEmpty() ){ | 266 | if ( ! s.isEmpty() ){ |
264 | j = s.length(); | 267 | j = s.length(); |
265 | for ( k = 0; k < j; ++k ) { | 268 | for ( k = 0; k < j; ++k ) { |
266 | int mul = k +1; | 269 | int mul = k +1; |
267 | add = s[k].unicode (); | 270 | add = s[k].unicode (); |
268 | if ( k < 16 ) | 271 | if ( k < 16 ) |
269 | mul = mul * mul; | 272 | mul = mul * mul; |
270 | add = add * mul *i*i*i; | 273 | int ii = i+1; |
274 | add = add * mul *ii*ii*ii; | ||
271 | cSum += add; | 275 | cSum += add; |
272 | } | 276 | } |
273 | } | 277 | } |
278 | if ( i == 0 ) | ||
279 | qDebug("csum: i == 0 %d ", cSum); | ||
280 | |||
274 | } | 281 | } |
275 | //QString dump = attList.join(","); | 282 | QString dump = attList.join(","); |
276 | //qDebug("csum: %s", dump.latin1()); | 283 | qDebug("csum: %d %s", cSum,dump.latin1()); |
277 | 284 | ||
278 | return cSum; | 285 | return cSum; |
279 | 286 | ||
280 | } | 287 | } |
281 | //extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum); | 288 | //extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum); |
282 | #include <stdlib.h> | 289 | #include <stdlib.h> |
283 | #define DEBUGMODE false | 290 | #define DEBUGMODE false |
284 | bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal) | 291 | bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal) |
285 | { | 292 | { |
286 | 293 | ||
287 | QString fileName; | 294 | QString fileName; |
288 | #ifdef _WIN32_ | 295 | #ifdef _WIN32_ |
289 | fileName = locateLocal("data", "korganizer") + "\\tempfile.vcs"; | 296 | fileName = locateLocal("data", "korganizer") + "\\tempfile.vcs"; |
290 | #else | 297 | #else |
291 | fileName = "/tmp/kdepimtemp.vcs"; | 298 | fileName = "/tmp/kdepimtemp.vcs"; |
292 | #endif | 299 | #endif |
293 | QString command ="./kammu --backup " + fileName + " -yes -C" + | 300 | QString command ="./kammu --backup " + fileName + " -yes" ; |
294 | mConnection +" -D" + mDevice +" -M" + mModel; | ||
295 | int ret = system ( command.latin1() ); | 301 | int ret = system ( command.latin1() ); |
296 | if ( ret != 0 ) { | 302 | if ( ret != 0 ) { |
297 | qDebug("Error::command returned %d", ret); | 303 | qDebug("Error::command returned %d", ret); |
298 | return false; | 304 | return false; |
299 | } | 305 | } |
300 | qDebug("Command returned %d", ret); | 306 | qDebug("Command returned %d", ret); |
301 | VCalFormat vfload; | 307 | VCalFormat vfload; |
302 | vfload.setLocalTime ( true ); | 308 | vfload.setLocalTime ( true ); |
303 | qDebug("loading file ..."); | 309 | qDebug("loading file ..."); |
304 | 310 | ||
305 | if ( ! vfload.load( calendar, fileName ) ) | 311 | if ( ! vfload.load( calendar, fileName ) ) |
306 | return false; | 312 | return false; |
307 | QPtrList<Event> er = calendar->rawEvents(); | 313 | QPtrList<Event> er = calendar->rawEvents(); |
308 | Event* ev = er.first(); | 314 | Event* ev = er.first(); |
309 | qDebug("reading events... "); | 315 | qDebug("reading events... "); |
310 | while ( ev ) { | 316 | while ( ev ) { |
311 | QStringList cat = ev->categories(); | 317 | QStringList cat = ev->categories(); |
312 | if ( cat.contains( "MeetingDEF" )) { | 318 | if ( cat.contains( "MeetingDEF" )) { |
313 | ev->setCategories( QStringList() ); | 319 | ev->setCategories( QStringList() ); |
314 | } | 320 | } |
315 | int id = ev->pilotId(); | 321 | int id = ev->pilotId(); |
316 | Event *event; | 322 | Event *event; |
317 | event = existingCal->event( mProfileName ,QString::number( id ) ); | 323 | event = existingCal->event( mProfileName ,QString::number( id ) ); |
318 | if ( event ) { | 324 | if ( event ) { |
319 | event = (Event*)event->clone(); | 325 | event = (Event*)event->clone(); |
320 | copyEvent( event, ev ); | 326 | copyEvent( event, ev ); |
321 | calendar->deleteEvent( ev ); | 327 | calendar->deleteEvent( ev ); |
322 | calendar->addEvent( event); | 328 | calendar->addEvent( event); |
323 | } | 329 | } |
324 | else | 330 | else |
325 | event = ev; | 331 | event = ev; |
326 | uint cSum; | 332 | uint cSum; |
327 | cSum = PhoneFormat::getCsumEvent( event ); | 333 | cSum = PhoneFormat::getCsumEvent( event ); |
328 | event->setCsum( mProfileName, QString::number( cSum )); | 334 | event->setCsum( mProfileName, QString::number( cSum )); |
329 | event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); | 335 | event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); |
330 | event->setID( mProfileName,QString::number( id ) ); | 336 | event->setID( mProfileName,QString::number( id ) ); |
331 | ev = er.next(); | 337 | ev = er.next(); |
332 | } | 338 | } |
333 | { | 339 | { |
334 | qDebug("reading todos... "); | 340 | qDebug("reading todos... "); |
335 | QPtrList<Todo> tr = calendar->rawTodos(); | 341 | QPtrList<Todo> tr = calendar->rawTodos(); |
336 | Todo* ev = tr.first(); | 342 | Todo* ev = tr.first(); |
337 | while ( ev ) { | 343 | while ( ev ) { |
338 | 344 | ||
339 | QStringList cat = ev->categories(); | 345 | QStringList cat = ev->categories(); |
340 | if ( cat.contains( "MeetingDEF" )) { | 346 | if ( cat.contains( "MeetingDEF" )) { |
341 | ev->setCategories( QStringList() ); | 347 | ev->setCategories( QStringList() ); |
342 | } | 348 | } |
343 | int id = ev->pilotId(); | 349 | int id = ev->pilotId(); |
344 | Todo *event; | 350 | Todo *event; |
345 | event = existingCal->todo( mProfileName ,QString::number( id ) ); | 351 | event = existingCal->todo( mProfileName ,QString::number( id ) ); |
346 | if ( event ) { | 352 | if ( event ) { |
353 | qDebug("copy todo %s ", event->summary().latin1()); | ||
354 | |||
347 | event = (Todo*)event->clone(); | 355 | event = (Todo*)event->clone(); |
348 | copyTodo( event, ev ); | 356 | copyTodo( event, ev ); |
349 | calendar->deleteTodo( ev ); | 357 | calendar->deleteTodo( ev ); |
350 | calendar->addTodo( event); | 358 | calendar->addTodo( event); |
351 | } | 359 | } |
352 | else | 360 | else |
353 | event = ev; | 361 | event = ev; |
354 | uint cSum; | 362 | uint cSum; |
355 | cSum = PhoneFormat::getCsumTodo( event ); | 363 | cSum = PhoneFormat::getCsumTodo( event ); |
356 | event->setCsum( mProfileName, QString::number( cSum )); | 364 | event->setCsum( mProfileName, QString::number( cSum )); |
357 | event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); | 365 | event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); |
358 | event->setID( mProfileName,QString::number( id ) ); | 366 | event->setID( mProfileName,QString::number( id ) ); |
359 | ev = tr.next(); | 367 | ev = tr.next(); |
360 | } | 368 | } |
361 | } | 369 | } |
362 | return true; | 370 | return true; |
363 | } | 371 | } |
364 | void PhoneFormat::copyEvent( Event* to, Event* from ) | 372 | void PhoneFormat::copyEvent( Event* to, Event* from ) |
365 | { | 373 | { |
366 | if ( from->dtStart().isValid() ) | 374 | if ( from->dtStart().isValid() ) |
367 | to->setDtStart( from->dtStart() ); | 375 | to->setDtStart( from->dtStart() ); |
368 | if ( from->dtEnd().isValid() ) | 376 | if ( from->dtEnd().isValid() ) |
369 | to->setDtEnd( from->dtEnd() ); | 377 | to->setDtEnd( from->dtEnd() ); |
370 | if ( !from->location().isEmpty() ) | 378 | if ( !from->location().isEmpty() ) |
371 | to->setLocation( from->location() ); | 379 | to->setLocation( from->location() ); |
372 | if ( !from->description().isEmpty() ) | 380 | if ( !from->description().isEmpty() ) |
373 | to->setDescription( from->description() ); | 381 | to->setDescription( from->description() ); |
374 | if ( !from->summary().isEmpty() ) | 382 | if ( !from->summary().isEmpty() ) |
375 | to->setSummary( from->summary() ); | 383 | to->setSummary( from->summary() ); |
376 | 384 | ||
377 | QPtrListIterator<Alarm> it( from->alarms() ); | 385 | QPtrListIterator<Alarm> it( from->alarms() ); |
378 | to->clearAlarms(); | 386 | if ( it.current() ) |
387 | to->clearAlarms(); | ||
379 | const Alarm *a; | 388 | const Alarm *a; |
380 | while( (a = it.current()) ) { | 389 | while( (a = it.current()) ) { |
381 | Alarm *b = new Alarm( *a ); | 390 | Alarm *b = new Alarm( *a ); |
382 | b->setParent( to ); | 391 | b->setParent( to ); |
383 | to->addAlarm( b ); | 392 | to->addAlarm( b ); |
384 | ++it; | 393 | ++it; |
385 | } | 394 | } |
386 | QStringList cat = to->categories(); | 395 | QStringList cat = to->categories(); |
387 | QStringList catFrom = from->categories(); | 396 | QStringList catFrom = from->categories(); |
388 | QString nCat; | 397 | QString nCat; |
389 | int iii; | 398 | int iii; |
390 | for ( iii = 0; iii < catFrom.count();++iii ) { | 399 | for ( iii = 0; iii < catFrom.count();++iii ) { |
391 | nCat = catFrom[iii]; | 400 | nCat = catFrom[iii]; |
392 | if ( !nCat.isEmpty() ) | 401 | if ( !nCat.isEmpty() ) |
393 | if ( !cat.contains( nCat )) { | 402 | if ( !cat.contains( nCat )) { |
394 | cat << nCat; | 403 | cat << nCat; |
395 | } | 404 | } |
396 | } | 405 | } |
397 | to->setCategories( cat ); | 406 | to->setCategories( cat ); |
398 | Recurrence * r = new Recurrence( *from->recurrence(),to); | 407 | Recurrence * r = new Recurrence( *from->recurrence(),to); |
399 | to->setRecurrence( r ) ; | 408 | to->setRecurrence( r ) ; |
400 | 409 | ||
401 | 410 | ||
402 | } | 411 | } |
403 | void PhoneFormat::copyTodo( Todo* to, Todo* from ) | 412 | void PhoneFormat::copyTodo( Todo* to, Todo* from ) |
404 | { | 413 | { |
405 | if ( from->dtStart().isValid() ) | 414 | if ( from->dtStart().isValid() ) |
406 | to->setDtStart( from->dtStart() ); | 415 | to->setDtStart( from->dtStart() ); |
407 | if ( from->dtDue().isValid() ) | 416 | if ( from->dtDue().isValid() ) |
408 | to->setDtDue( from->dtDue() ); | 417 | to->setDtDue( from->dtDue() ); |
409 | if ( !from->location().isEmpty() ) | 418 | if ( !from->location().isEmpty() ) |
410 | to->setLocation( from->location() ); | 419 | to->setLocation( from->location() ); |
411 | if ( !from->description().isEmpty() ) | 420 | if ( !from->description().isEmpty() ) |
412 | to->setDescription( from->description() ); | 421 | to->setDescription( from->description() ); |
413 | if ( !from->summary().isEmpty() ) | 422 | if ( !from->summary().isEmpty() ) |
414 | to->setSummary( from->summary() ); | 423 | to->setSummary( from->summary() ); |
415 | 424 | ||
416 | QPtrListIterator<Alarm> it( from->alarms() ); | 425 | QPtrListIterator<Alarm> it( from->alarms() ); |
417 | to->clearAlarms(); | 426 | if ( it.current() ) |
427 | to->clearAlarms(); | ||
418 | const Alarm *a; | 428 | const Alarm *a; |
419 | while( (a = it.current()) ) { | 429 | while( (a = it.current()) ) { |
420 | Alarm *b = new Alarm( *a ); | 430 | Alarm *b = new Alarm( *a ); |
421 | b->setParent( to ); | 431 | b->setParent( to ); |
422 | to->addAlarm( b ); | 432 | to->addAlarm( b ); |
423 | ++it; | 433 | ++it; |
424 | } | 434 | } |
425 | QStringList cat = to->categories(); | 435 | QStringList cat = to->categories(); |
426 | QStringList catFrom = from->categories(); | 436 | QStringList catFrom = from->categories(); |
427 | QString nCat; | 437 | QString nCat; |
428 | int iii; | 438 | int iii; |
429 | for ( iii = 0; iii < catFrom.count();++iii ) { | 439 | for ( iii = 0; iii < catFrom.count();++iii ) { |
430 | nCat = catFrom[iii]; | 440 | nCat = catFrom[iii]; |
431 | if ( !nCat.isEmpty() ) | 441 | if ( !nCat.isEmpty() ) |
432 | if ( !cat.contains( nCat )) { | 442 | if ( !cat.contains( nCat )) { |
433 | cat << nCat; | 443 | cat << nCat; |
434 | } | 444 | } |
435 | } | 445 | } |
436 | to->setCategories( cat ); | 446 | to->setCategories( cat ); |
437 | if ( from->isCompleted() ) { | 447 | if ( from->isCompleted() ) { |
438 | to->setCompleted( true ); | 448 | to->setCompleted( true ); |
439 | if( from->completed().isValid() ) | 449 | if( from->completed().isValid() ) |
440 | to->setCompleted( from->completed() ); | 450 | to->setCompleted( from->completed() ); |
441 | } else { | 451 | } else { |
442 | // set percentcomplete only, if to->isCompleted() | 452 | // set percentcomplete only, if to->isCompleted() |
443 | if ( to->isCompleted() ) | 453 | if ( to->isCompleted() ) |
444 | to->setPercentComplete(from->percentComplete()); | 454 | to->setPercentComplete(from->percentComplete()); |
445 | } | 455 | } |
446 | to->setPriority(from->priority()); | 456 | if( to->priority() == 2 && from->priority() == 1 ) |
457 | ; //skip | ||
458 | else if (to->priority() == 4 && from->priority() == 5 ) | ||
459 | ; | ||
460 | else | ||
461 | to->setPriority(from->priority()); | ||
447 | 462 | ||
448 | } | 463 | } |
449 | #include <qcstring.h> | 464 | #include <qcstring.h> |
450 | 465 | ||
451 | void PhoneFormat::afterSave( Incidence* inc) | 466 | void PhoneFormat::afterSave( Incidence* inc) |
452 | { | 467 | { |
453 | uint csum; | 468 | uint csum; |
454 | inc->removeID( mProfileName ); | 469 | inc->removeID( mProfileName ); |
470 | #if 0 | ||
455 | if ( inc->type() == "Event") | 471 | if ( inc->type() == "Event") |
456 | csum = PhoneFormat::getCsumEvent( (Event*) inc ); | 472 | csum = PhoneFormat::getCsumEvent( (Event*) inc ); |
457 | else | 473 | else |
458 | csum = PhoneFormat::getCsumTodo( (Todo*) inc ); | 474 | csum = PhoneFormat::getCsumTodo( (Todo*) inc ); |
459 | inc->setCsum( mProfileName, QString::number( csum )); | 475 | inc->setCsum( mProfileName, QString::number( csum )); |
476 | #endif | ||
460 | inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 477 | inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); |
461 | 478 | ||
462 | } | 479 | } |
463 | bool PhoneFormat::save( Calendar *calendar) | 480 | bool PhoneFormat::save( Calendar *calendar) |
464 | { | 481 | { |
465 | QLabel status ( i18n(" Opening device ..."), 0 ); | 482 | QLabel status ( i18n(" Opening device ..."), 0 ); |
466 | int w = status.sizeHint().width()+20 ; | 483 | int w = status.sizeHint().width()+20 ; |
467 | if ( w < 200 ) w = 230; | 484 | if ( w < 200 ) w = 230; |
468 | int h = status.sizeHint().height()+20 ; | 485 | int h = status.sizeHint().height()+20 ; |
469 | int dw = QApplication::desktop()->width(); | 486 | int dw = QApplication::desktop()->width(); |
470 | int dh = QApplication::desktop()->height(); | 487 | int dh = QApplication::desktop()->height(); |
471 | status.setCaption(i18n("Writing to phone...") ); | 488 | status.setCaption(i18n("Writing to phone...") ); |
472 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 489 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
473 | status.show(); | 490 | status.show(); |
474 | status.raise(); | 491 | status.raise(); |
475 | qApp->processEvents(); | 492 | qApp->processEvents(); |
476 | QString message; | 493 | QString message; |
477 | #ifdef _WIN32_ | 494 | #ifdef _WIN32_ |
478 | QString fileName = locateLocal("data", "korganizer") + "\\tempfile.vcs"; | 495 | QString fileName = locateLocal("data", "korganizer") + "\\tempfile.vcs"; |
479 | #else | 496 | #else |
480 | QString fileName = "/tmp/kdepimtemp.vcs"; | 497 | QString fileName = "/tmp/kdepimtemp.vcs"; |
481 | #endif | 498 | #endif |
482 | 499 | ||
483 | // 1 remove events which should be deleted | 500 | // 1 remove events which should be deleted |
484 | QPtrList<Event> er = calendar->rawEvents(); | 501 | QPtrList<Event> er = calendar->rawEvents(); |
485 | Event* ev = er.first(); | 502 | Event* ev = er.first(); |
486 | while ( ev ) { | 503 | while ( ev ) { |
487 | if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { | 504 | if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { |
488 | calendar->deleteEvent( ev ); | 505 | calendar->deleteEvent( ev ); |
489 | } else { | 506 | } else { |
490 | 507 | ||
491 | } | 508 | } |
492 | ev = er.next(); | 509 | ev = er.next(); |
493 | } | 510 | } |
494 | // 2 remove todos which should be deleted | 511 | // 2 remove todos which should be deleted |
495 | QPtrList<Todo> tl = calendar->rawTodos(); | 512 | QPtrList<Todo> tl = calendar->rawTodos(); |
496 | Todo* to = tl.first(); | 513 | Todo* to = tl.first(); |
497 | while ( to ) { | 514 | while ( to ) { |
498 | if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { | 515 | if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { |
499 | calendar->deleteTodo( to ); | 516 | calendar->deleteTodo( to ); |
500 | } | 517 | } |
501 | to = tl.next(); | 518 | to = tl.next(); |
502 | } | 519 | } |
503 | // 3 save file | 520 | // 3 save file |
504 | VCalFormat vfsave; | 521 | VCalFormat vfsave; |
505 | vfsave.setLocalTime ( true ); | 522 | vfsave.setLocalTime ( true ); |
506 | if ( ! vfsave.save( calendar, fileName ) ) | 523 | if ( ! vfsave.save( calendar, fileName ) ) |
507 | return false; | 524 | return false; |
508 | // 4 call kammu | 525 | // 4 call kammu |
509 | QString command ="./kammu --restore " + fileName + " -C" + | 526 | QString command ="./kammu --restore " + fileName ; |
510 | mConnection +" -D" + mDevice +" -M" + mModel; | ||
511 | int ret; | 527 | int ret; |
512 | while ( (ret = system ( command.latin1())) != 0 ) { | 528 | while ( (ret = system ( command.latin1())) != 0 ) { |
513 | qDebug("Error S::command returned %d. asking users", ret); | 529 | qDebug("Error S::command returned %d. asking users", ret); |
514 | int retval = KMessageBox::warningContinueCancel(0, | 530 | int retval = KMessageBox::warningContinueCancel(0, |
515 | i18n("Error accessing device!\nPlease turn on connection\nand retry!"),i18n("KO/Pi phone sync"),i18n("Retry"),i18n("Cancel")); | 531 | i18n("Error accessing device!\nPlease turn on connection\nand retry!"),i18n("KO/Pi phone sync"),i18n("Retry"),i18n("Cancel")); |
516 | if ( retval != KMessageBox::Continue ) | 532 | if ( retval != KMessageBox::Continue ) |
517 | return false; | 533 | return false; |
518 | } | 534 | } |
519 | if ( ret != 0 ) { | 535 | if ( ret != 0 ) { |
520 | qDebug("Error S::command returned %d", ret); | 536 | qDebug("Error S::command returned %d", ret); |
521 | return false; | 537 | return false; |
522 | } | 538 | } |
523 | // 5 reread data | 539 | // 5 reread data |
524 | message = i18n(" Rereading all data ... "); | 540 | message = i18n(" Rereading all data ... "); |
525 | status.setText ( message ); | 541 | status.setText ( message ); |
526 | qApp->processEvents(); | 542 | qApp->processEvents(); |
527 | CalendarLocal* calendarTemp = new CalendarLocal(); | 543 | CalendarLocal* calendarTemp = new CalendarLocal(); |
528 | calendarTemp->setTimeZoneId( calendar->timeZoneId()); | 544 | calendarTemp->setTimeZoneId( calendar->timeZoneId()); |
529 | if ( ! load( calendarTemp,calendar) ){ | 545 | if ( ! load( calendarTemp,calendar) ){ |
530 | qDebug("error reloading calendar "); | 546 | qDebug("error reloading calendar "); |
531 | delete calendarTemp; | 547 | delete calendarTemp; |
532 | return false; | 548 | return false; |
533 | } | 549 | } |
534 | // 6 compare data | 550 | // 6 compare data |
535 | 551 | ||
536 | //algo 6 compare event | 552 | //algo 6 compare event |
537 | er = calendar->rawEvents(); | 553 | er = calendar->rawEvents(); |
538 | ev = er.first(); | 554 | ev = er.first(); |
539 | message = i18n(" Comparing event # "); | 555 | message = i18n(" Comparing event # "); |
540 | QPtrList<Event> er1 = calendarTemp->rawEvents(); | 556 | QPtrList<Event> er1 = calendarTemp->rawEvents(); |
541 | Event* ev1; | 557 | Event* ev1; |
542 | int procCount = 0; | 558 | int procCount = 0; |
543 | while ( ev ) { | 559 | while ( ev ) { |
544 | //qDebug("event new ID %s",ev->summary().latin1()); | 560 | //qDebug("event new ID %s",ev->summary().latin1()); |
545 | status.setText ( message + QString::number ( ++procCount ) ); | 561 | status.setText ( message + QString::number ( ++procCount ) ); |
546 | qApp->processEvents(); | 562 | qApp->processEvents(); |
547 | uint csum; | 563 | uint csum; |
548 | csum = PhoneFormat::getCsumEvent( ev ); | 564 | csum = PhoneFormat::getCsumEvent( ev ); |
549 | QString cSum = QString::number( csum ); | 565 | QString cSum = QString::number( csum ); |
550 | ev->setCsum( mProfileName, cSum ); | 566 | ev->setCsum( mProfileName, cSum ); |
551 | //qDebug("Event cSum %s ", cSum.latin1()); | 567 | //qDebug("Event cSum %s ", cSum.latin1()); |
552 | ev1 = er1.first(); | 568 | ev1 = er1.first(); |
553 | while ( ev1 ) { | 569 | while ( ev1 ) { |
554 | if ( ev1->getCsum( mProfileName ) == cSum ) { | 570 | if ( ev1->getCsum( mProfileName ) == cSum ) { |
555 | er1.remove( ev1 ); | 571 | er1.remove( ev1 ); |
556 | afterSave( ev ); | 572 | afterSave( ev ); |
557 | ev->setID(mProfileName, ev1->getID(mProfileName) ); | 573 | ev->setID(mProfileName, ev1->getID(mProfileName) ); |
558 | //qDebug("Event found on phone for %s ", ev->summary().latin1()); | 574 | //qDebug("Event found on phone for %s ", ev->summary().latin1()); |