2015-07-15 09:16:59 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file vcommonsettings.cpp
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 15 7, 2015
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
|
|
|
** This source code is part of the Valentine project, a pattern making
|
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
|
|
|
** Copyright (C) 2015 Valentina project
|
|
|
|
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
|
|
|
|
**
|
|
|
|
** 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 "vcommonsettings.h"
|
|
|
|
|
|
|
|
#include <QApplication>
|
2016-07-15 11:30:55 +02:00
|
|
|
#include <QDate>
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QDir>
|
|
|
|
#include <QLocale>
|
|
|
|
#include <QMessageLogger>
|
|
|
|
#include <QStaticStringData>
|
|
|
|
#include <QStringData>
|
|
|
|
#include <QStringDataPtr>
|
|
|
|
#include <QVariant>
|
|
|
|
#include <QtDebug>
|
2017-05-12 14:09:19 +02:00
|
|
|
#include <QTextCodec>
|
2016-08-08 13:44:49 +02:00
|
|
|
|
2016-08-09 15:55:46 +02:00
|
|
|
#include "../vmisc/def.h"
|
2016-08-16 18:57:32 +02:00
|
|
|
#include "../vmisc/vmath.h"
|
2015-07-15 09:16:59 +02:00
|
|
|
|
2017-04-11 10:16:11 +02:00
|
|
|
const QString settingPathsIndividualMeasurements = QStringLiteral("paths/individual_measurements");
|
|
|
|
const QString settingPathsStandardMeasurements = QStringLiteral("paths/standard_measurements");
|
|
|
|
const QString settingPathsTemplates = QStringLiteral("paths/templates");
|
|
|
|
|
2017-04-12 08:49:05 +02:00
|
|
|
const QString settingConfigurationOsSeparator = QStringLiteral("configuration/osSeparator");
|
|
|
|
const QString settingConfigurationAutosaveState = QStringLiteral("configuration/autosave/state");
|
|
|
|
const QString settingConfigurationAutosaveTime = QStringLiteral("configuration/autosave/time");
|
|
|
|
const QString settingConfigurationSendReportState = QStringLiteral("configuration/send_report/state");
|
|
|
|
const QString settingConfigurationLocale = QStringLiteral("configuration/locale");
|
|
|
|
const QString settingPMSystemCode = QStringLiteral("configuration/pmscode");
|
|
|
|
const QString settingConfigurationUnit = QStringLiteral("configuration/unit");
|
|
|
|
const QString settingConfigurationConfirmItemDeletion = QStringLiteral("configuration/confirm_item_deletion");
|
|
|
|
const QString settingConfigurationConfirmFormatRewriting = QStringLiteral("configuration/confirm_format_rewriting");
|
|
|
|
const QString settingConfigurationToolBarStyle = QStringLiteral("configuration/tool_bar_style");
|
2017-04-11 10:16:11 +02:00
|
|
|
|
|
|
|
const QString settingPatternUser = QStringLiteral("pattern/user");
|
|
|
|
const QString settingPatternUndo = QStringLiteral("pattern/undo");
|
|
|
|
const QString settingPatternForbidFlipping = QStringLiteral("pattern/forbidFlipping");
|
|
|
|
const QString settingDoublePassmark = QStringLiteral("pattern/doublePassmark");
|
|
|
|
|
|
|
|
const QString settingGeneralRecentFileList = QStringLiteral("recentFileList");
|
|
|
|
const QString settingGeneralRestoreFileList = QStringLiteral("restoreFileList");
|
|
|
|
const QString settingGeneralGeometry = QStringLiteral("geometry");
|
|
|
|
const QString settingGeneralWindowState = QStringLiteral("windowState");
|
|
|
|
const QString settingGeneralToolbarsState = QStringLiteral("toolbarsState");
|
|
|
|
const QString settingPreferenceDialogSize = QStringLiteral("preferenceDialogSize");
|
|
|
|
const QString settingLatestSkippedVersion = QStringLiteral("lastestSkippedVersion");
|
|
|
|
const QString settingDateOfLastRemind = QStringLiteral("dateOfLastRemind");
|
|
|
|
const QString settingUserDefinedMaterials = QStringLiteral("configuration/userDefinedMaterials");
|
2015-07-15 09:16:59 +02:00
|
|
|
|
2017-05-12 14:09:19 +02:00
|
|
|
const QString settingCSVWithHeader = QStringLiteral("csv/withHeader");
|
|
|
|
const QString settingCSVCodec = QStringLiteral("csv/withCodec");
|
|
|
|
const QString settingCSVSeparator = QStringLiteral("csv/withSeparator");
|
|
|
|
|
2016-06-10 16:48:30 +02:00
|
|
|
static const QString commonIniFilename = QStringLiteral("common");
|
|
|
|
|
2017-02-17 19:54:16 +01:00
|
|
|
#if !defined(Q_OS_WIN)
|
|
|
|
const QString VCommonSettings::unixStandardSharePath = QStringLiteral("/usr/share/valentina");
|
|
|
|
#endif
|
|
|
|
|
2017-02-17 19:37:49 +01:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool SymlinkCopyDirRecursive(const QString &fromDir, const QString &toDir, bool replaceOnConflit)
|
|
|
|
{
|
|
|
|
QDir dir;
|
|
|
|
dir.setPath(fromDir);
|
|
|
|
|
|
|
|
foreach (QString copyFile, dir.entryList(QDir::Files))
|
|
|
|
{
|
|
|
|
const QString from = fromDir + QDir::separator() + copyFile;
|
|
|
|
const QString to = toDir + QDir::separator() + copyFile;
|
|
|
|
|
|
|
|
if (QFile::exists(to))
|
|
|
|
{
|
|
|
|
if (replaceOnConflit)
|
|
|
|
{
|
|
|
|
if (QFile::remove(to) == false)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (QFile::link(from, to) == false)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (QString copyDir, dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot))
|
|
|
|
{
|
|
|
|
const QString from = fromDir + QDir::separator() + copyDir;
|
|
|
|
const QString to = toDir + QDir::separator() + copyDir;
|
|
|
|
|
|
|
|
if (dir.mkpath(to) == false)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SymlinkCopyDirRecursive(from, to, replaceOnConflit) == false)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2016-10-30 13:34:55 +01:00
|
|
|
|
2015-07-15 09:16:59 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-10-18 11:56:47 +02:00
|
|
|
VCommonSettings::VCommonSettings(Format format, Scope scope, const QString &organization,
|
|
|
|
const QString &application, QObject *parent)
|
2015-10-18 13:51:14 +02:00
|
|
|
:QSettings(format, scope, organization, application, parent)
|
2015-07-15 09:16:59 +02:00
|
|
|
{}
|
|
|
|
|
2015-11-18 13:42:25 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-10-30 13:34:55 +01:00
|
|
|
QString VCommonSettings::SharePath(const QString &shareItem)
|
2015-11-18 13:42:25 +01:00
|
|
|
{
|
|
|
|
#ifdef Q_OS_WIN
|
2016-10-30 13:34:55 +01:00
|
|
|
return QApplication::applicationDirPath() + shareItem;
|
2015-11-18 13:42:25 +01:00
|
|
|
#elif defined(Q_OS_MAC)
|
2016-10-30 13:34:55 +01:00
|
|
|
QDir dirBundle(QApplication::applicationDirPath() + QStringLiteral("/../Resources") + shareItem);
|
2015-11-18 13:42:25 +01:00
|
|
|
if (dirBundle.exists())
|
|
|
|
{
|
|
|
|
return dirBundle.absolutePath();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-10-25 16:54:51 +02:00
|
|
|
QDir appDir = QDir(qApp->applicationDirPath());
|
|
|
|
appDir.cdUp();
|
|
|
|
appDir.cdUp();
|
|
|
|
appDir.cdUp();
|
2016-10-30 13:34:55 +01:00
|
|
|
QDir dir(appDir.absolutePath() + shareItem);
|
2015-11-18 13:42:25 +01:00
|
|
|
if (dir.exists())
|
|
|
|
{
|
|
|
|
return dir.absolutePath();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-02-04 12:28:47 +01:00
|
|
|
return VCommonSettings::unixStandardSharePath + shareItem;
|
2015-11-18 13:42:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#else // Unix
|
2016-10-30 13:34:55 +01:00
|
|
|
#ifdef QT_DEBUG
|
|
|
|
return QApplication::applicationDirPath() + shareItem;
|
|
|
|
#else
|
|
|
|
QDir dir(QApplication::applicationDirPath() + shareItem);
|
|
|
|
if (dir.exists())
|
|
|
|
{
|
|
|
|
return dir.absolutePath();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-02-04 12:28:47 +01:00
|
|
|
return VCommonSettings::unixStandardSharePath + shareItem;
|
2016-10-30 13:34:55 +01:00
|
|
|
}
|
|
|
|
#endif
|
2015-11-18 13:42:25 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-10-30 13:34:55 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString VCommonSettings::StandardTablesPath()
|
|
|
|
{
|
|
|
|
return SharePath(QStringLiteral("/tables/standard"));
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-02-17 19:37:49 +01:00
|
|
|
QString VCommonSettings::StandardTemplatesPath()
|
2016-10-30 13:34:55 +01:00
|
|
|
{
|
|
|
|
return SharePath(QStringLiteral("/tables/templates"));
|
|
|
|
}
|
|
|
|
|
2017-02-17 19:37:49 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VCommonSettings::PrepareStandardTemplates(const QString & currentPath)
|
|
|
|
{
|
|
|
|
QDir standardPath(VCommonSettings::StandardTemplatesPath());
|
|
|
|
const QDir localdata (VCommonSettings::GetDefPathTemplate());
|
|
|
|
if (currentPath == VCommonSettings::GetDefPathTemplate() && standardPath.exists() && not localdata.exists())
|
|
|
|
{
|
|
|
|
if (localdata.mkpath("."))
|
|
|
|
{
|
|
|
|
SymlinkCopyDirRecursive(VCommonSettings::StandardTemplatesPath(), VCommonSettings::GetDefPathTemplate(),
|
|
|
|
false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VCommonSettings::PrepareStandardTables(const QString ¤tPath)
|
|
|
|
{
|
|
|
|
QDir standardPath(VCommonSettings::StandardTablesPath());
|
|
|
|
const QDir localdata (VCommonSettings::GetDefPathStandardMeasurements());
|
|
|
|
if (currentPath == VCommonSettings::GetDefPathStandardMeasurements()
|
|
|
|
&& standardPath.exists()
|
|
|
|
&& not localdata.exists())
|
|
|
|
{
|
|
|
|
if (localdata.mkpath("."))
|
|
|
|
{
|
|
|
|
SymlinkCopyDirRecursive(VCommonSettings::StandardTablesPath(),
|
|
|
|
VCommonSettings::GetDefPathStandardMeasurements(), false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString VCommonSettings::GetDefPathIndividualMeasurements()
|
|
|
|
{
|
|
|
|
return QDir::homePath() + QLatin1String("/valentina/") + tr("measurements") + QLatin1String("/") + tr("individual");
|
|
|
|
}
|
|
|
|
|
2015-07-18 14:39:33 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString VCommonSettings::GetPathIndividualMeasurements() const
|
|
|
|
{
|
2016-06-10 16:48:30 +02:00
|
|
|
QSettings settings(this->format(), this->scope(), this->organizationName(), commonIniFilename);
|
2017-04-11 10:16:11 +02:00
|
|
|
return settings.value(settingPathsIndividualMeasurements, GetDefPathIndividualMeasurements()).toString();
|
2015-07-18 14:39:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VCommonSettings::SetPathIndividualMeasurements(const QString &value)
|
|
|
|
{
|
2016-06-10 16:48:30 +02:00
|
|
|
QSettings settings(this->format(), this->scope(), this->organizationName(), commonIniFilename);
|
2017-04-11 10:16:11 +02:00
|
|
|
settings.setValue(settingPathsIndividualMeasurements, value);
|
2015-10-18 14:38:05 +02:00
|
|
|
settings.sync();
|
2015-07-18 14:39:33 +02:00
|
|
|
}
|
|
|
|
|
2017-02-17 19:37:49 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString VCommonSettings::GetDefPathStandardMeasurements()
|
|
|
|
{
|
|
|
|
return QDir::homePath() + QLatin1String("/valentina/") + tr("measurements") + QLatin1String("/") + tr("multisize");
|
|
|
|
}
|
|
|
|
|
2015-07-18 14:39:33 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString VCommonSettings::GetPathStandardMeasurements() const
|
|
|
|
{
|
2016-06-10 16:48:30 +02:00
|
|
|
QSettings settings(this->format(), this->scope(), this->organizationName(), commonIniFilename);
|
2017-04-11 10:16:11 +02:00
|
|
|
return settings.value(settingPathsStandardMeasurements, GetDefPathStandardMeasurements()).toString();
|
2015-07-18 14:39:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VCommonSettings::SetPathStandardMeasurements(const QString &value)
|
|
|
|
{
|
2016-06-10 16:48:30 +02:00
|
|
|
QSettings settings(this->format(), this->scope(), this->organizationName(), commonIniFilename);
|
2017-04-11 10:16:11 +02:00
|
|
|
settings.setValue(settingPathsStandardMeasurements, value);
|
2015-10-18 14:38:05 +02:00
|
|
|
settings.sync();
|
2015-07-18 14:39:33 +02:00
|
|
|
}
|
|
|
|
|
2017-02-17 19:37:49 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString VCommonSettings::GetDefPathTemplate()
|
|
|
|
{
|
|
|
|
return QDir::homePath() + QLatin1String("/valentina/") + tr("templates");
|
|
|
|
}
|
2015-10-18 12:01:38 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString VCommonSettings::GetPathTemplate() const
|
|
|
|
{
|
2016-06-10 16:48:30 +02:00
|
|
|
QSettings settings(this->format(), this->scope(), this->organizationName(), commonIniFilename);
|
2017-04-11 10:16:11 +02:00
|
|
|
return settings.value(settingPathsTemplates, GetDefPathTemplate()).toString();
|
2015-10-18 12:01:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VCommonSettings::SetPathTemplate(const QString &value)
|
|
|
|
{
|
2016-06-10 16:48:30 +02:00
|
|
|
QSettings settings(this->format(), this->scope(), this->organizationName(), commonIniFilename);
|
2017-04-11 10:16:11 +02:00
|
|
|
settings.setValue(settingPathsTemplates, value);
|
2015-10-18 14:38:05 +02:00
|
|
|
settings.sync();
|
2015-10-18 12:01:38 +02:00
|
|
|
}
|
|
|
|
|
2015-07-15 09:16:59 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool VCommonSettings::GetOsSeparator() const
|
|
|
|
{
|
2017-04-11 10:16:11 +02:00
|
|
|
return value(settingConfigurationOsSeparator, 1).toBool();
|
2015-07-15 09:16:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VCommonSettings::SetOsSeparator(const bool &value)
|
|
|
|
{
|
2017-04-11 10:16:11 +02:00
|
|
|
setValue(settingConfigurationOsSeparator, value);
|
2015-07-15 09:16:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool VCommonSettings::GetAutosaveState() const
|
|
|
|
{
|
2017-04-11 10:16:11 +02:00
|
|
|
return value(settingConfigurationAutosaveState, 1).toBool();
|
2015-07-15 09:16:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VCommonSettings::SetAutosaveState(const bool &value)
|
|
|
|
{
|
2017-04-11 10:16:11 +02:00
|
|
|
setValue(settingConfigurationAutosaveState, value);
|
2015-07-15 09:16:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
int VCommonSettings::GetAutosaveTime() const
|
|
|
|
{
|
|
|
|
bool ok = false;
|
2017-04-11 10:16:11 +02:00
|
|
|
int val = value(settingConfigurationAutosaveTime, 1).toInt(&ok);
|
2015-07-15 09:16:59 +02:00
|
|
|
if (ok == false)
|
|
|
|
{
|
2017-04-11 10:16:11 +02:00
|
|
|
qDebug()<<"Could not convert value"<<value(settingConfigurationAutosaveTime, 1)
|
2015-07-15 09:16:59 +02:00
|
|
|
<<"to int. Return default value for autosave time"<<1<<"minutes.";
|
|
|
|
val = 1;
|
|
|
|
}
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VCommonSettings::SetAutosaveTime(const int &value)
|
|
|
|
{
|
2017-04-11 10:16:11 +02:00
|
|
|
setValue(settingConfigurationAutosaveTime, value);
|
2015-07-15 09:16:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool VCommonSettings::GetSendReportState() const
|
|
|
|
{
|
2017-04-11 10:16:11 +02:00
|
|
|
return value(settingConfigurationSendReportState, 1).toBool();
|
2015-07-15 09:16:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VCommonSettings::SetSendReportState(const bool &value)
|
|
|
|
{
|
2017-04-11 10:16:11 +02:00
|
|
|
setValue(settingConfigurationSendReportState, value);
|
2015-07-15 09:16:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString VCommonSettings::GetLocale() const
|
|
|
|
{
|
2017-04-11 10:16:11 +02:00
|
|
|
return value(settingConfigurationLocale, QLocale().name()).toString();
|
2015-07-15 09:16:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VCommonSettings::SetLocale(const QString &value)
|
|
|
|
{
|
2017-04-11 10:16:11 +02:00
|
|
|
setValue(settingConfigurationLocale, value);
|
2015-07-15 09:16:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-08-02 17:27:18 +02:00
|
|
|
QString VCommonSettings::GetPMSystemCode() const
|
|
|
|
{
|
2017-04-11 10:16:11 +02:00
|
|
|
return value(settingPMSystemCode, p0_S).toString();
|
2015-08-02 17:27:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VCommonSettings::SetPMSystemCode(const QString &value)
|
|
|
|
{
|
2017-04-11 10:16:11 +02:00
|
|
|
setValue(settingPMSystemCode, value);
|
2015-08-02 17:27:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-07-15 09:16:59 +02:00
|
|
|
QString VCommonSettings::GetUnit() const
|
|
|
|
{
|
2017-04-11 10:16:11 +02:00
|
|
|
return value(settingConfigurationUnit, "cm").toString();
|
2015-07-15 09:16:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VCommonSettings::SetUnit(const QString &value)
|
|
|
|
{
|
2017-04-11 10:16:11 +02:00
|
|
|
setValue(settingConfigurationUnit, value);
|
2015-07-15 09:16:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool VCommonSettings::GetConfirmItemDelete() const
|
|
|
|
{
|
2017-04-11 10:16:11 +02:00
|
|
|
return value(settingConfigurationConfirmItemDeletion, 1).toBool();
|
2015-07-15 09:16:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VCommonSettings::SetConfirmItemDelete(const bool &value)
|
|
|
|
{
|
2017-04-11 10:16:11 +02:00
|
|
|
setValue(settingConfigurationConfirmItemDeletion, value);
|
2015-07-15 09:16:59 +02:00
|
|
|
}
|
|
|
|
|
2017-04-12 08:49:05 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool VCommonSettings::GetConfirmFormatRewriting() const
|
|
|
|
{
|
|
|
|
return value(settingConfigurationConfirmFormatRewriting, 1).toBool();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VCommonSettings::SetConfirmFormatRewriting(const bool &value)
|
|
|
|
{
|
|
|
|
setValue(settingConfigurationConfirmFormatRewriting, value);
|
|
|
|
}
|
|
|
|
|
2015-07-15 09:16:59 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool VCommonSettings::GetToolBarStyle() const
|
|
|
|
{
|
2017-04-11 10:16:11 +02:00
|
|
|
return value(settingConfigurationToolBarStyle, 1).toBool();
|
2015-07-15 09:16:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VCommonSettings::SetToolBarStyle(const bool &value)
|
|
|
|
{
|
2017-04-11 10:16:11 +02:00
|
|
|
setValue(settingConfigurationToolBarStyle, value);
|
2015-07-15 09:16:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString VCommonSettings::GetUser() const
|
|
|
|
{
|
|
|
|
QString user;
|
|
|
|
#ifdef Q_OS_WIN
|
2017-04-14 16:47:39 +02:00
|
|
|
user = value(settingPatternUser, QString::fromLocal8Bit(qgetenv("USERNAME").constData())).toString();
|
2015-07-15 09:16:59 +02:00
|
|
|
#else
|
2017-04-11 10:16:11 +02:00
|
|
|
user = value(settingPatternUser, QString::fromLocal8Bit(qgetenv("USER").constData())).toString();
|
2015-07-15 09:16:59 +02:00
|
|
|
#endif
|
|
|
|
return user;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VCommonSettings::SetUser(const QString &value)
|
|
|
|
{
|
2017-04-11 10:16:11 +02:00
|
|
|
setValue(settingPatternUser, value);
|
2015-07-15 09:16:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
int VCommonSettings::GetUndoCount() const
|
|
|
|
{
|
|
|
|
bool ok = false;
|
2017-04-11 10:16:11 +02:00
|
|
|
int val = value(settingPatternUndo, 0).toInt(&ok);
|
2015-07-15 09:16:59 +02:00
|
|
|
if (ok == false)
|
|
|
|
{
|
2017-04-11 10:16:11 +02:00
|
|
|
qDebug()<<"Could not convert value"<<value(settingPatternUndo, 0)
|
2015-07-15 09:16:59 +02:00
|
|
|
<<"to int. Return default value for undo counts 0 (no limit).";
|
|
|
|
val = 0;
|
|
|
|
}
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VCommonSettings::SetUndoCount(const int &value)
|
|
|
|
{
|
2017-04-11 10:16:11 +02:00
|
|
|
setValue(settingPatternUndo, value);
|
2015-07-15 09:16:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QStringList VCommonSettings::GetRecentFileList() const
|
|
|
|
{
|
2017-04-11 10:16:11 +02:00
|
|
|
const QStringList files = value(settingGeneralRecentFileList).toStringList();
|
2016-09-09 13:01:57 +02:00
|
|
|
QStringList cleared;
|
|
|
|
|
|
|
|
for (int i = 0; i < files.size(); ++i)
|
|
|
|
{
|
|
|
|
if (QFileInfo(files.at(i)).exists())
|
|
|
|
{
|
|
|
|
cleared.append(files.at(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return cleared;
|
2015-07-15 09:16:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VCommonSettings::SetRecentFileList(const QStringList &value)
|
|
|
|
{
|
2017-04-11 10:16:11 +02:00
|
|
|
setValue(settingGeneralRecentFileList, value);
|
2015-07-15 09:16:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QStringList VCommonSettings::GetRestoreFileList() const
|
|
|
|
{
|
2017-04-11 10:16:11 +02:00
|
|
|
return value(settingGeneralRestoreFileList).toStringList();
|
2015-07-15 09:16:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VCommonSettings::SetRestoreFileList(const QStringList &value)
|
|
|
|
{
|
2017-04-11 10:16:11 +02:00
|
|
|
setValue(settingGeneralRestoreFileList, value);
|
2015-07-15 09:16:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QByteArray VCommonSettings::GetGeometry() const
|
|
|
|
{
|
2017-04-11 10:16:11 +02:00
|
|
|
return value(settingGeneralGeometry).toByteArray();
|
2015-07-15 09:16:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VCommonSettings::SetGeometry(const QByteArray &value)
|
|
|
|
{
|
2017-04-11 10:16:11 +02:00
|
|
|
setValue(settingGeneralGeometry, value);
|
2015-07-15 09:16:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QByteArray VCommonSettings::GetWindowState() const
|
|
|
|
{
|
2017-04-11 10:16:11 +02:00
|
|
|
return value(settingGeneralWindowState).toByteArray();
|
2015-07-15 09:16:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VCommonSettings::SetWindowState(const QByteArray &value)
|
|
|
|
{
|
2017-04-11 10:16:11 +02:00
|
|
|
setValue(settingGeneralWindowState, value);
|
2015-07-15 09:16:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QByteArray VCommonSettings::GetToolbarsState() const
|
|
|
|
{
|
2017-04-11 10:16:11 +02:00
|
|
|
return value(settingGeneralToolbarsState).toByteArray();
|
2015-07-15 09:16:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VCommonSettings::SetToolbarsState(const QByteArray &value)
|
|
|
|
{
|
2017-04-11 10:16:11 +02:00
|
|
|
setValue(settingGeneralToolbarsState, value);
|
2015-07-15 09:16:59 +02:00
|
|
|
}
|
2016-06-10 21:34:21 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QSize VCommonSettings::GetPreferenceDialogSize() const
|
|
|
|
{
|
2017-04-11 10:16:11 +02:00
|
|
|
return value(settingPreferenceDialogSize, QSize(0, 0)).toSize();
|
2016-06-10 21:34:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VCommonSettings::SetPreferenceDialogSize(const QSize& sz)
|
|
|
|
{
|
2017-04-11 10:16:11 +02:00
|
|
|
setValue(settingPreferenceDialogSize, sz);
|
2016-06-10 21:34:21 +02:00
|
|
|
}
|
2016-07-15 11:00:00 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
int VCommonSettings::GetLatestSkippedVersion() const
|
|
|
|
{
|
2016-07-15 12:14:48 +02:00
|
|
|
QSettings settings(this->format(), this->scope(), this->organizationName(), commonIniFilename);
|
2017-04-11 10:16:11 +02:00
|
|
|
return settings.value(settingLatestSkippedVersion, 0x0).toInt();
|
2016-07-15 11:00:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VCommonSettings::SetLatestSkippedVersion(int value)
|
|
|
|
{
|
2016-07-15 12:14:48 +02:00
|
|
|
QSettings settings(this->format(), this->scope(), this->organizationName(), commonIniFilename);
|
2017-04-11 10:16:11 +02:00
|
|
|
settings.setValue(settingLatestSkippedVersion, value);
|
2016-07-15 12:14:48 +02:00
|
|
|
settings.sync();
|
2016-07-15 11:00:00 +02:00
|
|
|
}
|
2016-07-15 11:30:55 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QDate VCommonSettings::GetDateOfLastRemind() const
|
|
|
|
{
|
2016-07-15 12:14:48 +02:00
|
|
|
QSettings settings(this->format(), this->scope(), this->organizationName(), commonIniFilename);
|
2017-04-11 10:16:11 +02:00
|
|
|
return settings.value(settingDateOfLastRemind, QDate(1900, 1, 1)).toDate();
|
2016-07-15 11:30:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VCommonSettings::SetDateOfLastRemind(const QDate &date)
|
|
|
|
{
|
2016-07-15 12:14:48 +02:00
|
|
|
QSettings settings(this->format(), this->scope(), this->organizationName(), commonIniFilename);
|
2017-04-11 10:16:11 +02:00
|
|
|
settings.setValue(settingDateOfLastRemind, date);
|
2016-07-15 12:14:48 +02:00
|
|
|
settings.sync();
|
2016-07-15 11:30:55 +02:00
|
|
|
}
|
2016-08-12 01:22:23 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QStringList VCommonSettings::GetUserDefinedMaterials() const
|
|
|
|
{
|
2017-04-11 10:16:11 +02:00
|
|
|
return value(settingUserDefinedMaterials).toStringList();
|
2016-08-12 01:22:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VCommonSettings::AddUserDefinedMaterial(QString qsMaterial)
|
|
|
|
{
|
|
|
|
QStringList qsl = GetUserDefinedMaterials();
|
|
|
|
qsl << qsMaterial;
|
2017-04-11 10:16:11 +02:00
|
|
|
setValue(settingUserDefinedMaterials, qsl);
|
2016-08-12 01:22:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VCommonSettings::ClearUserDefinedMaterial()
|
|
|
|
{
|
|
|
|
QStringList qsl;
|
2017-04-11 10:16:11 +02:00
|
|
|
setValue(settingUserDefinedMaterials, qsl);
|
2016-08-12 01:22:23 +02:00
|
|
|
}
|
2016-09-06 16:05:54 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool VCommonSettings::GetForbidWorkpieceFlipping() const
|
|
|
|
{
|
2017-04-11 10:16:11 +02:00
|
|
|
return value(settingPatternForbidFlipping, false).toBool();
|
2016-09-06 16:05:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VCommonSettings::SetForbidWorkpieceFlipping(bool value)
|
|
|
|
{
|
2017-04-11 10:16:11 +02:00
|
|
|
setValue(settingPatternForbidFlipping, value);
|
2016-09-06 16:05:54 +02:00
|
|
|
}
|
2017-04-05 12:22:33 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool VCommonSettings::IsDoublePassmark() const
|
|
|
|
{
|
2017-04-11 10:16:11 +02:00
|
|
|
return value(settingDoublePassmark, false).toBool();
|
2017-04-05 12:22:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VCommonSettings::SetDoublePassmark(bool value)
|
|
|
|
{
|
2017-04-11 10:16:11 +02:00
|
|
|
setValue(settingDoublePassmark, value);
|
2017-04-05 12:22:33 +02:00
|
|
|
}
|
2017-05-12 14:09:19 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VCommonSettings::SetCSVWithHeader(bool withHeader)
|
|
|
|
{
|
|
|
|
QSettings settings(this->format(), this->scope(), this->organizationName(), commonIniFilename);
|
|
|
|
settings.setValue(settingCSVWithHeader, withHeader);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool VCommonSettings::GetCSVWithHeader() const
|
|
|
|
{
|
|
|
|
QSettings settings(this->format(), this->scope(), this->organizationName(), commonIniFilename);
|
|
|
|
return settings.value(settingCSVWithHeader, GetDefCSVWithHeader()).toBool();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool VCommonSettings::GetDefCSVWithHeader() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VCommonSettings::SetCSVCodec(int mib)
|
|
|
|
{
|
|
|
|
QSettings settings(this->format(), this->scope(), this->organizationName(), commonIniFilename);
|
|
|
|
settings.setValue(settingCSVCodec, mib);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
int VCommonSettings::GetCSVCodec() const
|
|
|
|
{
|
|
|
|
QSettings settings(this->format(), this->scope(), this->organizationName(), commonIniFilename);
|
|
|
|
return settings.value(settingCSVCodec, GetDefCSVCodec()).toInt();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
int VCommonSettings::GetDefCSVCodec() const
|
|
|
|
{
|
|
|
|
return QTextCodec::codecForLocale()->mibEnum();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VCommonSettings::SetCSVSeparator(const QChar &separator)
|
|
|
|
{
|
|
|
|
QSettings settings(this->format(), this->scope(), this->organizationName(), commonIniFilename);
|
|
|
|
switch(separator.toLatin1())
|
|
|
|
{
|
|
|
|
case '\t':
|
|
|
|
settings.setValue(settingCSVSeparator, 0);
|
|
|
|
break;
|
|
|
|
case ';':
|
|
|
|
settings.setValue(settingCSVSeparator, 1);
|
|
|
|
break;
|
|
|
|
case ' ':
|
|
|
|
settings.setValue(settingCSVSeparator, 2);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
settings.setValue(settingCSVSeparator, 3);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QChar VCommonSettings::GetCSVSeparator() const
|
|
|
|
{
|
|
|
|
QSettings settings(this->format(), this->scope(), this->organizationName(), commonIniFilename);
|
|
|
|
const quint8 separator = static_cast<quint8>(settings.value(settingCSVSeparator, 3).toUInt());
|
|
|
|
switch(separator)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
return QChar('\t');
|
|
|
|
case 1:
|
|
|
|
return QChar(';');
|
|
|
|
case 2:
|
|
|
|
return QChar(' ');
|
|
|
|
default:
|
|
|
|
return QChar(',');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QChar VCommonSettings::GetDefCSVSeparator() const
|
|
|
|
{
|
|
|
|
return QChar(',');
|
|
|
|
}
|