From e154ba7440cee151a956504f7cea4582aeb88047 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 13 Apr 2024 12:34:09 +0300 Subject: [PATCH] Support for OneDrive on Windows. Move settings, "Svg fonts", "Font corrections" and "Known measurements" folders to user Documents. This will map to OneDrive's documents folder if OneDrive activated. --- src/app/puzzle/vpapplication.cpp | 7 ++++ src/app/tape/mapplication.cpp | 7 ++++ src/libs/vmisc/vabstractvalapplication.cpp | 7 ++++ src/libs/vmisc/vcommonsettings.cpp | 44 ++++++++++++++++++++-- 4 files changed, 62 insertions(+), 3 deletions(-) diff --git a/src/app/puzzle/vpapplication.cpp b/src/app/puzzle/vpapplication.cpp index 9cd5859d3..618f8d1cf 100644 --- a/src/app/puzzle/vpapplication.cpp +++ b/src/app/puzzle/vpapplication.cpp @@ -492,6 +492,13 @@ auto VPApplication::TrVars() -> const VTranslateVars * //--------------------------------------------------------------------------------------------------------------------- void VPApplication::OpenSettings() { +#if defined(Q_OS_WIN) + QString const docPath = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation); + if (!docPath.isEmpty()) + { + QSettings::setPath(QSettings::IniFormat, QSettings::UserScope, docPath); + } +#endif settings = new VPSettings(QSettings::IniFormat, QSettings::UserScope, QCoreApplication::organizationName(), QCoreApplication::applicationName(), this); connect(settings, &VPSettings::SVGFontsPathChanged, this, &VPApplication::SVGFontsPathChanged); diff --git a/src/app/tape/mapplication.cpp b/src/app/tape/mapplication.cpp index af6faab33..fc12b1938 100644 --- a/src/app/tape/mapplication.cpp +++ b/src/app/tape/mapplication.cpp @@ -614,6 +614,13 @@ void MApplication::AboutToQuit() //--------------------------------------------------------------------------------------------------------------------- void MApplication::OpenSettings() { +#if defined(Q_OS_WIN) + QString const docPath = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation); + if (!docPath.isEmpty()) + { + QSettings::setPath(QSettings::IniFormat, QSettings::UserScope, docPath); + } +#endif settings = new VTapeSettings(QSettings::IniFormat, QSettings::UserScope, QCoreApplication::organizationName(), QCoreApplication::applicationName(), this); connect(settings, &VTapeSettings::SVGFontsPathChanged, this, &MApplication::SVGFontsPathChanged); diff --git a/src/libs/vmisc/vabstractvalapplication.cpp b/src/libs/vmisc/vabstractvalapplication.cpp index f697bfef6..8ff682358 100644 --- a/src/libs/vmisc/vabstractvalapplication.cpp +++ b/src/libs/vmisc/vabstractvalapplication.cpp @@ -71,6 +71,13 @@ void VAbstractValApplication::PostWarningMessage(const QString &message, QtMsgTy */ void VAbstractValApplication::OpenSettings() { +#if defined(Q_OS_WIN) + QString const docPath = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation); + if (!docPath.isEmpty()) + { + QSettings::setPath(QSettings::IniFormat, QSettings::UserScope, docPath); + } +#endif settings = new VValentinaSettings(QSettings::IniFormat, QSettings::UserScope, QCoreApplication::organizationName(), QCoreApplication::applicationName(), this); connect(settings, &VValentinaSettings::SVGFontsPathChanged, this, &VAbstractValApplication::SVGFontsPathChanged); diff --git a/src/libs/vmisc/vcommonsettings.cpp b/src/libs/vmisc/vcommonsettings.cpp index 47eb3927f..f371f8dd2 100644 --- a/src/libs/vmisc/vcommonsettings.cpp +++ b/src/libs/vmisc/vcommonsettings.cpp @@ -347,7 +347,19 @@ void VCommonSettings::SetPathCustomImage(const QString &value) //--------------------------------------------------------------------------------------------------------------------- auto VCommonSettings::GetDefPathSVGFonts() -> QString { - return QDir::homePath() + QStringLiteral("/valentina/svg fonts"); + QString const defPath = QStringList{QDir::homePath(), "Valentina"_L1, "Svg fonts"_L1}.join(QDir::separator()); + +#if defined(Q_OS_WIN) + QString const docPath = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation); + if (docPath.isEmpty()) + { + return defPath; + } + + return QStringList{docPath, "Valentina"_L1, "Svg fonts"_L1}.join(QDir::separator()); +#else + return defPath; +#endif } //--------------------------------------------------------------------------------------------------------------------- @@ -375,7 +387,20 @@ void VCommonSettings::SetPathSVGFonts(const QString &value) //--------------------------------------------------------------------------------------------------------------------- auto VCommonSettings::GetDefPathFontCorrections() -> QString { - return QDir::homePath() + "/valentina/font corrections"_L1; + QString const defPath = + QStringList{QDir::homePath(), "Valentina"_L1, "Font corrections"_L1}.join(QDir::separator()); + +#if defined(Q_OS_WIN) + QString const docPath = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation); + if (docPath.isEmpty()) + { + return defPath; + } + + return QStringList{docPath, "Valentina"_L1, "Font corrections"_L1}.join(QDir::separator()); +#else + return defPath; +#endif } //--------------------------------------------------------------------------------------------------------------------- @@ -396,7 +421,20 @@ void VCommonSettings::SetPathFontCorrections(const QString &value) //--------------------------------------------------------------------------------------------------------------------- auto VCommonSettings::GetDefPathKnownMeasurements() -> QString { - return QDir::homePath() + "/valentina/known measurements"_L1; + QString const defPath = + QStringList{QDir::homePath(), "Valentina"_L1, "Known measurements"_L1}.join(QDir::separator()); + +#if defined(Q_OS_WIN) + QString const docPath = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation); + if (docPath.isEmpty()) + { + return defPath; + } + + return QStringList{docPath, "Valentina"_L1, "Known measurements"_L1}.join(QDir::separator()); +#else + return defPath; +#endif } //---------------------------------------------------------------------------------------------------------------------