summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Shienkov <denis.shienkov@gmail.com>2014-01-27 15:49:35 +0400
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-02-12 08:12:32 +0100
commit65dd36db940bd9b0c1806f66c54bb672b08eb9b8 (patch)
tree3416db9080185fac8745ea18e2bc71df6d7e4e49
parenta8597cbae47076e33b638c2e593f852c8c0a02d5 (diff)
downloadqtserialport-65dd36db940bd9b0c1806f66c54bb672b08eb9b8.tar.gz
Use QString for device properties
The device registry property of the SPDRP_HARDWAREID is not used any more. This property was used earlier for parsing of the VID/PID and had the type of the REG_MULTI_SZ which was interpreted as QStringList, see commit: d8dc10efb1714dcfafa6a08e107fd31fc1e3ce0e The current code is using only string based concept, hence changing the interface to QString. Tested on Windows 8 with on-board and virtual com0com serial ports using the cenumerator example. Change-Id: I31e4f85f1b145021c1b34b81ba890553604a0531 Reviewed-by: Laszlo Papp <lpapp@kde.org> Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
-rw-r--r--src/serialport/qserialportinfo_win.cpp65
1 files changed, 22 insertions, 43 deletions
diff --git a/src/serialport/qserialportinfo_win.cpp b/src/serialport/qserialportinfo_win.cpp
index e6296a2..85d40cc 100644
--- a/src/serialport/qserialportinfo_win.cpp
+++ b/src/serialport/qserialportinfo_win.cpp
@@ -46,15 +46,14 @@
#include "qserialport_win_p.h"
#ifndef Q_OS_WINCE
+#include <QtCore/quuid.h>
+#include <QtCore/qpair.h>
+#include <QtCore/qstringlist.h>
+
#include <initguid.h>
#include <setupapi.h>
#endif
-#include <QtCore/qvariant.h>
-#include <QtCore/qstringlist.h>
-#include <QtCore/quuid.h>
-#include <QtCore/qpair.h>
-
QT_BEGIN_NAMESPACE
#ifndef Q_OS_WINCE
@@ -104,47 +103,27 @@ static QStringList portNamesFromHardwareDeviceMap()
return result;
}
-static QVariant deviceRegistryProperty(HDEVINFO deviceInfoSet,
- PSP_DEVINFO_DATA deviceInfoData,
- DWORD property)
+static QString deviceRegistryProperty(HDEVINFO deviceInfoSet,
+ PSP_DEVINFO_DATA deviceInfoData,
+ DWORD property)
{
DWORD dataType = 0;
- DWORD dataSize = 0;
- ::SetupDiGetDeviceRegistryProperty(deviceInfoSet, deviceInfoData,
- property, &dataType, NULL, 0, &dataSize);
- QByteArray data(dataSize, 0);
- if (!::SetupDiGetDeviceRegistryProperty(deviceInfoSet, deviceInfoData, property, NULL,
- reinterpret_cast<unsigned char*>(data.data()),
- dataSize, NULL)
- || !dataSize) {
- return QVariant();
- }
-
- switch (dataType) {
-
- case REG_EXPAND_SZ:
- case REG_SZ: {
- return QVariant(QString::fromWCharArray(reinterpret_cast<const wchar_t *>(data.constData())));
- }
-
- case REG_MULTI_SZ: {
- QStringList list;
- int i = 0;
- forever {
- QString s = QString::fromWCharArray(reinterpret_cast<const wchar_t *>(data.constData()) + i);
- i += s.length() + 1;
- if (s.isEmpty())
- break;
- list.append(s);
+ QByteArray devicePropertyByteArray;
+ DWORD requiredSize = 0;
+ forever {
+ if (::SetupDiGetDeviceRegistryProperty(deviceInfoSet, deviceInfoData, property, &dataType,
+ reinterpret_cast<unsigned char *>(devicePropertyByteArray.data()),
+ devicePropertyByteArray.size(), &requiredSize)) {
+ break;
}
- return QVariant(list);
- }
- default:
- break;
+ if (::GetLastError() != ERROR_INSUFFICIENT_BUFFER
+ || (dataType != REG_SZ && dataType != REG_EXPAND_SZ)) {
+ return QString();
+ }
+ devicePropertyByteArray.resize(requiredSize);
}
-
- return QVariant();
+ return QString::fromWCharArray(reinterpret_cast<const wchar_t *>(devicePropertyByteArray.constData()));
}
static QString deviceInstanceIdentifier(HDEVINFO deviceInfoSet,
@@ -253,9 +232,9 @@ QList<QSerialPortInfo> QSerialPortInfo::availablePorts()
serialPortInfo.d_ptr->portName = s;
serialPortInfo.d_ptr->device = QSerialPortPrivate::portNameToSystemLocation(s);
serialPortInfo.d_ptr->description =
- deviceRegistryProperty(deviceInfoSet, &deviceInfoData, SPDRP_DEVICEDESC).toString();
+ deviceRegistryProperty(deviceInfoSet, &deviceInfoData, SPDRP_DEVICEDESC);
serialPortInfo.d_ptr->manufacturer =
- deviceRegistryProperty(deviceInfoSet, &deviceInfoData, SPDRP_MFG).toString();
+ deviceRegistryProperty(deviceInfoSet, &deviceInfoData, SPDRP_MFG);
s = deviceInstanceIdentifier(deviceInfoSet, &deviceInfoData).toUpper();