Refactorings.
This commit is contained in:
parent
c7cbb5fe8e
commit
9d6c42002d
15 changed files with 15 additions and 94 deletions
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
#include "core/messagefilter.h"
|
#include "core/messagefilter.h"
|
||||||
#include "definitions/typedefs.h"
|
#include "definitions/typedefs.h"
|
||||||
|
#include "miscellaneous/application.h"
|
||||||
#include "miscellaneous/textfactory.h"
|
#include "miscellaneous/textfactory.h"
|
||||||
#include "services/abstract/category.h"
|
#include "services/abstract/category.h"
|
||||||
#include "services/abstract/label.h"
|
#include "services/abstract/label.h"
|
||||||
|
@ -325,9 +326,9 @@ Assignment DatabaseQueries::getFeeds(const QSqlDatabase& db,
|
||||||
|
|
||||||
template<typename Categ, typename Fee>
|
template<typename Categ, typename Fee>
|
||||||
void DatabaseQueries::loadFromDatabase(ServiceRoot* root) {
|
void DatabaseQueries::loadFromDatabase(ServiceRoot* root) {
|
||||||
QSqlDatabase database = root->internalDatabase();
|
QSqlDatabase database = qApp->database()->connection(root->metaObject()->className());
|
||||||
Assignment categories = DatabaseQueries::getCategories<Categ>(database, root->accountId());
|
Assignment categories = DatabaseQueries::getCategories<Categ>(database, root->accountId());
|
||||||
Assignment feeds = DatabaseQueries::getFeeds<Fee>(database, root->internalFilters(), root->accountId());
|
Assignment feeds = DatabaseQueries::getFeeds<Fee>(database, qApp->feedReader()->messageFilters(), root->accountId());
|
||||||
auto labels = DatabaseQueries::getLabels(database, root->accountId());
|
auto labels = DatabaseQueries::getLabels(database, root->accountId());
|
||||||
|
|
||||||
root->performInitialAssembly(categories, feeds, labels);
|
root->performInitialAssembly(categories, feeds, labels);
|
||||||
|
|
|
@ -336,14 +336,6 @@ void ServiceRoot::restoreCustomFeedsData(const QMap<QString, QVariantMap>& data,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QSqlDatabase ServiceRoot::internalDatabase() const {
|
|
||||||
return qApp->database()->connection(metaObject()->className());
|
|
||||||
}
|
|
||||||
|
|
||||||
QList<MessageFilter*> ServiceRoot::internalFilters() const {
|
|
||||||
return qApp->feedReader()->messageFilters();
|
|
||||||
}
|
|
||||||
|
|
||||||
QNetworkProxy ServiceRoot::networkProxy() const {
|
QNetworkProxy ServiceRoot::networkProxy() const {
|
||||||
return m_networkProxy;
|
return m_networkProxy;
|
||||||
}
|
}
|
||||||
|
|
|
@ -200,11 +200,6 @@ class ServiceRoot : public RootItem {
|
||||||
|
|
||||||
void performInitialAssembly(const Assignment& categories, const Assignment& feeds, const QList<Label*>& labels);
|
void performInitialAssembly(const Assignment& categories, const Assignment& feeds, const QList<Label*>& labels);
|
||||||
|
|
||||||
// Helper methods to keep "application.h" inclusion
|
|
||||||
// out of this file.
|
|
||||||
QSqlDatabase internalDatabase() const;
|
|
||||||
QList<MessageFilter*> internalFilters() const;
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
virtual void addNewFeed(RootItem* selected_item, const QString& url = QString());
|
virtual void addNewFeed(RootItem* selected_item, const QString& url = QString());
|
||||||
virtual void addNewCategory(RootItem* selected_item);
|
virtual void addNewCategory(RootItem* selected_item);
|
||||||
|
|
|
@ -46,7 +46,7 @@ bool FeedlyServiceRoot::editViaGui() {
|
||||||
|
|
||||||
void FeedlyServiceRoot::start(bool freshly_activated) {
|
void FeedlyServiceRoot::start(bool freshly_activated) {
|
||||||
if (!freshly_activated) {
|
if (!freshly_activated) {
|
||||||
loadFromDatabase();
|
DatabaseQueries::loadFromDatabase<Category, FeedlyFeed>(this);
|
||||||
loadCacheFromFile();
|
loadCacheFromFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -204,12 +204,3 @@ RootItem* FeedlyServiceRoot::obtainNewTreeForSyncIn() const {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FeedlyServiceRoot::loadFromDatabase() {
|
|
||||||
QSqlDatabase database = qApp->database()->connection(metaObject()->className());
|
|
||||||
Assignment categories = DatabaseQueries::getCategories<Category>(database, accountId());
|
|
||||||
Assignment feeds = DatabaseQueries::getFeeds<FeedlyFeed>(database, qApp->feedReader()->messageFilters(), accountId());
|
|
||||||
auto labels = DatabaseQueries::getLabels(database, accountId());
|
|
||||||
|
|
||||||
performInitialAssembly(categories, feeds, labels);
|
|
||||||
}
|
|
||||||
|
|
|
@ -29,9 +29,6 @@ class FeedlyServiceRoot : public ServiceRoot, public CacheForServiceRoot {
|
||||||
protected:
|
protected:
|
||||||
virtual RootItem* obtainNewTreeForSyncIn() const;
|
virtual RootItem* obtainNewTreeForSyncIn() const;
|
||||||
|
|
||||||
private:
|
|
||||||
void loadFromDatabase();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FeedlyNetwork* m_network;
|
FeedlyNetwork* m_network;
|
||||||
};
|
};
|
||||||
|
|
|
@ -50,21 +50,6 @@ void GmailServiceRoot::writeNewEmail() {
|
||||||
FormAddEditEmail(this, qApp->mainFormWidget()).execForAdd();
|
FormAddEditEmail(this, qApp->mainFormWidget()).execForAdd();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GmailServiceRoot::loadFromDatabase() {
|
|
||||||
QSqlDatabase database = qApp->database()->connection(metaObject()->className());
|
|
||||||
Assignment categories = DatabaseQueries::getCategories<Category>(database, accountId());
|
|
||||||
Assignment feeds = DatabaseQueries::getFeeds<GmailFeed>(database, qApp->feedReader()->messageFilters(), accountId());
|
|
||||||
auto labels = DatabaseQueries::getLabels(database, accountId());
|
|
||||||
|
|
||||||
performInitialAssembly(categories, feeds, labels);
|
|
||||||
|
|
||||||
for (RootItem* feed : childItems()) {
|
|
||||||
if (feed->customId() == QL1S("INBOX")) {
|
|
||||||
feed->setKeepOnTop(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool GmailServiceRoot::downloadAttachmentOnMyOwn(const QUrl& url) const {
|
bool GmailServiceRoot::downloadAttachmentOnMyOwn(const QUrl& url) const {
|
||||||
QString str_url = url.toString();
|
QString str_url = url.toString();
|
||||||
QString attachment_id = str_url.mid(str_url.indexOf(QL1C('?')) + 1);
|
QString attachment_id = str_url.mid(str_url.indexOf(QL1C('?')) + 1);
|
||||||
|
@ -138,7 +123,7 @@ bool GmailServiceRoot::supportsCategoryAdding() const {
|
||||||
|
|
||||||
void GmailServiceRoot::start(bool freshly_activated) {
|
void GmailServiceRoot::start(bool freshly_activated) {
|
||||||
if (!freshly_activated) {
|
if (!freshly_activated) {
|
||||||
loadFromDatabase();
|
DatabaseQueries::loadFromDatabase<Category, GmailFeed>(this);
|
||||||
loadCacheFromFile();
|
loadCacheFromFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,6 +133,12 @@ void GmailServiceRoot::start(bool freshly_activated) {
|
||||||
syncIn();
|
syncIn();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (RootItem* feed : childItems()) {
|
||||||
|
if (feed->customId() == QL1S("INBOX")) {
|
||||||
|
feed->setKeepOnTop(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
m_network->oauth()->login();
|
m_network->oauth()->login();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,6 @@ class GmailServiceRoot : public ServiceRoot, public CacheForServiceRoot {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void writeNewEmail();
|
void writeNewEmail();
|
||||||
void loadFromDatabase();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GmailNetworkFactory* m_network;
|
GmailNetworkFactory* m_network;
|
||||||
|
|
|
@ -37,7 +37,7 @@ bool GreaderServiceRoot::editViaGui() {
|
||||||
|
|
||||||
void GreaderServiceRoot::start(bool freshly_activated) {
|
void GreaderServiceRoot::start(bool freshly_activated) {
|
||||||
if (!freshly_activated) {
|
if (!freshly_activated) {
|
||||||
loadFromDatabase();
|
DatabaseQueries::loadFromDatabase<Category, GreaderFeed>(this);
|
||||||
loadCacheFromFile();
|
loadCacheFromFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,12 +158,3 @@ void GreaderServiceRoot::updateTitleIcon() {
|
||||||
RootItem* GreaderServiceRoot::obtainNewTreeForSyncIn() const {
|
RootItem* GreaderServiceRoot::obtainNewTreeForSyncIn() const {
|
||||||
return m_network->categoriesFeedsLabelsTree(true, networkProxy());
|
return m_network->categoriesFeedsLabelsTree(true, networkProxy());
|
||||||
}
|
}
|
||||||
|
|
||||||
void GreaderServiceRoot::loadFromDatabase() {
|
|
||||||
QSqlDatabase database = qApp->database()->connection(metaObject()->className());
|
|
||||||
Assignment categories = DatabaseQueries::getCategories<Category>(database, accountId());
|
|
||||||
Assignment feeds = DatabaseQueries::getFeeds<GreaderFeed>(database, qApp->feedReader()->messageFilters(), accountId());
|
|
||||||
auto labels = DatabaseQueries::getLabels(database, accountId());
|
|
||||||
|
|
||||||
performInitialAssembly(categories, feeds, labels);
|
|
||||||
}
|
|
||||||
|
|
|
@ -37,9 +37,6 @@ class GreaderServiceRoot : public ServiceRoot, public CacheForServiceRoot {
|
||||||
protected:
|
protected:
|
||||||
virtual RootItem* obtainNewTreeForSyncIn() const;
|
virtual RootItem* obtainNewTreeForSyncIn() const;
|
||||||
|
|
||||||
private:
|
|
||||||
void loadFromDatabase();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GreaderNetwork* m_network;
|
GreaderNetwork* m_network;
|
||||||
};
|
};
|
||||||
|
|
|
@ -28,15 +28,6 @@ void InoreaderServiceRoot::updateTitle() {
|
||||||
setTitle(TextFactory::extractUsernameFromEmail(m_network->username()) + QSL(" (Inoreader)"));
|
setTitle(TextFactory::extractUsernameFromEmail(m_network->username()) + QSL(" (Inoreader)"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void InoreaderServiceRoot::loadFromDatabase() {
|
|
||||||
QSqlDatabase database = qApp->database()->connection(metaObject()->className());
|
|
||||||
Assignment categories = DatabaseQueries::getCategories<Category>(database, accountId());
|
|
||||||
Assignment feeds = DatabaseQueries::getFeeds<InoreaderFeed>(database, qApp->feedReader()->messageFilters(), accountId());
|
|
||||||
auto labels = DatabaseQueries::getLabels(database, accountId());
|
|
||||||
|
|
||||||
performInitialAssembly(categories, feeds, labels);
|
|
||||||
}
|
|
||||||
|
|
||||||
ServiceRoot::LabelOperation InoreaderServiceRoot::supportedLabelOperations() const {
|
ServiceRoot::LabelOperation InoreaderServiceRoot::supportedLabelOperations() const {
|
||||||
return ServiceRoot::LabelOperation(0);
|
return ServiceRoot::LabelOperation(0);
|
||||||
}
|
}
|
||||||
|
@ -66,7 +57,7 @@ bool InoreaderServiceRoot::supportsCategoryAdding() const {
|
||||||
|
|
||||||
void InoreaderServiceRoot::start(bool freshly_activated) {
|
void InoreaderServiceRoot::start(bool freshly_activated) {
|
||||||
if (!freshly_activated) {
|
if (!freshly_activated) {
|
||||||
loadFromDatabase();
|
DatabaseQueries::loadFromDatabase<Category, InoreaderFeed>(this);
|
||||||
loadCacheFromFile();
|
loadCacheFromFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,9 +33,6 @@ class InoreaderServiceRoot : public ServiceRoot, public CacheForServiceRoot {
|
||||||
protected:
|
protected:
|
||||||
virtual RootItem* obtainNewTreeForSyncIn() const;
|
virtual RootItem* obtainNewTreeForSyncIn() const;
|
||||||
|
|
||||||
private:
|
|
||||||
void loadFromDatabase();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
InoreaderNetworkFactory* m_network;
|
InoreaderNetworkFactory* m_network;
|
||||||
};
|
};
|
||||||
|
|
|
@ -49,7 +49,7 @@ bool OwnCloudServiceRoot::supportsCategoryAdding() const {
|
||||||
|
|
||||||
void OwnCloudServiceRoot::start(bool freshly_activated) {
|
void OwnCloudServiceRoot::start(bool freshly_activated) {
|
||||||
if (!freshly_activated) {
|
if (!freshly_activated) {
|
||||||
loadFromDatabase();
|
DatabaseQueries::loadFromDatabase<Category, OwnCloudFeed>(this);
|
||||||
loadCacheFromFile();
|
loadCacheFromFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,12 +126,3 @@ RootItem* OwnCloudServiceRoot::obtainNewTreeForSyncIn() const {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OwnCloudServiceRoot::loadFromDatabase() {
|
|
||||||
QSqlDatabase database = qApp->database()->connection(metaObject()->className());
|
|
||||||
Assignment categories = DatabaseQueries::getCategories<Category>(database, accountId());
|
|
||||||
Assignment feeds = DatabaseQueries::getFeeds<OwnCloudFeed>(database, qApp->feedReader()->messageFilters(), accountId());
|
|
||||||
auto labels = DatabaseQueries::getLabels(database, accountId());
|
|
||||||
|
|
||||||
performInitialAssembly(categories, feeds, labels);
|
|
||||||
}
|
|
||||||
|
|
|
@ -35,8 +35,6 @@ class OwnCloudServiceRoot : public ServiceRoot, public CacheForServiceRoot {
|
||||||
virtual RootItem* obtainNewTreeForSyncIn() const;
|
virtual RootItem* obtainNewTreeForSyncIn() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void loadFromDatabase();
|
|
||||||
|
|
||||||
OwnCloudNetworkFactory* m_network;
|
OwnCloudNetworkFactory* m_network;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@ StandardServiceRoot::~StandardServiceRoot() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void StandardServiceRoot::start(bool freshly_activated) {
|
void StandardServiceRoot::start(bool freshly_activated) {
|
||||||
loadFromDatabase();
|
DatabaseQueries::loadFromDatabase<StandardCategory, StandardFeed>(this);
|
||||||
|
|
||||||
if (freshly_activated && getSubTreeFeeds().isEmpty()) {
|
if (freshly_activated && getSubTreeFeeds().isEmpty()) {
|
||||||
// In other words, if there are no feeds or categories added.
|
// In other words, if there are no feeds or categories added.
|
||||||
|
@ -130,15 +130,6 @@ Qt::ItemFlags StandardServiceRoot::additionalFlags() const {
|
||||||
return Qt::ItemFlag::ItemIsDropEnabled;
|
return Qt::ItemFlag::ItemIsDropEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
void StandardServiceRoot::loadFromDatabase() {
|
|
||||||
QSqlDatabase database = qApp->database()->connection(metaObject()->className());
|
|
||||||
Assignment categories = DatabaseQueries::getCategories<StandardCategory>(database, accountId());
|
|
||||||
Assignment feeds = DatabaseQueries::getFeeds<StandardFeed>(database, qApp->feedReader()->messageFilters(), accountId());
|
|
||||||
auto labels = DatabaseQueries::getLabels(database, accountId());
|
|
||||||
|
|
||||||
performInitialAssembly(categories, feeds, labels);
|
|
||||||
}
|
|
||||||
|
|
||||||
void StandardServiceRoot::checkArgumentsForFeedAdding() {
|
void StandardServiceRoot::checkArgumentsForFeedAdding() {
|
||||||
for (const QString& arg : qApp->arguments().mid(1)) {
|
for (const QString& arg : qApp->arguments().mid(1)) {
|
||||||
checkArgumentForFeedAdding(arg);
|
checkArgumentForFeedAdding(arg);
|
||||||
|
|
|
@ -46,7 +46,6 @@ class StandardServiceRoot : public ServiceRoot {
|
||||||
bool mergeImportExportModel(FeedsImportExportModel* model, RootItem* target_root_node, QString& output_message);
|
bool mergeImportExportModel(FeedsImportExportModel* model, RootItem* target_root_node, QString& output_message);
|
||||||
|
|
||||||
QString processFeedUrl(const QString& feed_url);
|
QString processFeedUrl(const QString& feed_url);
|
||||||
void loadFromDatabase();
|
|
||||||
void checkArgumentForFeedAdding(const QString& argument);
|
void checkArgumentForFeedAdding(const QString& argument);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
Loading…
Add table
Reference in a new issue