Branch 'kolab/integration/4.13.0' - 2 commits - akonadi/notes kcalcore/event.cpp kcalcore/event.h kcalcore/tests kcalcore/todo.cpp kcalcore/todo.h

Sandro Knauß knauss at kolabsys.com
Sun Aug 10 15:21:55 CEST 2014


 akonadi/notes/noteutils.cpp       |    4 +-
 akonadi/notes/tests/notestest.cpp |   55 ++++++++++++++++++++++++++++++++++++++
 kcalcore/event.cpp                |    6 ++++
 kcalcore/event.h                  |    8 +++++
 kcalcore/tests/testevent.cpp      |   18 ++++++++++++
 kcalcore/tests/testevent.h        |    1 
 kcalcore/tests/testtodo.cpp       |   18 ++++++++++++
 kcalcore/tests/testtodo.h         |    1 
 kcalcore/todo.cpp                 |    6 ++++
 kcalcore/todo.h                   |    8 +++++
 10 files changed, 123 insertions(+), 2 deletions(-)

New commits:
commit 4435bcb73f62f06ae2132fc2398d0cba3347707a
Author: Sandro Knauß <knauss at kolabsys.com>
Date:   Sun Aug 3 19:29:00 2014 +0200

    Construct a event/todo out of an incidence
    
    REVIEW: 119591

diff --git a/kcalcore/event.cpp b/kcalcore/event.cpp
index 57d076e..9057cdf 100644
--- a/kcalcore/event.cpp
+++ b/kcalcore/event.cpp
@@ -78,6 +78,12 @@ Event::Event(const Event &other)
 {
 }
 
+Event::Event(const Incidence &other)
+    : Incidence(other)
+    , d(new KCalCore::Event::Private)
+{
+}
+
 Event::~Event()
 {
     delete d;
diff --git a/kcalcore/event.h b/kcalcore/event.h
index a09ad26..62da897 100644
--- a/kcalcore/event.h
+++ b/kcalcore/event.h
@@ -71,6 +71,14 @@ public:
     Event(const Event &other);
 
     /**
+      Costructs an event out of an incidence
+      This constructs allows to make it easy to create an event from a todo.
+      @param other is the incidence to copy.
+      @since 4.14
+    */
+    Event(const Incidence &other);
+
+    /**
       Destroys the event.
     */
     ~Event();
diff --git a/kcalcore/tests/testevent.cpp b/kcalcore/tests/testevent.cpp
index b0468a4..7981d2b 100644
--- a/kcalcore/tests/testevent.cpp
+++ b/kcalcore/tests/testevent.cpp
@@ -20,6 +20,7 @@
 */
 #include "testevent.h"
 #include "../event.h"
+#include "../todo.h"
 
 #include <qtest_kde.h>
 QTEST_KDEMAIN(EventTest, NoGUI)
@@ -140,6 +141,23 @@ void EventTest::testCopy()
     QVERIFY(event1.location() == event2.location());
 }
 
+void EventTest::testCopyIncidence()
+{
+    QDate dt = QDate::currentDate();
+    Todo todo;
+    todo.setDtStart(KDateTime(dt));
+    todo.setSummary(QLatin1String("Event1 Summary"));
+    todo.setDescription(QLatin1String("This is a description of the first event"));
+    todo.setLocation(QLatin1String("the place"));
+
+    Event event(todo);
+    QCOMPARE(event.uid(), todo.uid());
+    QCOMPARE(event.dtStart(), todo.dtStart());
+    QCOMPARE(event.summary(), todo.summary());
+    QCOMPARE(event.description(), todo.description());
+    QCOMPARE(event.location(), todo.location());
+}
+
 void EventTest::testAssign()
 {
     QDate dt = QDate::currentDate();
diff --git a/kcalcore/tests/testevent.h b/kcalcore/tests/testevent.h
index 46a95d9..509cb71 100644
--- a/kcalcore/tests/testevent.h
+++ b/kcalcore/tests/testevent.h
@@ -34,6 +34,7 @@ private Q_SLOTS:
     void testCompare();
     void testClone();
     void testCopy();
+    void testCopyIncidence();
     void testAssign();
     void testSerializer_data();
     void testSerializer();
diff --git a/kcalcore/tests/testtodo.cpp b/kcalcore/tests/testtodo.cpp
index 9a856a5..fd895be 100644
--- a/kcalcore/tests/testtodo.cpp
+++ b/kcalcore/tests/testtodo.cpp
@@ -20,6 +20,7 @@
 */
 #include "testtodo.h"
 #include "../todo.h"
+#include "../event.h"
 #include "attachment.h"
 
 #include <qtest_kde.h>
@@ -87,6 +88,23 @@ void TodoTest::testClone()
     QVERIFY(todo1.isCompleted() == todo2->isCompleted());
 }
 
+void TodoTest::testCopyIncidence()
+{
+  QDate dt = QDate::currentDate();
+  Event event;
+  event.setDtStart(KDateTime(dt));
+  event.setSummary(QLatin1String("Event1 Summary"));
+  event.setDescription(QLatin1String("This is a description of the first event"));
+  event.setLocation(QLatin1String("the place"));
+
+  Todo todo(event);
+  QCOMPARE(todo.uid(), event.uid());
+  QCOMPARE(todo.dtStart(), event.dtStart());
+  QCOMPARE(todo.summary(), event.summary());
+  QCOMPARE(todo.description(), event.description());
+  QCOMPARE(todo.location(), event.location());
+}
+
 void TodoTest::testAssign()
 {
     QDate dt = QDate::currentDate();
diff --git a/kcalcore/tests/testtodo.h b/kcalcore/tests/testtodo.h
index 003bea3..4463e5a 100644
--- a/kcalcore/tests/testtodo.h
+++ b/kcalcore/tests/testtodo.h
@@ -31,6 +31,7 @@ private Q_SLOTS:
     void testValidity();
     void testCompare();
     void testClone();
+    void testCopyIncidence();
     void testAssign();
     void testSetCompleted();
     void testStatus();
diff --git a/kcalcore/todo.cpp b/kcalcore/todo.cpp
index 30f277b..be2c4d5 100644
--- a/kcalcore/todo.cpp
+++ b/kcalcore/todo.cpp
@@ -92,6 +92,12 @@ Todo::Todo(const Todo &other)
 {
 }
 
+Todo::Todo(const Incidence &other)
+    : Incidence(other)
+    , d(new KCalCore::Todo::Private)
+{
+}
+
 Todo::~Todo()
 {
     delete d;
diff --git a/kcalcore/todo.h b/kcalcore/todo.h
index 76cfa84..25ff936 100644
--- a/kcalcore/todo.h
+++ b/kcalcore/todo.h
@@ -66,6 +66,14 @@ public:
     Todo(const Todo &other);
 
     /**
+      Costructs a todo out of an incidence
+      This constructs allows to make it easy to create a todo from an event.
+      @param other is the incidence to copy.
+      @since 4.14
+     */
+    Todo(const Incidence &other);
+
+    /**
       Destroys a to-do.
     */
     ~Todo();


commit 470862763fc2080ef1036c48cd17fdf215145927
Author: Sandro Knauß <knauss at kolabsys.com>
Date:   Sun Aug 3 19:46:39 2014 +0200

    Fixing RichtText format together with attachments
    
    REVIEW: 119592

diff --git a/akonadi/notes/noteutils.cpp b/akonadi/notes/noteutils.cpp
index 81e9c88..ac6744b 100644
--- a/akonadi/notes/noteutils.cpp
+++ b/akonadi/notes/noteutils.cpp
@@ -188,7 +188,7 @@ void NoteMessageWrapper::NoteMessageWrapperPrivate::readMimeMessage(const KMime:
   if ( msg->from( false ) )
     from = msg->from( false )->asUnicodeString();
   creationDate = msg->date( true )->dateTime();
-  if ( msg->contentType( false ) && msg->contentType( false )->asUnicodeString() == QLatin1String("text/html") ) {
+  if ( msg->mainBodyPart()->contentType( false ) && msg->mainBodyPart()->contentType()->mimeType() == "text/html" ) {
     textFormat = Qt::RichText;
   }
 
@@ -376,10 +376,10 @@ KMime::Message::Ptr NoteMessageWrapper::message() const
   }
 
   msg->subject( true )->fromUnicodeString( title, ENCODING );
-  msg->contentType( true )->setMimeType( d->textFormat == Qt::RichText ? "text/html" : "text/plain" );
   msg->date( true )->setDateTime( creationDate );
   msg->from( true )->fromUnicodeString( d->from, ENCODING );
   msg->mainBodyPart()->fromUnicodeString( text );
+  msg->mainBodyPart()->contentType( true )->setMimeType( d->textFormat == Qt::RichText ? "text/html" : "text/plain" );
   msg->appendHeader( new KMime::Headers::Generic(X_NOTES_LASTMODIFIED_HEADER, msg.get(), lastModifiedDate.toString( KDateTime::RFCDateDay ).toLatin1(), ENCODING ) );
   msg->appendHeader( new KMime::Headers::Generic( X_NOTES_UID_HEADER, msg.get(), uid, ENCODING ) );
 
diff --git a/akonadi/notes/tests/notestest.cpp b/akonadi/notes/tests/notestest.cpp
index 7e2433f..92c39b8 100644
--- a/akonadi/notes/tests/notestest.cpp
+++ b/akonadi/notes/tests/notestest.cpp
@@ -78,6 +78,61 @@ class NotesTest : public QObject
       QVERIFY(result.lastModifiedDate().isValid());
     }
 
+    void testNormalTextWithoutAttachments()
+    {
+        NoteMessageWrapper note;
+        QString text(QLatin1String("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\"> \
+            <html> \
+              <head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\"> p, li { white-space: pre-wrap; } </style></head> \
+              <body style=\"font-family:'Sans Serif'; font-size:9pt;\"> <p>sdfg</p></body> \
+            </html>"));
+        note.setText(text);
+
+        KMime::Message::Ptr msg = note.message();
+        NoteMessageWrapper result(msg);
+
+        QCOMPARE(result.text(), text);
+        QCOMPARE(result.textFormat(), Qt::PlainText);
+    }
+
+    void testRichTextWithoutAttachments()
+    {
+        NoteMessageWrapper note;
+        QString text(QLatin1String("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\"> \
+            <html> \
+              <head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\"> p, li { white-space: pre-wrap; } </style></head> \
+              <body style=\"font-family:'Sans Serif'; font-size:9pt;\"> <p>sdfg</p></body> \
+            </html>"));
+        note.setText(text, Qt::RichText);
+
+        KMime::Message::Ptr msg = note.message();
+        NoteMessageWrapper result(msg);
+
+        QCOMPARE(result.text(), text);
+        QCOMPARE(result.textFormat(), Qt::RichText);
+    }
+
+    void testRichTextWithAttachments()
+    {
+        NoteMessageWrapper note;
+        QString text(QLatin1String("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\"> \
+            <html> \
+              <head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\"> p, li { white-space: pre-wrap; } </style></head> \
+              <body style=\"font-family:'Sans Serif'; font-size:9pt;\"> <p>sdfg</p></body> \
+            </html>"));
+        note.setText(text, Qt::RichText);
+
+        Attachment a(QByteArray("testfile2"), QLatin1String("mimetype/mime3"));
+        a.setLabel(QLatin1String("label"));
+        note.attachments() << Attachment(QUrl("file://url/to/file"), QLatin1String("mimetype/mime")) << a;
+
+        KMime::Message::Ptr msg = note.message();
+        NoteMessageWrapper result(msg);
+
+        QCOMPARE(result.text(), text);
+        QCOMPARE(result.textFormat(), Qt::RichText);
+        QCOMPARE(result.attachments(), note.attachments());
+    }
 };
 
 QTEST_MAIN( NotesTest )




More information about the commits mailing list