[KDE/Mac] Fwd: Qtbase patch for configurable standard paths
David Faure
faure at kde.org
Tue Jan 19 08:05:21 UTC 2016
What about this solution, providing a qt.conf which extends QStandardPaths?
Very flexible, you can add paths without changing any code, once this patch is in.
And if it makes QSP work on both Windows and OSX, that's even better.
---------- Forwarded Message ----------
Subject: Qtbase patch for configurable standard paths
Date: Monday 05 October 2015, 11:06:52
From: Patrick Spendrin <ps_ml at gmx.de>
To: Andreas Holzammer <andy at kdab.com>, David Faure <faure at kde.org>
QStandardpaths currently is specific per user/computer.
This fails on windows in *at least* the following scenario:
(Qt-)Framework A wants to store its settings using QStandardPaths.
Two independent software vendors, company B and company C want to use
Framework A. Since both companies have a different release cycle and
maybe even different usecases for Framework A, it would be nice to
have a way to redirect the settings location without modifying the
source code of Qt or Framework A.
My idea is to use the (most likely) existing file qt.conf and add a
section to override the standardpaths location in there. The attached
patch gives a small idea how this could look like, since I haven't
contributed to Qt for a long time, I'd like to have some input first.
regards,
Patrick
-----------------------------------------
--
David Faure, faure at kde.org, http://www.davidfaure.fr
Working on KDE Frameworks 5
-------------- next part --------------
>From c6524a252fc362abe5b8412dcabec499ff092143 Mon Sep 17 00:00:00 2001
From: Patrick Spendrin <ps_ml at gmx.de>
Date: Tue, 29 Sep 2015 15:47:09 +0200
Subject: [PATCH] WIP: configurable standardpaths
---
src/corelib/global/global.pri | 1 +
src/corelib/global/qlibraryinfo.cpp | 49 +++++++++++++---------------
src/corelib/global/qlibraryinfo_p.h | 61 +++++++++++++++++++++++++++++++++++
src/corelib/io/qstandardpaths.cpp | 42 ++++++++++++++++++++++++
src/corelib/io/qstandardpaths.h | 2 ++
src/corelib/io/qstandardpaths_mac.mm | 4 +++
src/corelib/io/qstandardpaths_win.cpp | 4 ++-
7 files changed, 136 insertions(+), 27 deletions(-)
create mode 100644 src/corelib/global/qlibraryinfo_p.h
diff --git a/src/corelib/global/global.pri b/src/corelib/global/global.pri
index 6a8104b..a905cb2 100644
--- a/src/corelib/global/global.pri
+++ b/src/corelib/global/global.pri
@@ -10,6 +10,7 @@ HEADERS += \
global/qnumeric_p.h \
global/qnumeric.h \
global/qglobalstatic.h \
+ global/qlibraryinfo_p.h \
global/qlibraryinfo.h \
global/qlogging.h \
global/qtypeinfo.h \
diff --git a/src/corelib/global/qlibraryinfo.cpp b/src/corelib/global/qlibraryinfo.cpp
index 0cfcc4e..640e9cf 100644
--- a/src/corelib/global/qlibraryinfo.cpp
+++ b/src/corelib/global/qlibraryinfo.cpp
@@ -38,6 +38,7 @@
#include "qsettings.h"
#include "qlibraryinfo.h"
#include "qscopedpointer.h"
+#include "qlibraryinfo_p.h"
#ifdef QT_BUILD_QMAKE
QT_BEGIN_NAMESPACE
@@ -77,37 +78,33 @@ struct QLibrarySettings
};
Q_GLOBAL_STATIC(QLibrarySettings, qt_library_settings)
-class QLibraryInfoPrivate
-{
-public:
- static QSettings *findConfiguration();
#ifdef QT_BUILD_QMAKE
- static bool haveGroup(QLibraryInfo::PathGroup group)
- {
- QLibrarySettings *ls = qt_library_settings();
- return ls ? (group == QLibraryInfo::EffectiveSourcePaths
- ? ls->haveEffectiveSourcePaths
- : group == QLibraryInfo::EffectivePaths
- ? ls->haveEffectivePaths
- : group == QLibraryInfo::DevicePaths
- ? ls->haveDevicePaths
- : ls->havePaths) : false;
- }
+bool QLibraryInfoPrivate::haveGroup(QLibraryInfo::PathGroup group)
+{
+ QLibrarySettings *ls = qt_library_settings();
+ return ls ? (group == QLibraryInfo::EffectiveSourcePaths
+ ? ls->haveEffectiveSourcePaths
+ : group == QLibraryInfo::EffectivePaths
+ ? ls->haveEffectivePaths
+ : group == QLibraryInfo::DevicePaths
+ ? ls->haveDevicePaths
+ : ls->havePaths) : false;
+}
#endif
- static QSettings *configuration()
- {
- QLibrarySettings *ls = qt_library_settings();
- if (ls) {
+QSettings *QLibraryInfoPrivate::configuration()
+{
+ QLibrarySettings *ls = qt_library_settings();
+ if (ls) {
#ifndef QT_BUILD_QMAKE
- if (ls->reloadOnQAppAvailable && QCoreApplication::instance() != 0)
- ls->load();
+ if (ls->reloadOnQAppAvailable && QCoreApplication::instance() != 0)
+ ls->load();
#endif
- return ls->settings.data();
- } else {
- return 0;
- }
+ return ls->settings.data();
+ } else {
+ return 0;
}
-};
+}
+
static const char platformsSection[] = "Platforms";
diff --git a/src/corelib/global/qlibraryinfo_p.h b/src/corelib/global/qlibraryinfo_p.h
new file mode 100644
index 0000000..e6e1b15
--- /dev/null
+++ b/src/corelib/global/qlibraryinfo_p.h
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL21$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** As a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QLIBRARYINFO_P_H
+#define QLIBRARYINFO_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qsettings.h"
+#include "qlibraryinfo.h"
+
+class QLibraryInfoPrivate
+{
+public:
+ static QSettings *findConfiguration();
+#ifdef QT_BUILD_QMAKE
+ static bool haveGroup(QLibraryInfo::PathGroup group);
+#endif
+ static QSettings *configuration();
+};
+
+#endif
\ No newline at end of file
diff --git a/src/corelib/io/qstandardpaths.cpp b/src/corelib/io/qstandardpaths.cpp
index 74252d1..5bcfe2a 100644
--- a/src/corelib/io/qstandardpaths.cpp
+++ b/src/corelib/io/qstandardpaths.cpp
@@ -36,6 +36,10 @@
#include <qdir.h>
#include <qfileinfo.h>
#include <qhash.h>
+// #include <QtCore/private/qlibraryinfo_p.h>
+#if !defined(QT_BUILD_QMAKE) && !defined(QT_NO_SETTINGS) && !defined(QT_BOOTSTRAPPED)
+#include "../global/qlibraryinfo_p.h"
+#endif
#ifndef QT_BOOTSTRAPPED
#include <qobject.h>
@@ -661,6 +665,44 @@ bool QStandardPaths::isTestModeEnabled()
return qsp_testMode;
}
+static const char standardPathsSection[] = "StandardPaths";
+
+QString QStandardPaths::presetLocation(StandardLocation type)
+{
+#if !defined(QT_BUILD_QMAKE) && !defined(QT_NO_SETTINGS) && !defined(QT_BOOTSTRAPPED)
+ QStringList locations = QStringList() << QStringLiteral("DesktopLocation")
+ << QStringLiteral("DocumentsLocation")
+ << QStringLiteral("FontsLocation")
+ << QStringLiteral("ApplicationsLocation")
+ << QStringLiteral("MusicLocation")
+ << QStringLiteral("MoviesLocation")
+ << QStringLiteral("PicturesLocation")
+ << QStringLiteral("TempLocation")
+ << QStringLiteral("HomeLocation")
+ << QStringLiteral("DataLocation")
+ << QStringLiteral("CacheLocation")
+ << QStringLiteral("GenericDataLocation")
+ << QStringLiteral("RuntimeLocation")
+ << QStringLiteral("ConfigLocation")
+ << QStringLiteral("DownloadLocation")
+ << QStringLiteral("GenericCacheLocation")
+ << QStringLiteral("GenericConfigLocation")
+ << QStringLiteral("AppDataLocation")
+ << QStringLiteral("AppConfigLocation")
+ << QStringLiteral("AppLocalDataLocation");
+
+ QScopedPointer<const QSettings> settings(QLibraryInfoPrivate::findConfiguration());
+ if (!settings.isNull()) {
+ QString key = QLatin1String(standardPathsSection);
+ key += QLatin1Char('/');
+ key += locations[type];
+ return settings->value(key).toString();
+ }
+#endif // !QT_BUILD_QMAKE && !QT_NO_SETTINGS
+
+ return QString();
+}
+
QT_END_NAMESPACE
diff --git a/src/corelib/io/qstandardpaths.h b/src/corelib/io/qstandardpaths.h
index 5c0e08b..2fb29bb 100644
--- a/src/corelib/io/qstandardpaths.h
+++ b/src/corelib/io/qstandardpaths.h
@@ -92,6 +92,8 @@ public:
static bool isTestModeEnabled();
private:
+ static QString presetLocation(StandardLocation type);
+
// prevent construction
QStandardPaths();
~QStandardPaths();
diff --git a/src/corelib/io/qstandardpaths_mac.mm b/src/corelib/io/qstandardpaths_mac.mm
index d6126ce..29333bd 100644
--- a/src/corelib/io/qstandardpaths_mac.mm
+++ b/src/corelib/io/qstandardpaths_mac.mm
@@ -138,6 +138,10 @@ static QString macLocation(QStandardPaths::StandardLocation type, short domain)
QString QStandardPaths::writableLocation(StandardLocation type)
{
+ const QString result = QStandardPaths::presetLocation(type);
+ if(!result.isEmpty())
+ return result;
+
if (isTestModeEnabled()) {
const QString qttestDir = QDir::homePath() + QLatin1String("/.qttest");
QString path;
diff --git a/src/corelib/io/qstandardpaths_win.cpp b/src/corelib/io/qstandardpaths_win.cpp
index b1d5821..76d569d 100644
--- a/src/corelib/io/qstandardpaths_win.cpp
+++ b/src/corelib/io/qstandardpaths_win.cpp
@@ -87,7 +87,9 @@ static inline int clsidForAppDataLocation(QStandardPaths::StandardLocation type)
QString QStandardPaths::writableLocation(StandardLocation type)
{
- QString result;
+ QString result = QStandardPaths::presetLocation(type);
+ if (!result.isEmpty())
+ return result;
#if !defined(Q_OS_WINCE)
static GetKnownFolderPath SHGetKnownFolderPath = (GetKnownFolderPath)QSystemLibrary::resolve(QLatin1String("shell32"), "SHGetKnownFolderPath");
--
2.5.0.windows.1
More information about the kde-mac
mailing list