tdesktop/Telegram/SourceFiles/lang/lang_cloud_manager.h

106 lines
2.9 KiB
C
Raw Normal View History

/*
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
#include "mtproto/sender.h"
#include "base/weak_ptr.h"
namespace MTP {
class Instance;
} // namespace MTP
namespace Lang {
class Instance;
enum class Pack;
struct Language;
Language ParseLanguage(const MTPLangPackLanguage &data);
2019-11-27 08:02:56 +00:00
class CloudManager : public base::has_weak_ptr, private base::Subscriber {
public:
2019-11-27 08:02:56 +00:00
explicit CloudManager(Instance &langpack);
using Languages = std::vector<Language>;
void requestLanguageList();
const Languages &languageList() const {
return _languages;
}
base::Observable<void> &languageListChanged() {
return _languagesChanged;
}
void requestLangPackDifference(const QString &langId);
void applyLangPackDifference(const MTPLangPackDifference &difference);
2018-11-06 11:29:01 +00:00
void setCurrentVersions(int version, int baseVersion);
void resetToDefault();
void switchWithWarning(const QString &id);
void switchToLanguage(const QString &id);
void switchToLanguage(const Language &data);
void switchToTestLanguage();
void setSuggestedLanguage(const QString &langCode);
QString suggestedLanguage() const {
return _suggestedLanguage;
}
base::Observable<void> &firstLanguageSuggestion() {
return _firstLanguageSuggestion;
}
private:
mtpRequestId &packRequestId(Pack pack);
mtpRequestId packRequestId(Pack pack) const;
Pack packTypeFromId(const QString &id) const;
void requestLangPackDifference(Pack pack);
bool canApplyWithoutRestart(const QString &id) const;
void performSwitchToCustom();
void performSwitch(const Language &data);
2019-06-19 11:22:25 +00:00
void performSwitchAndAddToRecent(const Language &data);
void performSwitchAndRestart(const Language &data);
void restartAfterSwitch();
void offerSwitchLangPack();
bool showOfferSwitchBox();
Language findOfferedLanguage() const;
void requestLanguageAndSwitch(const QString &id, bool warning);
void applyLangPackData(Pack pack, const MTPDlangPackDifference &data);
void switchLangPackId(const Language &data);
void changeIdAndReInitConnection(const Language &data);
2019-11-27 08:02:56 +00:00
void sendSwitchingToLanguageRequest();
void resendRequests();
std::optional<MTP::Sender> _api;
Instance &_langpack;
Languages _languages;
base::Observable<void> _languagesChanged;
mtpRequestId _langPackRequestId = 0;
mtpRequestId _langPackBaseRequestId = 0;
mtpRequestId _languagesRequestId = 0;
QString _offerSwitchToId;
bool _restartAfterSwitch = false;
QString _suggestedLanguage;
bool _languageWasSuggested = false;
base::Observable<void> _firstLanguageSuggestion;
mtpRequestId _switchingToLanguageRequest = 0;
2019-11-27 08:02:56 +00:00
QString _switchingToLanguageId;
bool _switchingToLanguageWarning = false;
mtpRequestId _getKeysForSwitchRequestId = 0;
rpl::lifetime _lifetime;
};
CloudManager &CurrentCloudManager();
} // namespace Lang