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

mailtransport

filteractionjob.cpp
00001 /*
00002     Copyright (c) 2009 Constantin Berzan <exit3219@gmail.com>
00003 
00004     This library is free software; you can redistribute it and/or modify it
00005     under the terms of the GNU Library General Public License as published by
00006     the Free Software Foundation; either version 2 of the License, or (at your
00007     option) any later version.
00008 
00009     This library is distributed in the hope that it will be useful, but WITHOUT
00010     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00011     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00012     License for more details.
00013 
00014     You should have received a copy of the GNU Library General Public License
00015     along with this library; see the file COPYING.LIB.  If not, write to the
00016     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017     02110-1301, USA.
00018 */
00019 
00020 #include "filteractionjob_p.h"
00021 
00022 #include <akonadi/collection.h>
00023 #include <akonadi/itemfetchjob.h>
00024 #include <akonadi/itemfetchscope.h>
00025 
00026 #include <KDebug>
00027 
00028 using namespace Akonadi;
00029 
00030 class Akonadi::FilterActionJob::Private
00031 {
00032   public:
00033     Private( FilterActionJob *qq )
00034       : q( qq ), functor( 0 )
00035     {
00036     }
00037 
00038     ~Private()
00039     {
00040       delete functor;
00041     }
00042 
00043     FilterActionJob *q;
00044     Collection collection;
00045     Item::List items;
00046     FilterAction *functor;
00047     ItemFetchScope fetchScope;
00048 
00049     // slots:
00050     void fetchResult( KJob *job );
00051 
00052     void traverseItems();
00053 };
00054 
00055 void FilterActionJob::Private::fetchResult( KJob *job )
00056 {
00057   if ( job->error() ) {
00058     // KCompositeJob takes care of errors.
00059     return;
00060   }
00061 
00062   ItemFetchJob *fjob = dynamic_cast<ItemFetchJob*>( job );
00063   Q_ASSERT( fjob );
00064   Q_ASSERT( items.isEmpty() );
00065   items = fjob->items();
00066   traverseItems();
00067 }
00068 
00069 void FilterActionJob::Private::traverseItems()
00070 {
00071   Q_ASSERT( functor );
00072   kDebug() << "Traversing" << items.count() << "items.";
00073   foreach ( const Item &item, items ) {
00074     if ( functor->itemAccepted( item ) ) {
00075       functor->itemAction( item, q );
00076       kDebug() << "Added subjob for item" << item.id();
00077     }
00078   }
00079   if ( q->subjobs().isEmpty() ) {
00080     kDebug() << "No subjobs; I am done";
00081   } else {
00082     kDebug() << "Have subjobs; Done when last of them is";
00083   }
00084   q->commit();
00085 }
00086 
00087 FilterAction::~FilterAction()
00088 {
00089 }
00090 
00091 FilterActionJob::FilterActionJob( const Item &item, FilterAction *functor, QObject *parent )
00092   : TransactionSequence( parent ), d( new Private( this ) )
00093 {
00094   d->functor = functor;
00095   d->items << item;
00096 }
00097 
00098 FilterActionJob::FilterActionJob( const Item::List &items, FilterAction *functor, QObject *parent )
00099   : TransactionSequence( parent ), d( new Private( this ) )
00100 {
00101   d->functor = functor;
00102   d->items = items;
00103 }
00104 
00105 FilterActionJob::FilterActionJob( const Collection &collection,
00106                                   FilterAction *functor, QObject *parent )
00107   : TransactionSequence( parent ), d( new Private( this ) )
00108 {
00109   d->functor = functor;
00110   Q_ASSERT( collection.isValid() );
00111   d->collection = collection;
00112 }
00113 
00114 FilterActionJob::~FilterActionJob()
00115 {
00116   delete d;
00117 }
00118 
00119 void FilterActionJob::doStart()
00120 {
00121   if( d->collection.isValid() ) {
00122     kDebug() << "Fetching collection" << d->collection.id();
00123     ItemFetchJob *fjob = new ItemFetchJob( d->collection, this );
00124     Q_ASSERT( d->functor );
00125     d->fetchScope = d->functor->fetchScope();
00126     fjob->setFetchScope( d->fetchScope );
00127     connect( fjob, SIGNAL(result(KJob*)), this, SLOT(fetchResult(KJob*)) );
00128   } else {
00129     d->traverseItems();
00130   }
00131 }
00132 
00133 #include "filteractionjob_p.moc"
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon May 7 2012 23:58:59 by doxygen 1.8.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.8.3 API Reference

Skip menu "kdepimlibs-4.8.3 API Reference"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • 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