diff options
author | Qt Continuous Integration System <qt-info@nokia.com> | 2010-02-19 02:38:50 (GMT) |
---|---|---|
committer | Qt Continuous Integration System <qt-info@nokia.com> | 2010-02-19 02:38:50 (GMT) |
commit | e3db2e423f38c254331674360e4dded1d7fc1d60 (patch) | |
tree | 08a7133f6080268f6b5e16fe190c14addf477190 /tools | |
parent | 14866f7fd79f39c2f20f5e0149fe6e11d7121d70 (diff) | |
parent | 5a900c5647bfa642cce277196ebd1d1b9121dea2 (diff) | |
download | Qt-e3db2e423f38c254331674360e4dded1d7fc1d60.zip Qt-e3db2e423f38c254331674360e4dded1d7fc1d60.tar.gz Qt-e3db2e423f38c254331674360e4dded1d7fc1d60.tar.bz2 |
Merge branch '4.6' of scm.dev.nokia.troll.no:qt/qt-s60-public into 4.6-integration
* '4.6' of scm.dev.nokia.troll.no:qt/qt-s60-public:
Pass QAudioDeviceInfo when creating audio input/output in examples
Symbian backend for QtMultimedia audio
Modified configure to detect SDK support for Symbian audio backend
Added implementation of epocRoot() function to configure
Removed duplicated implementation of readRegistryKeys from configure
Factored epocRoot implementation out of qmake
Factored readRegistryKey implementation out of qmake
QWebView scrolling doesn't clear old elements before painting again
Diffstat (limited to 'tools')
-rw-r--r-- | tools/configure/configure.pro | 17 | ||||
-rw-r--r-- | tools/configure/configureapp.cpp | 50 | ||||
-rw-r--r-- | tools/configure/environment.cpp | 128 | ||||
-rw-r--r-- | tools/configure/environment.h | 5 | ||||
-rw-r--r-- | tools/shared/symbian/epocroot.cpp | 230 | ||||
-rw-r--r-- | tools/shared/symbian/epocroot.h | 67 | ||||
-rw-r--r-- | tools/shared/windows/registry.cpp | 161 | ||||
-rw-r--r-- | tools/shared/windows/registry.h | 64 |
8 files changed, 594 insertions, 128 deletions
diff --git a/tools/configure/configure.pro b/tools/configure/configure.pro index 243183c..91de7c2 100644 --- a/tools/configure/configure.pro +++ b/tools/configure/configure.pro @@ -3,8 +3,8 @@ DESTDIR = ../.. CONFIG += console flat CONFIG -= moc qt -DEFINES = UNICODE QT_NODLL QT_NO_CODECS QT_NO_TEXTCODEC QT_NO_UNICODETABLES QT_LITE_COMPONENT QT_NO_STL QT_NO_COMPRESS QT_BUILD_QMAKE QT_NO_THREAD QT_NO_QOBJECT _CRT_SECURE_NO_DEPRECATE - +DEFINES = UNICODE QT_NODLL QT_NO_CODECS QT_NO_TEXTCODEC QT_NO_UNICODETABLES QT_LITE_COMPONENT QT_NO_STL QT_NO_COMPRESS QT_NO_THREAD QT_NO_QOBJECT _CRT_SECURE_NO_DEPRECATE +DEFINES += QT_BOOTSTRAPPED win32 : LIBS += -lole32 -ladvapi32 win32-msvc.net | win32-msvc2* : QMAKE_CXXFLAGS += /EHsc @@ -27,6 +27,7 @@ INCPATH += $$QT_SOURCE_TREE/src/corelib/arch/generic \ $$QT_SOURCE_TREE/src/corelib/global \ $$QT_BUILD_TREE/include \ $$QT_BUILD_TREE/include/QtCore \ + $$QT_BUILD_TREE/tools/shared HEADERS = configureapp.h environment.h tools.h\ $$QT_SOURCE_TREE/src/corelib/tools/qbytearray.h \ @@ -58,7 +59,11 @@ HEADERS = configureapp.h environment.h tools.h\ $$QT_SOURCE_TREE/src/corelib/tools/qstring.h \ $$QT_SOURCE_TREE/src/corelib/tools/qstringlist.h \ $$QT_SOURCE_TREE/src/corelib/tools/qstringmatcher.h \ - $$QT_SOURCE_TREE/src/corelib/tools/qunicodetables_p.h + $$QT_SOURCE_TREE/src/corelib/tools/qunicodetables_p.h \ + $$QT_SOURCE_TREE/src/corelib/xml/qxmlstream.h \ + $$QT_SOURCE_TREE/src/corelib/xml/qxmlutils_p.h \ + $$QT_SOURCE_TREE/tools/shared/symbian/epocroot.h \ + $$QT_SOURCE_TREE/tools/shared/windows/registry.h SOURCES = main.cpp configureapp.cpp environment.cpp tools.cpp \ @@ -102,7 +107,11 @@ SOURCES = main.cpp configureapp.cpp environment.cpp tools.cpp \ $$QT_SOURCE_TREE/src/corelib/tools/qpoint.cpp \ $$QT_SOURCE_TREE/src/corelib/tools/qrect.cpp \ $$QT_SOURCE_TREE/src/corelib/kernel/qmetatype.cpp \ - $$QT_SOURCE_TREE/src/corelib/global/qmalloc.cpp + $$QT_SOURCE_TREE/src/corelib/global/qmalloc.cpp \ + $$QT_SOURCE_TREE/src/corelib/xml/qxmlstream.cpp \ + $$QT_SOURCE_TREE/src/corelib/xml/qxmlutils.cpp \ + $$QT_SOURCE_TREE/tools/shared/symbian/epocroot.cpp \ + $$QT_SOURCE_TREE/tools/shared/windows/registry.cpp win32:SOURCES += $$QT_SOURCE_TREE/src/corelib/io/qfsfileengine_win.cpp diff --git a/tools/configure/configureapp.cpp b/tools/configure/configureapp.cpp index 9e0cb70..d521276 100644 --- a/tools/configure/configureapp.cpp +++ b/tools/configure/configureapp.cpp @@ -247,7 +247,7 @@ Configure::Configure( int& argc, char** argv ) dictionary[ "PHONON" ] = "auto"; dictionary[ "PHONON_BACKEND" ] = "yes"; dictionary[ "MULTIMEDIA" ] = "yes"; - dictionary[ "AUDIO_BACKEND" ] = "yes"; + dictionary[ "AUDIO_BACKEND" ] = "auto"; dictionary[ "DIRECTSHOW" ] = "no"; dictionary[ "WEBKIT" ] = "auto"; dictionary[ "DECLARATIVE" ] = "auto"; @@ -2065,6 +2065,52 @@ bool Configure::checkAvailability(const QString &part) available = (dictionary.value("QMAKESPEC") == "win32-msvc2005") || (dictionary.value("QMAKESPEC") == "win32-msvc2008") || (dictionary.value("QMAKESPEC") == "win32-g++"); } else if (part == "DECLARATIVE") { available = QFile::exists(sourcePath + "/src/declarative/qml/qmlcomponent.h"); + } else if (part == "AUDIO_BACKEND") { + available = true; + if (dictionary.contains("XQMAKESPEC") && dictionary["XQMAKESPEC"].startsWith("symbian")) { + QString epocRoot = Environment::symbianEpocRoot(); + const QDir epocRootDir(epocRoot); + if (epocRootDir.exists()) { + QStringList paths; + paths << "epoc32/release/armv5/lib/mmfdevsound.dso" + << "epoc32/release/armv5/lib/mmfdevsound.lib" + << "epoc32/release/winscw/udeb/mmfdevsound.dll" + << "epoc32/release/winscw/udeb/mmfdevsound.lib" + << "epoc32/include/mmf/server/sounddevice.h"; + + QStringList::iterator i = paths.begin(); + while (i != paths.end()) { + const QString &path = epocRoot + *i; + if (QFile::exists(path)) + i = paths.erase(i); + else + ++i; + } + + available = (paths.size() == 0); + if (!available) { + if (epocRoot.isNull() || epocRoot == "") + epocRoot = "<empty string>"; + cout << endl + << "The QtMultimedia audio backend will not be built because required" << endl + << "support for CMMFDevSound was not found in the SDK." << endl + << "The SDK which was examined was located at the following path:" << endl + << " " << epocRoot << endl + << "The following required files were missing from the SDK:" << endl; + QString path; + foreach (path, paths) + cout << " " << path << endl; + cout << endl; + } + } else { + cout << endl + << "The SDK root was determined to be '" << epocRoot << "'." << endl + << "This directory was not found, so the SDK could not be checked for" << endl + << "CMMFDevSound support. The QtMultimedia audio backend will therefore" << endl + << "not be built." << endl << endl; + available = false; + } + } } return available; @@ -2153,6 +2199,8 @@ void Configure::autoDetection() dictionary["WEBKIT"] = checkAvailability("WEBKIT") ? "yes" : "no"; if (dictionary["DECLARATIVE"] == "auto") dictionary["DECLARATIVE"] = checkAvailability("DECLARATIVE") ? "yes" : "no"; + if (dictionary["AUDIO_BACKEND"] == "auto") + dictionary["AUDIO_BACKEND"] = checkAvailability("AUDIO_BACKEND") ? "yes" : "no"; // Qt/WinCE remote test application if (dictionary["CETEST"] == "auto") diff --git a/tools/configure/environment.cpp b/tools/configure/environment.cpp index af6f9e5..e93f9a0 100644 --- a/tools/configure/environment.cpp +++ b/tools/configure/environment.cpp @@ -60,6 +60,8 @@ using namespace std; #include <qt_windows.h> #endif +#include <symbian/epocroot.h> // from tools/shared +#include <windows/registry.h> // from tools/shared QT_BEGIN_NAMESPACE @@ -97,126 +99,6 @@ CompilerInfo *Environment::compilerInfo(Compiler compiler) } /*! - Returns the path part of a registry key. - Ei. - For a key - "Software\\Microsoft\\VisualStudio\\8.0\\Setup\\VC\\ProductDir" - it returns - "Software\\Microsoft\\VisualStudio\\8.0\\Setup\\VC\\" -*/ -QString Environment::keyPath(const QString &rKey) -{ - int idx = rKey.lastIndexOf(QLatin1Char('\\')); - if (idx == -1) - return QString(); - return rKey.left(idx + 1); -} - -/*! - Returns the name part of a registry key. - Ei. - For a key - "Software\\Microsoft\\VisualStudio\\8.0\\Setup\\VC\\ProductDir" - it returns - "ProductDir" -*/ -QString Environment::keyName(const QString &rKey) -{ - int idx = rKey.lastIndexOf(QLatin1Char('\\')); - if (idx == -1) - return rKey; - - QString res(rKey.mid(idx + 1)); - if (res == "Default" || res == ".") - res = ""; - return res; -} - -/*! - Returns a registry keys value in string form. - If the registry key does not exist, or cannot be accessed, a - QString() is returned. -*/ -QString Environment::readRegistryKey(HKEY parentHandle, const QString &rSubkey) -{ -#ifndef Q_OS_WIN32 - return QString(); -#else - QString rSubkeyName = keyName(rSubkey); - QString rSubkeyPath = keyPath(rSubkey); - - HKEY handle = 0; - LONG res = RegOpenKeyEx(parentHandle, (wchar_t*)rSubkeyPath.utf16(), 0, KEY_READ, &handle); - if (res != ERROR_SUCCESS) - return QString(); - - // get the size and type of the value - DWORD dataType; - DWORD dataSize; - res = RegQueryValueEx(handle, (wchar_t*)rSubkeyName.utf16(), 0, &dataType, 0, &dataSize); - if (res != ERROR_SUCCESS) { - RegCloseKey(handle); - return QString(); - } - - // get the value - QByteArray data(dataSize, 0); - res = RegQueryValueEx(handle, (wchar_t*)rSubkeyName.utf16(), 0, 0, - reinterpret_cast<unsigned char*>(data.data()), &dataSize); - if (res != ERROR_SUCCESS) { - RegCloseKey(handle); - return QString(); - } - - QString result; - switch (dataType) { - case REG_EXPAND_SZ: - case REG_SZ: { - result = QString::fromWCharArray(((const wchar_t *)data.constData())); - break; - } - - case REG_MULTI_SZ: { - QStringList l; - int i = 0; - for (;;) { - QString s = QString::fromWCharArray((const wchar_t *)data.constData() + i); - i += s.length() + 1; - - if (s.isEmpty()) - break; - l.append(s); - } - result = l.join(", "); - break; - } - - case REG_NONE: - case REG_BINARY: { - result = QString::fromWCharArray((const wchar_t *)data.constData(), data.size() / 2); - break; - } - - case REG_DWORD_BIG_ENDIAN: - case REG_DWORD: { - Q_ASSERT(data.size() == sizeof(int)); - int i; - memcpy((char*)&i, data.constData(), sizeof(int)); - result = QString::number(i); - break; - } - - default: - qWarning("QSettings: unknown data %d type in windows registry", dataType); - break; - } - - RegCloseKey(handle); - return result; -#endif -} - -/*! Returns the qmakespec for the compiler detected on the system. */ QString Environment::detectQMakeSpec() @@ -579,4 +461,10 @@ bool Environment::rmdir(const QString &name) return result; } +QString Environment::symbianEpocRoot() +{ + // Call function defined in tools/shared/symbian/epocroot.h + return ::epocRoot(); +} + QT_END_NAMESPACE diff --git a/tools/configure/environment.h b/tools/configure/environment.h index 2d0eafd..b1cbe3a 100644 --- a/tools/configure/environment.h +++ b/tools/configure/environment.h @@ -71,13 +71,12 @@ public: static bool cpdir(const QString &srcDir, const QString &destDir); static bool rmdir(const QString &name); + static QString symbianEpocRoot(); + private: static Compiler detectedCompiler; static CompilerInfo *compilerInfo(Compiler compiler); - static QString keyPath(const QString &rKey); - static QString keyName(const QString &rKey); - static QString readRegistryKey(HKEY parentHandle, const QString &rSubkey); }; diff --git a/tools/shared/symbian/epocroot.cpp b/tools/shared/symbian/epocroot.cpp new file mode 100644 index 0000000..071477d --- /dev/null +++ b/tools/shared/symbian/epocroot.cpp @@ -0,0 +1,230 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the qmake application of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <iostream> + +#include <QtCore/qdir.h> +#include <QtCore/qxmlstream.h> + +#include "epocroot.h" +#include "../windows/registry.h" + +// Registry key under which the location of the Symbian devices.xml file is +// stored. +// Note that, on 64-bit machines, this key is located under the 32-bit +// compatibility key: +// HKEY_LOCAL_MACHINE\Software\Wow6432Node +#define SYMBIAN_SDKS_REG_SUBKEY "Software\\Symbian\\EPOC SDKs\\CommonPath" + +#ifdef Q_OS_WIN32 +# define SYMBIAN_SDKS_REG_HANDLE HKEY_LOCAL_MACHINE +#else +# define SYMBIAN_SDKS_REG_HANDLE 0 +#endif + +// Value which is populated and returned by the epocRoot() function. +// Stored as a static value in order to avoid unnecessary re-evaluation. +static QString epocRootValue; + +#ifdef QT_BUILD_QMAKE +std::ostream &operator<<(std::ostream &s, const QString &val) { + s << val.toLocal8Bit().data(); + return s; +} +#else +// Operator implemented in configureapp.cpp +std::ostream &operator<<(std::ostream &s, const QString &val); +#endif + +QString getDevicesXmlPath() + { + // Note that the following call will return a null string on platforms other + // than Windows. If support is required on other platforms for devices.xml, + // an alternative mechanism for retrieving the location of this file will + // be required. + return readRegistryKey(SYMBIAN_SDKS_REG_HANDLE, SYMBIAN_SDKS_REG_SUBKEY); + } + +/** + * Checks whether epocRootValue points to an existent directory. + * If not, epocRootValue is set to an empty string and an error message is printed. + */ +void checkEpocRootExists(const QString &source) +{ + if (!epocRootValue.isEmpty()) { + QDir dir(epocRootValue); + if (!dir.exists()) { + std::cerr << "Warning: " << source << " is set to an invalid path: " << epocRootValue << std::endl; + epocRootValue = QString(); + } + } +} + +/** + * Translate path from Windows to Qt format. + */ +static void fixEpocRoot(QString &path) +{ + path.replace("\\", "/"); + + if (path.size() > 1 && path[1] == QChar(':')) { + path = path.mid(2); + } + + if (!path.size() || path[path.size()-1] != QChar('/')) { + path += QChar('/'); + } +} + +/** + * Determine the epoc root for the currently active SDK. + */ +QString epocRoot() +{ + if (epocRootValue.isEmpty()) { + // 1. If environment variable EPOCROOT is set and points to an existent + // directory, this is returned. + epocRootValue = qgetenv("EPOCROOT"); + checkEpocRootExists("EPOCROOT"); + + if (epocRootValue.isEmpty()) { + // 2. The location of devices.xml is specified by a registry key. If this + // file exists, it is parsed. + QString devicesXmlPath = getDevicesXmlPath(); + if (devicesXmlPath.isEmpty()) { + std::cerr << "Error: Symbian SDK registry key not found" << std::endl; + } else { + devicesXmlPath += "/devices.xml"; + QFile devicesFile(devicesXmlPath); + if (devicesFile.open(QIODevice::ReadOnly)) { + + // 3. If the EPOCDEVICE environment variable is set and a corresponding + // entry is found in devices.xml, and its epocroot value points to an + // existent directory, it is returned. + // 4. If a device element marked as default is found in devices.xml and its + // epocroot value points to an existent directory, this is returned. + + const QString epocDeviceValue = qgetenv("EPOCDEVICE"); + bool epocDeviceFound = false; + + QXmlStreamReader xml(&devicesFile); + while (!xml.atEnd()) { + xml.readNext(); + if (xml.isStartElement() && xml.name() == "devices") { + if (xml.attributes().value("version") == "1.0") { + while (!(xml.isEndElement() && xml.name() == "devices") && !xml.atEnd()) { + xml.readNext(); + if (xml.isStartElement() && xml.name() == "device") { + const bool isDefault = xml.attributes().value("default") == "yes"; + const QString id = xml.attributes().value("id").toString(); + const QString name = xml.attributes().value("name").toString(); + const bool epocDeviceMatch = (id + ":" + name) == epocDeviceValue; + epocDeviceFound |= epocDeviceMatch; + + if((epocDeviceValue.isEmpty() && isDefault) || epocDeviceMatch) { + // Found a matching device + while (!(xml.isEndElement() && xml.name() == "device") && !xml.atEnd()) { + xml.readNext(); + if (xml.isStartElement() && xml.name() == "epocroot") { + epocRootValue = xml.readElementText(); + const QString deviceSource = epocDeviceValue.isEmpty() + ? "default device" + : "EPOCDEVICE (" + epocDeviceValue + ")"; + checkEpocRootExists(deviceSource); + } + } + + if (epocRootValue.isEmpty()) + xml.raiseError("No epocroot element found"); + } + } + } + } else { + xml.raiseError("Invalid 'devices' element version"); + } + } + } + if (xml.hasError()) { + std::cerr << "Error: \"" << xml.errorString() << "\" when parsing devices.xml" << std::endl; + } else { + if (epocRootValue.isEmpty()) { + if (!epocDeviceValue.isEmpty()) { + if (epocDeviceFound) { + std::cerr << "Error: missing or invalid epocroot attribute " + << "in device '" << epocDeviceValue << "'"; + } else { + std::cerr << "Error: no device matching EPOCDEVICE (" + << epocDeviceValue << ")"; + } + } else { + if (epocDeviceFound) { + std::cerr << "Error: missing or invalid epocroot attribute " + << "in default device"; + } else { + std::cerr << "Error: no default device"; + } + } + std::cerr << " found in devices.xml file." << std::endl; + } + } + } else { + std::cerr << "Error: could not open file " << devicesXmlPath << std::endl; + } + } + } + + if (epocRootValue.isEmpty()) { + // 5. An empty string is returned. + std::cerr << "Error: failed to find epoc root" << std::endl + << "Either" << std::endl + << " 1. Set EPOCROOT environment variable to a valid value" << std::endl + << " or 2. Ensure that the HKEY_LOCAL_MACHINE\\" SYMBIAN_SDKS_REG_SUBKEY + " registry key is set, and then" << std::endl + << " a. Set EPOCDEVICE environment variable to a valid device" << std::endl + << " or b. Specify a default device in the devices.xml file." << std::endl; + } else { + fixEpocRoot(epocRootValue); + } + } + + return epocRootValue; +} + diff --git a/tools/shared/symbian/epocroot.h b/tools/shared/symbian/epocroot.h new file mode 100644 index 0000000..9846485 --- /dev/null +++ b/tools/shared/symbian/epocroot.h @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the qmake application of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef SYMBIAN_EPOCROOT_H +#define SYMBIAN_EPOCROOT_H + +#include <QtCore/qstring.h> + +/** + * Determine the epoc root for the currently active SDK. + * + * The algorithm used is as follows: + * 1. If environment variable EPOCROOT is set and points to an existent + * directory, this is returned. + * 2. The location of devices.xml is specified by a registry key. If this + * file exists, it is parsed. + * 3. If the EPOCDEVICE environment variable is set and a corresponding + * entry is found in devices.xml, and its epocroot value points to an + * existent directory, it is returned. + * 4. If a device element marked as default is found in devices.xml and its + * epocroot value points to an existent directory, this is returned. + * 5. An empty string is returned. + * + * Any return value other than the empty string therefore is guaranteed to + * point to an existent directory. + */ +QString epocRoot(); + +#endif // EPOCROOT_H diff --git a/tools/shared/windows/registry.cpp b/tools/shared/windows/registry.cpp new file mode 100644 index 0000000..d342d78 --- /dev/null +++ b/tools/shared/windows/registry.cpp @@ -0,0 +1,161 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the qmake application of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtCore/qstringlist.h> +#include "registry.h" + +/*! + Returns the path part of a registry key. + e.g. + For a key + "Software\\Microsoft\\VisualStudio\\8.0\\Setup\\VC\\ProductDir" + it returns + "Software\\Microsoft\\VisualStudio\\8.0\\Setup\\VC\\" +*/ +static QString keyPath(const QString &rKey) +{ + int idx = rKey.lastIndexOf(QLatin1Char('\\')); + if (idx == -1) + return QString(); + return rKey.left(idx + 1); +} + +/*! + Returns the name part of a registry key. + e.g. + For a key + "Software\\Microsoft\\VisualStudio\\8.0\\Setup\\VC\\ProductDir" + it returns + "ProductDir" +*/ +static QString keyName(const QString &rKey) +{ + int idx = rKey.lastIndexOf(QLatin1Char('\\')); + if (idx == -1) + return rKey; + + QString res(rKey.mid(idx + 1)); + if (res == "Default" || res == ".") + res = ""; + return res; +} + +QString readRegistryKey(HKEY parentHandle, const QString &rSubkey) +{ + QString result; + +#ifdef Q_OS_WIN32 + QString rSubkeyName = keyName(rSubkey); + QString rSubkeyPath = keyPath(rSubkey); + + HKEY handle = 0; + LONG res = RegOpenKeyEx(parentHandle, (wchar_t*)rSubkeyPath.utf16(), 0, KEY_READ, &handle); + + if (res != ERROR_SUCCESS) + return QString(); + + // get the size and type of the value + DWORD dataType; + DWORD dataSize; + res = RegQueryValueEx(handle, (wchar_t*)rSubkeyName.utf16(), 0, &dataType, 0, &dataSize); + if (res != ERROR_SUCCESS) { + RegCloseKey(handle); + return QString(); + } + + // get the value + QByteArray data(dataSize, 0); + res = RegQueryValueEx(handle, (wchar_t*)rSubkeyName.utf16(), 0, 0, + reinterpret_cast<unsigned char*>(data.data()), &dataSize); + if (res != ERROR_SUCCESS) { + RegCloseKey(handle); + return QString(); + } + + switch (dataType) { + case REG_EXPAND_SZ: + case REG_SZ: { + result = QString::fromWCharArray(((const wchar_t *)data.constData())); + break; + } + + case REG_MULTI_SZ: { + QStringList l; + int i = 0; + for (;;) { + QString s = QString::fromWCharArray((const wchar_t *)data.constData() + i); + i += s.length() + 1; + + if (s.isEmpty()) + break; + l.append(s); + } + result = l.join(", "); + break; + } + + case REG_NONE: + case REG_BINARY: { + result = QString::fromWCharArray((const wchar_t *)data.constData(), data.size() / 2); + break; + } + + case REG_DWORD_BIG_ENDIAN: + case REG_DWORD: { + Q_ASSERT(data.size() == sizeof(int)); + int i; + memcpy((char*)&i, data.constData(), sizeof(int)); + result = QString::number(i); + break; + } + + default: + qWarning("QSettings: unknown data %d type in windows registry", dataType); + break; + } + + RegCloseKey(handle); +#endif + + return result; +} + + diff --git a/tools/shared/windows/registry.h b/tools/shared/windows/registry.h new file mode 100644 index 0000000..3896527 --- /dev/null +++ b/tools/shared/windows/registry.h @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the qmake application of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef WINDOWS_REGISTRY_H +#define WINDOWS_REGISTRY_H + +#include <QtCore/qglobal.h> + +#ifdef Q_OS_WIN32 + #include <QtCore/qt_windows.h> +#else + typedef void* HKEY; +#endif + +#include <QtCore/qstring.h> + +/** + * Read a value from the Windows registry. + * + * If the key is not found, or the registry cannot be accessed (for example + * if this code is compiled for a platform other than Windows), a null + * string is returned. + */ +QString readRegistryKey(HKEY parentHandle, const QString &rSubkey); + +#endif // WINDOWS_REGISTRY_H |