31 #include <KMessageBox>
35 #include <QDomDocument>
43 using namespace boost;
44 using namespace Akregator;
45 using namespace Akregator::Backend;
47 class LoadFeedListCommand::Private {
51 void handleDocument(
const QDomDocument& doc );
52 QString createBackup(
const QString& path,
bool* ok );
53 void emitResult(
const shared_ptr<FeedList>& list );
57 QDomDocument defaultFeedList;
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>" );
78 QPointer<QObject> that( q );
79 KMessageBox::error( q->parentWidget(), msg, i18n(
"OPML Parsing Error") );
84 emitResult( feedList );
87 QString LoadFeedListCommand::Private::createBackup(
const QString& path,
bool* ok ) {
88 const QString backup = path
89 + QLatin1String(
"-backup.")
90 + QString::number(QDateTime::currentDateTime().toTime_t());
92 const bool copied = QFile::copy( path, backup );
98 LoadFeedListCommand::LoadFeedListCommand(
QObject* parent ) :
Command( parent ), d( new Private( this ) ) {
106 d->fileName = fileName;
109 d->defaultFeedList = doc;
116 void LoadFeedListCommand::doStart() {
117 QTimer::singleShot( KRandom::random() % 400,
this, SLOT(doLoad()) );
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();
136 if ( !QFile::exists( fileName ) ) {
137 handleDocument( defaultFeedList );
141 QFile file( fileName );
143 if ( !file.open( QIODevice::ReadOnly ) ) {
144 QPointer<QObject> that( q );
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" );
161 const QString details =
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>" );
175 QPointer<QObject> that( q );
177 KMessageBox::detailedError( q->parentWidget(), msg, details, title );
180 handleDocument( defaultFeedList );
184 handleDocument( doc );
187 #include "loadfeedlistcommand.moc"
void setDefaultFeedList(const QDomDocument &doc)
void setStorage(Backend::Storage *storage)
Storage is the main interface to the article archive.
The model of a feed tree, represents an OPML document.
void setFileName(const QString &fileName)