diff --git a/src/core/feedsmodel.cpp b/src/core/feedsmodel.cpp index 7eab47079..5a53493cb 100755 --- a/src/core/feedsmodel.cpp +++ b/src/core/feedsmodel.cpp @@ -252,33 +252,6 @@ bool FeedsModel::addCategory(StandardCategory *category, RootItem *parent) { return result; } -bool FeedsModel::editCategory(StandardCategory *original_category, StandardCategory *new_category_data) { - RootItem *original_parent = original_category->parent(); - RootItem *new_parent = new_category_data->parent(); - bool result = original_category->editItself(new_category_data); - - if (result && original_parent != new_parent) { - // User edited category and set it new parent item, - // se we need to move the item in the model too. - int original_index_of_category = original_parent->childItems().indexOf(original_category); - int new_index_of_category = new_parent->childCount(); - - // Remove the original item from the model... - beginRemoveRows(indexForItem(original_parent), original_index_of_category, original_index_of_category); - original_parent->removeChild(original_category); - endRemoveRows(); - - // ...and insert it under the new parent. - beginInsertRows(indexForItem(new_parent), new_index_of_category, new_index_of_category); - new_parent->appendChild(original_category); - endInsertRows(); - } - - // Cleanup temporary new category data. - delete new_category_data; - return result; -} - bool FeedsModel::addFeed(StandardFeed *feed, RootItem *parent) { // Get index of parent item (parent standard category or root item). QModelIndex parent_index = indexForItem(parent); @@ -297,30 +270,25 @@ bool FeedsModel::addFeed(StandardFeed *feed, RootItem *parent) { return result; } -bool FeedsModel::editFeed(StandardFeed *original_feed, StandardFeed *new_feed_data) { - RootItem *original_parent = original_feed->parent(); - RootItem *new_parent = new_feed_data->parent(); - bool result = original_feed->editItself(new_feed_data); +void FeedsModel::reassignNodeToNewParent(RootItem *original_node, RootItem *new_parent) { + RootItem *original_parent = original_node->parent(); - if (result && original_parent != new_parent) { + if (original_parent != new_parent) { // User edited category and set it new parent item, // se we need to move the item in the model too. - int original_index_of_feed = original_parent->childItems().indexOf(original_feed); + int original_index_of_feed = original_parent->childItems().indexOf(original_node); int new_index_of_feed = new_parent->childCount(); // Remove the original item from the model... beginRemoveRows(indexForItem(original_parent), original_index_of_feed, original_index_of_feed); - original_parent->removeChild(original_feed); + original_parent->removeChild(original_node); endRemoveRows(); // ... and insert it under the new parent. beginInsertRows(indexForItem(new_parent), new_index_of_feed, new_index_of_feed); - new_parent->appendChild(original_feed); + new_parent->appendChild(original_node); endInsertRows(); } - - delete new_feed_data; - return result; } QList FeedsModel::feedsForScheduledUpdate(bool auto_update_now) { diff --git a/src/core/feedsmodel.h b/src/core/feedsmodel.h index 215bb9057..96ca0b432 100755 --- a/src/core/feedsmodel.h +++ b/src/core/feedsmodel.h @@ -41,9 +41,6 @@ typedef QPair FeedAssignmentItem; class FeedsModel : public QAbstractItemModel { Q_OBJECT - friend class StandardFeed; - friend class StandardCategory; - public: // Constructors and destructors. explicit FeedsModel(QObject *parent = 0); @@ -75,15 +72,13 @@ class FeedsModel : public QAbstractItemModel { // Standard category manipulators. bool addCategory(StandardCategory *category, RootItem *parent); - bool editCategory(StandardCategory *original_category, StandardCategory *new_category_data); // Standard feed manipulators. bool addFeed(StandardFeed *feed, RootItem *parent); - // New feed is just temporary feed, it is not added to the model. - // It is used to fetch its data to the original feed - // and the original feed is moved if needed. - bool editFeed(StandardFeed *original_feed, StandardFeed *new_feed_data); + // Checks if new parent node is different from one used by original node. + // If it is, then it reassigns original_node to new parent. + void reassignNodeToNewParent(RootItem *original_node, RootItem *new_parent); // Returns the list of feeds which should be updated // according to auto-update schedule. diff --git a/src/core/rootitem.h b/src/core/rootitem.h index 96914ed7f..5fbfd56fc 100755 --- a/src/core/rootitem.h +++ b/src/core/rootitem.h @@ -75,7 +75,7 @@ class RootItem { return false; } - virtual void edit() { + virtual void editViaDialog() { } virtual int row() const; diff --git a/src/gui/feedsview.cpp b/src/gui/feedsview.cpp index d7031146c..9793ca65a 100755 --- a/src/gui/feedsview.cpp +++ b/src/gui/feedsview.cpp @@ -285,7 +285,7 @@ void FeedsView::editSelectedItem() { } if (selectedItem()->canBeEdited()) { - selectedItem()->edit(); + selectedItem()->editViaDialog(); } else { qApp->showGuiMessage(tr("Cannot edit item"), diff --git a/src/services/standard/gui/formstandardcategorydetails.cpp b/src/services/standard/gui/formstandardcategorydetails.cpp index 55af700e2..34bba3718 100755 --- a/src/services/standard/gui/formstandardcategorydetails.cpp +++ b/src/services/standard/gui/formstandardcategorydetails.cpp @@ -133,14 +133,19 @@ void FormStandardCategoryDetails::apply() { } } else { - if (m_feedsModel->editCategory(m_editableCategory, new_category)) { + bool edited = m_editableCategory->editItself(new_category); + + if (edited) { + m_feedsModel->reassignNodeToNewParent(m_editableCategory, new_category->parent()); + + // Remove new temporary feed data holder object. + delete new_category; accept(); } else { qApp->showGuiMessage(tr("Cannot edit category"), tr("Category was not edited due to error."), - QSystemTrayIcon::Critical, - qApp->mainForm(), true); + QSystemTrayIcon::Critical, this, true); } } } diff --git a/src/services/standard/gui/formstandardfeeddetails.cpp b/src/services/standard/gui/formstandardfeeddetails.cpp index f1884a1c4..adf3cf666 100755 --- a/src/services/standard/gui/formstandardfeeddetails.cpp +++ b/src/services/standard/gui/formstandardfeeddetails.cpp @@ -251,7 +251,13 @@ void FormStandardFeedDetails::apply() { } else { // Edit the feed. - if (m_feedsModel->editFeed(m_editableFeed, new_feed)) { + bool edited = m_editableFeed->editItself(new_feed); + + if (edited) { + m_feedsModel->reassignNodeToNewParent(m_editableFeed, new_feed->parent()); + + // Remove new temporary feed data holder object. + delete new_feed; accept(); } else { @@ -264,8 +270,8 @@ void FormStandardFeedDetails::apply() { void FormStandardFeedDetails::guessFeed() { QPair result = StandardFeed::guessFeed(m_ui->m_txtUrl->lineEdit()->text(), - m_ui->m_txtUsername->lineEdit()->text(), - m_ui->m_txtPassword->lineEdit()->text()); + m_ui->m_txtUsername->lineEdit()->text(), + m_ui->m_txtPassword->lineEdit()->text()); if (result.first != NULL) { // Icon or whole feed was guessed. @@ -308,8 +314,8 @@ void FormStandardFeedDetails::guessFeed() { void FormStandardFeedDetails::guessIconOnly() { QPair result = StandardFeed::guessFeed(m_ui->m_txtUrl->lineEdit()->text(), - m_ui->m_txtUsername->lineEdit()->text(), - m_ui->m_txtPassword->lineEdit()->text()); + m_ui->m_txtUsername->lineEdit()->text(), + m_ui->m_txtPassword->lineEdit()->text()); if (result.first != NULL) { // Icon or whole feed was guessed. @@ -476,7 +482,7 @@ void FormStandardFeedDetails::initialize() { } void FormStandardFeedDetails::loadCategories(const QList categories, - RootItem *root_item) { + RootItem *root_item) { m_ui->m_cmbParentCategory->addItem(root_item->icon(), root_item->title(), QVariant::fromValue((void*) root_item)); diff --git a/src/services/standard/standardcategory.cpp b/src/services/standard/standardcategory.cpp index eeae4d9c5..41e46b865 100755 --- a/src/services/standard/standardcategory.cpp +++ b/src/services/standard/standardcategory.cpp @@ -126,7 +126,7 @@ QVariant StandardCategory::data(int column, int role) const { } } -void StandardCategory::edit() { +void StandardCategory::editViaDialog() { // TODO: fix passing of the model QPointer form_pointer = new FormStandardCategoryDetails(qApp->mainForm()->tabWidget()->feedMessageViewer()->feedsView()->sourceModel(), qApp->mainForm()); diff --git a/src/services/standard/standardcategory.h b/src/services/standard/standardcategory.h index eb18a7cc8..9affc61b6 100755 --- a/src/services/standard/standardcategory.h +++ b/src/services/standard/standardcategory.h @@ -50,7 +50,7 @@ class StandardCategory : public RootItem { return true; } - void edit(); + void editViaDialog(); // Removes category and all its children from persistent // database. diff --git a/src/services/standard/standardfeed.cpp b/src/services/standard/standardfeed.cpp index 13d8a244d..5d83d2626 100755 --- a/src/services/standard/standardfeed.cpp +++ b/src/services/standard/standardfeed.cpp @@ -98,7 +98,7 @@ int StandardFeed::countOfUnreadMessages() const { return m_unreadCount; } -void StandardFeed::edit() { +void StandardFeed::editViaDialog() { // TODO: fix passing of the model QPointer form_pointer = new FormStandardFeedDetails(qApp->mainForm()->tabWidget()->feedMessageViewer()->feedsView()->sourceModel(), qApp->mainForm()); diff --git a/src/services/standard/standardfeed.h b/src/services/standard/standardfeed.h index 3c00b8e01..52fe743b5 100755 --- a/src/services/standard/standardfeed.h +++ b/src/services/standard/standardfeed.h @@ -66,7 +66,7 @@ class StandardFeed : public Feed { return true; } - void edit(); + void editViaDialog(); // Obtains data related to this feed. QVariant data(int column, int role) const; diff --git a/src/services/standard/standardserviceroot.cpp b/src/services/standard/standardserviceroot.cpp new file mode 100755 index 000000000..9fb60c691 --- /dev/null +++ b/src/services/standard/standardserviceroot.cpp @@ -0,0 +1,26 @@ +// This file is part of RSS Guard. +// +// Copyright (C) 2011-2015 by Martin Rotter +// +// RSS Guard is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// RSS Guard is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with RSS Guard. If not, see . + +#include "services/standard/standardserviceroot.h" + + +StandardServiceRoot::StandardServiceRoot(RootItem *parent) : ServiceRoot(parent) { +} + +StandardServiceRoot::~StandardServiceRoot() { +} + diff --git a/src/services/standard/standardserviceroot.h b/src/services/standard/standardserviceroot.h new file mode 100755 index 000000000..3664cc37f --- /dev/null +++ b/src/services/standard/standardserviceroot.h @@ -0,0 +1,30 @@ +// This file is part of RSS Guard. +// +// Copyright (C) 2011-2015 by Martin Rotter +// +// RSS Guard is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// RSS Guard is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with RSS Guard. If not, see . + +#ifndef STANDARDSERVICEROOT_H +#define STANDARDSERVICEROOT_H + +#include "services/abstract/serviceroot.h" + + +class StandardServiceRoot : public ServiceRoot { + public: + explicit StandardServiceRoot(RootItem *parent = NULL); + virtual ~StandardServiceRoot(); +}; + +#endif // STANDARDSERVICEROOT_H diff --git a/src/services/tt-rss/ttrssserviceroot.cpp b/src/services/tt-rss/ttrssserviceroot.cpp new file mode 100755 index 000000000..338d30bae --- /dev/null +++ b/src/services/tt-rss/ttrssserviceroot.cpp @@ -0,0 +1,26 @@ +// This file is part of RSS Guard. +// +// Copyright (C) 2011-2015 by Martin Rotter +// +// RSS Guard is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// RSS Guard is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with RSS Guard. If not, see . + +#include "services/tt-rss/ttrssserviceroot.h" + + +TtRssServiceRoot::TtRssServiceRoot(RootItem *parent) : ServiceRoot(parent) { +} + +TtRssServiceRoot::~TtRssServiceRoot() { +} + diff --git a/src/services/tt-rss/ttrssserviceroot.h b/src/services/tt-rss/ttrssserviceroot.h new file mode 100755 index 000000000..e98f585bf --- /dev/null +++ b/src/services/tt-rss/ttrssserviceroot.h @@ -0,0 +1,30 @@ +// This file is part of RSS Guard. +// +// Copyright (C) 2011-2015 by Martin Rotter +// +// RSS Guard is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// RSS Guard is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with RSS Guard. If not, see . + +#ifndef TTRSSSERVICEROOT_H +#define TTRSSSERVICEROOT_H + +#include "services/abstract/serviceroot.h" + + +class TtRssServiceRoot : public ServiceRoot { + public: + explicit TtRssServiceRoot(RootItem *parent = NULL); + virtual ~TtRssServiceRoot(); +}; + +#endif // TTRSSSERVICEROOT_H