mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-31 14:38:15 +00:00
Remove special case in SendFilesBox for an image.
This commit is contained in:
@@ -202,6 +202,7 @@ FileLoadResult::FileLoadResult(
|
||||
|
||||
FileLoadTask::FileLoadTask(
|
||||
const QString &filepath,
|
||||
const QByteArray &content,
|
||||
std::unique_ptr<FileMediaInformation> information,
|
||||
SendMediaType type,
|
||||
const FileLoadTo &to,
|
||||
@@ -211,23 +212,8 @@ FileLoadTask::FileLoadTask(
|
||||
, _to(to)
|
||||
, _album(std::move(album))
|
||||
, _filepath(filepath)
|
||||
, _information(std::move(information))
|
||||
, _type(type)
|
||||
, _caption(caption) {
|
||||
}
|
||||
|
||||
FileLoadTask::FileLoadTask(
|
||||
const QByteArray &content,
|
||||
const QImage &image,
|
||||
SendMediaType type,
|
||||
const FileLoadTo &to,
|
||||
const QString &caption,
|
||||
std::shared_ptr<SendingAlbum> album)
|
||||
: _id(rand_value<uint64>())
|
||||
, _to(to)
|
||||
, _album(std::move(album))
|
||||
, _content(content)
|
||||
, _image(image)
|
||||
, _information(std::move(information))
|
||||
, _type(type)
|
||||
, _caption(caption) {
|
||||
}
|
||||
@@ -361,6 +347,14 @@ bool FileLoadTask::CheckForImage(
|
||||
}
|
||||
return QImage();
|
||||
})();
|
||||
return FillImageInformation(std::move(image), animated, result);
|
||||
}
|
||||
|
||||
bool FileLoadTask::FillImageInformation(
|
||||
QImage &&image,
|
||||
bool animated,
|
||||
std::unique_ptr<FileMediaInformation> &result) {
|
||||
Expects(result != nullptr);
|
||||
|
||||
if (image.isNull()) {
|
||||
return false;
|
||||
@@ -395,7 +389,7 @@ void FileLoadTask::process() {
|
||||
auto isVideo = false;
|
||||
auto isVoice = (_type == SendMediaType::Audio);
|
||||
|
||||
auto fullimage = base::take(_image);
|
||||
auto fullimage = QImage();
|
||||
auto info = _filepath.isEmpty() ? QFileInfo() : QFileInfo(_filepath);
|
||||
if (info.exists()) {
|
||||
if (info.isDir()) {
|
||||
@@ -428,6 +422,12 @@ void FileLoadTask::process() {
|
||||
filename = filedialogDefaultName(qsl("audio"), qsl(".ogg"), QString(), true);
|
||||
filemime = "audio/ogg";
|
||||
} else {
|
||||
if (_information) {
|
||||
if (auto image = base::get_if<FileMediaInformation::Image>(
|
||||
&_information->media)) {
|
||||
fullimage = base::take(image->data);
|
||||
}
|
||||
}
|
||||
auto mimeType = mimeTypeForData(_content);
|
||||
filemime = mimeType.name();
|
||||
if (filemime != stickerMime) {
|
||||
|
@@ -282,17 +282,15 @@ public:
|
||||
const QString &filepath,
|
||||
const QByteArray &content,
|
||||
const QString &filemime);
|
||||
static bool FillImageInformation(
|
||||
QImage &&image,
|
||||
bool animated,
|
||||
std::unique_ptr<FileMediaInformation> &result);
|
||||
|
||||
FileLoadTask(
|
||||
const QString &filepath,
|
||||
std::unique_ptr<FileMediaInformation> information,
|
||||
SendMediaType type,
|
||||
const FileLoadTo &to,
|
||||
const QString &caption,
|
||||
std::shared_ptr<SendingAlbum> album = nullptr);
|
||||
FileLoadTask(
|
||||
const QByteArray &content,
|
||||
const QImage &image,
|
||||
std::unique_ptr<FileMediaInformation> information,
|
||||
SendMediaType type,
|
||||
const FileLoadTo &to,
|
||||
const QString &caption,
|
||||
@@ -312,9 +310,18 @@ public:
|
||||
void finish();
|
||||
|
||||
private:
|
||||
static bool CheckForSong(const QString &filepath, const QByteArray &content, std::unique_ptr<FileMediaInformation> &result);
|
||||
static bool CheckForVideo(const QString &filepath, const QByteArray &content, std::unique_ptr<FileMediaInformation> &result);
|
||||
static bool CheckForImage(const QString &filepath, const QByteArray &content, std::unique_ptr<FileMediaInformation> &result);
|
||||
static bool CheckForSong(
|
||||
const QString &filepath,
|
||||
const QByteArray &content,
|
||||
std::unique_ptr<FileMediaInformation> &result);
|
||||
static bool CheckForVideo(
|
||||
const QString &filepath,
|
||||
const QByteArray &content,
|
||||
std::unique_ptr<FileMediaInformation> &result);
|
||||
static bool CheckForImage(
|
||||
const QString &filepath,
|
||||
const QByteArray &content,
|
||||
std::unique_ptr<FileMediaInformation> &result);
|
||||
|
||||
template <typename Mimes, typename Extensions>
|
||||
static bool CheckMimeOrExtensions(const QString &filepath, const QString &filemime, Mimes &mimes, Extensions &extensions);
|
||||
@@ -330,7 +337,6 @@ private:
|
||||
QString _filepath;
|
||||
QByteArray _content;
|
||||
std::unique_ptr<FileMediaInformation> _information;
|
||||
QImage _image;
|
||||
int32 _duration = 0;
|
||||
VoiceWaveform _waveform;
|
||||
SendMediaType _type;
|
||||
|
@@ -61,11 +61,22 @@ bool PrepareAlbumMediaIsWaiting(
|
||||
// Use some special thread queue, like a separate QThreadPool.
|
||||
base::TaskQueue::Normal().Put([&, previewWidth] {
|
||||
const auto guard = gsl::finally([&] { semaphore.release(); });
|
||||
const auto filemime = mimeTypeForFile(QFileInfo(file.path)).name();
|
||||
file.information = FileLoadTask::ReadMediaInformation(
|
||||
file.path,
|
||||
QByteArray(),
|
||||
filemime);
|
||||
if (!file.path.isEmpty()) {
|
||||
file.mime = mimeTypeForFile(QFileInfo(file.path)).name();
|
||||
file.information = FileLoadTask::ReadMediaInformation(
|
||||
file.path,
|
||||
QByteArray(),
|
||||
file.mime);
|
||||
} else if (!file.content.isEmpty()) {
|
||||
file.mime = mimeTypeForData(file.content).name();
|
||||
file.information = FileLoadTask::ReadMediaInformation(
|
||||
QString(),
|
||||
file.content,
|
||||
file.mime);
|
||||
} else {
|
||||
Assert(file.information != nullptr);
|
||||
}
|
||||
|
||||
using Image = FileMediaInformation::Image;
|
||||
using Video = FileMediaInformation::Video;
|
||||
if (const auto image = base::get_if<Image>(
|
||||
@@ -94,17 +105,14 @@ bool PrepareAlbumMediaIsWaiting(
|
||||
|
||||
void PrepareAlbum(PreparedList &result, int previewWidth) {
|
||||
const auto count = int(result.files.size());
|
||||
if ((count < 2) || (count > kMaxAlbumCount)) {
|
||||
if (count > kMaxAlbumCount) {
|
||||
return;
|
||||
}
|
||||
|
||||
result.albumIsPossible = true;
|
||||
result.albumIsPossible = (count > 1);
|
||||
auto waiting = 0;
|
||||
QSemaphore semaphore;
|
||||
for (auto &file : result.files) {
|
||||
if (!result.albumIsPossible) {
|
||||
break;
|
||||
}
|
||||
if (PrepareAlbumMediaIsWaiting(semaphore, file, previewWidth)) {
|
||||
++waiting;
|
||||
}
|
||||
@@ -226,11 +234,34 @@ PreparedList PrepareMediaList(const QStringList &files, int previewWidth) {
|
||||
if (filesize > App::kImageSizeLimit || !toCompress) {
|
||||
result.allFilesForCompress = false;
|
||||
}
|
||||
result.files.push_back({ file });
|
||||
result.files.emplace_back(file);
|
||||
}
|
||||
PrepareAlbum(result, previewWidth);
|
||||
return result;
|
||||
}
|
||||
|
||||
PreparedList PrepareMediaFromImage(
|
||||
QImage &&image,
|
||||
QByteArray &&content,
|
||||
int previewWidth) {
|
||||
auto result = Storage::PreparedList();
|
||||
result.allFilesForCompress = ValidateThumbDimensions(
|
||||
image.width(),
|
||||
image.height());
|
||||
auto file = PreparedFile(QString());
|
||||
file.content = content;
|
||||
if (file.content.isEmpty()) {
|
||||
file.information = std::make_unique<FileMediaInformation>();
|
||||
const auto animated = false;
|
||||
FileLoadTask::FillImageInformation(
|
||||
std::move(image),
|
||||
animated,
|
||||
file.information);
|
||||
}
|
||||
result.files.push_back(std::move(file));
|
||||
PrepareAlbum(result, previewWidth);
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace Storage
|
||||
|
||||
|
@@ -46,8 +46,9 @@ struct PreparedFile {
|
||||
~PreparedFile();
|
||||
|
||||
QString path;
|
||||
QByteArray content;
|
||||
QString mime;
|
||||
std::unique_ptr<FileMediaInformation> information;
|
||||
base::optional<QImage> large;
|
||||
QImage preview;
|
||||
AlbumType type = AlbumType::None;
|
||||
|
||||
@@ -79,5 +80,9 @@ struct PreparedList {
|
||||
bool ValidateThumbDimensions(int width, int height);
|
||||
PreparedList PrepareMediaList(const QList<QUrl> &files, int previewWidth);
|
||||
PreparedList PrepareMediaList(const QStringList &files, int previewWidth);
|
||||
PreparedList PrepareMediaFromImage(
|
||||
QImage &&image,
|
||||
QByteArray &&content,
|
||||
int previewWidth);
|
||||
|
||||
} // namespace Storage
|
||||
|
Reference in New Issue
Block a user