From 2f6a91642f2585c8b226011a0bb5a3725a012b15 Mon Sep 17 00:00:00 2001 From: Linus Jahn Date: Sun, 2 Oct 2022 03:52:21 +0200 Subject: Make EncryptedHttpFileSharingProvider able to handle not just http However it is still limited by the sources supported by EncryptedHttpFileSource. --- src/client/QXmppFileSharingManager.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src/client/QXmppFileSharingManager.cpp') diff --git a/src/client/QXmppFileSharingManager.cpp b/src/client/QXmppFileSharingManager.cpp index 30c0ac1e..fc73099c 100644 --- a/src/client/QXmppFileSharingManager.cpp +++ b/src/client/QXmppFileSharingManager.cpp @@ -312,13 +312,11 @@ std::shared_ptr QXmppFileSharingManager::downloadFile( }; fileShare.visitSources([&](const std::any &source) { - std::type_index index(source.type()); - try { - download->m_providerDownload = d->providers.at(index)->downloadFile(source, std::move(output), std::move(onProgress), std::move(onFinished)); + if (auto provider = providerForSource(source)) { + download->m_providerDownload = provider->downloadFile(source, std::move(output), std::move(onProgress), std::move(onFinished)); return true; - } catch (const std::out_of_range &) { - return false; } + return false; }); return download; @@ -329,4 +327,13 @@ void QXmppFileSharingManager::internalRegisterProvider(std::type_index index, st d->providers.insert_or_assign(index, provider); } +std::shared_ptr QXmppFileSharingManager::providerForSource(const std::any &source) const +{ + if (auto provider = d->providers.find(std::type_index(source.type())); + provider != d->providers.cend()) { + return provider->second; + } + return {}; +} + #include "QXmppFileSharingManager.moc" -- cgit v1.2.3