From f131be94b967fee969571c827136146c20df9bae Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Wed, 4 Nov 2015 14:05:33 +0100 Subject: [PATCH] Merging of initial feeds now works, so does editing of standard feed/category. Needs a lot of polishment though. --- src/core/rootitem.cpp | 15 +++++++++++++++ src/core/rootitem.h | 3 +++ src/gui/feedmessageviewer.cpp | 7 +++---- src/services/abstract/feed.h | 4 ++-- .../standard/gui/formstandardcategorydetails.cpp | 5 ++--- .../standard/gui/formstandardfeeddetails.cpp | 5 ++--- src/services/standard/standardcategory.cpp | 13 ++++++------- src/services/standard/standardcategory.h | 3 +++ src/services/standard/standardfeed.cpp | 12 ++++++------ src/services/standard/standardfeed.h | 3 +++ src/services/standard/standardserviceroot.cpp | 5 ++++- 11 files changed, 49 insertions(+), 26 deletions(-) diff --git a/src/core/rootitem.cpp b/src/core/rootitem.cpp index a46f0a906..4546b4172 100755 --- a/src/core/rootitem.cpp +++ b/src/core/rootitem.cpp @@ -152,6 +152,21 @@ QList RootItem::getSubTreeFeeds() { return children; } +ServiceRoot *RootItem::getParentServiceRoot() { + RootItem *working_parent = this; + + while (working_parent->kind() != RootItemKind::Root) { + if (working_parent->kind() == RootItemKind::ServiceRoot) { + return working_parent->toServiceRoot(); + } + else { + working_parent = working_parent->parent(); + } + } + + return NULL; +} + bool RootItem::removeChild(RootItem *child) { return m_childItems.removeOne(child); } diff --git a/src/core/rootitem.h b/src/core/rootitem.h index 163e80ce9..dfc32b62a 100755 --- a/src/core/rootitem.h +++ b/src/core/rootitem.h @@ -157,6 +157,9 @@ class RootItem { QList getSubTreeCategories(); QList getSubTreeFeeds(); + // Returns the service root node which is direct or indirect parent of current item. + ServiceRoot *getParentServiceRoot(); + // Removes particular child at given index. // NOTE: Child is NOT freed from the memory. bool removeChild(int index); diff --git a/src/gui/feedmessageviewer.cpp b/src/gui/feedmessageviewer.cpp index df6fc5af8..6bb8cc241 100755 --- a/src/gui/feedmessageviewer.cpp +++ b/src/gui/feedmessageviewer.cpp @@ -26,6 +26,7 @@ #include "core/messagesproxymodel.h" #include "core/feeddownloader.h" #include "core/feedsselection.h" +#include "services/standard/standardserviceroot.h" #include "services/standard/standardfeed.h" #include "services/standard/standardfeedsimportexportmodel.h" #include "network-web/webbrowser.h" @@ -209,12 +210,10 @@ void FeedMessageViewer::loadInitialFeeds() { model.importAsOPML20(IOFactory::readTextFile(file_to_load)); model.checkAllItems(); - // TODO: dodělat, předpokládá nějaký rozumný přístup k standardnímu root servicu. - /* - if (m_feedsView->sourceModel()->mergeModel(&model, output_msg)) { + // TODO: double-check. + if (m_feedsView->sourceModel()->standardServiceRoot()->mergeImportExportModel(&model, output_msg)) { m_feedsView->expandAll(); } - */ } catch (ApplicationException &ex) { MessageBox::show(this, QMessageBox::Critical, tr("Error when loading initial feeds"), ex.message()); diff --git a/src/services/abstract/feed.h b/src/services/abstract/feed.h index f239b48bc..64aecd6f8 100755 --- a/src/services/abstract/feed.h +++ b/src/services/abstract/feed.h @@ -45,8 +45,8 @@ class Feed : public RootItem { }; enum ReadStatus { - Read = 0, - Unread = 1 + Unread = 0, + Read = 1 }; // Constructors. diff --git a/src/services/standard/gui/formstandardcategorydetails.cpp b/src/services/standard/gui/formstandardcategorydetails.cpp index b3fd72720..e1c5ec5a0 100755 --- a/src/services/standard/gui/formstandardcategorydetails.cpp +++ b/src/services/standard/gui/formstandardcategorydetails.cpp @@ -139,9 +139,6 @@ void FormStandardCategoryDetails::apply() { if (edited) { m_serviceRoot->feedsModel()->reassignNodeToNewParent(m_editableCategory, new_category->parent()); - - // Remove new temporary feed data holder object. - delete new_category; accept(); } else { @@ -149,6 +146,8 @@ void FormStandardCategoryDetails::apply() { tr("Category was not edited due to error."), QSystemTrayIcon::Critical, this, true); } + + delete new_category; } } diff --git a/src/services/standard/gui/formstandardfeeddetails.cpp b/src/services/standard/gui/formstandardfeeddetails.cpp index 7fa6d6c8c..80a6d7d97 100755 --- a/src/services/standard/gui/formstandardfeeddetails.cpp +++ b/src/services/standard/gui/formstandardfeeddetails.cpp @@ -258,9 +258,6 @@ void FormStandardFeedDetails::apply() { if (edited) { m_serviceRoot->feedsModel()->reassignNodeToNewParent(m_editableFeed, new_feed->parent()); - - // Remove new temporary feed data holder object. - delete new_feed; accept(); } else { @@ -268,6 +265,8 @@ void FormStandardFeedDetails::apply() { tr("Feed was not edited due to error."), QSystemTrayIcon::Critical, this, true); } + + delete new_feed; } } diff --git a/src/services/standard/standardcategory.cpp b/src/services/standard/standardcategory.cpp index b321eeed0..4a16421db 100755 --- a/src/services/standard/standardcategory.cpp +++ b/src/services/standard/standardcategory.cpp @@ -27,6 +27,7 @@ #include "gui/feedmessageviewer.h" #include "gui/feedsview.h" #include "services/standard/gui/formstandardcategorydetails.h" +#include "services/standard/standardserviceroot.h" #include #include @@ -54,6 +55,10 @@ StandardCategory::~StandardCategory() { qDebug("Destroying Category instance."); } +StandardServiceRoot *StandardCategory::serviceRoot() { + return static_cast(getParentServiceRoot()); +} + void StandardCategory::init() { m_kind = RootItemKind::Category; } @@ -127,16 +132,10 @@ QVariant StandardCategory::data(int column, int role) const { } bool StandardCategory::editViaDialog() { - // TODO: předávat service root. -/* - QPointer form_pointer = new FormStandardCategoryDetails(qApp->mainForm()->tabWidget()->feedMessageViewer()->feedsView()->sourceModel(), - qApp->mainForm()); - + QPointer form_pointer = new FormStandardCategoryDetails(serviceRoot(), qApp->mainForm()); form_pointer.data()->exec(this, NULL); - delete form_pointer.data(); - */ return false; } diff --git a/src/services/standard/standardcategory.h b/src/services/standard/standardcategory.h index 4f1cd8e41..499e329b4 100755 --- a/src/services/standard/standardcategory.h +++ b/src/services/standard/standardcategory.h @@ -25,6 +25,7 @@ class FeedsModel; +class StandardServiceRoot; // Base class for all categories contained in FeedsModel. // NOTE: This class should be derived to create PARTICULAR category types. @@ -39,6 +40,8 @@ class StandardCategory : public Category { explicit StandardCategory(const QSqlRecord &record); virtual ~StandardCategory(); + StandardServiceRoot *serviceRoot(); + // Returns the actual data representation of standard category. QVariant data(int column, int role) const; diff --git a/src/services/standard/standardfeed.cpp b/src/services/standard/standardfeed.cpp index 86104f076..4386a4dbc 100755 --- a/src/services/standard/standardfeed.cpp +++ b/src/services/standard/standardfeed.cpp @@ -29,6 +29,7 @@ #include "gui/dialogs/formmain.h" #include "gui/feedmessageviewer.h" #include "gui/feedsview.h" +#include "services/standard/standardserviceroot.h" #include "services/standard/gui/formstandardfeeddetails.h" #include @@ -98,16 +99,15 @@ int StandardFeed::countOfUnreadMessages() const { return m_unreadCount; } +StandardServiceRoot *StandardFeed::serviceRoot() { + return static_cast(getParentServiceRoot()); +} + bool StandardFeed::editViaDialog() { - // TODO: fix passing of the model + QPointer form_pointer = new FormStandardFeedDetails(serviceRoot(), qApp->mainForm()); - /* - QPointer form_pointer = new FormStandardFeedDetails(qApp->mainForm()->tabWidget()->feedMessageViewer()->feedsView()->sourceModel(), - qApp->mainForm()); form_pointer.data()->exec(this, NULL); - delete form_pointer.data(); - */ return false; } diff --git a/src/services/standard/standardfeed.h b/src/services/standard/standardfeed.h index 9196f069a..425c39baf 100755 --- a/src/services/standard/standardfeed.h +++ b/src/services/standard/standardfeed.h @@ -30,6 +30,7 @@ class Message; class FeedsModel; +class StandardServiceRoot; // Represents BASE class for feeds contained in FeedsModel. // NOTE: This class should be derived to create PARTICULAR feed types. @@ -52,6 +53,8 @@ class StandardFeed : public Feed { explicit StandardFeed(const QSqlRecord &record); virtual ~StandardFeed(); + StandardServiceRoot *serviceRoot(); + // Getters/setters for count of messages. // NOTE: For feeds, counts are stored internally // and can be updated from the database. diff --git a/src/services/standard/standardserviceroot.cpp b/src/services/standard/standardserviceroot.cpp index 666bea5c7..08c5101cc 100755 --- a/src/services/standard/standardserviceroot.cpp +++ b/src/services/standard/standardserviceroot.cpp @@ -289,7 +289,10 @@ bool StandardServiceRoot::mergeImportExportModel(FeedsImportExportModel *model, StandardFeed *new_feed = new StandardFeed(*source_feed); // Append this feed and end this iteration. - if (!new_feed->addItself(target_parent)) { + if (new_feed->addItself(target_parent)) { + m_feedsModel->assignNodeToNewParent(new_feed, target_parent); + } + else { delete new_feed; some_feed_category_error = true; }