Refactoring PuzzleApplication

This commit is contained in:
Ronan Le Tiec 2020-05-23 14:10:05 +02:00
parent 04e97b6e74
commit 5bd695b646
6 changed files with 42 additions and 42 deletions

View File

@ -29,7 +29,7 @@
#include <QMessageBox> // For QT_REQUIRE_VERSION #include <QMessageBox> // For QT_REQUIRE_VERSION
#include <QTimer> #include <QTimer>
#include "puzzleapplication.h" #include "vpapplication.h"
#include "../fervor/fvupdater.h" #include "../fervor/fvupdater.h"
#include "../vmisc/vsysexits.h" #include "../vmisc/vsysexits.h"
#include "../vmisc/def.h" #include "../vmisc/def.h"
@ -64,7 +64,7 @@ int main(int argc, char *argv[])
InitHighDpiScaling(argc, argv); InitHighDpiScaling(argc, argv);
#endif //Q_OS_MAC #endif //Q_OS_MAC
PuzzleApplication app(argc, argv); VPApplication app(argc, argv);
app.InitOptions(); app.InitOptions();
if (FvUpdater::IsStaledTestBuild()) if (FvUpdater::IsStaledTestBuild())
@ -78,7 +78,7 @@ int main(int argc, char *argv[])
return V_EX_UNAVAILABLE; return V_EX_UNAVAILABLE;
} }
QTimer::singleShot(0, &app, &PuzzleApplication::ProcessCMD); QTimer::singleShot(0, &app, &VPApplication::ProcessCMD);
#if defined(APPIMAGE) && defined(Q_OS_LINUX) #if defined(APPIMAGE) && defined(Q_OS_LINUX)
if (exe_dir) if (exe_dir)

View File

@ -6,7 +6,7 @@ SOURCES += \
$$PWD/main.cpp \ $$PWD/main.cpp \
$$PWD/puzzlecommands.cpp \ $$PWD/puzzlecommands.cpp \
$$PWD/puzzlemainwindow.cpp \ $$PWD/puzzlemainwindow.cpp \
$$PWD/puzzleapplication.cpp \ $$PWD/vpapplication.cpp \
$$PWD/vpiececarrouselpiecepreview.cpp \ $$PWD/vpiececarrouselpiecepreview.cpp \
$$PWD/vpuzzlecommandline.cpp \ $$PWD/vpuzzlecommandline.cpp \
$$PWD/vpiececarrousel.cpp \ $$PWD/vpiececarrousel.cpp \
@ -31,7 +31,7 @@ HEADERS += \
$$PWD/puzzlecommands.h \ $$PWD/puzzlecommands.h \
$$PWD/puzzlemainwindow.h \ $$PWD/puzzlemainwindow.h \
$$PWD/stable.h \ $$PWD/stable.h \
$$PWD/puzzleapplication.h \ $$PWD/vpapplication.h \
$$PWD/vpiececarrouselpiecepreview.h \ $$PWD/vpiececarrouselpiecepreview.h \
$$PWD/vpuzzlecommandline.h \ $$PWD/vpuzzlecommandline.h \
$$PWD/vpiececarrousel.h \ $$PWD/vpiececarrousel.h \

View File

@ -34,7 +34,7 @@
#include "dialogs/vpdialogabout.h" #include "dialogs/vpdialogabout.h"
#include "xml/vplayoutfilewriter.h" #include "xml/vplayoutfilewriter.h"
#include "xml/vplayoutfilereader.h" #include "xml/vplayoutfilereader.h"
#include "puzzleapplication.h" #include "vpapplication.h"
#include "../vlayout/vrawlayout.h" #include "../vlayout/vrawlayout.h"
#include "../vmisc/vsysexits.h" #include "../vmisc/vsysexits.h"
#include "../vmisc/projectversion.h" #include "../vmisc/projectversion.h"

View File

@ -1,6 +1,6 @@
/************************************************************************ /************************************************************************
** **
** @file puzzleapplication.cpp ** @file vpapplication.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com> ** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 16 2, 2020 ** @date 16 2, 2020
** **
@ -26,7 +26,7 @@
** **
*************************************************************************/ *************************************************************************/
#include "puzzleapplication.h" #include "vpapplication.h"
#include "version.h" #include "version.h"
#include "puzzlemainwindow.h" #include "puzzlemainwindow.h"
#include "../ifc/exception/vexceptionobjecterror.h" #include "../ifc/exception/vexceptionobjecterror.h"
@ -232,7 +232,7 @@ inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &con
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
PuzzleApplication::PuzzleApplication(int &argc, char **argv) VPApplication::VPApplication(int &argc, char **argv)
:VAbstractApplication(argc, argv), :VAbstractApplication(argc, argv),
mainWindows(), mainWindows(),
localServer(nullptr) localServer(nullptr)
@ -250,7 +250,7 @@ PuzzleApplication::PuzzleApplication(int &argc, char **argv)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
PuzzleApplication::~PuzzleApplication() VPApplication::~VPApplication()
{ {
qDeleteAll(mainWindows); qDeleteAll(mainWindows);
} }
@ -263,7 +263,7 @@ PuzzleApplication::~PuzzleApplication()
* @return value that is returned from the receiver's event handler. * @return value that is returned from the receiver's event handler.
*/ */
// reimplemented from QApplication so we can throw exceptions in slots // reimplemented from QApplication so we can throw exceptions in slots
bool PuzzleApplication::notify(QObject *receiver, QEvent *event) bool VPApplication::notify(QObject *receiver, QEvent *event)
{ {
try try
{ {
@ -324,13 +324,13 @@ bool PuzzleApplication::notify(QObject *receiver, QEvent *event)
/** /**
* @brief IsAppInGUIMode little hack that allow to have access to application state from VAbstractApplication class. * @brief IsAppInGUIMode little hack that allow to have access to application state from VAbstractApplication class.
*/ */
bool PuzzleApplication::IsAppInGUIMode() const bool VPApplication::IsAppInGUIMode() const
{ {
return CommandLine()->IsGuiEnabled(); return CommandLine()->IsGuiEnabled();
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
PuzzleMainWindow *PuzzleApplication::MainWindow() PuzzleMainWindow *VPApplication::MainWindow()
{ {
Clean(); Clean();
if (mainWindows.isEmpty()) if (mainWindows.isEmpty())
@ -343,7 +343,7 @@ PuzzleMainWindow *PuzzleApplication::MainWindow()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QList<PuzzleMainWindow *> PuzzleApplication::MainWindows() QList<PuzzleMainWindow *> VPApplication::MainWindows()
{ {
Clean(); Clean();
QList<PuzzleMainWindow*> list; QList<PuzzleMainWindow*> list;
@ -355,7 +355,7 @@ QList<PuzzleMainWindow *> PuzzleApplication::MainWindows()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
PuzzleMainWindow *PuzzleApplication::NewMainWindow(const VPuzzleCommandLinePtr &cmd) PuzzleMainWindow *VPApplication::NewMainWindow(const VPuzzleCommandLinePtr &cmd)
{ {
PuzzleMainWindow *puzzle = new PuzzleMainWindow(cmd); PuzzleMainWindow *puzzle = new PuzzleMainWindow(cmd);
mainWindows.prepend(puzzle); mainWindows.prepend(puzzle);
@ -367,7 +367,7 @@ PuzzleMainWindow *PuzzleApplication::NewMainWindow(const VPuzzleCommandLinePtr &
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void PuzzleApplication::InitOptions() void VPApplication::InitOptions()
{ {
qInstallMessageHandler(noisyFailureMsgHandler); qInstallMessageHandler(noisyFailureMsgHandler);
@ -397,27 +397,27 @@ void PuzzleApplication::InitOptions()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
const VTranslateVars *PuzzleApplication::TrVars() const VTranslateVars *VPApplication::TrVars()
{ {
return nullptr; return nullptr;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void PuzzleApplication::OpenSettings() void VPApplication::OpenSettings()
{ {
settings = new VPuzzleSettings(QSettings::IniFormat, QSettings::UserScope, QCoreApplication::organizationName(), settings = new VPuzzleSettings(QSettings::IniFormat, QSettings::UserScope, QCoreApplication::organizationName(),
QCoreApplication::applicationName(), this); QCoreApplication::applicationName(), this);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VPuzzleSettings *PuzzleApplication::PuzzleSettings() VPuzzleSettings *VPApplication::PuzzleSettings()
{ {
SCASSERT(settings != nullptr) SCASSERT(settings != nullptr)
return qobject_cast<VPuzzleSettings *>(settings); return qobject_cast<VPuzzleSettings *>(settings);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void PuzzleApplication::ActivateDarkMode() void VPApplication::ActivateDarkMode()
{ {
VPuzzleSettings *settings = qApp->PuzzleSettings(); VPuzzleSettings *settings = qApp->PuzzleSettings();
if (settings->GetDarkMode()) if (settings->GetDarkMode())
@ -437,7 +437,7 @@ void PuzzleApplication::ActivateDarkMode()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void PuzzleApplication::ParseCommandLine(const SocketConnection &connection, const QStringList &arguments) void VPApplication::ParseCommandLine(const SocketConnection &connection, const QStringList &arguments)
{ {
VPuzzleCommandLinePtr cmd; VPuzzleCommandLinePtr cmd;
VPuzzleCommandLine::ProcessInstance(cmd, arguments); VPuzzleCommandLine::ProcessInstance(cmd, arguments);
@ -461,7 +461,7 @@ void PuzzleApplication::ParseCommandLine(const SocketConnection &connection, con
qCDebug(mApp, "Can't establish connection to the server '%s'", qUtf8Printable(serverName)); qCDebug(mApp, "Can't establish connection to the server '%s'", qUtf8Printable(serverName));
localServer = new QLocalServer(this); localServer = new QLocalServer(this);
connect(localServer, &QLocalServer::newConnection, this, &PuzzleApplication::NewLocalSocketConnection); connect(localServer, &QLocalServer::newConnection, this, &VPApplication::NewLocalSocketConnection);
if (not localServer->listen(serverName)) if (not localServer->listen(serverName))
{ {
qCDebug(mApp, "Can't begin to listen for incoming connections on name '%s'", qCDebug(mApp, "Can't begin to listen for incoming connections on name '%s'",
@ -484,7 +484,7 @@ void PuzzleApplication::ParseCommandLine(const SocketConnection &connection, con
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void PuzzleApplication::ProcessArguments(const VPuzzleCommandLinePtr &cmd) void VPApplication::ProcessArguments(const VPuzzleCommandLinePtr &cmd)
{ {
const QStringList rawLayouts = cmd->OptionRawLayouts(); const QStringList rawLayouts = cmd->OptionRawLayouts();
const QStringList args = cmd->OptionFileNames(); const QStringList args = cmd->OptionFileNames();
@ -545,13 +545,13 @@ void PuzzleApplication::ProcessArguments(const VPuzzleCommandLinePtr &cmd)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void PuzzleApplication::ProcessCMD() void VPApplication::ProcessCMD()
{ {
ParseCommandLine(SocketConnection::Client, arguments()); ParseCommandLine(SocketConnection::Client, arguments());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
bool PuzzleApplication::event(QEvent *e) bool VPApplication::event(QEvent *e)
{ {
switch(e->type()) switch(e->type())
{ {
@ -591,13 +591,13 @@ bool PuzzleApplication::event(QEvent *e)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void PuzzleApplication::InitTrVars() void VPApplication::InitTrVars()
{ {
// do nothing // do nothing
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void PuzzleApplication::AboutToQuit() void VPApplication::AboutToQuit()
{ {
// If try to use the method QApplication::exit program can't sync settings and show warning about QApplication // If try to use the method QApplication::exit program can't sync settings and show warning about QApplication
// instance. Solution is to call sync() before quit. // instance. Solution is to call sync() before quit.
@ -606,7 +606,7 @@ void PuzzleApplication::AboutToQuit()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void PuzzleApplication::NewLocalSocketConnection() void VPApplication::NewLocalSocketConnection()
{ {
QScopedPointer<QLocalSocket>socket(localServer->nextPendingConnection()); QScopedPointer<QLocalSocket>socket(localServer->nextPendingConnection());
if (socket.isNull()) if (socket.isNull())
@ -625,7 +625,7 @@ void PuzzleApplication::NewLocalSocketConnection()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void PuzzleApplication::Clean() void VPApplication::Clean()
{ {
// cleanup any deleted main windows first // cleanup any deleted main windows first
for (int i = mainWindows.count() - 1; i >= 0; --i) for (int i = mainWindows.count() - 1; i >= 0; --i)
@ -638,7 +638,7 @@ void PuzzleApplication::Clean()
} }
//-------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------
VPuzzleCommandLinePtr PuzzleApplication::CommandLine() const VPuzzleCommandLinePtr VPApplication::CommandLine() const
{ {
return VPuzzleCommandLine::instance; return VPuzzleCommandLine::instance;
} }

View File

@ -1,6 +1,6 @@
/************************************************************************ /************************************************************************
** **
** @file puzzleapplication.h ** @file vpapplication.h
** @author Roman Telezhynskyi <dismine(at)gmail.com> ** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 16 2, 2020 ** @date 16 2, 2020
** **
@ -25,8 +25,8 @@
** along with Valentina. If not, see <http://www.gnu.org/licenses/>. ** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
** **
*************************************************************************/ *************************************************************************/
#ifndef PUZZLEAPPLICATION_H #ifndef VPAPPLICATION_H
#define PUZZLEAPPLICATION_H #define VPAPPLICATION_H
#include "../vmisc/def.h" #include "../vmisc/def.h"
#include "vpuzzlesettings.h" #include "vpuzzlesettings.h"
@ -35,23 +35,23 @@
#include <memory> #include <memory>
class PuzzleApplication;// use in define class VPApplication;// use in define
class PuzzleMainWindow; class PuzzleMainWindow;
class QLocalServer; class QLocalServer;
#if defined(qApp) #if defined(qApp)
#undef qApp #undef qApp
#endif #endif
#define qApp (static_cast<PuzzleApplication*>(VAbstractApplication::instance())) #define qApp (static_cast<VPApplication*>(VAbstractApplication::instance()))
enum class SocketConnection : bool {Client = false, Server = true}; enum class SocketConnection : bool {Client = false, Server = true};
class PuzzleApplication : public VAbstractApplication class VPApplication : public VAbstractApplication
{ {
Q_OBJECT Q_OBJECT
public: public:
PuzzleApplication(int &argc, char **argv); VPApplication(int &argc, char **argv);
virtual ~PuzzleApplication() override; virtual ~VPApplication() override;
virtual bool notify(QObject * receiver, QEvent * event) override; virtual bool notify(QObject * receiver, QEvent * event) override;
@ -85,11 +85,11 @@ private slots:
void NewLocalSocketConnection(); void NewLocalSocketConnection();
private: private:
Q_DISABLE_COPY(PuzzleApplication) Q_DISABLE_COPY(VPApplication)
QList<QPointer<PuzzleMainWindow> > mainWindows; QList<QPointer<PuzzleMainWindow> > mainWindows;
QLocalServer *localServer; QLocalServer *localServer;
void Clean(); void Clean();
}; };
#endif // PUZZLEAPPLICATION_H #endif // VPAPPLICATION_H

View File

@ -66,7 +66,7 @@ public:
protected: protected:
VPuzzleCommandLine(); VPuzzleCommandLine();
/** @brief create the single instance of the class inside puzzleapplication */ /** @brief create the single instance of the class inside vpapplication */
static VPuzzleCommandLinePtr Instance(const QCoreApplication &app); static VPuzzleCommandLinePtr Instance(const QCoreApplication &app);
static void ProcessInstance(VPuzzleCommandLinePtr &instance, const QStringList &arguments); static void ProcessInstance(VPuzzleCommandLinePtr &instance, const QStringList &arguments);
private: private:
@ -74,7 +74,7 @@ private:
static VPuzzleCommandLinePtr instance; static VPuzzleCommandLinePtr instance;
QCommandLineParser parser; QCommandLineParser parser;
bool isGuiEnabled; bool isGuiEnabled;
friend class PuzzleApplication; friend class VPApplication;
/** @brief add options to the QCommandLineParser that there are in the cmd can be */ /** @brief add options to the QCommandLineParser that there are in the cmd can be */
void InitCommandLineOptions(); void InitCommandLineOptions();