From 75818abb4baa26649baf8d3bf6709aefcda7195f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Remko=20Tron=C3=A7on?= <remko@synopsys.com>
Date: Fri, 30 Sep 2011 19:10:20 +0200
Subject: Fixed some Windows issues with FT.


diff --git a/Swift/QtUI/QtChatView.cpp b/Swift/QtUI/QtChatView.cpp
index cb7f901..7bb5818 100644
--- a/Swift/QtUI/QtChatView.cpp
+++ b/Swift/QtUI/QtChatView.cpp
@@ -22,6 +22,7 @@
 
 #include "QtWebView.h"
 #include "QtChatTheme.h"
+#include "QtSwiftUtil.h"
 
 
 namespace Swift {
@@ -302,7 +303,7 @@ void QtChatView::setFileTransferProgress(QString id, const int percentageDone) {
 void QtChatView::setFileTransferStatus(QString id, const ChatWindow::FileTransferState state, const QString& /* msg */) {
 	QWebElement ftElement = findDivElementWithID(document_, id);
 	if (ftElement.isNull()) {
-		SWIFT_LOG(debug) << "Tried to access FT UI via invalid id! id = " << id.toStdString() << std::endl;
+		SWIFT_LOG(debug) << "Tried to access FT UI via invalid id! id = " << Q2PSTRING(id) << std::endl;
 		return;
 	}
 
diff --git a/Swift/QtUI/QtChatWindow.cpp b/Swift/QtUI/QtChatWindow.cpp
index 496c42c..07ff47e 100644
--- a/Swift/QtUI/QtChatWindow.cpp
+++ b/Swift/QtUI/QtChatWindow.cpp
@@ -537,7 +537,7 @@ void QtChatWindow::setFileTransferStatus(std::string id, const FileTransferState
 
 void QtChatWindow::handleFileTransferCancel(QString id) {
 	qDebug() << "QtChatWindow::handleFileTransferCancel(" << id << ")";
-	onFileTransferCancel(id.toStdString());
+	onFileTransferCancel(Q2PSTRING(id));
 }
 
 void QtChatWindow::handleFileTransferSetDescription(QString id) {
@@ -553,7 +553,7 @@ void QtChatWindow::handleFileTransferStart(QString id) {
 	qDebug() << "QtChatWindow::handleFileTransferStart(" << id << ")";
 	
 	QString text = descriptions.find(id) == descriptions.end() ? QString() : descriptions[id];
-	onFileTransferStart(id.toStdString(), text.toStdString());
+	onFileTransferStart(Q2PSTRING(id), Q2PSTRING(text));
 }
 
 void QtChatWindow::handleFileTransferAccept(QString id, QString filename) {
@@ -561,7 +561,7 @@ void QtChatWindow::handleFileTransferAccept(QString id, QString filename) {
 
 	QString path = QFileDialog::getSaveFileName(this, tr("Save File"), filename);
 	if (!path.isEmpty()) {
-		onFileTransferAccept(id.toStdString(), path.toStdString());
+		onFileTransferAccept(Q2PSTRING(id), Q2PSTRING(path));
 	}
 }
 
@@ -677,7 +677,7 @@ void QtChatWindow::dragEnterEvent(QDragEnterEvent *event) {
 
 void QtChatWindow::dropEvent(QDropEvent *event) {
 	if (event->mimeData()->urls().size() == 1) {
-		onSendFileRequest(event->mimeData()->urls().at(0).toLocalFile().toStdString());
+		onSendFileRequest(Q2PSTRING(event->mimeData()->urls().at(0).toLocalFile()));
 	} else {
 		addSystemMessage("Sending of multiple files at once isn't supported at this time.");
 	}
diff --git a/Swift/QtUI/Roster/QtRosterWidget.cpp b/Swift/QtUI/Roster/QtRosterWidget.cpp
index 3d9b273..4c96695 100644
--- a/Swift/QtUI/Roster/QtRosterWidget.cpp
+++ b/Swift/QtUI/Roster/QtRosterWidget.cpp
@@ -75,7 +75,7 @@ void QtRosterWidget::contextMenuEvent(QContextMenuEvent* event) {
 		else if (sendFile && result == sendFile) {
 			QString fileName = QFileDialog::getOpenFileName(this, tr("Send File"), "", tr("All Files (*);;"));
 			if (!fileName.isEmpty()) {
-				eventStream_->send(boost::make_shared<SendFileUIEvent>(contact->getJID(), fileName.toStdString()));
+				eventStream_->send(boost::make_shared<SendFileUIEvent>(contact->getJID(), Q2PSTRING(fileName)));
 			}
 		}
 #endif
diff --git a/Swift/QtUI/Roster/QtTreeWidget.cpp b/Swift/QtUI/Roster/QtTreeWidget.cpp
index 2e37ba2..690515d 100644
--- a/Swift/QtUI/Roster/QtTreeWidget.cpp
+++ b/Swift/QtUI/Roster/QtTreeWidget.cpp
@@ -124,7 +124,7 @@ void QtTreeWidget::dropEvent(QDropEvent *event) {
 			if (contact->supportsFeature(ContactRosterItem::FileTransferFeature)) {
 				QString filename = event->mimeData()->urls().at(0).toLocalFile();
 				if (!filename.isEmpty()) {
-					eventStream_->send(boost::make_shared<SendFileUIEvent>(contact->getJID(), filename.toStdString()));
+					eventStream_->send(boost::make_shared<SendFileUIEvent>(contact->getJID(), Q2PSTRING(filename)));
 				}
 			}
 		}
diff --git a/Swiften/Examples/NetworkTool/main.cpp b/Swiften/Examples/NetworkTool/main.cpp
index fa19e14..ace38fd 100644
--- a/Swiften/Examples/NetworkTool/main.cpp
+++ b/Swiften/Examples/NetworkTool/main.cpp
@@ -12,6 +12,7 @@
 #include <Swiften/Network/NATTraversalGetPublicIPRequest.h>
 #include <Swiften/Network/NATTraversalForwardPortRequest.h>
 #include <Swiften/Network/NATTraversalRemovePortForwardingRequest.h>
+#include <Swiften/Network/PlatformNetworkEnvironment.h>
 
 using namespace Swift;
 
@@ -78,4 +79,7 @@ int main(int argc, char* argv[]) {
 		query->run();
 		eventLoop.run();
 	}
+	else if (std::string(argv[1]) == "get-local-ip") {
+		std::cout << PlatformNetworkEnvironment().getLocalAddress().toString() << std::endl;
+	}
 }
diff --git a/Swiften/Network/NATPMPInterface.h b/Swiften/Network/NATPMPInterface.h
index 55f5b87..6e7fb73 100644
--- a/Swiften/Network/NATPMPInterface.h
+++ b/Swiften/Network/NATPMPInterface.h
@@ -7,11 +7,13 @@
 #pragma once
 
 #include <boost/optional.hpp>
-#include <natpmp.h>
-
 #include <Swiften/Network/NATPortMapping.h>
 #include <Swiften/Network/NATTraversalInterface.h>
 
+// This has to be included after the previous headers, because of WIN32 macro
+// being defined somewhere.
+#include <natpmp.h>
+
 namespace Swift {
 	class NATPMPInterface : public NATTraversalInterface {
 		public:
diff --git a/Swiften/Network/WindowsNetworkEnvironment.cpp b/Swiften/Network/WindowsNetworkEnvironment.cpp
index a202015..20f559d 100644
--- a/Swiften/Network/WindowsNetworkEnvironment.cpp
+++ b/Swiften/Network/WindowsNetworkEnvironment.cpp
@@ -23,19 +23,19 @@ namespace Swift {
 std::vector<NetworkInterface> WindowsNetworkEnvironment::getNetworkInterfaces()  const {
 	std::vector<NetworkInterface> result;
 
-	std::vector<IP_ADAPTER_ADDRESSES> adapters;
+	ByteArray adapters;
 	ULONG bufferSize = 0;
 	ULONG ret;
 	ULONG flags = GAA_FLAG_INCLUDE_ALL_INTERFACES | GAA_FLAG_INCLUDE_PREFIX | GAA_FLAG_SKIP_MULTICAST | GAA_FLAG_SKIP_DNS_SERVER;
-	while ((ret = GetAdaptersAddresses(AF_UNSPEC, flags, NULL, vecptr(adapters), &bufferSize)) == ERROR_BUFFER_OVERFLOW) {
-		adapters.resize(bufferSize / sizeof(IP_ADAPTER_ADDRESSES));
+	while ((ret = GetAdaptersAddresses(AF_UNSPEC, flags, NULL, reinterpret_cast<IP_ADAPTER_ADDRESSES*>(vecptr(adapters)), &bufferSize)) == ERROR_BUFFER_OVERFLOW) {
+		adapters.resize(bufferSize);
 	};
 	if (ret != ERROR_SUCCESS) {
 		return result;
 	}
 
 	std::map<std::string,NetworkInterface> interfaces;
-	for (IP_ADAPTER_ADDRESSES* adapter = vecptr(adapters); adapter; adapter = adapter->Next) {
+	for (IP_ADAPTER_ADDRESSES* adapter = reinterpret_cast<IP_ADAPTER_ADDRESSES*>(vecptr(adapters)); adapter; adapter = adapter->Next) {
 		std::string name(adapter->AdapterName);
 		if (adapter->OperStatus != IfOperStatusUp) {
 			continue;
-- 
cgit v0.10.2-6-g49f6