datatransfer: omit download path when accepting file transfers

Change-Id: I5b1310a53199ee787aa3d2a8d93dc0ca16940ce9
parent 38ba6ed7
......@@ -66,18 +66,18 @@ public:
qlonglong& total,
qlonglong& progress);
QString accept(const QString& accountId,
const QString& fileId,
const QString& file_path,
std::size_t offset);
QString accept(const QString& accountId, const QString& fileId, const QString& filePath = {});
void download(const QString& accountId,
const QString& convId,
const QString& interactionId,
const QString& fileId,
const QString& path);
const QString& filePath = {});
void copyTo(const QString& accountId, const QString& convId, const QString& interactionId, const QString& destPath);
void copyTo(const QString& accountId,
const QString& convId,
const QString& interactionId,
const QString& destPath);
void cancel(const QString& accountId, const QString& conversationId, const QString& fileId);
......
......@@ -3646,24 +3646,25 @@ ConversationModelPimpl::acceptTransfer(const QString& convUid,
const QString& interactionId,
const QString& path)
{
auto destinationDir = linked.owner.accountModel->downloadDirectory;
if (destinationDir.isEmpty()) {
return;
}
auto& conversation = getConversationForUid(convUid).get();
if (conversation.isNotASwarm()) {
// This is a fallback, will be removed when swarm will be mandatory
auto destinationDir = linked.owner.accountModel->downloadDirectory;
if (destinationDir.isEmpty()) {
return;
}
#ifdef Q_OS_WIN
if (destinationDir.right(1) != '/') {
destinationDir += "/";
}
if (destinationDir.right(1) != '/') {
destinationDir += "/";
}
#endif
QDir dir = QFileInfo(destinationDir + path).absoluteDir();
if (!dir.exists())
dir.mkpath(".");
auto& conversation = getConversationForUid(convUid).get();
if (conversation.mode == conversation::Mode::NON_SWARM) {
QDir dir = QFileInfo(destinationDir + path).absoluteDir();
if (!dir.exists())
dir.mkpath(".");
auto acceptedFilePath = linked.owner.dataTransferModel->accept(linked.owner.id,
interactionId,
destinationDir + path,
0);
destinationDir + path);
auto fileId = linked.owner.dataTransferModel->getFileIdFromInteractionId(interactionId);
if (transfIdToDbIntId.find(fileId) != transfIdToDbIntId.end()) {
auto dbInteractionId = transfIdToDbIntId[fileId];
......@@ -3705,35 +3706,12 @@ ConversationModelPimpl::acceptTransfer(const QString& convUid,
auto interaction = conversation.interactions.find(interactionId);
if (interaction != conversation.interactions.end()) {
auto displayName = interaction->second.commit["displayName"];
auto fileId = interaction->second.commit["fileId"];
if (fileId.isEmpty()) {
qWarning() << "Cannot download file without fileId";
}
if (displayName.isEmpty()) {
displayName = interactionId;
}
int i = 0;
auto path = destinationDir + displayName;
do {
if (i > 0) {
path = destinationDir + QString::number(i) + displayName;
}
QFileInfo fi(path);
if (!fi.isFile())
break;
++i;
} while (i < 1000);
if (i == 1000) {
qWarning() << "Too much duplicates for " << destinationDir << path;
return;
}
linked.owner.dataTransferModel->download(linked.owner.id,
convUid,
interactionId,
fileId,
path);
linked.owner.dataTransferModel->download(linked.owner.id, convUid, interactionId, fileId);
} else {
qWarning() << "Cannot download file without valid interaction";
}
......
......@@ -204,15 +204,12 @@ DataTransferModel::fileTransferInfo(const QString& accountId,
}
QString
DataTransferModel::accept(const QString& accountId,
const QString& fileId,
const QString& file_path,
std::size_t)
DataTransferModel::accept(const QString& accountId, const QString& fileId, const QString& filePath)
{
auto unique_file_path = pimpl_->getUniqueFilePath(file_path);
auto dring_id = pimpl_->interactionToFileId[fileId];
ConfigurationManager::instance().acceptFileTransfer(accountId, dring_id, unique_file_path);
return unique_file_path;
auto uniqueFilePath = pimpl_->getUniqueFilePath(filePath);
auto daemonFileId = pimpl_->interactionToFileId[fileId];
ConfigurationManager::instance().acceptFileTransfer(accountId, daemonFileId, uniqueFilePath);
return uniqueFilePath;
}
void
......@@ -226,7 +223,10 @@ DataTransferModel::download(const QString& accountId,
}
void
DataTransferModel::copyTo(const QString& accountId, const QString& convId, const QString& interactionId, const QString& destPath)
DataTransferModel::copyTo(const QString& accountId,
const QString& convId,
const QString& interactionId,
const QString& destPath)
{
auto fileId = getFileIdFromInteractionId(interactionId);
if (fileId.isEmpty()) {
......@@ -248,7 +248,6 @@ DataTransferModel::copyTo(const QString& accountId, const QString& convId, const
src.copy(dest);
}
void
DataTransferModel::cancel(const QString& accountId,
const QString& conversationId,
......
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