language checking added

This commit is contained in:
John Preston 2015-01-06 14:13:43 +03:00
parent f560364f30
commit 3623cf8644
6 changed files with 48 additions and 19 deletions

View File

@ -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() {

View File

@ -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);

View File

@ -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();

View File

@ -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);

View File

@ -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!"));

View File

@ -54,6 +54,7 @@ protected:
bool readKeyValue(const char *&from, const char *end);
bool readingAll;
LangLoaderResult result;
};