diff options
-rw-r--r-- | Swift/QtUI/QtChatView.cpp | 3 | ||||
-rw-r--r-- | Swift/QtUI/QtChatWindow.cpp | 8 | ||||
-rw-r--r-- | Swift/QtUI/Roster/QtRosterWidget.cpp | 2 | ||||
-rw-r--r-- | Swift/QtUI/Roster/QtTreeWidget.cpp | 2 | ||||
-rw-r--r-- | Swiften/Examples/NetworkTool/main.cpp | 4 | ||||
-rw-r--r-- | Swiften/Network/NATPMPInterface.h | 6 | ||||
-rw-r--r-- | Swiften/Network/WindowsNetworkEnvironment.cpp | 8 |
7 files changed, 20 insertions, 13 deletions
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 @@ -16,18 +16,19 @@ #include <QStackedWidget> #include <QTimer> #include <QMessageBox> #include <QApplication> #include <Swiften/Base/Log.h> #include "QtWebView.h" #include "QtChatTheme.h" +#include "QtSwiftUtil.h" namespace Swift { QtChatView::QtChatView(QtChatTheme* theme, QWidget* parent) : QWidget(parent), fontSizeSteps_(0) { theme_ = theme; QVBoxLayout* mainLayout = new QVBoxLayout(this); mainLayout->setSpacing(0); @@ -296,19 +297,19 @@ void QtChatView::setFileTransferProgress(QString id, const int percentageDone) { progressBar.setStyleProperty("width", QString::number(percentageDone) + "%"); QWebElement progressBarValue = ftElement.findFirst("div.progressbar-value"); progressBarValue.setInnerXml(QString::number(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; } QString newInnerHTML = ""; if (state == ChatWindow::WaitingForAccept) { newInnerHTML = "Waiting for other side to accept the transfer.<br/>" "<input id=\"discard\" type=\"submit\" value=\"Cancel\" onclick=\"filetransfer.cancel(\'" + id + "\');\">"; } if (state == ChatWindow::Negotiating) { 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 @@ -531,43 +531,43 @@ void QtChatWindow::setFileTransferProgress(std::string id, const int percentageD messageLog_->setFileTransferProgress(QString::fromStdString(id), percentageDone); } void QtChatWindow::setFileTransferStatus(std::string id, const FileTransferState state, const std::string& msg) { messageLog_->setFileTransferStatus(QString::fromStdString(id), state, QString::fromStdString(msg)); } void QtChatWindow::handleFileTransferCancel(QString id) { qDebug() << "QtChatWindow::handleFileTransferCancel(" << id << ")"; - onFileTransferCancel(id.toStdString()); + onFileTransferCancel(Q2PSTRING(id)); } void QtChatWindow::handleFileTransferSetDescription(QString id) { bool ok = false; QString text = QInputDialog::getText(this, tr("File transfer description"), tr("Description:"), QLineEdit::Normal, "", &ok); if (ok) { descriptions[id] = text; } } 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) { qDebug() << "QtChatWindow::handleFileTransferAccept(" << id << ", " << filename << ")"; QString path = QFileDialog::getSaveFileName(this, tr("Save File"), filename); if (!path.isEmpty()) { - onFileTransferAccept(id.toStdString(), path.toStdString()); + onFileTransferAccept(Q2PSTRING(id), Q2PSTRING(path)); } } void QtChatWindow::addErrorMessage(const std::string& errorMessage) { if (isWidgetSelected()) { onAllMessagesRead(); } QString errorMessageHTML(Qt::escape(P2QSTRING(errorMessage))); @@ -671,19 +671,19 @@ void QtChatWindow::moveEvent(QMoveEvent*) { void QtChatWindow::dragEnterEvent(QDragEnterEvent *event) { if (event->mimeData()->hasUrls() && event->mimeData()->urls().size() == 1) { // TODO: check whether contact actually supports file transfer event->acceptProposedAction(); } } 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."); } } void QtChatWindow::replaceLastMessage(const std::string& message) { messageLog_->replaceLastMessage(P2QSTRING(Linkify::linkify(message))); } 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 @@ -69,19 +69,19 @@ void QtRosterWidget::contextMenuEvent(QContextMenuEvent* event) { else if (result == removeContact) { if (QtContactEditWindow::confirmContactDeletion(contact->getJID())) { eventStream_->send(boost::make_shared<RemoveRosterItemUIEvent>(contact->getJID())); } } #ifdef SWIFT_EXPERIMENTAL_FT 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 } else if (GroupRosterItem* group = dynamic_cast<GroupRosterItem*>(item)) { QAction* renameGroupAction = contextMenu.addAction(tr("Rename")); QAction* result = contextMenu.exec(event->globalPos()); if (result == renameGroupAction) { renameGroup(group); 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 @@ -118,19 +118,19 @@ void QtTreeWidget::dragEnterEvent(QDragEnterEvent *event) { void QtTreeWidget::dropEvent(QDropEvent *event) { QModelIndex index = indexAt(event->pos()); if (index.isValid()) { RosterItem* item = static_cast<RosterItem*>(index.internalPointer()); if (ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item)) { 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))); } } } } } void QtTreeWidget::dragMoveEvent(QDragMoveEvent* event) { QModelIndex index = indexAt(event->pos()); if (index.isValid()) { 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 @@ -6,18 +6,19 @@ #include <iostream> #include <boost/lexical_cast.hpp> #include <Swiften/EventLoop/SimpleEventLoop.h> #include <Swiften/Network/PlatformNATTraversalWorker.h> #include <Swiften/Network/NATTraversalGetPublicIPRequest.h> #include <Swiften/Network/NATTraversalForwardPortRequest.h> #include <Swiften/Network/NATTraversalRemovePortForwardingRequest.h> +#include <Swiften/Network/PlatformNetworkEnvironment.h> using namespace Swift; SimpleEventLoop eventLoop; void handleGetPublicIPRequestResponse(const boost::optional<HostAddress>& result) { if (result) { std::cerr << "Result: " << result->toString() << std::endl;; } @@ -72,10 +73,13 @@ int main(int argc, char* argv[]) { else if (std::string(argv[1]) == "remove-port-forward") { if (argc < 4) { std::cerr << "Invalid parameters" << std::endl; } boost::shared_ptr<NATTraversalRemovePortForwardingRequest> query = natTraverser.createRemovePortForwardingRequest(boost::lexical_cast<int>(argv[2]), boost::lexical_cast<int>(argv[3])); query->onResult.connect(boost::bind(&handleRemovePortForwardingRequestResponse, _1)); 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 @@ -1,23 +1,25 @@ /* * Copyright (c) 2011 Remko Tronçon * Licensed under the simplified BSD license. * See Documentation/Licenses/BSD-simplified.txt for more information. */ #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: NATPMPInterface(); ~NATPMPInterface(); virtual bool isAvailable(); virtual boost::optional<HostAddress> getPublicIP(); 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 @@ -17,31 +17,31 @@ #include <winsock2.h> #include <iphlpapi.h> 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; } for (IP_ADAPTER_UNICAST_ADDRESS* address = adapter->FirstUnicastAddress; address; address = address->Next) { boost::optional<HostAddress> hostAddress; if (address->Address.lpSockaddr->sa_family == PF_INET) { sockaddr_in* sa = reinterpret_cast<sockaddr_in*>(address->Address.lpSockaddr); hostAddress = HostAddress(reinterpret_cast<const unsigned char*>(&(sa->sin_addr)), 4); |