39
39
using namespace Kolab;
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
50
static int kcalPriorityToKolab( const int kcalPriority )
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];
59
kWarning() << "Got invalid priority" << kcalPriority;
64
static int kolabPrioritytoKCal( const int kolabPriority )
66
if ( kolabPriority >= 1 && kolabPriority <= 5 ) {
68
static const int priorityMap[5] = { 1, 3, 5, 7, 9 };
69
return priorityMap[kolabPriority - 1];
72
kWarning() << "Got invalid priority" << kolabPriority;
42
77
KCal::Todo* Task::xmlToTask( const QString& xml, const QString& tz )
158
193
if ( tagName == "priority" ) {
160
int priority = element.text().toInt( &ok );
161
if ( !ok || priority < 0 || priority > 5 )
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;
200
} else if ( tagName == "x-kcal-priority" ) {
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;
164
207
} else if ( tagName == "completed" ) {
166
209
int percent = element.text().toInt( &ok );
201
244
// Save the base class elements
202
245
Incidence::saveAttributes( element );
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() ) );
205
252
writeString( element, "completed", QString::number( percentCompleted() ) );
207
254
switch( status() ) {
246
293
bool Task::loadXML( const QDomDocument& document )
295
mKolabPriorityFromDom = -1;
296
mKCalPriorityFromDom = -1;
248
298
QDomElement top = document.documentElement();
250
300
if ( top.tagName() != "task" ) {
313
364
mHasCompletedDate = false;
367
void Task::decideAndSetPriority()
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 );
374
setPriority( mKCalPriorityFromDom );
377
// Out of sync, some other client changed the Kolab priority, so we have to ignore our
379
setPriority( kolabPrioritytoKCal( mKolabPriorityFromDom ) );
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 );
389
// Only Kolab priority set, use that
390
else if ( mKolabPriorityFromDom != -1 && mKCalPriorityFromDom == -1 ) {
391
setPriority( kolabPrioritytoKCal( mKolabPriorityFromDom ) );
394
// No priority set, use the default
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.
316
402
void Task::saveTo( KCal::Todo* task )
318
404
Incidence::saveTo( task );