2020-02-05 10:29:27 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
|
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2020-02-05 14:13:12 +00:00
|
|
|
#include "mtproto/dedicated_file_loader.h"
|
|
|
|
|
2020-02-05 14:28:22 +00:00
|
|
|
namespace tr {
|
|
|
|
template <typename ...>
|
|
|
|
struct phrase;
|
|
|
|
} // namespace tr
|
|
|
|
|
2020-06-10 10:49:10 +00:00
|
|
|
namespace Main {
|
|
|
|
class Session;
|
|
|
|
} // namespace Main
|
|
|
|
|
2020-02-05 13:06:38 +00:00
|
|
|
namespace Storage::CloudBlob {
|
2020-02-05 10:29:27 +00:00
|
|
|
|
2020-02-05 14:13:12 +00:00
|
|
|
constexpr auto kCloudLocationUsername = "tdhbcfiles"_cs;
|
|
|
|
|
2020-02-05 10:59:07 +00:00
|
|
|
struct Blob {
|
|
|
|
int id = 0;
|
|
|
|
int postId = 0;
|
2022-05-10 14:22:28 +00:00
|
|
|
int64 size = 0;
|
2020-02-05 10:59:07 +00:00
|
|
|
QString name;
|
|
|
|
};
|
|
|
|
|
2020-02-05 13:06:38 +00:00
|
|
|
struct Available {
|
2022-05-10 14:22:28 +00:00
|
|
|
int64 size = 0;
|
2020-02-05 13:06:38 +00:00
|
|
|
|
|
|
|
inline bool operator<(const Available &other) const {
|
|
|
|
return size < other.size;
|
|
|
|
}
|
|
|
|
inline bool operator==(const Available &other) const {
|
|
|
|
return size == other.size;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
struct Ready {
|
|
|
|
inline bool operator<(const Ready &other) const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
inline bool operator==(const Ready &other) const {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
struct Active {
|
|
|
|
inline bool operator<(const Active &other) const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
inline bool operator==(const Active &other) const {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
struct Failed {
|
|
|
|
inline bool operator<(const Failed &other) const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
inline bool operator==(const Failed &other) const {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-02-05 14:13:12 +00:00
|
|
|
using Loading = MTP::DedicatedLoader::Progress;
|
2020-08-31 08:14:53 +00:00
|
|
|
using BlobState = std::variant<
|
2020-02-05 14:13:12 +00:00
|
|
|
Available,
|
|
|
|
Ready,
|
|
|
|
Active,
|
|
|
|
Failed,
|
|
|
|
Loading>;
|
|
|
|
|
2020-02-05 10:29:27 +00:00
|
|
|
bool UnpackBlob(
|
|
|
|
const QString &path,
|
|
|
|
const QString &folder,
|
|
|
|
Fn<bool(const QString &)> checkNameCallback);
|
|
|
|
|
2020-02-05 14:28:22 +00:00
|
|
|
QString StateDescription(const BlobState &state, tr::phrase<> activeText);
|
|
|
|
|
2020-02-05 14:13:12 +00:00
|
|
|
class BlobLoader : public QObject {
|
|
|
|
public:
|
|
|
|
BlobLoader(
|
|
|
|
QObject *parent,
|
2020-06-10 10:49:10 +00:00
|
|
|
not_null<Main::Session*> session,
|
2020-02-05 14:13:12 +00:00
|
|
|
int id,
|
|
|
|
MTP::DedicatedLoader::Location location,
|
|
|
|
const QString &folder,
|
2022-05-10 14:22:28 +00:00
|
|
|
int64 size);
|
2020-02-05 14:13:12 +00:00
|
|
|
|
|
|
|
int id() const;
|
|
|
|
|
|
|
|
rpl::producer<BlobState> state() const;
|
|
|
|
virtual void destroy() = 0;
|
|
|
|
virtual void unpack(const QString &path) = 0;
|
|
|
|
|
|
|
|
protected:
|
2020-02-21 18:55:11 +00:00
|
|
|
virtual void fail();
|
2020-02-05 14:13:12 +00:00
|
|
|
|
|
|
|
const QString _folder;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void setImplementation(std::unique_ptr<MTP::DedicatedLoader> loader);
|
|
|
|
|
|
|
|
int _id = 0;
|
|
|
|
rpl::variable<BlobState> _state;
|
|
|
|
|
|
|
|
MTP::WeakInstance _mtproto;
|
2020-06-10 10:49:10 +00:00
|
|
|
|
2020-02-05 14:13:12 +00:00
|
|
|
std::unique_ptr<MTP::DedicatedLoader> _implementation;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2020-02-05 13:06:38 +00:00
|
|
|
} // namespace Storage::CloudBlob
|