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
|
2016-02-08 10:56:18 +00:00
|
|
|
Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
|
2014-12-19 21:33:22 +00:00
|
|
|
*/
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "lang.h"
|
|
|
|
|
2015-03-02 12:34:16 +00:00
|
|
|
#include "localstorage.h"
|
|
|
|
|
2014-12-19 21:33:22 +00:00
|
|
|
#include "languagebox.h"
|
|
|
|
#include "confirmbox.h"
|
|
|
|
#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"
|
|
|
|
|
|
|
|
LanguageBox::LanguageBox() :
|
2015-10-06 19:49:23 +00:00
|
|
|
_close(this, lang(lng_box_ok), st::defaultBoxButton) {
|
2014-12-19 21:33:22 +00:00
|
|
|
|
2014-12-20 21:33:08 +00:00
|
|
|
bool haveTestLang = (cLang() == languageTest);
|
2014-12-19 21:33:22 +00:00
|
|
|
|
2015-10-06 19:49:23 +00:00
|
|
|
int32 y = st::boxTitleHeight + 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) {
|
2015-10-06 19:49:23 +00:00
|
|
|
_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();
|
2014-12-19 21:33:22 +00:00
|
|
|
connect(_langs.back(), SIGNAL(changed()), this, SLOT(onChange()));
|
|
|
|
}
|
2014-12-19 22:03:50 +00:00
|
|
|
for (int32 i = 0; i < languageCount; ++i) {
|
2014-12-19 21:33:22 +00:00
|
|
|
LangLoaderResult result;
|
|
|
|
if (i) {
|
2016-04-07 10:03:10 +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));
|
|
|
|
}
|
2016-04-07 10:03:10 +00:00
|
|
|
_langs.push_back(new Radiobutton(this, qsl("lang"), i, result.value(lng_language_name, LanguageCodes[i].c_str() + qsl(" language")), (cLang() == i), st::langsButton));
|
2015-10-06 19:49:23 +00:00
|
|
|
_langs.back()->move(st::boxPadding.left() + st::boxOptionListPadding.left(), y);
|
|
|
|
y += _langs.back()->height() + st::boxOptionListPadding.top();
|
2014-12-19 21:33:22 +00:00
|
|
|
connect(_langs.back(), SIGNAL(changed()), this, SLOT(onChange()));
|
|
|
|
}
|
|
|
|
|
2015-10-06 19:49:23 +00:00
|
|
|
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());
|
2014-12-19 21:33:22 +00:00
|
|
|
|
2015-10-06 19:49:23 +00:00
|
|
|
connect(&_close, SIGNAL(clicked()), this, SLOT(onClose()));
|
2014-12-19 21:33:22 +00:00
|
|
|
|
2015-10-06 19:49:23 +00:00
|
|
|
_close.moveToRight(st::boxButtonPadding.right(), height() - st::boxButtonPadding.bottom() - _close.height());
|
2015-04-02 10:33:19 +00:00
|
|
|
prepare();
|
2014-12-19 21:33:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void LanguageBox::hideAll() {
|
2015-10-06 19:49:23 +00:00
|
|
|
_close.hide();
|
2014-12-19 21:33:22 +00:00
|
|
|
for (int32 i = 0, l = _langs.size(); i < l; ++i) {
|
|
|
|
_langs[i]->hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LanguageBox::showAll() {
|
2015-10-06 19:49:23 +00:00
|
|
|
_close.show();
|
2014-12-19 21:33:22 +00:00
|
|
|
for (int32 i = 0, l = _langs.size(); i < l; ++i) {
|
|
|
|
_langs[i]->show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-04-07 10:03:10 +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-04-07 10:03:10 +00:00
|
|
|
Ui::showLayer(new 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-04-07 10:03:10 +00:00
|
|
|
Ui::showLayer(new InformBox(qsl("Lang \"") + LanguageCodes[i].c_str() + qsl("\" warnings :(\n\nWarnings: ") + warn));
|
2015-01-06 11:13:43 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2015-12-07 18:09:05 +00:00
|
|
|
Ui::showLayer(new InformBox(qsl("Everything seems great in all %1 languages!").arg(languageCount - 1)));
|
2015-01-06 11:13:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-19 21:33:22 +00:00
|
|
|
void LanguageBox::paintEvent(QPaintEvent *e) {
|
2015-04-04 20:01:34 +00:00
|
|
|
Painter p(this);
|
2015-04-02 10:33:19 +00:00
|
|
|
if (paint(p)) return;
|
|
|
|
|
2015-10-06 19:49:23 +00:00
|
|
|
paintTitle(p, lang(lng_languages));
|
2014-12-19 21:33:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2016-04-07 10:03:10 +00:00
|
|
|
LangLoaderPlain loader(qsl(":/langs/lang_") + LanguageCodes[langId].c_str() + qsl(".strings"), LangLoaderRequest(lng_sure_save_language, lng_cancel, lng_box_ok));
|
2014-12-19 21:33:22 +00:00
|
|
|
result = loader.found();
|
2014-12-20 21:33:08 +00:00
|
|
|
} else if (langId == languageTest) {
|
2015-10-11 08:37:24 +00:00
|
|
|
LangLoaderPlain loader(cLangFile(), LangLoaderRequest(lng_sure_save_language, lng_cancel, lng_box_ok));
|
2014-12-19 21:33:22 +00:00
|
|
|
result = loader.found();
|
|
|
|
}
|
|
|
|
QString text = result.value(lng_sure_save_language, langOriginal(lng_sure_save_language)),
|
2015-10-03 10:09:09 +00:00
|
|
|
save = result.value(lng_box_ok, langOriginal(lng_box_ok)),
|
2015-10-11 08:37:24 +00:00
|
|
|
cancel = result.value(lng_cancel, langOriginal(lng_cancel));
|
2015-10-03 10:09:09 +00:00
|
|
|
ConfirmBox *box = new ConfirmBox(text, save, st::defaultBoxButton, cancel);
|
2014-12-19 21:33:22 +00:00
|
|
|
connect(box, SIGNAL(confirmed()), this, SLOT(onSave()));
|
|
|
|
connect(box, SIGNAL(closed()), this, SLOT(onRestore()));
|
2015-12-07 18:09:05 +00:00
|
|
|
Ui::showLayer(box, KeepOtherLayers);
|
2014-12-19 21:33:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LanguageBox::onRestore() {
|
|
|
|
for (int32 i = 0, l = _langs.size(); i < l; ++i) {
|
|
|
|
if (_langs[i]->val() == cLang()) {
|
|
|
|
_langs[i]->setChecked(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LanguageBox::onSave() {
|
|
|
|
for (int32 i = 0, l = _langs.size(); i < l; ++i) {
|
|
|
|
if (_langs[i]->checked()) {
|
|
|
|
cSetLang(_langs[i]->val());
|
2015-03-02 12:34:16 +00:00
|
|
|
Local::writeSettings();
|
2014-12-19 21:33:22 +00:00
|
|
|
cSetRestarting(true);
|
|
|
|
cSetRestartingToSettings(true);
|
|
|
|
App::quit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
LanguageBox::~LanguageBox() {
|
|
|
|
for (int32 i = 0, l = _langs.size(); i < l; ++i) {
|
|
|
|
delete _langs[i];
|
|
|
|
}
|
|
|
|
}
|