Refactoring.
This commit is contained in:
parent
36180a7c38
commit
f005b78ecc
|
@ -35,7 +35,11 @@
|
||||||
#include "../ifc/exception/vexceptionemptyparameter.h"
|
#include "../ifc/exception/vexceptionemptyparameter.h"
|
||||||
#include "../ifc/exception/vexceptionwrongid.h"
|
#include "../ifc/exception/vexceptionwrongid.h"
|
||||||
#include "../vmisc/vsysexits.h"
|
#include "../vmisc/vsysexits.h"
|
||||||
|
|
||||||
|
#if QT_VERSION < QT_VERSION_CHECK(5, 5, 0)
|
||||||
#include "../vmisc/diagnostic.h"
|
#include "../vmisc/diagnostic.h"
|
||||||
|
#endif // QT_VERSION < QT_VERSION_CHECK(5, 5, 0)
|
||||||
|
|
||||||
#include "../vmisc/qt_dispatch/qt_dispatch.h"
|
#include "../vmisc/qt_dispatch/qt_dispatch.h"
|
||||||
#include "../fervor/fvupdater.h"
|
#include "../fervor/fvupdater.h"
|
||||||
|
|
||||||
|
@ -46,7 +50,7 @@ QT_WARNING_PUSH
|
||||||
QT_WARNING_DISABLE_CLANG("-Wmissing-prototypes")
|
QT_WARNING_DISABLE_CLANG("-Wmissing-prototypes")
|
||||||
QT_WARNING_DISABLE_INTEL(1418)
|
QT_WARNING_DISABLE_INTEL(1418)
|
||||||
|
|
||||||
Q_LOGGING_CATEGORY(pApp, "p.application")
|
Q_LOGGING_CATEGORY(pApp, "p.application") // NOLINT
|
||||||
|
|
||||||
QT_WARNING_POP
|
QT_WARNING_POP
|
||||||
|
|
||||||
|
@ -246,10 +250,10 @@ inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &con
|
||||||
VPApplication::VPApplication(int &argc, char **argv)
|
VPApplication::VPApplication(int &argc, char **argv)
|
||||||
:VAbstractApplication(argc, argv)
|
:VAbstractApplication(argc, argv)
|
||||||
{
|
{
|
||||||
setApplicationDisplayName(VER_PRODUCTNAME_STR);
|
setApplicationDisplayName(QStringLiteral(VER_PRODUCTNAME_STR));
|
||||||
setApplicationName(VER_INTERNALNAME_STR);
|
setApplicationName(QStringLiteral(VER_INTERNALNAME_STR));
|
||||||
setOrganizationName(VER_COMPANYNAME_STR);
|
setOrganizationName(QStringLiteral(VER_COMPANYNAME_STR));
|
||||||
setOrganizationDomain(VER_COMPANYDOMAIN_STR);
|
setOrganizationDomain(QStringLiteral(VER_COMPANYDOMAIN_STR));
|
||||||
// Setting the Application version
|
// Setting the Application version
|
||||||
setApplicationVersion(APP_VERSION_STR);
|
setApplicationVersion(APP_VERSION_STR);
|
||||||
// We have been running Puzzle in two different cases.
|
// We have been running Puzzle in two different cases.
|
||||||
|
@ -261,7 +265,7 @@ VPApplication::VPApplication(int &argc, char **argv)
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
VPApplication::~VPApplication()
|
VPApplication::~VPApplication()
|
||||||
{
|
{
|
||||||
qDeleteAll(mainWindows);
|
qDeleteAll(m_mainWindows);
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -342,11 +346,11 @@ auto VPApplication::IsAppInGUIMode() const -> bool
|
||||||
auto VPApplication::MainWindow()-> VPMainWindow *
|
auto VPApplication::MainWindow()-> VPMainWindow *
|
||||||
{
|
{
|
||||||
Clean();
|
Clean();
|
||||||
if (mainWindows.isEmpty())
|
if (m_mainWindows.isEmpty())
|
||||||
{
|
{
|
||||||
NewMainWindow();
|
NewMainWindow();
|
||||||
}
|
}
|
||||||
return mainWindows[0];
|
return m_mainWindows[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -354,7 +358,8 @@ auto VPApplication::MainWindows() -> QList<VPMainWindow *>
|
||||||
{
|
{
|
||||||
Clean();
|
Clean();
|
||||||
QList<VPMainWindow*> list;
|
QList<VPMainWindow*> list;
|
||||||
for (auto &w : mainWindows)
|
list.reserve(m_mainWindows.size());
|
||||||
|
for (auto &w : m_mainWindows)
|
||||||
{
|
{
|
||||||
list.append(w);
|
list.append(w);
|
||||||
}
|
}
|
||||||
|
@ -373,7 +378,7 @@ auto VPApplication::NewMainWindow() -> VPMainWindow *
|
||||||
auto VPApplication::NewMainWindow(const VPCommandLinePtr &cmd) -> VPMainWindow *
|
auto VPApplication::NewMainWindow(const VPCommandLinePtr &cmd) -> VPMainWindow *
|
||||||
{
|
{
|
||||||
auto *puzzle = new VPMainWindow(cmd);
|
auto *puzzle = new VPMainWindow(cmd);
|
||||||
mainWindows.prepend(puzzle);
|
m_mainWindows.prepend(puzzle);
|
||||||
if (not cmd->IsTestModeEnabled())
|
if (not cmd->IsTestModeEnabled())
|
||||||
{
|
{
|
||||||
puzzle->show();
|
puzzle->show();
|
||||||
|
@ -394,7 +399,7 @@ void VPApplication::InitOptions()
|
||||||
qCDebug(pApp, "Build revision: %s", BUILD_REVISION);
|
qCDebug(pApp, "Build revision: %s", BUILD_REVISION);
|
||||||
qCDebug(pApp, "%s", qUtf8Printable(buildCompatibilityString()));
|
qCDebug(pApp, "%s", qUtf8Printable(buildCompatibilityString()));
|
||||||
qCDebug(pApp, "Built on %s at %s", __DATE__, __TIME__);
|
qCDebug(pApp, "Built on %s at %s", __DATE__, __TIME__);
|
||||||
qCDebug(pApp, "Command-line arguments: %s", qUtf8Printable(arguments().join(", ")));
|
qCDebug(pApp, "Command-line arguments: %s", qUtf8Printable(arguments().join(QStringLiteral(", "))));
|
||||||
qCDebug(pApp, "Process ID: %s", qUtf8Printable(QString().setNum(applicationPid())));
|
qCDebug(pApp, "Process ID: %s", qUtf8Printable(QString().setNum(applicationPid())));
|
||||||
|
|
||||||
CheckSystemLocale();
|
CheckSystemLocale();
|
||||||
|
@ -406,13 +411,13 @@ void VPApplication::InitOptions()
|
||||||
VPCommandLine::Instance();
|
VPCommandLine::Instance();
|
||||||
|
|
||||||
static const char * GENERIC_ICON_TO_CHECK = "document-open";
|
static const char * GENERIC_ICON_TO_CHECK = "document-open";
|
||||||
if (QIcon::hasThemeIcon(GENERIC_ICON_TO_CHECK) == false)
|
if (not QIcon::hasThemeIcon(GENERIC_ICON_TO_CHECK))
|
||||||
{
|
{
|
||||||
//If there is no default working icon theme then we should
|
//If there is no default working icon theme then we should
|
||||||
//use an icon theme that we provide via a .qrc file
|
//use an icon theme that we provide via a .qrc file
|
||||||
//This case happens under Windows and Mac OS X
|
//This case happens under Windows and Mac OS X
|
||||||
//This does not happen under GNOME or KDE
|
//This does not happen under GNOME or KDE
|
||||||
QIcon::setThemeName("win.icon.theme");
|
QIcon::setThemeName(QStringLiteral("win.icon.theme"));
|
||||||
}
|
}
|
||||||
ActivateDarkMode();
|
ActivateDarkMode();
|
||||||
}
|
}
|
||||||
|
@ -440,10 +445,10 @@ auto VPApplication::PuzzleSettings() -> VPSettings *
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void VPApplication::ActivateDarkMode()
|
void VPApplication::ActivateDarkMode()
|
||||||
{
|
{
|
||||||
VPSettings *settings = VPApplication::VApp()->PuzzleSettings();
|
VPSettings *settings = PuzzleSettings();
|
||||||
if (settings->GetDarkMode())
|
if (settings->GetDarkMode())
|
||||||
{
|
{
|
||||||
QFile f(":qdarkstyle/style.qss");
|
QFile f(QStringLiteral(":qdarkstyle/style.qss"));
|
||||||
if (!f.exists())
|
if (!f.exists())
|
||||||
{
|
{
|
||||||
qDebug()<<"Unable to set stylesheet, file not found\n";
|
qDebug()<<"Unable to set stylesheet, file not found\n";
|
||||||
|
@ -472,7 +477,7 @@ void VPApplication::ParseCommandLine(const SocketConnection &connection, const Q
|
||||||
{
|
{
|
||||||
qCDebug(pApp, "Connected to the server '%s'", qUtf8Printable(serverName));
|
qCDebug(pApp, "Connected to the server '%s'", qUtf8Printable(serverName));
|
||||||
QTextStream stream(&socket);
|
QTextStream stream(&socket);
|
||||||
stream << arguments.join(";;");
|
stream << arguments.join(QStringLiteral(";;"));
|
||||||
stream.flush();
|
stream.flush();
|
||||||
socket.waitForBytesWritten();
|
socket.waitForBytesWritten();
|
||||||
QCoreApplication::exit(V_EX_OK);
|
QCoreApplication::exit(V_EX_OK);
|
||||||
|
@ -480,24 +485,7 @@ void VPApplication::ParseCommandLine(const SocketConnection &connection, const Q
|
||||||
}
|
}
|
||||||
|
|
||||||
qCDebug(pApp, "Can't establish connection to the server '%s'", qUtf8Printable(serverName));
|
qCDebug(pApp, "Can't establish connection to the server '%s'", qUtf8Printable(serverName));
|
||||||
|
StartLocalServer(serverName);
|
||||||
localServer = new QLocalServer(this);
|
|
||||||
connect(localServer, &QLocalServer::newConnection, this, &VPApplication::NewLocalSocketConnection);
|
|
||||||
if (not localServer->listen(serverName))
|
|
||||||
{
|
|
||||||
qCDebug(pApp, "Can't begin to listen for incoming connections on name '%s'",
|
|
||||||
qUtf8Printable(serverName));
|
|
||||||
if (localServer->serverError() == QAbstractSocket::AddressInUseError)
|
|
||||||
{
|
|
||||||
QLocalServer::removeServer(serverName);
|
|
||||||
if (not localServer->listen(serverName))
|
|
||||||
{
|
|
||||||
qCWarning(pApp, "%s",
|
|
||||||
qUtf8Printable(tr("Can't begin to listen for incoming connections on name '%1'").arg(serverName)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
LoadTranslation(PuzzleSettings()->GetLocale());
|
LoadTranslation(PuzzleSettings()->GetLocale());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -509,54 +497,7 @@ void VPApplication::ProcessArguments(const VPCommandLinePtr &cmd)
|
||||||
{
|
{
|
||||||
const QStringList rawLayouts = cmd->OptionRawLayouts();
|
const QStringList rawLayouts = cmd->OptionRawLayouts();
|
||||||
const QStringList args = cmd->OptionFileNames();
|
const QStringList args = cmd->OptionFileNames();
|
||||||
if (args.count() > 0)
|
args.count() > 0 ? StartWithFiles(cmd, rawLayouts) : SingleStart(cmd, rawLayouts);
|
||||||
{
|
|
||||||
if (not cmd->IsGuiEnabled() && args.count() > 1)
|
|
||||||
{
|
|
||||||
qCCritical(pApp, "%s\n", qPrintable(tr("Export mode doesn't support opening several files.")));
|
|
||||||
cmd.get()->parser.showHelp(V_EX_USAGE);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args.count() > 1 && not rawLayouts.isEmpty())
|
|
||||||
{
|
|
||||||
qCCritical(pApp, "%s\n",
|
|
||||||
qPrintable(tr("Import raw layout data does not support opening several layout files.")));
|
|
||||||
cmd.get()->parser.showHelp(V_EX_USAGE);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const auto &arg : args)
|
|
||||||
{
|
|
||||||
NewMainWindow(cmd);
|
|
||||||
if (not MainWindow()->LoadFile(arg))
|
|
||||||
{
|
|
||||||
if (not cmd->IsGuiEnabled())
|
|
||||||
{
|
|
||||||
return; // process only one input file
|
|
||||||
}
|
|
||||||
delete MainWindow();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (not rawLayouts.isEmpty())
|
|
||||||
{
|
|
||||||
MainWindow()->ImportRawLayouts(rawLayouts);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (cmd->IsTestModeEnabled())
|
|
||||||
{
|
|
||||||
qCCritical(pApp, "%s\n", qPrintable(tr("Please, provide one input file.")));
|
|
||||||
cmd.get()->parser.showHelp(V_EX_USAGE);
|
|
||||||
}
|
|
||||||
|
|
||||||
NewMainWindow(cmd);
|
|
||||||
if (not rawLayouts.isEmpty())
|
|
||||||
{
|
|
||||||
MainWindow()->ImportRawLayouts(rawLayouts);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (not cmd->IsGuiEnabled())
|
if (not cmd->IsGuiEnabled())
|
||||||
{
|
{
|
||||||
|
@ -637,7 +578,7 @@ void VPApplication::AboutToQuit()
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void VPApplication::NewLocalSocketConnection()
|
void VPApplication::NewLocalSocketConnection()
|
||||||
{
|
{
|
||||||
QScopedPointer<QLocalSocket>socket(localServer->nextPendingConnection());
|
QScopedPointer<QLocalSocket>socket(m_localServer->nextPendingConnection());
|
||||||
if (socket.isNull())
|
if (socket.isNull())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
@ -647,7 +588,7 @@ void VPApplication::NewLocalSocketConnection()
|
||||||
const QString arg = stream.readAll();
|
const QString arg = stream.readAll();
|
||||||
if (not arg.isEmpty())
|
if (not arg.isEmpty())
|
||||||
{
|
{
|
||||||
ParseCommandLine(SocketConnection::Server, arg.split(";;"));
|
ParseCommandLine(SocketConnection::Server, arg.split(QStringLiteral(";;")));
|
||||||
}
|
}
|
||||||
MainWindow()->raise();
|
MainWindow()->raise();
|
||||||
MainWindow()->activateWindow();
|
MainWindow()->activateWindow();
|
||||||
|
@ -669,15 +610,93 @@ void VPApplication::SetPreferencesDialog(const QSharedPointer<DialogPuzzlePrefer
|
||||||
void VPApplication::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 = m_mainWindows.count() - 1; i >= 0; --i)
|
||||||
{
|
{
|
||||||
if (mainWindows.at(i).isNull())
|
if (m_mainWindows.at(i).isNull())
|
||||||
{
|
{
|
||||||
mainWindows.removeAt(i);
|
m_mainWindows.removeAt(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VPApplication::StartLocalServer(const QString &serverName)
|
||||||
|
{
|
||||||
|
m_localServer = new QLocalServer(this);
|
||||||
|
connect(m_localServer, &QLocalServer::newConnection, this, &VPApplication::NewLocalSocketConnection);
|
||||||
|
if (not m_localServer->listen(serverName))
|
||||||
|
{
|
||||||
|
qCDebug(pApp, "Can't begin to listen for incoming connections on name '%s'",
|
||||||
|
qUtf8Printable(serverName));
|
||||||
|
if (m_localServer->serverError() == QAbstractSocket::AddressInUseError)
|
||||||
|
{
|
||||||
|
QLocalServer::removeServer(serverName);
|
||||||
|
if (not m_localServer->listen(serverName))
|
||||||
|
{
|
||||||
|
qCWarning(pApp, "%s",
|
||||||
|
qUtf8Printable(tr("Can't begin to listen for incoming connections on name '%1'")
|
||||||
|
.arg(serverName)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VPApplication::StartWithFiles(const VPCommandLinePtr &cmd, const QStringList &rawLayouts)
|
||||||
|
{
|
||||||
|
const QStringList args = cmd->OptionFileNames();
|
||||||
|
if (args.count() > 0)
|
||||||
|
{
|
||||||
|
if (not cmd->IsGuiEnabled() && args.count() > 1)
|
||||||
|
{
|
||||||
|
qCCritical(pApp, "%s\n", qPrintable(tr("Export mode doesn't support opening several files.")));
|
||||||
|
cmd.get()->parser.showHelp(V_EX_USAGE);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.count() > 1 && not rawLayouts.isEmpty())
|
||||||
|
{
|
||||||
|
qCCritical(pApp, "%s\n",
|
||||||
|
qPrintable(tr("Import raw layout data does not support opening several layout files.")));
|
||||||
|
cmd.get()->parser.showHelp(V_EX_USAGE);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const auto &arg : args)
|
||||||
|
{
|
||||||
|
NewMainWindow(cmd);
|
||||||
|
if (not MainWindow()->LoadFile(arg))
|
||||||
|
{
|
||||||
|
if (not cmd->IsGuiEnabled())
|
||||||
|
{
|
||||||
|
return; // process only one input file
|
||||||
|
}
|
||||||
|
delete MainWindow();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (not rawLayouts.isEmpty())
|
||||||
|
{
|
||||||
|
MainWindow()->ImportRawLayouts(rawLayouts);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VPApplication::SingleStart(const VPCommandLinePtr &cmd, const QStringList &rawLayouts)
|
||||||
|
{
|
||||||
|
if (cmd->IsTestModeEnabled())
|
||||||
|
{
|
||||||
|
qCCritical(pApp, "%s\n", qPrintable(tr("Please, provide one input file.")));
|
||||||
|
cmd.get()->parser.showHelp(V_EX_USAGE);
|
||||||
|
}
|
||||||
|
|
||||||
|
NewMainWindow(cmd);
|
||||||
|
if (not rawLayouts.isEmpty())
|
||||||
|
{
|
||||||
|
MainWindow()->ImportRawLayouts(rawLayouts);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
auto VPApplication::CommandLine() -> VPCommandLinePtr
|
auto VPApplication::CommandLine() -> VPCommandLinePtr
|
||||||
{
|
{
|
||||||
|
@ -685,7 +704,7 @@ auto VPApplication::CommandLine() -> VPCommandLinePtr
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
VPApplication *VPApplication::VApp()
|
auto VPApplication::VApp() -> VPApplication *
|
||||||
{
|
{
|
||||||
return qobject_cast<VPApplication*>(QCoreApplication::instance());
|
return qobject_cast<VPApplication*>(QCoreApplication::instance());
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,32 +42,32 @@ enum class SocketConnection : bool {Client = false, Server = true};
|
||||||
|
|
||||||
class VPApplication : public VAbstractApplication
|
class VPApplication : public VAbstractApplication
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT // NOLINT
|
||||||
public:
|
public:
|
||||||
VPApplication(int &argc, char **argv);
|
VPApplication(int &argc, char **argv);
|
||||||
virtual ~VPApplication() override;
|
~VPApplication() override;
|
||||||
|
|
||||||
virtual bool notify(QObject * receiver, QEvent * event) override;
|
auto notify(QObject * receiver, QEvent * event) -> bool override;
|
||||||
|
|
||||||
virtual bool IsAppInGUIMode() const override;
|
auto IsAppInGUIMode() const -> bool override;
|
||||||
VPMainWindow *MainWindow();
|
auto MainWindow() -> VPMainWindow *;
|
||||||
QList<VPMainWindow*> MainWindows();
|
auto MainWindows() -> QList<VPMainWindow*>;
|
||||||
VPMainWindow *NewMainWindow();
|
auto NewMainWindow() -> VPMainWindow *;
|
||||||
VPMainWindow *NewMainWindow(const VPCommandLinePtr &cmd);
|
auto NewMainWindow(const VPCommandLinePtr &cmd) -> VPMainWindow *;
|
||||||
|
|
||||||
void InitOptions();
|
void InitOptions();
|
||||||
|
|
||||||
virtual const VTranslateVars *TrVars() override;
|
auto TrVars() -> const VTranslateVars * override;
|
||||||
|
|
||||||
virtual void OpenSettings() override;
|
void OpenSettings() override;
|
||||||
VPSettings *PuzzleSettings();
|
auto PuzzleSettings() -> VPSettings *;
|
||||||
void ActivateDarkMode();
|
void ActivateDarkMode();
|
||||||
|
|
||||||
void ParseCommandLine(const SocketConnection &connection, const QStringList &arguments);
|
void ParseCommandLine(const SocketConnection &connection, const QStringList &arguments);
|
||||||
void ProcessArguments(const VPCommandLinePtr &cmd);
|
void ProcessArguments(const VPCommandLinePtr &cmd);
|
||||||
|
|
||||||
static VPCommandLinePtr CommandLine();
|
static auto CommandLine() -> VPCommandLinePtr;
|
||||||
static VPApplication *VApp();
|
static auto VApp() -> VPApplication *;
|
||||||
|
|
||||||
auto PreferencesDialog() const -> QSharedPointer<DialogPuzzlePreferences>;
|
auto PreferencesDialog() const -> QSharedPointer<DialogPuzzlePreferences>;
|
||||||
void SetPreferencesDialog(const QSharedPointer<DialogPuzzlePreferences> &newPreferencesDialog);
|
void SetPreferencesDialog(const QSharedPointer<DialogPuzzlePreferences> &newPreferencesDialog);
|
||||||
|
@ -76,22 +76,27 @@ public slots:
|
||||||
void ProcessCMD();
|
void ProcessCMD();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void InitTrVars() override;
|
void InitTrVars() override;
|
||||||
virtual bool event(QEvent *e) override;
|
auto event(QEvent *e) -> bool override;
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
virtual void AboutToQuit() override;
|
void AboutToQuit() override;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void NewLocalSocketConnection();
|
void NewLocalSocketConnection();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(VPApplication)
|
Q_DISABLE_COPY_MOVE(VPApplication) //NOLINT
|
||||||
QList<QPointer<VPMainWindow> > mainWindows{};
|
QList<QPointer<VPMainWindow> > m_mainWindows{};
|
||||||
QLocalServer *localServer{nullptr};
|
QLocalServer *m_localServer{nullptr};
|
||||||
QWeakPointer<DialogPuzzlePreferences> m_preferencesDialog{};
|
QWeakPointer<DialogPuzzlePreferences> m_preferencesDialog{};
|
||||||
|
|
||||||
void Clean();
|
void Clean();
|
||||||
|
|
||||||
|
void StartLocalServer(const QString &serverName);
|
||||||
|
|
||||||
|
void StartWithFiles(const VPCommandLinePtr &cmd, const QStringList &rawLayouts);
|
||||||
|
void SingleStart(const VPCommandLinePtr &cmd, const QStringList &rawLayouts);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // VPAPPLICATION_H
|
#endif // VPAPPLICATION_H
|
||||||
|
|
|
@ -35,10 +35,13 @@
|
||||||
#include "../ifc/exception/vexceptionemptyparameter.h"
|
#include "../ifc/exception/vexceptionemptyparameter.h"
|
||||||
#include "../ifc/exception/vexceptionwrongid.h"
|
#include "../ifc/exception/vexceptionwrongid.h"
|
||||||
#include "../vmisc/vsysexits.h"
|
#include "../vmisc/vsysexits.h"
|
||||||
|
|
||||||
|
#if QT_VERSION < QT_VERSION_CHECK(5, 5, 0)
|
||||||
#include "../vmisc/diagnostic.h"
|
#include "../vmisc/diagnostic.h"
|
||||||
|
#endif // QT_VERSION < QT_VERSION_CHECK(5, 5, 0)
|
||||||
|
|
||||||
#include "../vmisc/qt_dispatch/qt_dispatch.h"
|
#include "../vmisc/qt_dispatch/qt_dispatch.h"
|
||||||
#include "../qmuparser/qmuparsererror.h"
|
#include "../qmuparser/qmuparsererror.h"
|
||||||
#include "../vpatterndb/variables/vmeasurement.h"
|
|
||||||
#include "../fervor/fvupdater.h"
|
#include "../fervor/fvupdater.h"
|
||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
@ -53,6 +56,7 @@
|
||||||
#include <QGridLayout>
|
#include <QGridLayout>
|
||||||
#include <QSpacerItem>
|
#include <QSpacerItem>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
|
#include <QGlobalStatic>
|
||||||
|
|
||||||
#if defined(APPIMAGE) && defined(Q_OS_LINUX)
|
#if defined(APPIMAGE) && defined(Q_OS_LINUX)
|
||||||
# include "../vmisc/appimage.h"
|
# include "../vmisc/appimage.h"
|
||||||
|
@ -62,12 +66,29 @@ QT_WARNING_PUSH
|
||||||
QT_WARNING_DISABLE_CLANG("-Wmissing-prototypes")
|
QT_WARNING_DISABLE_CLANG("-Wmissing-prototypes")
|
||||||
QT_WARNING_DISABLE_INTEL(1418)
|
QT_WARNING_DISABLE_INTEL(1418)
|
||||||
|
|
||||||
Q_LOGGING_CATEGORY(mApp, "m.application")
|
Q_LOGGING_CATEGORY(mApp, "m.application") // NOLINT
|
||||||
|
|
||||||
QT_WARNING_POP
|
QT_WARNING_POP
|
||||||
|
|
||||||
#include <QCommandLineParser>
|
#include <QCommandLineParser>
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, LONG_OPTION_DIMENSION_A, (QLatin1String("dimensionA"))) // NOLINT
|
||||||
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, SINGLE_OPTION_DIMENSION_A, (QChar('a'))) // NOLINT
|
||||||
|
|
||||||
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, LONG_OPTION_DIMENSION_B, (QLatin1String("dimensionB"))) // NOLINT
|
||||||
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, SINGLE_OPTION_DIMENSION_B, (QChar('b'))) // NOLINT
|
||||||
|
|
||||||
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, LONG_OPTION_DIMENSION_C, (QLatin1String("dimensionC"))) // NOLINT
|
||||||
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, SINGLE_OPTION_DIMENSION_C, (QChar('c'))) // NOLINT
|
||||||
|
|
||||||
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, LONG_OPTION_UNITS, (QLatin1String("units"))) // NOLINT
|
||||||
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, SINGLE_OPTION_UNITS, (QChar('u'))) // NOLINT
|
||||||
|
|
||||||
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, LONG_OPTION_TEST, (QLatin1String("test"))) // NOLINT
|
||||||
|
} // namespace
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
|
inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
|
||||||
{
|
{
|
||||||
|
@ -263,17 +284,12 @@ inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &con
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
MApplication::MApplication(int &argc, char **argv)
|
MApplication::MApplication(int &argc, char **argv)
|
||||||
:VAbstractApplication(argc, argv),
|
:VAbstractApplication(argc, argv)
|
||||||
mainWindows(),
|
|
||||||
localServer(nullptr),
|
|
||||||
trVars(nullptr),
|
|
||||||
dataBase(QPointer<DialogMDataBase>()),
|
|
||||||
testMode(false)
|
|
||||||
{
|
{
|
||||||
setApplicationDisplayName(VER_PRODUCTNAME_STR);
|
setApplicationDisplayName(QStringLiteral(VER_PRODUCTNAME_STR));
|
||||||
setApplicationName(VER_INTERNALNAME_STR);
|
setApplicationName(QStringLiteral(VER_INTERNALNAME_STR));
|
||||||
setOrganizationName(VER_COMPANYNAME_STR);
|
setOrganizationName(QStringLiteral(VER_COMPANYNAME_STR));
|
||||||
setOrganizationDomain(VER_COMPANYDOMAIN_STR);
|
setOrganizationDomain(QStringLiteral(VER_COMPANYDOMAIN_STR));
|
||||||
// Setting the Application version
|
// Setting the Application version
|
||||||
setApplicationVersion(APP_VERSION_STR);
|
setApplicationVersion(APP_VERSION_STR);
|
||||||
// We have been running Tape in two different cases.
|
// We have been running Tape in two different cases.
|
||||||
|
@ -285,12 +301,12 @@ MApplication::MApplication(int &argc, char **argv)
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
MApplication::~MApplication()
|
MApplication::~MApplication()
|
||||||
{
|
{
|
||||||
qDeleteAll(mainWindows);
|
qDeleteAll(m_mainWindows);
|
||||||
|
|
||||||
delete trVars;
|
delete m_trVars;
|
||||||
if (not dataBase.isNull())
|
if (not m_dataBase.isNull())
|
||||||
{
|
{
|
||||||
delete dataBase;
|
delete m_dataBase;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -302,7 +318,7 @@ MApplication::~MApplication()
|
||||||
* @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 MApplication::notify(QObject *receiver, QEvent *event)
|
auto MApplication::notify(QObject *receiver, QEvent *event) -> bool
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -372,37 +388,38 @@ bool MApplication::notify(QObject *receiver, QEvent *event)
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
bool MApplication::IsTestMode() const
|
auto MApplication::IsTestMode() const -> bool
|
||||||
{
|
{
|
||||||
return testMode;
|
return m_testMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
/**
|
/**
|
||||||
* @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 MApplication::IsAppInGUIMode() const
|
auto MApplication::IsAppInGUIMode() const -> bool
|
||||||
{
|
{
|
||||||
return not IsTestMode();
|
return not IsTestMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
TMainWindow *MApplication::MainWindow()
|
auto MApplication::MainWindow() -> TMainWindow *
|
||||||
{
|
{
|
||||||
Clean();
|
Clean();
|
||||||
if (mainWindows.isEmpty())
|
if (m_mainWindows.isEmpty())
|
||||||
{
|
{
|
||||||
NewMainWindow();
|
NewMainWindow();
|
||||||
}
|
}
|
||||||
return mainWindows[0];
|
return m_mainWindows[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
QList<TMainWindow *> MApplication::MainWindows()
|
auto MApplication::MainWindows() -> QList<TMainWindow *>
|
||||||
{
|
{
|
||||||
Clean();
|
Clean();
|
||||||
QList<TMainWindow*> list;
|
QList<TMainWindow*> list;
|
||||||
for (auto &w : mainWindows)
|
list.reserve(m_mainWindows.size());
|
||||||
|
for (auto &w : m_mainWindows)
|
||||||
{
|
{
|
||||||
list.append(w);
|
list.append(w);
|
||||||
}
|
}
|
||||||
|
@ -420,7 +437,7 @@ void MApplication::InitOptions()
|
||||||
qCDebug(mApp, "Build revision: %s", BUILD_REVISION);
|
qCDebug(mApp, "Build revision: %s", BUILD_REVISION);
|
||||||
qCDebug(mApp, "%s", qUtf8Printable(buildCompatibilityString()));
|
qCDebug(mApp, "%s", qUtf8Printable(buildCompatibilityString()));
|
||||||
qCDebug(mApp, "Built on %s at %s", __DATE__, __TIME__);
|
qCDebug(mApp, "Built on %s at %s", __DATE__, __TIME__);
|
||||||
qCDebug(mApp, "Command-line arguments: %s", qUtf8Printable(arguments().join(", ")));
|
qCDebug(mApp, "Command-line arguments: %s", qUtf8Printable(arguments().join(QStringLiteral(", "))));
|
||||||
qCDebug(mApp, "Process ID: %s", qUtf8Printable(QString().setNum(applicationPid())));
|
qCDebug(mApp, "Process ID: %s", qUtf8Printable(QString().setNum(applicationPid())));
|
||||||
|
|
||||||
CheckSystemLocale();
|
CheckSystemLocale();
|
||||||
|
@ -428,13 +445,13 @@ void MApplication::InitOptions()
|
||||||
LoadTranslation(QString());// By default the console version uses system locale
|
LoadTranslation(QString());// By default the console version uses system locale
|
||||||
|
|
||||||
static const char * GENERIC_ICON_TO_CHECK = "document-open";
|
static const char * GENERIC_ICON_TO_CHECK = "document-open";
|
||||||
if (QIcon::hasThemeIcon(GENERIC_ICON_TO_CHECK) == false)
|
if (not QIcon::hasThemeIcon(GENERIC_ICON_TO_CHECK))
|
||||||
{
|
{
|
||||||
//If there is no default working icon theme then we should
|
//If there is no default working icon theme then we should
|
||||||
//use an icon theme that we provide via a .qrc file
|
//use an icon theme that we provide via a .qrc file
|
||||||
//This case happens under Windows and Mac OS X
|
//This case happens under Windows and Mac OS X
|
||||||
//This does not happen under GNOME or KDE
|
//This does not happen under GNOME or KDE
|
||||||
QIcon::setThemeName("win.icon.theme");
|
QIcon::setThemeName(QStringLiteral("win.icon.theme"));
|
||||||
}
|
}
|
||||||
ActivateDarkMode();
|
ActivateDarkMode();
|
||||||
QResource::registerResource(diagramsPath());
|
QResource::registerResource(diagramsPath());
|
||||||
|
@ -444,10 +461,10 @@ void MApplication::InitOptions()
|
||||||
// Dark mode
|
// Dark mode
|
||||||
void MApplication::ActivateDarkMode()
|
void MApplication::ActivateDarkMode()
|
||||||
{
|
{
|
||||||
VTapeSettings *settings = MApplication::VApp()->TapeSettings();
|
VTapeSettings *settings = TapeSettings();
|
||||||
if (settings->GetDarkMode())
|
if (settings->GetDarkMode())
|
||||||
{
|
{
|
||||||
QFile f(":qdarkstyle/style.qss");
|
QFile f(QStringLiteral(":qdarkstyle/style.qss"));
|
||||||
if (!f.exists())
|
if (!f.exists())
|
||||||
{
|
{
|
||||||
qDebug()<<"Unable to set stylesheet, file not found\n";
|
qDebug()<<"Unable to set stylesheet, file not found\n";
|
||||||
|
@ -465,18 +482,18 @@ void MApplication::ActivateDarkMode()
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void MApplication::InitTrVars()
|
void MApplication::InitTrVars()
|
||||||
{
|
{
|
||||||
if (trVars != nullptr)
|
if (m_trVars != nullptr)
|
||||||
{
|
{
|
||||||
trVars->Retranslate();
|
m_trVars->Retranslate();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
trVars = new VTranslateVars();
|
m_trVars = new VTranslateVars();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
bool MApplication::event(QEvent *e)
|
auto MApplication::event(QEvent *e) -> bool
|
||||||
{
|
{
|
||||||
switch(e->type())
|
switch(e->type())
|
||||||
{
|
{
|
||||||
|
@ -484,7 +501,7 @@ bool MApplication::event(QEvent *e)
|
||||||
// Mac specific).
|
// Mac specific).
|
||||||
case QEvent::FileOpen:
|
case QEvent::FileOpen:
|
||||||
{
|
{
|
||||||
QFileOpenEvent *fileOpenEvent = static_cast<QFileOpenEvent *>(e);
|
auto *fileOpenEvent = static_cast<QFileOpenEvent *>(e);
|
||||||
const QString macFileOpen = fileOpenEvent->file();
|
const QString macFileOpen = fileOpenEvent->file();
|
||||||
if(not macFileOpen.isEmpty())
|
if(not macFileOpen.isEmpty())
|
||||||
{
|
{
|
||||||
|
@ -532,14 +549,14 @@ void MApplication::OpenSettings()
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
VTapeSettings *MApplication::TapeSettings()
|
auto MApplication::TapeSettings() -> VTapeSettings *
|
||||||
{
|
{
|
||||||
SCASSERT(settings != nullptr)
|
SCASSERT(settings != nullptr)
|
||||||
return qobject_cast<VTapeSettings *>(settings);
|
return qobject_cast<VTapeSettings *>(settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
QString MApplication::diagramsPath() const
|
auto MApplication::diagramsPath() -> QString
|
||||||
{
|
{
|
||||||
const QString dPath = QStringLiteral("/diagrams.rcc");
|
const QString dPath = QStringLiteral("/diagrams.rcc");
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
|
@ -568,40 +585,38 @@ QString MApplication::diagramsPath() const
|
||||||
{
|
{
|
||||||
return file.absoluteFilePath();
|
return file.absoluteFilePath();
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
#if defined(APPIMAGE) && defined(Q_OS_LINUX)
|
#if defined(APPIMAGE) && defined(Q_OS_LINUX)
|
||||||
/* Fix path to diagrams when run inside AppImage. */
|
/* Fix path to diagrams when run inside AppImage. */
|
||||||
return AppImageRoot() + PKGDATADIR + dPath;
|
return AppImageRoot() + PKGDATADIR + dPath;
|
||||||
#else
|
#else
|
||||||
return PKGDATADIR + dPath;
|
return PKGDATADIR + dPath;
|
||||||
#endif // defined(APPIMAGE) && defined(Q_OS_LINUX)
|
#endif // defined(APPIMAGE) && defined(Q_OS_LINUX)
|
||||||
}
|
#endif // Unix
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void MApplication::ShowDataBase()
|
void MApplication::ShowDataBase()
|
||||||
{
|
{
|
||||||
if (dataBase.isNull())
|
if (m_dataBase.isNull())
|
||||||
{
|
{
|
||||||
dataBase = new DialogMDataBase();
|
m_dataBase = new DialogMDataBase();
|
||||||
dataBase->setAttribute(Qt::WA_DeleteOnClose, true);
|
m_dataBase->setAttribute(Qt::WA_DeleteOnClose, true);
|
||||||
dataBase->setModal(false);
|
m_dataBase->setModal(false);
|
||||||
dataBase->show();
|
m_dataBase->show();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dataBase->activateWindow();
|
m_dataBase->activateWindow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void MApplication::RetranslateGroups()
|
void MApplication::RetranslateGroups()
|
||||||
{
|
{
|
||||||
if (not dataBase.isNull())
|
if (not m_dataBase.isNull())
|
||||||
{
|
{
|
||||||
dataBase->RetranslateGroups();
|
m_dataBase->RetranslateGroups();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -609,7 +624,7 @@ void MApplication::RetranslateGroups()
|
||||||
void MApplication::RetranslateTables()
|
void MApplication::RetranslateTables()
|
||||||
{
|
{
|
||||||
const QList<TMainWindow*> list = MainWindows();
|
const QList<TMainWindow*> list = MainWindows();
|
||||||
for (auto w : list)
|
for (auto *w : list)
|
||||||
{
|
{
|
||||||
w->RetranslateTable();
|
w->RetranslateTable();
|
||||||
}
|
}
|
||||||
|
@ -622,49 +637,14 @@ void MApplication::ParseCommandLine(const SocketConnection &connection, const QS
|
||||||
parser.setApplicationDescription(tr("Valentina's measurements editor."));
|
parser.setApplicationDescription(tr("Valentina's measurements editor."));
|
||||||
parser.addHelpOption();
|
parser.addHelpOption();
|
||||||
parser.addVersionOption();
|
parser.addVersionOption();
|
||||||
parser.addPositionalArgument("filename", tr("The measurement file."));
|
|
||||||
|
|
||||||
const QString LONG_OPTION_DIMENSION_A = QStringLiteral("dimensionA");
|
InitParserOptions(parser);
|
||||||
const QString SINGLE_OPTION_DIMENSION_A = QChar('a');
|
|
||||||
|
|
||||||
const QString LONG_OPTION_DIMENSION_B = QStringLiteral("dimensionB");
|
|
||||||
const QString SINGLE_OPTION_DIMENSION_B = QChar('b');
|
|
||||||
|
|
||||||
const QString LONG_OPTION_DIMENSION_C = QStringLiteral("dimensionC");
|
|
||||||
const QString SINGLE_OPTION_DIMENSION_C = QChar('c');
|
|
||||||
|
|
||||||
const QString LONG_OPTION_UNITS = QStringLiteral("units");
|
|
||||||
const QString SINGLE_OPTION_UNITS = QChar('u');
|
|
||||||
|
|
||||||
const QString LONG_OPTION_TEST = QStringLiteral("test");
|
|
||||||
|
|
||||||
parser.addOptions(
|
|
||||||
{
|
|
||||||
{{SINGLE_OPTION_DIMENSION_A, LONG_OPTION_DIMENSION_A}, tr("Set base for dimension A in the table units."),
|
|
||||||
tr("The dimension A base")},
|
|
||||||
|
|
||||||
{{SINGLE_OPTION_DIMENSION_B, LONG_OPTION_DIMENSION_B}, tr("Set base for dimension B in the table units."),
|
|
||||||
tr("The dimension B base")},
|
|
||||||
|
|
||||||
{{SINGLE_OPTION_DIMENSION_C, LONG_OPTION_DIMENSION_C}, tr("Set base for dimension C in the table units."),
|
|
||||||
tr("The dimension C base")},
|
|
||||||
|
|
||||||
{{SINGLE_OPTION_UNITS, LONG_OPTION_UNITS}, tr("Set pattern file units: cm, mm, inch."),
|
|
||||||
tr("The pattern units")},
|
|
||||||
|
|
||||||
{LONG_OPTION_TEST,
|
|
||||||
tr("Use for unit testing. Run the program and open a file without showing the main window.")},
|
|
||||||
|
|
||||||
{LONG_OPTION_NO_HDPI_SCALING,
|
|
||||||
tr("Disable high dpi scaling. Call this option if has problem with scaling (by default scaling enabled). "
|
|
||||||
"Alternatively you can use the %1 environment variable.").arg("QT_AUTO_SCREEN_SCALE_FACTOR=0")},
|
|
||||||
});
|
|
||||||
|
|
||||||
parser.process(arguments);
|
parser.process(arguments);
|
||||||
|
|
||||||
testMode = parser.isSet(LONG_OPTION_TEST);
|
m_testMode = parser.isSet(*LONG_OPTION_TEST);
|
||||||
|
|
||||||
if (not testMode && connection == SocketConnection::Client)
|
if (not m_testMode && connection == SocketConnection::Client)
|
||||||
{
|
{
|
||||||
const QString serverName = QCoreApplication::applicationName();
|
const QString serverName = QCoreApplication::applicationName();
|
||||||
QLocalSocket socket;
|
QLocalSocket socket;
|
||||||
|
@ -673,181 +653,24 @@ void MApplication::ParseCommandLine(const SocketConnection &connection, const QS
|
||||||
{
|
{
|
||||||
qCDebug(mApp, "Connected to the server '%s'", qUtf8Printable(serverName));
|
qCDebug(mApp, "Connected to the server '%s'", qUtf8Printable(serverName));
|
||||||
QTextStream stream(&socket);
|
QTextStream stream(&socket);
|
||||||
stream << QCoreApplication::arguments().join(";;");
|
stream << QCoreApplication::arguments().join(QStringLiteral(";;"));
|
||||||
stream.flush();
|
stream.flush();
|
||||||
socket.waitForBytesWritten();
|
socket.waitForBytesWritten();
|
||||||
qApp->exit(V_EX_OK);
|
QCoreApplication::exit(V_EX_OK);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
qCDebug(mApp, "Can't establish connection to the server '%s'", qUtf8Printable(serverName));
|
qCDebug(mApp, "Can't establish connection to the server '%s'", qUtf8Printable(serverName));
|
||||||
|
StartLocalServer(serverName);
|
||||||
localServer = new QLocalServer(this);
|
|
||||||
connect(localServer, &QLocalServer::newConnection, this, &MApplication::NewLocalSocketConnection);
|
|
||||||
if (not localServer->listen(serverName))
|
|
||||||
{
|
|
||||||
qCDebug(mApp, "Can't begin to listen for incoming connections on name '%s'",
|
|
||||||
qUtf8Printable(serverName));
|
|
||||||
if (localServer->serverError() == QAbstractSocket::AddressInUseError)
|
|
||||||
{
|
|
||||||
QLocalServer::removeServer(serverName);
|
|
||||||
if (not localServer->listen(serverName))
|
|
||||||
{
|
|
||||||
qCWarning(mApp, "%s",
|
|
||||||
qUtf8Printable(tr("Can't begin to listen for incoming connections on name '%1'").arg(serverName)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
LoadTranslation(TapeSettings()->GetLocale());
|
LoadTranslation(TapeSettings()->GetLocale());
|
||||||
}
|
}
|
||||||
|
|
||||||
const QStringList args = parser.positionalArguments();
|
const QStringList args = parser.positionalArguments();
|
||||||
if (args.count() > 0)
|
args.count() > 0 ? StartWithFiles(parser) : SingleStart(parser);
|
||||||
{
|
|
||||||
if (testMode && args.count() > 1)
|
|
||||||
{
|
|
||||||
qCCritical(mApp, "%s\n", qPrintable(tr("Test mode doesn't support opening several files.")));
|
|
||||||
parser.showHelp(V_EX_USAGE);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool flagDimensionA = false;
|
if (m_testMode)
|
||||||
bool flagDimensionB = false;
|
|
||||||
bool flagDimensionC = false;
|
|
||||||
bool flagUnits = false;
|
|
||||||
|
|
||||||
int dimensionAValue = 0;
|
|
||||||
int dimensionBValue = 0;
|
|
||||||
int dimensionCValue = 0;
|
|
||||||
Unit unit = Unit::Cm;
|
|
||||||
|
|
||||||
if (parser.isSet(LONG_OPTION_DIMENSION_A))
|
|
||||||
{
|
{
|
||||||
const QString value = parser.value(LONG_OPTION_DIMENSION_A);
|
QCoreApplication::exit(V_EX_OK); // close program after processing in console mode
|
||||||
|
|
||||||
bool ok = false;
|
|
||||||
dimensionAValue = value.toInt(&ok);
|
|
||||||
if(ok && dimensionAValue > 0)
|
|
||||||
{
|
|
||||||
flagDimensionA = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
qCCritical(mApp, "%s\n", qPrintable(tr("Invalid dimension A base value.")));
|
|
||||||
parser.showHelp(V_EX_USAGE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (parser.isSet(LONG_OPTION_DIMENSION_B))
|
|
||||||
{
|
|
||||||
const QString value = parser.value(LONG_OPTION_DIMENSION_B);
|
|
||||||
|
|
||||||
bool ok = false;
|
|
||||||
dimensionBValue = value.toInt(&ok);
|
|
||||||
if(ok && dimensionBValue > 0)
|
|
||||||
{
|
|
||||||
flagDimensionB = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
qCCritical(mApp, "%s\n", qPrintable(tr("Invalid dimension B base value.")));
|
|
||||||
parser.showHelp(V_EX_USAGE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (parser.isSet(LONG_OPTION_DIMENSION_C))
|
|
||||||
{
|
|
||||||
const QString value = parser.value(LONG_OPTION_DIMENSION_C);
|
|
||||||
|
|
||||||
bool ok = false;
|
|
||||||
dimensionCValue = value.toInt(&ok);
|
|
||||||
if(ok && dimensionCValue > 0)
|
|
||||||
{
|
|
||||||
flagDimensionC = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
qCCritical(mApp, "%s\n", qPrintable(tr("Invalid dimension C base value.")));
|
|
||||||
parser.showHelp(V_EX_USAGE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
const QString unitValue = parser.value(LONG_OPTION_UNITS);
|
|
||||||
if (not unitValue.isEmpty())
|
|
||||||
{
|
|
||||||
if (QStringList{unitMM, unitCM, unitINCH}.contains(unitValue))
|
|
||||||
{
|
|
||||||
flagUnits = true;
|
|
||||||
unit = StrToUnits(unitValue);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
qCCritical(mApp, "%s\n", qPrintable(tr("Invalid base size argument. Must be cm, mm or inch.")));
|
|
||||||
parser.showHelp(V_EX_USAGE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const auto &arg : args)
|
|
||||||
{
|
|
||||||
NewMainWindow();
|
|
||||||
if (not MainWindow()->LoadFile(arg))
|
|
||||||
{
|
|
||||||
if (testMode)
|
|
||||||
{
|
|
||||||
return; // process only one input file
|
|
||||||
}
|
|
||||||
delete MainWindow();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (flagDimensionA)
|
|
||||||
{
|
|
||||||
if (not MainWindow()->SetDimensionABase(dimensionAValue))
|
|
||||||
{
|
|
||||||
parser.showHelp(V_EX_USAGE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (flagDimensionB)
|
|
||||||
{
|
|
||||||
if (not MainWindow()->SetDimensionBBase(dimensionBValue))
|
|
||||||
{
|
|
||||||
parser.showHelp(V_EX_USAGE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (flagDimensionC)
|
|
||||||
{
|
|
||||||
if (not MainWindow()->SetDimensionCBase(dimensionCValue))
|
|
||||||
{
|
|
||||||
parser.showHelp(V_EX_USAGE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (flagUnits)
|
|
||||||
{
|
|
||||||
MainWindow()->SetPUnit(unit);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (not testMode)
|
|
||||||
{
|
|
||||||
NewMainWindow();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
qCCritical(mApp, "%s\n", qPrintable(tr("Please, provide one input file.")));
|
|
||||||
parser.showHelp(V_EX_USAGE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (testMode)
|
|
||||||
{
|
|
||||||
qApp->exit(V_EX_OK); // close program after processing in console mode
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -858,10 +681,10 @@ auto MApplication::VApp() -> MApplication *
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
TMainWindow *MApplication::NewMainWindow()
|
auto MApplication::NewMainWindow() -> TMainWindow *
|
||||||
{
|
{
|
||||||
TMainWindow *tape = new TMainWindow();
|
auto *tape = new TMainWindow();
|
||||||
mainWindows.prepend(tape);
|
m_mainWindows.prepend(tape);
|
||||||
if (not MApplication::VApp()->IsTestMode())
|
if (not MApplication::VApp()->IsTestMode())
|
||||||
{
|
{
|
||||||
tape->show();
|
tape->show();
|
||||||
|
@ -888,7 +711,7 @@ void MApplication::ProcessCMD()
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void MApplication::NewLocalSocketConnection()
|
void MApplication::NewLocalSocketConnection()
|
||||||
{
|
{
|
||||||
QLocalSocket *socket = localServer->nextPendingConnection();
|
QLocalSocket *socket = m_localServer->nextPendingConnection();
|
||||||
if (not socket)
|
if (not socket)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
@ -898,7 +721,7 @@ void MApplication::NewLocalSocketConnection()
|
||||||
const QString arg = stream.readAll();
|
const QString arg = stream.readAll();
|
||||||
if (not arg.isEmpty())
|
if (not arg.isEmpty())
|
||||||
{
|
{
|
||||||
ParseCommandLine(SocketConnection::Server, arg.split(";;"));
|
ParseCommandLine(SocketConnection::Server, arg.split(QStringLiteral(";;")));
|
||||||
}
|
}
|
||||||
delete socket;
|
delete socket;
|
||||||
MainWindow()->raise();
|
MainWindow()->raise();
|
||||||
|
@ -909,11 +732,222 @@ void MApplication::NewLocalSocketConnection()
|
||||||
void MApplication::Clean()
|
void MApplication::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 = m_mainWindows.count() - 1; i >= 0; --i)
|
||||||
{
|
{
|
||||||
if (mainWindows.at(i).isNull())
|
if (m_mainWindows.at(i).isNull())
|
||||||
{
|
{
|
||||||
mainWindows.removeAt(i);
|
m_mainWindows.removeAt(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void MApplication::InitParserOptions(QCommandLineParser &parser)
|
||||||
|
{
|
||||||
|
parser.addPositionalArgument(QStringLiteral("filename"), tr("The measurement file."));
|
||||||
|
|
||||||
|
parser.addOptions(
|
||||||
|
{
|
||||||
|
{{*SINGLE_OPTION_DIMENSION_A, *LONG_OPTION_DIMENSION_A}, tr("Set base for dimension A in the table units."),
|
||||||
|
tr("The dimension A base")},
|
||||||
|
|
||||||
|
{{*SINGLE_OPTION_DIMENSION_B, *LONG_OPTION_DIMENSION_B}, tr("Set base for dimension B in the table units."),
|
||||||
|
tr("The dimension B base")},
|
||||||
|
|
||||||
|
{{*SINGLE_OPTION_DIMENSION_C, *LONG_OPTION_DIMENSION_C}, tr("Set base for dimension C in the table units."),
|
||||||
|
tr("The dimension C base")},
|
||||||
|
|
||||||
|
{{*SINGLE_OPTION_UNITS, *LONG_OPTION_UNITS}, tr("Set pattern file units: cm, mm, inch."),
|
||||||
|
tr("The pattern units")},
|
||||||
|
|
||||||
|
{*LONG_OPTION_TEST,
|
||||||
|
tr("Use for unit testing. Run the program and open a file without showing the main window.")},
|
||||||
|
|
||||||
|
{LONG_OPTION_NO_HDPI_SCALING,
|
||||||
|
tr("Disable high dpi scaling. Call this option if has problem with scaling (by default scaling enabled). "
|
||||||
|
"Alternatively you can use the %1 environment variable.").arg("QT_AUTO_SCREEN_SCALE_FACTOR=0")},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void MApplication::StartLocalServer(const QString &serverName)
|
||||||
|
{
|
||||||
|
m_localServer = new QLocalServer(this);
|
||||||
|
connect(m_localServer, &QLocalServer::newConnection, this, &MApplication::NewLocalSocketConnection);
|
||||||
|
if (not m_localServer->listen(serverName))
|
||||||
|
{
|
||||||
|
qCDebug(mApp, "Can't begin to listen for incoming connections on name '%s'",
|
||||||
|
qUtf8Printable(serverName));
|
||||||
|
if (m_localServer->serverError() == QAbstractSocket::AddressInUseError)
|
||||||
|
{
|
||||||
|
QLocalServer::removeServer(serverName);
|
||||||
|
if (not m_localServer->listen(serverName))
|
||||||
|
{
|
||||||
|
qCWarning(mApp, "%s",
|
||||||
|
qUtf8Printable(tr("Can't begin to listen for incoming connections on name '%1'")
|
||||||
|
.arg(serverName)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void MApplication::StartWithFiles(QCommandLineParser &parser)
|
||||||
|
{
|
||||||
|
const QStringList args = parser.positionalArguments();
|
||||||
|
if (args.count() <= 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_testMode && args.count() > 1)
|
||||||
|
{
|
||||||
|
qCCritical(mApp, "%s\n", qPrintable(tr("Test mode doesn't support opening several files.")));
|
||||||
|
parser.showHelp(V_EX_USAGE);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool flagDimensionA = false;
|
||||||
|
bool flagDimensionB = false;
|
||||||
|
bool flagDimensionC = false;
|
||||||
|
bool flagUnits = false;
|
||||||
|
|
||||||
|
int dimensionAValue = 0;
|
||||||
|
int dimensionBValue = 0;
|
||||||
|
int dimensionCValue = 0;
|
||||||
|
Unit unit = Unit::Cm;
|
||||||
|
|
||||||
|
ParseDimensionAOption(parser, dimensionAValue, flagDimensionA);
|
||||||
|
ParseDimensionBOption(parser, dimensionBValue, flagDimensionB);
|
||||||
|
ParseDimensionCOption(parser, dimensionCValue, flagDimensionC);
|
||||||
|
ParseUnitsOption(parser, unit, flagUnits);
|
||||||
|
|
||||||
|
for (const auto &arg : args)
|
||||||
|
{
|
||||||
|
NewMainWindow();
|
||||||
|
if (not MainWindow()->LoadFile(arg))
|
||||||
|
{
|
||||||
|
if (m_testMode)
|
||||||
|
{
|
||||||
|
return; // process only one input file
|
||||||
|
}
|
||||||
|
delete MainWindow();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flagDimensionA && not MainWindow()->SetDimensionABase(dimensionAValue))
|
||||||
|
{
|
||||||
|
parser.showHelp(V_EX_USAGE);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flagDimensionB && not MainWindow()->SetDimensionBBase(dimensionBValue))
|
||||||
|
{
|
||||||
|
parser.showHelp(V_EX_USAGE);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flagDimensionC && not MainWindow()->SetDimensionCBase(dimensionCValue))
|
||||||
|
{
|
||||||
|
parser.showHelp(V_EX_USAGE);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flagUnits)
|
||||||
|
{
|
||||||
|
MainWindow()->SetPUnit(unit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void MApplication::SingleStart(QCommandLineParser &parser)
|
||||||
|
{
|
||||||
|
if (not m_testMode)
|
||||||
|
{
|
||||||
|
NewMainWindow();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
qCCritical(mApp, "%s\n", qPrintable(tr("Please, provide one input file.")));
|
||||||
|
parser.showHelp(V_EX_USAGE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void MApplication::ParseDimensionAOption(QCommandLineParser &parser, int &dimensionAValue, bool &flagDimensionA)
|
||||||
|
{
|
||||||
|
if (parser.isSet(*LONG_OPTION_DIMENSION_A))
|
||||||
|
{
|
||||||
|
const QString value = parser.value(*LONG_OPTION_DIMENSION_A);
|
||||||
|
|
||||||
|
bool ok = false;
|
||||||
|
dimensionAValue = value.toInt(&ok);
|
||||||
|
if(ok && dimensionAValue > 0)
|
||||||
|
{
|
||||||
|
flagDimensionA = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
qCCritical(mApp, "%s\n", qPrintable(tr("Invalid dimension A base value.")));
|
||||||
|
parser.showHelp(V_EX_USAGE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void MApplication::ParseDimensionBOption(QCommandLineParser &parser, int &dimensionBValue, bool &flagDimensionB)
|
||||||
|
{
|
||||||
|
if (parser.isSet(*LONG_OPTION_DIMENSION_B))
|
||||||
|
{
|
||||||
|
const QString value = parser.value(*LONG_OPTION_DIMENSION_B);
|
||||||
|
|
||||||
|
bool ok = false;
|
||||||
|
dimensionBValue = value.toInt(&ok);
|
||||||
|
if(ok && dimensionBValue > 0)
|
||||||
|
{
|
||||||
|
flagDimensionB = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
qCCritical(mApp, "%s\n", qPrintable(tr("Invalid dimension B base value.")));
|
||||||
|
parser.showHelp(V_EX_USAGE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void MApplication::ParseDimensionCOption(QCommandLineParser &parser, int &dimensionCValue, bool &flagDimensionC)
|
||||||
|
{
|
||||||
|
if (parser.isSet(*LONG_OPTION_DIMENSION_C))
|
||||||
|
{
|
||||||
|
const QString value = parser.value(*LONG_OPTION_DIMENSION_C);
|
||||||
|
|
||||||
|
bool ok = false;
|
||||||
|
dimensionCValue = value.toInt(&ok);
|
||||||
|
if(ok && dimensionCValue > 0)
|
||||||
|
{
|
||||||
|
flagDimensionC = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
qCCritical(mApp, "%s\n", qPrintable(tr("Invalid dimension C base value.")));
|
||||||
|
parser.showHelp(V_EX_USAGE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void MApplication::ParseUnitsOption(QCommandLineParser &parser, Unit &unit, bool &flagUnits)
|
||||||
|
{
|
||||||
|
const QString unitValue = parser.value(*LONG_OPTION_UNITS);
|
||||||
|
if (not unitValue.isEmpty())
|
||||||
|
{
|
||||||
|
if (QStringList{unitMM, unitCM, unitINCH}.contains(unitValue))
|
||||||
|
{
|
||||||
|
flagUnits = true;
|
||||||
|
unit = StrToUnits(unitValue);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
qCCritical(mApp, "%s\n", qPrintable(tr("Invalid base size argument. Must be cm, mm or inch.")));
|
||||||
|
parser.showHelp(V_EX_USAGE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,41 +30,41 @@
|
||||||
#define MAPPLICATION_H
|
#define MAPPLICATION_H
|
||||||
|
|
||||||
#include "../vpatterndb/vtranslatevars.h"
|
#include "../vpatterndb/vtranslatevars.h"
|
||||||
#include "../vmisc/def.h"
|
|
||||||
#include "vtapesettings.h"
|
#include "vtapesettings.h"
|
||||||
#include "../vmisc/vabstractapplication.h"
|
#include "../vmisc/vabstractapplication.h"
|
||||||
#include "dialogs/dialogmdatabase.h"
|
#include "dialogs/dialogmdatabase.h"
|
||||||
|
|
||||||
class TMainWindow;
|
class TMainWindow;
|
||||||
class QLocalServer;
|
class QLocalServer;
|
||||||
|
class QCommandLineParser;
|
||||||
|
|
||||||
enum class SocketConnection : bool {Client = false, Server = true};
|
enum class SocketConnection : bool {Client = false, Server = true};
|
||||||
|
|
||||||
class MApplication : public VAbstractApplication
|
class MApplication : public VAbstractApplication
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT // NOLINT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MApplication(int &argc, char **argv);
|
MApplication(int &argc, char **argv);
|
||||||
virtual ~MApplication() override;
|
~MApplication() override;
|
||||||
|
|
||||||
virtual bool notify(QObject * receiver, QEvent * event) override;
|
auto notify(QObject * receiver, QEvent * event) -> bool override;
|
||||||
|
|
||||||
bool IsTestMode() const;
|
auto IsTestMode() const -> bool;
|
||||||
virtual bool IsAppInGUIMode() const override;
|
auto IsAppInGUIMode() const -> bool override;
|
||||||
TMainWindow *MainWindow();
|
auto MainWindow() -> TMainWindow *;
|
||||||
QList<TMainWindow*> MainWindows();
|
auto MainWindows() -> QList<TMainWindow*>;
|
||||||
TMainWindow *NewMainWindow();
|
auto NewMainWindow() -> TMainWindow *;
|
||||||
|
|
||||||
void InitOptions();
|
void InitOptions();
|
||||||
|
|
||||||
virtual const VTranslateVars *TrVars() override;
|
auto TrVars() -> const VTranslateVars * override;
|
||||||
|
|
||||||
virtual void OpenSettings() override;
|
void OpenSettings() override;
|
||||||
VTapeSettings *TapeSettings();
|
auto TapeSettings() -> VTapeSettings *;
|
||||||
void ActivateDarkMode();
|
void ActivateDarkMode();
|
||||||
|
|
||||||
QString diagramsPath() const;
|
static auto diagramsPath() -> QString;
|
||||||
|
|
||||||
void ShowDataBase();
|
void ShowDataBase();
|
||||||
void RetranslateGroups();
|
void RetranslateGroups();
|
||||||
|
@ -72,36 +72,47 @@ public:
|
||||||
|
|
||||||
void ParseCommandLine(const SocketConnection &connection, const QStringList &arguments);
|
void ParseCommandLine(const SocketConnection &connection, const QStringList &arguments);
|
||||||
|
|
||||||
static MApplication *VApp();
|
static auto VApp() -> MApplication *;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void ProcessCMD();
|
void ProcessCMD();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void InitTrVars() override;
|
void InitTrVars() override;
|
||||||
virtual bool event(QEvent *e) override;
|
auto event(QEvent *e) -> bool override;
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
virtual void AboutToQuit() override;
|
void AboutToQuit() override;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void NewLocalSocketConnection();
|
void NewLocalSocketConnection();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(MApplication)
|
Q_DISABLE_COPY_MOVE(MApplication) // NOLINT
|
||||||
QList<QPointer<TMainWindow> > mainWindows;
|
QList<QPointer<TMainWindow> > m_mainWindows{};
|
||||||
QLocalServer *localServer;
|
QLocalServer *m_localServer{nullptr};
|
||||||
VTranslateVars *trVars;
|
VTranslateVars *m_trVars{nullptr};
|
||||||
QPointer<DialogMDataBase> dataBase;
|
QPointer<DialogMDataBase> m_dataBase{};
|
||||||
bool testMode;
|
bool m_testMode{false};
|
||||||
|
|
||||||
void Clean();
|
void Clean();
|
||||||
|
|
||||||
|
static void InitParserOptions(QCommandLineParser &parser);
|
||||||
|
void StartLocalServer(const QString &serverName);
|
||||||
|
|
||||||
|
void StartWithFiles(QCommandLineParser &parser);
|
||||||
|
void SingleStart(QCommandLineParser &parser);
|
||||||
|
|
||||||
|
static void ParseDimensionAOption(QCommandLineParser &parser, int &dimensionAValue, bool &flagDimensionA);
|
||||||
|
static void ParseDimensionBOption(QCommandLineParser &parser, int &dimensionBValue, bool &flagDimensionB);
|
||||||
|
static void ParseDimensionCOption(QCommandLineParser &parser, int &dimensionCValue, bool &flagDimensionC);
|
||||||
|
static void ParseUnitsOption(QCommandLineParser &parser, Unit &unit , bool &flagUnits);
|
||||||
};
|
};
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
inline const VTranslateVars *MApplication::TrVars()
|
inline auto MApplication::TrVars() -> const VTranslateVars *
|
||||||
{
|
{
|
||||||
return trVars;
|
return m_trVars;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // MAPPLICATION_H
|
#endif // MAPPLICATION_H
|
||||||
|
|
|
@ -56,7 +56,7 @@ QT_WARNING_PUSH
|
||||||
QT_WARNING_DISABLE_CLANG("-Wmissing-prototypes")
|
QT_WARNING_DISABLE_CLANG("-Wmissing-prototypes")
|
||||||
QT_WARNING_DISABLE_INTEL(1418)
|
QT_WARNING_DISABLE_INTEL(1418)
|
||||||
|
|
||||||
Q_LOGGING_CATEGORY(vApp, "v.application")
|
Q_LOGGING_CATEGORY(vApp, "v.application") // NOLINT
|
||||||
|
|
||||||
QT_WARNING_POP
|
QT_WARNING_POP
|
||||||
|
|
||||||
|
@ -64,25 +64,23 @@ Q_DECL_CONSTEXPR auto DAYS_TO_KEEP_LOGS = 3;
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
QString AppFilePath(const QString &appName)
|
auto AppFilePath(const QString &appName) -> QString
|
||||||
{
|
{
|
||||||
QString appNameExe = appName;
|
QString appNameExe = appName;
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
appNameExe += ".exe";
|
appNameExe += ".exe";
|
||||||
#endif
|
#endif
|
||||||
QFileInfo canonicalFile(QString("%1/%2").arg(QCoreApplication::applicationDirPath(), appNameExe));
|
QFileInfo canonicalFile(QStringLiteral("%1/%2").arg(QCoreApplication::applicationDirPath(), appNameExe));
|
||||||
if (canonicalFile.exists())
|
if (canonicalFile.exists())
|
||||||
{
|
{
|
||||||
return canonicalFile.absoluteFilePath();
|
return canonicalFile.absoluteFilePath();
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
QFileInfo debugFile(QStringLiteral("%1/../../%2/bin/%3")
|
||||||
QFileInfo debugFile(QString("%1/../../%2/bin/%3")
|
|
||||||
.arg(QCoreApplication::applicationDirPath(), appName, appNameExe));
|
.arg(QCoreApplication::applicationDirPath(), appName, appNameExe));
|
||||||
return debugFile.exists() ? debugFile.absoluteFilePath() : appNameExe;
|
return debugFile.exists() ? debugFile.absoluteFilePath() : appNameExe;
|
||||||
}
|
}
|
||||||
}
|
} // namespace
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
|
inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
|
||||||
|
@ -307,8 +305,6 @@ inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &con
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define DefWidth 1.2//mm
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
/**
|
/**
|
||||||
* @brief VApplication constructor.
|
* @brief VApplication constructor.
|
||||||
|
@ -316,16 +312,12 @@ inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &con
|
||||||
* @param argv command line.
|
* @param argv command line.
|
||||||
*/
|
*/
|
||||||
VApplication::VApplication(int &argc, char **argv)
|
VApplication::VApplication(int &argc, char **argv)
|
||||||
: VAbstractValApplication(argc, argv),
|
: VAbstractValApplication(argc, argv)
|
||||||
trVars(nullptr),
|
|
||||||
autoSaveTimer(nullptr),
|
|
||||||
lockLog(),
|
|
||||||
out(nullptr)
|
|
||||||
{
|
{
|
||||||
setApplicationDisplayName(VER_PRODUCTNAME_STR);
|
setApplicationDisplayName(QStringLiteral(VER_PRODUCTNAME_STR));
|
||||||
setApplicationName(VER_INTERNALNAME_STR);
|
setApplicationName(QStringLiteral(VER_INTERNALNAME_STR));
|
||||||
setOrganizationName(VER_COMPANYNAME_STR);
|
setOrganizationName(QStringLiteral(VER_COMPANYNAME_STR));
|
||||||
setOrganizationDomain(VER_COMPANYDOMAIN_STR);
|
setOrganizationDomain(QStringLiteral(VER_COMPANYDOMAIN_STR));
|
||||||
// Setting the Application version
|
// Setting the Application version
|
||||||
setApplicationVersion(APP_VERSION_STR);
|
setApplicationVersion(APP_VERSION_STR);
|
||||||
// making sure will create new instance...just in case we will ever do 2 objects of VApplication
|
// making sure will create new instance...just in case we will ever do 2 objects of VApplication
|
||||||
|
@ -337,7 +329,7 @@ VApplication::~VApplication()
|
||||||
{
|
{
|
||||||
qCDebug(vApp, "Application closing.");
|
qCDebug(vApp, "Application closing.");
|
||||||
qInstallMessageHandler(nullptr); // Resore the message handler
|
qInstallMessageHandler(nullptr); // Resore the message handler
|
||||||
delete trVars;
|
delete m_trVars;
|
||||||
VCommandLine::Reset();
|
VCommandLine::Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -386,7 +378,7 @@ void VApplication::NewValentina(const QString &fileName)
|
||||||
* @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 VApplication::notify(QObject *receiver, QEvent *event)
|
auto VApplication::notify(QObject *receiver, QEvent *event) -> bool
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -465,7 +457,7 @@ bool VApplication::notify(QObject *receiver, QEvent *event)
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void VApplication::ActivateDarkMode()
|
void VApplication::ActivateDarkMode()
|
||||||
{
|
{
|
||||||
VValentinaSettings *settings = VAbstractValApplication::VApp()->ValentinaSettings();
|
VValentinaSettings *settings = ValentinaSettings();
|
||||||
if (settings->GetDarkMode())
|
if (settings->GetDarkMode())
|
||||||
{
|
{
|
||||||
QFile f(QStringLiteral(":qdarkstyle/style.qss"));
|
QFile f(QStringLiteral(":qdarkstyle/style.qss"));
|
||||||
|
@ -479,24 +471,23 @@ void VApplication::ActivateDarkMode()
|
||||||
QTextStream ts(&f);
|
QTextStream ts(&f);
|
||||||
qApp->setStyleSheet(ts.readAll());
|
qApp->setStyleSheet(ts.readAll());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
QString VApplication::TapeFilePath() const
|
auto VApplication::TapeFilePath() -> QString
|
||||||
{
|
{
|
||||||
return AppFilePath(QStringLiteral("tape"));
|
return AppFilePath(QStringLiteral("tape"));
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
QString VApplication::PuzzleFilePath() const
|
auto VApplication::PuzzleFilePath() -> QString
|
||||||
{
|
{
|
||||||
return AppFilePath(QStringLiteral("puzzle"));
|
return AppFilePath(QStringLiteral("puzzle"));
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
QString VApplication::LogDirPath() const
|
auto VApplication::LogDirPath() -> QString
|
||||||
{
|
{
|
||||||
#if defined(Q_OS_WIN) || defined(Q_OS_OSX)
|
#if defined(Q_OS_WIN) || defined(Q_OS_OSX)
|
||||||
const QString logDirPath = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QString(),
|
const QString logDirPath = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QString(),
|
||||||
|
@ -510,16 +501,16 @@ QString VApplication::LogDirPath() const
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
QString VApplication::LogPath() const
|
auto VApplication::LogPath() -> QString
|
||||||
{
|
{
|
||||||
return QStringLiteral("%1/valentina-pid%2.log").arg(LogDirPath()).arg(applicationPid());
|
return QStringLiteral("%1/valentina-pid%2.log").arg(LogDirPath()).arg(applicationPid());
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
bool VApplication::CreateLogDir() const
|
auto VApplication::CreateLogDir() -> bool
|
||||||
{
|
{
|
||||||
QDir logDir(LogDirPath());
|
QDir logDir(LogDirPath());
|
||||||
if (logDir.exists() == false)
|
if (not logDir.exists())
|
||||||
{
|
{
|
||||||
return logDir.mkpath(QChar('.')); // Create directory for log if need
|
return logDir.mkpath(QChar('.')); // Create directory for log if need
|
||||||
}
|
}
|
||||||
|
@ -529,13 +520,13 @@ bool VApplication::CreateLogDir() const
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void VApplication::BeginLogging()
|
void VApplication::BeginLogging()
|
||||||
{
|
{
|
||||||
VlpCreateLock(lockLog, LogPath(), [this](){return new QFile(LogPath());});
|
VlpCreateLock(m_lockLog, LogPath(), [](){return new QFile(LogPath());});
|
||||||
|
|
||||||
if (lockLog->IsLocked())
|
if (m_lockLog->IsLocked())
|
||||||
{
|
{
|
||||||
if (lockLog->GetProtected()->open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text))
|
if (m_lockLog->GetProtected()->open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text))
|
||||||
{
|
{
|
||||||
out.reset(new QTextStream(lockLog->GetProtected().data()));
|
m_out.reset(new QTextStream(m_lockLog->GetProtected().data()));
|
||||||
qInstallMessageHandler(noisyFailureMsgHandler);
|
qInstallMessageHandler(noisyFailureMsgHandler);
|
||||||
qCDebug(vApp, "Log file %s was locked.", qUtf8Printable(LogPath()));
|
qCDebug(vApp, "Log file %s was locked.", qUtf8Printable(LogPath()));
|
||||||
}
|
}
|
||||||
|
@ -552,18 +543,18 @@ void VApplication::BeginLogging()
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void VApplication::ClearOldLogs() const
|
void VApplication::ClearOldLogs()
|
||||||
{
|
{
|
||||||
const QString workingDirectory = QDir::currentPath();// Save the app working directory
|
const QString workingDirectory = QDir::currentPath();// Save the app working directory
|
||||||
QDir logsDir(LogDirPath());
|
QDir logsDir(LogDirPath());
|
||||||
logsDir.setNameFilters(QStringList("*.log"));
|
logsDir.setNameFilters(QStringList(QStringLiteral("*.log")));
|
||||||
logsDir.setCurrent(LogDirPath());
|
QDir::setCurrent(LogDirPath());
|
||||||
|
|
||||||
const QStringList allFiles = logsDir.entryList(QDir::NoDotAndDotDot | QDir::Files);
|
const QStringList allFiles = logsDir.entryList(QDir::NoDotAndDotDot | QDir::Files);
|
||||||
if (allFiles.isEmpty() == false)
|
if (not allFiles.isEmpty())
|
||||||
{
|
{
|
||||||
qCDebug(vApp, "Clearing old logs");
|
qCDebug(vApp, "Clearing old logs");
|
||||||
for (auto &fn : allFiles)
|
for (const auto &fn : allFiles)
|
||||||
{
|
{
|
||||||
QFileInfo info(fn);
|
QFileInfo info(fn);
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
|
||||||
|
@ -640,7 +631,7 @@ void VApplication::InitOptions()
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
QStringList VApplication::LabelLanguages()
|
auto VApplication::LabelLanguages() -> QStringList
|
||||||
{
|
{
|
||||||
QStringList list {"de", // German
|
QStringList list {"de", // German
|
||||||
"en", // English
|
"en", // English
|
||||||
|
@ -666,32 +657,32 @@ void VApplication::StartLogging()
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
QTextStream *VApplication::LogFile()
|
auto VApplication::LogFile() -> QTextStream *
|
||||||
{
|
{
|
||||||
return out.get();
|
return m_out.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
const VTranslateVars *VApplication::TrVars()
|
auto VApplication::TrVars() -> const VTranslateVars *
|
||||||
{
|
{
|
||||||
return trVars;
|
return m_trVars;
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void VApplication::InitTrVars()
|
void VApplication::InitTrVars()
|
||||||
{
|
{
|
||||||
if (trVars != nullptr)
|
if (m_trVars != nullptr)
|
||||||
{
|
{
|
||||||
trVars->Retranslate();
|
m_trVars->Retranslate();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
trVars = new VTranslateVars();
|
m_trVars = new VTranslateVars();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
bool VApplication::event(QEvent *e)
|
auto VApplication::event(QEvent *e) -> bool
|
||||||
{
|
{
|
||||||
switch(e->type())
|
switch(e->type())
|
||||||
{
|
{
|
||||||
|
@ -699,11 +690,11 @@ bool VApplication::event(QEvent *e)
|
||||||
// Mac specific).
|
// Mac specific).
|
||||||
case QEvent::FileOpen:
|
case QEvent::FileOpen:
|
||||||
{
|
{
|
||||||
QFileOpenEvent *fileOpenEvent = static_cast<QFileOpenEvent *>(e);
|
auto *fileOpenEvent = dynamic_cast<QFileOpenEvent *>(e);
|
||||||
const QString macFileOpen = fileOpenEvent->file();
|
const QString macFileOpen = fileOpenEvent->file();
|
||||||
if(not macFileOpen.isEmpty())
|
if(not macFileOpen.isEmpty())
|
||||||
{
|
{
|
||||||
MainWindow *window = qobject_cast<MainWindow*>(mainWindow);
|
auto *window = qobject_cast<MainWindow*>(mainWindow);
|
||||||
if (window)
|
if (window)
|
||||||
{
|
{
|
||||||
window->LoadPattern(macFileOpen); // open file in existing window
|
window->LoadPattern(macFileOpen); // open file in existing window
|
||||||
|
@ -738,7 +729,7 @@ void VApplication::AboutToQuit()
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
bool VApplication::IsGUIMode()
|
auto VApplication::IsGUIMode() -> bool
|
||||||
{
|
{
|
||||||
return (VCommandLine::instance != nullptr) && VCommandLine::instance->IsGuiEnabled();
|
return (VCommandLine::instance != nullptr) && VCommandLine::instance->IsGuiEnabled();
|
||||||
}
|
}
|
||||||
|
@ -747,13 +738,13 @@ bool VApplication::IsGUIMode()
|
||||||
/**
|
/**
|
||||||
* @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 VApplication::IsAppInGUIMode() const
|
auto VApplication::IsAppInGUIMode() const -> bool
|
||||||
{
|
{
|
||||||
return IsGUIMode();
|
return IsGUIMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
bool VApplication::IsPedantic() const
|
auto VApplication::IsPedantic() const -> bool
|
||||||
{
|
{
|
||||||
return (VCommandLine::instance != nullptr) && VCommandLine::instance->IsPedantic();
|
return (VCommandLine::instance != nullptr) && VCommandLine::instance->IsPedantic();
|
||||||
}
|
}
|
||||||
|
@ -765,7 +756,7 @@ auto VApplication::VApp() -> VApplication *
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
const VCommandLinePtr VApplication::CommandLine() const
|
auto VApplication::CommandLine() -> VCommandLinePtr
|
||||||
{
|
{
|
||||||
return VCommandLine::instance;
|
return VCommandLine::instance;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,6 @@
|
||||||
#define VAPPLICATION_H
|
#define VAPPLICATION_H
|
||||||
|
|
||||||
#include "../vmisc/vabstractvalapplication.h"
|
#include "../vmisc/vabstractvalapplication.h"
|
||||||
#include "../vwidgets/vmaingraphicsview.h"
|
|
||||||
#include "../vpatterndb/vtranslatevars.h"
|
#include "../vpatterndb/vtranslatevars.h"
|
||||||
#include "vcmdexport.h"
|
#include "vcmdexport.h"
|
||||||
#include "vlockguard.h"
|
#include "vlockguard.h"
|
||||||
|
@ -42,72 +41,73 @@ class VApplication;// use in define
|
||||||
*/
|
*/
|
||||||
class VApplication : public VAbstractValApplication
|
class VApplication : public VAbstractValApplication
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT // NOLINT
|
||||||
public:
|
public:
|
||||||
|
|
||||||
VApplication(int &argc, char ** argv);
|
VApplication(int &argc, char ** argv);
|
||||||
virtual ~VApplication() override;
|
~VApplication() override;
|
||||||
|
|
||||||
static void NewValentina(const QString &fileName = QString());
|
static void NewValentina(const QString &fileName = QString());
|
||||||
virtual bool notify(QObject * receiver, QEvent * event) override;
|
auto notify(QObject * receiver, QEvent * event) -> bool override;
|
||||||
|
|
||||||
void InitOptions();
|
void InitOptions();
|
||||||
|
|
||||||
QString TapeFilePath() const;
|
static auto TapeFilePath() -> QString;
|
||||||
QString PuzzleFilePath() const;
|
static auto PuzzleFilePath() -> QString;
|
||||||
|
|
||||||
QTimer *getAutoSaveTimer() const;
|
auto getAutoSaveTimer() const -> QTimer *;
|
||||||
void setAutoSaveTimer(QTimer *value);
|
void setAutoSaveTimer(QTimer *value);
|
||||||
|
|
||||||
static QStringList LabelLanguages();
|
static auto LabelLanguages() -> QStringList;
|
||||||
|
|
||||||
void StartLogging();
|
void StartLogging();
|
||||||
void ActivateDarkMode();
|
void ActivateDarkMode();
|
||||||
QTextStream *LogFile();
|
auto LogFile() -> QTextStream *;
|
||||||
|
|
||||||
virtual const VTranslateVars *TrVars() override;
|
auto TrVars() -> const VTranslateVars * override;
|
||||||
|
|
||||||
bool static IsGUIMode();
|
auto static IsGUIMode() -> bool;
|
||||||
virtual bool IsAppInGUIMode() const override;
|
auto IsAppInGUIMode() const -> bool override;
|
||||||
virtual bool IsPedantic() const override;
|
auto IsPedantic() const -> bool override;
|
||||||
|
|
||||||
static VApplication *VApp();
|
static auto VApp() -> VApplication *;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void InitTrVars() override;
|
void InitTrVars() override;
|
||||||
virtual bool event(QEvent *e) override;
|
auto event(QEvent *e) -> bool override;
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
virtual void AboutToQuit() override;
|
void AboutToQuit() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(VApplication)
|
Q_DISABLE_COPY_MOVE(VApplication) // NOLINT
|
||||||
VTranslateVars *trVars;
|
VTranslateVars *m_trVars{nullptr};
|
||||||
QTimer *autoSaveTimer;
|
QTimer *m_autoSaveTimer{nullptr};
|
||||||
|
|
||||||
QSharedPointer<VLockGuard<QFile>> lockLog;
|
QSharedPointer<VLockGuard<QFile>> m_lockLog{};
|
||||||
std::shared_ptr<QTextStream> out;
|
std::shared_ptr<QTextStream> m_out{nullptr};
|
||||||
|
|
||||||
QString LogDirPath()const;
|
static auto LogDirPath() -> QString;
|
||||||
QString LogPath()const;
|
static auto LogPath() -> QString;
|
||||||
bool CreateLogDir()const;
|
static auto CreateLogDir() -> bool;
|
||||||
void BeginLogging();
|
void BeginLogging();
|
||||||
void ClearOldLogs()const;
|
static void ClearOldLogs();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
//moved to the end of class so merge should go
|
//moved to the end of class so merge should go
|
||||||
const VCommandLinePtr CommandLine() const;
|
static auto CommandLine() -> VCommandLinePtr;
|
||||||
};
|
};
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
inline QTimer *VApplication::getAutoSaveTimer() const
|
inline auto VApplication::getAutoSaveTimer() const -> QTimer *
|
||||||
{
|
{
|
||||||
return autoSaveTimer;
|
return m_autoSaveTimer;
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
inline void VApplication::setAutoSaveTimer(QTimer *value)
|
inline void VApplication::setAutoSaveTimer(QTimer *value)
|
||||||
{
|
{
|
||||||
autoSaveTimer = value;
|
m_autoSaveTimer = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // VAPPLICATION_H
|
#endif // VAPPLICATION_H
|
||||||
|
|
|
@ -28,11 +28,12 @@
|
||||||
|
|
||||||
#include "preferencespatternpage.h"
|
#include "preferencespatternpage.h"
|
||||||
#include "ui_preferencespatternpage.h"
|
#include "ui_preferencespatternpage.h"
|
||||||
#include "../../core/vapplication.h"
|
|
||||||
#include "../ifc/xml/vabstractpattern.h"
|
|
||||||
#include "../dialogdatetimeformats.h"
|
#include "../dialogdatetimeformats.h"
|
||||||
#include "../dialogknownmaterials.h"
|
#include "../dialogknownmaterials.h"
|
||||||
#include "../vmisc/vvalentinasettings.h"
|
#include "../vmisc/vvalentinasettings.h"
|
||||||
|
#include "../vmisc/vabstractvalapplication.h"
|
||||||
|
#include "../vwidgets/vmaingraphicsview.h"
|
||||||
|
#include "../ifc/xml/vabstractpattern.h"
|
||||||
|
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QDate>
|
#include <QDate>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user