Branch 'feature/notes_on_emails' - 2 commits - messageviewer/job messageviewer/viewer

Aaron Seigo seigo at kolabsys.com
Fri Oct 10 16:44:48 CEST 2014


 messageviewer/job/createnotejob.cpp |   33 +++++++++++++++++++++++++++-
 messageviewer/job/createnotejob.h   |    1 
 messageviewer/viewer/viewer_p.cpp   |   42 +++++++++++++++++++++++++++++++++++-
 messageviewer/viewer/viewer_p.h     |    3 ++
 4 files changed, 77 insertions(+), 2 deletions(-)

New commits:
commit 5111f8bfe27c5cd6b0925c494cbf06dc21e644f3
Author: Aaron Seigo <aseigo at kde.org>
Date:   Fri Oct 10 16:43:47 2014 +0200

    if there is a note, then fetch the note info for editting before showing the note edit

diff --git a/messageviewer/viewer/viewer_p.cpp b/messageviewer/viewer/viewer_p.cpp
index 3817948..9dc81c9 100644
--- a/messageviewer/viewer/viewer_p.cpp
+++ b/messageviewer/viewer/viewer_p.cpp
@@ -3445,11 +3445,51 @@ void ViewerPrivate::slotCreateEvent(const KCalCore::Event::Ptr &eventPtr, const
 
 void ViewerPrivate::slotShowCreateNoteWidget()
 {
+    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;
+            }
+        }
+
+        if (relation.isValid()) {
+            Akonadi::ItemFetchJob* job = new Akonadi::ItemFetchJob(relation.right());
+            job->fetchScope().fetchFullPayload(true);
+            connect(job, SIGNAL(result(KJob*)), this, SLOT(slotNoteItemFetched(KJob*)));
+            return;
+        }
+    }
+
+    showCreateNewNoteWidget();
+}
+
+void ViewerPrivate::showCreateNewNoteWidget()
+{
     if (mMessage) {
         mCreateNote->setMessage(mMessage);
         mCreateNote->showNoteEdit();
     } else {
-        qDebug()<<" There is not valid message";
+        qDebug() << "There is not valid message";
+    }
+}
+
+void ViewerPrivate::slotNoteItemFetched(KJob *job)
+{
+    if (job->error()) {
+        showCreateNewNoteWidget();
+    } else {
+        Akonadi::ItemFetchJob *fetch = qobject_cast<Akonadi::ItemFetchJob*>( job );
+        Q_ASSERT( fetch );
+        if (fetch->items().isEmpty() || !fetch->items().first().hasPayload<KMime::Message::Ptr>()) {
+            showCreateNewNoteWidget();
+        } else {
+            Akonadi::NoteUtils::NoteMessageWrapper note(fetch->items().first().payload<KMime::Message::Ptr>());
+            mCreateNote->setMessage(note.message());
+            mCreateNote->showNoteEdit();
+        }
     }
 }
 
diff --git a/messageviewer/viewer/viewer_p.h b/messageviewer/viewer/viewer_p.h
index 819df31..3797363 100644
--- a/messageviewer/viewer/viewer_p.h
+++ b/messageviewer/viewer/viewer_p.h
@@ -620,6 +620,7 @@ public slots:
     void slotShowCreateTodoWidget();
     void slotShowCreateEventWidget();
     void slotShowCreateNoteWidget();
+    void slotNoteItemFetched(KJob *job);
 
 signals:
     void showStatusBarMessage( const QString &message );
@@ -634,7 +635,9 @@ signals:
 
     void changeDisplayMail(Viewer::ForceDisplayTo,bool);
     void moveMessageToTrash();
+
 private:
+    void showCreateNewNoteWidget();
     QString attachmentInjectionHtml() const;
     QString recipientsQuickListLinkHtml( bool, const QString & ) const;
     void initGrantleeThemeName();


commit 35a80484f91d2ef2e627e1840a24fe5bffce4977
Author: Aaron Seigo <aseigo at kde.org>
Date:   Fri Oct 10 16:28:54 2014 +0200

    if the note exists, update it rather than create a new one

diff --git a/messageviewer/job/createnotejob.cpp b/messageviewer/job/createnotejob.cpp
index 6735c14..f58702d 100644
--- a/messageviewer/job/createnotejob.cpp
+++ b/messageviewer/job/createnotejob.cpp
@@ -20,6 +20,8 @@
 #include <Akonadi/KMime/MessageParts>
 #include <Akonadi/RelationCreateJob>
 #include <Akonadi/ItemCreateJob>
+#include <Akonadi/ItemModifyJob>
+#include <Akonadi/Relation>
 
 #include <KMime/Message>
 #include <QApplication>
@@ -43,11 +45,29 @@ void CreateNoteJob::start()
 {
     mNote.setFrom(QCoreApplication::applicationName() + QCoreApplication::applicationVersion());
     mNote.setLastModifiedDate(KDateTime::currentUtcDateTime());
+    if (!mItem.relations().isEmpty())  {
+        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(*/) {
+                relation = r;
+                break;
+            }
+        }
+
+        if (relation.isValid()) {
+            Akonadi::Item item = relation.right();
+            item.setMimeType(Akonadi::NoteUtils::noteMimeType());
+            item.setPayload(mNote.message());
+            Akonadi::ItemModifyJob *modifyJob = new Akonadi::ItemModifyJob(item);
+            connect(modifyJob, SIGNAL(result(KJob*)), this, SLOT(noteUpdated(KJob*)));
+            return;
+        }
+    }
 
     Akonadi::Item newNoteItem;
     newNoteItem.setMimeType( Akonadi::NoteUtils::noteMimeType() );
     newNoteItem.setPayload( mNote.message() );
-
     Akonadi::ItemCreateJob *createJob = new Akonadi::ItemCreateJob(newNoteItem, mCollection);
     connect(createJob, SIGNAL(result(KJob*)), this, SLOT(noteCreated(KJob*)));
 }
@@ -67,8 +87,19 @@ void CreateNoteJob::noteCreated(KJob *job)
     }
 }
 
+void CreateNoteJob::noteUpdated(KJob *job)
+{
+    if ( job->error() ) {
+        setError( job->error() );
+        setErrorText( job->errorText() );
+    }
+
+    emitResult();
+}
+
 void CreateNoteJob::relationCreated(KJob *job)
 {
+   Q_UNUSED(job)
    emitResult();
 }
 
diff --git a/messageviewer/job/createnotejob.h b/messageviewer/job/createnotejob.h
index 6680376..5191308 100644
--- a/messageviewer/job/createnotejob.h
+++ b/messageviewer/job/createnotejob.h
@@ -39,6 +39,7 @@ public:
 
 private slots:
     void noteCreated(KJob *job);
+    void noteUpdated(KJob *job);
     void relationCreated(KJob *job);
 
 private:




More information about the commits mailing list