Ignore:
Timestamp:
May 5, 2011, 5:36:53 AM (14 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/tools/shared/symbian/epocroot.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    4040****************************************************************************/
    4141
    42 #include <iostream>
    43 
    4442#include <QtCore/qdir.h>
    4543#include <QtCore/qxmlstream.h>
    4644
    47 #include "epocroot.h"
    48 #include "../windows/registry.h"
     45#include "epocroot_p.h"
     46#include "../windows/registry_p.h"
     47
     48QT_BEGIN_NAMESPACE
    4949
    5050// Registry key under which the location of the Symbian devices.xml file is
     
    6565static QString epocRootValue;
    6666
    67 #ifdef QT_BUILD_QMAKE
    68 std::ostream &operator<<(std::ostream &s, const QString &val) {
    69     s << val.toLocal8Bit().data();
    70     return s;
    71 }
    72 #else
    73 // Operator implemented in configureapp.cpp
    74 std::ostream &operator<<(std::ostream &s, const QString &val);
    75 #endif
    76 
    77 QString getDevicesXmlPath()
     67static QString getDevicesXmlPath()
    7868    {
    7969    // Note that the following call will return a null string on platforms other
     
    8171    // an alternative mechanism for retrieving the location of this file will
    8272    // be required.
    83     return readRegistryKey(SYMBIAN_SDKS_REG_HANDLE, SYMBIAN_SDKS_REG_SUBKEY);
     73    return qt_readRegistryKey(SYMBIAN_SDKS_REG_HANDLE, QLatin1String(SYMBIAN_SDKS_REG_SUBKEY));
    8474    }
    8575
     
    8878 * If not, epocRootValue is set to an empty string and an error message is printed.
    8979 */
    90 void checkEpocRootExists(const QString &source)
     80static void checkEpocRootExists(const QString &source)
    9181{
    9282    if (!epocRootValue.isEmpty()) {
    9383        QDir dir(epocRootValue);
    9484        if (!dir.exists()) {
    95             std::cerr << "Warning: " << source << " is set to an invalid path: " << epocRootValue << std::endl;
     85            qWarning("Warning: %s is set to an invalid path: '%s'", qPrintable(source),
     86                     qPrintable(epocRootValue));
    9687            epocRootValue = QString();
    9788        }
     
    10495static void fixEpocRoot(QString &path)
    10596{
    106     path.replace("\\", "/");
    107 
    108     if (path.size() > 1 && path[1] == QChar(':')) {
    109         path = path.mid(2);
    110     }
    111 
    112     if (!path.size() || path[path.size()-1] != QChar('/')) {
    113         path += QChar('/');
     97    path.replace(QLatin1Char('\\'), QLatin1Char('/'));
     98
     99    if (!path.size() || path[path.size()-1] != QLatin1Char('/')) {
     100        path += QLatin1Char('/');
    114101    }
    115102}
     
    118105 * Determine the epoc root for the currently active SDK.
    119106 */
    120 QString epocRoot()
     107QString qt_epocRoot()
    121108{
    122109    if (epocRootValue.isEmpty()) {
    123110        // 1. If environment variable EPOCROOT is set and points to an existent
    124111        //    directory, this is returned.
    125         epocRootValue = qgetenv("EPOCROOT");
    126         checkEpocRootExists("EPOCROOT");
     112        epocRootValue = QString::fromLocal8Bit(qgetenv("EPOCROOT").constData());
     113        checkEpocRootExists(QLatin1String("EPOCROOT environment variable"));
    127114
    128115        if (epocRootValue.isEmpty()) {
     
    130117            //    file exists, it is parsed.
    131118            QString devicesXmlPath = getDevicesXmlPath();
    132             if (devicesXmlPath.isEmpty()) {
    133                 std::cerr << "Error: Symbian SDK registry key not found" << std::endl;
    134             } else {
    135                 devicesXmlPath += "/devices.xml";
     119            if (!devicesXmlPath.isEmpty()) {
     120                devicesXmlPath += QLatin1String("/devices.xml");
    136121                QFile devicesFile(devicesXmlPath);
    137122                if (devicesFile.open(QIODevice::ReadOnly)) {
     
    143128                    //    epocroot value points to an existent directory, this is returned.
    144129
    145                     const QString epocDeviceValue = qgetenv("EPOCDEVICE");
     130                    const QString epocDeviceValue = QString::fromLocal8Bit(qgetenv("EPOCDEVICE").constData());
    146131                    bool epocDeviceFound = false;
    147132
     
    149134                    while (!xml.atEnd()) {
    150135                        xml.readNext();
    151                         if (xml.isStartElement() && xml.name() == "devices") {
    152                             if (xml.attributes().value("version") == "1.0") {
    153                                 while (!(xml.isEndElement() && xml.name() == "devices") && !xml.atEnd()) {
     136                        if (xml.isStartElement() && xml.name() == QLatin1String("devices")) {
     137                            if (xml.attributes().value(QLatin1String("version")) == QLatin1String("1.0")) {
     138                                while (!(xml.isEndElement() && xml.name() == QLatin1String("devices")) && !xml.atEnd()) {
    154139                                    xml.readNext();
    155                                     if (xml.isStartElement() && xml.name() == "device") {
    156                                         const bool isDefault =  xml.attributes().value("default") == "yes";
    157                                         const QString id = xml.attributes().value("id").toString();
    158                                         const QString name =  xml.attributes().value("name").toString();
    159                                         const bool epocDeviceMatch = (id + ":" + name) == epocDeviceValue;
     140                                    if (xml.isStartElement() && xml.name() == QLatin1String("device")) {
     141                                        const bool isDefault = xml.attributes().value(QLatin1String("default")) == QLatin1String("yes");
     142                                        const QString id = xml.attributes().value(QLatin1String("id")).toString();
     143                                        const QString name = xml.attributes().value(QLatin1String("name")).toString();
     144                                        const QString alias = xml.attributes().value(QLatin1String("alias")).toString();
     145                                        bool epocDeviceMatch = QString(id + QLatin1String(":") + name) == epocDeviceValue;
     146                                        if (!alias.isEmpty())
     147                                            epocDeviceMatch |= alias == epocDeviceValue;
    160148                                        epocDeviceFound |= epocDeviceMatch;
    161149
    162150                                        if((epocDeviceValue.isEmpty() && isDefault) || epocDeviceMatch) {
    163151                                            // Found a matching device
    164                                             while (!(xml.isEndElement() && xml.name() == "device") && !xml.atEnd()) {
     152                                            while (!(xml.isEndElement() && xml.name() == QLatin1String("device")) && !xml.atEnd()) {
    165153                                                xml.readNext();
    166                                                 if (xml.isStartElement() && xml.name() == "epocroot") {
     154                                                if (xml.isStartElement() && xml.name() == QLatin1String("epocroot")) {
    167155                                                    epocRootValue = xml.readElementText();
    168156                                                    const QString deviceSource = epocDeviceValue.isEmpty()
    169                                                         ? "default device"
    170                                                         : "EPOCDEVICE (" + epocDeviceValue + ")";
     157                                                        ? QLatin1String("default device")
     158                                                        : QString(QLatin1String("EPOCDEVICE (") + epocDeviceValue + QLatin1String(")"));
    171159                                                    checkEpocRootExists(deviceSource);
    172160                                                }
     
    174162
    175163                                            if (epocRootValue.isEmpty())
    176                                                 xml.raiseError("No epocroot element found");
     164                                                xml.raiseError(QLatin1String("No epocroot element found"));
    177165                                        }
    178166                                    }
    179167                                }
    180168                            } else {
    181                                 xml.raiseError("Invalid 'devices' element version");
     169                                xml.raiseError(QLatin1String("Invalid 'devices' element version"));
    182170                            }
    183171                        }
    184172                    }
    185173                    if (xml.hasError()) {
    186                         std::cerr << "Error: \"" << xml.errorString() << "\" when parsing devices.xml" << std::endl;
     174                        qWarning("Warning: Error \"%s\" when parsing devices.xml",
     175                                 qPrintable(xml.errorString()));
    187176                    } else {
    188177                        if (epocRootValue.isEmpty()) {
    189178                            if (!epocDeviceValue.isEmpty()) {
    190179                                if (epocDeviceFound) {
    191                                     std::cerr << "Error: missing or invalid epocroot attribute "
    192                                               << "in device '" << epocDeviceValue << "'";
     180                                    qWarning("Warning: Missing or invalid epocroot attribute in device '%s' in devices.xml.",
     181                                             qPrintable(epocDeviceValue));
    193182                                } else {
    194                                     std::cerr << "Error: no device matching EPOCDEVICE ("
    195                                               << epocDeviceValue << ")";
     183                                    qWarning("Warning: No device matching EPOCDEVICE (%s) in devices.xml.",
     184                                             qPrintable(epocDeviceValue));
    196185                                }
    197186                            } else {
    198187                                if (epocDeviceFound) {
    199                                     std::cerr << "Error: missing or invalid epocroot attribute "
    200                                               << "in default device";
     188                                    qWarning("Warning: Missing or invalid epocroot attribute in default device in devices.xml.");
    201189                                } else {
    202                                     std::cerr << "Error: no default device";
     190                                    qWarning("Warning: No default device set in devices.xml.");
    203191                                }
    204192                            }
    205                             std::cerr << " found in devices.xml file." << std::endl;
    206193                        }
    207194                    }
    208195                } else {
    209                     std::cerr << "Error: could not open file " << devicesXmlPath << std::endl;
     196                    qWarning("Warning: Could not open file: '%s'.", qPrintable(devicesXmlPath));
    210197                }
    211198            }
     
    214201        if (epocRootValue.isEmpty()) {
    215202            // 5. An empty string is returned.
    216             std::cerr << "Error: failed to find epoc root" << std::endl
    217                  << "Either" << std::endl
    218                  << "    1. Set EPOCROOT environment variable to a valid value" << std::endl
    219                  << " or 2. Ensure that the HKEY_LOCAL_MACHINE\\" SYMBIAN_SDKS_REG_SUBKEY
    220                     " registry key is set, and then" << std::endl
    221                  << "       a. Set EPOCDEVICE environment variable to a valid device" << std::endl
    222                  << "    or b. Specify a default device in the devices.xml file." << std::endl;
     203            qWarning("Warning: failed to resolve epocroot."
     204#ifdef Q_OS_WIN32
     205                     "\nEither\n"
     206                     "    1. Set EPOCROOT environment variable to a valid value.\n"
     207                     " or 2. Ensure that the HKEY_LOCAL_MACHINE\\" SYMBIAN_SDKS_REG_SUBKEY
     208                     " registry key is set, and then\n"
     209                     "       a. Set EPOCDEVICE environment variable to a valid device\n"
     210                     "    or b. Specify a default device in the devices.xml file.");
     211#else
     212                     " Set EPOCROOT environment variable to a valid value.");
     213#endif
    223214        } else {
    224215            fixEpocRoot(epocRootValue);
     
    229220}
    230221
     222QT_END_NAMESPACE
Note: See TracChangeset for help on using the changeset viewer.