Fix pasting images from Firefox on Windows.

Fixes #10564.

Together with the image data Firefox sets to the clipboard an URLs list
which has a path to local temp file, created from that image.

Reading images from disk is slower + sometimes the content of the file
is wrong so for this case we prefer to read the image data directly.
This commit is contained in:
John Preston
2023-03-06 11:58:25 +04:00
parent c687882760
commit ff4af1b9bc
10 changed files with 70 additions and 34 deletions

View File

@@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "editor/editor_paint.h"
#include "core/mime_type.h"
#include "ui/boxes/confirm_box.h"
#include "editor/controllers/controllers.h"
#include "editor/scene/scene.h"
@@ -204,16 +205,17 @@ void Paint::handleMimeData(const QMimeData *data) {
using Error = Ui::PreparedList::Error;
const auto premium = false; // Don't support > 2GB files here.
auto result = data->hasUrls()
const auto list = Core::ReadMimeUrls(data);
auto result = !list.isEmpty()
? Storage::PrepareMediaList(
base::GetMimeUrls(data).mid(0, 1),
list.mid(0, 1),
_imageSize.width() / 2,
premium)
: Ui::PreparedList(Error::EmptyFile, QString());
if (result.error == Error::None) {
add(base::take(result.files.front().preview));
} else if (data->hasImage()) {
add(qvariant_cast<QImage>(data->imageData()));
} else if (auto read = Core::ReadMimeImage(data)) {
add(std::move(read.image));
}
}