Added service root node classes and refactored editing of feeds/cats.

This commit is contained in:
Martin Rotter 2015-10-30 11:41:02 +01:00
parent d390ea2df6
commit fa373df15c
14 changed files with 147 additions and 61 deletions

View File

@ -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<Feed*> FeedsModel::feedsForScheduledUpdate(bool auto_update_now) {

View File

@ -41,9 +41,6 @@ typedef QPair<int, StandardFeed*> 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.

View File

@ -75,7 +75,7 @@ class RootItem {
return false;
}
virtual void edit() {
virtual void editViaDialog() {
}
virtual int row() const;

View File

@ -285,7 +285,7 @@ void FeedsView::editSelectedItem() {
}
if (selectedItem()->canBeEdited()) {
selectedItem()->edit();
selectedItem()->editViaDialog();
}
else {
qApp->showGuiMessage(tr("Cannot edit item"),

View File

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

View File

@ -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<StandardFeed*, QNetworkReply::NetworkError> 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<StandardFeed*, QNetworkReply::NetworkError> 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<StandardCategory*> categories,
RootItem *root_item) {
RootItem *root_item) {
m_ui->m_cmbParentCategory->addItem(root_item->icon(),
root_item->title(),
QVariant::fromValue((void*) root_item));

View File

@ -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<FormStandardCategoryDetails> form_pointer = new FormStandardCategoryDetails(qApp->mainForm()->tabWidget()->feedMessageViewer()->feedsView()->sourceModel(),
qApp->mainForm());

View File

@ -50,7 +50,7 @@ class StandardCategory : public RootItem {
return true;
}
void edit();
void editViaDialog();
// Removes category and all its children from persistent
// database.

View File

@ -98,7 +98,7 @@ int StandardFeed::countOfUnreadMessages() const {
return m_unreadCount;
}
void StandardFeed::edit() {
void StandardFeed::editViaDialog() {
// TODO: fix passing of the model
QPointer<FormStandardFeedDetails> form_pointer = new FormStandardFeedDetails(qApp->mainForm()->tabWidget()->feedMessageViewer()->feedsView()->sourceModel(),
qApp->mainForm());

View File

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

View File

@ -0,0 +1,26 @@
// This file is part of RSS Guard.
//
// Copyright (C) 2011-2015 by Martin Rotter <rotter.martinos@gmail.com>
//
// 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 <http://www.gnu.org/licenses/>.
#include "services/standard/standardserviceroot.h"
StandardServiceRoot::StandardServiceRoot(RootItem *parent) : ServiceRoot(parent) {
}
StandardServiceRoot::~StandardServiceRoot() {
}

View File

@ -0,0 +1,30 @@
// This file is part of RSS Guard.
//
// Copyright (C) 2011-2015 by Martin Rotter <rotter.martinos@gmail.com>
//
// 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 <http://www.gnu.org/licenses/>.
#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

View File

@ -0,0 +1,26 @@
// This file is part of RSS Guard.
//
// Copyright (C) 2011-2015 by Martin Rotter <rotter.martinos@gmail.com>
//
// 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 <http://www.gnu.org/licenses/>.
#include "services/tt-rss/ttrssserviceroot.h"
TtRssServiceRoot::TtRssServiceRoot(RootItem *parent) : ServiceRoot(parent) {
}
TtRssServiceRoot::~TtRssServiceRoot() {
}

View File

@ -0,0 +1,30 @@
// This file is part of RSS Guard.
//
// Copyright (C) 2011-2015 by Martin Rotter <rotter.martinos@gmail.com>
//
// 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 <http://www.gnu.org/licenses/>.
#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