fileTransfer: use displayName for copy to downloads

Change-Id: I85cf4c66c9959342e2f28c270311614ee17a015d
parent 00c8256e
......@@ -77,7 +77,8 @@ public:
void copyTo(const QString& accountId,
const QString& convId,
const QString& interactionId,
const QString& destPath);
const QString& destPath,
const QString& displayName);
void cancel(const QString& accountId, const QString& conversationId, const QString& fileId);
......
......@@ -94,19 +94,17 @@ DataTransferModel::Impl::Impl(DataTransferModel& up_link)
QString
DataTransferModel::Impl::getUniqueFilePath(const QString& filename, const QString& path)
{
auto wantedDest = filename;
QString base(wantedDest);
QString ext = QFileInfo(wantedDest).completeSuffix();
if (!ext.isEmpty()) {
auto base = filename;
QString ext = QFileInfo(base).completeSuffix();
if (!ext.isEmpty())
ext = ext.prepend(".");
}
if (!path.isEmpty()) {
QFileInfo fi(filename);
wantedDest = QDir(path).filePath(fi.baseName() + ext);
}
if (!QFile::exists(wantedDest)) {
return wantedDest;
}
QFileInfo fi(filename);
auto p = !path.isEmpty() ? path : fi.dir().path();
base = QDir(p).filePath(fi.baseName() + ext);
if (!QFile::exists(base))
return base;
base.chop(ext.size());
QString ret;
for (int suffix = 1;; suffix++) {
......@@ -226,7 +224,8 @@ void
DataTransferModel::copyTo(const QString& accountId,
const QString& convId,
const QString& interactionId,
const QString& destPath)
const QString& destPath,
const QString& displayName)
{
auto fileId = getFileIdFromInteractionId(interactionId);
if (fileId.isEmpty()) {
......@@ -243,8 +242,11 @@ DataTransferModel::copyTo(const QString& accountId,
if (!src.exists())
return;
auto realPath = srcfi.isSymLink() ? srcfi.symLinkTarget() : path;
auto dest = pimpl_->getUniqueFilePath(realPath, destPath);
auto filename = displayName;
if (displayName.isEmpty())
filename = srcfi.isSymLink() ? srcfi.symLinkTarget() : path;
auto dest = pimpl_->getUniqueFilePath(filename, destPath);
qDebug() << "Copy to " << dest;
src.copy(dest);
}
......
......@@ -1331,7 +1331,7 @@ function updateFileInteraction(message_div, message_object, forceTypeToFile = fa
if (!message_div.querySelector(`.dropdown_${message_id}`)) {
if (!is_swarm || message_delivery_status === "finished") {
var message_dropdown = buildMessageDropdown(message_id)
var message_dropdown = buildMessageDropdown(message_id, message_object["displayName"])
message_div.appendChild(message_dropdown)
}
}
......@@ -1649,7 +1649,7 @@ function textInteraction(message_id, message_direction, htmlText) {
* Build message dropdown
* @return a message dropdown for passed message id
*/
function buildMessageDropdown(message_id) {
function buildMessageDropdown(message_id, display_name) {
const menu_element = document.createElement("div")
menu_element.setAttribute("class", "menu_interaction")
menu_element.innerHTML =
......@@ -1684,11 +1684,12 @@ function buildMessageDropdown(message_id) {
save.innerHTML = i18n.gettext("Copy to downloads")
}
save.msg_id = message_id
save.display_name = display_name
save.onclick = function () {
if (use_qt) {
window.jsbridge.copyToDownloads(`${this.msg_id}`)
window.jsbridge.copyToDownloads(this.msg_id, this.display_name)
} else {
window.prompt(`COPY:${this.msg_id}`)
window.prompt(`COPY:${this.msg_id}:${this.display_name}`)
}
}
dropdown.appendChild(save)
......@@ -1915,7 +1916,7 @@ function buildNewMessage(message_object) {
}
if (!message_div.querySelector(`.dropdown_${message_id}`)) {
if (is_swarm && delivery_status === "finished") {
var message_dropdown = buildMessageDropdown(message_id)
var message_dropdown = buildMessageDropdown(message_id, message_object["displayName"])
message_div.appendChild(message_dropdown)
}
}
......@@ -1949,7 +1950,6 @@ function buildNewMessage(message_object) {
message_div.appendChild(temp)
}
if (message_type !== "typing" && !is_swarm && !message_div.querySelector(`.dropdown_${message_id}`)) {
var message_dropdown = buildMessageDropdown(message_id)
message_div.appendChild(message_dropdown)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment