2014-05-30 12:53:19 +04:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2014-12-01 13:47:38 +03:00
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
2014-05-30 12:53:19 +04: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 16:16:42 +03: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 12:53:19 +04:00
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
2017-01-11 22:31:31 +04:00
|
|
|
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
2014-05-30 12:53:19 +04:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2017-12-19 20:57:42 +04:00
|
|
|
struct FileLoadResult;
|
|
|
|
struct SendMediaReady;
|
2014-05-30 12:53:19 +04:00
|
|
|
|
2017-08-04 16:54:32 +02:00
|
|
|
namespace Storage {
|
|
|
|
|
|
|
|
class Uploader : public QObject, public RPCSender {
|
2014-05-30 12:53:19 +04:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2017-08-04 16:54:32 +02:00
|
|
|
Uploader();
|
2016-11-28 18:45:07 +03:00
|
|
|
void uploadMedia(const FullMsgId &msgId, const SendMediaReady &image);
|
2017-12-19 20:57:42 +04:00
|
|
|
void upload(
|
|
|
|
const FullMsgId &msgId,
|
|
|
|
const std::shared_ptr<FileLoadResult> &file);
|
2014-05-30 12:53:19 +04:00
|
|
|
|
2015-09-03 13:48:40 +03:00
|
|
|
int32 currentOffset(const FullMsgId &msgId) const; // -1 means file not found
|
|
|
|
int32 fullSize(const FullMsgId &msgId) const;
|
2014-05-30 12:53:19 +04:00
|
|
|
|
2015-09-03 13:48:40 +03:00
|
|
|
void cancel(const FullMsgId &msgId);
|
2015-12-24 22:26:28 +03:00
|
|
|
void pause(const FullMsgId &msgId);
|
2015-09-03 13:48:40 +03:00
|
|
|
void confirm(const FullMsgId &msgId);
|
2014-05-30 12:53:19 +04:00
|
|
|
|
|
|
|
void clear();
|
|
|
|
|
2017-08-04 16:54:32 +02:00
|
|
|
~Uploader();
|
|
|
|
|
2014-05-30 12:53:19 +04:00
|
|
|
public slots:
|
2015-12-24 22:26:28 +03:00
|
|
|
void unpause();
|
2014-05-30 12:53:19 +04:00
|
|
|
void sendNext();
|
2014-10-30 19:23:44 +03:00
|
|
|
void killSessions();
|
2014-05-30 12:53:19 +04:00
|
|
|
|
|
|
|
signals:
|
2016-02-25 19:19:54 +03: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 12:53:19 +04:00
|
|
|
|
2015-09-03 13:48:40 +03:00
|
|
|
void photoProgress(const FullMsgId &msgId);
|
|
|
|
void documentProgress(const FullMsgId &msgId);
|
2014-05-30 12:53:19 +04:00
|
|
|
|
2015-09-03 13:48:40 +03:00
|
|
|
void photoFailed(const FullMsgId &msgId);
|
|
|
|
void documentFailed(const FullMsgId &msgId);
|
2014-05-30 12:53:19 +04:00
|
|
|
|
|
|
|
private:
|
2017-12-19 20:57:42 +04:00
|
|
|
struct File;
|
2014-05-30 12:53:19 +04:00
|
|
|
|
|
|
|
void partLoaded(const MTPBool &result, mtpRequestId requestId);
|
|
|
|
bool partFailed(const RPCError &err, mtpRequestId requestId);
|
|
|
|
|
|
|
|
void currentFailed();
|
|
|
|
|
2017-12-18 14:38:14 +04:00
|
|
|
base::flat_map<mtpRequestId, QByteArray> requestsSent;
|
|
|
|
base::flat_map<mtpRequestId, int32> docRequestsSent;
|
|
|
|
base::flat_map<mtpRequestId, int32> dcMap;
|
2017-08-04 16:54:32 +02:00
|
|
|
uint32 sentSize = 0;
|
|
|
|
uint32 sentSizes[MTP::kUploadSessionsCount] = { 0 };
|
2016-02-12 19:35:06 +03:00
|
|
|
|
2017-12-18 14:38:14 +04:00
|
|
|
FullMsgId uploadingId;
|
|
|
|
FullMsgId _pausedId;
|
|
|
|
std::map<FullMsgId, File> queue;
|
|
|
|
std::map<FullMsgId, File> uploaded;
|
2014-10-30 19:23:44 +03:00
|
|
|
QTimer nextTimer, killSessionsTimer;
|
2014-05-30 12:53:19 +04:00
|
|
|
|
|
|
|
};
|
2017-08-04 16:54:32 +02:00
|
|
|
|
|
|
|
} // namespace Storage
|