tdesktop/Telegram/SourceFiles/core/mime_type.h
John Preston ff4af1b9bc 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.
2023-03-08 16:10:36 +04:00

72 lines
1.7 KiB
C++

/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
#include <QtCore/QFileInfo>
#include <QtCore/QString>
#include <QtCore/QStringList>
#include <QtCore/QMimeType>
#include <QtGui/QImage>
class QMimeData;
namespace Core {
class MimeType {
public:
enum class Known {
Unknown,
TDesktopTheme,
TDesktopPalette,
WebP,
Tgs,
Tgv,
};
explicit MimeType(const QMimeType &type);
explicit MimeType(Known type);
QStringList globPatterns() const;
QString filterString() const;
QString name() const;
private:
QMimeType _typeStruct;
Known _type = Known::Unknown;
};
[[nodiscard]] MimeType MimeTypeForName(const QString &mime);
[[nodiscard]] MimeType MimeTypeForFile(const QFileInfo &file);
[[nodiscard]] MimeType MimeTypeForData(const QByteArray &data);
[[nodiscard]] bool IsMimeStickerAnimated(const QString &mime);
[[nodiscard]] bool IsMimeSticker(const QString &mime);
[[nodiscard]] bool IsMimeAcceptedForPhotoVideoAlbum(const QString &mime);
[[nodiscard]] bool FileIsImage(const QString &name, const QString &mime);
[[nodiscard]] std::shared_ptr<QMimeData> ShareMimeMediaData(
not_null<const QMimeData*> original);
struct MimeImageData {
QImage image;
QByteArray content;
[[nodiscard]] bool empty() const {
return image.isNull();
}
explicit operator bool() const {
return !empty();
}
};
[[nodiscard]] MimeImageData ReadMimeImage(not_null<const QMimeData*> data);
[[nodiscard]] QString ReadMimeText(not_null<const QMimeData*> data);
[[nodiscard]] QList<QUrl> ReadMimeUrls(not_null<const QMimeData*> data);
} // namespace Core