Refactoring.

This commit is contained in:
Martin Rotter 2014-04-17 13:49:38 +02:00
parent 0210d7bd31
commit 5842657cb9
32 changed files with 130 additions and 65 deletions

View File

@ -1,8 +1,25 @@
// This file is part of RSS Guard.
//
// Copyright (C) 2011-2014 by Martin Rotter <rotter.martinos@gmail.com>
//
// 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 <http://www.gnu.org/licenses/>.
#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() {

View File

@ -1,8 +1,30 @@
// This file is part of RSS Guard.
//
// Copyright (C) 2011-2014 by Martin Rotter <rotter.martinos@gmail.com>
//
// 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 <http://www.gnu.org/licenses/>.
#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.

View File

@ -21,7 +21,6 @@
#include <QThread>
#include <QDebug>
#include <QApplication>
FeedDownloader::FeedDownloader(QObject *parent) : QObject(parent) {

View File

@ -21,7 +21,7 @@
#include "core/feedsmodelrootitem.h"
#include <QSqlRecord>
#include <QApplication>
#include <QCoreApplication>
class FeedsModelFeed;

View File

@ -25,12 +25,11 @@
#include <QSqlRecord>
#include <QPair>
#include <QNetworkReply>
#include <QApplication>
#include <QCoreApplication>
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 {

View File

@ -17,7 +17,7 @@
#include "core/feedsmodelrootitem.h"
#include "qtsingleapplication/qtsingleapplication.h"
#include "application.h"
#include <QVariant>
@ -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);
}

View File

@ -21,7 +21,7 @@
#include "miscellaneous/textfactory.h"
#include "miscellaneous/databasefactory.h"
#include "miscellaneous/iconfactory.h"
#include "qtsingleapplication/qtsingleapplication.h"
#include "application.h"
#include <QSqlRecord>
#include <QSqlError>
@ -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);
}

View File

@ -33,7 +33,7 @@
#include "gui/statusbar.h"
#include "gui/feedmessageviewer.h"
#include "gui/formupdate.h"
#include "qtsingleapplication/qtsingleapplication.h"
#include "application.h"
#include <QCloseEvent>
#include <QSessionManager>
@ -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) {

View File

@ -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 <QProcess>
#include <QNetworkProxy>

View File

@ -17,13 +17,7 @@
#include "gui/locationlineedit.h"
#include "definitions/definitions.h"
#include "miscellaneous/settings.h"
#include <QPaintEvent>
#include <QStyleOptionFrameV2>
#include <QPainter>
#include <QApplication>
#include <QMouseEvent>
LocationLineEdit::LocationLineEdit(QWidget *parent)

View File

@ -18,13 +18,14 @@
#include "gui/messagebox.h"
#include "miscellaneous/iconfactory.h"
#include "application.h"
#include <QDialogButtonBox>
#include <QtGlobal>
#include <QDialogButtonBox>
#include <QPushButton>
#include <QDialogButtonBox>
#include <QStyle>
#include <QApplication>
MessageBox::MessageBox(QWidget *parent) : QMessageBox(parent) {
}

View File

@ -21,7 +21,7 @@
#include "miscellaneous/settings.h"
#include "gui/formmain.h"
#include "gui/formsettings.h"
#include "qtsingleapplication/qtsingleapplication.h"
#include "application.h"
#include <QPainter>
#include <QTimer>
@ -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,

View File

@ -26,8 +26,8 @@
#include "gui/formmain.h"
#include "gui/feedmessageviewer.h"
#include "gui/plaintoolbutton.h"
#include "application.h"
#include <QApplication>
#include <QMenu>
#include <QToolButton>

View File

@ -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();
}

View File

@ -19,8 +19,8 @@
#include "definitions/definitions.h"
#include "miscellaneous/settings.h"
#include "application.h"
#include <QApplication>
#include <QDir>
#include <QSqlQuery>
#include <QSqlError>

View File

@ -18,8 +18,8 @@
#include "miscellaneous/debugging.h"
#include "definitions/definitions.h"
#include "application.h"
#include <QApplication>
#include <QDir>
#include <cstdio>

View File

@ -18,15 +18,17 @@
#ifndef ICONFACTORY_H
#define ICONFACTORY_H
#include <QObject>
#include "definitions/definitions.h"
#include "application.h"
#include <QString>
#include <QIcon>
#include <QPointer>
#include <QHash>
#include <QApplication>
#include <QDir>
#include "definitions/definitions.h"
class IconFactory : public QObject {
public:

View File

@ -19,10 +19,9 @@
#include "definitions/definitions.h"
#include "miscellaneous/settings.h"
#include "qtsingleapplication/qtsingleapplication.h"
#include "application.h"
#include <QPointer>
#include <QApplication>
#include <QTranslator>
#include <QDir>
#include <QFileInfoList>
@ -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));
}

View File

@ -18,8 +18,8 @@
#include "miscellaneous/settings.h"
#include "definitions/definitions.h"
#include "application.h"
#include <QApplication>
#include <QDebug>
#include <QDir>
#include <QPointer>

View File

@ -19,6 +19,7 @@
#define SETTINGS_H
#include <QSettings>
#include <QPointer>

View File

@ -19,8 +19,8 @@
#include "definitions/definitions.h"
#include "miscellaneous/settings.h"
#include "application.h"
#include <QApplication>
#include <QDir>
#include <QStyleFactory>
#include <QDomDocument>

View File

@ -19,6 +19,7 @@
#define SKINFACTORY_H
#include <QObject>
#include <QPointer>
#include <QStringList>
#include <QMetaType>

View File

@ -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 <QSettings>
#endif
#include <QString>
#include <QFile>
#include <QApplication>
#include <QDomDocument>
#include <QDomElement>
#include <QDomAttr>
@ -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);

View File

@ -19,6 +19,7 @@
#define SYSTEMFACTORY_H
#include <QObject>
#include <QPointer>
#include <QMutex>
#include <QMetaType>

View File

@ -19,7 +19,7 @@
#define NETWORKFACTORY_H
#include <QNetworkReply>
#include <QApplication>
#include <QCoreApplication>
class NetworkFactory {

View File

@ -19,7 +19,6 @@
#include <QNetworkReply>
#include <QAuthenticator>
#include <QApplication>
SilentNetworkAccessManager::SilentNetworkAccessManager(QObject *parent)

View File

@ -17,8 +17,9 @@
#include "network-web/webbrowsernetworkaccessmanager.h"
#include "application.h"
#include <QNetworkReply>
#include <QApplication>
QPointer<WebBrowserNetworkAccessManager> WebBrowserNetworkAccessManager::s_instance;

View File

@ -2,8 +2,8 @@
#include "definitions/definitions.h"
#include "miscellaneous/settings.h"
#include "application.h"
#include <QApplication>
#include <QRegExp>
#include <QWebSettings>
#include <QProcess>

View File

@ -54,7 +54,7 @@ void WebView::onLoadFinished(bool ok) {
}
void WebView::copySelectedText() {
QApplication::clipboard()->setText(selectedText());
Application::clipboard()->setText(selectedText());
}
void WebView::openLinkInNewTab() {

View File

@ -1,9 +1,25 @@
// This file is part of RSS Guard.
//
// Copyright (C) 2011-2014 by Martin Rotter <rotter.martinos@gmail.com>
//
// 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 <http://www.gnu.org/licenses/>.
#include "updater/formupdater.h"
#include "definitions/definitions.h"
#include "qtsingleapplication/qtsingleapplication.h"
#include <QApplication>
#include <QDesktopWidget>
#include <QIcon>
#include <QDir>
@ -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<QtSingleApplication*>(qApp)->sendMessage(APP_QUIT_INSTANCE)) {
if (static_cast<QtSingleApplication*>(QCoreApplication::instance())->sendMessage(APP_QUIT_INSTANCE)) {
printText("The main application is running. Quitting it.");
printText("Waiting for 6000 ms for main application to finish.");

View File

@ -1,3 +1,20 @@
// This file is part of RSS Guard.
//
// Copyright (C) 2011-2014 by Martin Rotter <rotter.martinos@gmail.com>
//
// 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 <http://www.gnu.org/licenses/>.
#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:

View File

@ -26,9 +26,6 @@
#include <QFileInfo>
#include <QDir>
#include <iostream>
#include <limits>
// 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;