• 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
importfeedlistcommand.cpp
Go to the documentation of this file.
1 /*
2  This file is part of Akregator.
3 
4  Copyright (C) 2009 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 "importfeedlistcommand.h"
26 
27 #include "feedlist.h"
28 #include "folder.h"
29 #include "kernel.h"
30 
31 #include <KDebug>
32 #include <KInputDialog>
33 #include <KLocalizedString>
34 
35 #include <QDomDocument>
36 #include <QPointer>
37 #include <QTimer>
38 
39 #ifndef Q_MOC_RUN
40 #include <boost/shared_ptr.hpp>
41 #endif
42 
43 #include <cassert>
44 
45 using namespace boost;
46 using namespace Akregator;
47 
48 class ImportFeedListCommand::Private
49 {
50  ImportFeedListCommand* const q;
51 public:
52  explicit Private( ImportFeedListCommand* qq );
53 
54  void doImport();
55 
56  weak_ptr<FeedList> targetList;
57  QDomDocument document;
58  ImportFeedListCommand::RootFolderOption rootFolderOption;
59  QString importedRootFolderName;
60 };
61 
62 ImportFeedListCommand::Private::Private( ImportFeedListCommand* qq )
63  : q( qq )
64  , targetList()
65  , rootFolderOption( Ask )
66  , importedRootFolderName( i18n("Imported Feeds") )
67 {
68 
69 }
70 
71 void ImportFeedListCommand::Private::doImport()
72 {
73  const shared_ptr<FeedList> target = targetList.lock();
74 
75  if ( !target )
76  {
77  if ( !target )
78  kWarning() << "Target list was deleted, could not import feed list";
79  q->done();
80  return;
81  }
82 
83  std::auto_ptr<FeedList> importedList( new FeedList( Kernel::self()->storage() ) );
84  const bool parsed = importedList->readFromOpml( document );
85 
86  // FIXME: parsing error, print some message
87  if (!parsed) {
88  q->done();
89  return;
90  }
91 
92 
93  QPointer<QObject> that( q );
94 
95  bool ok=false;
96 
97  if ( rootFolderOption == ImportFeedListCommand::Ask )
98  importedRootFolderName = KInputDialog::getText( i18n("Add Imported Folder"),
99  i18n("Imported folder name:"),
100  importedRootFolderName,
101  &ok,
102  q->parentWidget() );
103 
104 
105  if ( !ok || !that ) {
106  if ( that )
107  q->done();
108  return;
109  }
110 
111  Folder* folder = target->allFeedsFolder();
112 
113  if ( rootFolderOption != None ) {
114  folder = new Folder( importedRootFolderName );
115  target->allFeedsFolder()->appendChild( folder );
116  }
117 
118  target->append( importedList.get(), folder );
119 
120  q->done();
121 }
122 
123 ImportFeedListCommand::ImportFeedListCommand( QObject* parent ) : Command( parent ), d( new Private( this ) )
124 {
125 }
126 
127 ImportFeedListCommand::~ImportFeedListCommand()
128 {
129  delete d;
130 }
131 
132 void ImportFeedListCommand::setTargetList( const weak_ptr<FeedList>& feedList )
133 {
134  d->targetList = feedList;
135 }
136 
137 void ImportFeedListCommand::setImportedRootFolderOption( RootFolderOption opt ) {
138  d->rootFolderOption = opt;
139 }
140 
141 void ImportFeedListCommand::setImportedRootFolderName( const QString& defaultName ) {
142  d->importedRootFolderName = defaultName;
143 }
144 
145 void ImportFeedListCommand::setFeedListDocument( const QDomDocument& doc ) {
146  d->document = doc;
147 }
148 
149 void ImportFeedListCommand::doAbort()
150 {
151  //TODO
152 }
153 
154 void ImportFeedListCommand::doStart()
155 {
156  QTimer::singleShot( 0, this, SLOT(doImport()) );
157 }
158 
159 #include "moc_importfeedlistcommand.cpp"
feedlist.h
Akregator::Command
Definition: command.h:36
kernel.h
QPointer
importfeedlistcommand.h
Akregator::ImportFeedListCommand::setImportedRootFolderOption
void setImportedRootFolderOption(RootFolderOption opt)
Definition: importfeedlistcommand.cpp:137
Akregator::FeedList
The model of a feed tree, represents an OPML document.
Definition: feedlist.h:78
Akregator::ImportFeedListCommand::ImportFeedListCommand
ImportFeedListCommand(QObject *parent=0)
Definition: importfeedlistcommand.cpp:123
Akregator::ImportFeedListCommand::~ImportFeedListCommand
~ImportFeedListCommand()
Definition: importfeedlistcommand.cpp:127
QObject
Akregator::Kernel::self
static Kernel * self()
Definition: kernel.cpp:39
Akregator::ImportFeedListCommand::setTargetList
void setTargetList(const boost::weak_ptr< FeedList > &feedList)
Definition: importfeedlistcommand.cpp:132
Akregator::ImportFeedListCommand
Definition: importfeedlistcommand.h:40
QString
Akregator::ImportFeedListCommand::setImportedRootFolderName
void setImportedRootFolderName(const QString &defaultName)
Definition: importfeedlistcommand.cpp:141
QDomDocument
folder.h
Akregator::ImportFeedListCommand::Ask
Definition: importfeedlistcommand.h:53
Akregator::ImportFeedListCommand::RootFolderOption
RootFolderOption
Definition: importfeedlistcommand.h:50
Akregator::Folder
Represents a folder (containing feeds and/or other folders)
Definition: folder.h:44
Akregator::ImportFeedListCommand::setFeedListDocument
void setFeedListDocument(const QDomDocument &doc)
Definition: importfeedlistcommand.cpp:145
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