30 #include <KLocalizedString>
31 #include <KMessageBox>
35 #include <QDomDocument>
43 using namespace boost;
44 using namespace Akregator;
45 using namespace Akregator::Backend;
47 class LoadFeedListCommand::Private {
53 void emitResult(
const shared_ptr<FeedList>& list );
61 void LoadFeedListCommand::Private::emitResult(
const shared_ptr<FeedList>& list ) {
62 emit q->result( list );
66 void LoadFeedListCommand::Private::handleDocument(
const QDomDocument& doc ) {
67 shared_ptr<FeedList> feedList(
new FeedList( storage ) );
68 if ( !feedList->readFromOpml( doc ) ) {
70 const QString backupFile = createBackup( fileName, &backupCreated );
73 i18n(
"<qt>The standard feed list is corrupted (invalid OPML). "
74 "A backup was created:<p><b>%1</b></p></qt>", backupFile ) :
75 i18n(
"<qt>The standard feed list is corrupted (invalid OPML). "
76 "Could not create a backup.</qt>" );
79 KMessageBox::error( q->parentWidget(), msg, i18n(
"OPML Parsing Error") );
84 emitResult( feedList );
87 QString LoadFeedListCommand::Private::createBackup(
const QString& path,
bool* ok ) {
98 LoadFeedListCommand::LoadFeedListCommand(
QObject* parent ) :
Command( parent ), d( new Private( this ) ) {
106 d->fileName = fileName;
109 d->defaultFeedList = doc;
116 void LoadFeedListCommand::doStart() {
120 void LoadFeedListCommand::doAbort() {
124 void LoadFeedListCommand::Private::doLoad() {
126 assert( !fileName.isNull() );
127 emit q->progress( 0, i18n(
"Opening Feed List...") );
132 const QString listBackup = storage->restoreFeedList();
137 handleDocument( defaultFeedList );
141 QFile file( fileName );
143 if ( !file.open( QIODevice::ReadOnly ) ) {
147 i18n(
"<qt>Could not open feed list (%1) for reading.</qt>", file.fileName() ),
148 i18n(
"Read Error" ) );
150 handleDocument( defaultFeedList );
157 if ( !doc.
setContent( &file,
true, &errMsg, &errLine, &errCol ) ) {
158 bool backupCreated =
false;
159 const QString backupFile = createBackup( fileName, &backupCreated );
160 const QString title = i18nc(
"error message window caption",
"XML Parsing Error" );
162 i18n(
"<qt><p>XML parsing error in line <numid>%1</numid>, "
163 "column <numid>%2</numid> of %3:</p><p>%4</p></qt>",
170 i18n(
"<qt>The standard feed list is corrupted (invalid XML). "
171 "A backup was created:<p><b>%1</b></p></qt>", backupFile ) :
172 i18n(
"<qt>The standard feed list is corrupted (invalid XML). "
173 "Could not create a backup.</qt>" );
177 KMessageBox::detailedError( q->parentWidget(), msg, details, title );
180 handleDocument( defaultFeedList );
184 handleDocument( doc );
187 #include "moc_loadfeedlistcommand.cpp"
void setDefaultFeedList(const QDomDocument &doc)
void setStorage(Backend::Storage *storage)
Storage is the main interface to the article archive.
bool copy(const QString &newName)
The model of a feed tree, represents an OPML document.
QString number(int n, int base)
QDateTime currentDateTime()
void setFileName(const QString &fileName)
bool setContent(const QByteArray &data, bool namespaceProcessing, QString *errorMsg, int *errorLine, int *errorColumn)