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

List:       kde-commits
Subject:    [kdepim/akregator_port] akregator2/src: Implement canceling feed fetching/syncing
From:       Frank Osterfeld <osterfeld () kde ! org>
Date:       2013-03-02 15:20:44
Message-ID: 20130302152044.5CDDEA60C6 () git ! kde ! org
[Download RAW message or body]

Git commit 8598bb88da2def537c010f35caa926e945c4616a by Frank Osterfeld.
Committed on 02/03/2013 at 16:19.
Pushed by osterfeld into branch 'akregator_port'.

Implement canceling feed fetching/syncing

M  +0    -1    akregator2/src/CMakeLists.txt
M  +16   -0    akregator2/src/actionmanagerimpl.cpp
M  +3    -0    akregator2/src/actionmanagerimpl.h
M  +2    -15   akregator2/src/mainwidget.cpp
D  +0    -275  akregator2/src/progressmanager.cpp
D  +0    -112  akregator2/src/progressmanager.h

http://commits.kde.org/kdepim/8598bb88da2def537c010f35caa926e945c4616a

diff --git a/akregator2/src/CMakeLists.txt b/akregator2/src/CMakeLists.txt
index 33d227a..f23b71c 100644
--- a/akregator2/src/CMakeLists.txt
+++ b/akregator2/src/CMakeLists.txt
@@ -83,7 +83,6 @@ set(akregator2part_PART_SRCS
    importfeedlistcommand.cpp
 #   importitemsjob.cpp
    tabwidget.cpp
-   #   progressmanager.cpp
    modifycommands.cpp
    akregator2_part.cpp
    mainwidget.cpp
diff --git a/akregator2/src/actionmanagerimpl.cpp b/akregator2/src/actionmanagerimpl.cpp
index eccd19e..e20a7d4 100644
--- a/akregator2/src/actionmanagerimpl.cpp
+++ b/akregator2/src/actionmanagerimpl.cpp
@@ -56,6 +56,8 @@
 #include <QWidget>
 #include <QApplication>
 
+#include <libkdepim/progressmanager.h>
+
 #include <boost/shared_ptr.hpp>
 
 using namespace boost;
@@ -136,6 +138,13 @@ ActionManagerImpl::ActionManagerImpl(Part* part, QObject* parent ) : ActionManag
     d->speakSelectedArticlesAction = 0;
     d->actionCollection = part->actionCollection();
     initPart();
+
+    connect( KPIM::ProgressManager::instance(), SIGNAL(progressItemAdded(KPIM::ProgressItem*)),
+             this, SLOT(progressItemsChanged()), Qt::QueuedConnection );
+    connect( KPIM::ProgressManager::instance(), SIGNAL(progressItemCanceled(KPIM::ProgressItem*)),
+             this, SLOT(progressItemsChanged()), Qt::QueuedConnection );
+    connect( KPIM::ProgressManager::instance(), SIGNAL(progressItemCompleted(KPIM::ProgressItem*)),
+             this, SLOT(progressItemsChanged()), Qt::QueuedConnection );
 }
 
 ActionManagerImpl::~ActionManagerImpl()
@@ -163,6 +172,13 @@ void ActionManagerImpl::setTrayIcon(TrayIcon* trayIcon)
         traypop->addAction(actionCollection()->action("options_configure"));
 }
 
+void ActionManagerImpl::progressItemsChanged()
+{
+    if ( QAction* stopAction = action("feed_stop") ) {
+        const bool canCancel = !KPIM::ProgressManager::instance()->isEmpty();
+        stopAction->setEnabled( canCancel );
+    }
+}
 
 void ActionManagerImpl::initPart()
 {
diff --git a/akregator2/src/actionmanagerimpl.h b/akregator2/src/actionmanagerimpl.h
index 64208e2..63b21ad 100644
--- a/akregator2/src/actionmanagerimpl.h
+++ b/akregator2/src/actionmanagerimpl.h
@@ -86,6 +86,9 @@ class ActionManagerImpl : public ActionManager
 
         KActionCollection* actionCollection();
 
+    private Q_SLOTS:
+        void progressItemsChanged();
+
     private:
 
         void initPart();
diff --git a/akregator2/src/mainwidget.cpp b/akregator2/src/mainwidget.cpp
index 84c22b8..b0d57e6 100644
--- a/akregator2/src/mainwidget.cpp
+++ b/akregator2/src/mainwidget.cpp
@@ -43,9 +43,7 @@
 #include "framemanager.h"
 #include "kernel.h"
 #include "openurlrequest.h"
-#ifdef WITH_LIBKDEPIM
-#include "progressmanager.h"
-#endif
+#include <libkdepim/progressmanager.h>
 
 #include "searchbar.h"
 #include "selectioncontroller.h"
@@ -106,10 +104,6 @@ public:
     explicit Private( MainWidget* qq ) : q( qq ) {}
     void setUpAndStart( Command* cmd ) {
         cmd->setParentWidget( q );
-#ifdef WITH_LIBKDEPIM	
-        if ( cmd->isUserVisible() )
-            KPIM::ProgressManager::self()->addJob( cmd );
-#endif
         cmd->start();
     }
 };
@@ -522,9 +516,7 @@ void Akregator2::MainWidget::slotCombinedView()
     if (m_viewMode == CombinedView)
         return;
 
-#ifdef KRSS_PORT_DISABLED
     m_articleListView->slotClear();
-#endif
     m_articleListView->hide();
     m_viewMode = CombinedView;
 
@@ -720,12 +712,7 @@ void Akregator2::MainWidget::slotFetchAllFeeds()
 }
 
 void Akregator2::MainWidget::slotAbortFetches() {
-#ifdef KRSS_PORT_DISABLED
-    if ( !m_feedList )
-        return;
-    Q_FOREACH( const shared_ptr<const KRss::Feed>& feed, m_feedList->constFeeds() )
-        feed->abortFetch();
-#endif
+    KPIM::ProgressManager::instance()->slotAbortAll();
 }
 
 void Akregator2::MainWidget::slotFetchQueueStarted()
diff --git a/akregator2/src/progressmanager.cpp b/akregator2/src/progressmanager.cpp
deleted file mode 100644
index 2593554..0000000
--- a/akregator2/src/progressmanager.cpp
+++ /dev/null
@@ -1,275 +0,0 @@
-/*
-    This file is part of Akregator2.
-
-    Copyright (C) 2005 Frank Osterfeld <osterfeld@kde.org>
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-
-    As a special exception, permission is given to link this program
-    with any edition of Qt, and distribute the resulting executable,
-    without including the source code for Qt in the source distribution.
-*/
-
-#include "progressmanager.h"
-
-#include <krss/feedlist.h>
-
-#include <QHash>
-#include <QList>
-
-#include <KLocale>
-#include <KGlobal>
-#include <libkdepim/progressmanager.h>
-
-#include <boost/shared_ptr.hpp>
-
-using namespace boost;
-
-namespace Akregator2 {
-
-class ProgressManagerPrivate
-{
-    public:
-        shared_ptr<KRss::FeedList> feedList;
-        QHash<KRss::Feed::Id, FetchProgressItemHandler*> handlers;
-        ProgressManager instance;
-};
-
-K_GLOBAL_STATIC( ProgressManagerPrivate, d )
-
-ProgressManager* ProgressManager::self()
-{
-    return &d->instance;
-}
-
-ProgressManager::ProgressManager()
-{
-}
-
-ProgressManager::~ProgressManager()
-{
-}
-
-void ProgressManager::setFeedList( const shared_ptr<KRss::FeedList>& feedList )
-{
-    if ( feedList == d->feedList )
-        return;
-
-    if ( d->feedList ) {
-        qDeleteAll( d->handlers );
-        d->handlers.clear();
-        d->feedList.get()->disconnect( this );
-    }
-
-    d->feedList = feedList;
-
-    if ( d->feedList ) {
-        Q_FOREACH( const KRss::Feed::Id& id, d->feedList->feedIds() )
-            slotFeedAdded( id );
-
-        connect( feedList.get(), SIGNAL(feedAdded(KRss::Feed::Id)),
-                 this, SLOT(slotFeedAdded(KRss::Feed::Id)) );
-        connect( feedList.get(), SIGNAL(feedRemoved(KRss::Feed::Id)),
-                 this, SLOT(slotFeedRemoved(KRss::Feed::Id)) );    }
-}
-
-void ProgressManager::addJob( KJob *job )
-{
-    // deletes itself
-    new JobProgressItemHandler( job );
-}
-
-void ProgressManager::slotFeedAdded( const KRss::Feed::Id& id )
-{
-    if ( d->handlers.contains( id ) )
-        return;
-
-    const shared_ptr<const KRss::Feed> feed = d->feedList->constFeedById( id );
-    assert( feed );
-
-    d->handlers.insert( id, new FetchProgressItemHandler( feed ) );
-}
-
-void ProgressManager::slotFeedRemoved( const KRss::Feed::Id& id )
-{
-    delete d->handlers.take( id );
-}
-
-class FetchProgressItemHandler::FetchProgressItemHandlerPrivate
-{
-    public:
-        explicit FetchProgressItemHandlerPrivate( const shared_ptr<const KRss::Feed>& feed_ )
-            : feed( feed_ ), progressItem( 0 ) {}
-        const shared_ptr<const KRss::Feed> feed;
-        KPIM::ProgressItem* progressItem;
-};
-
-FetchProgressItemHandler::FetchProgressItemHandler( const shared_ptr<const KRss::Feed>& feed )
-    : d( new FetchProgressItemHandlerPrivate( feed ) )
-{
-    connect( feed.get(), SIGNAL(fetchStarted(KRss::Feed::Id)),
-             this, SLOT(slotFetchStarted(KRss::Feed::Id)) );
-    connect( feed.get(), SIGNAL(fetchPercent(KRss::Feed::Id,uint)),
-             this, SLOT(slotFetchPercent(KRss::Feed::Id,uint)) );
-    connect( feed.get(), SIGNAL(fetchFinished(KRss::Feed::Id)),
-             this, SLOT(slotFetchFinished(KRss::Feed::Id)) );
-    connect( feed.get(), SIGNAL(fetchFailed(KRss::Feed::Id,QString)),
-             this, SLOT(slotFetchFailed(KRss::Feed::Id,QString)) );
-    connect( feed.get(), SIGNAL(fetchAborted(KRss::Feed::Id)),
-             this, SLOT(slotFetchAborted(KRss::Feed::Id)) );
-}
-
-FetchProgressItemHandler::~FetchProgressItemHandler()
-{
-    if ( d->progressItem ) {
-        d->progressItem->setComplete();
-        d->progressItem = 0;
-    }
-
-    delete d;
-    d = 0;
-}
-
-void FetchProgressItemHandler::slotFetchStarted( const KRss::Feed::Id& id )
-{
-    Q_UNUSED( id )
-    if ( d->progressItem ) {
-        d->progressItem->setStatus( i18n( "Fetching" ) );
-        d->progressItem->setComplete();
-        d->progressItem = 0;
-    }
-
-    d->progressItem = KPIM::ProgressManager::createProgressItem( KPIM::ProgressManager::getUniqueID(),
-                                                                 d->feed->title() );
-
-    connect( d->progressItem, SIGNAL(progressItemCanceled(KPIM::ProgressItem*)),
-             d->feed.get(), SLOT(abortFetch()) );
-}
-
-void FetchProgressItemHandler::slotFetchPercent( const KRss::Feed::Id& id, uint percentage )
-{
-    Q_UNUSED( id )
-    if ( d->progressItem ) {
-        d->progressItem->setStatus( i18n( "Fetching" ) );
-        d->progressItem->setProgress( percentage );
-    }
-}
-
-void FetchProgressItemHandler::slotFetchFinished( const KRss::Feed::Id& id )
-{
-    Q_UNUSED( id )
-    if ( d->progressItem ) {
-        d->progressItem->setStatus(i18n("Fetch completed"));
-        d->progressItem->setComplete();
-        d->progressItem = 0;
-    }
-}
-
-void FetchProgressItemHandler::slotFetchFailed( const KRss::Feed::Id& id, const QString& errorMessage )
-{
-    Q_UNUSED( id )
-    if ( d->progressItem ) {
-        d->progressItem->setStatus( i18n( "Fetch error. %1", errorMessage ) );
-        d->progressItem->setComplete();
-        d->progressItem = 0;
-    }
-}
-
-void FetchProgressItemHandler::slotFetchAborted( const KRss::Feed::Id& id )
-{
-    Q_UNUSED( id )
-    if ( d->progressItem ) {
-        d->progressItem->setStatus(i18n("Fetch aborted"));
-        d->progressItem->setComplete();
-        d->progressItem = 0;
-    }
-}
-
-class JobProgressItemHandler::JobProgressItemHandlerPrivate
-{
-    public:
-        explicit JobProgressItemHandlerPrivate( const KJob *job_ )
-            : job( job_ ), progressItem( 0 ) {}
-        const KJob * const job;
-        KPIM::ProgressItem* progressItem;
-};
-
-JobProgressItemHandler::JobProgressItemHandler( const KJob *job )
-    : d( new JobProgressItemHandlerPrivate( job ) )
-{
-    connect( d->job, SIGNAL(result(KJob*)),
-             this, SLOT(slotJobResult(KJob*)) );
-    connect( d->job, SIGNAL(destroyed(QObject*)),
-             this, SLOT(slotJobDestroyed()) );
-    connect( d->job, SIGNAL(percent(KJob*,ulong)),
-             this, SLOT(slotJobPercent(KJob*,ulong)) );
-
-    d->progressItem = KPIM::ProgressManager::createProgressItem( KPIM::ProgressManager::getUniqueID(),
-                                                                 i18n( "Item Loading" ), QString(),
-                                                                 false );
-    d->progressItem->setStatus( i18n( "Loading" ) );
-    d->progressItem->setProgress( 0 );
-}
-
-JobProgressItemHandler::~JobProgressItemHandler()
-{
-    if ( d->progressItem ) {
-        d->progressItem->setComplete();
-        d->progressItem = 0;
-    }
-
-    delete d;
-    d = 0;
-}
-
-void JobProgressItemHandler::slotJobPercent( KJob *job, unsigned long percentage )
-{
-    Q_UNUSED( job )
-    if ( d->progressItem ) {
-        d->progressItem->setStatus( i18n( "Loading" ) );
-        d->progressItem->setProgress( percentage );
-    }
-}
-
-void JobProgressItemHandler::slotJobResult( KJob *job )
-{
-    Q_UNUSED( job )
-    job->disconnect( this );
-    if ( d->progressItem ) {
-        if ( job->error() )
-            d->progressItem->setStatus( i18n( "Load error. %1", job->errorString() ) );
-        else
-            d->progressItem->setStatus( i18n( "Load completed" ) );
-        d->progressItem->setComplete();
-        d->progressItem = 0;
-    }
-
-    deleteLater();
-}
-
-void JobProgressItemHandler::slotJobDestroyed()
-{
-    if ( d->progressItem ) {
-        d->progressItem->setStatus( i18n( "Canceled" ) );
-        d->progressItem->setComplete();
-        d->progressItem = 0;
-    }
-
-    deleteLater();
-}
-
-} // namespace Akregator2
-
-#include "progressmanager.moc"
diff --git a/akregator2/src/progressmanager.h b/akregator2/src/progressmanager.h
deleted file mode 100644
index 634d8dd..0000000
--- a/akregator2/src/progressmanager.h
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
-    This file is part of Akregator2.
-
-    Copyright (C) 2005 Frank Osterfeld <osterfeld@kde.org>
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-
-    As a special exception, permission is given to link this program
-    with any edition of Qt, and distribute the resulting executable,
-    without including the source code for Qt in the source distribution.
-*/
-
-#ifndef AKREGATOR2_PROGRESSMANAGER_H
-#define AKREGATOR2_PROGRESSMANAGER_H
-
-#include <QObject>
-
-namespace boost {
-template <typename T> class shared_ptr;
-}
-
-namespace KRss {
-class FeedList;
-class Feed;
-}
-
-namespace Akregator2
-{
-
-class ProgressItemHandler;
-
-/** This class manages the progress items for all feeds */
-
-class ProgressManager : public QObject
-{
-    Q_OBJECT
-    public:
-        static ProgressManager* self();
-
-        /** sets the feed list to be managed */
-        void setFeedList( const boost::shared_ptr<KRss::FeedList>& feedList );
-        /** adds a job to track the progress of */
-        void addJob( KJob *job );
-
-    protected slots:
-        void slotFeedAdded( const KRss::Feed::Id& id );
-        void slotFeedRemoved( const KRss::Feed::Id& id );
-
-    private:
-        friend class ProgressManagerPrivate;
-        ProgressManager();
-        ~ProgressManager();
-        static ProgressManager* m_self;
-};
-
-/** this class handles the creation and deletion of progress items for one feed.
-    This is an internal class intended to be used in ProgressManager only */
-
-class FetchProgressItemHandler : public QObject
-{
-    Q_OBJECT
-    public:
-        explicit FetchProgressItemHandler( const boost::shared_ptr<const KRss::Feed>& feed );
-        ~FetchProgressItemHandler();
-
-    public slots:
-        void slotFetchStarted( const KRss::Feed::Id& id );
-        void slotFetchPercent( const KRss::Feed::Id& id, uint percentage );
-        void slotFetchFinished( const KRss::Feed::Id& id );
-        void slotFetchFailed( const KRss::Feed::Id& id, const QString& errorMessage );
-        void slotFetchAborted( const KRss::Feed::Id& id );
-
-    private:
-        class FetchProgressItemHandlerPrivate;
-        FetchProgressItemHandlerPrivate* d;
-};
-
-/** this class handles the creation and deletion of progress items for one item listing job.
-    This is an internal class intended to be used in ProgressManager only
-    note: deletes itself once the job is finished */
-class JobProgressItemHandler : public QObject
-{
-    Q_OBJECT
-    public:
-        explicit JobProgressItemHandler( const KJob *job );
-        ~JobProgressItemHandler();
-
-    public slots:
-        void slotJobPercent( KJob *job, unsigned long percentage );
-        void slotJobResult( KJob *job );
-        void slotJobDestroyed();
-
-    private:
-        class JobProgressItemHandlerPrivate;
-        JobProgressItemHandlerPrivate* d;
-};
-
-} // namespace Akregator2
-
-#endif // AKREGATOR2_PROGRESSMANAGER_H
[prev in list] [next in list] [prev in thread] [next in thread] 

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