• 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
createfeedcommand.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 "createfeedcommand.h"
26 
27 #include "addfeeddialog.h"
28 #include "feed.h"
29 #include "feedlist.h"
30 #include "feedpropertiesdialog.h"
31 #include "folder.h"
32 #include "mainwidget.h"
33 #include "subscriptionlistview.h"
34 
35 #include <KInputDialog>
36 #include <KLocalizedString>
37 #include <KUrl>
38 
39 #include <QPointer>
40 #include <QTimer>
41 #include <QClipboard>
42 
43 #include <cassert>
44 
45 using namespace Akregator;
46 
47 class CreateFeedCommand::Private
48 {
49  CreateFeedCommand* const q;
50 public:
51  explicit Private( CreateFeedCommand* qq );
52 
53  void doCreate();
54 
55  QPointer<MainWidget> m_parent;
56  QPointer<Folder> m_rootFolder;
57  QPointer<SubscriptionListView> m_subscriptionListView;
58  QString m_url;
59  QPointer<Folder> m_parentFolder;
60  QPointer<TreeNode> m_after;
61  bool m_autoexec;
62 };
63 
64 CreateFeedCommand::Private::Private( CreateFeedCommand* qq )
65  : q( qq ),
66  m_rootFolder( 0 ),
67  m_subscriptionListView( 0 ),
68  m_parentFolder( 0 ),
69  m_after( 0 ),
70  m_autoexec( false )
71 {
72 
73 }
74 
75 void CreateFeedCommand::Private::doCreate()
76 {
77  assert( m_rootFolder );
78  assert( m_subscriptionListView );
79 
80  QPointer<AddFeedDialog> afd = new AddFeedDialog( q->parentWidget(), "add_feed" );
81 
82  QString url = m_url;
83 
84  if( url.isEmpty() )
85  {
86  const QClipboard* const clipboard = QApplication::clipboard();
87  assert( clipboard );
88  const QString clipboardText = clipboard->text();
89  // Check for the hostname, since the isValid method is not strict enough
90  if( !KUrl( clipboardText ).host().isEmpty() )
91  url = clipboardText;
92  }
93 
94  afd->setUrl( KUrl::fromPercentEncoding( url.toLatin1() ) );
95 
96  QPointer<QObject> thisPointer( q );
97 
98  if ( m_autoexec )
99  afd->accept();
100  else
101  afd->exec();
102 
103  if ( !thisPointer ) { // "this" might have been deleted while exec()!
104  delete afd;
105  return;
106  }
107 
108  Feed* const feed = afd->feed();
109  delete afd;
110 
111  if ( !feed )
112  {
113  q->done();
114  return;
115  }
116 
117  QPointer<FeedPropertiesDialog> dlg = new FeedPropertiesDialog( q->parentWidget(), "edit_feed" );
118  dlg->setFeed( feed );
119  dlg->selectFeedName();
120 
121  if ( !m_autoexec && ( dlg->exec() != QDialog::Accepted || !thisPointer ) )
122  {
123  delete feed;
124  }
125  else
126  {
127  if ( !m_parentFolder ) {
128  if ( !m_rootFolder ) {
129  if ( m_parent->allFeedsList() ) {
130  q->setRootFolder( m_parent->allFeedsList()->allFeedsFolder() );
131  }
132  }
133  m_parentFolder = m_rootFolder;
134  }
135 
136  if ( m_parentFolder ) {
137  m_parentFolder->insertChild( feed, m_after );
138  m_subscriptionListView->ensureNodeVisible( feed );
139  }
140  }
141 
142  delete dlg;
143  q->done();
144 }
145 
146 CreateFeedCommand::CreateFeedCommand( MainWidget* parent ) : Command( parent ), d( new Private( this ) )
147 {
148  d->m_parent = parent;
149 }
150 
151 CreateFeedCommand::~CreateFeedCommand()
152 {
153  delete d;
154 }
155 
156 void CreateFeedCommand::setSubscriptionListView( SubscriptionListView* view )
157 {
158  d->m_subscriptionListView = view;
159 }
160 
161 void CreateFeedCommand::setRootFolder( Folder* rootFolder )
162 {
163  d->m_rootFolder = rootFolder;
164 }
165 
166 void CreateFeedCommand::setUrl( const QString& url )
167 {
168  d->m_url = url;
169 }
170 
171 void CreateFeedCommand::setPosition( Folder* parent, TreeNode* after )
172 {
173  d->m_parentFolder = parent;
174  d->m_after = after;
175 }
176 
177 void CreateFeedCommand::setAutoExecute( bool autoexec )
178 {
179  d->m_autoexec = autoexec;
180 }
181 
182 void CreateFeedCommand::doStart()
183 {
184  QTimer::singleShot( 0, this, SLOT(doCreate()) );
185 }
186 
187 void CreateFeedCommand::doAbort()
188 {
189 
190 }
191 
192 #include "createfeedcommand.moc"
Akregator::FeedPropertiesDialog
Definition: feedpropertiesdialog.h:58
feedlist.h
Akregator::CreateFeedCommand::setAutoExecute
void setAutoExecute(bool autoexec)
Definition: createfeedcommand.cpp:177
Akregator::Command
Definition: command.h:36
Akregator::MainWidget
This is the main widget of the view, containing tree view, article list, viewer etc.
Definition: mainwidget.h:68
Akregator::CreateFeedCommand::setPosition
void setPosition(Folder *parent, TreeNode *after)
Definition: createfeedcommand.cpp:171
Akregator::CreateFeedCommand::setSubscriptionListView
void setSubscriptionListView(SubscriptionListView *view)
Definition: createfeedcommand.cpp:156
feed.h
Akregator::SubscriptionListView
Definition: subscriptionlistview.h:39
createfeedcommand.h
Akregator::CreateFeedCommand::setUrl
void setUrl(const QString &url)
Definition: createfeedcommand.cpp:166
Akregator::CreateFeedCommand
Definition: createfeedcommand.h:37
feedpropertiesdialog.h
subscriptionlistview.h
Akregator::FeedPropertiesDialog::setFeed
void setFeed(Feed *feed)
Definition: feedpropertiesdialog.cpp:135
folder.h
mainwidget.h
Akregator::CreateFeedCommand::setRootFolder
void setRootFolder(Folder *rootFolder)
Definition: createfeedcommand.cpp:161
Akregator::Feed
represents a feed
Definition: feed.h:52
Akregator::Folder
Represents a folder (containing feeds and/or other folders)
Definition: folder.h:44
Akregator::CreateFeedCommand::~CreateFeedCommand
~CreateFeedCommand()
Definition: createfeedcommand.cpp:151
Akregator::AddFeedDialog
Definition: addfeeddialog.h:47
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
addfeeddialog.h
m_url
QString m_url
Definition: article.cpp:128
Akregator::CreateFeedCommand::CreateFeedCommand
CreateFeedCommand(MainWidget *parent=0)
Definition: createfeedcommand.cpp:146
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