Refactored redundant category classes.

This commit is contained in:
Martin Rotter 2017-09-20 15:03:44 +02:00
parent f10ee91194
commit ad2af43af2
15 changed files with 38 additions and 197 deletions

@ -296,7 +296,6 @@ HEADERS += src/core/feeddownloader.h \
src/services/owncloud/gui/formeditowncloudaccount.h \
src/services/owncloud/gui/formowncloudfeeddetails.h \
src/services/owncloud/network/owncloudnetworkfactory.h \
src/services/owncloud/owncloudcategory.h \
src/services/owncloud/owncloudfeed.h \
src/services/owncloud/owncloudserviceentrypoint.h \
src/services/owncloud/owncloudserviceroot.h \
@ -311,7 +310,6 @@ HEADERS += src/core/feeddownloader.h \
src/services/tt-rss/definitions.h \
src/services/tt-rss/gui/formttrssfeeddetails.h \
src/services/tt-rss/network/ttrssnetworkfactory.h \
src/services/tt-rss/ttrsscategory.h \
src/services/tt-rss/ttrssfeed.h \
src/services/tt-rss/ttrssserviceentrypoint.h \
src/services/tt-rss/ttrssserviceroot.h \
@ -338,8 +336,8 @@ HEADERS += src/core/feeddownloader.h \
src/services/abstract/labelsrootitem.h \
src/services/abstract/label.h \
src/miscellaneous/externaltool.h \
src/services/inoreader/definitions.h \
src/services/inoreader/inoreaderentrypoint.h
src/services/inoreader/definitions.h \
src/services/inoreader/inoreaderentrypoint.h
SOURCES += src/core/feeddownloader.cpp \
src/core/feedsmodel.cpp \
@ -423,7 +421,6 @@ SOURCES += src/core/feeddownloader.cpp \
src/services/owncloud/gui/formeditowncloudaccount.cpp \
src/services/owncloud/gui/formowncloudfeeddetails.cpp \
src/services/owncloud/network/owncloudnetworkfactory.cpp \
src/services/owncloud/owncloudcategory.cpp \
src/services/owncloud/owncloudfeed.cpp \
src/services/owncloud/owncloudserviceentrypoint.cpp \
src/services/owncloud/owncloudserviceroot.cpp \
@ -437,7 +434,6 @@ SOURCES += src/core/feeddownloader.cpp \
src/services/standard/standardserviceroot.cpp \
src/services/tt-rss/gui/formttrssfeeddetails.cpp \
src/services/tt-rss/network/ttrssnetworkfactory.cpp \
src/services/tt-rss/ttrsscategory.cpp \
src/services/tt-rss/ttrssfeed.cpp \
src/services/tt-rss/ttrssserviceentrypoint.cpp \
src/services/tt-rss/ttrssserviceroot.cpp \
@ -464,7 +460,7 @@ SOURCES += src/core/feeddownloader.cpp \
src/services/abstract/labelsrootitem.cpp \
src/services/abstract/label.cpp \
src/miscellaneous/externaltool.cpp \
src/services/inoreader/inoreaderentrypoint.cpp
src/services/inoreader/inoreaderentrypoint.cpp
OBJECTIVE_SOURCES += src/miscellaneous/disablewindowtabbing.mm

@ -23,14 +23,12 @@
#include "miscellaneous/textfactory.h"
#include "services/abstract/category.h"
#include "services/owncloud/network/owncloudnetworkfactory.h"
#include "services/owncloud/owncloudcategory.h"
#include "services/owncloud/owncloudfeed.h"
#include "services/owncloud/owncloudserviceroot.h"
#include "services/standard/standardcategory.h"
#include "services/standard/standardfeed.h"
#include "services/standard/standardserviceroot.h"
#include "services/tt-rss/network/ttrssnetworkfactory.h"
#include "services/tt-rss/ttrsscategory.h"
#include "services/tt-rss/ttrssfeed.h"
#include "services/tt-rss/ttrssserviceroot.h"
@ -1061,7 +1059,7 @@ Assignment DatabaseQueries::getOwnCloudCategories(QSqlDatabase db, int account_i
AssignmentItem pair;
pair.first = q.value(CAT_DB_PARENT_ID_INDEX).toInt();
pair.second = new OwnCloudCategory(q.record());
pair.second = new Category(q.record());
categories << pair;
}
@ -1504,7 +1502,7 @@ Assignment DatabaseQueries::getTtRssCategories(QSqlDatabase db, int account_id,
AssignmentItem pair;
pair.first = query_categories.value(CAT_DB_PARENT_ID_INDEX).toInt();
pair.second = new TtRssCategory(query_categories.record());
pair.second = new Category(query_categories.record());
categories << pair;
}

@ -20,12 +20,34 @@
#include "miscellaneous/application.h"
#include "miscellaneous/databasequeries.h"
#include "miscellaneous/iconfactory.h"
#include "miscellaneous/textfactory.h"
#include "services/abstract/cacheforserviceroot.h"
#include "services/abstract/feed.h"
#include "services/abstract/serviceroot.h"
Category::Category(RootItem* parent) : RootItem(parent) {
setKind(RootItemKind::Category);
if (icon().isNull()) {
setIcon(qApp->icons()->fromTheme(QSL("folder")));
}
}
Category::Category(const QSqlRecord& record) : Category(nullptr) {
setId(record.value(CAT_DB_ID_INDEX).toInt());
setCustomId(record.value(CAT_DB_CUSTOM_ID_INDEX).toInt());
if (customId() <= 0) {
setCustomId(id());
}
setTitle(record.value(CAT_DB_TITLE_INDEX).toString());
setDescription(record.value(CAT_DB_DESCRIPTION_INDEX).toString());
setCreationDate(TextFactory::parseDateTime(record.value(CAT_DB_DCREATED_INDEX).value<qint64>()).toLocalTime());
setIcon(qApp->icons()->fromByteArray(record.value(CAT_DB_ICON_INDEX).toByteArray()));
}
Category::~Category() {}

@ -26,6 +26,7 @@ class Category : public RootItem {
public:
explicit Category(RootItem* parent = nullptr);
explicit Category(const QSqlRecord& record);
virtual ~Category();
void updateCounts(bool including_total_count);

@ -22,9 +22,9 @@
#include "miscellaneous/settings.h"
#include "miscellaneous/textfactory.h"
#include "network-web/networkfactory.h"
#include "services/abstract/category.h"
#include "services/abstract/rootitem.h"
#include "services/owncloud/definitions.h"
#include "services/owncloud/owncloudcategory.h"
#include "services/owncloud/owncloudfeed.h"
#include <QJsonArray>
@ -486,7 +486,7 @@ RootItem* OwnCloudGetFeedsCategoriesResponse::feedsCategories(bool obtain_icons)
// Process categories first, then process feeds.
foreach (const QJsonValue& cat, QJsonDocument::fromJson(m_contentCategories.toUtf8()).object()["folders"].toArray()) {
QJsonObject item = cat.toObject();
OwnCloudCategory* category = new OwnCloudCategory();
Category* category = new Category();
category->setTitle(item["name"].toString());
category->setCustomId(item["id"].toInt());

@ -1,41 +0,0 @@
// This file is part of RSS Guard.
//
// Copyright (C) 2011-2017 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/owncloud/owncloudcategory.h"
#include "miscellaneous/application.h"
#include "miscellaneous/iconfactory.h"
#include "services/owncloud/owncloudserviceroot.h"
OwnCloudCategory::OwnCloudCategory(RootItem* parent) : Category(parent) {
// Categories in ownCloud have now icons etc. They just have titles.
setIcon(qApp->icons()->fromTheme(QSL("folder")));
}
OwnCloudCategory::OwnCloudCategory(const QSqlRecord& record) : Category(nullptr) {
setIcon(qApp->icons()->fromTheme(QSL("folder")));
setId(record.value(CAT_DB_ID_INDEX).toInt());
setTitle(record.value(CAT_DB_TITLE_INDEX).toString());
setCustomId(record.value(CAT_DB_CUSTOM_ID_INDEX).toInt());
}
OwnCloudServiceRoot* OwnCloudCategory::serviceRoot() const {
return qobject_cast<OwnCloudServiceRoot*>(getParentServiceRoot());
}
OwnCloudCategory::~OwnCloudCategory() {}

@ -1,38 +0,0 @@
// This file is part of RSS Guard.
//
// Copyright (C) 2011-2017 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 OWNCLOUDSERVICECATEGORY_H
#define OWNCLOUDSERVICECATEGORY_H
#include "services/abstract/category.h"
class OwnCloudServiceRoot;
class OwnCloudCategory : public Category {
Q_OBJECT
public:
explicit OwnCloudCategory(RootItem* parent = nullptr);
explicit OwnCloudCategory(const QSqlRecord& record);
virtual ~OwnCloudCategory();
private:
OwnCloudServiceRoot* serviceRoot() const;
};
#endif // OWNCLOUDSERVICECATEGORY_H

@ -28,7 +28,6 @@
#include "services/owncloud/gui/formeditowncloudaccount.h"
#include "services/owncloud/gui/formowncloudfeeddetails.h"
#include "services/owncloud/network/owncloudnetworkfactory.h"
#include "services/owncloud/owncloudcategory.h"
#include "services/owncloud/owncloudfeed.h"
#include "services/owncloud/owncloudserviceentrypoint.h"

@ -174,11 +174,4 @@ bool StandardCategory::editItself(StandardCategory* new_category_data) {
}
}
StandardCategory::StandardCategory(const QSqlRecord& record) : Category(nullptr) {
setId(record.value(CAT_DB_ID_INDEX).toInt());
setCustomId(id());
setTitle(record.value(CAT_DB_TITLE_INDEX).toString());
setDescription(record.value(CAT_DB_DESCRIPTION_INDEX).toString());
setCreationDate(TextFactory::parseDateTime(record.value(CAT_DB_DCREATED_INDEX).value<qint64>()).toLocalTime());
setIcon(qApp->icons()->fromByteArray(record.value(CAT_DB_ICON_INDEX).toByteArray()));
}
StandardCategory::StandardCategory(const QSqlRecord& record) : Category(record) {}

@ -21,7 +21,6 @@
#include "miscellaneous/application.h"
#include "services/tt-rss/definitions.h"
#include "services/tt-rss/network/ttrssnetworkfactory.h"
#include "services/tt-rss/ttrsscategory.h"
#include "services/tt-rss/ttrssfeed.h"
#include "services/tt-rss/ttrssserviceroot.h"
@ -51,14 +50,12 @@ void FormTtRssFeedDetails::apply() {
delete new_feed_data;
}
else {
RootItem* parent =
static_cast<RootItem*>(m_ui->m_cmbParentCategory->itemData(m_ui->m_cmbParentCategory->currentIndex()).value<void*>());
TtRssServiceRoot* root = parent->kind() == RootItemKind::Category ?
qobject_cast<TtRssCategory*>(parent)->serviceRoot() :
qobject_cast<TtRssServiceRoot*>(parent);
RootItem* parent = static_cast<RootItem*>(m_ui->m_cmbParentCategory->itemData(
m_ui->m_cmbParentCategory->currentIndex()).value<void*>());
TtRssServiceRoot* root = qobject_cast<TtRssServiceRoot*>(parent->getParentServiceRoot());
const int category_id = parent->kind() == RootItemKind::ServiceRoot ?
0 :
qobject_cast<TtRssCategory*>(parent)->customId();
parent->customId();
const TtRssSubscribeToFeedResponse response = root->network()->subscribeToFeed(m_ui->m_txtUrl->lineEdit()->text(),
category_id,
m_ui->m_gbAuthentication->isChecked(),

@ -23,9 +23,9 @@
#include "miscellaneous/iconfactory.h"
#include "miscellaneous/textfactory.h"
#include "network-web/networkfactory.h"
#include "services/abstract/category.h"
#include "services/abstract/rootitem.h"
#include "services/tt-rss/definitions.h"
#include "services/tt-rss/ttrsscategory.h"
#include "services/tt-rss/ttrssfeed.h"
#include <QJsonArray>
@ -502,7 +502,7 @@ RootItem* TtRssGetFeedsCategoriesResponse::feedsCategories(bool obtain_icons, QS
}
}
else {
TtRssCategory* category = new TtRssCategory();
Category* category = new Category();
category->setTitle(item["name"].toString());
category->setCustomId(item_id);

@ -1,45 +0,0 @@
// This file is part of RSS Guard.
//
// Copyright (C) 2011-2017 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/ttrsscategory.h"
#include "definitions/definitions.h"
#include "miscellaneous/application.h"
#include "miscellaneous/iconfactory.h"
#include "services/tt-rss/definitions.h"
#include "services/tt-rss/network/ttrssnetworkfactory.h"
#include "services/tt-rss/ttrssserviceroot.h"
#include <QVariant>
TtRssCategory::TtRssCategory(RootItem* parent) : Category(parent) {
setIcon(qApp->icons()->fromTheme(QSL("folder")));
}
TtRssCategory::TtRssCategory(const QSqlRecord& record) : Category(nullptr) {
setIcon(qApp->icons()->fromTheme(QSL("folder")));
setId(record.value(CAT_DB_ID_INDEX).toInt());
setTitle(record.value(CAT_DB_TITLE_INDEX).toString());
setCustomId(record.value(CAT_DB_CUSTOM_ID_INDEX).toInt());
}
TtRssCategory::~TtRssCategory() {}
TtRssServiceRoot* TtRssCategory::serviceRoot() const {
return qobject_cast<TtRssServiceRoot*>(getParentServiceRoot());
}

@ -1,39 +0,0 @@
// This file is part of RSS Guard.
//
// Copyright (C) 2011-2017 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 TTRSSCATEGORY_H
#define TTRSSCATEGORY_H
#include "services/abstract/category.h"
#include <QSqlRecord>
class TtRssServiceRoot;
class TtRssCategory : public Category {
Q_OBJECT
public:
explicit TtRssCategory(RootItem* parent = nullptr);
explicit TtRssCategory(const QSqlRecord& record);
virtual ~TtRssCategory();
TtRssServiceRoot* serviceRoot() const;
};
#endif // TTRSSCATEGORY_H

@ -26,7 +26,6 @@
#include "services/tt-rss/definitions.h"
#include "services/tt-rss/gui/formttrssfeeddetails.h"
#include "services/tt-rss/network/ttrssnetworkfactory.h"
#include "services/tt-rss/ttrsscategory.h"
#include "services/tt-rss/ttrssserviceroot.h"
#include <QPointer>
@ -79,7 +78,7 @@ bool TtRssFeed::deleteViaGui() {
}
bool TtRssFeed::editItself(TtRssFeed* new_feed_data) {
QSqlDatabase database = qApp->database()->connection("aa", DatabaseFactory::FromSettings);
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
if (DatabaseQueries::editBaseFeed(database, id(), new_feed_data->autoUpdateType(),
new_feed_data->autoUpdateInitialInterval())) {

@ -30,7 +30,6 @@
#include "services/tt-rss/gui/formeditttrssaccount.h"
#include "services/tt-rss/gui/formttrssfeeddetails.h"
#include "services/tt-rss/network/ttrssnetworkfactory.h"
#include "services/tt-rss/ttrsscategory.h"
#include "services/tt-rss/ttrssfeed.h"
#include "services/tt-rss/ttrssserviceentrypoint.h"