diff --git a/src/core/feedsimportexportmodel.cpp b/src/core/feedsimportexportmodel.cpp index 2c15b1ee7..12e1d7fef 100644 --- a/src/core/feedsimportexportmodel.cpp +++ b/src/core/feedsimportexportmodel.cpp @@ -20,6 +20,8 @@ #include "core/feedsmodelfeed.h" #include "core/feedsmodelcategory.h" #include "definitions/definitions.h" +#include "miscellaneous/application.h" +#include "miscellaneous/iconfactory.h" #include #include @@ -192,6 +194,8 @@ bool FeedsImportExportModel::importAsOPML20(const QByteArray &data) { new_feed->setDescription(feed_description); new_feed->setEncoding(feed_encoding); new_feed->setUrl(feed_url); + new_feed->setCreationDate(QDateTime::currentDateTime()); + new_feed->setIcon(qApp->icons()->fromTheme("folder-feed")); new_feed->setAutoUpdateType(FeedsModelFeed::DefaultAutoUpdate); if (feed_type == "RSS1") { @@ -214,6 +218,8 @@ bool FeedsImportExportModel::importAsOPML20(const QByteArray &data) { FeedsModelCategory *new_category = new FeedsModelCategory(active_model_item); new_category->setTitle(category_title); + new_category->setIcon(qApp->icons()->fromTheme("folder-category")); + new_category->setCreationDate(QDateTime::currentDateTime()); new_category->setDescription(category_description); active_model_item->appendChild(new_category); diff --git a/src/core/feedsmodel.cpp b/src/core/feedsmodel.cpp index c10aa9a77..10b02b807 100755 --- a/src/core/feedsmodel.cpp +++ b/src/core/feedsmodel.cpp @@ -185,12 +185,14 @@ bool FeedsModel::addCategory(FeedsModelCategory *category, FeedsModelRootItem *p query_add.bindValue(":icon", qApp->icons()->toByteArray(category->icon())); if (!query_add.exec()) { + qDebug("Failed to add category to database: %s.", qPrintable(query_add.lastError().text())); + // Query failed. return false; } - query_add.prepare("SELECT id FROM Categories WHERE date_created = :date_created;"); - query_add.bindValue(":date_created", category->creationDate().toMSecsSinceEpoch()); + query_add.prepare("SELECT id FROM Categories WHERE title = :title;"); + query_add.bindValue(":title", category->title()); if (query_add.exec() && query_add.next()) { // New category was added, fetch is primary id // from the database. @@ -288,12 +290,14 @@ bool FeedsModel::addFeed(FeedsModelFeed *feed, FeedsModelRootItem *parent) { query_add_feed.bindValue(":type", (int) feed->type()); if (!query_add_feed.exec()) { + qDebug("Failed to add feed to database: %s.", qPrintable(query_add_feed.lastError().text())); + // Query failed. return false; } - query_add_feed.prepare("SELECT id FROM Feeds WHERE date_created = :date_created;"); - query_add_feed.bindValue(":date_created", feed->creationDate().toMSecsSinceEpoch()); + query_add_feed.prepare("SELECT id FROM Feeds WHERE url = :url;"); + query_add_feed.bindValue(":url", feed->url()); if (query_add_feed.exec() && query_add_feed.next()) { // New feed was added, fetch is primary id from the database. feed->setId(query_add_feed.value(0).toInt()); @@ -543,15 +547,19 @@ bool FeedsModel::mergeRootItem(FeedsModelRootItem *root_item, QString &output_me foreach (FeedsModelRootItem *source_item, source_parent->childItems()) { if (source_item->kind() == FeedsModelRootItem::Category) { FeedsModelCategory *source_category = static_cast(source_item); - FeedsModelCategory *new_category = new FeedsModelCategory(source_category); - - // Process all children of this category. - original_parents.push(new_category); - new_parents.push(source_category); + FeedsModelCategory *new_category = new FeedsModelCategory(*source_category); // Add category to model. new_category->clearChildren(); - addCategory(new_category, target_parent); + + if (addCategory(new_category, target_parent)) { + // Process all children of this category. + original_parents.push(new_category); + new_parents.push(source_category); + } + else { + some_feed_category_error = true; + } } else if (source_item->kind() == FeedsModelRootItem::Feed) { FeedsModelFeed *source_feed = static_cast(source_item); @@ -559,7 +567,9 @@ bool FeedsModel::mergeRootItem(FeedsModelRootItem *root_item, QString &output_me FeedsModelFeed *new_feed = new FeedsModelFeed(*source_feed); // Append this feed and end this iteration. - addFeed(new_feed, target_parent); + if (!addFeed(new_feed, target_parent)) { + some_feed_category_error = true; + } } } } @@ -567,7 +577,14 @@ bool FeedsModel::mergeRootItem(FeedsModelRootItem *root_item, QString &output_me // Changes are done now. Finalize the new model. emit layoutChanged(); - return true; + if (some_feed_category_error) { + output_message = tr("Import successfull, but some feeds/categories were not imported due to error."); + } + else { + output_message = tr("Import was completely successfull."); + } + + return !some_feed_category_error; } void FeedsModel::reloadChangedLayout(QModelIndexList list) { diff --git a/src/core/feedsmodelfeed.cpp b/src/core/feedsmodelfeed.cpp index f379c6ff9..8446e0312 100755 --- a/src/core/feedsmodelfeed.cpp +++ b/src/core/feedsmodelfeed.cpp @@ -47,8 +47,8 @@ FeedsModelFeed::FeedsModelFeed(FeedsModelRootItem *parent_item) m_totalCount(0), m_unreadCount(0), m_autoUpdateType(DontAutoUpdate), - m_autoUpdateRemainingInterval(DEFAULT_AUTO_UPDATE_INTERVAL), m_autoUpdateInitialInterval(DEFAULT_AUTO_UPDATE_INTERVAL), + m_autoUpdateRemainingInterval(DEFAULT_AUTO_UPDATE_INTERVAL), m_encoding(QString()), m_url(QString()) { m_kind = FeedsModelRootItem::Feed; @@ -56,13 +56,18 @@ FeedsModelFeed::FeedsModelFeed(FeedsModelRootItem *parent_item) FeedsModelFeed::FeedsModelFeed(const FeedsModelFeed &other) : FeedsModelRootItem(NULL), m_totalCount(0), m_unreadCount(0) { + m_passwordProtected = other.passwordProtected(); + m_username = other.username(); + m_password = other.password(); m_status = other.status(); + m_networkError = other.networkError(); m_type = other.type(); m_autoUpdateType = other.autoUpdateType(); m_autoUpdateInitialInterval = other.autoUpdateInitialInterval(); + m_autoUpdateRemainingInterval = other.autoUpdateRemainingInterval(); m_encoding = other.encoding(); m_url = other.url(); - m_kind = other.kind(); + m_kind = FeedsModelRootItem::Feed; m_title = other.title(); m_id = other.id(); m_icon = other.icon(); @@ -533,6 +538,6 @@ void FeedsModelFeed::updateMessages(const QList &messages) { } } - - - +QNetworkReply::NetworkError FeedsModelFeed::networkError() const { + return m_networkError; +} diff --git a/src/core/feedsmodelfeed.h b/src/core/feedsmodelfeed.h index a676c8a0c..f3c5be8c4 100755 --- a/src/core/feedsmodelfeed.h +++ b/src/core/feedsmodelfeed.h @@ -169,6 +169,8 @@ class FeedsModelFeed : public FeedsModelRootItem { m_status = status; } + QNetworkReply::NetworkError networkError() const; + // Loads standard feed object from given SQL record. static FeedsModelFeed *loadFromRecord(const QSqlRecord &record); diff --git a/src/gui/formimportexport.cpp b/src/gui/formimportexport.cpp index ccb3a7522..5acb73b82 100644 --- a/src/gui/formimportexport.cpp +++ b/src/gui/formimportexport.cpp @@ -237,6 +237,7 @@ void FormImportExport::importFeeds() { QString output_message; if (qApp->mainForm()->tabWidget()->feedMessageViewer()->feedsView()->sourceModel()->mergeRootItem(m_model->rootItem(), output_message)) { + qApp->mainForm()->tabWidget()->feedMessageViewer()->feedsView()->expandAll(); m_ui->m_lblResult->setStatus(WidgetWithStatus::Ok, output_message, output_message); } else {