mirror of https://github.com/procxx/kepka.git
Update intro change language link.
Also now MTP::Sender isn't bound to MTP::Instance, because Intro Widget is MTP::Sender, but Intro::PhoneWidget destroys current MTP::Instance.
This commit is contained in:
parent
b94099e25b
commit
d51fd7b3ad
|
@ -98,6 +98,8 @@ Widget::Widget(QWidget *parent) : TWidget(parent)
|
|||
}
|
||||
|
||||
void Widget::refreshLang() {
|
||||
_changeLanguage.destroy();
|
||||
createLanguageLink();
|
||||
InvokeQueued(this, [this] { updateControlsGeometry(); });
|
||||
}
|
||||
|
||||
|
@ -118,7 +120,9 @@ void Widget::createLanguageLink() {
|
|||
auto currentId = Lang::Current().id();
|
||||
auto defaultId = Lang::DefaultLanguageId();
|
||||
auto suggestedId = Lang::CurrentCloudManager().suggestedLanguage();
|
||||
if (!suggestedId.isEmpty() && suggestedId != currentId) {
|
||||
if (!currentId.isEmpty() && currentId != defaultId) {
|
||||
createLink(Lang::GetOriginalValue(lng_switch_to_this), defaultId);
|
||||
} else if (!suggestedId.isEmpty() && suggestedId != currentId) {
|
||||
request(MTPlangpack_GetStrings(MTP_string(suggestedId), MTP_vector<MTPstring>(1, MTP_string("lng_switch_to_this")))).done([this, suggestedId, createLink](const MTPVector<MTPLangPackString> &result) {
|
||||
auto strings = Lang::Instance::ParseStrings(result);
|
||||
auto it = strings.find(lng_switch_to_this);
|
||||
|
@ -126,8 +130,6 @@ void Widget::createLanguageLink() {
|
|||
createLink(it->second, suggestedId);
|
||||
}
|
||||
}).send();
|
||||
} else if (!currentId.isEmpty() && currentId != defaultId) {
|
||||
createLink(Lang::GetOriginalValue(lng_switch_to_this), defaultId);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
|||
|
||||
namespace Lang {
|
||||
|
||||
CloudManager::CloudManager(Instance &langpack, gsl::not_null<MTP::Instance*> mtproto) : MTP::Sender(mtproto)
|
||||
CloudManager::CloudManager(Instance &langpack, gsl::not_null<MTP::Instance*> mtproto) : MTP::Sender()
|
||||
, _langpack(langpack) {
|
||||
requestLangPackDifference();
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ QString langNewVersionText() {
|
|||
|
||||
bool langFirstNameGoesSecond() {
|
||||
auto fullname = lang(lng_full_name__tagged);
|
||||
for (auto begin = fullname.constData(), ch = begin, end = ch + fullname.size(); ch != end;) {
|
||||
for (auto begin = fullname.constData(), ch = begin, end = ch + fullname.size(); ch != end; ++ch) {
|
||||
if (*ch == TextCommand) {
|
||||
if (ch + 3 < end && (ch + 1)->unicode() == TextCommandLangTag && *(ch + 3) == TextCommand) {
|
||||
if ((ch + 2)->unicode() == 0x0020 + lt_last_name) {
|
||||
|
|
|
@ -186,7 +186,7 @@ private:
|
|||
|
||||
};
|
||||
|
||||
Instance::Private::Private(Instance *instance, DcOptions *options, Instance::Mode mode) : Sender(instance), _instance(instance)
|
||||
Instance::Private::Private(Instance *instance, DcOptions *options, Instance::Mode mode) : Sender(), _instance(instance)
|
||||
, _dcOptions(options)
|
||||
, _mode(mode) {
|
||||
}
|
||||
|
|
|
@ -186,9 +186,6 @@ class Sender {
|
|||
gsl::not_null<Sender*> sender() const noexcept {
|
||||
return _sender;
|
||||
}
|
||||
gsl::not_null<Instance*> instance() const noexcept {
|
||||
return _sender->_instance;
|
||||
}
|
||||
void registerRequest(mtpRequestId requestId) {
|
||||
_sender->requestRegister(requestId);
|
||||
}
|
||||
|
@ -205,7 +202,7 @@ class Sender {
|
|||
};
|
||||
|
||||
public:
|
||||
Sender(gsl::not_null<Instance*> instance = MainInstance()) noexcept : _instance(instance) {
|
||||
Sender() noexcept {
|
||||
}
|
||||
|
||||
template <typename Request>
|
||||
|
@ -255,7 +252,7 @@ public:
|
|||
}
|
||||
|
||||
mtpRequestId send() {
|
||||
auto id = instance()->send(_request, takeOnDone(), takeOnFail(), takeDcId(), takeCanWait(), takeAfter());
|
||||
auto id = MainInstance()->send(_request, takeOnDone(), takeOnFail(), takeDcId(), takeCanWait(), takeAfter());
|
||||
registerRequest(id);
|
||||
return id;
|
||||
}
|
||||
|
@ -288,7 +285,7 @@ public:
|
|||
SentRequestWrap request(mtpRequestId requestId) noexcept WARN_UNUSED_RESULT;
|
||||
|
||||
void requestSendDelayed() {
|
||||
_instance->sendAnything();
|
||||
MainInstance()->sendAnything();
|
||||
}
|
||||
void requestCancellingDiscard() {
|
||||
for (auto &request : _requests) {
|
||||
|
@ -296,30 +293,28 @@ public:
|
|||
}
|
||||
}
|
||||
gsl::not_null<Instance*> requestMTP() const {
|
||||
return _instance;
|
||||
return MainInstance();
|
||||
}
|
||||
|
||||
private:
|
||||
class RequestWrap {
|
||||
public:
|
||||
RequestWrap(Instance *instance, mtpRequestId requestId) noexcept : _instance(instance), _id(requestId) {
|
||||
RequestWrap(Instance *instance, mtpRequestId requestId) noexcept : _id(requestId) {
|
||||
}
|
||||
|
||||
mtpRequestId id() const noexcept {
|
||||
return _id;
|
||||
}
|
||||
void handled() const noexcept {
|
||||
_instance = nullptr;
|
||||
}
|
||||
|
||||
~RequestWrap() {
|
||||
if (_instance) {
|
||||
_instance->cancel(_id);
|
||||
if (auto instance = MainInstance()) {
|
||||
instance->cancel(_id);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
mutable Instance *_instance = nullptr;
|
||||
mtpRequestId _id = 0;
|
||||
|
||||
};
|
||||
|
@ -353,7 +348,7 @@ private:
|
|||
friend class SentRequestWrap;
|
||||
|
||||
void requestRegister(mtpRequestId requestId) {
|
||||
_requests.emplace(_instance, requestId);
|
||||
_requests.emplace(MainInstance(), requestId);
|
||||
}
|
||||
void requestHandled(mtpRequestId requestId) {
|
||||
auto it = _requests.find(requestId);
|
||||
|
@ -369,7 +364,6 @@ private:
|
|||
}
|
||||
}
|
||||
|
||||
gsl::not_null<Instance*> _instance;
|
||||
std::set<RequestWrap, RequestWrapComparator> _requests; // Better to use flatmap.
|
||||
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue