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

akonadi

  • sources
  • kde-4.12
  • kdepimlibs
  • akonadi
  • kmime
markascommand.cpp
1 /*
2  Copyright (c) 2010 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com
3  Copyright (c) 2010 Andras Mantia <andras@kdab.com>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19 
20 #include "markascommand_p.h"
21 #include "util_p.h"
22 #include <akonadi/itemfetchjob.h>
23 #include <akonadi/itemfetchscope.h>
24 #include <akonadi/itemmodifyjob.h>
25 
26 MarkAsCommand::MarkAsCommand( const Akonadi::MessageStatus& targetStatus, const Akonadi::Item::List& msgList, bool invert, QObject* parent): CommandBase( parent )
27 {
28  mInvertMark = invert;
29  mMessages = msgList;
30  mTargetStatus = targetStatus;
31  mFolderListJobCount = 0;
32 }
33 
34 MarkAsCommand::MarkAsCommand(const Akonadi::MessageStatus &targetStatus, const Akonadi::Collection::List& folders, bool invert, QObject* parent): CommandBase( parent )
35 {
36  mInvertMark = invert;
37  mFolders = folders;
38  mTargetStatus = targetStatus;
39  mFolderListJobCount = mFolders.size();
40 }
41 
42 void MarkAsCommand::slotFetchDone(KJob* job)
43 {
44  mFolderListJobCount--;
45 
46  if ( job->error() ) {
47  // handle errors
48  Util::showJobError(job);
49  emitResult( Failed );
50  return;
51  }
52 
53  Akonadi::ItemFetchJob *fjob = static_cast<Akonadi::ItemFetchJob*>( job );
54  mMessages.clear();
55  foreach( const Akonadi::Item &item, fjob->items() ) {
56  Akonadi::MessageStatus status;
57  status.setStatusFromFlags( item.flags() );
58  if ( mInvertMark ) {
59  if ( status & mTargetStatus ) {
60  mMessages.append( item );
61  }
62  } else
63  if ( !( status & mTargetStatus ) ) {
64  mMessages.append( item );
65  }
66  }
67  if ( mMessages.empty() ) {
68  if ( mFolderListJobCount == 0 ) {
69  emitResult( OK );
70  return;
71  }
72  } else {
73  markMessages();
74  }
75  if ( mFolderListJobCount > 0 ) {
76  Akonadi::ItemFetchJob *job = new Akonadi::ItemFetchJob( mFolders[mFolderListJobCount - 1], parent() );
77  job->fetchScope().setAncestorRetrieval( Akonadi::ItemFetchScope::Parent );
78  connect( job, SIGNAL(result(KJob*)), this, SLOT(slotFetchDone(KJob*)) );
79  }
80 }
81 
82 void MarkAsCommand::execute()
83 {
84  if ( !mFolders.isEmpty() ) {
85  //yes, we go backwards, shouldn't matter
86  Akonadi::ItemFetchJob *job = new Akonadi::ItemFetchJob( mFolders[mFolderListJobCount - 1], parent() );
87  job->fetchScope().setAncestorRetrieval( Akonadi::ItemFetchScope::Parent );
88  connect( job, SIGNAL(result(KJob*)), this, SLOT(slotFetchDone(KJob*)) );
89  } else if ( !mMessages.isEmpty() ) {
90  mFolders << mMessages.first().parentCollection();
91  markMessages();
92  } else {
93  emitResult( OK );
94  }
95 }
96 
97 void MarkAsCommand::markMessages()
98 {
99  mMarkJobCount = 0;
100 
101  QSet<QByteArray> flags = mTargetStatus.statusFlags();
102  Q_ASSERT( flags.size() == 1 );
103  Akonadi::Item::Flag flag;
104  if ( !flags.isEmpty() )
105  flag = *( flags.begin() );
106 
107  Akonadi::Item::List itemsToModify;
108  foreach( const Akonadi::Item &it, mMessages ) {
109  Akonadi::Item item( it );
110 
111  // be careful to only change the flags we want to change, not to overwrite them
112  // otherwise ItemModifyJob will not do what we expect
113  if ( mInvertMark ) {
114  if ( item.hasFlag( flag ) ) {
115  item.clearFlag( flag );
116  itemsToModify.push_back( item );
117  }
118  } else {
119  if ( !item.hasFlag( flag ) ) {
120  item.setFlag( flag );
121  itemsToModify.push_back( item );
122  }
123  }
124  }
125 
126  mMarkJobCount++;
127  if ( itemsToModify.isEmpty() ) {
128  slotModifyItemDone( 0 ); // pretend we did something
129  } else {
130  Akonadi::ItemModifyJob *modifyJob = new Akonadi::ItemModifyJob( itemsToModify, this );
131  modifyJob->setIgnorePayload( true );
132  modifyJob->disableRevisionCheck();
133  connect( modifyJob, SIGNAL(result(KJob*)), this, SLOT(slotModifyItemDone(KJob*)) );
134  }
135 }
136 
137 void MarkAsCommand::slotModifyItemDone( KJob * job )
138 {
139  mMarkJobCount--;
140  //NOTE(Andras): from kmail/kmmcommands, KMSetStatusCommand
141  if ( job && job->error() ) {
142  kDebug()<<" Error trying to set item status:" << job->errorText();
143  emitResult( Failed );
144  }
145  if ( mMarkJobCount == 0 && mFolderListJobCount == 0 ) {
146  emitResult( OK );
147  }
148 }
149 
150 #include "moc_markascommand_p.cpp"
Akonadi::ItemModifyJob::disableRevisionCheck
void disableRevisionCheck()
Disables the check of the revision number.
Definition: itemmodifyjob.cpp:374
Akonadi::ItemFetchJob::items
Item::List items() const
Returns the fetched items.
Definition: itemfetchjob.cpp:228
Akonadi::ItemFetchJob::fetchScope
ItemFetchScope & fetchScope()
Returns the item fetch scope.
Definition: itemfetchjob.cpp:256
Akonadi::MessageStatus::setStatusFromFlags
void setStatusFromFlags(const QSet< QByteArray > &flags)
Set the status as a whole e.g.
Definition: messagestatus.cpp:619
Akonadi::ItemFetchScope::Parent
Only retrieve the immediate parent collection.
Definition: itemfetchscope.h:77
Akonadi::ItemFetchScope::setAncestorRetrieval
void setAncestorRetrieval(AncestorRetrieval ancestorDepth)
Sets how many levels of ancestor collections should be included in the retrieval. ...
Definition: itemfetchscope.cpp:128
Akonadi::ItemModifyJob::setIgnorePayload
void setIgnorePayload(bool ignore)
Sets whether the payload of the modified item shall be omitted from transmission to the Akonadi stora...
Definition: itemmodifyjob.cpp:335
Akonadi::ItemModifyJob
Job that modifies an existing item in the Akonadi storage.
Definition: itemmodifyjob.h:97
Akonadi::ItemFetchJob
Job that fetches items from the Akonadi storage.
Definition: itemfetchjob.h:82
Akonadi::MessageStatus
Akonadi KMime Message Status.
Definition: messagestatus.h:51
Akonadi::Collection::List
QList< Collection > List
Describes a list of collections.
Definition: collection.h:81
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:00:27 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akonadi

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

kdepimlibs API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kldap
  • kmbox
  • kmime
  • kpimidentities
  • kpimtextedit
  • kresources
  • ktnef
  • kxmlrpcclient
  • microblog

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