Add Patch to make qtstandardpaths configurable
authorAndre Heinecke <aheinecke@intevation.de>
Tue, 1 Mar 2016 14:02:51 +0000 (15:02 +0100)
committerAndre Heinecke <aheinecke@intevation.de>
Tue, 1 Mar 2016 14:02:51 +0000 (15:02 +0100)
* Makefile.am (EXTRA_DIST): Add patch.
* patches/qtbase-5.5.1/config-standardpaths.patch: New.

--
QStandardPaths is in a bad state by default. It writes config
data into %LOCALAPPDATA% (without subdir) which does not make
sense at all.

This patch makes it possible to change this with a qt.conf file

Makefile.am
patches/qtbase-5.5.1/config-standardpaths.patch [new file with mode: 0755]

index 708c7bf..2bc639f 100644 (file)
@@ -33,6 +33,7 @@ EXTRA_DIST = autogen.sh README.GIT ONEWS \
         patches/qtbase-5.5.1/fix-syssemaphore.patch \
         patches/qtbase-5.5.1/fix-zlib-link.patch \
         patches/qtbase-5.5.1/relative-paths.patch \
+        patches/qtbase-5.5.1/config-standardpaths.patch \
         patches/w32pth-2.0.5/workaround-broken-libtool.patch \
         patches/qttools/disable-most-tools.patch \
         patches/ki18n/no-tests.patch \
diff --git a/patches/qtbase-5.5.1/config-standardpaths.patch b/patches/qtbase-5.5.1/config-standardpaths.patch
new file mode 100755 (executable)
index 0000000..9a11f26
--- /dev/null
@@ -0,0 +1,291 @@
+#! /bin/sh
+patch -p1 -f $* < $0
+exit $?
+
+From c6524a252fc362abe5b8412dcabec499ff092143 Mon Sep 17 00:00:00 2001
+From: Patrick Spendrin <ps_ml@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,13 @@
+ #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
++#ifdef Q_OS_WIN
++#include <windows.h>
++#endif
+
+ #ifndef QT_BOOTSTRAPPED
+ #include <qobject.h>
+@@ -655,6 +659,55 @@ 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];
++        const QString value = settings->value(key).toString();
++#ifdef Q_OS_WIN
++        if (value.isEmpty())
++#endif
++          return value;
++#ifdef Q_OS_WIN
++        wchar_t expandedPath[MAX_PATH] = {0};
++        if (ExpandEnvironmentStrings((wchar_t*)value.utf16(), expandedPath, MAX_PATH)) {
++            return QString::fromWCharArray(expandedPath).replace("\\", "//");
++        }
++        return value;
++#endif
++    }
++#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