2014-05-30 08:53:19 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2014-12-01 10:47:38 +00:00
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
Telegram Desktop is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
2015-10-03 13:16:42 +00:00
|
|
|
In addition, as a special exception, the copyright holders give permission
|
|
|
|
to link the code of portions of this program with the OpenSSL library.
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
2016-02-08 10:56:18 +00:00
|
|
|
Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
|
2014-05-30 08:53:19 +00:00
|
|
|
*/
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "localimageloader.h"
|
2016-04-07 18:05:28 +00:00
|
|
|
#include "ui/filedialog.h"
|
2016-07-05 17:44:02 +00:00
|
|
|
#include "media/media_audio.h"
|
2015-10-27 02:39:02 +00:00
|
|
|
|
2016-11-28 15:45:07 +00:00
|
|
|
#include "boxes/send_files_box.h"
|
2016-06-24 10:37:29 +00:00
|
|
|
#include "media/media_clip_reader.h"
|
2015-10-27 02:39:02 +00:00
|
|
|
#include "mainwidget.h"
|
2016-04-12 21:31:28 +00:00
|
|
|
#include "mainwindow.h"
|
2015-10-27 02:39:02 +00:00
|
|
|
#include "lang.h"
|
|
|
|
#include "boxes/confirmbox.h"
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2015-09-29 18:59:26 +00:00
|
|
|
TaskQueue::TaskQueue(QObject *parent, int32 stopTimeoutMs) : QObject(parent), _thread(0), _worker(0), _stopTimer(0) {
|
2015-09-29 18:44:31 +00:00
|
|
|
if (stopTimeoutMs > 0) {
|
|
|
|
_stopTimer = new QTimer(this);
|
|
|
|
connect(_stopTimer, SIGNAL(timeout()), this, SLOT(stop()));
|
|
|
|
_stopTimer->setSingleShot(true);
|
|
|
|
_stopTimer->setInterval(stopTimeoutMs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TaskId TaskQueue::addTask(TaskPtr task) {
|
|
|
|
{
|
|
|
|
QMutexLocker lock(&_tasksToProcessMutex);
|
|
|
|
_tasksToProcess.push_back(task);
|
|
|
|
}
|
2015-10-28 02:41:13 +00:00
|
|
|
|
|
|
|
wakeThread();
|
|
|
|
|
|
|
|
return task->id();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TaskQueue::addTasks(const TasksList &tasks) {
|
|
|
|
{
|
|
|
|
QMutexLocker lock(&_tasksToProcessMutex);
|
|
|
|
_tasksToProcess.append(tasks);
|
|
|
|
}
|
|
|
|
|
|
|
|
wakeThread();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TaskQueue::wakeThread() {
|
2015-09-29 18:44:31 +00:00
|
|
|
if (!_thread) {
|
|
|
|
_thread = new QThread();
|
|
|
|
|
|
|
|
_worker = new TaskQueueWorker(this);
|
|
|
|
_worker->moveToThread(_thread);
|
|
|
|
|
|
|
|
connect(this, SIGNAL(taskAdded()), _worker, SLOT(onTaskAdded()));
|
|
|
|
connect(_worker, SIGNAL(taskProcessed()), this, SLOT(onTaskProcessed()));
|
|
|
|
|
|
|
|
_thread->start();
|
|
|
|
}
|
|
|
|
if (_stopTimer) _stopTimer->stop();
|
|
|
|
emit taskAdded();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TaskQueue::cancelTask(TaskId id) {
|
2015-11-23 16:05:30 +00:00
|
|
|
{
|
|
|
|
QMutexLocker lock(&_tasksToProcessMutex);
|
|
|
|
for (int32 i = 0, l = _tasksToProcess.size(); i != l; ++i) {
|
|
|
|
if (_tasksToProcess.at(i)->id() == id) {
|
|
|
|
_tasksToProcess.removeAt(i);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
QMutexLocker lock(&_tasksToFinishMutex);
|
|
|
|
for (int32 i = 0, l = _tasksToFinish.size(); i != l; ++i) {
|
|
|
|
if (_tasksToFinish.at(i)->id() == id) {
|
|
|
|
_tasksToFinish.removeAt(i);
|
|
|
|
return;
|
2015-09-29 18:44:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TaskQueue::onTaskProcessed() {
|
|
|
|
do {
|
|
|
|
TaskPtr task;
|
|
|
|
{
|
|
|
|
QMutexLocker lock(&_tasksToFinishMutex);
|
|
|
|
if (_tasksToFinish.isEmpty()) break;
|
|
|
|
task = _tasksToFinish.front();
|
|
|
|
_tasksToFinish.pop_front();
|
|
|
|
}
|
|
|
|
task->finish();
|
|
|
|
} while (true);
|
|
|
|
|
|
|
|
if (_stopTimer) {
|
|
|
|
QMutexLocker lock(&_tasksToProcessMutex);
|
|
|
|
if (_tasksToProcess.isEmpty()) {
|
|
|
|
_stopTimer->start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TaskQueue::stop() {
|
|
|
|
if (_thread) {
|
|
|
|
_thread->requestInterruption();
|
|
|
|
_thread->quit();
|
2016-03-01 02:36:23 +00:00
|
|
|
DEBUG_LOG(("Waiting for taskThread to finish"));
|
2015-09-29 18:44:31 +00:00
|
|
|
_thread->wait();
|
|
|
|
delete _worker;
|
|
|
|
delete _thread;
|
|
|
|
_worker = 0;
|
|
|
|
_thread = 0;
|
|
|
|
}
|
|
|
|
_tasksToProcess.clear();
|
|
|
|
_tasksToFinish.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
TaskQueue::~TaskQueue() {
|
|
|
|
stop();
|
|
|
|
delete _stopTimer;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TaskQueueWorker::onTaskAdded() {
|
|
|
|
if (_inTaskAdded) return;
|
|
|
|
_inTaskAdded = true;
|
2016-01-05 04:28:06 +00:00
|
|
|
|
2015-09-29 18:44:31 +00:00
|
|
|
bool someTasksLeft = false;
|
|
|
|
do {
|
|
|
|
TaskPtr task;
|
|
|
|
{
|
|
|
|
QMutexLocker lock(&_queue->_tasksToProcessMutex);
|
|
|
|
if (!_queue->_tasksToProcess.isEmpty()) {
|
|
|
|
task = _queue->_tasksToProcess.front();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (task) {
|
|
|
|
task->process();
|
|
|
|
bool emitTaskProcessed = false;
|
|
|
|
{
|
|
|
|
QMutexLocker lockToProcess(&_queue->_tasksToProcessMutex);
|
|
|
|
if (!_queue->_tasksToProcess.isEmpty() && _queue->_tasksToProcess.front() == task) {
|
|
|
|
_queue->_tasksToProcess.pop_front();
|
|
|
|
someTasksLeft = !_queue->_tasksToProcess.isEmpty();
|
|
|
|
|
|
|
|
QMutexLocker lockToFinish(&_queue->_tasksToFinishMutex);
|
|
|
|
emitTaskProcessed = _queue->_tasksToFinish.isEmpty();
|
|
|
|
_queue->_tasksToFinish.push_back(task);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (emitTaskProcessed) {
|
|
|
|
emit taskProcessed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
QCoreApplication::processEvents();
|
|
|
|
} while (someTasksLeft && !thread()->isInterruptionRequested());
|
|
|
|
|
|
|
|
_inTaskAdded = false;
|
|
|
|
}
|
2015-10-27 02:39:02 +00:00
|
|
|
|
2016-11-28 15:45:07 +00:00
|
|
|
FileLoadTask::FileLoadTask(const QString &filepath, SendMediaType type, const FileLoadTo &to, const QString &caption) : _id(rand_value<uint64>())
|
2015-10-27 02:39:02 +00:00
|
|
|
, _to(to)
|
|
|
|
, _filepath(filepath)
|
|
|
|
, _type(type)
|
2016-11-28 15:45:07 +00:00
|
|
|
, _caption(caption) {
|
2015-10-27 02:39:02 +00:00
|
|
|
}
|
|
|
|
|
2016-11-28 15:45:07 +00:00
|
|
|
FileLoadTask::FileLoadTask(const QByteArray &content, const QImage &image, SendMediaType type, const FileLoadTo &to, const QString &caption) : _id(rand_value<uint64>())
|
2015-10-27 02:39:02 +00:00
|
|
|
, _to(to)
|
|
|
|
, _content(content)
|
|
|
|
, _image(image)
|
2015-10-28 02:41:13 +00:00
|
|
|
, _type(type)
|
2016-11-28 15:45:07 +00:00
|
|
|
, _caption(caption) {
|
2015-10-27 02:39:02 +00:00
|
|
|
}
|
|
|
|
|
2016-11-28 15:45:07 +00:00
|
|
|
FileLoadTask::FileLoadTask(const QByteArray &voice, int32 duration, const VoiceWaveform &waveform, const FileLoadTo &to, const QString &caption) : _id(rand_value<uint64>())
|
2015-10-27 02:39:02 +00:00
|
|
|
, _to(to)
|
2016-02-12 16:35:06 +00:00
|
|
|
, _content(voice)
|
2015-10-27 02:39:02 +00:00
|
|
|
, _duration(duration)
|
2016-02-12 16:35:06 +00:00
|
|
|
, _waveform(waveform)
|
2016-11-28 15:45:07 +00:00
|
|
|
, _type(SendMediaType::Audio)
|
|
|
|
, _caption(caption) {
|
2015-10-27 02:39:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FileLoadTask::process() {
|
|
|
|
const QString stickerMime = qsl("image/webp");
|
|
|
|
|
2016-11-28 15:45:07 +00:00
|
|
|
_result = MakeShared<FileLoadResult>(_id, _to, _caption);
|
2015-10-27 02:39:02 +00:00
|
|
|
|
|
|
|
QString filename, filemime;
|
|
|
|
qint64 filesize = 0;
|
|
|
|
QByteArray filedata;
|
|
|
|
|
|
|
|
uint64 thumbId = 0;
|
|
|
|
QString thumbname = "thumb.jpg";
|
|
|
|
QByteArray thumbdata;
|
|
|
|
|
2016-11-28 15:45:07 +00:00
|
|
|
auto animated = false;
|
|
|
|
auto song = false;
|
|
|
|
auto gif = false;
|
|
|
|
auto voice = (_type == SendMediaType::Audio);
|
|
|
|
auto fullimage = base::take(_image);
|
2015-10-27 02:39:02 +00:00
|
|
|
|
|
|
|
if (!_filepath.isEmpty()) {
|
|
|
|
QFileInfo info(_filepath);
|
2015-11-02 22:36:26 +00:00
|
|
|
if (info.isDir()) {
|
|
|
|
_result->filesize = -1;
|
|
|
|
return;
|
|
|
|
}
|
2015-10-27 02:39:02 +00:00
|
|
|
filesize = info.size();
|
|
|
|
filemime = mimeTypeForFile(info).name();
|
|
|
|
filename = info.fileName();
|
2016-11-28 15:45:07 +00:00
|
|
|
auto opaque = (filemime != stickerMime);
|
|
|
|
fullimage = App::readImage(_filepath, 0, opaque, &animated);
|
2015-10-27 02:39:02 +00:00
|
|
|
} else if (!_content.isEmpty()) {
|
|
|
|
filesize = _content.size();
|
2016-02-12 16:35:06 +00:00
|
|
|
if (voice) {
|
2015-10-27 02:39:02 +00:00
|
|
|
filename = filedialogDefaultName(qsl("audio"), qsl(".ogg"), QString(), true);
|
|
|
|
filemime = "audio/ogg";
|
|
|
|
} else {
|
2016-11-28 15:45:07 +00:00
|
|
|
auto mimeType = mimeTypeForData(_content);
|
2016-02-12 16:35:06 +00:00
|
|
|
filemime = mimeType.name();
|
2016-11-28 15:45:07 +00:00
|
|
|
if (filemime != stickerMime) {
|
|
|
|
fullimage = Images::prepareOpaque(std_::move(fullimage));
|
2016-02-12 16:35:06 +00:00
|
|
|
}
|
|
|
|
if (filemime == "image/jpeg") {
|
2016-11-28 15:45:07 +00:00
|
|
|
filename = filedialogDefaultName(qsl("photo"), qsl(".jpg"), QString(), true);
|
|
|
|
} else if (filemime == "image/png") {
|
|
|
|
filename = filedialogDefaultName(qsl("image"), qsl(".png"), QString(), true);
|
2016-02-12 16:35:06 +00:00
|
|
|
} else {
|
|
|
|
QString ext;
|
|
|
|
QStringList patterns = mimeType.globPatterns();
|
|
|
|
if (!patterns.isEmpty()) {
|
|
|
|
ext = patterns.front().replace('*', QString());
|
|
|
|
}
|
|
|
|
filename = filedialogDefaultName(qsl("file"), ext, QString(), true);
|
2015-10-27 02:39:02 +00:00
|
|
|
}
|
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
} else if (!fullimage.isNull() && fullimage.width() > 0) {
|
|
|
|
if (_type == SendMediaType::Photo) {
|
|
|
|
auto w = fullimage.width(), h = fullimage.height();
|
|
|
|
if (w >= 20 * h || h >= 20 * w) {
|
|
|
|
_type = SendMediaType::File;
|
|
|
|
} else {
|
|
|
|
filesize = -1; // Fill later.
|
|
|
|
filemime = mimeTypeForName("image/jpeg").name();
|
|
|
|
filename = filedialogDefaultName(qsl("image"), qsl(".jpg"), QString(), true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (_type == SendMediaType::File) {
|
|
|
|
filemime = mimeTypeForName("image/png").name();
|
|
|
|
filename = filedialogDefaultName(qsl("image"), qsl(".png"), QString(), true);
|
|
|
|
{
|
|
|
|
QBuffer buffer(&_content);
|
|
|
|
fullimage.save(&buffer, "PNG");
|
|
|
|
}
|
|
|
|
filesize = _content.size();
|
2015-10-27 02:39:02 +00:00
|
|
|
}
|
2016-11-28 15:45:07 +00:00
|
|
|
fullimage = Images::prepareOpaque(std_::move(fullimage));
|
2015-10-27 02:39:02 +00:00
|
|
|
}
|
|
|
|
_result->filesize = (int32)qMin(filesize, qint64(INT_MAX));
|
|
|
|
|
2016-11-28 15:45:07 +00:00
|
|
|
if (!filesize || filesize > App::kFileSizeLimit) {
|
2015-10-27 02:39:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
PreparedPhotoThumbs photoThumbs;
|
|
|
|
QVector<MTPPhotoSize> photoSizes;
|
|
|
|
QPixmap thumb;
|
|
|
|
|
|
|
|
QVector<MTPDocumentAttribute> attributes(1, MTP_documentAttributeFilename(MTP_string(filename)));
|
|
|
|
|
|
|
|
MTPPhotoSize thumbSize(MTP_photoSizeEmpty(MTP_string("")));
|
|
|
|
MTPPhoto photo(MTP_photoEmpty(MTP_long(0)));
|
|
|
|
MTPDocument document(MTP_documentEmpty(MTP_long(0)));
|
|
|
|
|
2016-02-12 16:35:06 +00:00
|
|
|
if (!voice) {
|
2015-10-27 02:39:02 +00:00
|
|
|
if (filemime == qstr("audio/mp3") || filemime == qstr("audio/m4a") || filemime == qstr("audio/aac") || filemime == qstr("audio/ogg") || filemime == qstr("audio/flac") ||
|
|
|
|
filename.endsWith(qstr(".mp3"), Qt::CaseInsensitive) || filename.endsWith(qstr(".m4a"), Qt::CaseInsensitive) ||
|
|
|
|
filename.endsWith(qstr(".aac"), Qt::CaseInsensitive) || filename.endsWith(qstr(".ogg"), Qt::CaseInsensitive) ||
|
|
|
|
filename.endsWith(qstr(".flac"), Qt::CaseInsensitive)) {
|
|
|
|
QImage cover;
|
|
|
|
QByteArray coverBytes, coverFormat;
|
|
|
|
MTPDocumentAttribute audioAttribute = audioReadSongAttributes(_filepath, _content, cover, coverBytes, coverFormat);
|
|
|
|
if (audioAttribute.type() == mtpc_documentAttributeAudio) {
|
|
|
|
attributes.push_back(audioAttribute);
|
|
|
|
song = true;
|
|
|
|
if (!cover.isNull()) { // cover to thumb
|
|
|
|
int32 cw = cover.width(), ch = cover.height();
|
|
|
|
if (cw < 20 * ch && ch < 20 * cw) {
|
2016-07-13 17:34:57 +00:00
|
|
|
QPixmap full = (cw > 90 || ch > 90) ? App::pixmapFromImageInPlace(cover.scaled(90, 90, Qt::KeepAspectRatio, Qt::SmoothTransformation)) : App::pixmapFromImageInPlace(std_::move(cover));
|
2015-10-27 02:39:02 +00:00
|
|
|
{
|
|
|
|
QByteArray thumbFormat = "JPG";
|
|
|
|
int32 thumbQuality = 87;
|
|
|
|
|
|
|
|
QBuffer buffer(&thumbdata);
|
|
|
|
full.save(&buffer, thumbFormat, thumbQuality);
|
|
|
|
}
|
|
|
|
|
|
|
|
thumb = full;
|
|
|
|
thumbSize = MTP_photoSize(MTP_string(""), MTP_fileLocationUnavailable(MTP_long(0), MTP_int(0), MTP_long(0)), MTP_int(full.width()), MTP_int(full.height()), MTP_int(0));
|
|
|
|
|
2016-03-24 10:12:18 +00:00
|
|
|
thumbId = rand_value<uint64>();
|
2015-10-27 02:39:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-01-05 04:28:06 +00:00
|
|
|
if (filemime == qstr("video/mp4") || filename.endsWith(qstr(".mp4"), Qt::CaseInsensitive) || animated) {
|
2015-12-28 15:34:45 +00:00
|
|
|
QImage cover;
|
2016-06-24 10:37:29 +00:00
|
|
|
MTPDocumentAttribute animatedAttribute = Media::Clip::readAttributes(_filepath, _content, cover);
|
2015-12-28 15:34:45 +00:00
|
|
|
if (animatedAttribute.type() == mtpc_documentAttributeVideo) {
|
|
|
|
int32 cw = cover.width(), ch = cover.height();
|
|
|
|
if (cw < 20 * ch && ch < 20 * cw) {
|
|
|
|
attributes.push_back(MTP_documentAttributeAnimated());
|
|
|
|
attributes.push_back(animatedAttribute);
|
|
|
|
gif = true;
|
|
|
|
|
2016-07-13 17:34:57 +00:00
|
|
|
QPixmap full = (cw > 90 || ch > 90) ? App::pixmapFromImageInPlace(cover.scaled(90, 90, Qt::KeepAspectRatio, Qt::SmoothTransformation)) : App::pixmapFromImageInPlace(std_::move(cover));
|
2015-12-28 15:34:45 +00:00
|
|
|
{
|
|
|
|
QByteArray thumbFormat = "JPG";
|
|
|
|
int32 thumbQuality = 87;
|
|
|
|
|
|
|
|
QBuffer buffer(&thumbdata);
|
|
|
|
full.save(&buffer, thumbFormat, thumbQuality);
|
|
|
|
}
|
|
|
|
|
|
|
|
thumb = full;
|
|
|
|
thumbSize = MTP_photoSize(MTP_string(""), MTP_fileLocationUnavailable(MTP_long(0), MTP_int(0), MTP_long(0)), MTP_int(full.width()), MTP_int(full.height()), MTP_int(0));
|
|
|
|
|
2016-03-24 10:12:18 +00:00
|
|
|
thumbId = rand_value<uint64>();
|
2015-12-28 15:34:45 +00:00
|
|
|
|
2016-01-05 04:28:06 +00:00
|
|
|
if (filename.endsWith(qstr(".mp4"), Qt::CaseInsensitive)) {
|
|
|
|
filemime = qstr("video/mp4");
|
|
|
|
}
|
2015-12-28 15:34:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-10-27 02:39:02 +00:00
|
|
|
}
|
|
|
|
|
2016-02-12 16:35:06 +00:00
|
|
|
if (!fullimage.isNull() && fullimage.width() > 0 && !song && !gif && !voice) {
|
2016-11-15 11:56:49 +00:00
|
|
|
auto w = fullimage.width(), h = fullimage.height();
|
2015-10-27 02:39:02 +00:00
|
|
|
attributes.push_back(MTP_documentAttributeImageSize(MTP_int(w), MTP_int(h)));
|
|
|
|
|
|
|
|
if (w < 20 * h && h < 20 * w) {
|
|
|
|
if (animated) {
|
|
|
|
attributes.push_back(MTP_documentAttributeAnimated());
|
2016-11-28 15:45:07 +00:00
|
|
|
} else if (_type != SendMediaType::File) {
|
2016-11-15 11:56:49 +00:00
|
|
|
auto thumb = (w > 100 || h > 100) ? App::pixmapFromImageInPlace(fullimage.scaled(100, 100, Qt::KeepAspectRatio, Qt::SmoothTransformation)) : QPixmap::fromImage(fullimage);
|
2015-10-27 02:39:02 +00:00
|
|
|
photoThumbs.insert('s', thumb);
|
|
|
|
photoSizes.push_back(MTP_photoSize(MTP_string("s"), MTP_fileLocationUnavailable(MTP_long(0), MTP_int(0), MTP_long(0)), MTP_int(thumb.width()), MTP_int(thumb.height()), MTP_int(0)));
|
|
|
|
|
2016-11-15 11:56:49 +00:00
|
|
|
auto medium = (w > 320 || h > 320) ? App::pixmapFromImageInPlace(fullimage.scaled(320, 320, Qt::KeepAspectRatio, Qt::SmoothTransformation)) : QPixmap::fromImage(fullimage);
|
2015-10-27 02:39:02 +00:00
|
|
|
photoThumbs.insert('m', medium);
|
|
|
|
photoSizes.push_back(MTP_photoSize(MTP_string("m"), MTP_fileLocationUnavailable(MTP_long(0), MTP_int(0), MTP_long(0)), MTP_int(medium.width()), MTP_int(medium.height()), MTP_int(0)));
|
|
|
|
|
2016-11-15 11:56:49 +00:00
|
|
|
auto full = (w > 1280 || h > 1280) ? App::pixmapFromImageInPlace(fullimage.scaled(1280, 1280, Qt::KeepAspectRatio, Qt::SmoothTransformation)) : QPixmap::fromImage(fullimage);
|
2015-10-27 02:39:02 +00:00
|
|
|
photoThumbs.insert('y', full);
|
|
|
|
photoSizes.push_back(MTP_photoSize(MTP_string("y"), MTP_fileLocationUnavailable(MTP_long(0), MTP_int(0), MTP_long(0)), MTP_int(full.width()), MTP_int(full.height()), MTP_int(0)));
|
|
|
|
|
|
|
|
{
|
|
|
|
QBuffer buffer(&filedata);
|
2016-12-02 19:16:35 +00:00
|
|
|
full.save(&buffer, "JPG", 87);
|
2015-10-27 02:39:02 +00:00
|
|
|
}
|
|
|
|
|
2016-09-13 10:03:21 +00:00
|
|
|
MTPDphoto::Flags photoFlags = 0;
|
|
|
|
photo = MTP_photo(MTP_flags(photoFlags), MTP_long(_id), MTP_long(0), MTP_int(unixtime()), MTP_vector<MTPPhotoSize>(photoSizes));
|
2016-12-13 17:07:56 +00:00
|
|
|
|
|
|
|
if (filesize < 0) {
|
|
|
|
filesize = _result->filesize = filedata.size();
|
|
|
|
}
|
2015-10-27 02:39:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QByteArray thumbFormat = "JPG";
|
|
|
|
int32 thumbQuality = 87;
|
|
|
|
if (!animated && filemime == stickerMime && w > 0 && h > 0 && w <= StickerMaxSize && h <= StickerMaxSize && filesize < StickerInMemory) {
|
2016-09-13 10:03:21 +00:00
|
|
|
MTPDdocumentAttributeSticker::Flags stickerFlags = 0;
|
|
|
|
attributes.push_back(MTP_documentAttributeSticker(MTP_flags(stickerFlags), MTP_string(""), MTP_inputStickerSetEmpty(), MTPMaskCoords()));
|
2015-10-27 02:39:02 +00:00
|
|
|
thumbFormat = "webp";
|
|
|
|
thumbname = qsl("thumb.webp");
|
|
|
|
}
|
|
|
|
|
2016-07-13 17:34:57 +00:00
|
|
|
QPixmap full = (w > 90 || h > 90) ? App::pixmapFromImageInPlace(fullimage.scaled(90, 90, Qt::KeepAspectRatio, Qt::SmoothTransformation)) : QPixmap::fromImage(fullimage, Qt::ColorOnly);
|
2015-10-27 02:39:02 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
QBuffer buffer(&thumbdata);
|
|
|
|
full.save(&buffer, thumbFormat, thumbQuality);
|
|
|
|
}
|
|
|
|
|
|
|
|
thumb = full;
|
|
|
|
thumbSize = MTP_photoSize(MTP_string(""), MTP_fileLocationUnavailable(MTP_long(0), MTP_int(0), MTP_long(0)), MTP_int(full.width()), MTP_int(full.height()), MTP_int(0));
|
|
|
|
|
2016-03-24 10:12:18 +00:00
|
|
|
thumbId = rand_value<uint64>();
|
2015-10-27 02:39:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-12 16:35:06 +00:00
|
|
|
if (voice) {
|
2016-04-01 10:23:40 +00:00
|
|
|
attributes[0] = MTP_documentAttributeAudio(MTP_flags(MTPDdocumentAttributeAudio::Flag::f_voice | MTPDdocumentAttributeAudio::Flag::f_waveform), MTP_int(_duration), MTPstring(), MTPstring(), MTP_bytes(documentWaveformEncode5bit(_waveform)));
|
2016-02-12 16:35:06 +00:00
|
|
|
attributes.resize(1);
|
2016-07-08 13:56:53 +00:00
|
|
|
document = MTP_document(MTP_long(_id), MTP_long(0), MTP_int(unixtime()), MTP_string(filemime), MTP_int(filesize), thumbSize, MTP_int(MTP::maindc()), MTP_int(0), MTP_vector<MTPDocumentAttribute>(attributes));
|
2016-12-13 17:07:56 +00:00
|
|
|
} else if (_type != SendMediaType::Photo) {
|
2016-07-08 13:56:53 +00:00
|
|
|
document = MTP_document(MTP_long(_id), MTP_long(0), MTP_int(unixtime()), MTP_string(filemime), MTP_int(filesize), thumbSize, MTP_int(MTP::maindc()), MTP_int(0), MTP_vector<MTPDocumentAttribute>(attributes));
|
2016-12-13 17:07:56 +00:00
|
|
|
_type = SendMediaType::File;
|
2015-10-27 02:39:02 +00:00
|
|
|
}
|
2016-01-05 04:28:06 +00:00
|
|
|
|
2015-10-27 02:39:02 +00:00
|
|
|
_result->type = _type;
|
|
|
|
_result->filepath = _filepath;
|
|
|
|
_result->content = _content;
|
|
|
|
|
|
|
|
_result->filename = filename;
|
2015-12-19 14:37:28 +00:00
|
|
|
_result->filemime = filemime;
|
2015-10-27 02:39:02 +00:00
|
|
|
_result->setFileData(filedata);
|
|
|
|
|
|
|
|
_result->thumbId = thumbId;
|
|
|
|
_result->thumbname = thumbname;
|
|
|
|
_result->setThumbData(thumbdata);
|
|
|
|
_result->thumb = thumb;
|
|
|
|
|
|
|
|
_result->photo = photo;
|
|
|
|
_result->document = document;
|
|
|
|
_result->photoThumbs = photoThumbs;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FileLoadTask::finish() {
|
|
|
|
if (!_result || !_result->filesize) {
|
2016-12-13 17:07:56 +00:00
|
|
|
Ui::show(Box<InformBox>(lng_send_image_empty(lt_name, _filepath)), KeepOtherLayers);
|
2016-11-28 15:45:07 +00:00
|
|
|
} else if (_result->filesize == -1) { // dir
|
2016-12-13 17:07:56 +00:00
|
|
|
Ui::show(Box<InformBox>(lng_send_folder(lt_name, QFileInfo(_filepath).dir().dirName())), KeepOtherLayers);
|
2016-11-28 15:45:07 +00:00
|
|
|
} else if (_result->filesize > App::kFileSizeLimit) {
|
2016-12-13 17:07:56 +00:00
|
|
|
Ui::show(Box<InformBox>(lng_send_image_too_large(lt_name, _filepath)), KeepOtherLayers);
|
2016-11-28 15:45:07 +00:00
|
|
|
} else if (App::main()) {
|
|
|
|
App::main()->onSendFileConfirm(_result);
|
2015-10-27 02:39:02 +00:00
|
|
|
}
|
|
|
|
}
|