2014-12-19 21:33:22 +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.
|
|
|
|
|
2015-10-03 13:16:42 +00:00
|
|
|
In addition, as a special exception, the copyright holders give permission
|
|
|
|
to link the code of portions of this program with the OpenSSL library.
|
|
|
|
|
2014-12-19 21:33:22 +00:00
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
2017-01-11 18:31:31 +00:00
|
|
|
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
2014-12-19 21:33:22 +00:00
|
|
|
*/
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "boxes/language_box.h"
|
2014-12-19 21:33:22 +00:00
|
|
|
|
2016-10-28 09:20:24 +00:00
|
|
|
#include "lang.h"
|
2016-11-11 13:46:04 +00:00
|
|
|
#include "ui/widgets/checkbox.h"
|
|
|
|
#include "ui/widgets/buttons.h"
|
2017-03-04 10:23:56 +00:00
|
|
|
#include "storage/localstorage.h"
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "boxes/confirm_box.h"
|
2014-12-19 21:33:22 +00:00
|
|
|
#include "mainwidget.h"
|
2016-04-12 21:31:28 +00:00
|
|
|
#include "mainwindow.h"
|
2014-12-19 21:33:22 +00:00
|
|
|
#include "langloaderplain.h"
|
2016-11-15 11:56:49 +00:00
|
|
|
#include "styles/style_boxes.h"
|
2014-12-19 21:33:22 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void LanguageBox::prepare() {
|
|
|
|
addButton(lang(lng_box_ok), [this] { closeBox(); });
|
2014-12-19 21:33:22 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
setTitle(lang(lng_languages));
|
2014-12-19 21:33:22 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
auto haveTestLang = (cLang() == languageTest);
|
|
|
|
|
2017-03-18 11:55:04 +00:00
|
|
|
_langGroup = std::make_shared<Ui::RadiobuttonGroup>(cLang());
|
2016-12-13 17:07:56 +00:00
|
|
|
auto y = st::boxOptionListPadding.top();
|
2014-12-19 22:03:50 +00:00
|
|
|
_langs.reserve(languageCount + (haveTestLang ? 1 : 0));
|
2014-12-19 21:33:22 +00:00
|
|
|
if (haveTestLang) {
|
2017-03-18 11:55:04 +00:00
|
|
|
_langs.emplace_back(this, _langGroup, languageTest, qsl("Custom Lang"), st::langsButton);
|
2015-10-06 19:49:23 +00:00
|
|
|
_langs.back()->move(st::boxPadding.left() + st::boxOptionListPadding.left(), y);
|
2016-12-13 17:07:56 +00:00
|
|
|
y += _langs.back()->heightNoMargins() + st::boxOptionListSkip;
|
2014-12-19 21:33:22 +00:00
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
for (auto i = 0; i != languageCount; ++i) {
|
2014-12-19 21:33:22 +00:00
|
|
|
LangLoaderResult result;
|
|
|
|
if (i) {
|
2016-10-28 12:44:28 +00:00
|
|
|
LangLoaderPlain loader(qsl(":/langs/lang_") + LanguageCodes[i].c_str() + qsl(".strings"), langLoaderRequest(lng_language_name));
|
2014-12-19 21:33:22 +00:00
|
|
|
result = loader.found();
|
|
|
|
} else {
|
|
|
|
result.insert(lng_language_name, langOriginal(lng_language_name));
|
|
|
|
}
|
2017-03-18 11:55:04 +00:00
|
|
|
_langs.emplace_back(this, _langGroup, i, result.value(lng_language_name, LanguageCodes[i].c_str() + qsl(" language")), st::langsButton);
|
2015-10-06 19:49:23 +00:00
|
|
|
_langs.back()->move(st::boxPadding.left() + st::boxOptionListPadding.left(), y);
|
2016-12-13 17:07:56 +00:00
|
|
|
y += _langs.back()->heightNoMargins() + st::boxOptionListSkip;
|
2014-12-19 21:33:22 +00:00
|
|
|
}
|
2017-03-18 11:55:04 +00:00
|
|
|
_langGroup->setChangedCallback([this](int value) { languageChanged(value); });
|
2014-12-19 21:33:22 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
auto optionsCount = languageCount + (haveTestLang ? 1 : 0);
|
|
|
|
setDimensions(st::langsWidth, st::boxOptionListPadding.top() + optionsCount * st::langsButton.height + (optionsCount - 1) * st::boxOptionListSkip + st::boxOptionListPadding.bottom() + st::boxPadding.bottom());
|
2014-12-19 21:33:22 +00:00
|
|
|
}
|
|
|
|
|
2015-01-06 11:13:43 +00:00
|
|
|
void LanguageBox::mousePressEvent(QMouseEvent *e) {
|
|
|
|
if ((e->modifiers() & Qt::CTRL) && (e->modifiers() & Qt::ALT) && (e->modifiers() & Qt::SHIFT)) {
|
|
|
|
for (int32 i = 1; i < languageCount; ++i) {
|
2016-10-28 12:44:28 +00:00
|
|
|
LangLoaderPlain loader(qsl(":/langs/lang_") + LanguageCodes[i].c_str() + qsl(".strings"), langLoaderRequest(lngkeys_cnt));
|
2015-01-06 11:13:43 +00:00
|
|
|
if (!loader.errors().isEmpty()) {
|
2016-12-13 17:07:56 +00:00
|
|
|
Ui::show(Box<InformBox>(qsl("Lang \"") + LanguageCodes[i].c_str() + qsl("\" error :(\n\nError: ") + loader.errors()));
|
2015-01-06 11:13:43 +00:00
|
|
|
return;
|
|
|
|
} else if (!loader.warnings().isEmpty()) {
|
|
|
|
QString warn = loader.warnings();
|
2016-03-24 15:07:13 +00:00
|
|
|
if (warn.size() > 256) warn = warn.mid(0, 253) + qsl("...");
|
2016-12-13 17:07:56 +00:00
|
|
|
Ui::show(Box<InformBox>(qsl("Lang \"") + LanguageCodes[i].c_str() + qsl("\" warnings :(\n\nWarnings: ") + warn));
|
2015-01-06 11:13:43 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
Ui::show(Box<InformBox>(qsl("Everything seems great in all %1 languages!").arg(languageCount - 1)));
|
2015-01-06 11:13:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 11:55:04 +00:00
|
|
|
void LanguageBox::languageChanged(int languageId) {
|
|
|
|
Expects(languageId == languageTest || (languageId >= 0 && languageId < base::array_size(LanguageCodes)));
|
2014-12-19 21:33:22 +00:00
|
|
|
|
2017-03-18 11:55:04 +00:00
|
|
|
if (languageId == cLang()) {
|
|
|
|
return;
|
2014-12-19 21:33:22 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 11:55:04 +00:00
|
|
|
LangLoaderResult result;
|
|
|
|
if (languageId > 0) {
|
|
|
|
LangLoaderPlain loader(qsl(":/langs/lang_") + LanguageCodes[languageId].c_str() + qsl(".strings"), langLoaderRequest(lng_sure_save_language, lng_cancel, lng_box_ok));
|
|
|
|
result = loader.found();
|
|
|
|
} else if (languageId == languageTest) {
|
|
|
|
LangLoaderPlain loader(cLangFile(), langLoaderRequest(lng_sure_save_language, lng_cancel, lng_box_ok));
|
|
|
|
result = loader.found();
|
2014-12-19 21:33:22 +00:00
|
|
|
}
|
2017-03-18 11:55:04 +00:00
|
|
|
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, languageId] {
|
|
|
|
cSetLang(languageId);
|
|
|
|
Local::writeSettings();
|
|
|
|
App::restart();
|
|
|
|
}), base::lambda_guarded(this, [this] {
|
|
|
|
_langGroup->setValue(cLang());
|
|
|
|
})), KeepOtherLayers);
|
2014-12-19 21:33:22 +00:00
|
|
|
}
|