2014-05-30 08:53:19 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2014-05-30 08:53:19 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "base/observer.h"
|
2018-07-13 21:25:47 +00:00
|
|
|
#include "data/data_file_origin.h"
|
2018-08-27 11:35:58 +00:00
|
|
|
#include "base/binary_guard.h"
|
2016-05-25 17:59:21 +00:00
|
|
|
|
2017-03-04 19:36:59 +00:00
|
|
|
namespace Storage {
|
2018-08-27 11:35:58 +00:00
|
|
|
namespace Cache {
|
|
|
|
struct Key;
|
|
|
|
} // namespace Cache
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2017-08-15 15:59:40 +00:00
|
|
|
constexpr auto kMaxFileInMemory = 10 * 1024 * 1024; // 10 MB max file could be hold in memory
|
|
|
|
constexpr auto kMaxVoiceInMemory = 2 * 1024 * 1024; // 2 MB audio is hold in memory and auto loaded
|
|
|
|
constexpr auto kMaxStickerInMemory = 2 * 1024 * 1024; // 2 MB stickers hold in memory, auto loaded and displayed inline
|
|
|
|
constexpr auto kMaxAnimationInMemory = kMaxFileInMemory; // 10 MB gif and mp4 animations held in memory while playing
|
|
|
|
|
2017-03-04 19:36:59 +00:00
|
|
|
class Downloader final {
|
|
|
|
public:
|
2017-04-06 16:49:42 +00:00
|
|
|
Downloader();
|
|
|
|
|
2017-03-04 19:36:59 +00:00
|
|
|
int currentPriority() const {
|
|
|
|
return _priority;
|
|
|
|
}
|
|
|
|
void clearPriorities();
|
|
|
|
|
2017-04-06 16:49:42 +00:00
|
|
|
void delayedDestroyLoader(std::unique_ptr<FileLoader> loader);
|
|
|
|
|
2017-03-04 19:36:59 +00:00
|
|
|
base::Observable<void> &taskFinished() {
|
|
|
|
return _taskFinishedObservable;
|
|
|
|
}
|
|
|
|
|
2017-03-23 16:11:35 +00:00
|
|
|
void requestedAmountIncrement(MTP::DcId dcId, int index, int amount);
|
|
|
|
int chooseDcIndexForRequest(MTP::DcId dcId) const;
|
|
|
|
|
2017-04-15 17:35:13 +00:00
|
|
|
~Downloader();
|
|
|
|
|
2017-03-04 19:36:59 +00:00
|
|
|
private:
|
|
|
|
base::Observable<void> _taskFinishedObservable;
|
|
|
|
int _priority = 1;
|
2016-07-08 13:56:53 +00:00
|
|
|
|
2017-04-06 16:49:42 +00:00
|
|
|
SingleQueuedInvokation _delayedLoadersDestroyer;
|
|
|
|
std::vector<std::unique_ptr<FileLoader>> _delayedDestroyedLoaders;
|
|
|
|
|
2017-03-23 16:11:35 +00:00
|
|
|
using RequestedInDc = std::array<int64, MTP::kDownloadSessionsCount>;
|
|
|
|
std::map<MTP::DcId, RequestedInDc> _requestedBytesAmount;
|
|
|
|
|
2015-09-29 15:29:21 +00:00
|
|
|
};
|
|
|
|
|
2017-03-04 19:36:59 +00:00
|
|
|
} // namespace Storage
|
|
|
|
|
2015-09-29 18:44:31 +00:00
|
|
|
struct StorageImageSaved {
|
2017-03-04 11:28:21 +00:00
|
|
|
StorageImageSaved() = default;
|
|
|
|
explicit StorageImageSaved(const QByteArray &data) : data(data) {
|
2015-09-29 18:44:31 +00:00
|
|
|
}
|
2017-03-04 11:28:21 +00:00
|
|
|
|
2015-09-29 18:44:31 +00:00
|
|
|
QByteArray data;
|
2017-03-04 11:28:21 +00:00
|
|
|
|
2015-09-29 18:44:31 +00:00
|
|
|
};
|
|
|
|
|
2015-12-30 19:09:20 +00:00
|
|
|
class mtpFileLoader;
|
|
|
|
class webFileLoader;
|
|
|
|
|
|
|
|
struct FileLoaderQueue;
|
|
|
|
class FileLoader : public QObject {
|
2014-05-30 08:53:19 +00:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2018-08-28 21:09:55 +00:00
|
|
|
FileLoader(
|
|
|
|
const QString &toFile,
|
|
|
|
int32 size,
|
|
|
|
LocationType locationType,
|
|
|
|
LoadToCacheSetting toCache,
|
|
|
|
LoadFromCloudSetting fromCloud,
|
|
|
|
bool autoLoading,
|
|
|
|
uint8 cacheTag);
|
|
|
|
|
2017-03-04 11:28:21 +00:00
|
|
|
bool finished() const {
|
|
|
|
return _finished;
|
2015-09-29 18:44:31 +00:00
|
|
|
}
|
2018-10-12 16:41:51 +00:00
|
|
|
void finishWithBytes(const QByteArray &data);
|
2017-03-04 11:28:21 +00:00
|
|
|
bool cancelled() const {
|
|
|
|
return _cancelled;
|
2015-09-29 18:44:31 +00:00
|
|
|
}
|
|
|
|
const QByteArray &bytes() const {
|
2015-12-24 19:26:28 +00:00
|
|
|
return _data;
|
2015-09-29 18:44:31 +00:00
|
|
|
}
|
2017-03-03 16:59:57 +00:00
|
|
|
virtual uint64 objId() const {
|
|
|
|
return 0;
|
|
|
|
}
|
2016-04-10 14:53:01 +00:00
|
|
|
QByteArray imageFormat(const QSize &shrinkBox = QSize()) const;
|
2018-10-12 16:41:51 +00:00
|
|
|
QImage imageData(const QSize &shrinkBox = QSize()) const;
|
2015-09-29 18:44:31 +00:00
|
|
|
QString fileName() const {
|
2017-08-15 15:59:40 +00:00
|
|
|
return _filename;
|
2015-09-29 18:44:31 +00:00
|
|
|
}
|
2018-07-13 21:25:47 +00:00
|
|
|
virtual Data::FileOrigin fileOrigin() const {
|
|
|
|
return Data::FileOrigin();
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
float64 currentProgress() const;
|
2015-12-30 19:09:20 +00:00
|
|
|
virtual int32 currentOffset(bool includeSkipped = false) const = 0;
|
2014-05-30 08:53:19 +00:00
|
|
|
int32 fullSize() const;
|
|
|
|
|
2015-12-24 19:26:28 +00:00
|
|
|
bool setFileName(const QString &filename); // set filename for loaders to cache
|
|
|
|
void permitLoadFromCloud();
|
2014-09-04 07:33:44 +00:00
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
void pause();
|
|
|
|
void start(bool loadFirst = false, bool prior = true);
|
|
|
|
void cancel();
|
2015-12-23 19:23:14 +00:00
|
|
|
|
|
|
|
bool loading() const {
|
2015-12-24 19:26:28 +00:00
|
|
|
return _inQueue;
|
2015-12-23 19:23:14 +00:00
|
|
|
}
|
|
|
|
bool paused() const {
|
|
|
|
return _paused;
|
|
|
|
}
|
|
|
|
bool started() const {
|
2015-12-24 19:26:28 +00:00
|
|
|
return _inQueue || _paused;
|
2015-12-23 19:23:14 +00:00
|
|
|
}
|
|
|
|
bool loadingLocal() const {
|
2018-08-27 11:35:58 +00:00
|
|
|
return (_localStatus == LocalStatus::Loading);
|
2015-12-23 19:23:14 +00:00
|
|
|
}
|
2015-12-24 19:26:28 +00:00
|
|
|
bool autoLoading() const {
|
|
|
|
return _autoLoading;
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2015-12-30 19:09:20 +00:00
|
|
|
virtual void stop() {
|
|
|
|
}
|
|
|
|
virtual ~FileLoader();
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2018-08-27 11:35:58 +00:00
|
|
|
void localLoaded(
|
|
|
|
const StorageImageSaved &result,
|
2018-10-12 16:41:51 +00:00
|
|
|
const QByteArray &imageFormat,
|
|
|
|
const QImage &imageData);
|
2015-09-29 18:44:31 +00:00
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
signals:
|
2015-12-30 19:09:20 +00:00
|
|
|
void progress(FileLoader *loader);
|
|
|
|
void failed(FileLoader *loader, bool started);
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2015-12-30 19:09:20 +00:00
|
|
|
protected:
|
2018-08-27 11:35:58 +00:00
|
|
|
enum class LocalStatus {
|
|
|
|
NotTried,
|
|
|
|
NotFound,
|
|
|
|
Loading,
|
|
|
|
Loaded,
|
|
|
|
};
|
|
|
|
|
2016-04-10 14:53:01 +00:00
|
|
|
void readImage(const QSize &shrinkBox) const;
|
2015-12-30 19:09:20 +00:00
|
|
|
|
2018-08-27 11:35:58 +00:00
|
|
|
bool tryLoadLocal();
|
|
|
|
void loadLocal(const Storage::Cache::Key &key);
|
2018-09-21 16:28:46 +00:00
|
|
|
virtual std::optional<Storage::Cache::Key> cacheKey() const = 0;
|
2018-08-27 11:35:58 +00:00
|
|
|
virtual void cancelRequests() = 0;
|
|
|
|
|
|
|
|
void startLoading(bool loadFirst, bool prior);
|
|
|
|
void removeFromQueue();
|
|
|
|
void cancel(bool failed);
|
|
|
|
|
|
|
|
void loadNext();
|
|
|
|
virtual bool loadPart() = 0;
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
not_null<Storage::Downloader*> _downloader;
|
2016-10-12 19:34:25 +00:00
|
|
|
FileLoader *_prev = nullptr;
|
|
|
|
FileLoader *_next = nullptr;
|
|
|
|
int _priority = 0;
|
2017-03-23 16:11:35 +00:00
|
|
|
FileLoaderQueue *_queue = nullptr;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-10-12 19:34:25 +00:00
|
|
|
bool _paused = false;
|
|
|
|
bool _autoLoading = false;
|
2018-08-28 21:09:55 +00:00
|
|
|
uint8 _cacheTag = 0;
|
2016-10-12 19:34:25 +00:00
|
|
|
bool _inQueue = false;
|
2017-03-04 11:28:21 +00:00
|
|
|
bool _finished = false;
|
|
|
|
bool _cancelled = false;
|
2018-08-27 11:35:58 +00:00
|
|
|
mutable LocalStatus _localStatus = LocalStatus::NotTried;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2017-08-15 15:59:40 +00:00
|
|
|
QString _filename;
|
2015-12-24 19:26:28 +00:00
|
|
|
QFile _file;
|
2016-10-12 19:34:25 +00:00
|
|
|
bool _fileIsOpen = false;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2015-12-24 19:26:28 +00:00
|
|
|
LoadToCacheSetting _toCache;
|
|
|
|
LoadFromCloudSetting _fromCloud;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2015-12-24 19:26:28 +00:00
|
|
|
QByteArray _data;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2015-12-24 19:26:28 +00:00
|
|
|
int32 _size;
|
2015-12-30 19:09:20 +00:00
|
|
|
LocationType _locationType;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2018-08-27 11:35:58 +00:00
|
|
|
base::binary_guard _localLoading;
|
2015-09-29 18:44:31 +00:00
|
|
|
mutable QByteArray _imageFormat;
|
2018-10-12 16:41:51 +00:00
|
|
|
mutable QImage _imageData;
|
2015-09-29 18:44:31 +00:00
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
};
|
2015-12-24 19:26:28 +00:00
|
|
|
|
2015-12-30 19:09:20 +00:00
|
|
|
class StorageImageLocation;
|
2018-03-04 20:04:13 +00:00
|
|
|
class WebFileLocation;
|
2015-12-30 19:09:20 +00:00
|
|
|
class mtpFileLoader : public FileLoader, public RPCSender {
|
|
|
|
public:
|
2018-07-13 16:49:46 +00:00
|
|
|
mtpFileLoader(
|
2018-07-15 16:36:19 +00:00
|
|
|
not_null<StorageImageLocation*> location,
|
2018-07-13 21:25:47 +00:00
|
|
|
Data::FileOrigin origin,
|
2018-07-13 16:49:46 +00:00
|
|
|
int32 size,
|
|
|
|
LoadFromCloudSetting fromCloud,
|
2018-08-28 21:09:55 +00:00
|
|
|
bool autoLoading,
|
|
|
|
uint8 cacheTag);
|
2018-07-13 16:49:46 +00:00
|
|
|
mtpFileLoader(
|
|
|
|
int32 dc,
|
|
|
|
uint64 id,
|
|
|
|
uint64 accessHash,
|
|
|
|
const QByteArray &fileReference,
|
2018-07-13 21:25:47 +00:00
|
|
|
Data::FileOrigin origin,
|
2018-07-13 16:49:46 +00:00
|
|
|
LocationType type,
|
|
|
|
const QString &toFile,
|
|
|
|
int32 size,
|
|
|
|
LoadToCacheSetting toCache,
|
|
|
|
LoadFromCloudSetting fromCloud,
|
2018-08-28 21:09:55 +00:00
|
|
|
bool autoLoading,
|
|
|
|
uint8 cacheTag);
|
2018-07-13 16:49:46 +00:00
|
|
|
mtpFileLoader(
|
|
|
|
const WebFileLocation *location,
|
|
|
|
int32 size,
|
|
|
|
LoadFromCloudSetting fromCloud,
|
2018-08-28 21:09:55 +00:00
|
|
|
bool autoLoading,
|
|
|
|
uint8 cacheTag);
|
2018-10-08 18:14:05 +00:00
|
|
|
mtpFileLoader(
|
|
|
|
const GeoPointLocation *location,
|
|
|
|
int32 size,
|
|
|
|
LoadFromCloudSetting fromCloud,
|
|
|
|
bool autoLoading,
|
|
|
|
uint8 cacheTag);
|
2015-12-30 19:09:20 +00:00
|
|
|
|
2017-03-03 16:59:57 +00:00
|
|
|
int32 currentOffset(bool includeSkipped = false) const override;
|
2018-07-13 21:25:47 +00:00
|
|
|
Data::FileOrigin fileOrigin() const override;
|
2015-12-30 19:09:20 +00:00
|
|
|
|
2017-03-03 16:59:57 +00:00
|
|
|
uint64 objId() const override {
|
2015-12-30 19:09:20 +00:00
|
|
|
return _id;
|
|
|
|
}
|
|
|
|
|
2017-03-03 16:59:57 +00:00
|
|
|
void stop() override {
|
2017-04-06 19:02:40 +00:00
|
|
|
rpcInvalidate();
|
2015-12-30 19:09:20 +00:00
|
|
|
}
|
2018-07-15 16:36:19 +00:00
|
|
|
void refreshFileReferenceFrom(
|
|
|
|
const Data::UpdatedFileReferences &data,
|
|
|
|
int requestId,
|
|
|
|
const QByteArray ¤t);
|
2015-12-30 19:09:20 +00:00
|
|
|
|
|
|
|
~mtpFileLoader();
|
|
|
|
|
2017-03-05 17:33:32 +00:00
|
|
|
private:
|
2017-03-23 16:11:35 +00:00
|
|
|
struct RequestData {
|
|
|
|
MTP::DcId dcId = 0;
|
|
|
|
int dcIndex = 0;
|
|
|
|
int offset = 0;
|
|
|
|
};
|
2017-07-13 09:13:07 +00:00
|
|
|
struct CdnFileHash {
|
|
|
|
CdnFileHash(int limit, QByteArray hash) : limit(limit), hash(hash) {
|
|
|
|
}
|
|
|
|
int limit = 0;
|
|
|
|
QByteArray hash;
|
|
|
|
};
|
2018-09-21 16:28:46 +00:00
|
|
|
std::optional<Storage::Cache::Key> cacheKey() const override;
|
2017-03-03 16:59:57 +00:00
|
|
|
void cancelRequests() override;
|
2015-12-30 19:09:20 +00:00
|
|
|
|
2017-03-05 17:33:32 +00:00
|
|
|
int partSize() const;
|
2017-03-23 16:11:35 +00:00
|
|
|
RequestData prepareRequest(int offset) const;
|
|
|
|
void makeRequest(int offset);
|
2015-12-30 19:09:20 +00:00
|
|
|
|
2018-03-04 20:04:13 +00:00
|
|
|
MTPInputFileLocation computeLocation() const;
|
2017-03-03 16:59:57 +00:00
|
|
|
bool loadPart() override;
|
2017-03-23 16:11:35 +00:00
|
|
|
void normalPartLoaded(const MTPupload_File &result, mtpRequestId requestId);
|
|
|
|
void webPartLoaded(const MTPupload_WebFile &result, mtpRequestId requestId);
|
|
|
|
void cdnPartLoaded(const MTPupload_CdnFile &result, mtpRequestId requestId);
|
2018-03-04 20:04:13 +00:00
|
|
|
void reuploadDone(const MTPVector<MTPFileHash> &result, mtpRequestId requestId);
|
2017-07-13 09:13:07 +00:00
|
|
|
void requestMoreCdnFileHashes();
|
2018-03-04 20:04:13 +00:00
|
|
|
void getCdnFileHashesDone(const MTPVector<MTPFileHash> &result, mtpRequestId requestId);
|
2017-03-05 17:33:32 +00:00
|
|
|
|
2018-03-27 12:16:00 +00:00
|
|
|
bool feedPart(int offset, bytes::const_span buffer);
|
|
|
|
void partLoaded(int offset, bytes::const_span buffer);
|
2017-12-08 13:13:13 +00:00
|
|
|
|
2018-07-13 16:49:46 +00:00
|
|
|
bool partFailed(const RPCError &error, mtpRequestId requestId);
|
2017-03-23 16:11:35 +00:00
|
|
|
bool cdnPartFailed(const RPCError &error, mtpRequestId requestId);
|
|
|
|
|
|
|
|
void placeSentRequest(mtpRequestId requestId, const RequestData &requestData);
|
|
|
|
int finishSentRequestGetOffset(mtpRequestId requestId);
|
|
|
|
void switchToCDN(int offset, const MTPDupload_fileCdnRedirect &redirect);
|
2018-03-04 20:04:13 +00:00
|
|
|
void addCdnHashes(const QVector<MTPFileHash> &hashes);
|
|
|
|
void changeCDNParams(int offset, MTP::DcId dcId, const QByteArray &token, const QByteArray &encryptionKey, const QByteArray &encryptionIV, const QVector<MTPFileHash> &hashes);
|
2017-07-13 09:13:07 +00:00
|
|
|
|
|
|
|
enum class CheckCdnHashResult {
|
|
|
|
NoHash,
|
|
|
|
Invalid,
|
|
|
|
Good,
|
|
|
|
};
|
2018-03-27 12:16:00 +00:00
|
|
|
CheckCdnHashResult checkCdnFileHash(int offset, bytes::const_span buffer);
|
2017-03-23 16:11:35 +00:00
|
|
|
|
|
|
|
std::map<mtpRequestId, RequestData> _sentRequests;
|
2015-12-30 19:09:20 +00:00
|
|
|
|
2016-07-08 13:56:53 +00:00
|
|
|
bool _lastComplete = false;
|
|
|
|
int32 _skippedBytes = 0;
|
|
|
|
int32 _nextRequestOffset = 0;
|
2015-12-30 19:09:20 +00:00
|
|
|
|
2017-03-23 16:11:35 +00:00
|
|
|
MTP::DcId _dcId = 0; // for photo locations
|
2018-07-15 16:36:19 +00:00
|
|
|
StorageImageLocation *_location = nullptr;
|
2015-12-30 19:09:20 +00:00
|
|
|
|
2017-03-05 17:33:32 +00:00
|
|
|
uint64 _id = 0; // for document locations
|
|
|
|
uint64 _accessHash = 0;
|
2018-07-13 16:49:46 +00:00
|
|
|
QByteArray _fileReference;
|
2015-12-31 15:27:21 +00:00
|
|
|
|
2018-03-04 20:04:13 +00:00
|
|
|
const WebFileLocation *_urlLocation = nullptr; // for webdocument locations
|
2018-10-08 18:14:05 +00:00
|
|
|
const GeoPointLocation *_geoLocation = nullptr; // for webdocument locations
|
2017-03-05 17:33:32 +00:00
|
|
|
|
2018-07-13 21:25:47 +00:00
|
|
|
Data::FileOrigin _origin;
|
|
|
|
|
2017-03-23 16:11:35 +00:00
|
|
|
MTP::DcId _cdnDcId = 0;
|
|
|
|
QByteArray _cdnToken;
|
|
|
|
QByteArray _cdnEncryptionKey;
|
|
|
|
QByteArray _cdnEncryptionIV;
|
2017-07-13 09:13:07 +00:00
|
|
|
std::map<int, CdnFileHash> _cdnFileHashes;
|
|
|
|
std::map<int, QByteArray> _cdnUncheckedParts;
|
|
|
|
mtpRequestId _cdnHashesRequestId = 0;
|
2017-03-23 16:11:35 +00:00
|
|
|
|
2015-12-30 19:09:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class webFileLoaderPrivate;
|
|
|
|
|
|
|
|
class webFileLoader : public FileLoader {
|
|
|
|
public:
|
2018-08-27 11:35:58 +00:00
|
|
|
webFileLoader(
|
|
|
|
const QString &url,
|
|
|
|
const QString &to,
|
|
|
|
LoadFromCloudSetting fromCloud,
|
2018-08-28 21:09:55 +00:00
|
|
|
bool autoLoading,
|
|
|
|
uint8 cacheTag);
|
2015-12-30 19:09:20 +00:00
|
|
|
|
2018-08-27 11:35:58 +00:00
|
|
|
int32 currentOffset(bool includeSkipped = false) const override;
|
2015-12-30 19:09:20 +00:00
|
|
|
|
|
|
|
void onProgress(qint64 already, qint64 size);
|
|
|
|
void onFinished(const QByteArray &data);
|
|
|
|
void onError();
|
|
|
|
|
2018-08-27 11:35:58 +00:00
|
|
|
void stop() override {
|
2015-12-30 19:09:20 +00:00
|
|
|
cancelRequests();
|
|
|
|
}
|
|
|
|
|
|
|
|
~webFileLoader();
|
|
|
|
|
|
|
|
protected:
|
2018-08-27 11:35:58 +00:00
|
|
|
void cancelRequests() override;
|
2018-09-21 16:28:46 +00:00
|
|
|
std::optional<Storage::Cache::Key> cacheKey() const override;
|
2018-08-27 11:35:58 +00:00
|
|
|
bool loadPart() override;
|
2015-12-30 19:09:20 +00:00
|
|
|
|
|
|
|
QString _url;
|
|
|
|
|
|
|
|
bool _requestSent;
|
|
|
|
int32 _already;
|
|
|
|
|
|
|
|
friend class WebLoadManager;
|
|
|
|
webFileLoaderPrivate *_private;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
enum WebReplyProcessResult {
|
|
|
|
WebReplyProcessError,
|
|
|
|
WebReplyProcessProgress,
|
|
|
|
WebReplyProcessFinished,
|
|
|
|
};
|
|
|
|
|
|
|
|
class WebLoadManager : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
WebLoadManager(QThread *thread);
|
|
|
|
|
|
|
|
void append(webFileLoader *loader, const QString &url);
|
|
|
|
void stop(webFileLoader *reader);
|
|
|
|
bool carries(webFileLoader *reader) const;
|
|
|
|
|
|
|
|
~WebLoadManager();
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void processDelayed();
|
|
|
|
|
|
|
|
void progress(webFileLoader *loader, qint64 already, qint64 size);
|
|
|
|
void finished(webFileLoader *loader, QByteArray data);
|
|
|
|
void error(webFileLoader *loader);
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
void onFailed(QNetworkReply *reply);
|
|
|
|
void onFailed(QNetworkReply::NetworkError error);
|
|
|
|
void onProgress(qint64 already, qint64 size);
|
|
|
|
void onMeta();
|
|
|
|
|
|
|
|
void process();
|
|
|
|
void finish();
|
|
|
|
|
|
|
|
private:
|
|
|
|
void clear();
|
|
|
|
void sendRequest(webFileLoaderPrivate *loader, const QString &redirect = QString());
|
|
|
|
bool handleReplyResult(webFileLoaderPrivate *loader, WebReplyProcessResult result);
|
|
|
|
|
|
|
|
QNetworkAccessManager _manager;
|
|
|
|
typedef QMap<webFileLoader*, webFileLoaderPrivate*> LoaderPointers;
|
|
|
|
LoaderPointers _loaderPointers;
|
|
|
|
mutable QMutex _loaderPointersMutex;
|
|
|
|
|
|
|
|
typedef OrderedSet<webFileLoaderPrivate*> Loaders;
|
|
|
|
Loaders _loaders;
|
|
|
|
|
|
|
|
typedef QMap<QNetworkReply*, webFileLoaderPrivate*> Replies;
|
|
|
|
Replies _replies;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class WebLoadMainManager : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
void progress(webFileLoader *loader, qint64 already, qint64 size);
|
|
|
|
void finished(webFileLoader *loader, QByteArray data);
|
|
|
|
void error(webFileLoader *loader);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
static FileLoader * const CancelledFileLoader = SharedMemoryLocation<FileLoader, 0>();
|
|
|
|
static mtpFileLoader * const CancelledMtpFileLoader = static_cast<mtpFileLoader*>(CancelledFileLoader);
|
|
|
|
static webFileLoader * const CancelledWebFileLoader = static_cast<webFileLoader*>(CancelledFileLoader);
|
|
|
|
static WebLoadManager * const FinishedWebLoadManager = SharedMemoryLocation<WebLoadManager, 0>();
|
|
|
|
|
|
|
|
void stopWebLoadManager();
|