From 8c2f5b42dfcb4f472f0b42e9f72288d2981fd263 Mon Sep 17 00:00:00 2001 From: Kimmo Varis Date: Fri, 3 Jul 2009 14:18:35 +0300 Subject: [PATCH] GUI: Check translation file exists before loading it. This allows more accurate error message for the user. --- gui/cppcheck_de.ts | 58 +++++++++++++------------------------- gui/cppcheck_en.ts | 48 +++++++++++++++---------------- gui/cppcheck_fi.ts | 48 +++++++++++++++---------------- gui/cppcheck_ru.ts | 58 +++++++++++++------------------------- gui/cppcheck_se.ts | 58 +++++++++++++------------------------- gui/translationhandler.cpp | 10 ++++++- 6 files changed, 114 insertions(+), 166 deletions(-) diff --git a/gui/cppcheck_de.ts b/gui/cppcheck_de.ts index d0a75d01a..fcda7ac7c 100644 --- a/gui/cppcheck_de.ts +++ b/gui/cppcheck_de.ts @@ -18,7 +18,7 @@ Cppcheck - A tool for static C/C++ code analysis. - + Copyright (C) 2007-2009 Daniel Marjamäki and cppcheck team. @@ -117,9 +117,9 @@ kate -l(line) (file) - - - + + + Cppcheck @@ -299,44 +299,44 @@ kate -l(line) (file) - + Cannot exit while checking. Stop the checking before exiting. - + License - + Authors - + XML files (*.xml);;Text files (*.txt) - + Save the report file - + XML files (*.xml) - + Cppcheck - %1 - + Failed to change language: %1 @@ -346,37 +346,17 @@ Stop the checking before exiting. QObject - - English - - - - - Finnish - - - - - Swedish - - - - - German - - - - - Russian - - - - + Incorrect language specified! - + + Language file %1 not found! + + + + Failed to load language from file %1 diff --git a/gui/cppcheck_en.ts b/gui/cppcheck_en.ts index ebf21f0be..7586e2a2b 100644 --- a/gui/cppcheck_en.ts +++ b/gui/cppcheck_en.ts @@ -18,7 +18,7 @@ Cppcheck - A tool for static C/C++ code analysis. Cppcheck - A tool for static C/C++ code analysis. - + Copyright (C) 2007-2009 Daniel Marjamäki and cppcheck team. Copyright (C) 2007-2009 Daniel Marjamäki and cppcheck team. @@ -130,9 +130,9 @@ kate -l(line) (file) - - - + + + Cppcheck Cppcheck @@ -312,7 +312,7 @@ kate -l(line) (file) No suitable files found to check! - + Cannot exit while checking. Stop the checking before exiting. @@ -321,37 +321,37 @@ Stop the checking before exiting. Stop the checking before exiting. - + License License - + Authors Authors - + XML files (*.xml);;Text files (*.txt) XML files (*.xml);;Text files (*.txt) - + Save the report file Save the report file - + XML files (*.xml) XML files (*.xml) - + Cppcheck - %1 Cppcheck - %1 - + Failed to change language: %1 @@ -363,37 +363,37 @@ Stop the checking before exiting. QObject - English - English + English - Finnish - Finnish + Finnish - Swedish - Swedish + Swedish - German - German + German - Russian - Russian + Russian - + Incorrect language specified! Incorrect language specified! - + + Language file %1 not found! + + + + Failed to load language from file %1 Failed to load language from file %1 diff --git a/gui/cppcheck_fi.ts b/gui/cppcheck_fi.ts index fbf65112a..a11765b33 100644 --- a/gui/cppcheck_fi.ts +++ b/gui/cppcheck_fi.ts @@ -18,7 +18,7 @@ Cppcheck - A tool for static C/C++ code analysis. Cppcheck - Työkalu C/C++ koodin staattiseen analysointiin. - + Copyright (C) 2007-2009 Daniel Marjamäki and cppcheck team. Copyright (C) 2007-2009 Daniel Marjamäki ja cppcheck tiimi. @@ -132,9 +132,9 @@ kate -l(line) (file) - - - + + + Cppcheck Cppcheck @@ -314,7 +314,7 @@ kate -l(line) (file) Tarkistettavaksi sopivia tiedostoja ei löytynyt! - + Cannot exit while checking. Stop the checking before exiting. @@ -323,37 +323,37 @@ Stop the checking before exiting. Lopeta tarkistus ennen ohjelman sammuttamista. - + License Lisenssi - + Authors Tekijät - + XML files (*.xml);;Text files (*.txt) XML-tiedostot (*.xml);;Tekstitiedostot (*.txt) - + Save the report file Tallenna raportti - + XML files (*.xml) XML-tiedostot (*xml) - + Cppcheck - %1 Cppcheck - %1 - + Failed to change language: %1 @@ -363,37 +363,37 @@ Lopeta tarkistus ennen ohjelman sammuttamista. QObject - English - Englanti + Englanti - Finnish - Suomi + Suomi - Swedish - Ruotsi + Ruotsi - German - Saksa + Saksa - Russian - Venäjä + Venäjä - + Incorrect language specified! Virheellinen kieli valittu! - + + Language file %1 not found! + + + + Failed to load language from file %1 Kielen lataaminen tiedostosta %1 epäonnistui diff --git a/gui/cppcheck_ru.ts b/gui/cppcheck_ru.ts index 2b0e02a14..f27e0139e 100644 --- a/gui/cppcheck_ru.ts +++ b/gui/cppcheck_ru.ts @@ -18,7 +18,7 @@ Cppcheck - A tool for static C/C++ code analysis. - + Copyright (C) 2007-2009 Daniel Marjamäki and cppcheck team. @@ -119,9 +119,9 @@ kate -l(line) (file) - - - + + + Cppcheck @@ -301,44 +301,44 @@ kate -l(line) (file) - + Cannot exit while checking. Stop the checking before exiting. - + License - + Authors - + XML files (*.xml);;Text files (*.txt) - + Save the report file - + XML files (*.xml) - + Cppcheck - %1 - + Failed to change language: %1 @@ -348,37 +348,17 @@ Stop the checking before exiting. QObject - - English - - - - - Finnish - - - - - Swedish - - - - - German - - - - - Russian - - - - + Incorrect language specified! - + + Language file %1 not found! + + + + Failed to load language from file %1 diff --git a/gui/cppcheck_se.ts b/gui/cppcheck_se.ts index 2b0e02a14..f27e0139e 100644 --- a/gui/cppcheck_se.ts +++ b/gui/cppcheck_se.ts @@ -18,7 +18,7 @@ Cppcheck - A tool for static C/C++ code analysis. - + Copyright (C) 2007-2009 Daniel Marjamäki and cppcheck team. @@ -119,9 +119,9 @@ kate -l(line) (file) - - - + + + Cppcheck @@ -301,44 +301,44 @@ kate -l(line) (file) - + Cannot exit while checking. Stop the checking before exiting. - + License - + Authors - + XML files (*.xml);;Text files (*.txt) - + Save the report file - + XML files (*.xml) - + Cppcheck - %1 - + Failed to change language: %1 @@ -348,37 +348,17 @@ Stop the checking before exiting. QObject - - English - - - - - Finnish - - - - - Swedish - - - - - German - - - - - Russian - - - - + Incorrect language specified! - + + Language file %1 not found! + + + + Failed to load language from file %1 diff --git a/gui/translationhandler.cpp b/gui/translationhandler.cpp index 04eb59faf..57da03158 100644 --- a/gui/translationhandler.cpp +++ b/gui/translationhandler.cpp @@ -19,6 +19,7 @@ #include "translationhandler.h" #include +#include #include TranslationHandler::TranslationHandler(QObject *parent) : @@ -47,7 +48,7 @@ TranslationHandler::TranslationHandler(QObject *parent) : } else { - qDebug() << "Failed to load english translation!"; + qDebug() << "Failed to load English translation!"; delete english; } } @@ -88,6 +89,13 @@ bool TranslationHandler::SetLanguage(const int index, QString &error) return false; } + // Check translation file exists before trying to load it + if (!QFile::exists(mFiles[index])) + { + error = QObject::tr("Language file %1 not found!"); + error = error.arg(mFiles[index]); + return false; + } //Load the new language if (!mTranslator->load(mFiles[index]))