• 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
articlejobs.cpp
Go to the documentation of this file.
1 /*
2  This file is part of Akregator.
3 
4  Copyright (C) 2007 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 "articlejobs.h"
26 #include "article.h"
27 #include "feed.h"
28 #include "feedlist.h"
29 #include "kernel.h"
30 
31 #include <KDebug>
32 #include <KLocalizedString>
33 
34 #include <QTimer>
35 
36 #include <vector>
37 
38 #include <cassert>
39 
40 using namespace Akregator;
41 
42 Akregator::ArticleDeleteJob::ArticleDeleteJob( QObject* parent ) : KJob( parent ), m_feedList( Kernel::self()->feedList() )
43 {
44  assert( m_feedList );
45 }
46 
47 void Akregator::ArticleDeleteJob::appendArticleIds( const QList<Akregator::ArticleId>& ids )
48 {
49  m_ids += ids;
50 }
51 
52 void Akregator::ArticleDeleteJob::appendArticleId( const Akregator::ArticleId& id )
53 {
54  m_ids += id;
55 }
56 
57 
58 void Akregator::ArticleDeleteJob::start()
59 {
60  QTimer::singleShot( 20, this, SLOT(doStart()) );
61 }
62 
63 void Akregator::ArticleDeleteJob::doStart()
64 {
65  if ( !m_feedList )
66  {
67  kWarning() << "Feedlist object was deleted, items not deleted";
68  emitResult();
69  return;
70  }
71  std::vector<Akregator::Feed*> feeds;
72 
73  Q_FOREACH ( const Akregator::ArticleId& id, m_ids )
74  {
75  Akregator::Article article = m_feedList->findArticle( id.feedUrl, id.guid );
76  if ( article.isNull() )
77  continue;
78 
79  if ( Feed* const feed = m_feedList->findByURL( id.feedUrl ) )
80  {
81  feeds.push_back( feed );
82  feed->setNotificationMode( false );
83  }
84  article.setDeleted();
85  }
86 
87  Q_FOREACH ( Akregator::Feed* const i, feeds )
88  i->setNotificationMode( true );
89 
90  emitResult();
91 }
92 
93 Akregator::ArticleModifyJob::ArticleModifyJob( QObject* parent ) : KJob( parent ), m_feedList( Kernel::self()->feedList() )
94 {
95  Q_ASSERT( m_feedList );
96 }
97 
98 void Akregator::ArticleModifyJob::setStatus( const ArticleId& id, int status )
99 {
100  m_status[id] = status;
101 }
102 
103 void Akregator::ArticleModifyJob::setKeep( const ArticleId& id, bool keep )
104 {
105  m_keepFlags[id] = keep;
106 }
107 
108 void Akregator::ArticleModifyJob::start()
109 {
110  QTimer::singleShot( 20, this, SLOT(doStart()) );
111 }
112 
113 void Akregator::ArticleModifyJob::doStart()
114 {
115 
116  if ( !m_feedList )
117  {
118  kWarning() << "Feedlist object was deleted, items not modified";
119  emitResult();
120  return;
121  }
122  std::vector<Akregator::Feed*> feeds;
123 
124  Q_FOREACH ( const Akregator::ArticleId& id, m_keepFlags.keys() ) //krazy:exclude=foreach
125  {
126  Akregator::Feed* feed = m_feedList->findByURL( id.feedUrl );
127  if ( !feed )
128  continue;
129  feed->setNotificationMode( false );
130  feeds.push_back( feed );
131  Akregator::Article article = feed->findArticle( id.guid );
132  if ( !article.isNull() )
133  article.setKeep( m_keepFlags[id] );
134  }
135 
136  Q_FOREACH ( const Akregator::ArticleId& id, m_status.keys() ) //krazy:exclude=foreach
137  {
138  Akregator::Feed* feed = m_feedList->findByURL( id.feedUrl );
139  if ( !feed )
140  continue;
141  feed->setNotificationMode( false );
142  feeds.push_back( feed );
143  Akregator::Article article = feed->findArticle( id.guid );
144  if ( !article.isNull() )
145  article.setStatus( m_status[id] );
146  }
147 
148  Q_FOREACH ( Akregator::Feed* const i, feeds )
149  i->setNotificationMode( true );
150  emitResult();
151 }
152 
153 CompositeJob::CompositeJob( QObject* parent ) : KCompositeJob( parent )
154 {
155 
156 }
157 
158 bool CompositeJob::addSubjob( KJob* job )
159 {
160  return KCompositeJob::addSubjob( job );
161 }
162 
163 
164 void CompositeJob::start()
165 {
166  if ( subjobs().isEmpty() )
167  {
168  emitResult();
169  return;
170  }
171  Q_FOREACH( KJob* const i, subjobs() )
172  {
173  i->start();
174  }
175 }
176 
177 ArticleListJob::ArticleListJob( TreeNode* p ) : KJob( p ), m_node( p ) {}
178 
179 void ArticleListJob::start() {
180  QTimer::singleShot( 20, this, SLOT(doList()) );
181 }
182 
183 void ArticleListJob::doList() {
184  if ( m_node )
185  m_articles = m_node->articles();
186  else {
187  setError( ListingFailed );
188  setErrorText( i18n("The feed to be listed was already removed.") );
189  }
190  emitResult();
191 }
192 
193 TreeNode* ArticleListJob::node() const {
194  return m_node;
195 }
196 
197 QList<Article> ArticleListJob::articles() const {
198  return m_articles;
199 }
200 
201 #include "articlejobs.moc"
Akregator::ArticleModifyJob::setStatus
void setStatus(const ArticleId &id, int status)
Definition: articlejobs.cpp:98
Akregator::ArticleModifyJob::start
void start()
Definition: articlejobs.cpp:108
feedlist.h
kernel.h
articlejobs.h
Akregator::ArticleListJob::ListingFailed
Definition: articlejobs.h:120
Akregator::ArticleListJob::node
TreeNode * node() const
Definition: articlejobs.cpp:193
Akregator::CompositeJob
Definition: articlejobs.h:58
QObject
feed.h
Akregator::ArticleListJob::ArticleListJob
ArticleListJob(TreeNode *parent=0)
Definition: articlejobs.cpp:177
Akregator::Article::isNull
bool isNull() const
Definition: article.cpp:253
Akregator::ArticleListJob::articles
QList< Article > articles() const
Definition: articlejobs.cpp:197
Akregator::ArticleListJob::start
void start()
Definition: articlejobs.cpp:179
Akregator::ArticleModifyJob
Definition: articlejobs.h:86
Akregator::ArticleDeleteJob::start
void start()
Definition: articlejobs.cpp:58
article.h
Akregator::ArticleId
Definition: articlejobs.h:46
Akregator::ArticleDeleteJob::appendArticleIds
void appendArticleIds(const Akregator::ArticleIdList &ids)
Definition: articlejobs.cpp:47
Akregator::ArticleDeleteJob::ArticleDeleteJob
ArticleDeleteJob(QObject *parent=0)
Definition: articlejobs.cpp:42
Akregator::Feed
represents a feed
Definition: feed.h:52
Akregator::ArticleDeleteJob::appendArticleId
void appendArticleId(const Akregator::ArticleId &id)
Definition: articlejobs.cpp:52
Akregator::Feed::findArticle
Article findArticle(const QString &guid) const
returns article by guid
Definition: feed.cpp:208
Akregator::Article
A proxy class for Syndication::ItemPtr with some additional methods to assist sorting.
Definition: article.h:61
Akregator::Kernel
Definition: kernel.h:43
KCompositeJob
Akregator::TreeNode
Abstract base class for all kind of elements in the feed tree, like feeds and feed groups (and search...
Definition: treenode.h:59
KJob
Akregator::CompositeJob::addSubjob
bool addSubjob(KJob *job)
Definition: articlejobs.cpp:158
Akregator::ArticleModifyJob::setKeep
void setKeep(const ArticleId &id, bool keep)
Definition: articlejobs.cpp:103
Akregator::TreeNode::setNotificationMode
virtual void setNotificationMode(bool doNotify)
Definition: treenode.cpp:178
Akregator::CompositeJob::start
void start()
Definition: articlejobs.cpp:164
QList< Akregator::ArticleId >
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