ClipboardUtils: isValidImageUrl and isValidImageUrl excluded to UrlUtils
This commit is contained in:
parent
9311ebe7fe
commit
781133238a
|
@ -123,6 +123,7 @@ add_library(StatusQ SHARED
|
|||
include/StatusQ/sumaggregator.h
|
||||
include/StatusQ/systemutilsinternal.h
|
||||
include/StatusQ/undefinedfilter.h
|
||||
include/StatusQ/urlutils.h
|
||||
include/StatusQ/writableproxymodel.h
|
||||
src/aggregator.cpp
|
||||
src/clipboardutils.cpp
|
||||
|
@ -155,6 +156,7 @@ add_library(StatusQ SHARED
|
|||
src/sumaggregator.cpp
|
||||
src/systemutilsinternal.cpp
|
||||
src/undefinedfilter.cpp
|
||||
src/urlutils.cpp
|
||||
src/writableproxymodel.cpp
|
||||
|
||||
# wallet
|
||||
|
|
|
@ -52,8 +52,6 @@ public:
|
|||
return new ClipboardUtils;
|
||||
}
|
||||
|
||||
Q_INVOKABLE bool isValidImageUrl(const QUrl &url, const QStringList &acceptedExtensions) const;
|
||||
Q_INVOKABLE qint64 getFileSize(const QUrl &url) const;
|
||||
Q_INVOKABLE void copyTextToClipboard(const QString& text);
|
||||
Q_INVOKABLE void clear();
|
||||
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class QQmlEngine;
|
||||
class QJSEngine;
|
||||
|
||||
class UrlUtils : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static QObject* qmlInstance(QQmlEngine* engine, QJSEngine* scriptEngine);
|
||||
|
||||
Q_INVOKABLE static bool isValidImageUrl(const QUrl &url,
|
||||
const QStringList &acceptedExtensions);
|
||||
Q_INVOKABLE static qint64 getFileSize(const QUrl &url);
|
||||
};
|
|
@ -72,22 +72,6 @@ QList<QUrl> ClipboardUtils::urls() const
|
|||
return m_clipboard->mimeData()->urls();
|
||||
}
|
||||
|
||||
bool ClipboardUtils::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, Qt::CaseInsensitive);
|
||||
});
|
||||
}
|
||||
|
||||
qint64 ClipboardUtils::getFileSize(const QUrl& url) const
|
||||
{
|
||||
if (url.isLocalFile()) {
|
||||
return QFile(url.toLocalFile()).size();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ClipboardUtils::copyTextToClipboard(const QString &text)
|
||||
{
|
||||
m_clipboard->setText(text);
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include "StatusQ/sumaggregator.h"
|
||||
#include "StatusQ/systemutilsinternal.h"
|
||||
#include "StatusQ/undefinedfilter.h"
|
||||
#include "StatusQ/urlutils.h"
|
||||
#include "StatusQ/writableproxymodel.h"
|
||||
|
||||
#include "wallet/managetokenscontroller.h"
|
||||
|
@ -78,6 +79,8 @@ public:
|
|||
qmlRegisterType<FormattedDoubleProperty>("StatusQ", 0, 1, "FormattedDoubleProperty");
|
||||
|
||||
qmlRegisterSingletonType<ClipboardUtils>("StatusQ", 0, 1, "QClipboardProxy", &ClipboardUtils::qmlInstance);
|
||||
qmlRegisterSingletonType<UrlUtils>("StatusQ", 0, 1, "UrlUtils", &UrlUtils::qmlInstance);
|
||||
|
||||
qmlRegisterType<ModelEntry>("StatusQ", 0, 1, "ModelEntry");
|
||||
qmlRegisterType<SnapshotObject>("StatusQ", 0, 1, "SnapshotObject");
|
||||
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
#include "StatusQ/urlutils.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QUrl>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
QObject* UrlUtils::qmlInstance(QQmlEngine*, QJSEngine*)
|
||||
{
|
||||
return new UrlUtils;
|
||||
}
|
||||
|
||||
bool UrlUtils::isValidImageUrl(const QUrl& url, const QStringList& acceptedExtensions)
|
||||
{
|
||||
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, Qt::CaseInsensitive);
|
||||
});
|
||||
}
|
||||
|
||||
qint64 UrlUtils::getFileSize(const QUrl& url)
|
||||
{
|
||||
if (url.isLocalFile())
|
||||
return QFile(url.toLocalFile()).size();
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -338,14 +338,14 @@ QtObject {
|
|||
|
||||
function isValidDragNDropImage(url) {
|
||||
return url.startsWith(Constants.dataImagePrefix) ||
|
||||
QClipboardProxy.isValidImageUrl(url, Constants.acceptedDragNDropImageExtensions)
|
||||
UrlUtils.isValidImageUrl(url, Constants.acceptedDragNDropImageExtensions)
|
||||
}
|
||||
|
||||
function isFilesizeValid(img) {
|
||||
if (img.startsWith(Constants.dataImagePrefix)) {
|
||||
return img.length < maxImgSizeBytes
|
||||
}
|
||||
const size = QClipboardProxy.getFileSize(img)
|
||||
const size = UrlUtils.getFileSize(img)
|
||||
return size <= maxImgSizeBytes
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue