2018-10-23 09:44:42 +00:00
|
|
|
/*
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
#include "ui/image/image_source.h"
|
|
|
|
|
2019-12-04 12:15:58 +00:00
|
|
|
#include "storage/cache/storage_cache_database.h"
|
|
|
|
#include "storage/file_download_mtproto.h"
|
|
|
|
#include "storage/file_download_web.h"
|
2018-10-23 09:44:42 +00:00
|
|
|
#include "data/data_session.h"
|
2019-01-04 11:09:48 +00:00
|
|
|
#include "data/data_file_origin.h"
|
2018-10-23 09:44:42 +00:00
|
|
|
#include "history/history_item.h"
|
|
|
|
#include "history/history.h"
|
2019-07-24 11:45:24 +00:00
|
|
|
#include "main/main_session.h"
|
2019-09-13 06:06:02 +00:00
|
|
|
#include "app.h"
|
2018-10-23 09:44:42 +00:00
|
|
|
|
2019-09-04 07:19:15 +00:00
|
|
|
#include <QtCore/QBuffer>
|
|
|
|
|
2018-10-23 09:44:42 +00:00
|
|
|
namespace Images {
|
2020-05-29 14:08:18 +00:00
|
|
|
namespace {
|
2018-10-23 09:44:42 +00:00
|
|
|
|
2020-05-29 14:08:18 +00:00
|
|
|
[[nodiscard]] QByteArray ReadContent(const QString &path) {
|
|
|
|
auto file = QFile(path);
|
|
|
|
const auto good = (file.size() <= App::kImageSizeLimit)
|
|
|
|
&& file.open(QIODevice::ReadOnly);
|
|
|
|
return good ? file.readAll() : QByteArray();
|
2018-10-23 09:44:42 +00:00
|
|
|
}
|
|
|
|
|
2020-05-29 14:08:18 +00:00
|
|
|
[[nodiscard]] QImage ReadImage(const QByteArray &content) {
|
|
|
|
return App::readImage(content, nullptr, false, nullptr);
|
2018-10-23 09:44:42 +00:00
|
|
|
}
|
|
|
|
|
2020-05-29 14:08:18 +00:00
|
|
|
} // namespace
|
2018-10-23 09:44:42 +00:00
|
|
|
|
2020-05-29 14:08:18 +00:00
|
|
|
ImageSource::ImageSource(const QString &path)
|
|
|
|
: ImageSource(ReadContent(path)) {
|
2018-10-23 09:44:42 +00:00
|
|
|
}
|
|
|
|
|
2020-05-29 14:08:18 +00:00
|
|
|
ImageSource::ImageSource(const QByteArray &content)
|
|
|
|
: ImageSource(ReadImage(content)) {
|
2018-10-23 09:44:42 +00:00
|
|
|
}
|
|
|
|
|
2020-05-29 14:08:18 +00:00
|
|
|
ImageSource::ImageSource(QImage &&data) : _data(std::move(data)) {
|
2018-10-23 09:44:42 +00:00
|
|
|
}
|
|
|
|
|
2020-05-29 14:08:18 +00:00
|
|
|
void ImageSource::load() {
|
2018-10-23 09:44:42 +00:00
|
|
|
}
|
|
|
|
|
2020-05-29 14:08:18 +00:00
|
|
|
QImage ImageSource::takeLoaded() {
|
|
|
|
return _data;
|
2018-10-23 09:44:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int ImageSource::width() {
|
2020-05-29 14:08:18 +00:00
|
|
|
return _data.width();
|
2018-10-23 09:44:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int ImageSource::height() {
|
2020-05-29 14:08:18 +00:00
|
|
|
return _data.height();
|
2018-10-23 09:44:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Images
|