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

kmailtransport

  • kde-4.x
  • pim
  • kmailtransport
  • src
  • kmailtransportakonadi
filteractionjob.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2009 Constantin Berzan <[email protected]>
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 #include "filteractionjob_p.h"
21 
22 #include <collection.h>
23 #include <itemfetchjob.h>
24 #include <itemfetchscope.h>
25 
26 #include "mailtransportakonadi_debug.h"
27 
28 using namespace Akonadi;
29 
30 class Q_DECL_HIDDEN Akonadi::FilterActionJob::Private
31 {
32 public:
33  Private(FilterActionJob *qq)
34  : q(qq)
35  , functor(nullptr)
36  {
37  }
38 
39  ~Private()
40  {
41  delete functor;
42  }
43 
44  FilterActionJob *q;
45  Collection collection;
46  Item::List items;
47  FilterAction *functor = nullptr;
48  ItemFetchScope fetchScope;
49 
50  // Q_SLOTS:
51  void fetchResult(KJob *job);
52 
53  void traverseItems();
54 };
55 
56 void FilterActionJob::Private::fetchResult(KJob *job)
57 {
58  if (job->error()) {
59  // KCompositeJob takes care of errors.
60  return;
61  }
62 
63  ItemFetchJob *fjob = dynamic_cast<ItemFetchJob *>(job);
64  Q_ASSERT(fjob);
65  Q_ASSERT(items.isEmpty());
66  items = fjob->items();
67  traverseItems();
68 }
69 
70 void FilterActionJob::Private::traverseItems()
71 {
72  Q_ASSERT(functor);
73  qCDebug(MAILTRANSPORTAKONADI_LOG) << "Traversing" << items.count() << "items.";
74  for (const Item &item : qAsConst(items)) {
75  if (functor->itemAccepted(item)) {
76  functor->itemAction(item, q);
77  qCDebug(MAILTRANSPORTAKONADI_LOG) << "Added subjob for item" << item.id();
78  }
79  }
80  if (q->subjobs().isEmpty()) {
81  qCDebug(MAILTRANSPORTAKONADI_LOG) << "No subjobs; I am done";
82  } else {
83  qCDebug(MAILTRANSPORTAKONADI_LOG) << "Have subjobs; Done when last of them is";
84  }
85  q->commit();
86 }
87 
88 FilterAction::~FilterAction()
89 {
90 }
91 
92 FilterActionJob::FilterActionJob(const Item &item, FilterAction *functor, QObject *parent)
93  : TransactionSequence(parent)
94  , d(new Private(this))
95 {
96  d->functor = functor;
97  d->items << item;
98 }
99 
100 FilterActionJob::FilterActionJob(const Item::List &items, FilterAction *functor, QObject *parent)
101  : TransactionSequence(parent)
102  , d(new Private(this))
103 {
104  d->functor = functor;
105  d->items = items;
106 }
107 
108 FilterActionJob::FilterActionJob(const Collection &collection, FilterAction *functor, QObject *parent)
109  : TransactionSequence(parent)
110  , d(new Private(this))
111 {
112  d->functor = functor;
113  Q_ASSERT(collection.isValid());
114  d->collection = collection;
115 }
116 
117 FilterActionJob::~FilterActionJob()
118 {
119  delete d;
120 }
121 
122 void FilterActionJob::doStart()
123 {
124  if (d->collection.isValid()) {
125  qCDebug(MAILTRANSPORTAKONADI_LOG) << "Fetching collection" << d->collection.id();
126  ItemFetchJob *fjob = new ItemFetchJob(d->collection, this);
127  Q_ASSERT(d->functor);
128  d->fetchScope = d->functor->fetchScope();
129  fjob->setFetchScope(d->fetchScope);
130  connect(fjob, &ItemFetchJob::result, this, [this](KJob *job) {
131  d->fetchResult(job);
132  });
133  } else {
134  d->traverseItems();
135  }
136 }
137 
138 #include "moc_filteractionjob_p.cpp"
Akonadi::FilterActionJob::FilterActionJob
FilterActionJob(const Item &item, FilterAction *functor, QObject *parent=nullptr)
Creates a filter action job to act on a single item.
QObject
Akonadi::FilterActionJob::~FilterActionJob
~FilterActionJob() override
Destroys the filter action job.
Definition: filteractionjob.cpp:117
TransactionSequence
filteractionjob_p.h
Akonadi::FilterAction::~FilterAction
virtual ~FilterAction()
Destroys this filter action.
Definition: filteractionjob.cpp:88
Akonadi::FilterAction
Base class for a filter/action for FilterActionJob.
Definition: filteractionjob_p.h:74
Akonadi::FilterActionJob::doStart
void doStart() override
Definition: filteractionjob.cpp:122
KJob
This file is part of the KDE documentation.
Documentation copyright © 1996-2019 The KDE developers.
Generated on Thu Dec 5 2019 03:54:32 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kmailtransport

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

pim API Reference

Skip menu "pim API Reference"
  • akonadi-calendar-tools
  •   konsolekalendar
  • akregator
  •   src
  • kalarmcal
  •   src
  •     lib
  • kdepim-runtime
  •   agents
  •   src
  • kleopatra
  •   src
  • kmailtransport
  • knotes
  • kontact
  • kontactinterface
  • kpimtextedit
  • ksmtp
  • ktnef
  • libkgapi
  • libkleo
  •   src
  •     src
  •     src

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