From 5842657cb96ba65e4053a86f7e659ba40529dd7e Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Thu, 17 Apr 2014 13:49:38 +0200 Subject: [PATCH] Refactoring. --- src/application.cpp | 21 ++++++++++++++-- src/application.h | 24 ++++++++++++++++++- src/core/feeddownloader.cpp | 1 - src/core/feedsmodelcategory.h | 2 +- src/core/feedsmodelfeed.h | 3 +-- src/core/feedsmodelrootitem.cpp | 4 ++-- src/core/messagesmodel.cpp | 4 ++-- src/gui/formmain.cpp | 4 ++-- src/gui/formsettings.cpp | 2 +- src/gui/locationlineedit.cpp | 8 +------ src/gui/messagebox.cpp | 5 ++-- src/gui/systemtrayicon.cpp | 4 ++-- src/gui/tabwidget.cpp | 2 +- src/main.cpp | 18 +++++++------- src/miscellaneous/databasefactory.cpp | 2 +- src/miscellaneous/debugging.cpp | 2 +- src/miscellaneous/iconfactory.h | 8 ++++--- src/miscellaneous/localization.cpp | 7 +++--- src/miscellaneous/settings.cpp | 2 +- src/miscellaneous/settings.h | 1 + src/miscellaneous/skinfactory.cpp | 2 +- src/miscellaneous/skinfactory.h | 1 + src/miscellaneous/systemfactory.cpp | 10 ++++---- src/miscellaneous/systemfactory.h | 1 + src/network-web/networkfactory.h | 2 +- .../silentnetworkaccessmanager.cpp | 1 - .../webbrowsernetworkaccessmanager.cpp | 3 ++- src/network-web/webfactory.cpp | 2 +- src/network-web/webview.cpp | 2 +- src/updater/formupdater.cpp | 24 +++++++++++++++---- src/updater/formupdater.h | 18 ++++++++++++++ src/updater/main.cpp | 5 +--- 32 files changed, 130 insertions(+), 65 deletions(-) diff --git a/src/application.cpp b/src/application.cpp index b346e3efc..e307a99b6 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -1,8 +1,25 @@ +// This file is part of RSS Guard. +// +// Copyright (C) 2011-2014 by Martin Rotter +// +// RSS Guard is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// RSS Guard is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with RSS Guard. If not, see . + #include "application.h" -Application::Application(int &argc, char **argv) - : QtSingleApplication(argc, argv) { +Application::Application(const QString &id, int &argc, char **argv) + : QtSingleApplication(id, argc, argv) { } Application::~Application() { diff --git a/src/application.h b/src/application.h index 4c9c5ae87..fb9b88182 100644 --- a/src/application.h +++ b/src/application.h @@ -1,8 +1,30 @@ +// This file is part of RSS Guard. +// +// Copyright (C) 2011-2014 by Martin Rotter +// +// RSS Guard is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// RSS Guard is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with RSS Guard. If not, see . + #ifndef APPLICATION_H #define APPLICATION_H #include "qtsingleapplication/qtsingleapplication.h" +#if defined(qApp) +#undef qApp +#endif +#define qApp (Application::instance()) + // TODO: presunout nektery veci sem, settings atp class Application : public QtSingleApplication { @@ -10,7 +32,7 @@ class Application : public QtSingleApplication { public: // Constructors and destructors. - explicit Application(int &argc, char **argv); + explicit Application(const QString &id, int &argc, char **argv); virtual ~Application(); // Returns pointer to "GOD" application singleton. diff --git a/src/core/feeddownloader.cpp b/src/core/feeddownloader.cpp index 596be3355..9a3330e04 100644 --- a/src/core/feeddownloader.cpp +++ b/src/core/feeddownloader.cpp @@ -21,7 +21,6 @@ #include #include -#include FeedDownloader::FeedDownloader(QObject *parent) : QObject(parent) { diff --git a/src/core/feedsmodelcategory.h b/src/core/feedsmodelcategory.h index 2b2bc3b3e..0b90c09b9 100755 --- a/src/core/feedsmodelcategory.h +++ b/src/core/feedsmodelcategory.h @@ -21,7 +21,7 @@ #include "core/feedsmodelrootitem.h" #include -#include +#include class FeedsModelFeed; diff --git a/src/core/feedsmodelfeed.h b/src/core/feedsmodelfeed.h index 89a336dd0..69fc1960f 100755 --- a/src/core/feedsmodelfeed.h +++ b/src/core/feedsmodelfeed.h @@ -25,12 +25,11 @@ #include #include #include -#include +#include class Message; - // Represents BASE class for feeds contained in FeedsModel. // NOTE: This class should be derived to create PARTICULAR feed types. class FeedsModelFeed : public FeedsModelRootItem { diff --git a/src/core/feedsmodelrootitem.cpp b/src/core/feedsmodelrootitem.cpp index 8842d37cf..1396561c4 100755 --- a/src/core/feedsmodelrootitem.cpp +++ b/src/core/feedsmodelrootitem.cpp @@ -17,7 +17,7 @@ #include "core/feedsmodelrootitem.h" -#include "qtsingleapplication/qtsingleapplication.h" +#include "application.h" #include @@ -35,7 +35,7 @@ FeedsModelRootItem::~FeedsModelRootItem() { } void FeedsModelRootItem::setupFonts() { - m_normalFont = QtSingleApplication::font("FeedsView"); + m_normalFont = Application::font("FeedsView"); m_boldFont = m_normalFont; m_boldFont.setBold(true); } diff --git a/src/core/messagesmodel.cpp b/src/core/messagesmodel.cpp index c90aaa5d9..2618feb4e 100644 --- a/src/core/messagesmodel.cpp +++ b/src/core/messagesmodel.cpp @@ -21,7 +21,7 @@ #include "miscellaneous/textfactory.h" #include "miscellaneous/databasefactory.h" #include "miscellaneous/iconfactory.h" -#include "qtsingleapplication/qtsingleapplication.h" +#include "application.h" #include #include @@ -62,7 +62,7 @@ void MessagesModel::fetchAll() { } void MessagesModel::setupFonts() { - m_normalFont = QtSingleApplication::font("MessagesView"); + m_normalFont = Application::font("MessagesView"); m_boldFont = m_normalFont; m_boldFont.setBold(true); } diff --git a/src/gui/formmain.cpp b/src/gui/formmain.cpp index 2c1bac752..6c961587b 100755 --- a/src/gui/formmain.cpp +++ b/src/gui/formmain.cpp @@ -33,7 +33,7 @@ #include "gui/statusbar.h" #include "gui/feedmessageviewer.h" #include "gui/formupdate.h" -#include "qtsingleapplication/qtsingleapplication.h" +#include "application.h" #include #include @@ -219,7 +219,7 @@ void FormMain::display() { raise(); // Raise alert event. Check the documentation for more info on this. - QtSingleApplication::alert(this); + Application::alert(this); } void FormMain::onCommitData(QSessionManager &manager) { diff --git a/src/gui/formsettings.cpp b/src/gui/formsettings.cpp index 5f9f2805d..111fc5152 100755 --- a/src/gui/formsettings.cpp +++ b/src/gui/formsettings.cpp @@ -38,8 +38,8 @@ #include "gui/messagebox.h" #include "gui/basetoolbar.h" #include "gui/messagestoolbar.h" -#include "qtsingleapplication/qtsingleapplication.h" #include "dynamic-shortcuts/dynamicshortcuts.h" +#include "application.h" #include #include diff --git a/src/gui/locationlineedit.cpp b/src/gui/locationlineedit.cpp index f2aa96e4d..84185eff2 100644 --- a/src/gui/locationlineedit.cpp +++ b/src/gui/locationlineedit.cpp @@ -17,13 +17,7 @@ #include "gui/locationlineedit.h" -#include "definitions/definitions.h" -#include "miscellaneous/settings.h" - -#include -#include -#include -#include +#include LocationLineEdit::LocationLineEdit(QWidget *parent) diff --git a/src/gui/messagebox.cpp b/src/gui/messagebox.cpp index 440e8355e..5324ded57 100644 --- a/src/gui/messagebox.cpp +++ b/src/gui/messagebox.cpp @@ -18,13 +18,14 @@ #include "gui/messagebox.h" #include "miscellaneous/iconfactory.h" +#include "application.h" -#include #include +#include #include #include #include -#include + MessageBox::MessageBox(QWidget *parent) : QMessageBox(parent) { } diff --git a/src/gui/systemtrayicon.cpp b/src/gui/systemtrayicon.cpp index fde662880..9a626b223 100644 --- a/src/gui/systemtrayicon.cpp +++ b/src/gui/systemtrayicon.cpp @@ -21,7 +21,7 @@ #include "miscellaneous/settings.h" #include "gui/formmain.h" #include "gui/formsettings.h" -#include "qtsingleapplication/qtsingleapplication.h" +#include "application.h" #include #include @@ -36,7 +36,7 @@ TrayIconMenu::~TrayIconMenu() { } bool TrayIconMenu::event(QEvent *event) { - if (QtSingleApplication::activeModalWidget() != NULL && + if (Application::activeModalWidget() != NULL && event->type() == QEvent::Show) { QTimer::singleShot(0, this, SLOT(hide())); SystemTrayIcon::instance()->showMessage(APP_LONG_NAME, diff --git a/src/gui/tabwidget.cpp b/src/gui/tabwidget.cpp index dbebac8ac..8185cc42e 100644 --- a/src/gui/tabwidget.cpp +++ b/src/gui/tabwidget.cpp @@ -26,8 +26,8 @@ #include "gui/formmain.h" #include "gui/feedmessageviewer.h" #include "gui/plaintoolbutton.h" +#include "application.h" -#include #include #include diff --git a/src/main.cpp b/src/main.cpp index c277cebae..bc17476f3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -27,7 +27,7 @@ #include "gui/systemtrayicon.h" #include "gui/feedmessageviewer.h" #include "gui/feedsview.h" -#include "qtsingleapplication/qtsingleapplication.h" +#include "application.h" // Needed for setting ini file format on Mac OS. #ifdef Q_OS_MAC @@ -66,8 +66,8 @@ int main(int argc, char *argv[]) { #endif // Instantiate base application object. - QtSingleApplication application(APP_LOW_NAME, argc, argv); - qDebug("Instantiated QtSingleApplication class."); + Application application(APP_LOW_NAME, argc, argv); + qDebug("Instantiated Application class."); // Check if another instance is running. if (application.sendMessage(APP_IS_RUNNING)) { @@ -85,11 +85,11 @@ int main(int argc, char *argv[]) { Localization::instance()->load(); // These settings needs to be set before any QSettings object. - QtSingleApplication::setApplicationName(APP_NAME); - QtSingleApplication::setApplicationVersion(APP_VERSION); - QtSingleApplication::setOrganizationName(APP_AUTHOR); - QtSingleApplication::setOrganizationDomain(APP_URL); - QtSingleApplication::setWindowIcon(QIcon(APP_ICON_PATH)); + Application::setApplicationName(APP_NAME); + Application::setApplicationVersion(APP_VERSION); + Application::setOrganizationName(APP_AUTHOR); + Application::setOrganizationDomain(APP_URL); + Application::setWindowIcon(QIcon(APP_ICON_PATH)); qDebug().nospace() << "Creating main application form in thread: \'" << QThread::currentThreadId() << "\'."; @@ -126,5 +126,5 @@ int main(int argc, char *argv[]) { &main_window, SLOT(processExecutionMessage(QString))); // Enter global event loop. - return QtSingleApplication::exec(); + return Application::exec(); } diff --git a/src/miscellaneous/databasefactory.cpp b/src/miscellaneous/databasefactory.cpp index 11a0be88a..fffc608f7 100644 --- a/src/miscellaneous/databasefactory.cpp +++ b/src/miscellaneous/databasefactory.cpp @@ -19,8 +19,8 @@ #include "definitions/definitions.h" #include "miscellaneous/settings.h" +#include "application.h" -#include #include #include #include diff --git a/src/miscellaneous/debugging.cpp b/src/miscellaneous/debugging.cpp index bf57b6abe..84112f4d2 100644 --- a/src/miscellaneous/debugging.cpp +++ b/src/miscellaneous/debugging.cpp @@ -18,8 +18,8 @@ #include "miscellaneous/debugging.h" #include "definitions/definitions.h" +#include "application.h" -#include #include #include diff --git a/src/miscellaneous/iconfactory.h b/src/miscellaneous/iconfactory.h index 1fa1c6cc9..c440686a4 100644 --- a/src/miscellaneous/iconfactory.h +++ b/src/miscellaneous/iconfactory.h @@ -18,15 +18,17 @@ #ifndef ICONFACTORY_H #define ICONFACTORY_H +#include + +#include "definitions/definitions.h" +#include "application.h" + #include #include #include #include -#include #include -#include "definitions/definitions.h" - class IconFactory : public QObject { public: diff --git a/src/miscellaneous/localization.cpp b/src/miscellaneous/localization.cpp index 33e73bcc1..291610320 100644 --- a/src/miscellaneous/localization.cpp +++ b/src/miscellaneous/localization.cpp @@ -19,10 +19,9 @@ #include "definitions/definitions.h" #include "miscellaneous/settings.h" -#include "qtsingleapplication/qtsingleapplication.h" +#include "application.h" #include -#include #include #include #include @@ -61,7 +60,7 @@ void Localization::load() { if (app_translator->load(QString("rssguard-%1.qm").arg(desired_localization), APP_LANG_PATH, "-")) { - QApplication::installTranslator(app_translator); + Application::installTranslator(app_translator); qDebug("Application localization '%s' loaded successfully.", qPrintable(desired_localization)); } @@ -74,7 +73,7 @@ void Localization::load() { if (qt_translator->load(QString("qt-%1.qm").arg(desired_localization), APP_LANG_PATH, "-")) { - QApplication::installTranslator(qt_translator); + Application::installTranslator(qt_translator); qDebug("Qt localization '%s' loaded successfully.", qPrintable(desired_localization)); } diff --git a/src/miscellaneous/settings.cpp b/src/miscellaneous/settings.cpp index 0200511ab..f30a87e43 100644 --- a/src/miscellaneous/settings.cpp +++ b/src/miscellaneous/settings.cpp @@ -18,8 +18,8 @@ #include "miscellaneous/settings.h" #include "definitions/definitions.h" +#include "application.h" -#include #include #include #include diff --git a/src/miscellaneous/settings.h b/src/miscellaneous/settings.h index 0c9df77d5..dc825d874 100644 --- a/src/miscellaneous/settings.h +++ b/src/miscellaneous/settings.h @@ -19,6 +19,7 @@ #define SETTINGS_H #include + #include diff --git a/src/miscellaneous/skinfactory.cpp b/src/miscellaneous/skinfactory.cpp index ee60e17c9..3958428d8 100644 --- a/src/miscellaneous/skinfactory.cpp +++ b/src/miscellaneous/skinfactory.cpp @@ -19,8 +19,8 @@ #include "definitions/definitions.h" #include "miscellaneous/settings.h" +#include "application.h" -#include #include #include #include diff --git a/src/miscellaneous/skinfactory.h b/src/miscellaneous/skinfactory.h index 7c293847b..0d244ece5 100644 --- a/src/miscellaneous/skinfactory.h +++ b/src/miscellaneous/skinfactory.h @@ -19,6 +19,7 @@ #define SKINFACTORY_H #include + #include #include #include diff --git a/src/miscellaneous/systemfactory.cpp b/src/miscellaneous/systemfactory.cpp index 4e21c5f55..0bb0df299 100644 --- a/src/miscellaneous/systemfactory.cpp +++ b/src/miscellaneous/systemfactory.cpp @@ -19,16 +19,14 @@ #include "definitions/definitions.h" #include "network-web/networkfactory.h" +#include "application.h" #if defined(Q_OS_WIN) -#include "qtsingleapplication/qtsingleapplication.h" - #include #endif #include #include -#include #include #include #include @@ -55,7 +53,7 @@ SystemFactory::AutoStartStatus SystemFactory::getAutoStartStatus() { bool autostart_enabled = registry_key.value(APP_LOW_NAME, "").toString().replace('\\', '/') == - QtSingleApplication::applicationFilePath(); + Application::applicationFilePath(); if (autostart_enabled) { return SystemFactory::Enabled; @@ -138,8 +136,8 @@ bool SystemFactory::setAutoStartStatus(const AutoStartStatus &new_status) { switch (new_status) { case SystemFactory::Enabled: registry_key.setValue(APP_LOW_NAME, - QtSingleApplication::applicationFilePath().replace('/', - '\\')); + Application::applicationFilePath().replace('/', + '\\')); return true; case SystemFactory::Disabled: registry_key.remove(APP_LOW_NAME); diff --git a/src/miscellaneous/systemfactory.h b/src/miscellaneous/systemfactory.h index 31168e8ce..8b23355a1 100644 --- a/src/miscellaneous/systemfactory.h +++ b/src/miscellaneous/systemfactory.h @@ -19,6 +19,7 @@ #define SYSTEMFACTORY_H #include + #include #include #include diff --git a/src/network-web/networkfactory.h b/src/network-web/networkfactory.h index c6707ca2d..d45c50b47 100644 --- a/src/network-web/networkfactory.h +++ b/src/network-web/networkfactory.h @@ -19,7 +19,7 @@ #define NETWORKFACTORY_H #include -#include +#include class NetworkFactory { diff --git a/src/network-web/silentnetworkaccessmanager.cpp b/src/network-web/silentnetworkaccessmanager.cpp index 05ea2bd4f..e8f5d504c 100644 --- a/src/network-web/silentnetworkaccessmanager.cpp +++ b/src/network-web/silentnetworkaccessmanager.cpp @@ -19,7 +19,6 @@ #include #include -#include SilentNetworkAccessManager::SilentNetworkAccessManager(QObject *parent) diff --git a/src/network-web/webbrowsernetworkaccessmanager.cpp b/src/network-web/webbrowsernetworkaccessmanager.cpp index 4b2db15ed..567eed16a 100644 --- a/src/network-web/webbrowsernetworkaccessmanager.cpp +++ b/src/network-web/webbrowsernetworkaccessmanager.cpp @@ -17,8 +17,9 @@ #include "network-web/webbrowsernetworkaccessmanager.h" +#include "application.h" + #include -#include QPointer WebBrowserNetworkAccessManager::s_instance; diff --git a/src/network-web/webfactory.cpp b/src/network-web/webfactory.cpp index 13941bc71..b02d590e2 100644 --- a/src/network-web/webfactory.cpp +++ b/src/network-web/webfactory.cpp @@ -2,8 +2,8 @@ #include "definitions/definitions.h" #include "miscellaneous/settings.h" +#include "application.h" -#include #include #include #include diff --git a/src/network-web/webview.cpp b/src/network-web/webview.cpp index 03b2f9eb1..a0276ff4a 100644 --- a/src/network-web/webview.cpp +++ b/src/network-web/webview.cpp @@ -54,7 +54,7 @@ void WebView::onLoadFinished(bool ok) { } void WebView::copySelectedText() { - QApplication::clipboard()->setText(selectedText()); + Application::clipboard()->setText(selectedText()); } void WebView::openLinkInNewTab() { diff --git a/src/updater/formupdater.cpp b/src/updater/formupdater.cpp index f44ffb158..f96c1ce2b 100644 --- a/src/updater/formupdater.cpp +++ b/src/updater/formupdater.cpp @@ -1,9 +1,25 @@ +// This file is part of RSS Guard. +// +// Copyright (C) 2011-2014 by Martin Rotter +// +// RSS Guard is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// RSS Guard is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with RSS Guard. If not, see . + #include "updater/formupdater.h" #include "definitions/definitions.h" #include "qtsingleapplication/qtsingleapplication.h" -#include #include #include #include @@ -60,7 +76,7 @@ void FormUpdater::startUpgrade() { printHeading("Welcome to RSS Guard updater"); printText("Analyzing updater arguments."); - if (QApplication::arguments().size() != 5) { + if (QtSingleApplication::arguments().size() != 5) { printText("Insufficient arguments passed. Update process cannot proceed."); printText("\nPress any key to exit updater..."); @@ -87,7 +103,7 @@ void FormUpdater::startUpgrade() { void FormUpdater::saveArguments() { // Obtain parameters. - QStringList arguments = QApplication::arguments(); + QStringList arguments = QtSingleApplication::arguments(); m_parsedArguments["updater_path"] = QDir::toNativeSeparators(qApp->applicationFilePath()); m_parsedArguments["current_version"] = arguments.at(1); @@ -210,7 +226,7 @@ bool FormUpdater::doPreparationCleanup() { printText(QString("Check for running instances of RSS Guard, attempt %1.").arg(i)); - if (static_cast(qApp)->sendMessage(APP_QUIT_INSTANCE)) { + if (static_cast(QCoreApplication::instance())->sendMessage(APP_QUIT_INSTANCE)) { printText("The main application is running. Quitting it."); printText("Waiting for 6000 ms for main application to finish."); diff --git a/src/updater/formupdater.h b/src/updater/formupdater.h index 500a09852..35cff9480 100644 --- a/src/updater/formupdater.h +++ b/src/updater/formupdater.h @@ -1,3 +1,20 @@ +// This file is part of RSS Guard. +// +// Copyright (C) 2011-2014 by Martin Rotter +// +// RSS Guard is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// RSS Guard is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with RSS Guard. If not, see . + #ifndef FORMUPDATER_H #define FORMUPDATER_H @@ -61,6 +78,7 @@ class FormUpdater : public QMainWindow { void consumeDebugMessage(QtMsgType type, const QString &message); signals: + // Emitted if new debug messaages is produced and should be printed. void debugMessageProduced(QtMsgType type, QString message); protected: diff --git a/src/updater/main.cpp b/src/updater/main.cpp index 07654fdac..9a638a8c1 100644 --- a/src/updater/main.cpp +++ b/src/updater/main.cpp @@ -26,9 +26,6 @@ #include #include -#include -#include - // Main entry point to "rssguard_updater.exe". // It expects 4 ARGUMENTS: @@ -40,7 +37,7 @@ int main(int argc, char *argv[]) { // Instantiate base application object. QtSingleApplication application(APP_LOW_NAME, argc, argv); - application.setQuitOnLastWindowClosed(true); + QtSingleApplication::setQuitOnLastWindowClosed(true); FormUpdater main_form;