[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kdepimlibs/akregator_port] krss: make itemlistjobs killable, to abort item listings when the user s
From:       Frank Osterfeld <frank.osterfeld () kdemail ! net>
Date:       2012-03-31 15:16:21
Message-ID: 20120331151621.DF611A60DD () git ! kde ! org
[Download RAW message or body]

Git commit b326a9356757aaf2cb6a347f0a7369f5f6d22b48 by Frank Osterfeld.
Committed on 04/10/2009 at 12:30.
Pushed by osterfeld into branch 'akregator_port'.

make itemlistjobs killable, to abort item listings when the user switches to another \
feed while the listing is going on. Unfortunately ItemFetchJobs are not killable, so \
for now simply delete the job.

svn path=/branches/work/akonadi-ports/kdepim/; revision=1031190

M  +7    -2    krss/feed.cpp
M  +6    -2    krss/feed_p.h
M  +13   -2    krss/itemlistjob.cpp
M  +4    -0    krss/itemlistjob.h

http://commits.kde.org/kdepimlibs/b326a9356757aaf2cb6a347f0a7369f5f6d22b48

diff --git a/krss/feed.cpp b/krss/feed.cpp
index a9654ae..0b10ed3 100644
--- a/krss/feed.cpp
+++ b/krss/feed.cpp
@@ -301,13 +301,18 @@ void ItemListJobImpl::doStart() {
     Akonadi::ItemFetchJob *job = new Akonadi::ItemFetchJob( \
m_feed->d->m_feedCollection, this );  if ( !m_fetchScope.isEmpty() )
         job->setFetchScope( m_fetchScope );
-    connect( job, SIGNAL( itemsReceived( const Akonadi::Item::List& ) ),
-             this, SLOT( slotItemsReceived( const Akonadi::Item::List& ) ) );
+    connect( job, SIGNAL(itemsReceived(Akonadi::Item::List)),
+             this, SLOT(slotItemsReceived(Akonadi::Item::List)) );
     connect(job, SIGNAL(finished(KJob*)), this, SLOT(jobDone(KJob*)) );
     m_job = job;
     job->start();
 }
 
+bool ItemListJobImpl::doKill() {
+     delete m_job;
+    return true;
+}
+
 StatusModifyJobImpl::StatusModifyJobImpl( Feed *parent )
     : StatusModifyJob( parent ), m_feed( parent ), m_jobs( 0 ), m_totalJobs( 0 )
 {
diff --git a/krss/feed_p.h b/krss/feed_p.h
index 89b7710..decc300 100644
--- a/krss/feed_p.h
+++ b/krss/feed_p.h
@@ -24,10 +24,12 @@
 #include "feedcollection.h"
 
 #include <Akonadi/Item>
-#include <akonadi/itemfetchscope.h>
+#include <Akonadi/ItemFetchJob>
+#include <Akonadi/ItemFetchScope>
 
 #include <QtGui/QIcon>
 #include <QtCore/QList>
+#include <QtCore/QPointer>
 
 namespace Akonadi {
     class ItemFetchJob;
@@ -81,6 +83,8 @@ public:
     /* reimp */  QList<KRss::Item> items() const { return m_items; }
 
     /* reimp */ void start();
+protected:
+    /* reimp */ bool doKill();
 
 private Q_SLOTS:
     void doStart();
@@ -89,7 +93,7 @@ private Q_SLOTS:
 
 private:
     const Feed* m_feed;
-    Akonadi::ItemFetchJob* m_job;
+    QPointer<Akonadi::ItemFetchJob> m_job;
     QList<KRss::Item> m_items;
     Akonadi::ItemFetchScope m_fetchScope;
 };
diff --git a/krss/itemlistjob.cpp b/krss/itemlistjob.cpp
index 8ccc091..ca96886 100644
--- a/krss/itemlistjob.cpp
+++ b/krss/itemlistjob.cpp
@@ -21,6 +21,7 @@
 #include <akonadi/itemfetchscope.h>
 #include <KDebug>
 #include <QHash>
+#include <QPointer>
 
 #include <boost/bind.hpp>
 
@@ -31,7 +32,9 @@
 using namespace boost;
 using namespace KRss;
 
-ItemListJob::ItemListJob( QObject* parent ) : KJob( parent ) {}
+ItemListJob::ItemListJob( QObject* parent ) : KJob( parent ) {
+    setCapabilities( capabilities() | KJob::Killable );
+}
 
 ItemListJob::~ItemListJob() {
 }
@@ -41,7 +44,7 @@ class CompositeItemListJob::Private {
 public:
 
     explicit Private( CompositeItemListJob* qq ) : q( qq ), haveFilter( false ) {}
-    QList<ItemListJob*> jobs;
+    QList<QPointer<ItemListJob> > jobs;
     QList<KRss::Item> items;
     Akonadi::ItemFetchScope scope;
     QHash<KJob*,unsigned long> percentages;
@@ -147,6 +150,14 @@ void CompositeItemListJob::Private::doStart() {
         i->start();
 }
 
+bool CompositeItemListJob::doKill() {
+    Q_FOREACH( const QPointer<ItemListJob>& i, d->jobs )
+        if ( i )
+            i->kill();
+    return true;
+}
+
+
 void CompositeItemListJob::Private::jobDone( KJob* j ) {
     ItemListJob* job = qobject_cast<ItemListJob*>( j );
     assert( job && jobs.contains( job ) );
diff --git a/krss/itemlistjob.h b/krss/itemlistjob.h
index 2b1d8cf..c4914c8 100644
--- a/krss/itemlistjob.h
+++ b/krss/itemlistjob.h
@@ -45,6 +45,8 @@ namespace KRss {
         virtual Akonadi::ItemFetchScope &fetchScope() = 0;
 
         virtual QList<KRss::Item> items() const = 0;
+    protected:
+        /* reimp */ bool doKill() = 0;
     };
 
     class KRSS_EXPORT CompositeItemListJob : public ItemListJob {
@@ -67,6 +69,8 @@ namespace KRss {
 
         void setFilter( const boost::function1<bool, const Item&>& filter );
         void clearFilter();
+    protected:
+        /* reimp */ bool doKill();
 
     private:
         class Private;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic