mirror of
https://github.com/status-im/status-desktop.git
synced 2025-01-23 21:11:55 +00:00
fix(QClipboardProxy): use more reliable clipboard/DND checks
- getFileSize: NIM version would crash on non-existing or remote files - isValidImageUrl: properly detect file extensions when the URL contains a query (eg "file.jpeg?width=1000&height=600")
This commit is contained in:
parent
010640acd0
commit
b5a7df685a
@ -76,16 +76,6 @@ QtObject:
|
|||||||
proc generateAlias*(self: Utils, pk: string): string {.slot.} =
|
proc generateAlias*(self: Utils, pk: string): string {.slot.} =
|
||||||
return generateAliasFromPk(pk)
|
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.} =
|
proc readTextFile*(self: Utils, filepath: string): string {.slot.} =
|
||||||
try:
|
try:
|
||||||
return readFile(filepath)
|
return readFile(filepath)
|
||||||
|
@ -52,6 +52,9 @@ public:
|
|||||||
return new QClipboardProxy;
|
return new QClipboardProxy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Q_INVOKABLE bool isValidImageUrl(const QUrl &url, const QStringList &acceptedExtensions) const;
|
||||||
|
Q_INVOKABLE qint64 getFileSize(const QUrl &url) const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void contentChanged();
|
void contentChanged();
|
||||||
};
|
};
|
||||||
|
@ -6,6 +6,9 @@
|
|||||||
#include <QImage>
|
#include <QImage>
|
||||||
#include <QMimeData>
|
#include <QMimeData>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
#include <QFile>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
QClipboardProxy::QClipboardProxy()
|
QClipboardProxy::QClipboardProxy()
|
||||||
: m_clipboard(QGuiApplication::clipboard())
|
: m_clipboard(QGuiApplication::clipboard())
|
||||||
@ -67,3 +70,19 @@ QList<QUrl> QClipboardProxy::urls() const
|
|||||||
{
|
{
|
||||||
return m_clipboard->mimeData()->urls();
|
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;
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user