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;
}
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*>feeds_for_update;

View File

@ -47,12 +47,6 @@ class RSSGUARD_DLLSPEC FeedsModel : public QAbstractItemModel {
// the model root item.
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
// according to auto-update schedule.
// 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) {
QListWidgetItem* item = new QListWidgetItem(entry_point->icon(), entry_point->name(), m_ui->m_listEntryPoints);
if (entry_point->isSingleInstanceService() && m_model->containsServiceRootFromEntryPoint(entry_point)) {
// 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());
}
item->setToolTip(entry_point->description());
}
m_ui->m_listEntryPoints->setCurrentRow(m_entryPoints.size() - 1);

View File

@ -2,6 +2,7 @@
#include "miscellaneous/application.h"
#include "3rd-party/boolinq/boolinq.h"
#include "dynamic-shortcuts/dynamicshortcuts.h"
#include "exceptions/applicationexception.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))) {
// 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) {
root->checkArgumentForFeedAdding(msg);
if (rt != nullptr) {
rt->addNewFeed(nullptr, msg);
}
else {
showGuiMessage(tr("Cannot add feed"),

View File

@ -28,11 +28,6 @@ class ServiceEntryPoint {
// to the global feed model.
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".
virtual QString name() const = 0;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -10,6 +10,7 @@
#include "services/abstract/serviceroot.h"
#include "services/standard/gui/standardfeeddetails.h"
#include "services/standard/standardfeed.h"
#include "services/standard/standardserviceroot.h"
#include <QFileDialog>
#include <QTextCodec>
@ -32,7 +33,10 @@ int FormStandardFeedDetails::addEditFeed(StandardFeed* input_feed, RootItem* par
if (input_feed == nullptr) {
// User is adding 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 {
setEditableFeed(input_feed);

View File

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

View File

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

View File

@ -146,7 +146,7 @@ void StandardServiceRoot::checkArgumentsForFeedAdding() {
QString StandardServiceRoot::processFeedUrl(const QString& feed_url) {
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:"))) {
return without_feed_prefix;

View File

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

View File

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

View File

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