summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/QtUI')
-rw-r--r--Swift/QtUI/QtChatView.h5
-rw-r--r--Swift/QtUI/QtChatWindow.cpp4
-rw-r--r--Swift/QtUI/QtChatWindow.h2
-rw-r--r--Swift/QtUI/QtPlainChatView.cpp12
-rw-r--r--Swift/QtUI/QtPlainChatView.h7
-rw-r--r--Swift/QtUI/QtWebKitChatView.cpp18
-rw-r--r--Swift/QtUI/QtWebKitChatView.h2
7 files changed, 33 insertions, 17 deletions
diff --git a/Swift/QtUI/QtChatView.h b/Swift/QtUI/QtChatView.h
index 75e38e2..e1d2e1a 100644
--- a/Swift/QtUI/QtChatView.h
+++ b/Swift/QtUI/QtChatView.h
@@ -7,8 +7,9 @@
#pragma once
#include <string>
-#include <boost/shared_ptr.hpp>
+
#include <boost/date_time/posix_time/posix_time.hpp>
+#include <boost/shared_ptr.hpp>
#include <QWidget>
@@ -43,7 +44,7 @@ namespace Swift {
virtual void replaceLastMessage(const ChatWindow::ChatMessage& message, const ChatWindow::TimestampBehaviour /*timestampBehaviour*/) = 0;
virtual void setAckState(const std::string& id, ChatWindow::AckState state) = 0;
- virtual std::string addFileTransfer(const std::string& senderName, bool senderIsSelf, const std::string& filename, const boost::uintmax_t sizeInBytes) = 0;
+ virtual std::string addFileTransfer(const std::string& senderName, bool senderIsSelf, const std::string& filename, const boost::uintmax_t sizeInBytes, const std::string& description) = 0;
virtual void setFileTransferProgress(std::string, const int percentageDone) = 0;
virtual void setFileTransferStatus(std::string, const ChatWindow::FileTransferState state, const std::string& msg = "") = 0;
virtual void addMUCInvitation(const std::string& senderName, const JID& jid, const std::string& reason, const std::string& password, bool direct, bool isImpromptu, bool isContinuation) = 0;
diff --git a/Swift/QtUI/QtChatWindow.cpp b/Swift/QtUI/QtChatWindow.cpp
index abbfae5..caa556f 100644
--- a/Swift/QtUI/QtChatWindow.cpp
+++ b/Swift/QtUI/QtChatWindow.cpp
@@ -906,9 +906,9 @@ void QtChatWindow::replaceWithAction(const ChatMessage& message, const std::stri
messageLog_->replaceWithAction(message, id, time, highlight);
}
-std::string QtChatWindow::addFileTransfer(const std::string& senderName, bool senderIsSelf, const std::string& filename, const boost::uintmax_t sizeInBytes) {
+std::string QtChatWindow::addFileTransfer(const std::string& senderName, bool senderIsSelf, const std::string& filename, const boost::uintmax_t sizeInBytes, const std::string& description) {
handleAppendedToLog();
- return messageLog_->addFileTransfer(senderName, senderIsSelf, filename, sizeInBytes);
+ return messageLog_->addFileTransfer(senderName, senderIsSelf, filename, sizeInBytes, description);
}
void QtChatWindow::setFileTransferProgress(std::string id, const int percentageDone) {
diff --git a/Swift/QtUI/QtChatWindow.h b/Swift/QtUI/QtChatWindow.h
index bbcdee7..121192a 100644
--- a/Swift/QtUI/QtChatWindow.h
+++ b/Swift/QtUI/QtChatWindow.h
@@ -90,7 +90,7 @@ namespace Swift {
void replaceMessage(const ChatMessage& message, const std::string& id, const boost::posix_time::ptime& time, const HighlightAction& highlight);
void replaceWithAction(const ChatMessage& message, const std::string& id, const boost::posix_time::ptime& time, const HighlightAction& highlight);
// File transfer related stuff
- std::string addFileTransfer(const std::string& senderName, bool senderIsSelf, const std::string& filename, const boost::uintmax_t sizeInBytes);
+ std::string addFileTransfer(const std::string& senderName, bool senderIsSelf, const std::string& filename, const boost::uintmax_t sizeInBytes, const std::string& description);
void setFileTransferProgress(std::string id, const int percentageDone);
void setFileTransferStatus(std::string id, const FileTransferState state, const std::string& msg);
diff --git a/Swift/QtUI/QtPlainChatView.cpp b/Swift/QtUI/QtPlainChatView.cpp
index e062efc..a794167 100644
--- a/Swift/QtUI/QtPlainChatView.cpp
+++ b/Swift/QtUI/QtPlainChatView.cpp
@@ -177,7 +177,7 @@ void QtPlainChatView::setAckState(const std::string& /*id*/, ChatWindow::AckStat
}
}
-std::string QtPlainChatView::addFileTransfer(const std::string& senderName, bool senderIsSelf, const std::string& filename, const boost::uintmax_t sizeInBytes)
+std::string QtPlainChatView::addFileTransfer(const std::string& senderName, bool senderIsSelf, const std::string& filename, const boost::uintmax_t sizeInBytes, const std::string& description)
{
const std::string ftId = "ft" + boost::lexical_cast<std::string>(idGenerator_++);
const std::string sizeString = formatSize(sizeInBytes);
@@ -187,11 +187,13 @@ std::string QtPlainChatView::addFileTransfer(const std::string& senderName, bool
QString description = QInputDialog::getText(this, tr("File transfer description"),
tr("Description:"), QLineEdit::Normal, "");
/* NOTE: it is not possible to abort if description is not provided, since we must always return a valid transfer id */
- const std::string message = std::string() + "Confirm file transfer: <i>" + filename + " (" + sizeString + " bytes)</i>";
+ const std::string descriptionMessage = description.isEmpty() ? "" : (" \"" + Q2PSTRING(description) + "\"");
+ const std::string message = std::string() + "Confirm file transfer: <i>" + filename + " (" + sizeString + " bytes)</i>" + descriptionMessage;
transfer = new FileTransfer(this, senderIsSelf, ftId, filename, ChatWindow::WaitingForAccept, Q2PSTRING(description), message, true);
addSystemMessage(ChatWindow::ChatMessage("Preparing to start file transfer..."), ChatWindow::DefaultDirection);
} else { /* incoming transfer */
- const std::string message = std::string() + "Incoming file transfer: <i>" + filename + " (" + sizeString + " bytes)</i>";
+ const std::string descriptionMessage = description.empty() ? "" : (" \"" + description + "\"");
+ const std::string message = std::string() + "Incoming file transfer: <i>" + filename + " (" + sizeString + " bytes)</i>" + descriptionMessage;
transfer = new FileTransfer(this, senderIsSelf, ftId, filename, ChatWindow::WaitingForAccept, "", message, true);
addSystemMessage("Incoming file transfer from " + senderName + "...", ChatWindow::DefaultDirection);
}
@@ -285,6 +287,8 @@ void QtPlainChatView::fileTransferAccept()
FileTransfer* transfer = transferIter->second;
+ const std::string message = transfer->message_;
+
if (transfer->senderIsSelf_) { /* if we are the sender, kick of the transfer */
window_->onFileTransferStart(transfer->ftId_, transfer->description_);
} else { /* ask the user where to save the file first */
@@ -296,7 +300,7 @@ void QtPlainChatView::fileTransferAccept()
window_->onFileTransferAccept(transfer->ftId_, Q2PSTRING(path));
}
- setFileTransferStatus(transfer->ftId_, ChatWindow::Negotiating, transfer->message_);
+ setFileTransferStatus(transfer->ftId_, ChatWindow::Negotiating, message);
}
void QtPlainChatView::fileTransferReject()
diff --git a/Swift/QtUI/QtPlainChatView.h b/Swift/QtUI/QtPlainChatView.h
index 782944f..aeb50b6 100644
--- a/Swift/QtUI/QtPlainChatView.h
+++ b/Swift/QtUI/QtPlainChatView.h
@@ -7,11 +7,12 @@
#pragma once
#include <string>
-#include <boost/shared_ptr.hpp>
+
#include <boost/date_time/posix_time/posix_time.hpp>
+#include <boost/shared_ptr.hpp>
-#include <QWidget>
#include <QTextEdit>
+#include <QWidget>
#include <Swift/Controllers/UIInterfaces/ChatWindow.h>
@@ -50,7 +51,7 @@ namespace Swift {
virtual void replaceSystemMessage(const ChatWindow::ChatMessage& message, const std::string& id, const ChatWindow::TimestampBehaviour /*timestampBehaviour*/);
virtual void setAckState(const std::string& /*id*/, ChatWindow::AckState /*state*/);
- virtual std::string addFileTransfer(const std::string& /*senderName*/, bool /*senderIsSelf*/, const std::string& /*filename*/, const boost::uintmax_t /*sizeInBytes*/);
+ virtual std::string addFileTransfer(const std::string& /*senderName*/, bool /*senderIsSelf*/, const std::string& /*filename*/, const boost::uintmax_t /*sizeInBytes*/, const std::string& /*description*/);
virtual void setFileTransferProgress(std::string, const int /*percentageDone*/);
virtual void setFileTransferStatus(std::string, const ChatWindow::FileTransferState /*state*/, const std::string& /*msg*/ = "");
virtual void addMUCInvitation(const std::string& /*senderName*/, const JID& /*jid*/, const std::string& /*reason*/, const std::string& /*password*/, bool /*direct*/, bool /*isImpromptu*/, bool /*isContinuation*/);
diff --git a/Swift/QtUI/QtWebKitChatView.cpp b/Swift/QtUI/QtWebKitChatView.cpp
index 7e0e505..260da8a 100644
--- a/Swift/QtUI/QtWebKitChatView.cpp
+++ b/Swift/QtUI/QtWebKitChatView.cpp
@@ -441,6 +441,11 @@ void QtWebKitChatView::setFileTransferStatus(QString id, const ChatWindow::FileT
QString newInnerHTML = "";
if (state == ChatWindow::Initialisation) {
+ QWebElement filenameSizeDescriptionElement = ftElement.parent().firstChild();
+ QString description = QtUtilities::htmlEscape(descriptions_[id]);
+ if (!description.isEmpty()) {
+ filenameSizeDescriptionElement.prependOutside(QString(" \"%1\"").arg(description));
+ }
newInnerHTML = tr("Preparing to transfer.") + "<br/>" +
buildChatWindowButton(tr("Cancel"), ButtonFileTransferCancel, id);
}
@@ -660,17 +665,19 @@ QString QtWebKitChatView::buildChatWindowButton(const QString& name, const QStri
return html;
}
-std::string QtWebKitChatView::addFileTransfer(const std::string& senderName, bool senderIsSelf, const std::string& filename, const boost::uintmax_t sizeInBytes) {
+std::string QtWebKitChatView::addFileTransfer(const std::string& senderName, bool senderIsSelf, const std::string& filename, const boost::uintmax_t sizeInBytes, const std::string& description) {
SWIFT_LOG(debug) << "addFileTransfer" << std::endl;
QString ft_id = QString("ft%1").arg(P2QSTRING(boost::lexical_cast<std::string>(idCounter_++)));
QString actionText;
QString htmlString;
QString formattedFileSize = P2QSTRING(formatSize(sizeInBytes));
+ QString sanitizedFileName = QtUtilities::htmlEscape(P2QSTRING(filename));
+ QString sanitizedDescription = QtUtilities::htmlEscape(P2QSTRING(description));
if (senderIsSelf) {
// outgoing
- filePaths_[ft_id] = P2QSTRING(filename);
- actionText = tr("Send file: %1 (%2)").arg(P2QSTRING(filename)).arg(formattedFileSize);
+ filePaths_[ft_id] = sanitizedFileName;
+ actionText = tr("Send file: %1 (%2)").arg(sanitizedFileName).arg(formattedFileSize);
htmlString = actionText + " <br/>" +
"<div id='" + ft_id + "'>" +
buildChatWindowButton(tr("Cancel"), ButtonFileTransferCancel, ft_id) +
@@ -679,7 +686,10 @@ std::string QtWebKitChatView::addFileTransfer(const std::string& senderName, boo
"</div>";
} else {
// incoming
- actionText = tr("Receiving file: %1 (%2)").arg(P2QSTRING(filename)).arg(formattedFileSize);
+ actionText = tr("Receiving file: %1 (%2)").arg(sanitizedFileName).arg(formattedFileSize);
+ if (!sanitizedDescription.isEmpty()) {
+ actionText += QString(" \"%1\"").arg(sanitizedDescription);
+ }
htmlString = actionText + " <br/>" +
"<div id='" + ft_id + "'>" +
buildChatWindowButton(tr("Cancel"), ButtonFileTransferCancel, ft_id) +
diff --git a/Swift/QtUI/QtWebKitChatView.h b/Swift/QtUI/QtWebKitChatView.h
index af2da01..99375f7 100644
--- a/Swift/QtUI/QtWebKitChatView.h
+++ b/Swift/QtUI/QtWebKitChatView.h
@@ -66,7 +66,7 @@ namespace Swift {
virtual void replaceLastMessage(const ChatWindow::ChatMessage& message, const ChatWindow::TimestampBehaviour timestampBehaviour) SWIFTEN_OVERRIDE;
virtual void setAckState(const std::string& id, ChatWindow::AckState state) SWIFTEN_OVERRIDE;
- virtual std::string addFileTransfer(const std::string& senderName, bool senderIsSelf, const std::string& filename, const boost::uintmax_t sizeInBytes) SWIFTEN_OVERRIDE;
+ virtual std::string addFileTransfer(const std::string& senderName, bool senderIsSelf, const std::string& filename, const boost::uintmax_t sizeInBytes, const std::string& description) SWIFTEN_OVERRIDE;
virtual void setFileTransferProgress(std::string, const int percentageDone) SWIFTEN_OVERRIDE;
virtual void setFileTransferStatus(std::string, const ChatWindow::FileTransferState state, const std::string& msg = "") SWIFTEN_OVERRIDE;
virtual void addMUCInvitation(const std::string& senderName, const JID& jid, const std::string& reason, const std::string& password, bool direct, bool isImpromptu, bool isContinuation) SWIFTEN_OVERRIDE;