summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Mollekopf <mollekopf@kolabsys.com>2013-09-23 14:07:38 (GMT)
committerChristian Mollekopf <mollekopf@kolabsys.com>2013-09-23 14:07:38 (GMT)
commit518d3d901352f8000846ac262870a8c3097ac27a (patch)
treec84d4ad3a3c36694d468c8ff24146224956106dd
parent6f5997417a8c2eed2886a8cc8869374ac4c70c46 (diff)
downloadlibkolab-518d3d901352f8000846ac262870a8c3097ac27a.tar.gz
Implemented KEP:8 in kolabv2 format (priorities).
-rw-r--r--kolabformatV2/incidence.cpp41
-rw-r--r--kolabformatV2/incidence.h6
-rw-r--r--kolabformatV2/task.cpp110
-rw-r--r--kolabformatV2/task.h16
-rw-r--r--tests/testfiles/v2/task/complex.ics.mime3
-rw-r--r--tests/testfiles/v2/task/prioritytest1.ics.mime3
-rw-r--r--tests/testfiles/v2/task/prioritytest2.ics.mime3
-rw-r--r--tests/testfiles/v2/task/simple.ics.mime3
8 files changed, 49 insertions, 136 deletions
diff --git a/kolabformatV2/incidence.cpp b/kolabformatV2/incidence.cpp
index f627334..9f0e381 100644
--- a/kolabformatV2/incidence.cpp
+++ b/kolabformatV2/incidence.cpp
@@ -44,9 +44,8 @@
using namespace KolabV2;
-
Incidence::Incidence( const QString& tz, const KCalCore::Incidence::Ptr &incidence )
- : KolabBase( tz ), mFloatingStatus( Unset ), mHasAlarm( false )
+ : KolabBase( tz ), mFloatingStatus( Unset ), mHasAlarm( false ), mPriority( 0 )
{
Q_UNUSED( incidence );
}
@@ -55,6 +54,16 @@ Incidence::~Incidence()
{
}
+void Incidence::setPriority( int priority )
+{
+ mPriority = priority;
+}
+
+int Incidence::priority() const
+{
+ return mPriority;
+}
+
void Incidence::setSummary( const QString& summary )
{
mSummary = summary;
@@ -472,7 +481,25 @@ bool Incidence::loadAttribute( QDomElement& element )
{
QString tagName = element.tagName();
- if ( tagName == "summary" )
+ if ( tagName == "priority" ) {
+ bool ok;
+ int p = element.text().toInt( &ok );
+ if ( !ok || p < 1 || p > 9 ) {
+ kWarning() << "Invalid \"priority\" value:" << element.text();
+ } else {
+ setPriority( p );
+ }
+ } else if ( tagName == "x-kcal-priority" ) { //for backwards compat
+ bool ok;
+ int p = element.text().toInt( &ok );
+ if ( !ok || p < 0 || p > 9 ) {
+ kWarning() << "Invalid \"x-kcal-priority\" value:" << element.text();
+ } else {
+ if ( priority() == 0 ) {
+ setPriority(p);
+ }
+ }
+ } else if ( tagName == "summary" )
setSummary( element.text() );
else if ( tagName == "location" )
setLocation( element.text() );
@@ -527,6 +554,10 @@ bool Incidence::saveAttributes( QDomElement& element ) const
// Save the base class elements
KolabBase::saveAttributes( element );
+ if (priority() != 0) {
+ writeString( element, "priority", QString::number( priority() ) );
+ }
+
if ( mFloatingStatus == HasTime )
writeString( element, "start-date", dateTimeToString( startDate() ) );
else
@@ -747,6 +778,7 @@ void Incidence::setFields( const KCalCore::Incidence::Ptr &incidence )
{
KolabBase::setFields( incidence );
+ setPriority( incidence->priority() );
if ( incidence->allDay() ) {
// This is a all-day event. Don't timezone move this one
mFloatingStatus = AllDay;
@@ -857,6 +889,7 @@ void Incidence::saveTo( const KCalCore::Incidence::Ptr &incidence )
{
KolabBase::saveTo( incidence );
+ incidence->setPriority( priority() );
if ( mFloatingStatus == AllDay ) {
// This is an all-day event. Don't timezone move this one
incidence->setDtStart( startDate() );
@@ -972,6 +1005,6 @@ QString Incidence::productID() const
}
// Unhandled KCalCore::Incidence fields:
-// revision, status (unused), priority (done in tasks), attendee.uid,
+// revision, status (unused), attendee.uid,
// mComments, mReadOnly
diff --git a/kolabformatV2/incidence.h b/kolabformatV2/incidence.h
index ad1fa72..b918bd0 100644
--- a/kolabformatV2/incidence.h
+++ b/kolabformatV2/incidence.h
@@ -78,6 +78,9 @@ public:
void saveTo( const KCalCore::Incidence::Ptr &incidence );
+ virtual void setPriority( int priority );
+ virtual int priority() const;
+
virtual void setSummary( const QString& summary );
virtual QString summary() const;
@@ -159,6 +162,9 @@ protected:
};
QList<Custom> mCustomList;
+ // This is the KCal priority, not the Kolab priority.
+ // See kcalPriorityToKolab() and kolabPrioritytoKCal().
+ int mPriority;
};
}
diff --git a/kolabformatV2/task.cpp b/kolabformatV2/task.cpp
index fef0d30..0e6772f 100644
--- a/kolabformatV2/task.cpp
+++ b/kolabformatV2/task.cpp
@@ -38,42 +38,6 @@
using namespace KolabV2;
-// Kolab Storage Specification:
-// "The priority can be a number between 1 and 5, with 1 being the highest priority."
-// iCalendar (RFC 2445):
-// "The priority is specified as an integer in the range
-// zero to nine. A value of zero specifies an
-// undefined priority. A value of one is the
-// highest priority. A value of nine is the lowest
-// priority."
-
-static int kcalPriorityToKolab( const int kcalPriority )
-{
- if ( kcalPriority >= 0 && kcalPriority <= 9 ) {
- // We'll map undefined (0) to 3 (default)
- // 0 1 2 3 4 5 6 7 8 9
- static const int priorityMap[10] = { 3, 1, 1, 2, 2, 3, 3, 4, 4, 5 };
- return priorityMap[kcalPriority];
- }
- else {
- kWarning() << "Got invalid priority" << kcalPriority;
- return 3;
- }
-}
-
-static int kolabPrioritytoKCal( const int kolabPriority )
-{
- if ( kolabPriority >= 1 && kolabPriority <= 5 ) {
- // 1 2 3 4 5
- static const int priorityMap[5] = { 1, 3, 5, 7, 9 };
- return priorityMap[kolabPriority - 1];
- }
- else {
- kWarning() << "Got invalid priority" << kolabPriority;
- return 5;
- }
-}
-
KCalCore::Todo::Ptr Task::fromXml( const QDomDocument& xmlDoc, const QString& tz )
{
Task task( tz );
@@ -91,7 +55,7 @@ QString Task::taskToXML( const KCalCore::Todo::Ptr &todo, const QString& tz )
Task::Task( const QString& tz, const KCalCore::Todo::Ptr &task )
: Incidence( tz, task ),
- mPriority( 5 ), mPercentCompleted( 0 ),
+ mPercentCompleted( 0 ),
mStatus( KCalCore::Incidence::StatusNone ),
mHasStartDate( false ), mHasDueDate( false ),
mHasCompletedDate( false )
@@ -105,16 +69,6 @@ Task::~Task()
{
}
-void Task::setPriority( int priority )
-{
- mPriority = priority;
-}
-
-int Task::priority() const
-{
- return mPriority;
-}
-
void Task::setPercentCompleted( int percent )
{
mPercentCompleted = percent;
@@ -209,21 +163,7 @@ bool Task::loadAttribute( QDomElement& element )
{
QString tagName = element.tagName();
- if ( tagName == "priority" ) {
- bool ok;
- mKolabPriorityFromDom = element.text().toInt( &ok );
- if ( !ok || mKolabPriorityFromDom < 1 || mKolabPriorityFromDom > 5 ) {
- kWarning() << "Invalid \"priority\" value:" << element.text();
- mKolabPriorityFromDom = -1;
- }
- } else if ( tagName == "x-kcal-priority" ) {
- bool ok;
- mKCalPriorityFromDom = element.text().toInt( &ok );
- if ( !ok || mKCalPriorityFromDom < 0 || mKCalPriorityFromDom > 9 ) {
- kWarning() << "Invalid \"x-kcal-priority\" value:" << element.text();
- mKCalPriorityFromDom = -1;
- }
- } else if ( tagName == "completed" ) {
+ if ( tagName == "completed" ) {
bool ok;
int percent = element.text().toInt( &ok );
if ( !ok || percent < 0 || percent > 100 )
@@ -263,11 +203,6 @@ bool Task::saveAttributes( QDomElement& element ) const
// Save the base class elements
Incidence::saveAttributes( element );
- // We need to save x-kcal-priority as well, since the Kolab priority can only save values from
- // 1 to 5, but we have values from 0 to 9, and do not want to loose them
- writeString( element, "priority", QString::number( kcalPriorityToKolab( priority() ) ) );
- writeString( element, "x-kcal-priority", QString::number( priority() ) );
-
writeString( element, "completed", QString::number( percentCompleted() ) );
switch( status() ) {
@@ -318,9 +253,6 @@ bool Task::saveAttributes( QDomElement& element ) const
bool Task::loadXML( const QDomDocument& document )
{
- mKolabPriorityFromDom = -1;
- mKCalPriorityFromDom = -1;
-
QDomElement top = document.documentElement();
if ( top.tagName() != "task" ) {
@@ -342,7 +274,6 @@ bool Task::loadXML( const QDomDocument& document )
kDebug() <<"Node is not a comment or an element???";
}
- decideAndSetPriority();
return true;
}
@@ -368,7 +299,6 @@ void Task::setFields( const KCalCore::Todo::Ptr &task )
{
Incidence::setFields( task );
- setPriority( task->priority() );
setPercentCompleted( task->percentComplete() );
setStatus( task->status() );
setHasStartDate( task->hasStartDate() );
@@ -399,46 +329,10 @@ void Task::setFields( const KCalCore::Todo::Ptr &task )
}
}
-void Task::decideAndSetPriority()
-{
- // If we have both Kolab and KCal values in the XML, we prefer the KCal value, but only if the
- // values are still in sync
- if ( mKolabPriorityFromDom != -1 && mKCalPriorityFromDom != -1 ) {
- const bool inSync = ( kcalPriorityToKolab( mKCalPriorityFromDom ) == mKolabPriorityFromDom );
- if ( inSync ) {
- setPriority( mKCalPriorityFromDom );
- }
- else {
- // Out of sync, some other client changed the Kolab priority, so we have to ignore our
- // KCal priority
- setPriority( kolabPrioritytoKCal( mKolabPriorityFromDom ) );
- }
- }
-
- // Only KCal priority set, use that.
- else if ( mKolabPriorityFromDom == -1 && mKCalPriorityFromDom != -1 ) {
- kWarning() << "No Kolab priority found, only the KCal priority!";
- setPriority( mKCalPriorityFromDom );
- }
-
- // Only Kolab priority set, use that
- else if ( mKolabPriorityFromDom != -1 && mKCalPriorityFromDom == -1 ) {
- setPriority( kolabPrioritytoKCal( mKolabPriorityFromDom ) );
- }
-
- // No priority set, use the default
- else {
- // According the RFC 2445, we should use 0 here, for undefined priority, but AFAIK KOrganizer
- // doesn't support that, so we'll use 5.
- setPriority( 5 );
- }
-}
-
void Task::saveTo( const KCalCore::Todo::Ptr &task )
{
Incidence::saveTo( task );
- task->setPriority( priority() );
task->setPercentComplete( percentCompleted() );
task->setStatus( status() );
task->setHasStartDate( hasStartDate() );
diff --git a/kolabformatV2/task.h b/kolabformatV2/task.h
index 487b98a..da45caf 100644
--- a/kolabformatV2/task.h
+++ b/kolabformatV2/task.h
@@ -71,9 +71,6 @@ public:
void saveTo( const KCalCore::Todo::Ptr &todo );
- virtual void setPriority( int priority );
- virtual int priority() const;
-
virtual void setPercentCompleted( int percent );
virtual int percentCompleted() const;
@@ -112,19 +109,6 @@ protected:
// Read all known fields from this ical todo
void setFields( const KCalCore::Todo::Ptr & );
- // This sets the priority of this task by looking at mKolabPriorityFromDom and
- // mKCalPriorityFromDom.
- void decideAndSetPriority();
-
- // This is the KCal priority, not the Kolab priority.
- // See kcalPriorityToKolab() and kolabPrioritytoKCal().
- int mPriority;
-
- // Those priority values are the raw values read by loadAttribute().
- // They will be converted later in decideAndSetPriority().
- int mKolabPriorityFromDom;
- int mKCalPriorityFromDom;
-
int mPercentCompleted;
KCalCore::Incidence::Status mStatus;
QString mParent;
diff --git a/tests/testfiles/v2/task/complex.ics.mime b/tests/testfiles/v2/task/complex.ics.mime
index 87c1cd9..5c3dc20 100644
--- a/tests/testfiles/v2/task/complex.ics.mime
+++ b/tests/testfiles/v2/task/complex.ics.mime
@@ -29,6 +29,7 @@ Content-Disposition: attachment; filename="kolab.xml"
<creation-date>2009-09-01T13:39:15Z</creation-date>
<last-modification-date>2009-09-01T13:39:15+00:00</last-modification-date>
<sensitivity>private</sensitivity>
+ <priority>1</priority>
<start-date>2009-09-01T14:00:00Z</start-date>
<summary>Complex Task</summary>
<location>Here</location>
@@ -64,8 +65,6 @@ Content-Disposition: attachment; filename="kolab.xml"
<end-offset>-15</end-offset>
</alarm>
</advanced-alarms>
- <priority>1</priority>
- <x-kcal-priority>1</x-kcal-priority>
<completed>50</completed>
<status>not-started</status>
<due-date>2009-09-08T14:00:00Z</due-date>
diff --git a/tests/testfiles/v2/task/prioritytest1.ics.mime b/tests/testfiles/v2/task/prioritytest1.ics.mime
index 3de9bd2..5a48d7a 100644
--- a/tests/testfiles/v2/task/prioritytest1.ics.mime
+++ b/tests/testfiles/v2/task/prioritytest1.ics.mime
@@ -27,10 +27,9 @@ Content-Disposition: attachment; filename="kolab.xml"
<creation-date>2009-09-01T13:17:03Z</creation-date>
<last-modification-date>2009-09-01T13:17:03+00:00</last-modification-date>
<sensitivity>public</sensitivity>
+ <priority>8</priority>
<summary>Simple Task</summary>
<organizer/>
- <priority>4</priority>
- <x-kcal-priority>8</x-kcal-priority>
<completed>0</completed>
<status>not-started</status>
</task>
diff --git a/tests/testfiles/v2/task/prioritytest2.ics.mime b/tests/testfiles/v2/task/prioritytest2.ics.mime
index ad15dbb..ca22058 100644
--- a/tests/testfiles/v2/task/prioritytest2.ics.mime
+++ b/tests/testfiles/v2/task/prioritytest2.ics.mime
@@ -27,10 +27,9 @@ Content-Disposition: attachment; filename="kolab.xml"
<creation-date>2009-09-01T13:17:03Z</creation-date>
<last-modification-date>2009-09-01T13:17:03+00:00</last-modification-date>
<sensitivity>public</sensitivity>
+ <priority>1</priority>
<summary>Simple Task</summary>
<organizer/>
- <priority>1</priority>
- <x-kcal-priority>1</x-kcal-priority>
<completed>0</completed>
<status>not-started</status>
</task>
diff --git a/tests/testfiles/v2/task/simple.ics.mime b/tests/testfiles/v2/task/simple.ics.mime
index f1322ef..8855a4b 100644
--- a/tests/testfiles/v2/task/simple.ics.mime
+++ b/tests/testfiles/v2/task/simple.ics.mime
@@ -27,10 +27,9 @@ Content-Disposition: attachment; filename="kolab.xml"
<creation-date>2009-09-01T13:17:03Z</creation-date>
<last-modification-date>2009-09-01T13:17:03+00:00</last-modification-date>
<sensitivity>public</sensitivity>
+ <priority>7</priority>
<summary>Simple Task</summary>
<organizer/>
- <priority>4</priority>
- <x-kcal-priority>7</x-kcal-priority>
<completed>0</completed>
<status>not-started</status>
</task>