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

akregator

  • sources
  • kde-4.14
  • kdepim
  • akregator
  • src
deletesubscriptioncommand.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 "deletesubscriptioncommand.h"
26 
27 #include "feed.h"
28 #include "feedlist.h"
29 #include "folder.h"
30 #include "subscriptionlistjobs.h"
31 #include "treenodevisitor.h"
32 
33 #include <KLocalizedString>
34 #include <KMessageBox>
35 
36 #include <QPointer>
37 #include <QTimer>
38 
39 using namespace Akregator;
40 using namespace boost;
41 
42 namespace {
43 
44 class DeleteNodeVisitor : public TreeNodeVisitor
45 {
46  public:
47  explicit DeleteNodeVisitor( QWidget* parent ) : m_widget( parent ), m_job( 0 ) {}
48 
49 
50  bool visitFolder( Folder* node )
51  {
52  const QString msg = node->title().isEmpty()
53  ? i18n("<qt>Are you sure you want to delete this folder and its feeds and subfolders?</qt>")
54  : i18n("<qt>Are you sure you want to delete folder <b>%1</b> and its feeds and subfolders?</qt>", node->title());
55 
56  if ( KMessageBox::warningContinueCancel( m_widget,
57  msg,
58  i18n( "Delete Folder" ),
59  KStandardGuiItem::del(),
60  KStandardGuiItem::cancel(),
61  QLatin1String("Disable delete folder confirmation") ) != KMessageBox::Continue )
62  return true;
63  m_job = reallyCreateJob( node );
64  //TODO: port focus
65  //m_widget->m_feedListView->setFocus();
66  return true;
67  }
68 
69  virtual bool visitFeed(Feed* node)
70  {
71  QString msg;
72  if (node->title().isEmpty())
73  msg = i18n("<qt>Are you sure you want to delete this feed?</qt>");
74  else
75  msg = i18n("<qt>Are you sure you want to delete feed <b>%1</b>?</qt>", node->title());
76 
77  if ( KMessageBox::warningContinueCancel( m_widget,
78  msg,
79  i18n( "Delete Feed" ),
80  KStandardGuiItem::del(),
81  KStandardGuiItem::cancel(),
82  QLatin1String("Disable delete feed confirmation") ) != KMessageBox::Continue )
83  return true;
84  m_job = reallyCreateJob( node );
85  //TODO: port focus
86  // m_widget->m_feedListView->setFocus();
87  return true;
88  }
89 
90 
91  DeleteSubscriptionJob* createJob( TreeNode* node )
92  {
93  m_job = 0;
94  if ( node )
95  visit( node );
96  return m_job;
97  }
98 
99  private:
100  static DeleteSubscriptionJob* reallyCreateJob( TreeNode* node )
101  {
102  DeleteSubscriptionJob* job = new DeleteSubscriptionJob;
103  job->setSubscriptionId( node->id() );
104  return job;
105  }
106 
107  private:
108  QPointer<QWidget> m_widget;
109  QPointer<DeleteSubscriptionJob> m_job;
110 };
111 
112 }
113 
114 class DeleteSubscriptionCommand::Private
115 {
116  DeleteSubscriptionCommand* const q;
117 public:
118  explicit Private( DeleteSubscriptionCommand* qq );
119  ~Private();
120 
121  void startDelete();
122  void jobFinished();
123 
124  weak_ptr<FeedList> m_list;
125  int m_subscriptionId;
126 };
127 
128 DeleteSubscriptionCommand::Private::Private( DeleteSubscriptionCommand* qq ) : q( qq ),
129  m_list(),
130  m_subscriptionId( -1 )
131 {
132 
133 }
134 
135 DeleteSubscriptionCommand::Private::~Private()
136 {
137 }
138 
139 DeleteSubscriptionCommand::DeleteSubscriptionCommand( QObject* parent ) : Command( parent ), d( new Private( this ) )
140 {
141 }
142 
143 DeleteSubscriptionCommand::~DeleteSubscriptionCommand()
144 {
145  delete d;
146 }
147 
148 void DeleteSubscriptionCommand::setSubscription( const weak_ptr<FeedList>& feedList, int subId )
149 {
150  d->m_list = feedList;
151  d->m_subscriptionId = subId;
152 }
153 
154 int DeleteSubscriptionCommand::subscriptionId() const
155 {
156  return d->m_subscriptionId;
157 }
158 
159 weak_ptr<FeedList> DeleteSubscriptionCommand::feedList() const
160 {
161  return d->m_list;
162 }
163 
164 void DeleteSubscriptionCommand::doStart()
165 {
166  QTimer::singleShot( 0, this, SLOT(startDelete()) );
167 }
168 
169 void DeleteSubscriptionCommand::Private::jobFinished()
170 {
171  q->done();
172 }
173 
174 void DeleteSubscriptionCommand::Private::startDelete()
175 {
176  const shared_ptr<FeedList> list = m_list.lock();
177  if ( !list ) {
178  q->done();
179  return;
180  }
181  TreeNode* const node = list->findByID( m_subscriptionId );
182  DeleteNodeVisitor visitor( q->parentWidget() );
183  DeleteSubscriptionJob* job = visitor.createJob( node );
184  if ( !job )
185  {
186  q->done();
187  return;
188  }
189 
190  QObject::connect( job, SIGNAL(finished(KJob*)), q, SLOT(jobFinished()) );
191  job->start();
192 }
193 
194 void DeleteSubscriptionCommand::doAbort()
195 {
196 
197 }
198 
199 #include "moc_deletesubscriptioncommand.cpp"
Akregator::DeleteSubscriptionCommand
Definition: deletesubscriptioncommand.h:39
Akregator::DeleteSubscriptionCommand::subscriptionId
int subscriptionId() const
Definition: deletesubscriptioncommand.cpp:154
QWidget
feedlist.h
Akregator::Command
Definition: command.h:36
Akregator::TreeNode::title
QString title() const
Get title of node.
Definition: treenode.cpp:87
QPointer< QWidget >
feed.h
Akregator::DeleteSubscriptionCommand::DeleteSubscriptionCommand
DeleteSubscriptionCommand(QObject *parent=0)
Definition: deletesubscriptioncommand.cpp:139
treenodevisitor.h
Akregator::DeleteSubscriptionCommand::feedList
boost::weak_ptr< FeedList > feedList() const
Definition: deletesubscriptioncommand.cpp:159
QObject
QString::isEmpty
bool isEmpty() const
Akregator::DeleteSubscriptionJob::setSubscriptionId
void setSubscriptionId(int id)
Definition: subscriptionlistjobs.cpp:130
QString
folder.h
Akregator::DeleteSubscriptionCommand::~DeleteSubscriptionCommand
~DeleteSubscriptionCommand()
Definition: deletesubscriptioncommand.cpp:143
Akregator::DeleteSubscriptionJob
Definition: subscriptionlistjobs.h:83
QLatin1String
Akregator::TreeNodeVisitor
Definition: treenodevisitor.h:35
Akregator::Feed
represents a feed
Definition: feed.h:53
Akregator::Folder
Represents a folder (containing feeds and/or other folders)
Definition: folder.h:44
Akregator::DeleteSubscriptionCommand::setSubscription
void setSubscription(const boost::weak_ptr< FeedList > &feedList, int subId)
Definition: deletesubscriptioncommand.cpp:148
subscriptionlistjobs.h
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
Akregator::TreeNode
Abstract base class for all kind of elements in the feed tree, like feeds and feed groups (and search...
Definition: treenode.h:58
Akregator::TreeNode::id
virtual uint id() const
returns the ID of this node.
Definition: treenode.cpp:198
KJob
deletesubscriptioncommand.h
QTimer::singleShot
singleShot
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:34:00 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
  • pimprint

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