diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-02-01 17:03:14 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-02-01 17:03:14 +0900 |
commit | 2eb0cace848d7d0415a69be9159cfdf6b1bf1117 (patch) | |
tree | c503c8b0d2edda443ff457625ae49284223e565b /room.cpp | |
parent | a375af174a73b6dc77c4f6e06ceb1a0e910af3a9 (diff) | |
download | libquotient-2eb0cace848d7d0415a69be9159cfdf6b1bf1117.tar.gz libquotient-2eb0cace848d7d0415a69be9159cfdf6b1bf1117.zip |
Room::fileNameToDownload: get a sensible initial name for the file picker
Works (at least, should work) with both Qt Widgets and QML.
Diffstat (limited to 'room.cpp')
-rw-r--r-- | room.cpp | 23 |
1 files changed, 21 insertions, 2 deletions
@@ -543,6 +543,25 @@ void Room::resetHighlightCount() emit highlightCountChanged(this); } +QString Room::fileNameToDownload(const QString& eventId) +{ + auto evtIt = findInTimeline(eventId); + if (evtIt != timelineEdge() && + evtIt->event()->type() == EventType::RoomMessage) + { + auto* event = static_cast<const RoomMessageEvent*>(evtIt->event()); + if (event->hasFileContent()) + { + auto* fileInfo = event->content()->fileInfo(); + return !fileInfo->originalName.isEmpty() ? fileInfo->originalName : + !event->plainBody().isEmpty() ? event->plainBody() : + QString(); + } + } + qWarning() << "No files to download in event" << eventId; + return {}; +} + FileTransferInfo Room::fileTransferInfo(const QString& id) const { auto infoIt = d->fileTransfers.find(id); @@ -981,8 +1000,8 @@ void Room::downloadFile(const QString& eventId, const QUrl& localFilename) auto fileName = !localFilename.isEmpty() ? localFilename.toLocalFile() : !fileInfo->originalName.isEmpty() ? (safeTempPrefix + fileInfo->originalName) : - !event->plainBody().isEmpty() ? - (safeTempPrefix + event->plainBody()) : QString(); + !event->plainBody().isEmpty() ? (safeTempPrefix + event->plainBody()) : + (safeTempPrefix + fileInfo->mimeType.preferredSuffix()); auto job = connection()->downloadFile(fileInfo->url, fileName); if (isJobRunning(job)) { |