From 3623cf8644642536cf7731f04ff5266d0b1c175a Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 6 Jan 2015 14:13:43 +0300 Subject: [PATCH] language checking added --- Telegram/SourceFiles/application.cpp | 6 ++-- Telegram/SourceFiles/boxes/languagebox.cpp | 17 +++++++++ Telegram/SourceFiles/boxes/languagebox.h | 1 + Telegram/SourceFiles/lang.h | 1 + Telegram/SourceFiles/langloaderplain.cpp | 41 +++++++++++++--------- Telegram/SourceFiles/langloaderplain.h | 1 + 6 files changed, 48 insertions(+), 19 deletions(-) diff --git a/Telegram/SourceFiles/application.cpp b/Telegram/SourceFiles/application.cpp index 868571f8c..94f6a6cfc 100644 --- a/Telegram/SourceFiles/application.cpp +++ b/Telegram/SourceFiles/application.cpp @@ -705,9 +705,9 @@ void Application::startApp() { } } - if (!cLangErrors().isEmpty()) { - window->showLayer(new ConfirmBox("Custom lang failed :(\n\nError: " + cLangErrors(), true, lang(lng_close))); - } +// if (!cLangErrors().isEmpty()) { +// window->showLayer(new ConfirmBox("Custom lang failed :(\n\nError: " + cLangErrors(), true, lang(lng_close))); +// } } void Application::socketDisconnected() { diff --git a/Telegram/SourceFiles/boxes/languagebox.cpp b/Telegram/SourceFiles/boxes/languagebox.cpp index ca7bf97de..66100204b 100644 --- a/Telegram/SourceFiles/boxes/languagebox.cpp +++ b/Telegram/SourceFiles/boxes/languagebox.cpp @@ -87,6 +87,23 @@ void LanguageBox::keyPressEvent(QKeyEvent *e) { } } +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) { + LangLoaderPlain loader(qsl(":/langs/lang_") + LanguageCodes[i] + qsl(".strings"), LangLoaderRequest(lngkeys_cnt)); + if (!loader.errors().isEmpty()) { + App::wnd()->showLayer(new ConfirmBox(qsl("Lang \"") + LanguageCodes[i] + qsl("\" error :(\n\nError: ") + loader.errors(), true, lang(lng_close))); + return; + } else if (!loader.warnings().isEmpty()) { + QString warn = loader.warnings(); + if (warn.size() > 256) warn = warn.mid(0, 254) + qsl(".."); + App::wnd()->showLayer(new ConfirmBox(qsl("Lang \"") + LanguageCodes[i] + qsl("\" warnings :(\n\nWarnings: ") + warn, true, lang(lng_close))); + return; + } + } + } +} + void LanguageBox::parentResized() { QSize s = parentWidget()->size(); setGeometry((s.width() - _width) / 2, (s.height() - _height) / 2, _width, _height); diff --git a/Telegram/SourceFiles/boxes/languagebox.h b/Telegram/SourceFiles/boxes/languagebox.h index 207070563..12ce5c7d1 100644 --- a/Telegram/SourceFiles/boxes/languagebox.h +++ b/Telegram/SourceFiles/boxes/languagebox.h @@ -28,6 +28,7 @@ public: void parentResized(); void animStep(float64 ms); void keyPressEvent(QKeyEvent *e); + void mousePressEvent(QMouseEvent *e); void paintEvent(QPaintEvent *e); void startHide(); ~LanguageBox(); diff --git a/Telegram/SourceFiles/lang.h b/Telegram/SourceFiles/lang.h index 259a43827..a69ac83c5 100644 --- a/Telegram/SourceFiles/lang.h +++ b/Telegram/SourceFiles/lang.h @@ -109,6 +109,7 @@ protected: LangKey subkeyIndex(LangKey key, ushort tag, ushort index) const; bool feedKeyValue(LangKey key, const QString &value); + void foundKeyValue(LangKey key); void error(const QString &text) { _err.push_back(text); diff --git a/Telegram/SourceFiles/langloaderplain.cpp b/Telegram/SourceFiles/langloaderplain.cpp index 1210c685b..94843061c 100644 --- a/Telegram/SourceFiles/langloaderplain.cpp +++ b/Telegram/SourceFiles/langloaderplain.cpp @@ -89,7 +89,7 @@ bool LangLoaderPlain::readKeyValue(const char *&from, const char *end) { if (varKey == lngkeys_cnt) { warning(QString("Unknown key '%1'!").arg(QLatin1String(varName))); } - } else if (!request.contains(varKey)) { + } else if (!readingAll && !request.contains(varKey)) { varKey = lngkeys_cnt; } bool readingValue = (varKey != lngkeys_cnt); @@ -155,13 +155,17 @@ bool LangLoaderPlain::readKeyValue(const char *&from, const char *end) { if (*from == '|') { if (from > start) subvarValue.append(start, int(from - start)); if (countedIndex >= lngtags_max_counted_values) throw Exception(QString("Too many values inside counted tag '%1' in '%2' key!").arg(QLatin1String(tagName)).arg(QLatin1String(varName))); - if (feedingValue) { - LangKey subkey = subkeyIndex(varKey, index, countedIndex++); - if (subkey == lngkeys_cnt) { - readingValue = false; - warning(QString("Unexpected counted tag '%1' in key '%2', not using value.").arg(QLatin1String(tagName)).arg(QLatin1String(varName))); - break; - } else if (!feedKeyValue(subkey, QString::fromUtf8(subvarValue))) throw Exception(QString("Tag '%1' is not counted in key '%2'!").arg(QLatin1String(tagName)).arg(QLatin1String(varName))); + LangKey subkey = subkeyIndex(varKey, index, countedIndex++); + if (subkey == lngkeys_cnt) { + readingValue = false; + warning(QString("Unexpected counted tag '%1' in key '%2', not using value.").arg(QLatin1String(tagName)).arg(QLatin1String(varName))); + break; + } else { + if (feedingValue) { + if (!feedKeyValue(subkey, QString::fromUtf8(subvarValue))) throw Exception(QString("Tag '%1' is not counted in key '%2'!").arg(QLatin1String(tagName)).arg(QLatin1String(varName))); + } else { + foundKeyValue(subkey); + } } subvarValue = QByteArray(); foundtag = false; @@ -200,13 +204,17 @@ bool LangLoaderPlain::readKeyValue(const char *&from, const char *end) { if (from > start) subvarValue.append(start, int(from - start)); if (countedIndex >= lngtags_max_counted_values) throw Exception(QString("Too many values inside counted tag '%1' in '%2' key!").arg(QLatin1String(tagName)).arg(QLatin1String(varName))); - if (feedingValue) { - LangKey subkey = subkeyIndex(varKey, index, countedIndex++); - if (subkey == lngkeys_cnt) { - readingValue = false; - warning(QString("Unexpected counted tag '%1' in key '%2', not using value.").arg(QLatin1String(tagName)).arg(QLatin1String(varName))); - break; - } else if (!feedKeyValue(subkey, QString::fromUtf8(subvarValue))) throw Exception(QString("Tag '%1' is not counted in key '%2'!").arg(QLatin1String(tagName)).arg(QLatin1String(varName))); + LangKey subkey = subkeyIndex(varKey, index, countedIndex++); + if (subkey == lngkeys_cnt) { + readingValue = false; + warning(QString("Unexpected counted tag '%1' in key '%2', not using value.").arg(QLatin1String(tagName)).arg(QLatin1String(varName))); + break; + } else { + if (feedingValue) { + if (!feedKeyValue(subkey, QString::fromUtf8(subvarValue))) throw Exception(QString("Tag '%1' is not counted in key '%2'!").arg(QLatin1String(tagName)).arg(QLatin1String(varName))); + } else { + foundKeyValue(subkey); + } } } start = from + 1; @@ -225,6 +233,7 @@ bool LangLoaderPlain::readKeyValue(const char *&from, const char *end) { if (feedingValue) { if (!feedKeyValue(varKey, QString::fromUtf8(varValue))) throw Exception(QString("Could not write value in key '%1'!").arg(QLatin1String(varName))); } else { + foundKeyValue(varKey); result.insert(varKey, QString::fromUtf8(varValue)); } } @@ -232,7 +241,7 @@ bool LangLoaderPlain::readKeyValue(const char *&from, const char *end) { return true; } -LangLoaderPlain::LangLoaderPlain(const QString &file, const LangLoaderRequest &request) : file(file), request(request) { +LangLoaderPlain::LangLoaderPlain(const QString &file, const LangLoaderRequest &request) : file(file), request(request), readingAll(request.contains(lngkeys_cnt)) { QFile f(file); if (!f.open(QIODevice::ReadOnly)) { error(qsl("Could not open input file!")); diff --git a/Telegram/SourceFiles/langloaderplain.h b/Telegram/SourceFiles/langloaderplain.h index f072ba436..8b03afb1c 100644 --- a/Telegram/SourceFiles/langloaderplain.h +++ b/Telegram/SourceFiles/langloaderplain.h @@ -54,6 +54,7 @@ protected: bool readKeyValue(const char *&from, const char *end); + bool readingAll; LangLoaderResult result; };