summaryrefslogtreecommitdiffstats
path: root/src/serialport/qserialportinfo_unix.cpp
diff options
context:
space:
mode:
authorDenis Shienkov <denis.shienkov@gmail.com>2014-11-24 18:21:57 +0300
committerDenis Shienkov <denis.shienkov@gmail.com>2014-11-27 11:19:43 +0100
commitab51ad6a5f4e533c31bd8e5b6f16a3bcd09a3ee6 (patch)
tree783f2a4cccc2fcc420bef5557bf8b47aa10049d6 /src/serialport/qserialportinfo_unix.cpp
parenta00cbfb7f336a56b9ae2235c44149ec63ced9ee5 (diff)
Allow to use custom devices paths
QSP incorrectly transforms non-standard device names to their paths and vice-versa (for example, "/home/ttyS0", "//./COM1", and so on). Now this problem is solved: * The transformation code is moved to QSPP. * Added autotests auto/qserialportinfoprivate to testing of conversion algorithm. These tests are private and can be activated with building of QtSerialPort with: qmake "QT_CONFIG+=private_tests warnings_are_errors" \ DEFINES+=QT_BUILD_INTERNAL Tested on Windows 8, Linux, OSX with auto-tests, with on-board and virtual serial ports. Task-number: QTBUG-38639 Change-Id: I43757a7f1390f53ed2b1d70de59c6bfb71892a59 Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
Diffstat (limited to 'src/serialport/qserialportinfo_unix.cpp')
-rw-r--r--src/serialport/qserialportinfo_unix.cpp18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/serialport/qserialportinfo_unix.cpp b/src/serialport/qserialportinfo_unix.cpp
index 7322a3c8..96375816 100644
--- a/src/serialport/qserialportinfo_unix.cpp
+++ b/src/serialport/qserialportinfo_unix.cpp
@@ -100,7 +100,7 @@ QList<QSerialPortInfo> availablePortsByFiltersOfDevices()
foreach (const QString &deviceFilePath, filteredDeviceFilePaths()) {
QSerialPortInfoPrivate priv;
priv.device = deviceFilePath;
- priv.portName = QSerialPortPrivate::portNameFromSystemLocation(deviceFilePath);
+ priv.portName = QSerialPortInfoPrivate::portNameFromSystemLocation(deviceFilePath);
serialPortInfoList.append(priv);
}
@@ -202,7 +202,7 @@ QList<QSerialPortInfo> availablePortsBySysfs()
}
priv.portName = targetPath.mid(lastIndexOfSlash + 1);
- priv.device = QSerialPortPrivate::portNameToSystemLocation(priv.portName);
+ priv.device = QSerialPortInfoPrivate::portNameToSystemLocation(priv.portName);
serialPortInfoList.append(priv);
}
@@ -401,4 +401,18 @@ bool QSerialPortInfo::isValid() const
return f.exists();
}
+QString QSerialPortInfoPrivate::portNameToSystemLocation(const QString &source)
+{
+ return (source.startsWith(QLatin1Char('/'))
+ || source.startsWith(QStringLiteral("./"))
+ || source.startsWith(QStringLiteral("../")))
+ ? source : (QStringLiteral("/dev/") + source);
+}
+
+QString QSerialPortInfoPrivate::portNameFromSystemLocation(const QString &source)
+{
+ return source.startsWith(QStringLiteral("/dev/"))
+ ? source.mid(5) : source;
+}
+
QT_END_NAMESPACE