3 commits - kolabformatV2/incidence.cpp kolabformatV2/incidence.h kolabformatV2/task.cpp kolabformatV2/task.h tests/testfiles utils/kolabformatchecker.cpp
Christian Mollekopf
mollekopf at kolabsys.com
Mon Sep 23 16:10:15 CEST 2013
kolabformatV2/incidence.cpp | 41 ++++++++-
kolabformatV2/incidence.h | 6 +
kolabformatV2/task.cpp | 110 -------------------------
kolabformatV2/task.h | 16 ---
tests/testfiles/v2/task/complex.ics.mime | 3
tests/testfiles/v2/task/prioritytest1.ics.mime | 3
tests/testfiles/v2/task/prioritytest2.ics.mime | 3
tests/testfiles/v2/task/simple.ics.mime | 3
utils/kolabformatchecker.cpp | 49 +++++------
9 files changed, 74 insertions(+), 160 deletions(-)
New commits:
commit 518d3d901352f8000846ac262870a8c3097ac27a
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date: Mon Sep 23 16:07:38 2013 +0200
Implemented KEP:8 in kolabv2 format (priorities).
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>
commit 6f5997417a8c2eed2886a8cc8869374ac4c70c46
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date: Mon Sep 23 15:06:03 2013 +0200
codingstyle
diff --git a/utils/kolabformatchecker.cpp b/utils/kolabformatchecker.cpp
index b738a1b..10dc6c2 100644
--- a/utils/kolabformatchecker.cpp
+++ b/utils/kolabformatchecker.cpp
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2012 Sofia Balicka <balicka at kolabsys.com>
+ * Copyright (C) 2013 Christian Mollekopf <mollekopf at kolabsys.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
@@ -19,11 +20,11 @@
#include <iostream>
#include <string>
#include <vector>
+#include <QString>
+#include <QFile>
#include <kolabformat.h>
#include "kolabformat/errorhandler.h"
#include "kolabformat/kolabobject.h"
-#include "qstring.h"
-#include <QFile>
namespace po = boost::program_options;
using namespace std;
@@ -50,7 +51,7 @@ int main(int argc, char *argv[])
desc.add_options()
("help", "produce help message")
("input-file", po::value<std::vector<std::string> >(), "input files")
- ;
+ ;
po::positional_options_description p;
p.add("input-file", -1);
@@ -72,35 +73,35 @@ int main(int argc, char *argv[])
cout << "Specify input-file\n";
return -1;
}
-
- int returnValue = 0;
- cout << endl;
+ int returnValue = 0;
+
+ cout << endl;
- for(vector<string>::const_iterator it = inputFiles.begin();
+ for(vector<string>::const_iterator it = inputFiles.begin();
it != inputFiles.end(); it++){
- cout << "File: " << *it << endl;
+ cout << "File: " << *it << endl;
- bool ok;
- KMime::Message::Ptr message = readMimeFile( QString::fromStdString(*it), ok);
+ bool ok;
+ KMime::Message::Ptr message = readMimeFile( QString::fromStdString(*it), ok);
- if(!ok){
- returnValue = -1;
- cout << endl;
- continue;
- }
+ if(!ok){
+ returnValue = -1;
+ cout << endl;
+ continue;
+ }
- Kolab::KolabObjectReader reader(message);
+ Kolab::KolabObjectReader reader(message);
- if (Kolab::ErrorHandler::errorOccured()){
- cout << "Errors occured during parsing." << endl;
- returnValue = -1;
- } else {
- cout << "Parsed message without error." << endl;
- }
+ if (Kolab::ErrorHandler::errorOccured()){
+ cout << "Errors occured during parsing." << endl;
+ returnValue = -1;
+ } else {
+ cout << "Parsed message without error." << endl;
+ }
- cout << endl;
+ cout << endl;
}
return returnValue;
commit 55db6fd4c1e49def5563dddd8ad8ae9eb8ac7264
Author: Christian Mollekopf <mollekopf at kolabsys.com>
Date: Mon Sep 23 15:01:35 2013 +0200
We have to convert CRLF to LF, otherwise some files will not load.
This is typically encountered when downloading example files from somewhere.
diff --git a/utils/kolabformatchecker.cpp b/utils/kolabformatchecker.cpp
index 47120f3..b738a1b 100644
--- a/utils/kolabformatchecker.cpp
+++ b/utils/kolabformatchecker.cpp
@@ -38,7 +38,7 @@ KMime::Message::Ptr readMimeFile( const QString &fileName, bool &ok)
}
const QByteArray data = file.readAll();
KMime::Message::Ptr msg = KMime::Message::Ptr(new KMime::Message);
- msg->setContent( data );
+ msg->setContent( KMime::CRLFtoLF(data) );
msg->parse();
return msg;
}
More information about the commits
mailing list