Merging of initial feeds now works, so does editing of standard feed/category. Needs a lot of polishment though.

This commit is contained in:
Martin Rotter 2015-11-04 14:05:33 +01:00
parent 80dbf26e62
commit f131be94b9
11 changed files with 49 additions and 26 deletions

View File

@ -152,6 +152,21 @@ QList<Feed*> 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);
}

View File

@ -157,6 +157,9 @@ class RootItem {
QList<Category*> getSubTreeCategories();
QList<Feed*> 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);

View File

@ -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());

View File

@ -45,8 +45,8 @@ class Feed : public RootItem {
};
enum ReadStatus {
Read = 0,
Unread = 1
Unread = 0,
Read = 1
};
// Constructors.

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -27,6 +27,7 @@
#include "gui/feedmessageviewer.h"
#include "gui/feedsview.h"
#include "services/standard/gui/formstandardcategorydetails.h"
#include "services/standard/standardserviceroot.h"
#include <QVariant>
#include <QSqlQuery>
@ -54,6 +55,10 @@ StandardCategory::~StandardCategory() {
qDebug("Destroying Category instance.");
}
StandardServiceRoot *StandardCategory::serviceRoot() {
return static_cast<StandardServiceRoot*>(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<FormStandardCategoryDetails> form_pointer = new FormStandardCategoryDetails(qApp->mainForm()->tabWidget()->feedMessageViewer()->feedsView()->sourceModel(),
qApp->mainForm());
QPointer<FormStandardCategoryDetails> form_pointer = new FormStandardCategoryDetails(serviceRoot(), qApp->mainForm());
form_pointer.data()->exec(this, NULL);
delete form_pointer.data();
*/
return false;
}

View File

@ -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;

View File

@ -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 <QSqlDatabase>
@ -98,16 +99,15 @@ int StandardFeed::countOfUnreadMessages() const {
return m_unreadCount;
}
StandardServiceRoot *StandardFeed::serviceRoot() {
return static_cast<StandardServiceRoot*>(getParentServiceRoot());
}
bool StandardFeed::editViaDialog() {
// TODO: fix passing of the model
QPointer<FormStandardFeedDetails> form_pointer = new FormStandardFeedDetails(serviceRoot(), qApp->mainForm());
/*
QPointer<FormStandardFeedDetails> form_pointer = new FormStandardFeedDetails(qApp->mainForm()->tabWidget()->feedMessageViewer()->feedsView()->sourceModel(),
qApp->mainForm());
form_pointer.data()->exec(this, NULL);
delete form_pointer.data();
*/
return false;
}

View File

@ -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.

View File

@ -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;
}