QStandardPaths Patch

Patrick Spendrin ps_ml at gmx.de
Tue Oct 13 06:40:58 UTC 2015


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Am 12.10.2015 um 22:15 schrieb Christoph Cullmann:
> Hi,
> 
> I have seen some patch floating around to allow to overwrite the
> QStandardPaths locations via qt.conf.
> 
> I like that idea, thought in the patch I have seen the writable
> location is overwritten.
> 
> Should not be the "non-writable" ones overwritten?

Well, not sure if it is my patch that you saw, (I attached it for
reference), but what we want to achieve is not to modify the install
location (that is a different topic) but the location of the
equivalent of the .kde directory; this now maps to some %APPDATA%-like
location directly, meaning that it will collide if a certain framework
is used in two different installations:
Say you install kile and you install kdevelop on the other hand,
settings for the ktexteditor framework are now mapped to the same
file, even though you might not want that (these are different apps
after all) and might also be dangerous due to version conflicts (in
contrary to Linux distributions, you have no way to make sure that
both installations are updated).

If there are similar problems for the non-writeable location, this
patch of course can be adapted too.

I am not sure if the patch is ok to submit yet, but maybe I should try i
t.

> 
> Greetings Christoph
> 
regards,
Patrick
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.21 (MingW32)

iQIcBAEBAgAGBQJWHKd5AAoJEPAKI6QtGt1xiR0P/RG1HnE4sNWHOv9lIC8spuSK
GO5SsfexcgGEhRNpJeQo+EJUyl+eU7hN1cCU8UYOhZZ2Jv3xvCf32l4LLG4FR+Se
N7RGlm5U5q7ZixNZQIErRYRvtw2hHWQW55pnC3Hw45mEvJm6za+lbyM/n7MmeIKR
xkEHJ4qA9UoQFppKtYXIeRwpfQQuuGbqpTDyyZCQVgusqmcr9XKiwrj2nbsD9o4Q
g1NNBlxl+4BUlpTKN72M4a/8ZtPpEx2GI1WPB5XbQWvOLugC74yDaK6KBqYuAt6d
q6oxUcbs+dzF4YtPmutvn496EDmXg8rTUOR+ilvMgsuqf8KHs0i8SJBn4my7EF5L
vrJDm7ZjsqXmQ231LvjFEN//SSYmr1CWiLVTIVfwCtvCFan9sdjlZXvcFzeGQLhg
6eRksCVOIB+xuiBFEM8w1a5tM29kVUaYtPFSRHxQPxcHE1QEVQVYSqrd7g+mhYED
HBJd8MBLVwwitNYKdDLQ/yw0EYH/2ZwbfNl1wbgUKaiNKWE1tXzC9IR0h9PgJikW
JTR13PdkoHosc4Km2NeS0ePPPolHy95l9/jIjAQeDLi7Ey3V+RwqY1UXrOuqVqqC
DYDp/NkPXsgx2HAMopNb0qRcpj7GBmOcgC7TkYrFHqSiKtXEQfzAOPrTklYhsaD/
eihYIY+6EpGbDhwWRwnE
=ZEVq
-----END PGP SIGNATURE-----
-------------- 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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-WIP-configurable-standardpaths.patch.sig
Type: application/octet-stream
Size: 543 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-windows/attachments/20151013/ca569a3d/attachment-0001.obj>


More information about the Kde-windows mailing list