Work on refactoring. Added some switches.

This commit is contained in:
Martin Rotter 2016-08-14 20:10:35 +02:00
parent 1695af454b
commit 97f8863a0a
7 changed files with 76 additions and 31 deletions

View file

@ -28,6 +28,7 @@
#include "miscellaneous/databasecleaner.h" #include "miscellaneous/databasecleaner.h"
#include "miscellaneous/iconfactory.h" #include "miscellaneous/iconfactory.h"
#include "miscellaneous/mutex.h" #include "miscellaneous/mutex.h"
#include "miscellaneous/feedreader.h"
#include "gui/messagebox.h" #include "gui/messagebox.h"
#include "gui/statusbar.h" #include "gui/statusbar.h"
#include "gui/dialogs/formmain.h" #include "gui/dialogs/formmain.h"
@ -711,7 +712,7 @@ bool FeedsModel::emptyAllBins() {
void FeedsModel::loadActivatedServiceAccounts() { void FeedsModel::loadActivatedServiceAccounts() {
// Iterate all globally available feed "service plugins". // 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. // Load all stored root nodes from the entry point and add those to the model.
QList<ServiceRoot*> roots = entry_point->initializeSubtree(); QList<ServiceRoot*> roots = entry_point->initializeSubtree();

View file

@ -24,6 +24,7 @@
#include "miscellaneous/mutex.h" #include "miscellaneous/mutex.h"
#include "miscellaneous/databasefactory.h" #include "miscellaneous/databasefactory.h"
#include "miscellaneous/iconfactory.h" #include "miscellaneous/iconfactory.h"
#include "miscellaneous/feedreader.h"
#include "network-web/webfactory.h" #include "network-web/webfactory.h"
#include "gui/feedsview.h" #include "gui/feedsview.h"
#include "gui/messagebox.h" #include "gui/messagebox.h"
@ -556,7 +557,7 @@ void FormMain::showWiki() {
} }
void FormMain::showAddAccountDialog() { void FormMain::showAddAccountDialog() {
QScopedPointer<FormAddAccount> form_update(new FormAddAccount(qApp->feedServices(), QScopedPointer<FormAddAccount> form_update(new FormAddAccount(qApp->feedReader()->feedServices(),
tabWidget()->feedMessageViewer()->feedsView()->sourceModel(), tabWidget()->feedMessageViewer()->feedsView()->sourceModel(),
this)); this));
form_update->exec(); form_update->exec();

View file

@ -39,20 +39,21 @@
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
bool run_as_cron = false; bool run_minimal_without_gui = false;
for (int i; i < argc; i++) { for (int i; i < argc; i++) {
const QString str = QString::fromLocal8Bit(argv[i]); const QString str = QString::fromLocal8Bit(argv[i]);
if (str == "-h") { if (str == "-h" || str == "--help") {
qDebug("Usage: rssguard [OPTIONS]\n\n" qDebug("Usage: rssguard [OPTIONS]\n\n"
"Option\tMeaning\n" "Option\t\tGNU long option\t\tMeaning\n"
"aaaa\tbbbb"); "-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; return EXIT_SUCCESS;
} }
else if (str == "-cron") { else if (str == "-c" || str == "--cron") {
run_as_cron = true; run_minimal_without_gui = true;
} }
} }
@ -70,7 +71,7 @@ int main(int argc, char *argv[]) {
qInstallMessageHandler(Debugging::debugHandler); qInstallMessageHandler(Debugging::debugHandler);
// Instantiate base application object. // 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."); qDebug("Instantiated Application class.");
// Check if another instance is running. // Check if another instance is running.

View file

@ -41,9 +41,10 @@
#include <QWebEngineDownloadItem> #include <QWebEngineDownloadItem>
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), : QtSingleApplication(id, argc, argv),
m_feedReader(new FeedReader(this)), m_updateFeedsLock(nullptr), m_feedServices(QList<ServiceEntryPoint*>()), m_userActions(QList<QAction*>()), m_mainForm(nullptr), m_runMinimalWithoutGui(run_minimal_without_gui), m_feedReader(new FeedReader(this)),
m_updateFeedsLock(nullptr), m_userActions(QList<QAction*>()), m_mainForm(nullptr),
m_trayIcon(nullptr), m_settings(nullptr), m_system(nullptr), m_skins(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) { m_localization(nullptr), m_icons(nullptr), m_database(nullptr), m_downloadManager(nullptr) {
connect(this, SIGNAL(aboutToQuit()), this, SLOT(onAboutToQuit())); connect(this, SIGNAL(aboutToQuit()), this, SLOT(onAboutToQuit()));
@ -55,24 +56,12 @@ Application::Application(const QString &id, int &argc, char **argv)
Application::~Application() { Application::~Application() {
qDebug("Destroying Application instance."); qDebug("Destroying Application instance.");
qDeleteAll(m_feedServices);
} }
FeedReader *Application::feedReader() { FeedReader *Application::feedReader() {
return m_feedReader; return m_feedReader;
} }
QList<ServiceEntryPoint*> 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<QAction*> Application::userActions() { QList<QAction*> Application::userActions() {
if (m_mainForm != nullptr && m_userActions.isEmpty()) { if (m_mainForm != nullptr && m_userActions.isEmpty()) {
m_userActions = m_mainForm->allActions(); m_userActions = m_mainForm->allActions();

View file

@ -53,15 +53,11 @@ class Application : public QtSingleApplication {
public: public:
// Constructors and destructors. // 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(); virtual ~Application();
FeedReader *feedReader(); FeedReader *feedReader();
// List of all installed "feed service plugins", including obligatory
// "standard" service entry point.
QList<ServiceEntryPoint*> feedServices();
// Globally accessible actions. // Globally accessible actions.
QList<QAction*> userActions(); QList<QAction*> userActions();
@ -178,6 +174,7 @@ class Application : public QtSingleApplication {
void eliminateFirstRun(); void eliminateFirstRun();
void eliminateFirstRun(const QString &version); void eliminateFirstRun(const QString &version);
bool m_runMinimalWithoutGui;
FeedReader *m_feedReader; FeedReader *m_feedReader;
// This read-write lock is used by application on its close. // 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. // action will be allowed to lock for reading.
QScopedPointer<Mutex> m_updateFeedsLock; QScopedPointer<Mutex> m_updateFeedsLock;
QList<ServiceEntryPoint*> m_feedServices;
QList<QAction*> m_userActions; QList<QAction*> m_userActions;
FormMain *m_mainForm; FormMain *m_mainForm;
SystemTrayIcon *m_trayIcon; SystemTrayIcon *m_trayIcon;

View file

@ -17,10 +17,46 @@
#include "miscellaneous/feedreader.h" #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<ServiceEntryPoint*>()) {
} }
FeedReader::~FeedReader() { FeedReader::~FeedReader() {
qDebug("Destroying FeedReader instance."); qDebug("Destroying FeedReader instance.");
qDeleteAll(m_feedServices);
}
QList<ServiceEntryPoint*> 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() {
} }

View file

@ -20,6 +20,12 @@
#include <QObject> #include <QObject>
class FeedDownloader;
class FeedsModel;
class MessagesModel;
class ServiceEntryPoint;
class FeedReader : public QObject { class FeedReader : public QObject {
Q_OBJECT Q_OBJECT
@ -27,9 +33,24 @@ class FeedReader : public QObject {
explicit FeedReader(QObject *parent = 0); explicit FeedReader(QObject *parent = 0);
virtual ~FeedReader(); virtual ~FeedReader();
signals: // List of all installed "feed service plugins", including obligatory
// "standard" service entry point.
QList<ServiceEntryPoint*> feedServices();
FeedDownloader *feedDownloader() const;
FeedsModel *feedsModel() const;
MessagesModel *messagesModel() const;
public slots: public slots:
void start();
void stop();
private:
QList<ServiceEntryPoint*> m_feedServices;
FeedDownloader *m_feedDownloader;
FeedsModel *m_feedsModel;
MessagesModel *m_messagesModel;
}; };
#endif // FEEDREADER_H #endif // FEEDREADER_H