• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

messageviewer

  • sources
  • kde-4.14
  • kdepim
  • messageviewer
  • job
createtodojob.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2014-2015 Montel Laurent <montel@kde.org>
3 
4  This program is free software; you can redistribute it and/or modify it
5  under the terms of the GNU General Public License, version 2, as
6  published by the Free Software Foundation.
7 
8  This program is distributed in the hope that it will be useful, but
9  WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License along
14  with this program; if not, write to the Free Software Foundation, Inc.,
15  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 #include "createtodojob.h"
19 
20 #include <Akonadi/KMime/MessageParts>
21 #include <Akonadi/ItemFetchJob>
22 #include <Akonadi/ItemFetchScope>
23 #include <Akonadi/ItemCreateJob>
24 
25 #include <KMime/Message>
26 #include <QDebug>
27 
28 using namespace MessageViewer;
29 
30 CreateTodoJob::CreateTodoJob(const KCalCore::Todo::Ptr &todoPtr, const Akonadi::Collection &collection, const Akonadi::Item &item, QObject *parent)
31  : KJob(parent),
32  mItem(item),
33  mCollection(collection),
34  mTodoPtr(todoPtr)
35 {
36 }
37 
38 CreateTodoJob::~CreateTodoJob()
39 {
40  qDebug()<<" CreateTodoJob::~CreateTodoJob()";
41 }
42 
43 void CreateTodoJob::start()
44 {
45  // We need the full payload to attach the mail to the incidence
46  if ( !mItem.loadedPayloadParts().contains( Akonadi::MessagePart::Body ) ) {
47  Akonadi::ItemFetchJob *job = new Akonadi::ItemFetchJob( mItem );
48  job->fetchScope().fetchFullPayload();
49  connect( job, SIGNAL(result(KJob*)), this, SLOT(slotFetchDone(KJob*)) );
50  } else {
51  createTodo();
52  }
53 }
54 
55 void CreateTodoJob::slotFetchDone(KJob *job)
56 {
57  qDebug()<<" void CreateTodoJob::slotFetchDone(KJob *job)";
58  Akonadi::ItemFetchJob *fetchJob = qobject_cast<Akonadi::ItemFetchJob *>(job);
59  if ( fetchJob->items().count() == 1 ) {
60  mItem = fetchJob->items().first();
61  } else {
62  qDebug()<<" createTodo Error during fetch: "<<job->errorString();
63  Q_EMIT emitResult();
64  return;
65  }
66  createTodo();
67 }
68 
69 void CreateTodoJob::createTodo()
70 {
71  if ( !mItem.hasPayload<KMime::Message::Ptr>() ) {
72  qDebug()<<" item has not payload";
73  Q_EMIT emitResult();
74  return;
75  }
76  KMime::Message::Ptr msg = mItem.payload<KMime::Message::Ptr>();
77 
78  KCalCore::Attachment::Ptr attachmentPtr(new KCalCore::Attachment( msg->encodedContent().toBase64(), KMime::Message::mimeType() ));
79  const KMime::Headers::Subject * const subject = msg->subject(false);
80  if (subject)
81  attachmentPtr->setLabel(subject->asUnicodeString());
82  mTodoPtr->addAttachment(attachmentPtr);
83 
84  Akonadi::Item newTodoItem;
85  newTodoItem.setMimeType( KCalCore::Todo::todoMimeType() );
86  newTodoItem.setPayload<KCalCore::Todo::Ptr>( mTodoPtr );
87 
88  Akonadi::ItemCreateJob *createJob = new Akonadi::ItemCreateJob(newTodoItem, mCollection);
89  connect(createJob, SIGNAL(result(KJob*)), this, SLOT(slotCreateNewTodo(KJob*)));
90 }
91 
92 void CreateTodoJob::slotCreateNewTodo(KJob *job)
93 {
94  if ( job->error() ) {
95  qDebug() << "Error during create new Todo "<<job->errorString();
96  }
97  Q_EMIT emitResult();
98 }
MessageViewer::CreateTodoJob::~CreateTodoJob
~CreateTodoJob()
Definition: createtodojob.cpp:38
MessageViewer::CreateTodoJob::start
void start()
Definition: createtodojob.cpp:43
QObject
MessageViewer::CreateTodoJob::CreateTodoJob
CreateTodoJob(const KCalCore::Todo::Ptr &todoPtr, const Akonadi::Collection &collection, const Akonadi::Item &item, QObject *parent=0)
Definition: createtodojob.cpp:30
createtodojob.h
KJob
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:32:45 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

messageviewer

Skip menu "messageviewer"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer
  • pimprint

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal