Refactoring PuzzleApplication
This commit is contained in:
parent
04e97b6e74
commit
5bd695b646
|
@ -29,7 +29,7 @@
|
|||
#include <QMessageBox> // For QT_REQUIRE_VERSION
|
||||
#include <QTimer>
|
||||
|
||||
#include "puzzleapplication.h"
|
||||
#include "vpapplication.h"
|
||||
#include "../fervor/fvupdater.h"
|
||||
#include "../vmisc/vsysexits.h"
|
||||
#include "../vmisc/def.h"
|
||||
|
@ -64,7 +64,7 @@ int main(int argc, char *argv[])
|
|||
InitHighDpiScaling(argc, argv);
|
||||
#endif //Q_OS_MAC
|
||||
|
||||
PuzzleApplication app(argc, argv);
|
||||
VPApplication app(argc, argv);
|
||||
app.InitOptions();
|
||||
|
||||
if (FvUpdater::IsStaledTestBuild())
|
||||
|
@ -78,7 +78,7 @@ int main(int argc, char *argv[])
|
|||
return V_EX_UNAVAILABLE;
|
||||
}
|
||||
|
||||
QTimer::singleShot(0, &app, &PuzzleApplication::ProcessCMD);
|
||||
QTimer::singleShot(0, &app, &VPApplication::ProcessCMD);
|
||||
|
||||
#if defined(APPIMAGE) && defined(Q_OS_LINUX)
|
||||
if (exe_dir)
|
||||
|
|
|
@ -6,7 +6,7 @@ SOURCES += \
|
|||
$$PWD/main.cpp \
|
||||
$$PWD/puzzlecommands.cpp \
|
||||
$$PWD/puzzlemainwindow.cpp \
|
||||
$$PWD/puzzleapplication.cpp \
|
||||
$$PWD/vpapplication.cpp \
|
||||
$$PWD/vpiececarrouselpiecepreview.cpp \
|
||||
$$PWD/vpuzzlecommandline.cpp \
|
||||
$$PWD/vpiececarrousel.cpp \
|
||||
|
@ -31,7 +31,7 @@ HEADERS += \
|
|||
$$PWD/puzzlecommands.h \
|
||||
$$PWD/puzzlemainwindow.h \
|
||||
$$PWD/stable.h \
|
||||
$$PWD/puzzleapplication.h \
|
||||
$$PWD/vpapplication.h \
|
||||
$$PWD/vpiececarrouselpiecepreview.h \
|
||||
$$PWD/vpuzzlecommandline.h \
|
||||
$$PWD/vpiececarrousel.h \
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
#include "dialogs/vpdialogabout.h"
|
||||
#include "xml/vplayoutfilewriter.h"
|
||||
#include "xml/vplayoutfilereader.h"
|
||||
#include "puzzleapplication.h"
|
||||
#include "vpapplication.h"
|
||||
#include "../vlayout/vrawlayout.h"
|
||||
#include "../vmisc/vsysexits.h"
|
||||
#include "../vmisc/projectversion.h"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/************************************************************************
|
||||
**
|
||||
** @file puzzleapplication.cpp
|
||||
** @file vpapplication.cpp
|
||||
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||
** @date 16 2, 2020
|
||||
**
|
||||
|
@ -26,7 +26,7 @@
|
|||
**
|
||||
*************************************************************************/
|
||||
|
||||
#include "puzzleapplication.h"
|
||||
#include "vpapplication.h"
|
||||
#include "version.h"
|
||||
#include "puzzlemainwindow.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),
|
||||
mainWindows(),
|
||||
localServer(nullptr)
|
||||
|
@ -250,7 +250,7 @@ PuzzleApplication::PuzzleApplication(int &argc, char **argv)
|
|||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
PuzzleApplication::~PuzzleApplication()
|
||||
VPApplication::~VPApplication()
|
||||
{
|
||||
qDeleteAll(mainWindows);
|
||||
}
|
||||
|
@ -263,7 +263,7 @@ PuzzleApplication::~PuzzleApplication()
|
|||
* @return value that is returned from the receiver's event handler.
|
||||
*/
|
||||
// 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
|
||||
{
|
||||
|
@ -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.
|
||||
*/
|
||||
bool PuzzleApplication::IsAppInGUIMode() const
|
||||
bool VPApplication::IsAppInGUIMode() const
|
||||
{
|
||||
return CommandLine()->IsGuiEnabled();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
PuzzleMainWindow *PuzzleApplication::MainWindow()
|
||||
PuzzleMainWindow *VPApplication::MainWindow()
|
||||
{
|
||||
Clean();
|
||||
if (mainWindows.isEmpty())
|
||||
|
@ -343,7 +343,7 @@ PuzzleMainWindow *PuzzleApplication::MainWindow()
|
|||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QList<PuzzleMainWindow *> PuzzleApplication::MainWindows()
|
||||
QList<PuzzleMainWindow *> VPApplication::MainWindows()
|
||||
{
|
||||
Clean();
|
||||
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);
|
||||
mainWindows.prepend(puzzle);
|
||||
|
@ -367,7 +367,7 @@ PuzzleMainWindow *PuzzleApplication::NewMainWindow(const VPuzzleCommandLinePtr &
|
|||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void PuzzleApplication::InitOptions()
|
||||
void VPApplication::InitOptions()
|
||||
{
|
||||
qInstallMessageHandler(noisyFailureMsgHandler);
|
||||
|
||||
|
@ -397,27 +397,27 @@ void PuzzleApplication::InitOptions()
|
|||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
const VTranslateVars *PuzzleApplication::TrVars()
|
||||
const VTranslateVars *VPApplication::TrVars()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void PuzzleApplication::OpenSettings()
|
||||
void VPApplication::OpenSettings()
|
||||
{
|
||||
settings = new VPuzzleSettings(QSettings::IniFormat, QSettings::UserScope, QCoreApplication::organizationName(),
|
||||
QCoreApplication::applicationName(), this);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
VPuzzleSettings *PuzzleApplication::PuzzleSettings()
|
||||
VPuzzleSettings *VPApplication::PuzzleSettings()
|
||||
{
|
||||
SCASSERT(settings != nullptr)
|
||||
return qobject_cast<VPuzzleSettings *>(settings);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void PuzzleApplication::ActivateDarkMode()
|
||||
void VPApplication::ActivateDarkMode()
|
||||
{
|
||||
VPuzzleSettings *settings = qApp->PuzzleSettings();
|
||||
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;
|
||||
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));
|
||||
|
||||
localServer = new QLocalServer(this);
|
||||
connect(localServer, &QLocalServer::newConnection, this, &PuzzleApplication::NewLocalSocketConnection);
|
||||
connect(localServer, &QLocalServer::newConnection, this, &VPApplication::NewLocalSocketConnection);
|
||||
if (not localServer->listen(serverName))
|
||||
{
|
||||
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 args = cmd->OptionFileNames();
|
||||
|
@ -545,13 +545,13 @@ void PuzzleApplication::ProcessArguments(const VPuzzleCommandLinePtr &cmd)
|
|||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void PuzzleApplication::ProcessCMD()
|
||||
void VPApplication::ProcessCMD()
|
||||
{
|
||||
ParseCommandLine(SocketConnection::Client, arguments());
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
bool PuzzleApplication::event(QEvent *e)
|
||||
bool VPApplication::event(QEvent *e)
|
||||
{
|
||||
switch(e->type())
|
||||
{
|
||||
|
@ -591,13 +591,13 @@ bool PuzzleApplication::event(QEvent *e)
|
|||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void PuzzleApplication::InitTrVars()
|
||||
void VPApplication::InitTrVars()
|
||||
{
|
||||
// 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
|
||||
// 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());
|
||||
if (socket.isNull())
|
||||
|
@ -625,7 +625,7 @@ void PuzzleApplication::NewLocalSocketConnection()
|
|||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void PuzzleApplication::Clean()
|
||||
void VPApplication::Clean()
|
||||
{
|
||||
// cleanup any deleted main windows first
|
||||
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;
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
/************************************************************************
|
||||
**
|
||||
** @file puzzleapplication.h
|
||||
** @file vpapplication.h
|
||||
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||
** @date 16 2, 2020
|
||||
**
|
||||
|
@ -25,8 +25,8 @@
|
|||
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
|
||||
**
|
||||
*************************************************************************/
|
||||
#ifndef PUZZLEAPPLICATION_H
|
||||
#define PUZZLEAPPLICATION_H
|
||||
#ifndef VPAPPLICATION_H
|
||||
#define VPAPPLICATION_H
|
||||
|
||||
#include "../vmisc/def.h"
|
||||
#include "vpuzzlesettings.h"
|
||||
|
@ -35,23 +35,23 @@
|
|||
|
||||
#include <memory>
|
||||
|
||||
class PuzzleApplication;// use in define
|
||||
class VPApplication;// use in define
|
||||
class PuzzleMainWindow;
|
||||
class QLocalServer;
|
||||
|
||||
#if defined(qApp)
|
||||
#undef qApp
|
||||
#endif
|
||||
#define qApp (static_cast<PuzzleApplication*>(VAbstractApplication::instance()))
|
||||
#define qApp (static_cast<VPApplication*>(VAbstractApplication::instance()))
|
||||
|
||||
enum class SocketConnection : bool {Client = false, Server = true};
|
||||
|
||||
class PuzzleApplication : public VAbstractApplication
|
||||
class VPApplication : public VAbstractApplication
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
PuzzleApplication(int &argc, char **argv);
|
||||
virtual ~PuzzleApplication() override;
|
||||
VPApplication(int &argc, char **argv);
|
||||
virtual ~VPApplication() override;
|
||||
|
||||
virtual bool notify(QObject * receiver, QEvent * event) override;
|
||||
|
||||
|
@ -85,11 +85,11 @@ private slots:
|
|||
void NewLocalSocketConnection();
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(PuzzleApplication)
|
||||
Q_DISABLE_COPY(VPApplication)
|
||||
QList<QPointer<PuzzleMainWindow> > mainWindows;
|
||||
QLocalServer *localServer;
|
||||
|
||||
void Clean();
|
||||
};
|
||||
|
||||
#endif // PUZZLEAPPLICATION_H
|
||||
#endif // VPAPPLICATION_H
|
|
@ -66,7 +66,7 @@ public:
|
|||
protected:
|
||||
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 void ProcessInstance(VPuzzleCommandLinePtr &instance, const QStringList &arguments);
|
||||
private:
|
||||
|
@ -74,7 +74,7 @@ private:
|
|||
static VPuzzleCommandLinePtr instance;
|
||||
QCommandLineParser parser;
|
||||
bool isGuiEnabled;
|
||||
friend class PuzzleApplication;
|
||||
friend class VPApplication;
|
||||
|
||||
/** @brief add options to the QCommandLineParser that there are in the cmd can be */
|
||||
void InitCommandLineOptions();
|
||||
|
|
Loading…
Reference in New Issue
Block a user