mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-15 13:47:05 +02:00
Decrease the amount of clipboard data retrievation
This commit is contained in:
parent
073c1a4d0f
commit
16669402cf
3 changed files with 17 additions and 18 deletions
|
@ -805,13 +805,13 @@ void SendFilesBox::captionResized() {
|
|||
}
|
||||
|
||||
bool SendFilesBox::canAddFiles(not_null<const QMimeData*> data) const {
|
||||
return (data->hasUrls() && CanAddUrls(base::GetMimeUrls(data))) || data->hasImage();
|
||||
return CanAddUrls(base::GetMimeUrls(data)) || data->hasImage();
|
||||
}
|
||||
|
||||
bool SendFilesBox::addFiles(not_null<const QMimeData*> data) {
|
||||
const auto premium = _controller->session().premium();
|
||||
auto list = [&] {
|
||||
const auto urls = data->hasUrls() ? base::GetMimeUrls(data) : QList<QUrl>();
|
||||
const auto urls = base::GetMimeUrls(data);
|
||||
auto result = CanAddUrls(urls)
|
||||
? Storage::PrepareMediaList(
|
||||
urls,
|
||||
|
|
|
@ -39,15 +39,17 @@ inline bool in_range(Value &&value, From &&from, Till &&till) {
|
|||
return (value >= from) && (value < till);
|
||||
}
|
||||
|
||||
inline auto GetMimeUrls(const QMimeData *data) {
|
||||
#if __has_include(<KUrlMimeData>)
|
||||
inline QList<QUrl> GetMimeUrls(const QMimeData *data) {
|
||||
if (!data->hasUrls()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
return KUrlMimeData::urlsFromMimeData(
|
||||
data,
|
||||
KUrlMimeData::PreferLocalUrls);
|
||||
#else
|
||||
return data->urls();
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#if __has_include(<KSandbox>) && defined DeclareReadSetting
|
||||
inline QString FlatpakID() {
|
||||
|
|
|
@ -88,14 +88,15 @@ void PrepareDetailsInParallel(PreparedList &result, int previewWidth) {
|
|||
} // namespace
|
||||
|
||||
bool ValidatePhotoEditorMediaDragData(not_null<const QMimeData*> data) {
|
||||
if (base::GetMimeUrls(data).size() > 1) {
|
||||
const auto urls = base::GetMimeUrls(data);
|
||||
if (urls.size() > 1) {
|
||||
return false;
|
||||
} else if (data->hasImage()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (data->hasUrls()) {
|
||||
const auto url = base::GetMimeUrls(data).front();
|
||||
if (!urls.isEmpty()) {
|
||||
const auto url = urls.front();
|
||||
if (url.isLocalFile()) {
|
||||
using namespace Core;
|
||||
const auto info = QFileInfo(Platform::File::UrlToLocal(url));
|
||||
|
@ -111,14 +112,15 @@ bool ValidatePhotoEditorMediaDragData(not_null<const QMimeData*> data) {
|
|||
bool ValidateEditMediaDragData(
|
||||
not_null<const QMimeData*> data,
|
||||
Ui::AlbumType albumType) {
|
||||
if (base::GetMimeUrls(data).size() > 1) {
|
||||
const auto urls = base::GetMimeUrls(data);
|
||||
if (urls.size() > 1) {
|
||||
return false;
|
||||
} else if (data->hasImage()) {
|
||||
return (albumType != Ui::AlbumType::Music);
|
||||
}
|
||||
|
||||
if (albumType == Ui::AlbumType::PhotoVideo && data->hasUrls()) {
|
||||
const auto url = base::GetMimeUrls(data).front();
|
||||
if (albumType == Ui::AlbumType::PhotoVideo && !urls.isEmpty()) {
|
||||
const auto url = urls.front();
|
||||
if (url.isLocalFile()) {
|
||||
using namespace Core;
|
||||
const auto info = QFileInfo(Platform::File::UrlToLocal(url));
|
||||
|
@ -138,12 +140,7 @@ MimeDataState ComputeMimeDataState(const QMimeData *data) {
|
|||
return MimeDataState::Image;
|
||||
}
|
||||
|
||||
const auto uriListFormat = qsl("text/uri-list");
|
||||
if (!data->hasFormat(uriListFormat)) {
|
||||
return MimeDataState::None;
|
||||
}
|
||||
|
||||
const auto &urls = base::GetMimeUrls(data);
|
||||
const auto urls = base::GetMimeUrls(data);
|
||||
if (urls.isEmpty()) {
|
||||
return MimeDataState::None;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue