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