~ubuntu-branches/ubuntu/lucid/kdepim-runtime/lucid-proposed

« back to all changes in this revision

Viewing changes to resources/kolabproxy/task.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Thomas
  • Date: 2010-01-06 18:57:08 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20100106185708-njxieh19nqhom3nd
Tags: 4:4.3.90-0ubuntu1
* New upstream beta release:
  - Bump build-depend versions

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
 
39
39
using namespace Kolab;
40
40
 
 
41
// Kolab Storage Specification:
 
42
//    "The priority can be a number between 1 and 5, with 1 being the highest priority."
 
43
// iCalendar (RFC 2445):
 
44
//    "The priority is specified as an integer in the range
 
45
//     zero to nine. A value of zero specifies an
 
46
//     undefined priority. A value of one is the
 
47
//     highest priority. A value of nine is the lowest
 
48
//     priority."
 
49
 
 
50
static int kcalPriorityToKolab( const int kcalPriority )
 
51
{
 
52
  if ( kcalPriority >= 0 && kcalPriority <= 9 ) {
 
53
    // We'll map undefined (0) to 3 (default)
 
54
    //                                   0  1  2  3  4  5  6  7  8  9
 
55
    static const int priorityMap[10] = { 3, 1, 1, 2, 2, 3, 3, 4, 4, 5 };
 
56
    return priorityMap[kcalPriority];
 
57
  }
 
58
  else {
 
59
    kWarning() << "Got invalid priority" << kcalPriority;
 
60
    return 3;
 
61
  }
 
62
}
 
63
 
 
64
static int kolabPrioritytoKCal( const int kolabPriority )
 
65
{
 
66
  if ( kolabPriority >= 1 && kolabPriority <= 5 ) {
 
67
    //                                  1  2  3  4  5
 
68
    static const int priorityMap[5] = { 1, 3, 5, 7, 9 };
 
69
    return priorityMap[kolabPriority - 1];
 
70
  }
 
71
  else {
 
72
    kWarning() << "Got invalid priority" << kolabPriority;
 
73
    return 5;
 
74
  }
 
75
}
41
76
 
42
77
KCal::Todo* Task::xmlToTask( const QString& xml, const QString& tz )
43
78
{
157
192
 
158
193
  if ( tagName == "priority" ) {
159
194
    bool ok;
160
 
    int priority = element.text().toInt( &ok );
161
 
    if ( !ok || priority < 0 || priority > 5 )
162
 
      priority = 3;
163
 
    setPriority( priority );
 
195
    mKolabPriorityFromDom = element.text().toInt( &ok );
 
196
    if ( !ok || mKolabPriorityFromDom < 1 || mKolabPriorityFromDom > 5 ) {
 
197
      kWarning() << "Invalid \"priority\" value:" << element.text();
 
198
      mKolabPriorityFromDom = -1;
 
199
    }
 
200
  } else if ( tagName == "x-kcal-priority" ) {
 
201
    bool ok;
 
202
    mKCalPriorityFromDom = element.text().toInt( &ok );
 
203
    if ( !ok || mKCalPriorityFromDom < 0 || mKCalPriorityFromDom > 9 ) {
 
204
      kWarning() << "Invalid \"x-kcal-priority\" value:" << element.text();
 
205
      mKCalPriorityFromDom = -1;
 
206
    }
164
207
  } else if ( tagName == "completed" ) {
165
208
    bool ok;
166
209
    int percent = element.text().toInt( &ok );
201
244
  // Save the base class elements
202
245
  Incidence::saveAttributes( element );
203
246
 
204
 
  writeString( element, "priority", QString::number( priority() ) );
 
247
  // We need to save x-kcal-priority as well, since the Kolab priority can only save values from
 
248
  // 1 to 5, but we have values from 0 to 9, and do not want to loose them
 
249
  writeString( element, "priority", QString::number( kcalPriorityToKolab( priority() ) ) );
 
250
  writeString( element, "x-kcal-priority", QString::number( priority() ) );
 
251
 
205
252
  writeString( element, "completed", QString::number( percentCompleted() ) );
206
253
 
207
254
  switch( status() ) {
245
292
 
246
293
bool Task::loadXML( const QDomDocument& document )
247
294
{
 
295
  mKolabPriorityFromDom = -1;
 
296
  mKCalPriorityFromDom = -1;
 
297
 
248
298
  QDomElement top = document.documentElement();
249
299
 
250
300
  if ( top.tagName() != "task" ) {
266
316
      kDebug() <<"Node is not a comment or an element???";
267
317
  }
268
318
 
 
319
  decideAndSetPriority();
269
320
  return true;
270
321
}
271
322
 
313
364
    mHasCompletedDate = false;
314
365
}
315
366
 
 
367
void Task::decideAndSetPriority()
 
368
{
 
369
  // If we have both Kolab and KCal values in the XML, we prefer the KCal value, but only if the
 
370
  // values are still in sync
 
371
  if  ( mKolabPriorityFromDom != -1 && mKCalPriorityFromDom != -1 ) {
 
372
    const bool inSync = ( kcalPriorityToKolab( mKCalPriorityFromDom ) == mKolabPriorityFromDom );
 
373
    if ( inSync ) {
 
374
      setPriority( mKCalPriorityFromDom );
 
375
    }
 
376
    else {
 
377
      // Out of sync, some other client changed the Kolab priority, so we have to ignore our
 
378
      // KCal priority
 
379
      setPriority( kolabPrioritytoKCal( mKolabPriorityFromDom ) );
 
380
    }
 
381
  }
 
382
 
 
383
  // Only KCal priority set, use that.
 
384
  else if ( mKolabPriorityFromDom == -1 && mKCalPriorityFromDom != -1 ) {
 
385
    kWarning() << "No Kolab priority found, only the KCal priority!";
 
386
    setPriority( mKCalPriorityFromDom );
 
387
  }
 
388
 
 
389
  // Only Kolab priority set, use that
 
390
  else if ( mKolabPriorityFromDom != -1 && mKCalPriorityFromDom == -1 ) {
 
391
    setPriority( kolabPrioritytoKCal( mKolabPriorityFromDom ) );
 
392
  }
 
393
 
 
394
  // No priority set, use the default
 
395
  else {
 
396
    // According the RFC 2445, we should use 0 here, for undefined priority, but AFAIK KOrganizer
 
397
    // doesn't support that, so we'll use 5.
 
398
    setPriority( 5 );
 
399
  }
 
400
}
 
401
 
316
402
void Task::saveTo( KCal::Todo* task )
317
403
{
318
404
  Incidence::saveTo( task );