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
					
				
					 5 changed files with 16 additions and 20 deletions
				
			
		|  | @ -98,6 +98,8 @@ Widget::Widget(QWidget *parent) : TWidget(parent) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void Widget::refreshLang() { | void Widget::refreshLang() { | ||||||
|  | 	_changeLanguage.destroy(); | ||||||
|  | 	createLanguageLink(); | ||||||
| 	InvokeQueued(this, [this] { updateControlsGeometry(); }); | 	InvokeQueued(this, [this] { updateControlsGeometry(); }); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -118,7 +120,9 @@ void Widget::createLanguageLink() { | ||||||
| 	auto currentId = Lang::Current().id(); | 	auto currentId = Lang::Current().id(); | ||||||
| 	auto defaultId = Lang::DefaultLanguageId(); | 	auto defaultId = Lang::DefaultLanguageId(); | ||||||
| 	auto suggestedId = Lang::CurrentCloudManager().suggestedLanguage(); | 	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) { | 		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 strings = Lang::Instance::ParseStrings(result); | ||||||
| 			auto it = strings.find(lng_switch_to_this); | 			auto it = strings.find(lng_switch_to_this); | ||||||
|  | @ -126,8 +130,6 @@ void Widget::createLanguageLink() { | ||||||
| 				createLink(it->second, suggestedId); | 				createLink(it->second, suggestedId); | ||||||
| 			} | 			} | ||||||
| 		}).send(); | 		}).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 { | 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) { | , _langpack(langpack) { | ||||||
| 	requestLangPackDifference(); | 	requestLangPackDifference(); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -38,7 +38,7 @@ QString langNewVersionText() { | ||||||
| 
 | 
 | ||||||
| bool langFirstNameGoesSecond() { | bool langFirstNameGoesSecond() { | ||||||
| 	auto fullname = lang(lng_full_name__tagged); | 	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 == TextCommand) { | ||||||
| 			if (ch + 3 < end && (ch + 1)->unicode() == TextCommandLangTag && *(ch + 3) == TextCommand) { | 			if (ch + 3 < end && (ch + 1)->unicode() == TextCommandLangTag && *(ch + 3) == TextCommand) { | ||||||
| 				if ((ch + 2)->unicode() == 0x0020 + lt_last_name) { | 				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) | , _dcOptions(options) | ||||||
| , _mode(mode) { | , _mode(mode) { | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -186,9 +186,6 @@ class Sender { | ||||||
| 		gsl::not_null<Sender*> sender() const noexcept { | 		gsl::not_null<Sender*> sender() const noexcept { | ||||||
| 			return _sender; | 			return _sender; | ||||||
| 		} | 		} | ||||||
| 		gsl::not_null<Instance*> instance() const noexcept { |  | ||||||
| 			return _sender->_instance; |  | ||||||
| 		} |  | ||||||
| 		void registerRequest(mtpRequestId requestId) { | 		void registerRequest(mtpRequestId requestId) { | ||||||
| 			_sender->requestRegister(requestId); | 			_sender->requestRegister(requestId); | ||||||
| 		} | 		} | ||||||
|  | @ -205,7 +202,7 @@ class Sender { | ||||||
| 	}; | 	}; | ||||||
| 
 | 
 | ||||||
| public: | public: | ||||||
| 	Sender(gsl::not_null<Instance*> instance = MainInstance()) noexcept : _instance(instance) { | 	Sender() noexcept { | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	template <typename Request> | 	template <typename Request> | ||||||
|  | @ -255,7 +252,7 @@ public: | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		mtpRequestId send() { | 		mtpRequestId send() { | ||||||
| 			auto id = instance()->send(_request, takeOnDone(), takeOnFail(), takeDcId(), takeCanWait(), takeAfter()); | 			auto id = MainInstance()->send(_request, takeOnDone(), takeOnFail(), takeDcId(), takeCanWait(), takeAfter()); | ||||||
| 			registerRequest(id); | 			registerRequest(id); | ||||||
| 			return id; | 			return id; | ||||||
| 		} | 		} | ||||||
|  | @ -288,7 +285,7 @@ public: | ||||||
| 	SentRequestWrap request(mtpRequestId requestId) noexcept WARN_UNUSED_RESULT; | 	SentRequestWrap request(mtpRequestId requestId) noexcept WARN_UNUSED_RESULT; | ||||||
| 
 | 
 | ||||||
| 	void requestSendDelayed() { | 	void requestSendDelayed() { | ||||||
| 		_instance->sendAnything(); | 		MainInstance()->sendAnything(); | ||||||
| 	} | 	} | ||||||
| 	void requestCancellingDiscard() { | 	void requestCancellingDiscard() { | ||||||
| 		for (auto &request : _requests) { | 		for (auto &request : _requests) { | ||||||
|  | @ -296,30 +293,28 @@ public: | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	gsl::not_null<Instance*> requestMTP() const { | 	gsl::not_null<Instance*> requestMTP() const { | ||||||
| 		return _instance; | 		return MainInstance(); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
| 	class RequestWrap { | 	class RequestWrap { | ||||||
| 	public: | 	public: | ||||||
| 		RequestWrap(Instance *instance, mtpRequestId requestId) noexcept : _instance(instance), _id(requestId) { | 		RequestWrap(Instance *instance, mtpRequestId requestId) noexcept : _id(requestId) { | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		mtpRequestId id() const noexcept { | 		mtpRequestId id() const noexcept { | ||||||
| 			return _id; | 			return _id; | ||||||
| 		} | 		} | ||||||
| 		void handled() const noexcept { | 		void handled() const noexcept { | ||||||
| 			_instance = nullptr; |  | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		~RequestWrap() { | 		~RequestWrap() { | ||||||
| 			if (_instance) { | 			if (auto instance = MainInstance()) { | ||||||
| 				_instance->cancel(_id); | 				instance->cancel(_id); | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 	private: | 	private: | ||||||
| 		mutable Instance *_instance = nullptr; |  | ||||||
| 		mtpRequestId _id = 0; | 		mtpRequestId _id = 0; | ||||||
| 
 | 
 | ||||||
| 	}; | 	}; | ||||||
|  | @ -353,7 +348,7 @@ private: | ||||||
| 	friend class SentRequestWrap; | 	friend class SentRequestWrap; | ||||||
| 
 | 
 | ||||||
| 	void requestRegister(mtpRequestId requestId) { | 	void requestRegister(mtpRequestId requestId) { | ||||||
| 		_requests.emplace(_instance, requestId); | 		_requests.emplace(MainInstance(), requestId); | ||||||
| 	} | 	} | ||||||
| 	void requestHandled(mtpRequestId requestId) { | 	void requestHandled(mtpRequestId requestId) { | ||||||
| 		auto it = _requests.find(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.
 | 	std::set<RequestWrap, RequestWrapComparator> _requests; // Better to use flatmap.
 | ||||||
| 
 | 
 | ||||||
| }; | }; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 John Preston
						John Preston