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

akregator

  • sources
  • kde-4.12
  • kdepim
  • akregator
  • src
expireitemscommand.cpp
Go to the documentation of this file.
1 /*
2  This file is part of Akregator.
3 
4  Copyright (C) 2008 Frank Osterfeld <osterfeld@kde.org>
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 
20  As a special exception, permission is given to link this program
21  with any edition of Qt, and distribute the resulting executable,
22  without including the source code for Qt in the source distribution.
23 */
24 
25 #include "expireitemscommand.h"
26 
27 #include "articlejobs.h"
28 #include "feed.h"
29 #include "feedlist.h"
30 
31 #include <KDebug>
32 
33 #include <QPointer>
34 #include <QSet>
35 #include <QTimer>
36 
37 #include <boost/shared_ptr.hpp>
38 
39 #include <cassert>
40 
41 using namespace boost;
42 using namespace Akregator;
43 
44 class ExpireItemsCommand::Private
45 {
46  ExpireItemsCommand* const q;
47 public:
48  explicit Private( ExpireItemsCommand* qq );
49 
50  void createDeleteJobs();
51  void addDeleteJobForFeed( Feed* feed );
52  void jobFinished( KJob* );
53 
54  weak_ptr<FeedList> m_feedList;
55  QVector<int> m_feeds;
56  QSet<KJob*> m_jobs;
57 };
58 
59 ExpireItemsCommand::Private::Private( ExpireItemsCommand* qq ) : q( qq ), m_feedList()
60 {
61 
62 }
63 
64 void ExpireItemsCommand::Private::addDeleteJobForFeed( Feed* feed )
65 {
66  assert( feed );
67  ArticleDeleteJob* job = new ArticleDeleteJob( q );
68  connect( job, SIGNAL(finished(KJob*)), q, SLOT(jobFinished(KJob*)) );
69  m_jobs.insert( job );
70  feed->deleteExpiredArticles( job );
71  job->start();
72 }
73 
74 void ExpireItemsCommand::Private::jobFinished( KJob* job )
75 {
76  assert( !m_jobs.isEmpty() );
77  m_jobs.remove( job );
78  emit q->progress( ( ( m_feeds.count() - m_jobs.count() ) * 100 ) / m_feeds.count(), QString() );
79  if ( m_jobs.isEmpty() )
80  q->done();
81 }
82 
83 void ExpireItemsCommand::Private::createDeleteJobs()
84 {
85  assert( m_jobs.isEmpty() );
86  const shared_ptr<FeedList> feedList = m_feedList.lock();
87 
88  if ( m_feeds.isEmpty() || !feedList )
89  {
90  if ( !feedList )
91  kWarning() << "Associated feed list was deleted, could not expire items";
92  q->done();
93  return;
94  }
95 
96  Q_FOREACH ( const int i, m_feeds )
97  {
98  Feed* const feed = qobject_cast<Feed*>( feedList->findByID( i ) );
99  if ( feed )
100  addDeleteJobForFeed( feed );
101  }
102 }
103 
104 ExpireItemsCommand::ExpireItemsCommand( QObject* parent ) : Command( parent ), d( new Private( this ) )
105 {
106 }
107 
108 ExpireItemsCommand::~ExpireItemsCommand()
109 {
110  delete d;
111 }
112 
113 void ExpireItemsCommand::setFeedList( const weak_ptr<FeedList>& feedList )
114 {
115  d->m_feedList = feedList;
116 }
117 
118 weak_ptr<FeedList> ExpireItemsCommand::feedList() const
119 {
120  return d->m_feedList;
121 }
122 
123 void ExpireItemsCommand::setFeeds( const QVector<int>& feeds )
124 {
125  d->m_feeds = feeds;
126 }
127 
128 QVector<int> ExpireItemsCommand::feeds() const
129 {
130  return d->m_feeds;
131 }
132 
133 void ExpireItemsCommand::doAbort()
134 {
135  Q_FOREACH( KJob* const i, d->m_jobs )
136  i->kill();
137 }
138 
139 void ExpireItemsCommand::doStart()
140 {
141  QTimer::singleShot( 0, this, SLOT(createDeleteJobs()) );
142 }
143 
144 #include "expireitemscommand.moc"
feedlist.h
Akregator::Command
Definition: command.h:36
articlejobs.h
QObject
feed.h
Akregator::ExpireItemsCommand::~ExpireItemsCommand
~ExpireItemsCommand()
Definition: expireitemscommand.cpp:108
Akregator::ExpireItemsCommand::setFeedList
void setFeedList(const boost::weak_ptr< FeedList > &feedList)
Definition: expireitemscommand.cpp:113
Akregator::ExpireItemsCommand::feeds
QVector< int > feeds() const
Definition: expireitemscommand.cpp:128
Akregator::ArticleDeleteJob::start
void start()
Definition: articlejobs.cpp:58
Akregator::ExpireItemsCommand::feedList
boost::weak_ptr< FeedList > feedList() const
Definition: expireitemscommand.cpp:118
Akregator::ExpireItemsCommand::ExpireItemsCommand
ExpireItemsCommand(QObject *parent=0)
Definition: expireitemscommand.cpp:104
Akregator::ExpireItemsCommand
Definition: expireitemscommand.h:38
Akregator::ArticleDeleteJob
Definition: articlejobs.h:67
Akregator::Feed
represents a feed
Definition: feed.h:52
Akregator::Feed::deleteExpiredArticles
void deleteExpiredArticles(Akregator::ArticleDeleteJob *job)
deletes expired articles
Definition: feed.cpp:698
Akregator::ExpireItemsCommand::setFeeds
void setFeeds(const QVector< int > &feeds)
Definition: expireitemscommand.cpp:123
KJob
expireitemscommand.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:58:14 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akregator

Skip menu "akregator"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

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