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

kmail

  • sources
  • kde-4.14
  • kdepim
  • kmail
  • job
createtaskjob.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2014-2015 Montel Laurent <montel@kde.org>
3 
4  This library is free software; you can redistribute it and/or modify it
5  under the terms of the GNU Library General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or (at your
7  option) any later version.
8 
9  This library is distributed in the hope that it will be useful, but WITHOUT
10  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12  License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to the
16  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  02110-1301, USA.
18 
19 */
20 
21 
22 #include "createtaskjob.h"
23 #include "attributes/taskattribute.h"
24 #include <akonadi/kmime/messagestatus.h>
25 #include <KLocalizedString>
26 
27 #include <Akonadi/ItemFetchJob>
28 #include <Akonadi/ItemFetchScope>
29 #include <Akonadi/ItemModifyJob>
30 
31 #include <QDebug>
32 
33 CreateTaskJob::CreateTaskJob(const Akonadi::Item::List &items, QObject *parent)
34  : KJob(parent),
35  mListItem(items)
36 {
37 }
38 
39 CreateTaskJob::~CreateTaskJob()
40 {
41 
42 }
43 
44 void CreateTaskJob::start()
45 {
46  if (mListItem.isEmpty()) {
47  Q_EMIT emitResult();
48  return;
49  }
50  fetchItems();
51 }
52 
53 void CreateTaskJob::fetchItems()
54 {
55  Akonadi::ItemFetchJob *job = new Akonadi::ItemFetchJob( mListItem, this );
56  job->fetchScope().fetchFullPayload( true );
57  job->fetchScope().setAncestorRetrieval( Akonadi::ItemFetchScope::Parent );
58  job->fetchScope().fetchAttribute<TaskAttribute>();
59  connect( job, SIGNAL(result(KJob*)), SLOT(itemFetchJobDone(KJob*)) );
60 }
61 
62 void CreateTaskJob::itemFetchJobDone(KJob *job)
63 {
64  if (job->error()) {
65  qDebug() << job->errorString();
66  Q_EMIT emitResult();
67  return;
68  }
69  Akonadi::ItemFetchJob *fetchjob = qobject_cast<Akonadi::ItemFetchJob *>(job);
70  const Akonadi::Item::List lst = fetchjob->items();
71  if (lst.isEmpty()) {
72  Q_EMIT emitResult();
73  return;
74  }
75 
76  bool parentStatus = false;
77  // Toggle actions on threads toggle the whole thread
78  // depending on the state of the parent.
79  const Akonadi::Item first = lst.at(0);
80  Akonadi::MessageStatus pStatus;
81  pStatus.setStatusFromFlags( first.flags() );
82  if ( pStatus & Akonadi::MessageStatus::statusToAct() )
83  parentStatus = true;
84  else
85  parentStatus = false;
86 
87  Akonadi::Item::List itemsToModify;
88  foreach( const Akonadi::Item &it, lst ) {
89  //kDebug()<<" item ::"<<tmpItem;
90  if ( it.isValid() ) {
91  bool myStatus;
92  Akonadi::MessageStatus itemStatus;
93  itemStatus.setStatusFromFlags( it.flags() );
94  if ( itemStatus & Akonadi::MessageStatus::statusToAct() )
95  myStatus = true;
96  else
97  myStatus = false;
98  if ( myStatus != parentStatus )
99  continue;
100  }
101  Akonadi::Item item( it );
102  const Akonadi::Item::Flag flag = *(Akonadi::MessageStatus::statusToAct().statusFlags().begin());
103  if ( item.hasFlag( flag ) ) {
104  item.clearFlag( flag );
105  itemsToModify.push_back( item );
106  if (item.hasAttribute<TaskAttribute>()) {
107  //Change todo as done.
108  item.removeAttribute<TaskAttribute>();
109  }
110  } else {
111  item.setFlag( flag );
112  itemsToModify.push_back( item );
113  //TODO add TaskAttribute();
114  }
115  }
116 
117  if ( itemsToModify.isEmpty() ) {
118  slotModifyItemDone( 0 );
119  } else {
120  Akonadi::ItemModifyJob *modifyJob = new Akonadi::ItemModifyJob( itemsToModify, this );
121  modifyJob->disableRevisionCheck();
122  modifyJob->setIgnorePayload( true );
123  connect( modifyJob, SIGNAL(result(KJob*)), this, SLOT(slotModifyItemDone(KJob*)) );
124  }
125 }
126 
127 void CreateTaskJob::slotModifyItemDone(KJob *job)
128 {
129  //TODO
130  if (job && job->error()) {
131  qDebug()<<" error "<<job->errorString();
132  }
133  deleteLater();
134 }
CreateTaskJob::CreateTaskJob
CreateTaskJob(const Akonadi::Item::List &items, QObject *parent=0)
Definition: createtaskjob.cpp:33
taskattribute.h
createtaskjob.h
QObject
CreateTaskJob::start
void start()
Definition: createtaskjob.cpp:44
CreateTaskJob::~CreateTaskJob
~CreateTaskJob()
Definition: createtaskjob.cpp:39
TaskAttribute
Definition: taskattribute.h:25
KJob
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:34:32 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kmail

Skip menu "kmail"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

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