diff --git a/src/app/global/utils.nim b/src/app/global/utils.nim index 319c77e4b7..775e030a4b 100644 --- a/src/app/global/utils.nim +++ b/src/app/global/utils.nim @@ -76,16 +76,6 @@ QtObject: proc generateAlias*(self: Utils, pk: string): string {.slot.} = return generateAliasFromPk(pk) - proc getFileSize*(self: Utils, filename: string): string {.slot.} = - var f: File = nil - if f.open(self.formatImagePath(filename)): - try: - result = $(f.getFileSize()) - finally: - close(f) - else: - raise newException(IOError, "cannot open: " & filename) - proc readTextFile*(self: Utils, filepath: string): string {.slot.} = try: return readFile(filepath) diff --git a/ui/StatusQ/include/StatusQ/QClipboardProxy.h b/ui/StatusQ/include/StatusQ/QClipboardProxy.h index 0cef650701..c24926bcdb 100644 --- a/ui/StatusQ/include/StatusQ/QClipboardProxy.h +++ b/ui/StatusQ/include/StatusQ/QClipboardProxy.h @@ -52,6 +52,9 @@ public: return new QClipboardProxy; } + Q_INVOKABLE bool isValidImageUrl(const QUrl &url, const QStringList &acceptedExtensions) const; + Q_INVOKABLE qint64 getFileSize(const QUrl &url) const; + signals: void contentChanged(); }; diff --git a/ui/StatusQ/src/QClipboardProxy.cpp b/ui/StatusQ/src/QClipboardProxy.cpp index c54b28f000..81c6787efe 100644 --- a/ui/StatusQ/src/QClipboardProxy.cpp +++ b/ui/StatusQ/src/QClipboardProxy.cpp @@ -6,6 +6,9 @@ #include #include #include +#include + +#include QClipboardProxy::QClipboardProxy() : m_clipboard(QGuiApplication::clipboard()) @@ -67,3 +70,19 @@ QList QClipboardProxy::urls() const { return m_clipboard->mimeData()->urls(); } + +bool QClipboardProxy::isValidImageUrl(const QUrl& url, const QStringList& acceptedExtensions) const +{ + const auto strippedUrl = url.url(QUrl::RemoveAuthority | QUrl::RemoveFragment | QUrl::RemoveQuery); + return std::any_of(acceptedExtensions.constBegin(), acceptedExtensions.constEnd(), [strippedUrl](const auto & ext) { + return strippedUrl.endsWith(ext); + }); +} + +qint64 QClipboardProxy::getFileSize(const QUrl& url) const +{ + if (url.isLocalFile()) { + return QFile(url.toLocalFile()).size(); + } + return 0; +}