From df7019870dec125bea54f820c204e3794104e9dd Mon Sep 17 00:00:00 2001
From: Claudiu Olteanu <olteanu.claudiu@ymail.com>
Date: Sat, 19 Sep 2015 19:14:51 +0300
Subject: [PATCH 1/2] Fix Bluetooth address truncation issues on Windows

On some Windows platforms when we convert a Bth address to a String
it is formatted as "(XX:XX:XX:XX:XX:XX)". Therefore we first try to
remove the round parentheses and finally we truncate the string
to 17 because there are 6 two-digit hex values and 5 colons.

Signed-off-by: Claudiu Olteanu <olteanu.claudiu@ymail.com>
---
 qt-ui/btdeviceselectiondialog.cpp | 8 ++++----
 qt-ui/btdeviceselectiondialog.h   | 1 +
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/qt-ui/btdeviceselectiondialog.cpp b/qt-ui/btdeviceselectiondialog.cpp
index 74afda6..40d5731 100644
--- a/qt-ui/btdeviceselectiondialog.cpp
+++ b/qt-ui/btdeviceselectiondialog.cpp
@@ -609,14 +609,14 @@ void WinBluetoothDeviceDiscoveryAgent::run()
 				break;
 			}
 
-			// Save the name of the discovered device and truncate the address
-			QString deviceName = QString(pResults->lpszServiceInstanceName);
-			deviceAddress.truncate(addressSize / sizeof(wchar_t));
-
 			// Remove the round parentheses
 			deviceAddress.remove(')');
 			deviceAddress.remove('(');
 
+			// Save the name of the discovered device and truncate the address
+			QString deviceName = QString(pResults->lpszServiceInstanceName);
+			deviceAddress.truncate(BTH_ADDR_PRETTY_STRING_LEN);
+
 			// Create an object with information about the discovered device
 			QBluetoothDeviceInfo deviceInfo = QBluetoothDeviceInfo(QBluetoothAddress(deviceAddress), deviceName, 0);
 
diff --git a/qt-ui/btdeviceselectiondialog.h b/qt-ui/btdeviceselectiondialog.h
index 3d72db4..d947d34 100644
--- a/qt-ui/btdeviceselectiondialog.h
+++ b/qt-ui/btdeviceselectiondialog.h
@@ -15,6 +15,7 @@
 
 	#define SUCCESS				0
 	#define BTH_ADDR_STR_LEN                40
+	#define BTH_ADDR_PRETTY_STRING_LEN	17	// there are 6 two-digit hex values and 5 colons
 
 	#undef ERROR				// this is already declared in our headers
 	#undef IGNORE				// this is already declared in our headers
-- 
2.4.3

