aboutsummaryrefslogtreecommitdiff
path: root/src/base
diff options
context:
space:
mode:
Diffstat (limited to 'src/base')
-rw-r--r--src/base/QXmppFileShare.cpp23
-rw-r--r--src/base/QXmppFileShare.h10
-rw-r--r--src/base/QXmppUtils.cpp11
-rw-r--r--src/base/QXmppUtils_p.h1
4 files changed, 45 insertions, 0 deletions
diff --git a/src/base/QXmppFileShare.cpp b/src/base/QXmppFileShare.cpp
index 9dd4b686..28276b0c 100644
--- a/src/base/QXmppFileShare.cpp
+++ b/src/base/QXmppFileShare.cpp
@@ -125,6 +125,29 @@ void QXmppFileShare::setEncryptedSourecs(const QVector<QXmppEncryptedFileSource>
}
/// \cond
+void QXmppFileShare::visitSources(std::function<bool(const std::any &)> &&visitor) const
+{
+ for (const auto &httpSource : d->httpSources) {
+ if (visitor(httpSource)) {
+ return;
+ }
+ }
+ for (const auto &encryptedSource : d->encryptedSources) {
+ if (visitor(encryptedSource)) {
+ return;
+ }
+ }
+}
+
+void QXmppFileShare::addSource(const std::any &source)
+{
+ if (source.type() == typeid(QXmppHttpFileSource)) {
+ d->httpSources.push_back(std::any_cast<QXmppHttpFileSource>(source));
+ } else if (source.type() == typeid(QXmppEncryptedFileSource)) {
+ d->encryptedSources.push_back(std::any_cast<QXmppEncryptedFileSource>(source));
+ }
+}
+
bool QXmppFileShare::parse(const QDomElement &el)
{
if (el.tagName() == "file-sharing" && el.namespaceURI() == ns_sfs) {
diff --git a/src/base/QXmppFileShare.h b/src/base/QXmppFileShare.h
index b0d48bd3..b8506836 100644
--- a/src/base/QXmppFileShare.h
+++ b/src/base/QXmppFileShare.h
@@ -7,6 +7,9 @@
#include "QXmppGlobal.h"
+#include <any>
+#include <functional>
+
#include <QSharedDataPointer>
class QDomElement;
@@ -43,6 +46,13 @@ public:
/// \cond
bool parse(const QDomElement &el);
void toXml(QXmlStreamWriter *writer) const;
+
+protected:
+ friend class QXmppFileSharingManager;
+
+ // Private, internally used API:
+ void visitSources(std::function<bool(const std::any &)> &&visitor) const;
+ void addSource(const std::any &source);
/// \endcond
private:
diff --git a/src/base/QXmppUtils.cpp b/src/base/QXmppUtils.cpp
index 7ae74ba3..e0225d77 100644
--- a/src/base/QXmppUtils.cpp
+++ b/src/base/QXmppUtils.cpp
@@ -403,4 +403,15 @@ void QXmpp::Private::generateRandomBytes(uint8_t *bytes, uint32_t byteCount)
#endif
}
+float QXmpp::Private::calculateProgress(qint64 transferred, qint64 total)
+{
+ if (total > 0) {
+ if (transferred > total) {
+ return 1;
+ }
+ return float(transferred) / total;
+ }
+
+ return 0;
+}
/// \endcond
diff --git a/src/base/QXmppUtils_p.h b/src/base/QXmppUtils_p.h
index 9a7b6103..17a24634 100644
--- a/src/base/QXmppUtils_p.h
+++ b/src/base/QXmppUtils_p.h
@@ -16,6 +16,7 @@ namespace QXmpp::Private {
QXMPP_EXPORT QByteArray generateRandomBytes(uint32_t minimumByteCount, uint32_t maximumByteCount);
QXMPP_EXPORT void generateRandomBytes(uint8_t *bytes, uint32_t byteCount);
+float calculateProgress(qint64 transferred, qint64 total);
} // namespace QXmpp::Private