Some API cleanups, RSS Guard now allows you to add multiple "standard" accounts simultaneously.

This commit is contained in:
Martin Rotter 2021-01-11 10:50:08 +01:00
parent a8d3181edc
commit 25329b61fa
18 changed files with 49 additions and 110 deletions

View file

@ -302,24 +302,6 @@ QList<ServiceRoot*>FeedsModel::serviceRoots() const {
return roots; return roots;
} }
bool FeedsModel::containsServiceRootFromEntryPoint(const ServiceEntryPoint* point) const {
return boolinq::from(serviceRoots()).any([=](ServiceRoot* root) {
return root->code() == point->code();
});
}
StandardServiceRoot* FeedsModel::standardServiceRoot() const {
for (ServiceRoot* root : serviceRoots()) {
StandardServiceRoot* std_service_root;
if ((std_service_root = dynamic_cast<StandardServiceRoot*>(root)) != nullptr) {
return std_service_root;
}
}
return nullptr;
}
QList<Feed*>FeedsModel::feedsForScheduledUpdate(bool auto_update_now) { QList<Feed*>FeedsModel::feedsForScheduledUpdate(bool auto_update_now) {
QList<Feed*>feeds_for_update; QList<Feed*>feeds_for_update;

View file

@ -47,12 +47,6 @@ class RSSGUARD_DLLSPEC FeedsModel : public QAbstractItemModel {
// the model root item. // the model root item.
QList<ServiceRoot*> serviceRoots() const; QList<ServiceRoot*> serviceRoots() const;
// Determines if there is any account activated from given entry point.
bool containsServiceRootFromEntryPoint(const ServiceEntryPoint* point) const;
// Direct and the only global accessor to standard service root.
StandardServiceRoot* standardServiceRoot() const;
// Returns the list of feeds which should be updated // Returns the list of feeds which should be updated
// according to auto-update schedule. // according to auto-update schedule.
// Variable "auto_update_now" is true, when global timeout // Variable "auto_update_now" is true, when global timeout

View file

@ -52,14 +52,7 @@ void FormAddAccount::loadEntryPoints() {
for (const ServiceEntryPoint* entry_point : m_entryPoints) { for (const ServiceEntryPoint* entry_point : m_entryPoints) {
QListWidgetItem* item = new QListWidgetItem(entry_point->icon(), entry_point->name(), m_ui->m_listEntryPoints); QListWidgetItem* item = new QListWidgetItem(entry_point->icon(), entry_point->name(), m_ui->m_listEntryPoints);
if (entry_point->isSingleInstanceService() && m_model->containsServiceRootFromEntryPoint(entry_point)) { item->setToolTip(entry_point->description());
// Oops, this item cannot be added, it is single instance and is already added.
item->setFlags(Qt::ItemFlag::NoItemFlags);
item->setToolTip(tr("This account can be added only once."));
}
else {
item->setToolTip(entry_point->description());
}
} }
m_ui->m_listEntryPoints->setCurrentRow(m_entryPoints.size() - 1); m_ui->m_listEntryPoints->setCurrentRow(m_entryPoints.size() - 1);

View file

@ -2,6 +2,7 @@
#include "miscellaneous/application.h" #include "miscellaneous/application.h"
#include "3rd-party/boolinq/boolinq.h"
#include "dynamic-shortcuts/dynamicshortcuts.h" #include "dynamic-shortcuts/dynamicshortcuts.h"
#include "exceptions/applicationexception.h" #include "exceptions/applicationexception.h"
#include "gui/dialogs/formabout.h" #include "gui/dialogs/formabout.h"
@ -361,10 +362,12 @@ void Application::processExecutionMessage(const QString& message) {
} }
else if (msg.startsWith(QL1S(URI_SCHEME_FEED_SHORT))) { else if (msg.startsWith(QL1S(URI_SCHEME_FEED_SHORT))) {
// Application was running, and someone wants to add new feed. // Application was running, and someone wants to add new feed.
StandardServiceRoot* root = qApp->feedReader()->feedsModel()->standardServiceRoot(); ServiceRoot* rt = boolinq::from(feedReader()->feedsModel()->serviceRoots()).firstOrDefault([](ServiceRoot* root) {
return root->supportsFeedAdding();
});
if (root != nullptr) { if (rt != nullptr) {
root->checkArgumentForFeedAdding(msg); rt->addNewFeed(nullptr, msg);
} }
else { else {
showGuiMessage(tr("Cannot add feed"), showGuiMessage(tr("Cannot add feed"),

View file

@ -28,11 +28,6 @@ class ServiceEntryPoint {
// to the global feed model. // to the global feed model.
virtual QList<ServiceRoot*> initializeSubtree() const = 0; virtual QList<ServiceRoot*> initializeSubtree() const = 0;
// Can this service account be added just once?
// NOTE: This is true particularly for "standard" service
// which operates with normal RSS/ATOM feeds.
virtual bool isSingleInstanceService() const = 0;
// Human readable service name, for example "TT-RSS". // Human readable service name, for example "TT-RSS".
virtual QString name() const = 0; virtual QString name() const = 0;

View file

@ -24,10 +24,6 @@ QList<ServiceRoot*> GmailEntryPoint::initializeSubtree() const {
return DatabaseQueries::getGmailAccounts(database); return DatabaseQueries::getGmailAccounts(database);
} }
bool GmailEntryPoint::isSingleInstanceService() const {
return false;
}
QString GmailEntryPoint::name() const { QString GmailEntryPoint::name() const {
return QSL("Gmail"); return QSL("Gmail");
} }

View file

@ -7,15 +7,13 @@
class GmailEntryPoint : public ServiceEntryPoint { class GmailEntryPoint : public ServiceEntryPoint {
public: public:
ServiceRoot* createNewRoot() const; virtual ServiceRoot* createNewRoot() const;
virtual QList<ServiceRoot*> initializeSubtree() const;
QList<ServiceRoot*> initializeSubtree() const; virtual QString name() const;
bool isSingleInstanceService() const; virtual QString code() const;
QString name() const; virtual QString description() const;
QString code() const; virtual QString author() const;
QString description() const; virtual QIcon icon() const;
QString author() const;
QIcon icon() const;
}; };
#endif // GMAILENTRYPOINT_H #endif // GMAILENTRYPOINT_H

View file

@ -25,10 +25,6 @@ QList<ServiceRoot*> InoreaderEntryPoint::initializeSubtree() const {
return DatabaseQueries::getInoreaderAccounts(database); return DatabaseQueries::getInoreaderAccounts(database);
} }
bool InoreaderEntryPoint::isSingleInstanceService() const {
return false;
}
QString InoreaderEntryPoint::name() const { QString InoreaderEntryPoint::name() const {
return QSL("Inoreader"); return QSL("Inoreader");
} }

View file

@ -7,15 +7,13 @@
class InoreaderEntryPoint : public ServiceEntryPoint { class InoreaderEntryPoint : public ServiceEntryPoint {
public: public:
ServiceRoot* createNewRoot() const; virtual ServiceRoot* createNewRoot() const;
virtual QList<ServiceRoot*> initializeSubtree() const;
QList<ServiceRoot*> initializeSubtree() const; virtual QString name() const;
bool isSingleInstanceService() const; virtual QString code() const;
QString name() const; virtual QString description() const;
QString code() const; virtual QString author() const;
QString description() const; virtual QIcon icon() const;
QString author() const;
QIcon icon() const;
}; };
#endif // INOREADERENTRYPOINT_H #endif // INOREADERENTRYPOINT_H

View file

@ -22,10 +22,6 @@ QList<ServiceRoot*> OwnCloudServiceEntryPoint::initializeSubtree() const {
return DatabaseQueries::getOwnCloudAccounts(database); return DatabaseQueries::getOwnCloudAccounts(database);
} }
bool OwnCloudServiceEntryPoint::isSingleInstanceService() const {
return false;
}
QString OwnCloudServiceEntryPoint::name() const { QString OwnCloudServiceEntryPoint::name() const {
return QSL("Nextcloud News"); return QSL("Nextcloud News");
} }

View file

@ -7,15 +7,13 @@
class OwnCloudServiceEntryPoint : public ServiceEntryPoint { class OwnCloudServiceEntryPoint : public ServiceEntryPoint {
public: public:
ServiceRoot* createNewRoot() const; virtual ServiceRoot* createNewRoot() const;
virtual QList<ServiceRoot*> initializeSubtree() const;
QList<ServiceRoot*> initializeSubtree() const; virtual QString name() const;
bool isSingleInstanceService() const; virtual QString code() const;
QString name() const; virtual QString description() const;
QString code() const; virtual QString author() const;
QString description() const; virtual QIcon icon() const;
QString author() const;
QIcon icon() const;
}; };
#endif // OWNCLOUDSERVICEENTRYPOINT_H #endif // OWNCLOUDSERVICEENTRYPOINT_H

View file

@ -10,6 +10,7 @@
#include "services/abstract/serviceroot.h" #include "services/abstract/serviceroot.h"
#include "services/standard/gui/standardfeeddetails.h" #include "services/standard/gui/standardfeeddetails.h"
#include "services/standard/standardfeed.h" #include "services/standard/standardfeed.h"
#include "services/standard/standardserviceroot.h"
#include <QFileDialog> #include <QFileDialog>
#include <QTextCodec> #include <QTextCodec>
@ -32,7 +33,10 @@ int FormStandardFeedDetails::addEditFeed(StandardFeed* input_feed, RootItem* par
if (input_feed == nullptr) { if (input_feed == nullptr) {
// User is adding new feed. // User is adding new feed.
setWindowTitle(tr("Add new feed")); setWindowTitle(tr("Add new feed"));
m_standardFeedDetails->prepareForNewFeed(parent_to_select, url);
auto processed_url = qobject_cast<StandardServiceRoot*>(m_serviceRoot)->processFeedUrl(url);
m_standardFeedDetails->prepareForNewFeed(parent_to_select, processed_url);
} }
else { else {
setEditableFeed(input_feed); setEditableFeed(input_feed);

View file

@ -7,10 +7,6 @@
#include "miscellaneous/databasequeries.h" #include "miscellaneous/databasequeries.h"
#include "services/standard/standardserviceroot.h" #include "services/standard/standardserviceroot.h"
bool StandardServiceEntryPoint::isSingleInstanceService() const {
return true;
}
QString StandardServiceEntryPoint::name() const { QString StandardServiceEntryPoint::name() const {
return QObject::tr("Standard online feeds (RSS/ATOM/JSON)"); return QObject::tr("Standard online feeds (RSS/ATOM/JSON)");
} }

View file

@ -7,16 +7,13 @@
class StandardServiceEntryPoint : public ServiceEntryPoint { class StandardServiceEntryPoint : public ServiceEntryPoint {
public: public:
bool isSingleInstanceService() const; virtual QString name() const;
QString name() const; virtual QString description() const;
QString description() const; virtual QString author() const;
QString author() const; virtual QIcon icon() const;
QIcon icon() const; virtual QString code() const;
QString code() const; virtual ServiceRoot* createNewRoot() const;
virtual QList<ServiceRoot*> initializeSubtree() const;
ServiceRoot* createNewRoot() const;
QList<ServiceRoot*> initializeSubtree() const;
}; };
#endif // STANDARDSERVICEENTRYPOINT_H #endif // STANDARDSERVICEENTRYPOINT_H

View file

@ -146,7 +146,7 @@ void StandardServiceRoot::checkArgumentsForFeedAdding() {
QString StandardServiceRoot::processFeedUrl(const QString& feed_url) { QString StandardServiceRoot::processFeedUrl(const QString& feed_url) {
if (feed_url.startsWith(QL1S(URI_SCHEME_FEED_SHORT))) { if (feed_url.startsWith(QL1S(URI_SCHEME_FEED_SHORT))) {
QString without_feed_prefix = feed_url.mid(5); QString without_feed_prefix = feed_url.mid(QSL(URI_SCHEME_FEED_SHORT).size());
if (without_feed_prefix.startsWith(QL1S("https:")) || without_feed_prefix.startsWith(QL1S("http:"))) { if (without_feed_prefix.startsWith(QL1S("https:")) || without_feed_prefix.startsWith(QL1S("http:"))) {
return without_feed_prefix; return without_feed_prefix;

View file

@ -46,6 +46,7 @@ class StandardServiceRoot : public ServiceRoot {
// NOTE: This is used for import/export of the model. // NOTE: This is used for import/export of the model.
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);
void loadFromDatabase(); void loadFromDatabase();
void checkArgumentForFeedAdding(const QString& argument); void checkArgumentForFeedAdding(const QString& argument);
@ -56,7 +57,6 @@ class StandardServiceRoot : public ServiceRoot {
void exportFeeds(); void exportFeeds();
private: private:
QString processFeedUrl(const QString& feed_url);
void checkArgumentsForFeedAdding(); void checkArgumentsForFeedAdding();
QPointer<StandardFeed> m_feedForMetadata = {}; QPointer<StandardFeed> m_feedForMetadata = {};

View file

@ -9,10 +9,6 @@
#include "services/tt-rss/gui/formeditttrssaccount.h" #include "services/tt-rss/gui/formeditttrssaccount.h"
#include "services/tt-rss/ttrssserviceroot.h" #include "services/tt-rss/ttrssserviceroot.h"
bool TtRssServiceEntryPoint::isSingleInstanceService() const {
return false;
}
QString TtRssServiceEntryPoint::name() const { QString TtRssServiceEntryPoint::name() const {
return QSL("Tiny Tiny RSS"); return QSL("Tiny Tiny RSS");
} }

View file

@ -7,16 +7,13 @@
class TtRssServiceEntryPoint : public ServiceEntryPoint { class TtRssServiceEntryPoint : public ServiceEntryPoint {
public: public:
bool isSingleInstanceService() const; virtual QString name() const;
QString name() const; virtual QString description() const;
QString description() const; virtual QString author() const;
QString author() const; virtual QIcon icon() const;
QIcon icon() const; virtual QString code() const;
QString code() const; virtual ServiceRoot* createNewRoot() const;
virtual QList<ServiceRoot*> initializeSubtree() const;
ServiceRoot* createNewRoot() const;
QList<ServiceRoot*> initializeSubtree() const;
}; };
#endif // TTRSSSERVICEENTRYPOINT_H #endif // TTRSSSERVICEENTRYPOINT_H