Branch 'feature/notes_on_emails' - 5 commits - mailcommon/folder messagelist/core messagelist/storagemodel.cpp messageviewer/job

Aaron Seigo seigo at kolabsys.com
Thu Oct 9 17:50:47 CEST 2014


 mailcommon/folder/foldercollectionmonitor.cpp |    2 
 messagelist/core/messageitem.cpp              |   27 ++++++---
 messagelist/core/messageitem.h                |   11 +---
 messagelist/storagemodel.cpp                  |   12 +---
 messageviewer/job/createnotejob.cpp           |   71 ++++++--------------------
 messageviewer/job/createnotejob.h             |    4 -
 6 files changed, 48 insertions(+), 79 deletions(-)

New commits:
commit cf612b5bf19cb59d6667f14b22feb806d0fea992
Author: Aaron Seigo <aseigo at kde.org>
Date:   Thu Oct 9 16:33:13 2014 +0200

    we no longer care about annotations, but relations

diff --git a/mailcommon/folder/foldercollectionmonitor.cpp b/mailcommon/folder/foldercollectionmonitor.cpp
index f2ebf7d..895ff32 100644
--- a/mailcommon/folder/foldercollectionmonitor.cpp
+++ b/mailcommon/folder/foldercollectionmonitor.cpp
@@ -56,7 +56,7 @@ FolderCollectionMonitor::FolderCollectionMonitor( Akonadi::Session *session, QOb
   mMonitor->itemFetchScope().setFetchModificationTime( false );
   mMonitor->itemFetchScope().setFetchRemoteIdentification( false );
   mMonitor->itemFetchScope().setFetchTags( true );
-  mMonitor->itemFetchScope().fetchAttribute<Akonadi::EntityAnnotationsAttribute>( true );
+  mMonitor->itemFetchScope().setFetchRelations( true );
 }
 
 FolderCollectionMonitor::~FolderCollectionMonitor()


commit 2be02a261c4fab64bebed668f380758aaec1e8fc
Author: Aaron Seigo <aseigo at kde.org>
Date:   Thu Oct 9 16:32:40 2014 +0200

    update the implementation of the API to reflect that we are using realy notes

diff --git a/messagelist/core/messageitem.cpp b/messagelist/core/messageitem.cpp
index 52b7775..73cf0dd 100644
--- a/messagelist/core/messageitem.cpp
+++ b/messagelist/core/messageitem.cpp
@@ -25,6 +25,7 @@
 #include "theme.h"
 
 #include <akonadi/item.h>
+#include <akonadi/relation.h>
 #include <akonadi/tagattribute.h>
 #include <akonadi/tagfetchjob.h>
 #include <akonadi/tagfetchscope.h>
@@ -41,8 +42,8 @@ class MessageItem::Tag::Private
     Private()
         :mPriority( 0 ) //Initialize it
     {
-
     }
+
     QPixmap mPixmap;
     QString mName;
     QString mId;             ///< The unique id of this tag
@@ -260,20 +261,28 @@ bool MessageItem::hasAnnotation() const
 {
     Q_D( const MessageItem );
     //FIXME NOTES_ON_EMAIL
-    return false;
+    return !d->mAkonadiItem.relations().isEmpty();
 }
 
-QString MessageItem::annotation() const
+Akonadi::Item MessageItem::annotation() const
 {
     Q_D( const MessageItem );
     //FIXME NOTES_ON_EMAIL
-    return QString();
-}
+    if ( hasAnnotation() ) {
+        Akonadi::Relation relation;
+        foreach( const Akonadi::Relation &r, d->mAkonadiItem.relations() ) {
+            if ( r.type() == Akonadi::Relation::GENERIC ) {
+                relation = r;
+                break;
+            }
+        }
 
-void MessageItem::editAnnotation()
-{
-    Q_D( MessageItem );
-    //FIXME: NOTES_ON_EMAIL
+        if ( relation.isValid() ) {
+            return relation.right();
+        }
+    }
+
+    return Akonadi::Item();
 }
 
 const MessageItem::Tag * MessageItemPrivate::findTagInternal( const QString &szTagId ) const
diff --git a/messagelist/core/messageitem.h b/messagelist/core/messageitem.h
index e3f96da..48b4161 100644
--- a/messagelist/core/messageitem.h
+++ b/messagelist/core/messageitem.h
@@ -105,15 +105,12 @@ public:
     virtual bool hasAnnotation() const;
 
     /// Returns the annotation of the message, given that hasAnnotation() is true
-    QString annotation() const;
-
-    /// Shows a dialog to edit or delete the annotation
-    void editAnnotation();
+    Akonadi::Item annotation() const;
 
     /**
-   * Returns Tag associated to this message that has the specified id or 0
-   * if no such tag exists. mTagList will be 0 in 99% of the cases.
-   */
+     * Returns Tag associated to this message that has the specified id or 0
+     * if no such tag exists. mTagList will be 0 in 99% of the cases.
+     */
     const Tag * findTag( const QString &szTagId ) const;
 
     QString tagListDescription() const;


commit 62d25ce8596df6d2c96278e6b2cbf5efd0a51d91
Author: Aaron Seigo <aseigo at kde.org>
Date:   Thu Oct 9 16:11:56 2014 +0200

    don't defeat the optimization by creating new strings

diff --git a/messagelist/storagemodel.cpp b/messagelist/storagemodel.cpp
index e7822fa..d131479 100644
--- a/messagelist/storagemodel.cpp
+++ b/messagelist/storagemodel.cpp
@@ -233,7 +233,9 @@ bool StorageModel::initializeMessageItem( MessageList::Core::MessageItem *mi,
     }
 
     // Static for speed reasons
-    static const QString noSubject = i18nc( "displayed as subject when the subject of a mail is empty", "No Subject" );
+    static const QString noSubject = QLatin1Char( '(' ) +
+                                     i18nc( "displayed as subject when the subject of a mail is empty", "No Subject" ) +
+                                     QLatin1Char( ')' );
     static const QString unknown( i18nc( "displayed when a mail has unknown sender, receiver or date", "Unknown" ) );
 
     if ( sender.isEmpty() ) {
@@ -249,12 +251,8 @@ bool StorageModel::initializeMessageItem( MessageList::Core::MessageItem *mi,
                       bUseReceiver );
     mi->setItemId( item.id() );
 
-    QString subject = mail->subject()->asUnicodeString();
-    if ( subject.isEmpty() ) {
-        subject = QLatin1Char( '(' ) + noSubject + QLatin1Char( ')' );
-    }
-
-    mi->setSubject( subject );
+    const QString subject = mail->subject()->asUnicodeString();
+    mi->setSubject( subject.isEmpty() ? noSubject : subject );
 
     updateMessageItemData( mi, row );
 


commit 4a01a063f9ebfc27f238896df89bbfaac1e54b30
Author: Aaron Seigo <aseigo at kde.org>
Date:   Thu Oct 9 15:58:00 2014 +0200

    we don't really care about errors in the end
    
    relations can only be formed if the mail and the note are in the same
    collection. so it is completely plausible for a relation to fail but
    the note is created and stored in akonadi where requestsed.

diff --git a/messageviewer/job/createnotejob.cpp b/messageviewer/job/createnotejob.cpp
index 113aa8e..6735c14 100644
--- a/messageviewer/job/createnotejob.cpp
+++ b/messageviewer/job/createnotejob.cpp
@@ -37,12 +37,11 @@ CreateNoteJob::CreateNoteJob(const KMime::Message::Ptr &notePtr, const Akonadi::
 
 CreateNoteJob::~CreateNoteJob()
 {
-    qDebug()<<" CreateNoteJob::~CreateNoteJob()";
 }
 
 void CreateNoteJob::start()
 {
-    mNote.setFrom(QCoreApplication::applicationName()+QCoreApplication::applicationVersion());
+    mNote.setFrom(QCoreApplication::applicationName() + QCoreApplication::applicationVersion());
     mNote.setLastModifiedDate(KDateTime::currentUtcDateTime());
 
     Akonadi::Item newNoteItem;
@@ -70,14 +69,6 @@ void CreateNoteJob::noteCreated(KJob *job)
 
 void CreateNoteJob::relationCreated(KJob *job)
 {
-   if ( job->error() ) {
-        qDebug() << "Error when creating the relation" << job->errorString();
-        setError( job->error() );
-        setErrorText( job->errorText() );
-
-        //FIXME NOTES_ON_EMAIL on failure, what to do with the note? leave it? clean it up? ...?
-   }
-
    emitResult();
 }
 


commit 79a971ec66a734b6cb3b8e6c5f251241bb802c79
Author: Aaron Seigo <aseigo at kde.org>
Date:   Thu Oct 9 10:46:23 2014 +0200

    create the actual relation

diff --git a/messageviewer/job/createnotejob.cpp b/messageviewer/job/createnotejob.cpp
index 3364337..113aa8e 100644
--- a/messageviewer/job/createnotejob.cpp
+++ b/messageviewer/job/createnotejob.cpp
@@ -18,8 +18,7 @@
 #include "createnotejob.h"
 
 #include <Akonadi/KMime/MessageParts>
-#include <Akonadi/ItemFetchJob>
-#include <Akonadi/ItemFetchScope>
+#include <Akonadi/RelationCreateJob>
 #include <Akonadi/ItemCreateJob>
 
 #include <KMime/Message>
@@ -43,52 +42,6 @@ CreateNoteJob::~CreateNoteJob()
 
 void CreateNoteJob::start()
 {
-    // We need the full payload to attach the mail
-    if ( !mItem.loadedPayloadParts().contains( Akonadi::MessagePart::Body ) ) {
-        Akonadi::ItemFetchJob *job = new Akonadi::ItemFetchJob( mItem );
-        job->fetchScope().fetchFullPayload();
-        connect( job, SIGNAL(result(KJob*)), this, SLOT(slotFetchDone(KJob*)) );
-
-        if ( job->exec() ) {
-            if ( job->items().count() == 1 ) {
-                mItem = job->items().first();
-            }
-        } else {
-            qDebug()<<" createNote: Error during fetch: "<<job->errorString();
-        }
-    } else {
-        createNote();
-    }
-}
-
-void CreateNoteJob::slotFetchDone(KJob *job)
-{
-    qDebug()<<" void CreateNoteJob::slotFetchDone(KJob *job)";
-    Akonadi::ItemFetchJob *fetchJob = qobject_cast<Akonadi::ItemFetchJob *>(job);
-    if ( fetchJob->items().count() == 1 ) {
-        mItem = fetchJob->items().first();
-    } else {
-        Q_EMIT emitResult();
-        return;
-    }
-    createNote();
-}
-
-void CreateNoteJob::createNote()
-{
-    if ( !mItem.hasPayload<KMime::Message::Ptr>() ) {
-        qDebug()<<" item has not payload";
-        Q_EMIT emitResult();
-        return;
-    }
-    KMime::Message::Ptr msg =  mItem.payload<KMime::Message::Ptr>();
-
-    Akonadi::NoteUtils::Attachment attachment(msg->encodedContent(), msg->mimeType());
-    const KMime::Headers::Subject * const subject = msg->subject(false);
-    if (subject)
-        attachment.setLabel(subject->asUnicodeString());
-    mNote.attachments().append(attachment);
-
     mNote.setFrom(QCoreApplication::applicationName()+QCoreApplication::applicationVersion());
     mNote.setLastModifiedDate(KDateTime::currentUtcDateTime());
 
@@ -97,13 +50,34 @@ void CreateNoteJob::createNote()
     newNoteItem.setPayload( mNote.message() );
 
     Akonadi::ItemCreateJob *createJob = new Akonadi::ItemCreateJob(newNoteItem, mCollection);
-    connect(createJob, SIGNAL(result(KJob*)), this, SLOT(slotCreateNewNote(KJob*)));
+    connect(createJob, SIGNAL(result(KJob*)), this, SLOT(noteCreated(KJob*)));
 }
 
-void CreateNoteJob::slotCreateNewNote(KJob *job)
+void CreateNoteJob::noteCreated(KJob *job)
 {
     if ( job->error() ) {
         qDebug() << "Error during create new Note "<<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 CreateNoteJob::relationCreated(KJob *job)
+{
+   if ( job->error() ) {
+        qDebug() << "Error when creating the relation" << job->errorString();
+        setError( job->error() );
+        setErrorText( job->errorText() );
+
+        //FIXME NOTES_ON_EMAIL on failure, what to do with the note? leave it? clean it up? ...?
+   }
+
+   emitResult();
+}
+
diff --git a/messageviewer/job/createnotejob.h b/messageviewer/job/createnotejob.h
index 4749745..6680376 100644
--- a/messageviewer/job/createnotejob.h
+++ b/messageviewer/job/createnotejob.h
@@ -38,8 +38,8 @@ public:
     void start();
 
 private slots:
-    void slotFetchDone(KJob *job);
-    void slotCreateNewNote(KJob *job);
+    void noteCreated(KJob *job);
+    void relationCreated(KJob *job);
 
 private:
     void createNote();




More information about the commits mailing list