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

mailtransport

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

KDE's Doxygen guidelines are available online.

mailtransport

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

kdepimlibs-4.14.10 API Reference

Skip menu "kdepimlibs-4.14.10 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
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