diff --git a/src/core/feedsmodel.cpp b/src/core/feedsmodel.cpp index f67e7573f..f75ddf96a 100755 --- a/src/core/feedsmodel.cpp +++ b/src/core/feedsmodel.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include @@ -522,10 +523,51 @@ QModelIndex FeedsModel::indexForItem(FeedsModelRootItem *item) const { bool FeedsModel::mergeRootItem(FeedsModelRootItem *root_item, QString &output_message) { if (root_item == NULL) { + output_message = tr("Invalid tree data."); + qDebug("Root item for merging two models is null."); return false; } - return false; + QStack original_parents; original_parents.push(m_rootItem); + QStack new_parents; new_parents.push(root_item); + bool some_feed_category_error = false; + + // We are definitely about to add some new items into the model. + emit layoutAboutToBeChanged(); + + // Iterate all new items we would like to merge into current model. + while (!new_parents.isEmpty()) { + FeedsModelRootItem *target_parent = original_parents.pop(); + FeedsModelRootItem *source_parent = new_parents.pop(); + + 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); + + // Add category to model. + new_category->clearChildren(); + addCategory(new_category, target_parent); + } + 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. + addFeed(new_feed, target_parent); + } + } + } + + // Changes are done now. Finalize the new model. + emit layoutChanged(); + + return true; } bool FeedsModel::doesItemContainSameItem(FeedsModelRootItem *parent, FeedsModelRootItem *item) { diff --git a/src/core/feedsmodelfeed.cpp b/src/core/feedsmodelfeed.cpp index 0e4c01044..629ecbb81 100755 --- a/src/core/feedsmodelfeed.cpp +++ b/src/core/feedsmodelfeed.cpp @@ -48,6 +48,24 @@ FeedsModelFeed::FeedsModelFeed(FeedsModelRootItem *parent_item) m_kind = FeedsModelRootItem::Feed; } +FeedsModelFeed::FeedsModelFeed(const FeedsModelFeed &other) + : FeedsModelRootItem(NULL), m_totalCount(0), m_unreadCount(0) { + m_status = other.status(); + m_type = other.type(); + m_autoUpdateType = other.autoUpdateType(); + m_autoUpdateInitialInterval = other.autoUpdateInitialInterval(); + m_encoding = other.encoding(); + m_url = other.url(); + m_kind = other.kind(); + m_title = other.title(); + m_id = other.id(); + m_icon = other.icon(); + m_childItems = other.childItems(); + m_parentItem = other.parent(); + m_creationDate = other.creationDate(); + m_description = other.description(); +} + FeedsModelFeed::~FeedsModelFeed() { qDebug("Destroying FeedsModelFeed instance."); } diff --git a/src/core/feedsmodelfeed.h b/src/core/feedsmodelfeed.h index 26a89147c..a676c8a0c 100755 --- a/src/core/feedsmodelfeed.h +++ b/src/core/feedsmodelfeed.h @@ -63,6 +63,7 @@ class FeedsModelFeed : public FeedsModelRootItem { // Constructors and destructors. explicit FeedsModelFeed(FeedsModelRootItem *parent_item = NULL); + explicit FeedsModelFeed(const FeedsModelFeed &other); virtual ~FeedsModelFeed(); // Returns 0, feeds have no children.