Ignore:
Timestamp:
Aug 2, 2010, 9:27:30 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

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

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/tools/configure/environment.cpp

    r651 r769  
    6161#endif
    6262
     63#include <symbian/epocroot.h> // from tools/shared
     64#include <windows/registry.h> // from tools/shared
    6365
    6466QT_BEGIN_NAMESPACE
     
    9597        ++i;
    9698    return &(compiler_info[i]);
    97 }
    98 
    99 /*!
    100     Returns the path part of a registry key.
    101     Ei.
    102         For a key
    103             "Software\\Microsoft\\VisualStudio\\8.0\\Setup\\VC\\ProductDir"
    104         it returns
    105             "Software\\Microsoft\\VisualStudio\\8.0\\Setup\\VC\\"
    106 */
    107 QString Environment::keyPath(const QString &rKey)
    108 {
    109     int idx = rKey.lastIndexOf(QLatin1Char('\\'));
    110     if (idx == -1)
    111         return QString();
    112     return rKey.left(idx + 1);
    113 }
    114 
    115 /*!
    116     Returns the name part of a registry key.
    117     Ei.
    118         For a key
    119             "Software\\Microsoft\\VisualStudio\\8.0\\Setup\\VC\\ProductDir"
    120         it returns
    121             "ProductDir"
    122 */
    123 QString Environment::keyName(const QString &rKey)
    124 {
    125     int idx = rKey.lastIndexOf(QLatin1Char('\\'));
    126     if (idx == -1)
    127         return rKey;
    128 
    129     QString res(rKey.mid(idx + 1));
    130     if (res == "Default" || res == ".")
    131         res = "";
    132     return res;
    133 }
    134 
    135 /*!
    136     Returns a registry keys value in string form.
    137     If the registry key does not exist, or cannot be accessed, a
    138     QString() is returned.
    139 */
    140 QString Environment::readRegistryKey(HKEY parentHandle, const QString &rSubkey)
    141 {
    142 #ifndef Q_OS_WIN32
    143     return QString();
    144 #else
    145     QString rSubkeyName = keyName(rSubkey);
    146     QString rSubkeyPath = keyPath(rSubkey);
    147 
    148     HKEY handle = 0;
    149     LONG res = RegOpenKeyEx(parentHandle, (wchar_t*)rSubkeyPath.utf16(), 0, KEY_READ, &handle);
    150     if (res != ERROR_SUCCESS)
    151         return QString();
    152 
    153     // get the size and type of the value
    154     DWORD dataType;
    155     DWORD dataSize;
    156     res = RegQueryValueEx(handle, (wchar_t*)rSubkeyName.utf16(), 0, &dataType, 0, &dataSize);
    157     if (res != ERROR_SUCCESS) {
    158         RegCloseKey(handle);
    159         return QString();
    160     }
    161 
    162     // get the value
    163     QByteArray data(dataSize, 0);
    164     res = RegQueryValueEx(handle, (wchar_t*)rSubkeyName.utf16(), 0, 0,
    165                            reinterpret_cast<unsigned char*>(data.data()), &dataSize);
    166     if (res != ERROR_SUCCESS) {
    167         RegCloseKey(handle);
    168         return QString();
    169     }
    170 
    171     QString result;
    172     switch (dataType) {
    173         case REG_EXPAND_SZ:
    174         case REG_SZ: {
    175             result = QString::fromWCharArray(((const wchar_t *)data.constData()));
    176             break;
    177         }
    178 
    179         case REG_MULTI_SZ: {
    180             QStringList l;
    181             int i = 0;
    182             for (;;) {
    183                 QString s = QString::fromWCharArray((const wchar_t *)data.constData() + i);
    184                 i += s.length() + 1;
    185 
    186                 if (s.isEmpty())
    187                     break;
    188                 l.append(s);
    189             }
    190             result = l.join(", ");
    191             break;
    192         }
    193 
    194         case REG_NONE:
    195         case REG_BINARY: {
    196             result = QString::fromWCharArray((const wchar_t *)data.constData(), data.size() / 2);
    197             break;
    198         }
    199 
    200         case REG_DWORD_BIG_ENDIAN:
    201         case REG_DWORD: {
    202             Q_ASSERT(data.size() == sizeof(int));
    203             int i;
    204             memcpy((char*)&i, data.constData(), sizeof(int));
    205             result = QString::number(i);
    206             break;
    207         }
    208 
    209         default:
    210             qWarning("QSettings: unknown data %d type in windows registry", dataType);
    211             break;
    212     }
    213 
    214     RegCloseKey(handle);
    215     return result;
    216 #endif
    21799}
    218100
     
    580462}
    581463
     464QString Environment::symbianEpocRoot()
     465{
     466    // Call function defined in tools/shared/symbian/epocroot.h
     467    return ::epocRoot();
     468}
     469
    582470QT_END_NAMESPACE
Note: See TracChangeset for help on using the changeset viewer.