diff --git a/messageviewer/job/createnotejob.cpp b/messageviewer/job/createnotejob.cpp index 33643371dc..113aa8ef8a 100644 --- a/messageviewer/job/createnotejob.cpp +++ b/messageviewer/job/createnotejob.cpp @@ -1,109 +1,83 @@ /* Copyright (c) 2014 Sandro Knauß This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "createnotejob.h" #include -#include -#include +#include #include #include #include #include using namespace MessageViewer; CreateNoteJob::CreateNoteJob(const KMime::Message::Ptr ¬ePtr, const Akonadi::Collection &collection, const Akonadi::Item &item, QObject *parent) : KJob(parent), mItem(item), mCollection(collection), mNote(notePtr) { } CreateNoteJob::~CreateNoteJob() { qDebug()<<" 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: "<errorString(); - } - } else { - createNote(); - } -} - -void CreateNoteJob::slotFetchDone(KJob *job) -{ - qDebug()<<" void CreateNoteJob::slotFetchDone(KJob *job)"; - Akonadi::ItemFetchJob *fetchJob = qobject_cast(job); - if ( fetchJob->items().count() == 1 ) { - mItem = fetchJob->items().first(); - } else { - Q_EMIT emitResult(); - return; - } - createNote(); -} - -void CreateNoteJob::createNote() -{ - if ( !mItem.hasPayload() ) { - qDebug()<<" item has not payload"; - Q_EMIT emitResult(); - return; - } - KMime::Message::Ptr msg = mItem.payload(); - - 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()); 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(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 "<errorString(); + setError( job->error() ); + setErrorText( job->errorText() ); + emitResult(); + } else { + Akonadi::ItemCreateJob *createJob = static_cast ( 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 4749745f6d..6680376ed5 100644 --- a/messageviewer/job/createnotejob.h +++ b/messageviewer/job/createnotejob.h @@ -1,52 +1,52 @@ /* Copyright (c) 2014 Sandro Knauß This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef CREATENOTEJOB_H #define CREATENOTEJOB_H #include #include #include #include #include #include namespace MessageViewer { class CreateNoteJob : public KJob { Q_OBJECT public: explicit CreateNoteJob(const KMime::Message::Ptr ¬ePtr, const Akonadi::Collection &collection, const Akonadi::Item &item, QObject *parent = 0); ~CreateNoteJob(); void start(); private slots: - void slotFetchDone(KJob *job); - void slotCreateNewNote(KJob *job); + void noteCreated(KJob *job); + void relationCreated(KJob *job); private: void createNote(); Akonadi::Item mItem; Akonadi::Collection mCollection; Akonadi::NoteUtils::NoteMessageWrapper mNote; }; } #endif // CREATETODOJOB_H