2017-04-18 15:21:03 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
In addition, as a special exception, the copyright holders give permission
|
|
|
|
to link the code of portions of this program with the OpenSSL library.
|
|
|
|
|
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
|
|
|
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "mtproto/sender.h"
|
2017-05-30 17:58:25 +00:00
|
|
|
#include "base/weak_unique_ptr.h"
|
2017-04-18 15:21:03 +00:00
|
|
|
|
|
|
|
namespace MTP {
|
|
|
|
class Instance;
|
|
|
|
} // namespace MTP
|
|
|
|
|
|
|
|
namespace Lang {
|
|
|
|
|
|
|
|
class Instance;
|
|
|
|
|
2017-05-30 17:58:25 +00:00
|
|
|
class CloudManager : public base::enable_weak_from_this, private MTP::Sender, private base::Subscriber {
|
2017-04-18 15:21:03 +00:00
|
|
|
public:
|
|
|
|
CloudManager(Instance &langpack, gsl::not_null<MTP::Instance*> mtproto);
|
|
|
|
|
|
|
|
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
|