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
|
|
|
|
|
|
|
#include "boxes/photosendbox.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-03-24 10:12:18 +00:00
|
|
|
FileLoadTask::FileLoadTask(const QString &filepath, PrepareMediaType type, const FileLoadTo &to, FileLoadForceConfirmType confirm) : _id(rand_value<uint64>())
|
2015-10-27 02:39:02 +00:00
|
|
|
, _to(to)
|
|
|
|
, _filepath(filepath)
|
|
|
|
, _type(type)
|
2016-10-12 19:34:25 +00:00
|
|
|
, _confirm(confirm) {
|
2015-10-27 02:39:02 +00:00
|
|
|
}
|
|
|
|
|
2016-03-24 10:12:18 +00:00
|
|
|
FileLoadTask::FileLoadTask(const QByteArray &content, PrepareMediaType type, const FileLoadTo &to) : _id(rand_value<uint64>())
|
2015-10-27 02:39:02 +00:00
|
|
|
, _to(to)
|
|
|
|
, _content(content)
|
2016-10-12 19:34:25 +00:00
|
|
|
, _type(type) {
|
2015-10-27 02:39:02 +00:00
|
|
|
}
|
|
|
|
|
2016-03-24 10:12:18 +00:00
|
|
|
FileLoadTask::FileLoadTask(const QImage &image, PrepareMediaType type, const FileLoadTo &to, FileLoadForceConfirmType confirm, const QString &originalText) : _id(rand_value<uint64>())
|
2015-10-27 02:39:02 +00:00
|
|
|
, _to(to)
|
|
|
|
, _image(image)
|
2015-10-28 02:41:13 +00:00
|
|
|
, _type(type)
|
2015-10-27 02:39:02 +00:00
|
|
|
, _confirm(confirm)
|
2016-10-12 19:34:25 +00:00
|
|
|
, _originalText(originalText) {
|
2015-10-27 02:39:02 +00:00
|
|
|
}
|
|
|
|
|
2016-03-24 10:12:18 +00:00
|
|
|
FileLoadTask::FileLoadTask(const QByteArray &voice, int32 duration, const VoiceWaveform &waveform, const FileLoadTo &to) : _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-10-12 19:34:25 +00:00
|
|
|
, _type(PrepareAudio) {
|
2015-10-27 02:39:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FileLoadTask::process() {
|
|
|
|
const QString stickerMime = qsl("image/webp");
|
|
|
|
|
2015-11-24 11:23:14 +00:00
|
|
|
_result = FileLoadResultPtr(new FileLoadResult(_id, _to, _originalText));
|
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-02-12 16:35:06 +00:00
|
|
|
bool animated = false, song = false, gif = false, voice = (_type == PrepareAudio);
|
2015-10-27 02:39:02 +00:00
|
|
|
QImage fullimage = _image;
|
|
|
|
|
|
|
|
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-02-12 16:35:06 +00:00
|
|
|
if (filesize <= MaxUploadPhotoSize && !voice) {
|
2015-10-27 02:39:02 +00:00
|
|
|
bool opaque = (filemime != stickerMime);
|
|
|
|
fullimage = App::readImage(_filepath, 0, opaque, &animated);
|
|
|
|
}
|
|
|
|
} 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-02-12 16:35:06 +00:00
|
|
|
MimeType mimeType = mimeTypeForData(_content);
|
|
|
|
filemime = mimeType.name();
|
|
|
|
if (filesize <= MaxUploadPhotoSize && !voice) {
|
|
|
|
bool opaque = (filemime != stickerMime);
|
|
|
|
fullimage = App::readImage(_content, 0, opaque, &animated);
|
|
|
|
}
|
|
|
|
if (filemime == "image/jpeg") {
|
|
|
|
filename = filedialogDefaultName(qsl("image"), qsl(".jpg"), QString(), true);
|
|
|
|
} 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
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (!_image.isNull()) {
|
|
|
|
_image = QImage();
|
|
|
|
|
|
|
|
filemime = mimeTypeForName("image/png").name();
|
|
|
|
filename = filedialogDefaultName(qsl("image"), qsl(".png"), QString(), true);
|
|
|
|
{
|
|
|
|
QBuffer buffer(&_content);
|
|
|
|
fullimage.save(&buffer, "PNG");
|
|
|
|
}
|
|
|
|
filesize = _content.size();
|
|
|
|
|
|
|
|
if (fullimage.hasAlphaChannel()) {
|
|
|
|
QImage solid(fullimage.width(), fullimage.height(), QImage::Format_ARGB32_Premultiplied);
|
|
|
|
solid.fill(st::white->c);
|
|
|
|
{
|
|
|
|
QPainter(&solid).drawImage(0, 0, fullimage);
|
|
|
|
}
|
|
|
|
fullimage = solid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_result->filesize = (int32)qMin(filesize, qint64(INT_MAX));
|
|
|
|
|
|
|
|
if (!filesize || filesize > MaxUploadDocumentSize) {
|
|
|
|
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) {
|
2015-10-27 02:39:02 +00:00
|
|
|
int32 w = fullimage.width(), h = fullimage.height();
|
|
|
|
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());
|
2015-10-28 02:41:13 +00:00
|
|
|
} else if (_type != PrepareDocument) {
|
2016-07-13 17:34:57 +00:00
|
|
|
QPixmap 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-07-13 17:34:57 +00:00
|
|
|
QPixmap 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-07-13 17:34:57 +00:00
|
|
|
QPixmap 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);
|
|
|
|
full.save(&buffer, "JPG", 77);
|
|
|
|
}
|
|
|
|
|
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));
|
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));
|
2015-10-27 02:39:02 +00:00
|
|
|
} else {
|
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));
|
2015-10-27 02:39:02 +00:00
|
|
|
if (photo.type() == mtpc_photoEmpty) {
|
|
|
|
_type = PrepareDocument;
|
|
|
|
}
|
|
|
|
}
|
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) {
|
|
|
|
if (_result) App::main()->onSendFileCancel(_result);
|
2015-12-07 18:09:05 +00:00
|
|
|
Ui::showLayer(new InformBox(lang(lng_send_image_empty)), KeepOtherLayers);
|
2015-10-27 02:39:02 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-11-02 22:36:26 +00:00
|
|
|
if (_result->filesize == -1) { // dir
|
|
|
|
App::main()->onSendFileCancel(_result);
|
2015-12-07 18:09:05 +00:00
|
|
|
Ui::showLayer(new InformBox(lng_send_folder(lt_name, QFileInfo(_filepath).dir().dirName())), KeepOtherLayers);
|
2015-11-02 22:36:26 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-10-27 02:39:02 +00:00
|
|
|
if (_result->filesize > MaxUploadDocumentSize) {
|
|
|
|
App::main()->onSendFileCancel(_result);
|
2015-12-07 18:09:05 +00:00
|
|
|
Ui::showLayer(new InformBox(lang(lng_send_image_too_large)), KeepOtherLayers);
|
2015-10-27 02:39:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (App::main()) {
|
|
|
|
bool confirm = (_confirm == FileLoadAlwaysConfirm) || (_result->photo.type() != mtpc_photoEmpty && _confirm != FileLoadNeverConfirm);
|
|
|
|
if (confirm) {
|
2015-12-07 18:09:05 +00:00
|
|
|
Ui::showLayer(new PhotoSendBox(_result), ShowAfterOtherLayers);
|
2015-10-27 02:39:02 +00:00
|
|
|
} else {
|
2015-10-28 02:41:13 +00:00
|
|
|
if (_result->type == PrepareAuto) {
|
|
|
|
_result->type = (_result->photo.type() != mtpc_photoEmpty) ? PreparePhoto : PrepareDocument;
|
|
|
|
}
|
2015-10-27 02:39:02 +00:00
|
|
|
App::main()->onSendFileConfirm(_result, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|