From ad2af43af299e4e1a1257ca931325dd82d14bdbe Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Wed, 20 Sep 2017 15:03:44 +0200 Subject: [PATCH] Refactored redundant category classes. --- rssguard.pro | 10 ++--- src/miscellaneous/databasequeries.cpp | 6 +-- src/services/abstract/category.cpp | 22 +++++++++ src/services/abstract/category.h | 1 + .../network/owncloudnetworkfactory.cpp | 4 +- src/services/owncloud/owncloudcategory.cpp | 41 ----------------- src/services/owncloud/owncloudcategory.h | 38 ---------------- src/services/owncloud/owncloudserviceroot.cpp | 1 - src/services/standard/standardcategory.cpp | 9 +--- .../tt-rss/gui/formttrssfeeddetails.cpp | 11 ++--- .../tt-rss/network/ttrssnetworkfactory.cpp | 4 +- src/services/tt-rss/ttrsscategory.cpp | 45 ------------------- src/services/tt-rss/ttrsscategory.h | 39 ---------------- src/services/tt-rss/ttrssfeed.cpp | 3 +- src/services/tt-rss/ttrssserviceroot.cpp | 1 - 15 files changed, 38 insertions(+), 197 deletions(-) delete mode 100755 src/services/owncloud/owncloudcategory.cpp delete mode 100755 src/services/owncloud/owncloudcategory.h delete mode 100755 src/services/tt-rss/ttrsscategory.cpp delete mode 100755 src/services/tt-rss/ttrsscategory.h diff --git a/rssguard.pro b/rssguard.pro index 9d609dab8..6ca301ba6 100755 --- a/rssguard.pro +++ b/rssguard.pro @@ -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 diff --git a/src/miscellaneous/databasequeries.cpp b/src/miscellaneous/databasequeries.cpp index 592959841..1bd33a679 100755 --- a/src/miscellaneous/databasequeries.cpp +++ b/src/miscellaneous/databasequeries.cpp @@ -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; } diff --git a/src/services/abstract/category.cpp b/src/services/abstract/category.cpp index ab41480cc..6811ce3aa 100755 --- a/src/services/abstract/category.cpp +++ b/src/services/abstract/category.cpp @@ -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()).toLocalTime()); + + setIcon(qApp->icons()->fromByteArray(record.value(CAT_DB_ICON_INDEX).toByteArray())); } Category::~Category() {} diff --git a/src/services/abstract/category.h b/src/services/abstract/category.h index ae2aa0f67..e7c38d8cd 100755 --- a/src/services/abstract/category.h +++ b/src/services/abstract/category.h @@ -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); diff --git a/src/services/owncloud/network/owncloudnetworkfactory.cpp b/src/services/owncloud/network/owncloudnetworkfactory.cpp index 188688b10..6127ab161 100755 --- a/src/services/owncloud/network/owncloudnetworkfactory.cpp +++ b/src/services/owncloud/network/owncloudnetworkfactory.cpp @@ -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 @@ -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()); diff --git a/src/services/owncloud/owncloudcategory.cpp b/src/services/owncloud/owncloudcategory.cpp deleted file mode 100755 index b1c361f3e..000000000 --- a/src/services/owncloud/owncloudcategory.cpp +++ /dev/null @@ -1,41 +0,0 @@ -// This file is part of RSS Guard. - -// -// Copyright (C) 2011-2017 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/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(getParentServiceRoot()); -} - -OwnCloudCategory::~OwnCloudCategory() {} diff --git a/src/services/owncloud/owncloudcategory.h b/src/services/owncloud/owncloudcategory.h deleted file mode 100755 index 0bbea5fd1..000000000 --- a/src/services/owncloud/owncloudcategory.h +++ /dev/null @@ -1,38 +0,0 @@ -// This file is part of RSS Guard. - -// -// Copyright (C) 2011-2017 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 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 diff --git a/src/services/owncloud/owncloudserviceroot.cpp b/src/services/owncloud/owncloudserviceroot.cpp index 680205689..131a016a5 100755 --- a/src/services/owncloud/owncloudserviceroot.cpp +++ b/src/services/owncloud/owncloudserviceroot.cpp @@ -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" diff --git a/src/services/standard/standardcategory.cpp b/src/services/standard/standardcategory.cpp index 27624eb04..b8274654f 100755 --- a/src/services/standard/standardcategory.cpp +++ b/src/services/standard/standardcategory.cpp @@ -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()).toLocalTime()); - setIcon(qApp->icons()->fromByteArray(record.value(CAT_DB_ICON_INDEX).toByteArray())); -} +StandardCategory::StandardCategory(const QSqlRecord& record) : Category(record) {} diff --git a/src/services/tt-rss/gui/formttrssfeeddetails.cpp b/src/services/tt-rss/gui/formttrssfeeddetails.cpp index 5a3a93971..2f1ea5b47 100755 --- a/src/services/tt-rss/gui/formttrssfeeddetails.cpp +++ b/src/services/tt-rss/gui/formttrssfeeddetails.cpp @@ -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(m_ui->m_cmbParentCategory->itemData(m_ui->m_cmbParentCategory->currentIndex()).value()); - TtRssServiceRoot* root = parent->kind() == RootItemKind::Category ? - qobject_cast(parent)->serviceRoot() : - qobject_cast(parent); + RootItem* parent = static_cast(m_ui->m_cmbParentCategory->itemData( + m_ui->m_cmbParentCategory->currentIndex()).value()); + TtRssServiceRoot* root = qobject_cast(parent->getParentServiceRoot()); const int category_id = parent->kind() == RootItemKind::ServiceRoot ? 0 : - qobject_cast(parent)->customId(); + parent->customId(); const TtRssSubscribeToFeedResponse response = root->network()->subscribeToFeed(m_ui->m_txtUrl->lineEdit()->text(), category_id, m_ui->m_gbAuthentication->isChecked(), diff --git a/src/services/tt-rss/network/ttrssnetworkfactory.cpp b/src/services/tt-rss/network/ttrssnetworkfactory.cpp index 2e9194117..a9117e535 100755 --- a/src/services/tt-rss/network/ttrssnetworkfactory.cpp +++ b/src/services/tt-rss/network/ttrssnetworkfactory.cpp @@ -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 @@ -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); diff --git a/src/services/tt-rss/ttrsscategory.cpp b/src/services/tt-rss/ttrsscategory.cpp deleted file mode 100755 index 4cd4ba8a8..000000000 --- a/src/services/tt-rss/ttrsscategory.cpp +++ /dev/null @@ -1,45 +0,0 @@ -// This file is part of RSS Guard. - -// -// Copyright (C) 2011-2017 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/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 - -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(getParentServiceRoot()); -} diff --git a/src/services/tt-rss/ttrsscategory.h b/src/services/tt-rss/ttrsscategory.h deleted file mode 100755 index 2b836aee5..000000000 --- a/src/services/tt-rss/ttrsscategory.h +++ /dev/null @@ -1,39 +0,0 @@ -// This file is part of RSS Guard. - -// -// Copyright (C) 2011-2017 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 TTRSSCATEGORY_H -#define TTRSSCATEGORY_H - -#include "services/abstract/category.h" - -#include - -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 diff --git a/src/services/tt-rss/ttrssfeed.cpp b/src/services/tt-rss/ttrssfeed.cpp index dba296b9b..61a7f4726 100755 --- a/src/services/tt-rss/ttrssfeed.cpp +++ b/src/services/tt-rss/ttrssfeed.cpp @@ -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 @@ -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())) { diff --git a/src/services/tt-rss/ttrssserviceroot.cpp b/src/services/tt-rss/ttrssserviceroot.cpp index 326e2c5ee..4bd1c02a8 100755 --- a/src/services/tt-rss/ttrssserviceroot.cpp +++ b/src/services/tt-rss/ttrssserviceroot.cpp @@ -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"