aboutsummaryrefslogtreecommitdiff
path: root/room.cpp
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2018-02-03 12:12:04 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2018-02-03 12:12:04 +0900
commitc62180d910cc23b5360bbb0807d792f876f195a6 (patch)
tree656b744af4155b7b7c5f53e643367873d294bdde /room.cpp
parentb34368907cba52954849bfb0266e119e5563eeb7 (diff)
parentffb8233d1b6ac54e37391e1949697ba8f6828f47 (diff)
downloadlibquotient-c62180d910cc23b5360bbb0807d792f876f195a6.tar.gz
libquotient-c62180d910cc23b5360bbb0807d792f876f195a6.zip
Merge branch 'master' into kitsune-gtad
Diffstat (limited to 'room.cpp')
-rw-r--r--room.cpp53
1 files changed, 47 insertions, 6 deletions
diff --git a/room.cpp b/room.cpp
index bc7c083e..51da747e 100644
--- a/room.cpp
+++ b/room.cpp
@@ -99,7 +99,7 @@ class Room::Private
struct FileTransferPrivateInfo
{
-#if defined(_MSC_VER) && _MSC_VER < 1910
+#if (defined(_MSC_VER) && _MSC_VER < 1910) || (defined(__GNUC__) && __GNUC__ <= 4)
FileTransferPrivateInfo() = default;
FileTransferPrivateInfo(BaseJob* j, QString fileName)
: job(j), localFileInfo(fileName)
@@ -119,6 +119,9 @@ class Room::Private
if (p == 0)
p = -1;
}
+ if (p != -1)
+ qCDebug(PROFILER) << "Transfer progress:" << p << "/" << t
+ << "=" << llround(double(p) / t * 100) << "%";
progress = p; total = t;
}
};
@@ -543,6 +546,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);
@@ -561,7 +583,7 @@ FileTransferInfo Room::fileTransferInfo(const QString& id) const
total = INT_MAX;
}
-#if defined(_MSC_VER) && _MSC_VER < 1910
+#if (defined(_MSC_VER) && _MSC_VER < 1910) || (defined(__GNUC__) && __GNUC__ <= 4)
// A workaround for MSVC 2015 that fails with "error C2440: 'return':
// cannot convert from 'initializer list' to 'QMatrixClient::FileTransferInfo'"
FileTransferInfo fti;
@@ -790,8 +812,8 @@ QString Room::roomMembername(const User* u) const
// << "is not a member of the room" << id();
// }
- // In case of more than one namesake, disambiguate with user id.
- return username % " (" % u->id() % ")";
+ // In case of more than one namesake, use the full name to disambiguate
+ return u->fullName();
}
QString Room::roomMembername(const QString& userId) const
@@ -862,6 +884,17 @@ void Room::postMessage(const RoomMessageEvent& event)
connection()->callApi<SendEventJob>(id(), event);
}
+void Room::setName(const QString& newName)
+{
+ connection()->callApi<SetRoomStateJob>(id(), RoomNameEvent(newName));
+}
+
+void Room::setCanonicalAlias(const QString& newAlias)
+{
+ connection()->callApi<SetRoomStateJob>(id(),
+ RoomCanonicalAliasEvent(newAlias));
+}
+
void Room::setTopic(const QString& newTopic)
{
RoomTopicEvent evt(newTopic);
@@ -970,8 +1003,16 @@ 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());
+ if (QSysInfo::productType() == "windows")
+ {
+ const auto& suffixes = fileInfo->mimeType.suffixes();
+ if (!suffixes.isEmpty() &&
+ std::none_of(suffixes.begin(), suffixes.end(),
+ [fileName] (const QString& s) { return fileName.endsWith(s); }))
+ fileName += '.' + fileInfo->mimeType.preferredSuffix();
+ }
auto job = connection()->downloadFile(fileInfo->url, fileName);
if (isJobRunning(job))
{