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
|
2017-01-11 18:31:31 +00:00
|
|
|
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
2014-05-30 08:53:19 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2017-03-04 10:23:56 +00:00
|
|
|
#include "storage/localimageloader.h"
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2017-08-04 14:54:32 +00:00
|
|
|
namespace Storage {
|
|
|
|
|
|
|
|
class Uploader : public QObject, public RPCSender {
|
2014-05-30 08:53:19 +00:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2017-08-04 14:54:32 +00:00
|
|
|
Uploader();
|
2016-11-28 15:45:07 +00:00
|
|
|
void uploadMedia(const FullMsgId &msgId, const SendMediaReady &image);
|
2015-10-28 02:41:13 +00:00
|
|
|
void upload(const FullMsgId &msgId, const FileLoadResultPtr &file);
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2015-09-03 10:48:40 +00:00
|
|
|
int32 currentOffset(const FullMsgId &msgId) const; // -1 means file not found
|
|
|
|
int32 fullSize(const FullMsgId &msgId) const;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2015-09-03 10:48:40 +00:00
|
|
|
void cancel(const FullMsgId &msgId);
|
2015-12-24 19:26:28 +00:00
|
|
|
void pause(const FullMsgId &msgId);
|
2015-09-03 10:48:40 +00:00
|
|
|
void confirm(const FullMsgId &msgId);
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
void clear();
|
|
|
|
|
2017-08-04 14:54:32 +00:00
|
|
|
~Uploader();
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
public slots:
|
2015-12-24 19:26:28 +00:00
|
|
|
void unpause();
|
2014-05-30 08:53:19 +00:00
|
|
|
void sendNext();
|
2014-10-30 16:23:44 +00:00
|
|
|
void killSessions();
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
signals:
|
2016-02-25 16:19:54 +00:00
|
|
|
void photoReady(const FullMsgId &msgId, bool silent, const MTPInputFile &file);
|
|
|
|
void documentReady(const FullMsgId &msgId, bool silent, const MTPInputFile &file);
|
|
|
|
void thumbDocumentReady(const FullMsgId &msgId, bool silent, const MTPInputFile &file, const MTPInputFile &thumb);
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2015-09-03 10:48:40 +00:00
|
|
|
void photoProgress(const FullMsgId &msgId);
|
|
|
|
void documentProgress(const FullMsgId &msgId);
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2015-09-03 10:48:40 +00:00
|
|
|
void photoFailed(const FullMsgId &msgId);
|
|
|
|
void documentFailed(const FullMsgId &msgId);
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
struct File {
|
2016-11-28 15:45:07 +00:00
|
|
|
File(const SendMediaReady &media) : media(media), docSentParts(0) {
|
2014-05-30 08:53:19 +00:00
|
|
|
partsCount = media.parts.size();
|
2016-11-28 15:45:07 +00:00
|
|
|
if (type() == SendMediaType::File || type() == SendMediaType::Audio) {
|
2015-10-27 02:39:02 +00:00
|
|
|
setDocSize(media.file.isEmpty() ? media.data.size() : media.filesize);
|
|
|
|
} else {
|
|
|
|
docSize = docPartSize = docPartsCount = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
File(const FileLoadResultPtr &file) : file(file), docSentParts(0) {
|
2016-11-28 15:45:07 +00:00
|
|
|
partsCount = (type() == SendMediaType::Photo) ? file->fileparts.size() : file->thumbparts.size();
|
|
|
|
if (type() == SendMediaType::File || type() == SendMediaType::Audio) {
|
2015-10-27 02:39:02 +00:00
|
|
|
setDocSize(file->filesize);
|
|
|
|
} else {
|
|
|
|
docSize = docPartSize = docPartsCount = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void setDocSize(int32 size) {
|
|
|
|
docSize = size;
|
|
|
|
if (docSize >= 1024 * 1024 || !setPartSize(DocumentUploadPartSize0)) {
|
|
|
|
if (docSize > 32 * 1024 * 1024 || !setPartSize(DocumentUploadPartSize1)) {
|
|
|
|
if (!setPartSize(DocumentUploadPartSize2)) {
|
|
|
|
if (!setPartSize(DocumentUploadPartSize3)) {
|
|
|
|
if (!setPartSize(DocumentUploadPartSize4)) {
|
|
|
|
LOG(("Upload Error: bad doc size: %1").arg(docSize));
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bool setPartSize(uint32 partSize) {
|
|
|
|
docPartSize = partSize;
|
|
|
|
docPartsCount = (docSize / docPartSize) + ((docSize % docPartSize) ? 1 : 0);
|
|
|
|
return (docPartsCount <= DocumentMaxPartsCount);
|
|
|
|
}
|
|
|
|
|
2015-10-27 02:39:02 +00:00
|
|
|
FileLoadResultPtr file;
|
2016-11-28 15:45:07 +00:00
|
|
|
SendMediaReady media;
|
2014-05-30 08:53:19 +00:00
|
|
|
int32 partsCount;
|
2015-12-24 19:26:28 +00:00
|
|
|
mutable int32 fileSentSize;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2015-10-28 04:12:01 +00:00
|
|
|
uint64 id() const {
|
2015-10-27 02:39:02 +00:00
|
|
|
return file ? file->id : media.id;
|
|
|
|
}
|
2016-11-28 15:45:07 +00:00
|
|
|
SendMediaType type() const {
|
2015-10-27 02:39:02 +00:00
|
|
|
return file ? file->type : media.type;
|
|
|
|
}
|
2015-10-28 04:12:01 +00:00
|
|
|
uint64 thumbId() const {
|
2015-10-27 02:39:02 +00:00
|
|
|
return file ? file->thumbId : media.thumbId;
|
|
|
|
}
|
|
|
|
const QString &filename() const {
|
|
|
|
return file ? file->filename : media.filename;
|
|
|
|
}
|
|
|
|
|
2015-05-29 18:52:43 +00:00
|
|
|
HashMd5 md5Hash;
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
QSharedPointer<QFile> docFile;
|
|
|
|
int32 docSentParts;
|
|
|
|
int32 docSize;
|
|
|
|
int32 docPartSize;
|
|
|
|
int32 docPartsCount;
|
|
|
|
};
|
2015-09-03 10:48:40 +00:00
|
|
|
typedef QMap<FullMsgId, File> Queue;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
void partLoaded(const MTPBool &result, mtpRequestId requestId);
|
|
|
|
bool partFailed(const RPCError &err, mtpRequestId requestId);
|
|
|
|
|
|
|
|
void currentFailed();
|
|
|
|
|
|
|
|
QMap<mtpRequestId, QByteArray> requestsSent;
|
|
|
|
QMap<mtpRequestId, int32> docRequestsSent;
|
2014-10-30 16:23:44 +00:00
|
|
|
QMap<mtpRequestId, int32> dcMap;
|
2017-08-04 14:54:32 +00:00
|
|
|
uint32 sentSize = 0;
|
|
|
|
uint32 sentSizes[MTP::kUploadSessionsCount] = { 0 };
|
2016-02-12 16:35:06 +00:00
|
|
|
|
2015-12-24 19:26:28 +00:00
|
|
|
FullMsgId uploading, _paused;
|
2014-05-30 08:53:19 +00:00
|
|
|
Queue queue;
|
|
|
|
Queue uploaded;
|
2014-10-30 16:23:44 +00:00
|
|
|
QTimer nextTimer, killSessionsTimer;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
};
|
2017-08-04 14:54:32 +00:00
|
|
|
|
|
|
|
} // namespace Storage
|