void GeneralWidget::notifyFileQueryUpdated(const FileDialog::QueryUpdate &update) { if (_chooseLangFileQueryId != update.queryId) { return; } _chooseLangFileQueryId = 0; if (update.filePaths.isEmpty()) { return; } _testLanguage = QFileInfo(update.filePaths.front()).absoluteFilePath(); LangLoaderPlain loader(_testLanguage, langLoaderRequest(lng_sure_save_language, lng_cancel, lng_box_ok)); if (loader.errors().isEmpty()) { LangLoaderResult result = loader.found(); auto text = result.value(lng_sure_save_language, langOriginal(lng_sure_save_language)), save = result.value(lng_box_ok, langOriginal(lng_box_ok)), cancel = result.value(lng_cancel, langOriginal(lng_cancel)); Ui::show(Box<ConfirmBox>(text, save, cancel, base::lambda_guarded(this, [this] { cSetLangFile(_testLanguage); cSetLang(languageTest); Local::writeSettings(); onRestart(); }))); } else { Ui::show(Box<InformBox>("Custom lang failed :(\n\nError: " + loader.errors())); } }
LanguageBox::LanguageBox() : _close(this, lang(lng_box_ok), st::defaultBoxButton) { bool haveTestLang = (cLang() == languageTest); int32 y = st::boxTitleHeight + st::boxOptionListPadding.top(); _langs.reserve(languageCount + (haveTestLang ? 1 : 0)); if (haveTestLang) { _langs.push_back(new Radiobutton(this, qsl("lang"), languageTest, qsl("Custom Lang"), (cLang() == languageTest), st::langsButton)); _langs.back()->move(st::boxPadding.left() + st::boxOptionListPadding.left(), y); y += _langs.back()->height() + st::boxOptionListPadding.top(); connect(_langs.back(), SIGNAL(changed()), this, SLOT(onChange())); } for (int32 i = 0; i < languageCount; ++i) { LangLoaderResult result; if (i) { LangLoaderPlain loader(qsl(":/langs/lang_") + LanguageCodes[i] + qsl(".strings"), LangLoaderRequest(lng_language_name)); result = loader.found(); } else { result.insert(lng_language_name, langOriginal(lng_language_name)); } _langs.push_back(new Radiobutton(this, qsl("lang"), i, result.value(lng_language_name, LanguageCodes[i] + qsl(" language")), (cLang() == i), st::langsButton)); _langs.back()->move(st::boxPadding.left() + st::boxOptionListPadding.left(), y); y += _langs.back()->height() + st::boxOptionListPadding.top(); connect(_langs.back(), SIGNAL(changed()), this, SLOT(onChange())); } resizeMaxHeight(st::langsWidth, st::boxTitleHeight + (languageCount + (haveTestLang ? 1 : 0)) * (st::boxOptionListPadding.top() + st::langsButton.height) + st::boxOptionListPadding.bottom() + st::boxPadding.bottom() + st::boxButtonPadding.top() + _close.height() + st::boxButtonPadding.bottom()); connect(&_close, SIGNAL(clicked()), this, SLOT(onClose())); _close.moveToRight(st::boxButtonPadding.right(), height() - st::boxButtonPadding.bottom() - _close.height()); prepare(); }
QString langNewVersionTextForLang(int langId) { LangLoaderResult result; if (langId) { LangLoaderPlain loader(qsl(":/langs/lang_") + LanguageCodes[langId].c_str() + qsl(".strings"), LangLoaderRequest(lng_language_name, NEW_VER_KEY)); result = loader.found(); } else { result.insert(lng_language_name, langOriginal(lng_language_name)); result.insert(NEW_VER_KEY, langOriginal(NEW_VER_KEY)); } return result.value(lng_language_name, LanguageCodes[langId].c_str() + qsl(" language")) + qsl(":\n\n") + LangString(result.value(NEW_VER_KEY, qsl("--none--")))NEW_VER_POSTFIX; }
void LanguageBox::onChange() { if (isHidden()) return; for (int32 i = 0, l = _langs.size(); i < l; ++i) { int32 langId = _langs[i]->val(); if (_langs[i]->checked() && langId != cLang()) { LangLoaderResult result; if (langId > 0) { LangLoaderPlain loader(qsl(":/langs/lang_") + LanguageCodes[langId] + qsl(".strings"), LangLoaderRequest(lng_sure_save_language, lng_cancel, lng_box_ok)); result = loader.found(); } else if (langId == languageTest) { LangLoaderPlain loader(cLangFile(), LangLoaderRequest(lng_sure_save_language, lng_cancel, lng_box_ok)); result = loader.found(); } QString text = result.value(lng_sure_save_language, langOriginal(lng_sure_save_language)), save = result.value(lng_box_ok, langOriginal(lng_box_ok)), cancel = result.value(lng_cancel, langOriginal(lng_cancel)); ConfirmBox *box = new ConfirmBox(text, save, st::defaultBoxButton, cancel); connect(box, SIGNAL(confirmed()), this, SLOT(onSave())); connect(box, SIGNAL(closed()), this, SLOT(onRestore())); App::wnd()->replaceLayer(box); } } }