summaryrefslogtreecommitdiffstats
path: root/tools/shared
diff options
context:
space:
mode:
authorQt by Nokia <qt-info@nokia.com>2011-04-27 12:05:43 +0200
committeraxis <qt-info@nokia.com>2011-04-27 12:05:43 +0200
commit38be0d13830efd2d98281c645c3a60afe05ffece (patch)
tree6ea73f3ec77f7d153333779883e8120f82820abe /tools/shared
Initial import from the monolithic Qt.
This is the beginning of revision history for this module. If you want to look at revision history older than this, please refer to the Qt Git wiki for how to use Git history grafting. At the time of writing, this wiki is located here: http://qt.gitorious.org/qt/pages/GitIntroductionWithQt If you have already performed the grafting and you don't see any history beyond this commit, try running "git log" with the "--follow" argument. Branched from the monolithic repo, Qt master branch, at commit 896db169ea224deb96c59ce8af800d019de63f12
Diffstat (limited to 'tools/shared')
-rw-r--r--tools/shared/symbian/epocroot.cpp227
-rw-r--r--tools/shared/symbian/epocroot.pri11
-rw-r--r--tools/shared/symbian/epocroot_p.h83
-rw-r--r--tools/shared/windows/registry.cpp169
-rw-r--r--tools/shared/windows/registry_p.h80
5 files changed, 570 insertions, 0 deletions
diff --git a/tools/shared/symbian/epocroot.cpp b/tools/shared/symbian/epocroot.cpp
new file mode 100644
index 0000000000..5e6bc120cf
--- /dev/null
+++ b/tools/shared/symbian/epocroot.cpp
@@ -0,0 +1,227 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 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/qdir.h>
+#include <QtCore/qxmlstream.h>
+
+#include "epocroot_p.h"
+#include "../windows/registry_p.h"
+
+QT_BEGIN_NAMESPACE
+
+// 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;
+
+static 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 qt_readRegistryKey(SYMBIAN_SDKS_REG_HANDLE, QLatin1String(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.
+ */
+static void checkEpocRootExists(const QString &source)
+{
+ if (!epocRootValue.isEmpty()) {
+ QDir dir(epocRootValue);
+ if (!dir.exists()) {
+ qWarning("Warning: %s is set to an invalid path: '%s'", qPrintable(source),
+ qPrintable(epocRootValue));
+ epocRootValue = QString();
+ }
+ }
+}
+
+/**
+ * Translate path from Windows to Qt format.
+ */
+static void fixEpocRoot(QString &path)
+{
+ path.replace(QLatin1Char('\\'), QLatin1Char('/'));
+
+ if (!path.size() || path[path.size()-1] != QLatin1Char('/')) {
+ path += QLatin1Char('/');
+ }
+#ifdef Q_OS_WIN32
+ // Make sure we have drive letter in epocroot
+ if (path.startsWith(QLatin1Char('/')))
+ path.prepend(QDir::currentPath().left(2));
+#endif
+}
+
+/**
+ * Determine the epoc root for the currently active SDK.
+ */
+QString qt_epocRoot()
+{
+ if (epocRootValue.isEmpty()) {
+ // 1. If environment variable EPOCROOT is set and points to an existent
+ // directory, this is returned.
+ epocRootValue = QString::fromLocal8Bit(qgetenv("EPOCROOT").constData());
+ checkEpocRootExists(QLatin1String("EPOCROOT environment variable"));
+
+ 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()) {
+ devicesXmlPath += QLatin1String("/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 = QString::fromLocal8Bit(qgetenv("EPOCDEVICE").constData());
+ bool epocDeviceFound = false;
+
+ QXmlStreamReader xml(&devicesFile);
+ while (!xml.atEnd()) {
+ xml.readNext();
+ if (xml.isStartElement() && xml.name() == QLatin1String("devices")) {
+ if (xml.attributes().value(QLatin1String("version")) == QLatin1String("1.0")) {
+ while (!(xml.isEndElement() && xml.name() == QLatin1String("devices")) && !xml.atEnd()) {
+ xml.readNext();
+ if (xml.isStartElement() && xml.name() == QLatin1String("device")) {
+ const bool isDefault = xml.attributes().value(QLatin1String("default")) == QLatin1String("yes");
+ const QString id = xml.attributes().value(QLatin1String("id")).toString();
+ const QString name = xml.attributes().value(QLatin1String("name")).toString();
+ const QString alias = xml.attributes().value(QLatin1String("alias")).toString();
+ bool epocDeviceMatch = QString(id + QLatin1String(":") + name) == epocDeviceValue;
+ if (!alias.isEmpty())
+ epocDeviceMatch |= alias == epocDeviceValue;
+ epocDeviceFound |= epocDeviceMatch;
+
+ if((epocDeviceValue.isEmpty() && isDefault) || epocDeviceMatch) {
+ // Found a matching device
+ while (!(xml.isEndElement() && xml.name() == QLatin1String("device")) && !xml.atEnd()) {
+ xml.readNext();
+ if (xml.isStartElement() && xml.name() == QLatin1String("epocroot")) {
+ epocRootValue = xml.readElementText();
+ const QString deviceSource = epocDeviceValue.isEmpty()
+ ? QLatin1String("default device")
+ : QString(QLatin1String("EPOCDEVICE (") + epocDeviceValue + QLatin1String(")"));
+ checkEpocRootExists(deviceSource);
+ }
+ }
+
+ if (epocRootValue.isEmpty())
+ xml.raiseError(QLatin1String("No epocroot element found"));
+ }
+ }
+ }
+ } else {
+ xml.raiseError(QLatin1String("Invalid 'devices' element version"));
+ }
+ }
+ }
+ if (xml.hasError()) {
+ qWarning("Warning: Error \"%s\" when parsing devices.xml",
+ qPrintable(xml.errorString()));
+ } else {
+ if (epocRootValue.isEmpty()) {
+ if (!epocDeviceValue.isEmpty()) {
+ if (epocDeviceFound) {
+ qWarning("Warning: Missing or invalid epocroot attribute in device '%s' in devices.xml.",
+ qPrintable(epocDeviceValue));
+ } else {
+ qWarning("Warning: No device matching EPOCDEVICE (%s) in devices.xml.",
+ qPrintable(epocDeviceValue));
+ }
+ } else {
+ if (epocDeviceFound) {
+ qWarning("Warning: Missing or invalid epocroot attribute in default device in devices.xml.");
+ } else {
+ qWarning("Warning: No default device set in devices.xml.");
+ }
+ }
+ }
+ }
+ } else {
+ qWarning("Warning: Could not open file: '%s'.", qPrintable(devicesXmlPath));
+ }
+ }
+ }
+
+ if (epocRootValue.isEmpty()) {
+ // 5. An empty string is returned.
+ qWarning("Warning: failed to resolve epocroot."
+#ifdef Q_OS_WIN32
+ "\nEither\n"
+ " 1. Set EPOCROOT environment variable to a valid value.\n"
+ " or 2. Ensure that the HKEY_LOCAL_MACHINE\\" SYMBIAN_SDKS_REG_SUBKEY
+ " registry key is set, and then\n"
+ " a. Set EPOCDEVICE environment variable to a valid device\n"
+ " or b. Specify a default device in the devices.xml file.");
+#else
+ " Set EPOCROOT environment variable to a valid value.");
+#endif
+ } else {
+ fixEpocRoot(epocRootValue);
+ }
+ }
+
+ return epocRootValue;
+}
+
+QT_END_NAMESPACE
diff --git a/tools/shared/symbian/epocroot.pri b/tools/shared/symbian/epocroot.pri
new file mode 100644
index 0000000000..f0f0dab535
--- /dev/null
+++ b/tools/shared/symbian/epocroot.pri
@@ -0,0 +1,11 @@
+# Epocroot resolving is only required for tools, so omit it from all mobile/embedded builds
+!symbian:!wince*:!embedded {
+HEADERS += \
+ $$QT_SOURCE_TREE/tools/shared/symbian/epocroot_p.h \
+ $$QT_SOURCE_TREE/tools/shared/windows/registry_p.h
+SOURCES += \
+ $$QT_SOURCE_TREE/tools/shared/symbian/epocroot.cpp \
+ $$QT_SOURCE_TREE/tools/shared/windows/registry.cpp
+INCLUDEPATH += $$QT_SOURCE_TREE/tools/shared
+DEFINES += QLIBRARYINFO_EPOCROOT
+}
diff --git a/tools/shared/symbian/epocroot_p.h b/tools/shared/symbian/epocroot_p.h
new file mode 100644
index 0000000000..61197dc653
--- /dev/null
+++ b/tools/shared/symbian/epocroot_p.h
@@ -0,0 +1,83 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 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 QT_SYMBIAN_EPOCROOT_H
+#define QT_SYMBIAN_EPOCROOT_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 <QtCore/qstring.h>
+
+QT_BEGIN_NAMESPACE
+
+/**
+ * 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 qt_epocRoot();
+
+QT_END_NAMESPACE
+
+#endif // QT_SYMBIAN_EPOCROOT_H
+
diff --git a/tools/shared/windows/registry.cpp b/tools/shared/windows/registry.cpp
new file mode 100644
index 0000000000..87808c4060
--- /dev/null
+++ b/tools/shared/windows/registry.cpp
@@ -0,0 +1,169 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 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_p.h"
+
+QT_BEGIN_NAMESPACE
+
+#ifdef Q_OS_WIN32
+/*!
+ 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 == QLatin1String("Default") || res == QLatin1String("."))
+ res = QString();
+ return res;
+}
+#endif
+
+QString qt_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(QLatin1String(", "));
+ 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 %u type in windows registry", quint32(dataType));
+ break;
+ }
+
+ RegCloseKey(handle);
+#else
+ Q_UNUSED(parentHandle);
+ Q_UNUSED(rSubkey)
+#endif
+
+ return result;
+}
+
+QT_END_NAMESPACE
+
diff --git a/tools/shared/windows/registry_p.h b/tools/shared/windows/registry_p.h
new file mode 100644
index 0000000000..226cedc49e
--- /dev/null
+++ b/tools/shared/windows/registry_p.h
@@ -0,0 +1,80 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 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 QT_WINDOWS_REGISTRY_H
+#define QT_WINDOWS_REGISTRY_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.
+//
+
+QT_BEGIN_NAMESPACE
+
+#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 qt_readRegistryKey(HKEY parentHandle, const QString &rSubkey);
+
+QT_END_NAMESPACE
+
+#endif // QT_WINDOWS_REGISTRY_H
+