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