2015-07-10 13:14:55 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file mapplication.cpp
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 8 7, 2015
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
2017-10-05 11:20:01 +02:00
|
|
|
** This source code is part of the Valentina project, a pattern making
|
2015-07-10 13:14:55 +02:00
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
|
|
|
** Copyright (C) 2015 Valentina project
|
2020-01-31 07:00:05 +01:00
|
|
|
** <https://gitlab.com/smart-pattern/valentina> All Rights Reserved.
|
2015-07-10 13:14:55 +02:00
|
|
|
**
|
|
|
|
** Valentina is free software: you can redistribute it and/or modify
|
|
|
|
** it under the terms of the GNU General Public License as published by
|
|
|
|
** the Free Software Foundation, either version 3 of the License, or
|
|
|
|
** (at your option) any later version.
|
|
|
|
**
|
|
|
|
** Valentina is distributed in the hope that it will be useful,
|
|
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
** GNU General Public License for more details.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU General Public License
|
|
|
|
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
#include "mapplication.h"
|
2023-08-05 17:58:29 +02:00
|
|
|
#include "../fervor/fvupdater.h"
|
2015-09-19 22:08:03 +02:00
|
|
|
#include "../ifc/exception/vexceptionbadid.h"
|
|
|
|
#include "../ifc/exception/vexceptionconversionerror.h"
|
|
|
|
#include "../ifc/exception/vexceptionemptyparameter.h"
|
2023-06-08 12:20:20 +02:00
|
|
|
#include "../ifc/exception/vexceptionobjecterror.h"
|
2015-09-19 22:08:03 +02:00
|
|
|
#include "../ifc/exception/vexceptionwrongid.h"
|
2023-08-05 17:58:29 +02:00
|
|
|
#include "../qmuparser/qmuparsererror.h"
|
2023-10-28 08:55:21 +02:00
|
|
|
#include "../vformat/knownmeasurements/vknownmeasurementsdatabase.h"
|
2023-06-27 13:15:21 +02:00
|
|
|
#include "../vganalytics/def.h"
|
|
|
|
#include "../vganalytics/vganalytics.h"
|
2022-08-12 17:50:13 +02:00
|
|
|
#include "../vmisc/projectversion.h"
|
2023-08-05 17:58:29 +02:00
|
|
|
#include "../vmisc/qt_dispatch/qt_dispatch.h"
|
2023-07-24 12:41:42 +02:00
|
|
|
#include "../vmisc/theme/vtheme.h"
|
2023-06-08 12:20:20 +02:00
|
|
|
#include "../vmisc/vsysexits.h"
|
2023-11-07 10:20:31 +01:00
|
|
|
#include "dialogs/dialogtapepreferences.h"
|
|
|
|
#include "qfuturewatcher.h"
|
|
|
|
#include "tkmmainwindow.h"
|
2023-06-08 12:20:20 +02:00
|
|
|
#include "tmainwindow.h"
|
|
|
|
#include "version.h"
|
2023-10-23 15:57:22 +02:00
|
|
|
#include "vtapeshortcutmanager.h"
|
2022-08-03 13:41:19 +02:00
|
|
|
|
2023-10-28 08:55:21 +02:00
|
|
|
#include "QtConcurrent/qtconcurrentrun.h"
|
2023-08-05 17:58:29 +02:00
|
|
|
#include <QCommandLineParser>
|
2015-07-15 09:16:59 +02:00
|
|
|
#include <QDir>
|
2015-07-10 13:14:55 +02:00
|
|
|
#include <QFileOpenEvent>
|
2023-10-28 08:55:21 +02:00
|
|
|
#include <QFileSystemWatcher>
|
|
|
|
#include <QFuture>
|
2023-06-08 12:20:20 +02:00
|
|
|
#include <QGlobalStatic>
|
|
|
|
#include <QGridLayout>
|
2015-08-29 11:48:03 +02:00
|
|
|
#include <QLocalServer>
|
2023-06-08 12:20:20 +02:00
|
|
|
#include <QLocalSocket>
|
2015-09-15 20:21:51 +02:00
|
|
|
#include <QMessageBox>
|
2023-06-08 12:20:20 +02:00
|
|
|
#include <QPointer>
|
|
|
|
#include <QResource>
|
2015-10-01 16:59:01 +02:00
|
|
|
#include <QSpacerItem>
|
2023-07-24 12:41:42 +02:00
|
|
|
#include <QStyleFactory>
|
2015-10-18 21:30:51 +02:00
|
|
|
#include <QThread>
|
2023-06-08 12:20:20 +02:00
|
|
|
#include <QTranslator>
|
2023-08-05 17:58:29 +02:00
|
|
|
#include <QUuid>
|
2023-06-08 12:20:20 +02:00
|
|
|
#include <iostream>
|
2015-07-10 13:14:55 +02:00
|
|
|
|
2023-01-04 17:31:50 +01:00
|
|
|
#if !defined(BUILD_REVISION) && defined(QBS_BUILD)
|
2023-11-09 16:59:21 +01:00
|
|
|
#include <QEvent>
|
2023-01-04 17:31:50 +01:00
|
|
|
#include <vcsRepoState.h>
|
|
|
|
#define BUILD_REVISION VCS_REPO_STATE_REVISION
|
|
|
|
#endif
|
|
|
|
|
2020-07-13 15:11:57 +02:00
|
|
|
#if defined(APPIMAGE) && defined(Q_OS_LINUX)
|
2023-06-08 12:20:20 +02:00
|
|
|
#include "../vmisc/appimage.h"
|
2020-07-13 15:11:57 +02:00
|
|
|
#endif // defined(APPIMAGE) && defined(Q_OS_LINUX)
|
|
|
|
|
2023-10-07 17:56:39 +02:00
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(6, 4, 0)
|
|
|
|
#include "../vmisc/compatibility.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
using namespace Qt::Literals::StringLiterals;
|
|
|
|
|
2016-08-06 20:42:40 +02:00
|
|
|
QT_WARNING_PUSH
|
|
|
|
QT_WARNING_DISABLE_CLANG("-Wmissing-prototypes")
|
|
|
|
QT_WARNING_DISABLE_INTEL(1418)
|
2015-10-19 15:21:06 +02:00
|
|
|
|
2022-08-03 13:41:19 +02:00
|
|
|
Q_LOGGING_CATEGORY(mApp, "m.application") // NOLINT
|
2015-09-19 22:08:03 +02:00
|
|
|
|
2016-08-06 20:42:40 +02:00
|
|
|
QT_WARNING_POP
|
2015-10-19 15:21:06 +02:00
|
|
|
|
2022-08-03 13:41:19 +02:00
|
|
|
namespace
|
|
|
|
{
|
2023-06-21 09:24:51 +02:00
|
|
|
QT_WARNING_PUSH
|
|
|
|
QT_WARNING_DISABLE_CLANG("-Wunused-member-function")
|
|
|
|
|
2023-10-07 17:56:39 +02:00
|
|
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, LONG_OPTION_DIMENSION_A, ("dimensionA"_L1)) // NOLINT
|
|
|
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, SINGLE_OPTION_DIMENSION_A, ('a'_L1)) // NOLINT
|
2022-08-03 13:41:19 +02:00
|
|
|
|
2023-10-07 17:56:39 +02:00
|
|
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, LONG_OPTION_DIMENSION_B, ("dimensionB"_L1)) // NOLINT
|
|
|
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, SINGLE_OPTION_DIMENSION_B, ('b'_L1)) // NOLINT
|
2022-08-03 13:41:19 +02:00
|
|
|
|
2023-10-07 17:56:39 +02:00
|
|
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, LONG_OPTION_DIMENSION_C, ("dimensionC"_L1)) // NOLINT
|
|
|
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, SINGLE_OPTION_DIMENSION_C, ('c'_L1)) // NOLINT
|
2022-08-03 13:41:19 +02:00
|
|
|
|
2023-10-07 17:56:39 +02:00
|
|
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, LONG_OPTION_UNITS, ("units"_L1)) // NOLINT
|
|
|
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, SINGLE_OPTION_UNITS, ('u'_L1)) // NOLINT
|
2022-08-03 13:41:19 +02:00
|
|
|
|
2023-11-07 10:20:31 +01:00
|
|
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, LONG_OPTION_KNOWN, ("known"_L1)) // NOLINT
|
|
|
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, SINGLE_OPTION_KNOWN, ('k'_L1)) // NOLINT
|
|
|
|
|
2023-10-07 17:56:39 +02:00
|
|
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, LONG_OPTION_TEST, ("test"_L1)) // NOLINT
|
2023-06-21 09:24:51 +02:00
|
|
|
|
|
|
|
QT_WARNING_POP
|
2023-06-08 12:20:20 +02:00
|
|
|
} // namespace
|
2022-08-03 13:41:19 +02:00
|
|
|
|
2015-09-15 20:21:51 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
|
|
|
|
{
|
2018-09-28 20:05:42 +02:00
|
|
|
// only the GUI thread should display message boxes. If you are
|
|
|
|
// writing a multithreaded application and the error happens on
|
|
|
|
// a non-GUI thread, you'll have to queue the message to the GUI
|
|
|
|
QCoreApplication *instance = QCoreApplication::instance();
|
|
|
|
const bool isGuiThread = instance && (QThread::currentThread() == instance->thread());
|
|
|
|
|
|
|
|
if (not isGuiThread)
|
|
|
|
{
|
|
|
|
auto Handler = [](QtMsgType type, const QMessageLogContext &context, const QString &msg)
|
2023-06-08 12:20:20 +02:00
|
|
|
{ noisyFailureMsgHandler(type, context, msg); };
|
2018-09-28 20:05:42 +02:00
|
|
|
|
|
|
|
q_dispatch_async_main(Handler, type, context, msg);
|
|
|
|
return;
|
|
|
|
}
|
2015-09-15 20:21:51 +02:00
|
|
|
|
|
|
|
// Why on earth didn't Qt want to make failed signal/slot connections qWarning?
|
2016-07-20 10:25:53 +02:00
|
|
|
if ((type == QtDebugMsg) && msg.contains(QStringLiteral("::connect")))
|
2015-09-15 20:21:51 +02:00
|
|
|
{
|
|
|
|
type = QtWarningMsg;
|
|
|
|
}
|
|
|
|
|
2016-08-03 13:54:18 +02:00
|
|
|
#if defined(V_NO_ASSERT)
|
2016-05-24 12:06:51 +02:00
|
|
|
// I have decided to hide this annoing message for release builds.
|
2016-08-03 13:54:18 +02:00
|
|
|
if ((type == QtWarningMsg) && msg.contains(QStringLiteral("QSslSocket: cannot resolve")))
|
|
|
|
{
|
|
|
|
type = QtDebugMsg;
|
|
|
|
}
|
|
|
|
|
2016-07-20 10:25:53 +02:00
|
|
|
if ((type == QtWarningMsg) && msg.contains(QStringLiteral("setGeometry: Unable to set geometry")))
|
2016-05-24 12:06:51 +02:00
|
|
|
{
|
|
|
|
type = QtDebugMsg;
|
|
|
|
}
|
2023-06-08 12:20:20 +02:00
|
|
|
#endif // defined(V_NO_ASSERT)
|
2016-05-24 12:06:51 +02:00
|
|
|
|
2015-11-18 13:54:53 +01:00
|
|
|
#if defined(Q_OS_MAC)
|
2023-08-12 11:03:28 +02:00
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(5, 7, 0)
|
2023-06-08 12:20:20 +02:00
|
|
|
// Try hide very annoying, Qt related, warnings in Mac OS X
|
|
|
|
// QNSView mouseDragged: Internal mouse button tracking invalid (missing Qt::LeftButton)
|
|
|
|
// https://bugreports.qt.io/browse/QTBUG-42846
|
|
|
|
if ((type == QtWarningMsg) && msg.contains(QStringLiteral("QNSView")))
|
|
|
|
{
|
|
|
|
type = QtDebugMsg;
|
|
|
|
}
|
|
|
|
#endif
|
2016-05-04 15:40:15 +02:00
|
|
|
|
2023-06-08 12:20:20 +02:00
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(5, 9, 0)
|
2016-05-04 15:40:15 +02:00
|
|
|
// Hide Qt bug 'Assertion when reading an icns file'
|
|
|
|
// https://bugreports.qt.io/browse/QTBUG-45537
|
2015-11-18 13:54:53 +01:00
|
|
|
// Remove after Qt fix will be released
|
2016-07-20 10:25:53 +02:00
|
|
|
if ((type == QtWarningMsg) && msg.contains(QStringLiteral("QICNSHandler::read()")))
|
2015-11-18 13:54:53 +01:00
|
|
|
{
|
|
|
|
type = QtDebugMsg;
|
2016-09-20 20:12:19 +02:00
|
|
|
}
|
2023-06-08 12:20:20 +02:00
|
|
|
#endif
|
2021-06-04 07:49:09 +02:00
|
|
|
|
|
|
|
// Hide anything that starts with QMacCGContext
|
|
|
|
if ((type == QtWarningMsg) && msg.contains(QStringLiteral("QMacCGContext::")))
|
|
|
|
{
|
|
|
|
type = QtDebugMsg;
|
|
|
|
}
|
2016-09-20 20:12:19 +02:00
|
|
|
|
|
|
|
// See issue #568
|
2016-09-20 20:33:33 +02:00
|
|
|
if (msg.contains(QStringLiteral("Error receiving trust for a CA certificate")))
|
2016-09-20 20:12:19 +02:00
|
|
|
{
|
|
|
|
type = QtDebugMsg;
|
2015-11-18 13:54:53 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-09-15 20:21:51 +02:00
|
|
|
// this is another one that doesn't make sense as just a debug message. pretty serious
|
|
|
|
// sign of a problem
|
|
|
|
// http://www.developer.nokia.com/Community/Wiki/QPainter::begin:Paint_device_returned_engine_%3D%3D_0_(Known_Issue)
|
2023-06-08 12:20:20 +02:00
|
|
|
if ((type == QtDebugMsg) && msg.contains(QStringLiteral("QPainter::begin")) &&
|
|
|
|
msg.contains(QStringLiteral("Paint device returned engine")))
|
2015-09-15 20:21:51 +02:00
|
|
|
{
|
|
|
|
type = QtWarningMsg;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This qWarning about "Cowardly refusing to send clipboard message to hung application..."
|
|
|
|
// is something that can easily happen if you are debugging and the application is paused.
|
|
|
|
// As it is so common, not worth popping up a dialog.
|
2023-06-08 12:20:20 +02:00
|
|
|
if ((type == QtWarningMsg) && msg.contains(QStringLiteral("QClipboard::event")) &&
|
|
|
|
msg.contains(QStringLiteral("Cowardly refusing")))
|
2015-09-15 20:21:51 +02:00
|
|
|
{
|
|
|
|
type = QtDebugMsg;
|
|
|
|
}
|
|
|
|
|
2023-06-22 17:30:43 +02:00
|
|
|
// Annoying warning that we can ignore
|
|
|
|
if ((type == QtWarningMsg) && (msg.contains(QStringLiteral("OpenType support missing for")) ||
|
|
|
|
msg.contains(QStringLiteral("DirectWrite: CreateFontFaceFromHDC() failed (Indicates "
|
|
|
|
"an error in an input file such as a font file.)"))))
|
|
|
|
{
|
|
|
|
type = QtDebugMsg;
|
|
|
|
}
|
|
|
|
|
2020-11-20 12:18:38 +01:00
|
|
|
QString logMsg = msg;
|
2021-02-06 14:52:21 +01:00
|
|
|
const bool isWarningMessage = VAbstractApplication::VApp()->IsWarningMessage(msg);
|
2020-11-20 12:18:38 +01:00
|
|
|
if (isWarningMessage)
|
|
|
|
{
|
|
|
|
logMsg = logMsg.remove(VAbstractApplication::warningMessageSignature);
|
|
|
|
}
|
|
|
|
|
2015-09-28 20:54:41 +02:00
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case QtDebugMsg:
|
2020-11-20 12:18:38 +01:00
|
|
|
vStdOut() << QApplication::translate("mNoisyHandler", "DEBUG:") << logMsg << "\n";
|
2015-09-28 20:54:41 +02:00
|
|
|
return;
|
|
|
|
case QtWarningMsg:
|
2020-11-20 12:18:38 +01:00
|
|
|
vStdErr() << QApplication::translate("mNoisyHandler", "WARNING:") << logMsg << "\n";
|
2015-10-01 16:59:01 +02:00
|
|
|
break;
|
2015-09-28 20:54:41 +02:00
|
|
|
case QtCriticalMsg:
|
2020-11-20 12:18:38 +01:00
|
|
|
vStdErr() << QApplication::translate("mNoisyHandler", "CRITICAL:") << logMsg << "\n";
|
2015-10-01 16:59:01 +02:00
|
|
|
break;
|
2015-09-28 20:54:41 +02:00
|
|
|
case QtFatalMsg:
|
2020-11-20 12:18:38 +01:00
|
|
|
vStdErr() << QApplication::translate("mNoisyHandler", "FATAL:") << logMsg << "\n";
|
2015-09-28 20:54:41 +02:00
|
|
|
break;
|
2015-10-01 16:59:01 +02:00
|
|
|
case QtInfoMsg:
|
2020-11-20 12:18:38 +01:00
|
|
|
vStdOut() << QApplication::translate("mNoisyHandler", "INFO:") << logMsg << "\n";
|
2015-10-01 16:59:01 +02:00
|
|
|
break;
|
2015-09-28 20:54:41 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-06-21 13:16:17 +02:00
|
|
|
vStdOut().flush();
|
|
|
|
vStdErr().flush();
|
|
|
|
|
2015-09-15 20:21:51 +02:00
|
|
|
if (isGuiThread)
|
|
|
|
{
|
2023-06-08 12:20:20 +02:00
|
|
|
// fixme: trying to make sure there are no save/load dialogs are opened, because error message during them will
|
|
|
|
// lead to crash
|
2017-03-23 09:25:46 +01:00
|
|
|
const bool topWinAllowsPop = (QApplication::activeModalWidget() == nullptr) ||
|
2023-06-08 12:20:20 +02:00
|
|
|
!QApplication::activeModalWidget()->inherits("QFileDialog");
|
2015-09-15 20:21:51 +02:00
|
|
|
QMessageBox messageBox;
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case QtWarningMsg:
|
2016-08-03 13:54:18 +02:00
|
|
|
messageBox.setWindowTitle(QApplication::translate("mNoisyHandler", "Warning"));
|
2015-09-15 20:21:51 +02:00
|
|
|
messageBox.setIcon(QMessageBox::Warning);
|
|
|
|
break;
|
|
|
|
case QtCriticalMsg:
|
2016-08-03 13:54:18 +02:00
|
|
|
messageBox.setWindowTitle(QApplication::translate("mNoisyHandler", "Critical error"));
|
2015-09-15 20:21:51 +02:00
|
|
|
messageBox.setIcon(QMessageBox::Critical);
|
|
|
|
break;
|
|
|
|
case QtFatalMsg:
|
2016-08-03 13:54:18 +02:00
|
|
|
messageBox.setWindowTitle(QApplication::translate("mNoisyHandler", "Fatal error"));
|
2015-09-15 20:21:51 +02:00
|
|
|
messageBox.setIcon(QMessageBox::Critical);
|
|
|
|
break;
|
2015-10-01 16:59:01 +02:00
|
|
|
case QtInfoMsg:
|
2016-08-03 13:54:18 +02:00
|
|
|
messageBox.setWindowTitle(QApplication::translate("mNoisyHandler", "Information"));
|
2015-10-01 16:59:01 +02:00
|
|
|
messageBox.setIcon(QMessageBox::Information);
|
|
|
|
break;
|
2015-09-28 20:54:41 +02:00
|
|
|
case QtDebugMsg:
|
2015-10-28 15:22:36 +01:00
|
|
|
Q_UNREACHABLE(); //-V501
|
2017-02-22 18:34:29 +01:00
|
|
|
break;
|
2015-09-15 20:21:51 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == QtWarningMsg || type == QtCriticalMsg || type == QtFatalMsg)
|
|
|
|
{
|
2021-02-06 14:52:21 +01:00
|
|
|
if (not MApplication::VApp()->IsTestMode())
|
2015-09-28 12:42:26 +02:00
|
|
|
{
|
|
|
|
if (topWinAllowsPop)
|
|
|
|
{
|
2020-11-20 12:18:38 +01:00
|
|
|
messageBox.setText(VAbstractApplication::ClearMessage(logMsg));
|
2015-09-28 12:42:26 +02:00
|
|
|
messageBox.setStandardButtons(QMessageBox::Ok);
|
|
|
|
messageBox.setWindowModality(Qt::ApplicationModal);
|
|
|
|
messageBox.setModal(true);
|
2023-06-08 12:20:20 +02:00
|
|
|
#ifndef QT_NO_CURSOR
|
2017-07-09 08:02:26 +02:00
|
|
|
QGuiApplication::setOverrideCursor(Qt::ArrowCursor);
|
2023-06-08 12:20:20 +02:00
|
|
|
#endif
|
2015-09-28 12:42:26 +02:00
|
|
|
messageBox.exec();
|
2023-06-08 12:20:20 +02:00
|
|
|
#ifndef QT_NO_CURSOR
|
2017-07-09 08:02:26 +02:00
|
|
|
QGuiApplication::restoreOverrideCursor();
|
2023-06-08 12:20:20 +02:00
|
|
|
#endif
|
2015-09-28 12:42:26 +02:00
|
|
|
}
|
|
|
|
}
|
2015-09-15 20:21:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (QtFatalMsg == type)
|
|
|
|
{
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (type != QtDebugMsg)
|
|
|
|
{
|
|
|
|
abort(); // be NOISY unless overridden!
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-10 13:14:55 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
MApplication::MApplication(int &argc, char **argv)
|
2023-11-07 10:20:31 +01:00
|
|
|
: VAbstractApplication(argc, argv),
|
|
|
|
m_knownMeasurementsRepopulateWatcher(new QFutureWatcher<void>(this))
|
2022-08-03 13:41:19 +02:00
|
|
|
{
|
|
|
|
setApplicationDisplayName(QStringLiteral(VER_PRODUCTNAME_STR));
|
|
|
|
setApplicationName(QStringLiteral(VER_INTERNALNAME_STR));
|
|
|
|
setOrganizationName(QStringLiteral(VER_COMPANYNAME_STR));
|
|
|
|
setOrganizationDomain(QStringLiteral(VER_COMPANYDOMAIN_STR));
|
2015-07-10 13:14:55 +02:00
|
|
|
// Setting the Application version
|
2023-07-25 13:01:41 +02:00
|
|
|
setApplicationVersion(AppVersionStr());
|
2016-01-15 17:02:14 +01:00
|
|
|
// We have been running Tape in two different cases.
|
|
|
|
// The first inside own bundle where info.plist is works fine, but the second,
|
|
|
|
// when we run inside Valentina's bundle, require direct setting the icon.
|
2015-07-12 16:19:53 +02:00
|
|
|
setWindowIcon(QIcon(":/tapeicon/64x64/logo.png"));
|
2023-07-24 12:41:42 +02:00
|
|
|
VTheme::Instance()->StoreDefaultThemeName(QIcon::themeName());
|
2015-07-10 13:14:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
MApplication::~MApplication()
|
|
|
|
{
|
2023-11-09 16:46:34 +01:00
|
|
|
if (MApplication::IsAppInGUIMode() && settings->IsCollectStatistic())
|
2023-06-27 13:15:21 +02:00
|
|
|
{
|
|
|
|
auto *statistic = VGAnalytics::Instance();
|
|
|
|
|
|
|
|
QString clientID = settings->GetClientID();
|
|
|
|
if (!clientID.isEmpty())
|
|
|
|
{
|
|
|
|
statistic->SendAppCloseEvent(m_uptimeTimer.elapsed());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-03 13:41:19 +02:00
|
|
|
qDeleteAll(m_mainWindows);
|
2023-11-07 10:20:31 +01:00
|
|
|
qDeleteAll(m_kmMainWindows);
|
2015-08-02 17:27:18 +02:00
|
|
|
|
2022-08-03 13:41:19 +02:00
|
|
|
delete m_trVars;
|
|
|
|
if (not m_dataBase.isNull())
|
2015-08-02 17:27:18 +02:00
|
|
|
{
|
2022-08-03 13:41:19 +02:00
|
|
|
delete m_dataBase;
|
2015-08-02 17:27:18 +02:00
|
|
|
}
|
2015-07-10 13:14:55 +02:00
|
|
|
}
|
|
|
|
|
2015-09-19 22:08:03 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief notify Reimplemented from QApplication::notify().
|
|
|
|
* @param receiver receiver.
|
|
|
|
* @param event event.
|
|
|
|
* @return value that is returned from the receiver's event handler.
|
|
|
|
*/
|
|
|
|
// reimplemented from QApplication so we can throw exceptions in slots
|
2022-08-03 13:41:19 +02:00
|
|
|
auto MApplication::notify(QObject *receiver, QEvent *event) -> bool
|
2015-09-19 22:08:03 +02:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
return QApplication::notify(receiver, event);
|
|
|
|
}
|
|
|
|
catch (const VExceptionObjectError &e)
|
|
|
|
{
|
2023-06-08 12:20:20 +02:00
|
|
|
qCCritical(mApp, "%s\n\n%s\n\n%s",
|
|
|
|
qUtf8Printable(tr("Error parsing file. Program will be terminated.")), //-V807
|
2015-10-01 16:59:01 +02:00
|
|
|
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
|
2015-10-11 11:06:14 +02:00
|
|
|
exit(V_EX_DATAERR);
|
2015-09-19 22:08:03 +02:00
|
|
|
}
|
|
|
|
catch (const VExceptionBadId &e)
|
|
|
|
{
|
2015-10-01 16:59:01 +02:00
|
|
|
qCCritical(mApp, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Error bad id. Program will be terminated.")),
|
|
|
|
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
|
2015-10-11 11:06:14 +02:00
|
|
|
exit(V_EX_DATAERR);
|
2015-09-19 22:08:03 +02:00
|
|
|
}
|
|
|
|
catch (const VExceptionConversionError &e)
|
|
|
|
{
|
2015-10-01 16:59:01 +02:00
|
|
|
qCCritical(mApp, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Error can't convert value. Program will be terminated.")),
|
|
|
|
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
|
2015-10-11 11:06:14 +02:00
|
|
|
exit(V_EX_DATAERR);
|
2015-09-19 22:08:03 +02:00
|
|
|
}
|
|
|
|
catch (const VExceptionEmptyParameter &e)
|
|
|
|
{
|
2015-10-01 16:59:01 +02:00
|
|
|
qCCritical(mApp, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Error empty parameter. Program will be terminated.")),
|
|
|
|
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
|
2015-10-11 11:06:14 +02:00
|
|
|
exit(V_EX_DATAERR);
|
2015-09-19 22:08:03 +02:00
|
|
|
}
|
|
|
|
catch (const VExceptionWrongId &e)
|
|
|
|
{
|
2015-10-01 16:59:01 +02:00
|
|
|
qCCritical(mApp, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Error wrong id. Program will be terminated.")),
|
|
|
|
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
|
2015-10-11 11:06:14 +02:00
|
|
|
exit(V_EX_DATAERR);
|
2015-09-19 22:08:03 +02:00
|
|
|
}
|
2015-11-02 17:25:29 +01:00
|
|
|
catch (const VExceptionToolWasDeleted &e)
|
|
|
|
{
|
|
|
|
qCCritical(mApp, "%s\n\n%s\n\n%s",
|
2022-08-12 17:50:13 +02:00
|
|
|
qUtf8Printable(QStringLiteral("Unhadled deleting tool. Continue use object after deleting!")),
|
2015-11-02 17:25:29 +01:00
|
|
|
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
|
|
|
|
exit(V_EX_DATAERR);
|
|
|
|
}
|
2015-09-19 22:08:03 +02:00
|
|
|
catch (const VException &e)
|
|
|
|
{
|
2023-06-08 12:20:20 +02:00
|
|
|
qCCritical(mApp, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Something's wrong!!")), qUtf8Printable(e.ErrorMessage()),
|
|
|
|
qUtf8Printable(e.DetailedInformation()));
|
2015-09-19 22:08:03 +02:00
|
|
|
return true;
|
|
|
|
}
|
2020-11-20 12:18:38 +01:00
|
|
|
catch (const qmu::QmuParserWarning &e)
|
|
|
|
{
|
|
|
|
qCCritical(mApp, "%s", qUtf8Printable(tr("Formula warning: %1. Program will be terminated.").arg(e.GetMsg())));
|
|
|
|
exit(V_EX_DATAERR);
|
|
|
|
}
|
2015-09-19 22:08:03 +02:00
|
|
|
// These last two cases special. I found that we can't show here modal dialog with error message.
|
|
|
|
// Somehow program doesn't waite untile an error dialog will be closed. But if ignore this program will hang.
|
|
|
|
catch (const qmu::QmuParserError &e)
|
|
|
|
{
|
2015-10-01 16:59:01 +02:00
|
|
|
qCCritical(mApp, "%s", qUtf8Printable(tr("Parser error: %1. Program will be terminated.").arg(e.GetMsg())));
|
2015-10-11 11:06:14 +02:00
|
|
|
exit(V_EX_DATAERR);
|
2015-09-19 22:08:03 +02:00
|
|
|
}
|
2015-10-01 16:59:01 +02:00
|
|
|
catch (std::exception &e)
|
2015-09-19 22:08:03 +02:00
|
|
|
{
|
2015-10-01 16:59:01 +02:00
|
|
|
qCCritical(mApp, "%s", qUtf8Printable(tr("Exception thrown: %1. Program will be terminated.").arg(e.what())));
|
2015-10-11 11:06:14 +02:00
|
|
|
exit(V_EX_SOFTWARE);
|
2015-09-19 22:08:03 +02:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-09-28 12:42:26 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-08-03 13:41:19 +02:00
|
|
|
auto MApplication::IsTestMode() const -> bool
|
2015-09-28 12:42:26 +02:00
|
|
|
{
|
2022-08-03 13:41:19 +02:00
|
|
|
return m_testMode;
|
2015-09-28 12:42:26 +02:00
|
|
|
}
|
|
|
|
|
2015-07-10 13:14:55 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-12-22 19:12:09 +01:00
|
|
|
/**
|
|
|
|
* @brief IsAppInGUIMode little hack that allow to have access to application state from VAbstractApplication class.
|
|
|
|
*/
|
2022-08-03 13:41:19 +02:00
|
|
|
auto MApplication::IsAppInGUIMode() const -> bool
|
2015-12-22 19:12:09 +01:00
|
|
|
{
|
2021-05-21 17:08:37 +02:00
|
|
|
return not IsTestMode();
|
2015-12-22 19:12:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-11-07 10:20:31 +01:00
|
|
|
auto MApplication::MainTapeWindow() -> TMainWindow *
|
2015-07-10 13:14:55 +02:00
|
|
|
{
|
2023-11-07 10:20:31 +01:00
|
|
|
CleanTapeWindows();
|
2022-08-03 13:41:19 +02:00
|
|
|
if (m_mainWindows.isEmpty())
|
2015-07-10 13:14:55 +02:00
|
|
|
{
|
2023-11-07 10:20:31 +01:00
|
|
|
NewMainTapeWindow();
|
2015-07-10 13:14:55 +02:00
|
|
|
}
|
2023-11-07 10:20:31 +01:00
|
|
|
return m_mainWindows.first();
|
2015-07-10 13:14:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-11-07 10:20:31 +01:00
|
|
|
auto MApplication::MainTapeWindows() -> QList<TMainWindow *>
|
2015-07-10 13:14:55 +02:00
|
|
|
{
|
2023-11-07 10:20:31 +01:00
|
|
|
CleanTapeWindows();
|
2023-06-08 12:20:20 +02:00
|
|
|
QList<TMainWindow *> list;
|
2022-08-03 13:41:19 +02:00
|
|
|
list.reserve(m_mainWindows.size());
|
|
|
|
for (auto &w : m_mainWindows)
|
2015-07-10 13:14:55 +02:00
|
|
|
{
|
2018-04-03 13:36:38 +02:00
|
|
|
list.append(w);
|
2015-07-10 13:14:55 +02:00
|
|
|
}
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2015-07-15 09:16:59 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void MApplication::InitOptions()
|
|
|
|
{
|
2015-09-15 20:21:51 +02:00
|
|
|
qInstallMessageHandler(noisyFailureMsgHandler);
|
|
|
|
|
2015-07-15 09:16:59 +02:00
|
|
|
OpenSettings();
|
|
|
|
|
2023-07-25 13:01:41 +02:00
|
|
|
qCDebug(mApp, "Version: %s", qUtf8Printable(AppVersionStr()));
|
2015-10-03 16:16:28 +02:00
|
|
|
qCDebug(mApp, "Build revision: %s", BUILD_REVISION);
|
|
|
|
qCDebug(mApp, "%s", qUtf8Printable(buildCompatibilityString()));
|
|
|
|
qCDebug(mApp, "Built on %s at %s", __DATE__, __TIME__);
|
2022-08-03 13:41:19 +02:00
|
|
|
qCDebug(mApp, "Command-line arguments: %s", qUtf8Printable(arguments().join(QStringLiteral(", "))));
|
2017-03-23 09:25:46 +01:00
|
|
|
qCDebug(mApp, "Process ID: %s", qUtf8Printable(QString().setNum(applicationPid())));
|
2015-07-15 09:16:59 +02:00
|
|
|
|
2023-06-08 12:20:20 +02:00
|
|
|
LoadTranslation(QString()); // By default the console version uses system locale
|
2015-08-02 17:27:18 +02:00
|
|
|
|
2022-09-15 14:02:44 +02:00
|
|
|
CheckSystemLocale();
|
|
|
|
|
2023-10-04 16:02:18 +02:00
|
|
|
QTimer::singleShot(0, this,
|
|
|
|
[]()
|
|
|
|
{
|
|
|
|
QString country = VGAnalytics::CountryCode();
|
2023-10-07 17:56:39 +02:00
|
|
|
if (country == "ru"_L1 || country == "by"_L1)
|
2023-10-04 16:02:18 +02:00
|
|
|
{
|
2023-10-31 18:55:29 +01:00
|
|
|
qFatal("country not detected");
|
2023-10-04 16:02:18 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-08-09 14:46:02 +02:00
|
|
|
VTheme::InitApplicationStyle();
|
2023-07-24 12:41:42 +02:00
|
|
|
VTheme::SetIconTheme();
|
|
|
|
VTheme::InitThemeMode();
|
|
|
|
|
2023-06-27 13:15:21 +02:00
|
|
|
auto *statistic = VGAnalytics::Instance();
|
|
|
|
QString clientID = settings->GetClientID();
|
|
|
|
if (clientID.isEmpty())
|
|
|
|
{
|
|
|
|
clientID = QUuid::createUuid().toString();
|
|
|
|
settings->SetClientID(clientID);
|
|
|
|
}
|
|
|
|
statistic->SetClientID(clientID);
|
|
|
|
statistic->SetGUILanguage(settings->GetLocale());
|
|
|
|
statistic->SetMeasurementId(GA_MEASUREMENT_ID);
|
|
|
|
statistic->SetApiSecret(GA_API_SECRET);
|
2023-06-29 16:54:54 +02:00
|
|
|
statistic->SetRepoRevision(QLatin1String(BUILD_REVISION));
|
2023-06-27 13:15:21 +02:00
|
|
|
statistic->Enable(settings->IsCollectStatistic());
|
2023-10-23 15:57:22 +02:00
|
|
|
|
|
|
|
m_shortcutManager = new VTapeShortcutManager(this);
|
2015-08-02 17:27:18 +02:00
|
|
|
}
|
2018-10-29 13:05:49 +01:00
|
|
|
|
2015-07-15 09:16:59 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void MApplication::InitTrVars()
|
|
|
|
{
|
2022-08-03 13:41:19 +02:00
|
|
|
if (m_trVars != nullptr)
|
2015-08-02 17:27:18 +02:00
|
|
|
{
|
2022-08-03 13:41:19 +02:00
|
|
|
m_trVars->Retranslate();
|
2015-08-08 16:33:37 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-08-03 13:41:19 +02:00
|
|
|
m_trVars = new VTranslateVars();
|
2015-08-02 17:27:18 +02:00
|
|
|
}
|
2015-07-15 09:16:59 +02:00
|
|
|
}
|
|
|
|
|
2015-11-19 16:17:25 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-08-03 13:41:19 +02:00
|
|
|
auto MApplication::event(QEvent *e) -> bool
|
2015-11-19 16:17:25 +01:00
|
|
|
{
|
2023-06-08 12:20:20 +02:00
|
|
|
switch (e->type())
|
2015-11-19 16:17:25 +01:00
|
|
|
{
|
|
|
|
// In Mac OS X the QFileOpenEvent event is generated when user perform "Open With" from Finder (this event is
|
|
|
|
// Mac specific).
|
|
|
|
case QEvent::FileOpen:
|
|
|
|
{
|
2023-11-09 16:46:34 +01:00
|
|
|
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-static-cast-downcast)
|
|
|
|
auto *fileOpenEvent = static_cast<QFileOpenEvent *>(e);
|
2016-12-21 17:00:56 +01:00
|
|
|
const QString macFileOpen = fileOpenEvent->file();
|
2023-06-08 12:20:20 +02:00
|
|
|
if (not macFileOpen.isEmpty())
|
2015-11-19 16:17:25 +01:00
|
|
|
{
|
2023-11-09 16:46:34 +01:00
|
|
|
if (macFileOpen.endsWith(".vkm"_L1))
|
|
|
|
{
|
|
|
|
TKMMainWindow *mw = MainKMWindow();
|
|
|
|
if (mw)
|
|
|
|
{
|
2023-11-09 16:59:21 +01:00
|
|
|
m_knownMeasurementsMode = true;
|
2023-11-09 16:46:34 +01:00
|
|
|
mw->LoadFile(macFileOpen); // open file in existing window
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2015-11-19 16:17:25 +01:00
|
|
|
{
|
2023-11-09 16:46:34 +01:00
|
|
|
TMainWindow *mw = MainTapeWindow();
|
|
|
|
if (mw)
|
|
|
|
{
|
|
|
|
mw->LoadFile(macFileOpen); // open file in existing window
|
|
|
|
}
|
2015-11-19 16:17:25 +01:00
|
|
|
}
|
2016-12-21 17:00:56 +01:00
|
|
|
return true;
|
2015-11-19 16:17:25 +01:00
|
|
|
}
|
2015-11-30 11:55:39 +01:00
|
|
|
break;
|
2015-11-19 16:17:25 +01:00
|
|
|
}
|
|
|
|
#if defined(Q_OS_MAC)
|
2023-11-09 16:59:21 +01:00
|
|
|
case QEvent::ApplicationStateChange:
|
|
|
|
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-static-cast-downcast)
|
|
|
|
if (static_cast<QApplicationStateChangeEvent *>(e)->applicationState() == Qt::ApplicationActive)
|
2023-11-09 16:46:34 +01:00
|
|
|
{
|
2023-11-09 16:59:21 +01:00
|
|
|
if (m_knownMeasurementsMode)
|
2023-11-09 16:46:34 +01:00
|
|
|
{
|
2023-11-09 16:59:21 +01:00
|
|
|
CleanKMWindows();
|
|
|
|
TKMMainWindow *mw = MainKMWindow();
|
|
|
|
if (mw && not mw->isMinimized())
|
|
|
|
{
|
|
|
|
mw->show();
|
|
|
|
}
|
2023-11-09 16:46:34 +01:00
|
|
|
}
|
2023-11-09 16:59:21 +01:00
|
|
|
else
|
2023-11-09 16:46:34 +01:00
|
|
|
{
|
2023-11-09 16:59:21 +01:00
|
|
|
CleanTapeWindows();
|
|
|
|
TMainWindow *mw = MainTapeWindow();
|
|
|
|
if (mw && not mw->isMinimized())
|
|
|
|
{
|
|
|
|
mw->show();
|
|
|
|
}
|
2023-11-09 16:46:34 +01:00
|
|
|
}
|
2023-11-09 16:59:21 +01:00
|
|
|
return true;
|
2015-11-19 16:17:25 +01:00
|
|
|
}
|
2023-11-09 17:41:59 +01:00
|
|
|
break;
|
2023-06-08 12:20:20 +02:00
|
|
|
#endif // defined(Q_OS_MAC)
|
2015-11-19 16:17:25 +01:00
|
|
|
default:
|
|
|
|
return VAbstractApplication::event(e);
|
|
|
|
}
|
|
|
|
return VAbstractApplication::event(e);
|
|
|
|
}
|
|
|
|
|
2019-07-01 11:47:06 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void MApplication::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.
|
|
|
|
// Connect this slot with VApplication::aboutToQuit.
|
|
|
|
Settings()->sync();
|
|
|
|
}
|
|
|
|
|
2015-07-15 09:16:59 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void MApplication::OpenSettings()
|
|
|
|
{
|
2017-04-14 16:43:26 +02:00
|
|
|
settings = new VTapeSettings(QSettings::IniFormat, QSettings::UserScope, QCoreApplication::organizationName(),
|
|
|
|
QCoreApplication::applicationName(), this);
|
2023-06-22 17:30:43 +02:00
|
|
|
connect(settings, &VTapeSettings::SVGFontsPathChanged, this, &MApplication::SVGFontsPathChanged);
|
2023-10-28 08:55:21 +02:00
|
|
|
connect(settings, &VTapeSettings::KnownMeasurementsPathChanged, this, &MApplication::KnownMeasurementsPathChanged);
|
2015-07-15 09:16:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-08-03 13:41:19 +02:00
|
|
|
auto MApplication::TapeSettings() -> VTapeSettings *
|
2015-07-15 09:16:59 +02:00
|
|
|
{
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(settings != nullptr)
|
2015-07-24 14:06:53 +02:00
|
|
|
return qobject_cast<VTapeSettings *>(settings);
|
2015-07-15 09:16:59 +02:00
|
|
|
}
|
|
|
|
|
2015-08-20 12:56:55 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-10-03 16:16:28 +02:00
|
|
|
void MApplication::ParseCommandLine(const SocketConnection &connection, const QStringList &arguments)
|
2015-08-20 12:56:55 +02:00
|
|
|
{
|
|
|
|
QCommandLineParser parser;
|
2015-10-03 19:27:27 +02:00
|
|
|
parser.setApplicationDescription(tr("Valentina's measurements editor."));
|
2015-08-20 12:56:55 +02:00
|
|
|
parser.addHelpOption();
|
|
|
|
parser.addVersionOption();
|
|
|
|
|
2022-08-03 13:41:19 +02:00
|
|
|
InitParserOptions(parser);
|
2020-10-03 06:33:56 +02:00
|
|
|
|
|
|
|
parser.process(arguments);
|
|
|
|
|
2022-08-03 13:41:19 +02:00
|
|
|
m_testMode = parser.isSet(*LONG_OPTION_TEST);
|
2023-11-07 10:20:31 +01:00
|
|
|
m_knownMeasurementsMode = parser.isSet(*LONG_OPTION_KNOWN);
|
2015-09-28 12:42:26 +02:00
|
|
|
|
2022-08-03 13:41:19 +02:00
|
|
|
if (not m_testMode && connection == SocketConnection::Client)
|
2015-09-28 17:34:29 +02:00
|
|
|
{
|
2015-10-03 16:16:28 +02:00
|
|
|
const QString serverName = QCoreApplication::applicationName();
|
|
|
|
QLocalSocket socket;
|
|
|
|
socket.connectToServer(serverName);
|
|
|
|
if (socket.waitForConnected(1000))
|
|
|
|
{
|
|
|
|
qCDebug(mApp, "Connected to the server '%s'", qUtf8Printable(serverName));
|
|
|
|
QTextStream stream(&socket);
|
2023-10-31 18:55:29 +01:00
|
|
|
stream << QCoreApplication::arguments().join(";;"_L1);
|
2015-10-03 16:16:28 +02:00
|
|
|
stream.flush();
|
|
|
|
socket.waitForBytesWritten();
|
2022-08-03 13:41:19 +02:00
|
|
|
QCoreApplication::exit(V_EX_OK);
|
2015-10-11 11:06:14 +02:00
|
|
|
return;
|
2015-10-03 16:16:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
qCDebug(mApp, "Can't establish connection to the server '%s'", qUtf8Printable(serverName));
|
2022-08-03 13:41:19 +02:00
|
|
|
StartLocalServer(serverName);
|
2015-09-28 17:34:29 +02:00
|
|
|
LoadTranslation(TapeSettings()->GetLocale());
|
|
|
|
}
|
|
|
|
|
2015-08-20 12:56:55 +02:00
|
|
|
const QStringList args = parser.positionalArguments();
|
2022-08-08 15:14:46 +02:00
|
|
|
bool success = args.count() > 0 ? StartWithFiles(parser) : SingleStart(parser);
|
|
|
|
|
|
|
|
if (not success)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2015-08-20 12:56:55 +02:00
|
|
|
|
2022-08-03 13:41:19 +02:00
|
|
|
if (m_testMode)
|
2015-08-20 12:56:55 +02:00
|
|
|
{
|
2022-08-03 13:41:19 +02:00
|
|
|
QCoreApplication::exit(V_EX_OK); // close program after processing in console mode
|
2015-10-11 11:06:14 +02:00
|
|
|
}
|
2015-08-20 12:56:55 +02:00
|
|
|
}
|
|
|
|
|
2021-02-06 14:52:21 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
auto MApplication::VApp() -> MApplication *
|
|
|
|
{
|
2023-06-08 12:20:20 +02:00
|
|
|
return qobject_cast<MApplication *>(QCoreApplication::instance());
|
2021-02-06 14:52:21 +01:00
|
|
|
}
|
|
|
|
|
2023-10-28 08:55:21 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
auto MApplication::KnownMeasurementsDatabase() -> VKnownMeasurementsDatabase *
|
|
|
|
{
|
|
|
|
if (m_knownMeasurementsDatabase == nullptr)
|
|
|
|
{
|
|
|
|
m_knownMeasurementsDatabase = new VKnownMeasurementsDatabase();
|
|
|
|
|
|
|
|
RestartKnownMeasurementsDatabaseWatcher();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!m_knownMeasurementsDatabase->IsPopulated())
|
|
|
|
{
|
|
|
|
m_knownMeasurementsDatabase->PopulateMeasurementsDatabase();
|
|
|
|
}
|
|
|
|
|
|
|
|
return m_knownMeasurementsDatabase;
|
|
|
|
}
|
|
|
|
|
2023-11-07 10:20:31 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void MApplication::Preferences(QWidget *parent)
|
|
|
|
{
|
|
|
|
// Calling constructor of the dialog take some time. Because of this user have time to call the dialog twice.
|
|
|
|
static QPointer<DialogTapePreferences> guard; // Prevent any second run
|
|
|
|
if (guard.isNull())
|
|
|
|
{
|
|
|
|
QGuiApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
|
|
|
|
auto *preferences = new DialogTapePreferences(parent);
|
|
|
|
// QScopedPointer needs to be sure any exception will never block guard
|
|
|
|
QScopedPointer<DialogTapePreferences> dlg(preferences);
|
|
|
|
guard = preferences;
|
|
|
|
// Must be first
|
|
|
|
|
2023-11-09 16:46:34 +01:00
|
|
|
for (const auto &w : qAsConst(m_mainWindows))
|
2023-11-07 10:20:31 +01:00
|
|
|
{
|
|
|
|
if (!w.isNull())
|
|
|
|
{
|
|
|
|
connect(dlg.data(), &DialogTapePreferences::UpdateProperties, w, &TMainWindow::WindowsLocale,
|
|
|
|
Qt::QueuedConnection);
|
|
|
|
connect(dlg.data(), &DialogTapePreferences::UpdateProperties, w, &TMainWindow::ToolBarStyles,
|
|
|
|
Qt::QueuedConnection);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-09 16:46:34 +01:00
|
|
|
for (const auto &w : qAsConst(m_kmMainWindows))
|
2023-11-07 10:20:31 +01:00
|
|
|
{
|
|
|
|
if (!w.isNull())
|
|
|
|
{
|
|
|
|
connect(dlg.data(), &DialogTapePreferences::UpdateProperties, w, &TKMMainWindow::WindowsLocale,
|
|
|
|
Qt::QueuedConnection);
|
|
|
|
connect(dlg.data(), &DialogTapePreferences::UpdateProperties, w, &TKMMainWindow::ToolBarStyles,
|
|
|
|
Qt::QueuedConnection);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QGuiApplication::restoreOverrideCursor();
|
|
|
|
dlg->exec();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
guard->raise();
|
|
|
|
guard->activateWindow();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-28 08:55:21 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void MApplication::RestartKnownMeasurementsDatabaseWatcher()
|
|
|
|
{
|
|
|
|
if (m_knownMeasurementsDatabase != nullptr)
|
|
|
|
{
|
|
|
|
delete m_knownMeasurementsDatabaseWatcher;
|
|
|
|
m_knownMeasurementsDatabaseWatcher = new QFileSystemWatcher({settings->GetPathKnownMeasurements()}, this);
|
|
|
|
connect(m_knownMeasurementsDatabaseWatcher, &QFileSystemWatcher::directoryChanged, this,
|
|
|
|
&MApplication::RepopulateMeasurementsDatabase);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-10 13:14:55 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-11-07 10:20:31 +01:00
|
|
|
auto MApplication::NewMainTapeWindow() -> TMainWindow *
|
2015-07-10 13:14:55 +02:00
|
|
|
{
|
2022-08-03 13:41:19 +02:00
|
|
|
auto *tape = new TMainWindow();
|
|
|
|
m_mainWindows.prepend(tape);
|
2021-02-06 14:52:21 +01:00
|
|
|
if (not MApplication::VApp()->IsTestMode())
|
2015-09-28 12:42:26 +02:00
|
|
|
{
|
|
|
|
tape->show();
|
2021-05-21 19:51:46 +02:00
|
|
|
tape->UpdateWindowTitle();
|
2015-09-28 12:42:26 +02:00
|
|
|
}
|
2015-07-10 13:14:55 +02:00
|
|
|
return tape;
|
|
|
|
}
|
|
|
|
|
2023-11-07 10:20:31 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
auto MApplication::MainKMWindow() -> TKMMainWindow *
|
|
|
|
{
|
|
|
|
CleanKMWindows();
|
|
|
|
if (m_kmMainWindows.isEmpty())
|
|
|
|
{
|
|
|
|
NewMainKMWindow();
|
|
|
|
}
|
|
|
|
return m_kmMainWindows.first();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
auto MApplication::MainKMWindows() -> QList<TKMMainWindow *>
|
|
|
|
{
|
|
|
|
CleanKMWindows();
|
|
|
|
QList<TKMMainWindow *> list;
|
|
|
|
list.reserve(m_kmMainWindows.size());
|
|
|
|
for (auto &w : m_kmMainWindows)
|
|
|
|
{
|
|
|
|
list.append(w);
|
|
|
|
}
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
auto MApplication::NewMainKMWindow() -> TKMMainWindow *
|
|
|
|
{
|
|
|
|
auto *known = new TKMMainWindow();
|
|
|
|
m_kmMainWindows.prepend(known);
|
|
|
|
if (not MApplication::VApp()->IsTestMode())
|
|
|
|
{
|
|
|
|
known->show();
|
|
|
|
known->UpdateWindowTitle();
|
|
|
|
}
|
|
|
|
return known;
|
|
|
|
}
|
|
|
|
|
2015-10-11 11:06:14 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void MApplication::ProcessCMD()
|
|
|
|
{
|
|
|
|
ParseCommandLine(SocketConnection::Client, arguments());
|
2021-11-18 13:55:15 +01:00
|
|
|
|
|
|
|
if (IsAppInGUIMode() && Settings()->IsAutomaticallyCheckUpdates())
|
|
|
|
{
|
|
|
|
// Set feed URL before doing anything else
|
|
|
|
FvUpdater::sharedUpdater()->SetFeedURL(FvUpdater::CurrentFeedURL());
|
|
|
|
|
|
|
|
// Check for updates automatically
|
|
|
|
FvUpdater::sharedUpdater()->CheckForUpdatesSilent();
|
|
|
|
}
|
2015-10-11 11:06:14 +02:00
|
|
|
}
|
|
|
|
|
2015-07-10 13:14:55 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void MApplication::NewLocalSocketConnection()
|
|
|
|
{
|
2022-08-03 13:41:19 +02:00
|
|
|
QLocalSocket *socket = m_localServer->nextPendingConnection();
|
2015-07-10 13:14:55 +02:00
|
|
|
if (not socket)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
socket->waitForReadyRead(1000);
|
|
|
|
QTextStream stream(socket);
|
2015-08-20 12:56:55 +02:00
|
|
|
const QString arg = stream.readAll();
|
|
|
|
if (not arg.isEmpty())
|
2015-07-10 13:14:55 +02:00
|
|
|
{
|
2022-08-03 13:41:19 +02:00
|
|
|
ParseCommandLine(SocketConnection::Server, arg.split(QStringLiteral(";;")));
|
2015-07-10 13:14:55 +02:00
|
|
|
}
|
|
|
|
delete socket;
|
2023-11-07 10:20:31 +01:00
|
|
|
MainTapeWindow()->raise();
|
|
|
|
MainTapeWindow()->activateWindow();
|
2015-07-10 13:14:55 +02:00
|
|
|
}
|
|
|
|
|
2023-10-28 08:55:21 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void MApplication::RepopulateMeasurementsDatabase(const QString &path)
|
|
|
|
{
|
|
|
|
Q_UNUSED(path)
|
|
|
|
if (m_knownMeasurementsDatabase != nullptr)
|
|
|
|
{
|
2023-11-07 10:20:31 +01:00
|
|
|
m_knownMeasurementsRepopulateWatcher->setFuture(
|
|
|
|
QtConcurrent::run([this]() { m_knownMeasurementsDatabase->PopulateMeasurementsDatabase(); }));
|
|
|
|
QObject::connect(m_knownMeasurementsRepopulateWatcher, &QFutureWatcher<void>::finished, this,
|
|
|
|
&MApplication::SyncKnownMeasurements);
|
2023-10-28 08:55:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void MApplication::KnownMeasurementsPathChanged(const QString &oldPath, const QString &newPath)
|
|
|
|
{
|
|
|
|
if (oldPath != newPath)
|
|
|
|
{
|
|
|
|
if (m_knownMeasurementsDatabase != nullptr)
|
|
|
|
{
|
|
|
|
RestartKnownMeasurementsDatabaseWatcher();
|
|
|
|
RepopulateMeasurementsDatabase(newPath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-10 13:14:55 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-11-07 10:20:31 +01:00
|
|
|
void MApplication::SyncKnownMeasurements()
|
|
|
|
{
|
2023-11-09 16:46:34 +01:00
|
|
|
for (const auto &w : qAsConst(m_mainWindows))
|
2023-11-07 10:20:31 +01:00
|
|
|
{
|
|
|
|
if (!w.isNull())
|
|
|
|
{
|
|
|
|
w->SyncKnownMeasurements();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void MApplication::CleanTapeWindows()
|
2015-07-10 13:14:55 +02:00
|
|
|
{
|
|
|
|
// cleanup any deleted main windows first
|
2023-02-09 16:23:11 +01:00
|
|
|
for (vsizetype i = m_mainWindows.count() - 1; i >= 0; --i)
|
2022-08-03 13:41:19 +02:00
|
|
|
{
|
|
|
|
if (m_mainWindows.at(i).isNull())
|
|
|
|
{
|
|
|
|
m_mainWindows.removeAt(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-07 10:20:31 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void MApplication::CleanKMWindows()
|
|
|
|
{
|
|
|
|
// cleanup any deleted main windows first
|
|
|
|
for (vsizetype i = m_kmMainWindows.count() - 1; i >= 0; --i)
|
|
|
|
{
|
|
|
|
if (m_kmMainWindows.at(i).isNull())
|
|
|
|
{
|
|
|
|
m_kmMainWindows.removeAt(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-03 13:41:19 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void MApplication::InitParserOptions(QCommandLineParser &parser)
|
|
|
|
{
|
|
|
|
parser.addPositionalArgument(QStringLiteral("filename"), tr("The measurement file."));
|
|
|
|
|
2023-06-08 12:20:20 +02:00
|
|
|
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")},
|
2022-08-03 13:41:19 +02:00
|
|
|
|
2023-06-08 12:20:20 +02:00
|
|
|
{{*SINGLE_OPTION_DIMENSION_B, *LONG_OPTION_DIMENSION_B},
|
|
|
|
tr("Set base for dimension B in the table units."),
|
|
|
|
tr("The dimension B base")},
|
2022-08-03 13:41:19 +02:00
|
|
|
|
2023-06-08 12:20:20 +02:00
|
|
|
{{*SINGLE_OPTION_DIMENSION_C, *LONG_OPTION_DIMENSION_C},
|
|
|
|
tr("Set base for dimension C in the table units."),
|
|
|
|
tr("The dimension C base")},
|
2022-08-03 13:41:19 +02:00
|
|
|
|
2023-06-08 12:20:20 +02:00
|
|
|
{{*SINGLE_OPTION_UNITS, *LONG_OPTION_UNITS},
|
|
|
|
tr("Set pattern file units: cm, mm, inch."),
|
|
|
|
tr("The pattern units")},
|
2022-08-03 13:41:19 +02:00
|
|
|
|
2023-11-07 10:20:31 +01:00
|
|
|
{{*SINGLE_OPTION_KNOWN, *LONG_OPTION_KNOWN}, tr("Activate known measurements mode.")},
|
|
|
|
|
2022-08-03 13:41:19 +02:00
|
|
|
{*LONG_OPTION_TEST,
|
2023-06-08 12:20:20 +02:00
|
|
|
tr("Use for unit testing. Run the program and open a file without showing the main window.")},
|
2022-08-03 13:41:19 +02:00
|
|
|
|
|
|
|
{LONG_OPTION_NO_HDPI_SCALING,
|
2023-06-08 12:20:20 +02:00
|
|
|
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")},
|
|
|
|
});
|
2022-08-03 13:41:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
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))
|
|
|
|
{
|
2023-06-08 12:20:20 +02:00
|
|
|
qCDebug(mApp, "Can't begin to listen for incoming connections on name '%s'", qUtf8Printable(serverName));
|
2022-08-03 13:41:19 +02:00
|
|
|
if (m_localServer->serverError() == QAbstractSocket::AddressInUseError)
|
|
|
|
{
|
|
|
|
QLocalServer::removeServer(serverName);
|
|
|
|
if (not m_localServer->listen(serverName))
|
|
|
|
{
|
2023-06-08 12:20:20 +02:00
|
|
|
qCWarning(
|
|
|
|
mApp, "%s",
|
|
|
|
qUtf8Printable(tr("Can't begin to listen for incoming connections on name '%1'").arg(serverName)));
|
2022-08-03 13:41:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-08-08 15:14:46 +02:00
|
|
|
auto MApplication::StartWithFiles(QCommandLineParser &parser) -> bool
|
2022-08-03 13:41:19 +02:00
|
|
|
{
|
|
|
|
const QStringList args = parser.positionalArguments();
|
|
|
|
if (args.count() <= 0)
|
|
|
|
{
|
2022-08-08 15:14:46 +02:00
|
|
|
QCoreApplication::exit(V_EX_DATAERR);
|
|
|
|
return false;
|
2022-08-03 13:41:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2023-11-07 10:20:31 +01:00
|
|
|
if (!m_knownMeasurementsMode)
|
|
|
|
{
|
|
|
|
return StartWithMeasurementFiles(parser);
|
|
|
|
}
|
|
|
|
|
|
|
|
return StartWithKnownMeasurementFiles(parser);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
auto MApplication::StartWithMeasurementFiles(QCommandLineParser &parser) -> bool
|
|
|
|
{
|
|
|
|
const QStringList args = parser.positionalArguments();
|
|
|
|
|
2022-08-03 13:41:19 +02:00
|
|
|
bool flagDimensionA = false;
|
|
|
|
bool flagDimensionB = false;
|
|
|
|
bool flagDimensionC = false;
|
|
|
|
bool flagUnits = false;
|
|
|
|
|
2023-10-06 07:56:10 +02:00
|
|
|
qreal dimensionAValue = 0;
|
|
|
|
qreal dimensionBValue = 0;
|
|
|
|
qreal dimensionCValue = 0;
|
2022-08-03 13:41:19 +02:00
|
|
|
Unit unit = Unit::Cm;
|
|
|
|
|
|
|
|
ParseDimensionAOption(parser, dimensionAValue, flagDimensionA);
|
|
|
|
ParseDimensionBOption(parser, dimensionBValue, flagDimensionB);
|
|
|
|
ParseDimensionCOption(parser, dimensionCValue, flagDimensionC);
|
|
|
|
ParseUnitsOption(parser, unit, flagUnits);
|
|
|
|
|
2023-11-07 10:20:31 +01:00
|
|
|
return std::all_of(args.begin(), args.end(),
|
|
|
|
[&](const auto &arg)
|
|
|
|
{
|
|
|
|
NewMainTapeWindow();
|
|
|
|
if (not MainTapeWindow()->LoadFile(arg))
|
|
|
|
{
|
|
|
|
delete MainTapeWindow();
|
|
|
|
return !m_testMode;
|
|
|
|
}
|
2022-08-03 13:41:19 +02:00
|
|
|
|
2023-11-07 10:20:31 +01:00
|
|
|
if (flagDimensionA)
|
|
|
|
{
|
|
|
|
MainTapeWindow()->SetDimensionABase(dimensionAValue);
|
|
|
|
}
|
2022-08-03 13:41:19 +02:00
|
|
|
|
2023-11-07 10:20:31 +01:00
|
|
|
if (flagDimensionB)
|
|
|
|
{
|
|
|
|
MainTapeWindow()->SetDimensionBBase(dimensionBValue);
|
|
|
|
}
|
2022-08-03 13:41:19 +02:00
|
|
|
|
2023-11-07 10:20:31 +01:00
|
|
|
if (flagDimensionC)
|
|
|
|
{
|
|
|
|
MainTapeWindow()->SetDimensionCBase(dimensionCValue);
|
|
|
|
}
|
2022-08-03 13:41:19 +02:00
|
|
|
|
2023-11-07 10:20:31 +01:00
|
|
|
if (flagUnits)
|
|
|
|
{
|
|
|
|
MainTapeWindow()->SetPUnit(unit);
|
|
|
|
}
|
2022-08-08 15:14:46 +02:00
|
|
|
|
2023-11-07 10:20:31 +01:00
|
|
|
return true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
auto MApplication::StartWithKnownMeasurementFiles(QCommandLineParser &parser) -> bool
|
|
|
|
{
|
|
|
|
const QStringList args = parser.positionalArguments();
|
|
|
|
|
|
|
|
return std::all_of(args.begin(), args.end(),
|
|
|
|
[&](const auto &arg)
|
|
|
|
{
|
|
|
|
NewMainKMWindow();
|
|
|
|
if (not MainKMWindow()->LoadFile(arg))
|
|
|
|
{
|
|
|
|
delete MainKMWindow();
|
|
|
|
return !m_testMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
});
|
2022-08-03 13:41:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-08-08 15:14:46 +02:00
|
|
|
auto MApplication::SingleStart(QCommandLineParser &parser) -> bool
|
2022-08-03 13:41:19 +02:00
|
|
|
{
|
|
|
|
if (not m_testMode)
|
2015-07-10 13:14:55 +02:00
|
|
|
{
|
2023-11-07 10:20:31 +01:00
|
|
|
if (!m_knownMeasurementsMode)
|
|
|
|
{
|
|
|
|
NewMainTapeWindow();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NewMainKMWindow();
|
|
|
|
}
|
2022-08-03 13:41:19 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qCCritical(mApp, "%s\n", qPrintable(tr("Please, provide one input file.")));
|
|
|
|
parser.showHelp(V_EX_USAGE);
|
2022-08-08 15:14:46 +02:00
|
|
|
return false;
|
2022-08-03 13:41:19 +02:00
|
|
|
}
|
2022-08-08 15:14:46 +02:00
|
|
|
|
|
|
|
return true;
|
2022-08-03 13:41:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-10-06 07:56:10 +02:00
|
|
|
void MApplication::ParseDimensionAOption(QCommandLineParser &parser, qreal &dimensionAValue, bool &flagDimensionA)
|
2022-08-03 13:41:19 +02:00
|
|
|
{
|
|
|
|
if (parser.isSet(*LONG_OPTION_DIMENSION_A))
|
|
|
|
{
|
|
|
|
const QString value = parser.value(*LONG_OPTION_DIMENSION_A);
|
|
|
|
|
|
|
|
bool ok = false;
|
2023-10-06 07:56:10 +02:00
|
|
|
dimensionAValue = value.toDouble(&ok);
|
2023-06-08 12:20:20 +02:00
|
|
|
if (ok && dimensionAValue > 0)
|
2022-08-03 13:41:19 +02:00
|
|
|
{
|
|
|
|
flagDimensionA = true;
|
|
|
|
}
|
|
|
|
else
|
2015-07-10 13:14:55 +02:00
|
|
|
{
|
2022-08-03 13:41:19 +02:00
|
|
|
qCCritical(mApp, "%s\n", qPrintable(tr("Invalid dimension A base value.")));
|
|
|
|
parser.showHelp(V_EX_USAGE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-10-06 07:56:10 +02:00
|
|
|
void MApplication::ParseDimensionBOption(QCommandLineParser &parser, qreal &dimensionBValue, bool &flagDimensionB)
|
2022-08-03 13:41:19 +02:00
|
|
|
{
|
|
|
|
if (parser.isSet(*LONG_OPTION_DIMENSION_B))
|
|
|
|
{
|
|
|
|
const QString value = parser.value(*LONG_OPTION_DIMENSION_B);
|
|
|
|
|
|
|
|
bool ok = false;
|
2023-10-06 07:56:10 +02:00
|
|
|
dimensionBValue = value.toDouble(&ok);
|
2023-06-08 12:20:20 +02:00
|
|
|
if (ok && dimensionBValue > 0)
|
2022-08-03 13:41:19 +02:00
|
|
|
{
|
|
|
|
flagDimensionB = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qCCritical(mApp, "%s\n", qPrintable(tr("Invalid dimension B base value.")));
|
|
|
|
parser.showHelp(V_EX_USAGE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-10-06 07:56:10 +02:00
|
|
|
void MApplication::ParseDimensionCOption(QCommandLineParser &parser, qreal &dimensionCValue, bool &flagDimensionC)
|
2022-08-03 13:41:19 +02:00
|
|
|
{
|
|
|
|
if (parser.isSet(*LONG_OPTION_DIMENSION_C))
|
|
|
|
{
|
|
|
|
const QString value = parser.value(*LONG_OPTION_DIMENSION_C);
|
|
|
|
|
|
|
|
bool ok = false;
|
2023-10-06 07:56:10 +02:00
|
|
|
dimensionCValue = value.toDouble(&ok);
|
2023-06-08 12:20:20 +02:00
|
|
|
if (ok && dimensionCValue > 0)
|
2022-08-03 13:41:19 +02:00
|
|
|
{
|
|
|
|
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);
|
2015-07-10 13:14:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|