Branch 'kolab/integration/4.13.0' - 2 commits - messagelist/core messageviewer/job messageviewer/viewer

Christian Mollekopf mollekopf at kolabsys.com
Mon Jan 26 23:51:11 CET 2015


 messagelist/core/messageitem.cpp     |   23 +++++++++++++++--------
 messagelist/core/messageitem_p.h     |    2 ++
 messageviewer/job/createeventjob.cpp |   25 +++++++++++++++++--------
 messageviewer/job/createeventjob.h   |    3 ++-
 messageviewer/job/createnotejob.cpp  |    2 +-
 messageviewer/job/createtodojob.cpp  |   26 ++++++++++++++++++--------
 messageviewer/job/createtodojob.h    |    3 ++-
 messageviewer/viewer/viewer_p.cpp    |   26 ++++++++++++++++----------
 messageviewer/viewer/viewer_p.h      |    2 ++
 9 files changed, 75 insertions(+), 37 deletions(-)

New commits:
commit cb3b340bc8f069795044e259a76404290c205997
Author: Sandro Knauß <knauss at kolabsys.com>
Date:   Fri Jan 23 16:39:58 2015 +0100

    A GENERIC relation is not only the connection between note and email
    
    Make sure that also other relations are handled correctly and really
    make sure, that the related object is a note.

diff --git a/messagelist/core/messageitem.cpp b/messagelist/core/messageitem.cpp
index 755cd4d..4bd2ecd 100644
--- a/messagelist/core/messageitem.cpp
+++ b/messagelist/core/messageitem.cpp
@@ -29,6 +29,7 @@
 #include <akonadi/tagattribute.h>
 #include <akonadi/tagfetchjob.h>
 #include <akonadi/tagfetchscope.h>
+#include <Akonadi/Notes/NoteUtils>
 #include <KIconLoader>
 #include <KLocalizedString>
 
@@ -170,6 +171,18 @@ void MessageItemPrivate::invalidateAnnotationCache()
 {
 }
 
+Akonadi::Relation MessageItemPrivate::relatedNoteRelation() const
+{
+    Akonadi::Relation relation;
+    foreach (const Akonadi::Relation &r, mAkonadiItem.relations()) {
+        if (r.type() == Akonadi::Relation::GENERIC && r.right().mimeType() == Akonadi::NoteUtils::noteMimeType() ) {
+            relation = r;
+            break;
+        }
+    }
+    return relation;
+}
+
 const MessageItem::Tag* MessageItemPrivate::bestTag() const
 {
     const MessageItem::Tag *best = 0;
@@ -259,20 +272,14 @@ QList< MessageItem::Tag * > MessageItem::tagList() const
 bool MessageItem::hasAnnotation() const
 {
     Q_D( const MessageItem );
-    return !d->mAkonadiItem.relations().isEmpty();
+    return d->relatedNoteRelation().isValid();
 }
 
 Akonadi::Item MessageItem::annotation() const
 {
     Q_D( const MessageItem );
     if ( hasAnnotation() ) {
-        Akonadi::Relation relation;
-        foreach( const Akonadi::Relation &r, d->mAkonadiItem.relations() ) {
-            if ( r.type() == Akonadi::Relation::GENERIC ) {
-                relation = r;
-                break;
-            }
-        }
+        Akonadi::Relation relation = d->relatedNoteRelation();
 
         if ( relation.isValid() ) {
             return relation.right();
diff --git a/messagelist/core/messageitem_p.h b/messagelist/core/messageitem_p.h
index dac7b67..dc4e3e7 100644
--- a/messagelist/core/messageitem_p.h
+++ b/messagelist/core/messageitem_p.h
@@ -64,6 +64,8 @@ public:
   // This creates mTagList and fills it with useful data
   void fillTagList( const Akonadi::Tag::List &taglist );
 
+  Akonadi::Relation relatedNoteRelation() const;
+
   QByteArray mMessageIdMD5;            ///< always set
   QByteArray mInReplyToIdMD5;          ///< set only if we're doing threading
   QByteArray mReferencesIdMD5;         ///< set only if we're doing threading
diff --git a/messageviewer/job/createnotejob.cpp b/messageviewer/job/createnotejob.cpp
index f58702d..1c1e81b 100644
--- a/messageviewer/job/createnotejob.cpp
+++ b/messageviewer/job/createnotejob.cpp
@@ -49,7 +49,7 @@ void CreateNoteJob::start()
         Akonadi::Relation relation;
         foreach (const Akonadi::Relation &r, mItem.relations()) {
             // assuming that GENERIC relations to emails are notes is a pretty horirific hack imo - aseigo
-            if (r.type() == Akonadi::Relation::GENERIC/* && r.right().mimeType() == Akonadi::NoteUtils::noteMimeType(*/) {
+            if (r.type() == Akonadi::Relation::GENERIC && r.right().mimeType() == Akonadi::NoteUtils::noteMimeType() ) {
                 relation = r;
                 break;
             }
diff --git a/messageviewer/viewer/viewer_p.cpp b/messageviewer/viewer/viewer_p.cpp
index d1fdec6..3554a49 100644
--- a/messageviewer/viewer/viewer_p.cpp
+++ b/messageviewer/viewer/viewer_p.cpp
@@ -1351,7 +1351,7 @@ void ViewerPrivate::setMessageInternal( const KMime::Message::Ptr message,
 {
     if ( mCreateNoteAction ) {
         QString createNoteText;
-        if ( mMessageItem.relations().isEmpty() ) {
+        if ( !relatedNoteRelation().isValid() ) {
             createNoteText = i18nc( "create a new note out of this message", "Create Note" );
         } else {
             createNoteText = i18nc( "edit a note on this message", "Edit Note" );
@@ -3446,18 +3446,24 @@ void ViewerPrivate::slotCreateEvent(const KCalCore::Event::Ptr &eventPtr, const
     createJob->start();
 }
 
-void ViewerPrivate::slotShowCreateNoteWidget()
+Akonadi::Relation ViewerPrivate::relatedNoteRelation()
 {
-    if (!mMessageItem.relations().isEmpty())  {
-        Akonadi::Relation relation;
-        foreach (const Akonadi::Relation &r, mMessageItem.relations()) {
-            // assuming that GENERIC relations to emails are notes is a pretty horirific hack imo - aseigo
-            if (r.type() == Akonadi::Relation::GENERIC/* && r.right().mimeType() == Akonadi::NoteUtils::noteMimeType(*/) {
-                relation = r;
-                break;
-            }
+    Akonadi::Relation relation;
+    foreach (const Akonadi::Relation &r, mMessageItem.relations()) {
+        // assuming that GENERIC relations to emails are notes is a pretty horirific hack imo - aseigo
+        if (r.type() == Akonadi::Relation::GENERIC && r.right().mimeType() == Akonadi::NoteUtils::noteMimeType() ) {
+            relation = r;
+            break;
         }
+    }
+    return relation;
+}
+
 
+void ViewerPrivate::slotShowCreateNoteWidget()
+{
+    if (!mMessageItem.relations().isEmpty())  {
+        Akonadi::Relation relation = relatedNoteRelation();
         if (relation.isValid()) {
             Akonadi::ItemFetchJob* job = new Akonadi::ItemFetchJob(relation.right());
             job->fetchScope().fetchFullPayload(true);
diff --git a/messageviewer/viewer/viewer_p.h b/messageviewer/viewer/viewer_p.h
index 3797363..7a334f6 100644
--- a/messageviewer/viewer/viewer_p.h
+++ b/messageviewer/viewer/viewer_p.h
@@ -642,6 +642,8 @@ private:
     QString recipientsQuickListLinkHtml( bool, const QString & ) const;
     void initGrantleeThemeName();
 
+    Akonadi::Relation relatedNoteRelation();
+
 public:
     NodeHelper* mNodeHelper;
     bool mHtmlMail, mHtmlLoadExternal, mHtmlOverride, mHtmlLoadExtOverride;


commit ca44a59440c91390745aa9d0d7651191f0e94d92
Author: Sandro Knauß <knauss at kolabsys.com>
Date:   Fri Jan 23 16:38:10 2015 +0100

    Create Relation instead of an attachment
    
    Create a Link between the new created ToDo and Event with the mail.

diff --git a/messageviewer/job/createeventjob.cpp b/messageviewer/job/createeventjob.cpp
index 465af51..8e99ad4 100644
--- a/messageviewer/job/createeventjob.cpp
+++ b/messageviewer/job/createeventjob.cpp
@@ -21,6 +21,7 @@
 #include <Akonadi/ItemFetchJob>
 #include <Akonadi/ItemFetchScope>
 #include <Akonadi/ItemCreateJob>
+#include <Akonadi/RelationCreateJob>
 
 #include <KMime/Message>
 #include <QDebug>
@@ -80,24 +81,32 @@ void CreateEventJob::createEvent()
         Q_EMIT emitResult();
         return;
     }
-    KMime::Message::Ptr msg =  mItem.payload<KMime::Message::Ptr>();
-
-    KCalCore::Attachment::Ptr attachmentPtr(new KCalCore::Attachment( msg->encodedContent().toBase64(), KMime::Message::mimeType() ));
-    attachmentPtr->setLabel(msg->subject(false)->asUnicodeString());
-    mEventPtr->addAttachment(attachmentPtr);
 
     Akonadi::Item newTodoItem;
     newTodoItem.setMimeType( KCalCore::Event::eventMimeType() );
     newTodoItem.setPayload<KCalCore::Event::Ptr>( mEventPtr );
 
     Akonadi::ItemCreateJob *createJob = new Akonadi::ItemCreateJob(newTodoItem, mCollection);
-    connect(createJob, SIGNAL(result(KJob*)), this, SLOT(slotCreateNewEvent(KJob*)));
+    connect(createJob, SIGNAL(result(KJob*)), this, SLOT(eventCreated(KJob*)));
 }
 
-void CreateEventJob::slotCreateNewEvent(KJob *job)
+void CreateEventJob::eventCreated(KJob *job)
 {
     if ( job->error() ) {
         qDebug() << "Error during create new Event "<<job->errorString();
+        setError( job->error() );
+        setErrorText( job->errorText() );
+        emitResult();
+    } else {
+        Akonadi::ItemCreateJob *createJob = static_cast<Akonadi::ItemCreateJob *> ( job );
+        Akonadi::Relation relation( Akonadi::Relation::GENERIC, mItem, createJob->item() );
+        Akonadi::RelationCreateJob *job = new Akonadi::RelationCreateJob( relation );
+        connect( job, SIGNAL( result( KJob * ) ), this, SLOT( relationCreated( KJob * ) ) );
     }
-    Q_EMIT emitResult();
+}
+
+void CreateEventJob::relationCreated(KJob *job)
+{
+   Q_UNUSED(job)
+   emitResult();
 }
diff --git a/messageviewer/job/createeventjob.h b/messageviewer/job/createeventjob.h
index b87aa2a..a8e41c8 100644
--- a/messageviewer/job/createeventjob.h
+++ b/messageviewer/job/createeventjob.h
@@ -35,7 +35,8 @@ public:
 
 private slots:
     void slotFetchDone(KJob *job);
-    void slotCreateNewEvent(KJob *job);
+    void eventCreated(KJob *job);
+    void relationCreated(KJob *job);
 
 private:
     void createEvent();
diff --git a/messageviewer/job/createtodojob.cpp b/messageviewer/job/createtodojob.cpp
index dff1148..e9ffa62 100644
--- a/messageviewer/job/createtodojob.cpp
+++ b/messageviewer/job/createtodojob.cpp
@@ -21,6 +21,7 @@
 #include <Akonadi/ItemFetchJob>
 #include <Akonadi/ItemFetchScope>
 #include <Akonadi/ItemCreateJob>
+#include <Akonadi/RelationCreateJob>
 
 #include <KMime/Message>
 #include <QDebug>
@@ -80,24 +81,33 @@ void CreateTodoJob::createTodo()
         Q_EMIT emitResult();
         return;
     }
-    KMime::Message::Ptr msg =  mItem.payload<KMime::Message::Ptr>();
-
-    KCalCore::Attachment::Ptr attachmentPtr(new KCalCore::Attachment( msg->encodedContent().toBase64(), KMime::Message::mimeType() ));
-    attachmentPtr->setLabel(msg->subject(false)->asUnicodeString());
-    mTodoPtr->addAttachment(attachmentPtr);
 
     Akonadi::Item newTodoItem;
     newTodoItem.setMimeType( KCalCore::Todo::todoMimeType() );
     newTodoItem.setPayload<KCalCore::Todo::Ptr>( mTodoPtr );
 
     Akonadi::ItemCreateJob *createJob = new Akonadi::ItemCreateJob(newTodoItem, mCollection);
-    connect(createJob, SIGNAL(result(KJob*)), this, SLOT(slotCreateNewTodo(KJob*)));
+    connect(createJob, SIGNAL(result(KJob*)), this, SLOT(todoCreated(KJob*)));
 }
 
-void CreateTodoJob::slotCreateNewTodo(KJob *job)
+void CreateTodoJob::todoCreated(KJob *job)
 {
     if ( job->error() ) {
         qDebug() << "Error during create new Todo "<<job->errorString();
+        setError( job->error() );
+        setErrorText( job->errorText() );
+        emitResult();
+    } else {
+        Akonadi::ItemCreateJob *createJob = static_cast<Akonadi::ItemCreateJob *> ( job );
+        Akonadi::Relation relation( Akonadi::Relation::GENERIC, mItem, createJob->item() );
+        Akonadi::RelationCreateJob *job = new Akonadi::RelationCreateJob( relation );
+        connect( job, SIGNAL( result( KJob * ) ), this, SLOT( relationCreated( KJob * ) ) );
     }
-    Q_EMIT emitResult();
+}
+
+
+void CreateTodoJob::relationCreated(KJob *job)
+{
+   Q_UNUSED(job)
+   emitResult();
 }
diff --git a/messageviewer/job/createtodojob.h b/messageviewer/job/createtodojob.h
index 03724de..98ac8b4 100644
--- a/messageviewer/job/createtodojob.h
+++ b/messageviewer/job/createtodojob.h
@@ -35,7 +35,8 @@ public:
 
 private slots:
     void slotFetchDone(KJob *job);
-    void slotCreateNewTodo(KJob *job);
+    void todoCreated(KJob *job);
+    void relationCreated(KJob *job);
 
 private:
     void createTodo();




More information about the commits mailing list