2017-04-18 15:21:03 +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.
|
2017-04-18 15:21:03 +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
|
2017-04-18 15:21:03 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "mtproto/sender.h"
|
2017-11-30 17:33:27 +00:00
|
|
|
#include "base/weak_ptr.h"
|
2017-04-18 15:21:03 +00:00
|
|
|
|
|
|
|
namespace MTP {
|
|
|
|
class Instance;
|
|
|
|
} // namespace MTP
|
|
|
|
|
|
|
|
namespace Lang {
|
|
|
|
|
|
|
|
class Instance;
|
|
|
|
|
2017-11-30 17:33:27 +00:00
|
|
|
class CloudManager : public base::has_weak_ptr, private MTP::Sender, private base::Subscriber {
|
2017-04-18 15:21:03 +00:00
|
|
|
public:
|
2017-08-17 08:31:24 +00:00
|
|
|
CloudManager(Instance &langpack, not_null<MTP::Instance*> mtproto);
|
2017-04-18 15:21:03 +00:00
|
|
|
|
|
|
|
struct Language {
|
|
|
|
QString id;
|
|
|
|
QString name;
|
2017-06-04 13:09:53 +00:00
|
|
|
QString nativeName;
|
2017-04-18 15:21:03 +00:00
|
|
|
};
|
|
|
|
using Languages = QVector<Language>;
|
|
|
|
|
|
|
|
void requestLanguageList();
|
|
|
|
Languages languageList() const {
|
|
|
|
return _languages;
|
|
|
|
}
|
|
|
|
base::Observable<void> &languageListChanged() {
|
|
|
|
return _languagesChanged;
|
|
|
|
}
|
|
|
|
void requestLangPackDifference();
|
|
|
|
void applyLangPackDifference(const MTPLangPackDifference &difference);
|
|
|
|
|
2017-05-30 17:58:25 +00:00
|
|
|
void resetToDefault();
|
|
|
|
void switchToLanguage(QString id);
|
|
|
|
void switchToTestLanguage();
|
2017-05-30 09:31:32 +00:00
|
|
|
void setSuggestedLanguage(const QString &langCode);
|
|
|
|
QString suggestedLanguage() const {
|
|
|
|
return _suggestedLanguage;
|
|
|
|
}
|
|
|
|
base::Observable<void> &firstLanguageSuggestion() {
|
|
|
|
return _firstLanguageSuggestion;
|
|
|
|
}
|
2017-04-18 15:21:03 +00:00
|
|
|
|
|
|
|
private:
|
2017-05-30 17:58:25 +00:00
|
|
|
bool canApplyWithoutRestart(const QString &id) const;
|
|
|
|
void performSwitchToCustom();
|
|
|
|
void performSwitch(const QString &id);
|
|
|
|
void performSwitchAndRestart(const QString &id);
|
2017-04-18 17:37:14 +00:00
|
|
|
void offerSwitchLangPack();
|
|
|
|
bool showOfferSwitchBox();
|
|
|
|
QString findOfferedLanguageName();
|
|
|
|
|
|
|
|
bool needToApplyLangPack(const QString &id);
|
|
|
|
void applyLangPackData(const MTPDlangPackDifference &data);
|
2017-04-18 15:21:03 +00:00
|
|
|
void switchLangPackId(const QString &id);
|
2017-04-18 17:37:14 +00:00
|
|
|
void changeIdAndReInitConnection(const QString &id);
|
2017-04-18 15:21:03 +00:00
|
|
|
|
|
|
|
Instance &_langpack;
|
|
|
|
Languages _languages;
|
|
|
|
base::Observable<void> _languagesChanged;
|
|
|
|
mtpRequestId _langPackRequestId = 0;
|
|
|
|
mtpRequestId _languagesRequestId = 0;
|
|
|
|
|
2017-04-18 17:37:14 +00:00
|
|
|
QString _offerSwitchToId;
|
2017-05-30 17:58:25 +00:00
|
|
|
bool _restartAfterSwitch = false;
|
2017-04-18 17:37:14 +00:00
|
|
|
|
2017-05-30 09:31:32 +00:00
|
|
|
QString _suggestedLanguage;
|
|
|
|
bool _languageWasSuggested = false;
|
|
|
|
base::Observable<void> _firstLanguageSuggestion;
|
|
|
|
|
2017-05-30 17:58:25 +00:00
|
|
|
mtpRequestId _switchingToLanguageRequest = 0;
|
|
|
|
|
2017-04-18 15:21:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
inline bool operator==(const CloudManager::Language &a, const CloudManager::Language &b) {
|
|
|
|
return (a.id == b.id) && (a.name == b.name);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool operator!=(const CloudManager::Language &a, const CloudManager::Language &b) {
|
|
|
|
return !(a == b);
|
|
|
|
}
|
|
|
|
|
|
|
|
CloudManager &CurrentCloudManager();
|
|
|
|
|
|
|
|
} // namespace Lang
|