From 97f8863a0a1cb0488ccf65363dddd8ec041a8ff4 Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Sun, 14 Aug 2016 20:10:35 +0200 Subject: [PATCH] Work on refactoring. Added some switches. --- src/core/feedsmodel.cpp | 3 ++- src/gui/dialogs/formmain.cpp | 3 ++- src/main.cpp | 15 ++++++------ src/miscellaneous/application.cpp | 17 +++----------- src/miscellaneous/application.h | 8 ++----- src/miscellaneous/feedreader.cpp | 38 ++++++++++++++++++++++++++++++- src/miscellaneous/feedreader.h | 23 ++++++++++++++++++- 7 files changed, 76 insertions(+), 31 deletions(-) diff --git a/src/core/feedsmodel.cpp b/src/core/feedsmodel.cpp index 7085042f7..3284f2668 100755 --- a/src/core/feedsmodel.cpp +++ b/src/core/feedsmodel.cpp @@ -28,6 +28,7 @@ #include "miscellaneous/databasecleaner.h" #include "miscellaneous/iconfactory.h" #include "miscellaneous/mutex.h" +#include "miscellaneous/feedreader.h" #include "gui/messagebox.h" #include "gui/statusbar.h" #include "gui/dialogs/formmain.h" @@ -711,7 +712,7 @@ bool FeedsModel::emptyAllBins() { void FeedsModel::loadActivatedServiceAccounts() { // Iterate all globally available feed "service plugins". - foreach (const ServiceEntryPoint *entry_point, qApp->feedServices()) { + foreach (const ServiceEntryPoint *entry_point, qApp->feedReader()->feedServices()) { // Load all stored root nodes from the entry point and add those to the model. QList roots = entry_point->initializeSubtree(); diff --git a/src/gui/dialogs/formmain.cpp b/src/gui/dialogs/formmain.cpp index 8105df882..c3c020fc4 100755 --- a/src/gui/dialogs/formmain.cpp +++ b/src/gui/dialogs/formmain.cpp @@ -24,6 +24,7 @@ #include "miscellaneous/mutex.h" #include "miscellaneous/databasefactory.h" #include "miscellaneous/iconfactory.h" +#include "miscellaneous/feedreader.h" #include "network-web/webfactory.h" #include "gui/feedsview.h" #include "gui/messagebox.h" @@ -556,7 +557,7 @@ void FormMain::showWiki() { } void FormMain::showAddAccountDialog() { - QScopedPointer form_update(new FormAddAccount(qApp->feedServices(), + QScopedPointer form_update(new FormAddAccount(qApp->feedReader()->feedServices(), tabWidget()->feedMessageViewer()->feedsView()->sourceModel(), this)); form_update->exec(); diff --git a/src/main.cpp b/src/main.cpp index 7ae38e828..2545bbc11 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -39,20 +39,21 @@ int main(int argc, char *argv[]) { - bool run_as_cron = false; + bool run_minimal_without_gui = false; for (int i; i < argc; i++) { const QString str = QString::fromLocal8Bit(argv[i]); - if (str == "-h") { + if (str == "-h" || str == "--help") { qDebug("Usage: rssguard [OPTIONS]\n\n" - "Option\tMeaning\n" - "aaaa\tbbbb"); + "Option\t\tGNU long option\t\tMeaning\n" + "-h\t\t--help\t\t\tDisplays this help.\n" + "-c\t\t--cron\t\t\tStarts the application without GUI and will regularly update configured feeds."); return EXIT_SUCCESS; } - else if (str == "-cron") { - run_as_cron = true; + else if (str == "-c" || str == "--cron") { + run_minimal_without_gui = true; } } @@ -70,7 +71,7 @@ int main(int argc, char *argv[]) { qInstallMessageHandler(Debugging::debugHandler); // Instantiate base application object. - Application application(APP_LOW_NAME, argc, argv); + Application application(APP_LOW_NAME, run_minimal_without_gui, argc, argv); qDebug("Instantiated Application class."); // Check if another instance is running. diff --git a/src/miscellaneous/application.cpp b/src/miscellaneous/application.cpp index 88a9e4503..e094290b0 100755 --- a/src/miscellaneous/application.cpp +++ b/src/miscellaneous/application.cpp @@ -41,9 +41,10 @@ #include -Application::Application(const QString &id, int &argc, char **argv) +Application::Application(const QString &id, bool run_minimal_without_gui, int &argc, char **argv) : QtSingleApplication(id, argc, argv), - m_feedReader(new FeedReader(this)), m_updateFeedsLock(nullptr), m_feedServices(QList()), m_userActions(QList()), m_mainForm(nullptr), + m_runMinimalWithoutGui(run_minimal_without_gui), m_feedReader(new FeedReader(this)), + m_updateFeedsLock(nullptr), m_userActions(QList()), m_mainForm(nullptr), m_trayIcon(nullptr), m_settings(nullptr), m_system(nullptr), m_skins(nullptr), m_localization(nullptr), m_icons(nullptr), m_database(nullptr), m_downloadManager(nullptr) { connect(this, SIGNAL(aboutToQuit()), this, SLOT(onAboutToQuit())); @@ -55,24 +56,12 @@ Application::Application(const QString &id, int &argc, char **argv) Application::~Application() { qDebug("Destroying Application instance."); - qDeleteAll(m_feedServices); } FeedReader *Application::feedReader() { return m_feedReader; } -QList Application::feedServices() { - if (m_feedServices.isEmpty()) { - // NOTE: All installed services create their entry points here. - m_feedServices.append(new StandardServiceEntryPoint()); - m_feedServices.append(new TtRssServiceEntryPoint()); - m_feedServices.append(new OwnCloudServiceEntryPoint()); - } - - return m_feedServices; -} - QList Application::userActions() { if (m_mainForm != nullptr && m_userActions.isEmpty()) { m_userActions = m_mainForm->allActions(); diff --git a/src/miscellaneous/application.h b/src/miscellaneous/application.h index 594ccea5a..dc99de4e1 100755 --- a/src/miscellaneous/application.h +++ b/src/miscellaneous/application.h @@ -53,15 +53,11 @@ class Application : public QtSingleApplication { public: // Constructors and destructors. - explicit Application(const QString &id, int &argc, char **argv); + explicit Application(const QString &id, bool run_minimal_without_gui, int &argc, char **argv); virtual ~Application(); FeedReader *feedReader(); - // List of all installed "feed service plugins", including obligatory - // "standard" service entry point. - QList feedServices(); - // Globally accessible actions. QList userActions(); @@ -178,6 +174,7 @@ class Application : public QtSingleApplication { void eliminateFirstRun(); void eliminateFirstRun(const QString &version); + bool m_runMinimalWithoutGui; FeedReader *m_feedReader; // This read-write lock is used by application on its close. @@ -194,7 +191,6 @@ class Application : public QtSingleApplication { // action will be allowed to lock for reading. QScopedPointer m_updateFeedsLock; - QList m_feedServices; QList m_userActions; FormMain *m_mainForm; SystemTrayIcon *m_trayIcon; diff --git a/src/miscellaneous/feedreader.cpp b/src/miscellaneous/feedreader.cpp index dfc66946a..7d80c0ab6 100644 --- a/src/miscellaneous/feedreader.cpp +++ b/src/miscellaneous/feedreader.cpp @@ -17,10 +17,46 @@ #include "miscellaneous/feedreader.h" +#include "services/standard/standardserviceentrypoint.h" +#include "services/owncloud/owncloudserviceentrypoint.h" +#include "services/tt-rss/ttrssserviceentrypoint.h" -FeedReader::FeedReader(QObject *parent) : QObject(parent) { + +FeedReader::FeedReader(QObject *parent) : QObject(parent), m_feedServices(QList()) { } FeedReader::~FeedReader() { qDebug("Destroying FeedReader instance."); + qDeleteAll(m_feedServices); +} + +QList FeedReader::feedServices() { + if (m_feedServices.isEmpty()) { + // NOTE: All installed services create their entry points here. + m_feedServices.append(new StandardServiceEntryPoint()); + m_feedServices.append(new TtRssServiceEntryPoint()); + m_feedServices.append(new OwnCloudServiceEntryPoint()); + } + + return m_feedServices; +} + +FeedDownloader *FeedReader::feedDownloader() const { + return m_feedDownloader; +} + +FeedsModel *FeedReader::feedsModel() const { + return m_feedsModel; +} + +MessagesModel *FeedReader::messagesModel() const { + return m_messagesModel; +} + +void FeedReader::start() { + +} + +void FeedReader::stop() { + } diff --git a/src/miscellaneous/feedreader.h b/src/miscellaneous/feedreader.h index 00fb35768..5bf4cb320 100644 --- a/src/miscellaneous/feedreader.h +++ b/src/miscellaneous/feedreader.h @@ -20,6 +20,12 @@ #include + +class FeedDownloader; +class FeedsModel; +class MessagesModel; +class ServiceEntryPoint; + class FeedReader : public QObject { Q_OBJECT @@ -27,9 +33,24 @@ class FeedReader : public QObject { explicit FeedReader(QObject *parent = 0); virtual ~FeedReader(); - signals: + // List of all installed "feed service plugins", including obligatory + // "standard" service entry point. + QList feedServices(); + + FeedDownloader *feedDownloader() const; + FeedsModel *feedsModel() const; + MessagesModel *messagesModel() const; public slots: + void start(); + void stop(); + + private: + QList m_feedServices; + + FeedDownloader *m_feedDownloader; + FeedsModel *m_feedsModel; + MessagesModel *m_messagesModel; }; #endif // FEEDREADER_H