From 4c494f63ae1cb3034889893e90f3d8f692569ec9 Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Wed, 3 Sep 2014 17:38:58 +0200 Subject: [PATCH] Import fixing. --- src/core/feedsimportexportmodel.cpp | 4 ++++ src/core/feedsimportexportmodel.h | 2 ++ src/core/feedsmodel.cpp | 14 ++++++++++---- src/core/feedsmodel.h | 3 ++- src/core/feedsmodelfeed.cpp | 4 +++- src/gui/formimportexport.cpp | 2 +- 6 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/core/feedsimportexportmodel.cpp b/src/core/feedsimportexportmodel.cpp index 12e1d7fef..dda3875f0 100644 --- a/src/core/feedsimportexportmodel.cpp +++ b/src/core/feedsimportexportmodel.cpp @@ -433,3 +433,7 @@ Qt::ItemFlags FeedsImportExportModel::flags(const QModelIndex &index) const { return flags; } + +bool FeedsImportExportModel::isItemChecked(FeedsModelRootItem *item) { + return m_checkStates.contains(item) && m_checkStates.value(item, Qt::Unchecked); +} diff --git a/src/core/feedsimportexportmodel.h b/src/core/feedsimportexportmodel.h index 3b1c76a8a..eb5b0242f 100644 --- a/src/core/feedsimportexportmodel.h +++ b/src/core/feedsimportexportmodel.h @@ -44,6 +44,8 @@ class FeedsImportExportModel : public QAbstractItemModel { bool setData(const QModelIndex &index, const QVariant &value, int role); Qt::ItemFlags flags(const QModelIndex &index) const; + bool isItemChecked(FeedsModelRootItem *item); + // Returns feed/category which lies at the specified index or // root item if index is invalid. FeedsModelRootItem *itemForIndex(const QModelIndex &index) const; diff --git a/src/core/feedsmodel.cpp b/src/core/feedsmodel.cpp index 10b02b807..fa06fc2f2 100755 --- a/src/core/feedsmodel.cpp +++ b/src/core/feedsmodel.cpp @@ -20,6 +20,7 @@ #include "definitions/definitions.h" #include "core/feedsmodelcategory.h" #include "core/feedsmodelfeed.h" +#include "core/feedsimportexportmodel.h" #include "miscellaneous/textfactory.h" #include "miscellaneous/databasefactory.h" #include "miscellaneous/iconfactory.h" @@ -525,15 +526,15 @@ QModelIndex FeedsModel::indexForItem(FeedsModelRootItem *item) const { return QModelIndex(); } -bool FeedsModel::mergeRootItem(FeedsModelRootItem *root_item, QString &output_message) { - if (root_item == NULL) { +bool FeedsModel::mergeModel(FeedsImportExportModel *model, QString &output_message) { + if (model == NULL || model->rootItem() == NULL) { output_message = tr("Invalid tree data."); qDebug("Root item for merging two models is null."); return false; } QStack original_parents; original_parents.push(m_rootItem); - QStack new_parents; new_parents.push(root_item); + QStack new_parents; new_parents.push(model->rootItem()); bool some_feed_category_error = false; // We are definitely about to add some new items into the model. @@ -545,6 +546,12 @@ bool FeedsModel::mergeRootItem(FeedsModelRootItem *root_item, QString &output_me FeedsModelRootItem *source_parent = new_parents.pop(); foreach (FeedsModelRootItem *source_item, source_parent->childItems()) { + if (!model->isItemChecked(source_item)) { + // We can skip this item, because it is not checked and should not be imported. + // NOTE: All descendants are thus skipped too. + continue; + } + if (source_item->kind() == FeedsModelRootItem::Category) { FeedsModelCategory *source_category = static_cast(source_item); FeedsModelCategory *new_category = new FeedsModelCategory(*source_category); @@ -563,7 +570,6 @@ bool FeedsModel::mergeRootItem(FeedsModelRootItem *root_item, QString &output_me } else if (source_item->kind() == FeedsModelRootItem::Feed) { FeedsModelFeed *source_feed = static_cast(source_item); - // TODO: dodělat kopirovaci konstruktor pořádně. FeedsModelFeed *new_feed = new FeedsModelFeed(*source_feed); // Append this feed and end this iteration. diff --git a/src/core/feedsmodel.h b/src/core/feedsmodel.h index 7e8049a77..89b07525a 100644 --- a/src/core/feedsmodel.h +++ b/src/core/feedsmodel.h @@ -28,6 +28,7 @@ class FeedsModelCategory; class FeedsModelFeed; +class FeedsImportExportModel; typedef QList > CategoryAssignment; typedef QPair CategoryAssignmentItem; @@ -138,7 +139,7 @@ class FeedsModel : public QAbstractItemModel { // Takes structure residing under given root item and adds feeds/categories from // it to active structure. - bool mergeRootItem(FeedsModelRootItem *root_item, QString &output_message); + bool mergeModel(FeedsImportExportModel *model, QString &output_message); public slots: // Feeds operations. diff --git a/src/core/feedsmodelfeed.cpp b/src/core/feedsmodelfeed.cpp index 8446e0312..71b555448 100755 --- a/src/core/feedsmodelfeed.cpp +++ b/src/core/feedsmodelfeed.cpp @@ -55,13 +55,15 @@ FeedsModelFeed::FeedsModelFeed(FeedsModelRootItem *parent_item) } FeedsModelFeed::FeedsModelFeed(const FeedsModelFeed &other) - : FeedsModelRootItem(NULL), m_totalCount(0), m_unreadCount(0) { + : FeedsModelRootItem(NULL) { 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_totalCount = other.countOfAllMessages(); + m_unreadCount = other.countOfUnreadMessages(); m_autoUpdateType = other.autoUpdateType(); m_autoUpdateInitialInterval = other.autoUpdateInitialInterval(); m_autoUpdateRemainingInterval = other.autoUpdateRemainingInterval(); diff --git a/src/gui/formimportexport.cpp b/src/gui/formimportexport.cpp index 5acb73b82..50ca4b770 100644 --- a/src/gui/formimportexport.cpp +++ b/src/gui/formimportexport.cpp @@ -236,7 +236,7 @@ void FormImportExport::exportFeeds() { void FormImportExport::importFeeds() { QString output_message; - if (qApp->mainForm()->tabWidget()->feedMessageViewer()->feedsView()->sourceModel()->mergeRootItem(m_model->rootItem(), output_message)) { + if (qApp->mainForm()->tabWidget()->feedMessageViewer()->feedsView()->sourceModel()->mergeModel(m_model, output_message)) { qApp->mainForm()->tabWidget()->feedMessageViewer()->feedsView()->expandAll(); m_ui->m_lblResult->setStatus(WidgetWithStatus::Ok, output_message, output_message); }