diff --git a/gui/applicationlist.cpp b/gui/applicationlist.cpp index a68d16072..9aba78dda 100644 --- a/gui/applicationlist.cpp +++ b/gui/applicationlist.cpp @@ -18,8 +18,10 @@ #include "applicationlist.h" #include +#include "common.h" -ApplicationList::ApplicationList() +ApplicationList::ApplicationList(QObject *parent) : + QObject(parent) { //ctor } @@ -29,11 +31,12 @@ ApplicationList::~ApplicationList() Clear(); } -void ApplicationList::LoadSettings(QSettings &programSettings) +void ApplicationList::LoadSettings(QSettings *programSettings) { - QStringList names = programSettings.value("Application names", QStringList()).toStringList(); - QStringList paths = programSettings.value("Application paths", QStringList()).toStringList(); + QStringList names = programSettings->value(SETTINGS_APPLICATION_NAMES, QStringList()).toStringList(); + QStringList paths = programSettings->value(SETTINGS_APPLICATION_PATHS, QStringList()).toStringList(); + if (names.size() == paths.size()) { for (int i = 0; i < names.size(); i++) @@ -43,7 +46,7 @@ void ApplicationList::LoadSettings(QSettings &programSettings) } } -void ApplicationList::SaveSettings(QSettings &programSettings) +void ApplicationList::SaveSettings(QSettings *programSettings) { QStringList names; QStringList paths; @@ -54,8 +57,8 @@ void ApplicationList::SaveSettings(QSettings &programSettings) paths << GetApplicationPath(i); } - programSettings.setValue("Application names", names); - programSettings.setValue("Application paths", paths); + programSettings->setValue(SETTINGS_APPLICATION_NAMES, names); + programSettings->setValue(SETTINGS_APPLICATION_PATHS, paths); } @@ -125,12 +128,17 @@ void ApplicationList::MoveFirst(const int index) } -void ApplicationList::Copy(ApplicationList &list) +void ApplicationList::Copy(ApplicationList *list) { - Clear(); - for (int i = 0; i < list.GetApplicationCount(); i++) + if (!list) { - AddApplicationType(list.GetApplicationName(i), list.GetApplicationPath(i)); + return; + } + + Clear(); + for (int i = 0;i < list->GetApplicationCount();i++) + { + AddApplicationType(list->GetApplicationName(i), list->GetApplicationPath(i)); } } diff --git a/gui/applicationlist.h b/gui/applicationlist.h index 96e5f2464..c9212e339 100644 --- a/gui/applicationlist.h +++ b/gui/applicationlist.h @@ -43,6 +43,7 @@ */ class ApplicationList : public QObject { + Q_OBJECT public: /** @@ -64,7 +65,7 @@ public: QString Path; } ApplicationType; - ApplicationList(); + ApplicationList(QObject *parent = 0); virtual ~ApplicationList(); /** @@ -72,13 +73,13 @@ public: * * @param programSettings QSettings to load application list from */ - void LoadSettings(QSettings &programSettings); + void LoadSettings(QSettings *programSettings); /** * @brief Save all applications * @param programSettings QSettings to save applications to */ - void SaveSettings(QSettings &programSettings); + void SaveSettings(QSettings *programSettings); /** * @brief Get the amount of applications in the list @@ -143,7 +144,7 @@ public: * list given as a parameter. * @param list Copying source */ - void Copy(ApplicationList &list); + void Copy(ApplicationList *list); protected: /** diff --git a/gui/common.h b/gui/common.h index 1cbda23fd..7b216fbd1 100644 --- a/gui/common.h +++ b/gui/common.h @@ -33,4 +33,30 @@ typedef enum } ShowTypes; +/** +* QSetting value names +*/ +#define SETTINGS_WINDOW_MAXIMIZED "Window maximized" +#define SETTINGS_WINDOW_WIDTH "Window width" +#define SETTINGS_WINDOW_HEIGHT "Window height" +#define SETTINGS_SHOW_ALL "Show all" +#define SETTINGS_SHOW_SECURITY "Show security" +#define SETTINGS_SHOW_STYLE "Show style" +#define SETTINGS_SHOW_ERRORS "Show errors" +#define SETTINGS_CHECK_PATH "Check path" +#define SETTINGS_CHECK_FORCE "Check force" +#define SETTINGS_CHECK_THREADS "Check threads" +#define SETTINGS_SHOW_FULL_PATH "Show full path" +#define SETTINGS_SHOW_NO_ERRORS "Show no errors message" +#define SETTINGS_SAVE_ALL_ERRORS "Save all errors" +#define SETTINGS_SAVE_FULL_PATH "Save full path" +#define SETTINGS_CHECK_DIALOG_WIDTH "Check dialog width" +#define SETTINGS_CHECK_DIALOG_HEIGHT "Check dialog height" +#define SETTINGS_APPLICATION_NAMES "Application names" +#define SETTINGS_APPLICATION_PATHS "Application paths" +#define SETTINGS_RESULT_COLUMN_WIDTH "Result column %1 width" +#define SETTINGS_LANGUAGE "Application language" +#define SETTINGS_TOOLBARS_SHOW "Toolbars/ShowStandard" + + #endif diff --git a/gui/cppcheck_de.ts b/gui/cppcheck_de.ts new file mode 100644 index 000000000..fc90bf83d --- /dev/null +++ b/gui/cppcheck_de.ts @@ -0,0 +1,550 @@ + + + + + AboutDialog + + + About cppcheck + + + + + Cppcheck - A tool for static C/C++ code analysis. + + + + + Version %1 + + + + + This program is licensed under the terms of the GNU General Public License version 3 + + + + + Close + + + + + ApplicationDialog + + + Here you can add applications that can open error files. +Specify a name for the application and the application to execute. + +The following texts are replaced with appriproate values when application is executed: +(file) - Filename containing the error +(line) - Line number containing the error +(message) - Error message +(severity) - Error severity + +Example opening a file with Kate and make Kate scroll to the correct line: +kate -l(line) (file) + + + + + Application's name + + + + + Application to execute + + + + + Browse + + + + + Cancel + + + + + Ok + + + + + Executable files (*.exe);;All files(*.*) + + + + + Select viewer application + + + + + Cppcheck + + + + + You must specify a name and a path for the application! + + + + + FileViewDialog + + + Close + + + + + Could not find the file: %1 + + + + + + Cppcheck + + + + + Could not read the file: %1 + + + + + MainWindow + + + + + + + Cppcheck + + + + + Show possible false positives + + + + + &File + + + + + &View + + + + + &Check + + + + + &Edit + + + + + toolBar + + + + + &License... + + + + + A&uthors... + + + + + &About... + + + + + &Files... + + + + + Ctrl+F + + + + + &Directory... + + + + + Ctrl+D + + + + + &Recheck files + + + + + Ctrl+R + + + + + &Stop + + + + + Esc + + + + + &Save results to file... + + + + + Ctrl+S + + + + + &Quit + + + + + &Clear results + + + + + &Preferences + + + + + Show security errors + + + + + Show style errors + + + + + Show common errors + + + + + &Check all + + + + + &Uncheck all + + + + + Collapse &all + + + + + &Expand all + + + + + &Toolbar + + + + + &Language + + + + + &Help + + + + + Select files to check + + + + + Select directory to check + + + + + No suitable files found to check! + + + + + Cannot exit while checking. + +Stop the checking before exiting. + + + + + XML files (*.xml);;Text files (*.txt) + + + + + Save the report file + + + + + XML files (*.xml) + + + + + Cppcheck - %1 + + + + + Failed to change language: + +%1 + + + + + QObject + + + English + + + + + Finnish + + + + + Swedish + + + + + German + + + + + Russian + + + + + Incorrect language specified! + + + + + Failed to load language from file %1 + + + + + ResultsTree + + + + File + + + + + + Severity + + + + + + Line + + + + + + Message + + + + + Copy filename + + + + + Copy full path + + + + + Cppcheck + + + + + You can open this error by specifying applications in program's settings. + + + + + Could not start %1 + +Please check the application path and parameters are correct. + + + + + ResultsView + + + + Cppcheck + + + + + No errors found. + + + + + Errors were found, but they are configured to be hidden. +To toggle what kind of errors are shown, open view menu. + + + + + Results + + + + + SettingsDialog + + + Cancel + + + + + Ok + + + + + General + + + + + Number of threads: + + + + + Check all #ifdef configurations + + + + + Show full path of files + + + + + Show "No errors found" message when no errors found + + + + + Applications + + + + + Add application + + + + + Delete application + + + + + Modify application + + + + + Set as default application + + + + + Reports + + + + + Save all errors when creating report + + + + + Save full path to files in reports + + + + + Settings + + + + + Add a new application + + + + + Modify an application + + + + diff --git a/gui/cppcheck_en.ts b/gui/cppcheck_en.ts new file mode 100644 index 000000000..147b881e7 --- /dev/null +++ b/gui/cppcheck_en.ts @@ -0,0 +1,569 @@ + + + + + AboutDialog + + + About cppcheck + About Cppcheck + + + + Cppcheck - A tool for static C/C++ code analysis. + Cppcheck - A tool for static C/C++ code analysis. + + + + Version %1 + Version %1 + + + + This program is licensed under the terms of the GNU General Public License version 3 + This program is licensed under the terms of the GNU General Public License version 3 + + + + Close + Close + + + + ApplicationDialog + + + Here you can add applications that can open error files. +Specify a name for the application and the application to execute. + +The following texts are replaced with appriproate values when application is executed: +(file) - Filename containing the error +(line) - Line number containing the error +(message) - Error message +(severity) - Error severity + +Example opening a file with Kate and make Kate scroll to the correct line: +kate -l(line) (file) + Here you can add applications that can open error files. +Specify a name for the application and the application to execute. + +The following texts are replaced with appriproate values when application is executed: +(file) - Filename containing the error +(line) - Line number containing the error +(message) - Error message +(severity) - Error severity + +Example opening a file with Kate and make Kate scroll to the correct line: +kate -l(line) (file) + + + + Application's name + Application's name + + + + Application to execute + Application to execute + + + + Browse + Browse + + + + Cancel + Cancel + + + + Ok + Ok + + + + Executable files (*.exe);;All files(*.*) + Executable files (*.exe);;All files(*.*) + + + + Select viewer application + Select viewer application + + + + Cppcheck + Cppcheck + + + + You must specify a name and a path for the application! + You must specify a name and a path for the application! + + + + FileViewDialog + + + Close + Close + + + + Could not find the file: %1 + Could not find the file: + + Could not find the file: %1 + + + + + Cppcheck + Cppcheck + + + + Could not read the file: %1 + Could not read the file: %1 + + + + MainWindow + + + + + + + Cppcheck + Cppcheck + + + + Show possible false positives + Show possible false positives + + + + &File + &File + + + + &View + &View + + + + &Check + &Check + + + + &Edit + &Edit + + + + toolBar + toolBar + + + + &License... + &License... + + + + A&uthors... + A&uthors... + + + + &About... + &About... + + + + &Files... + &Files... + + + + Ctrl+F + Ctrl+F + + + + &Directory... + &Directory... + + + + Ctrl+D + Ctrl+D + + + + &Recheck files + &Recheck files + + + + Ctrl+R + Ctrl+R + + + + &Stop + &Stop + + + + Esc + Esc + + + + &Save results to file... + &Save results to file... + + + + Ctrl+S + Ctrl+S + + + + &Quit + &Quit + + + + &Clear results + &Clear results + + + + &Preferences + &Preferences + + + + Show security errors + Show security errors + + + + Show style errors + Show style errors + + + + Show common errors + Show common errors + + + + &Check all + &Check all + + + + &Uncheck all + &Uncheck all + + + + Collapse &all + Collapse &all + + + + &Expand all + &Expand all + + + + &Toolbar + &Toolbar + + + + &Language + &Language + + + + &Help + &Help + + + + Select files to check + Select files to check + + + + Select directory to check + Select directory to check + + + + No suitable files found to check! + No suitable files found to check! + + + + Cannot exit while checking. + +Stop the checking before exiting. + Cannot exit while checking. + +Stop the checking before exiting. + + + + 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 + Failed to change language: + +%1 + + + + QObject + + + English + English + + + + Finnish + Finnish + + + + Swedish + Swedish + + + + German + German + + + + Russian + Russian + + + + Incorrect language specified! + Incorrect language specified! + + + + Failed to load language from file %1 + Failed to load language from file %1 + + + + ResultsTree + + + + File + File + + + + + Severity + Severity + + + + + Line + Line + + + + + Message + Message + + + + Copy filename + Copy filename + + + + Copy full path + Copy full path + + + + Cppcheck + Cppcheck + + + + You can open this error by specifying applications in program's settings. + You can open this error by specifying applications in program's settings. + + + + Could not start %1 + +Please check the application path and parameters are correct. + Could not start %1 + +Please check the application path and parameters are correct. + + + + ResultsView + + + + Cppcheck + Cppcheck + + + + No errors found. + No errors found. + + + + Errors were found, but they are configured to be hidden. +To toggle what kind of errors are shown, open view menu. + Errors were found, but they are configured to be hidden. +To toggle what kind of errors are shown, open view menu. + + + + Results + Results + + + + SettingsDialog + + + Cancel + Cancel + + + + Ok + Ok + + + + General + General + + + + Number of threads: + Number of threads: + + + + Check all #ifdef configurations + Check all #ifdef configurations + + + + Show full path of files + Show full path of files + + + + Show "No errors found" message when no errors found + Show "No errors found" message when no errors found + + + + Applications + Applications + + + + Add application + Add application + + + + Delete application + Delete application + + + + Modify application + Modify application + + + + Set as default application + Set as default application + + + + Reports + Reports + + + + Save all errors when creating report + Save all errors when creating report + + + + Save full path to files in reports + Save full path to files in reports + + + + Settings + Settings + + + + Add a new application + Add a new application + + + + Modify an application + Modify an application + + + diff --git a/gui/cppcheck_fi.ts b/gui/cppcheck_fi.ts new file mode 100644 index 000000000..d356c0b22 --- /dev/null +++ b/gui/cppcheck_fi.ts @@ -0,0 +1,569 @@ + + + + + AboutDialog + + + About cppcheck + Tietoa ohjelmasta Cppcheck + + + + Cppcheck - A tool for static C/C++ code analysis. + Cppcheck - Työkalu C/C++ koodin staattiseen analysointiin. + + + + Version %1 + Versio %1 + + + + This program is licensed under the terms of the GNU General Public License version 3 + Tämä ohjelma on lisensoitu GNU General Public Lisenssin version 3 alaiseksi + + + + Close + Sulje + + + + ApplicationDialog + + + Here you can add applications that can open error files. +Specify a name for the application and the application to execute. + +The following texts are replaced with appriproate values when application is executed: +(file) - Filename containing the error +(line) - Line number containing the error +(message) - Error message +(severity) - Error severity + +Example opening a file with Kate and make Kate scroll to the correct line: +kate -l(line) (file) + Voi lisätä ohjelmia joilla avata virheen sisältämiä tiedostoja +määrittämällä suoritettavan ohjelman ja nimen ohjelmalle. + +Suoritettavalle ohjelmalle voi määrittää parametreja jotka Cppcheck korvaa sopivilla arvoilla. +Parametrit ovat seuraavat: +(file) - Tiedosto joka sisältää virheen +(line) - Rivinumero josta virhe löytyy +(message) - Virheilmoitus +(severity) - Virheen vakavuus + +Esimerkki virheen avaamisesta Kate nimisellä tekstinkäsittelyohjelmalla: +kate -l(line) (file) + + + + + Application's name + Ohjelman nimi + + + + Application to execute + Suoritettava ohjelma + + + + Browse + Selaa + + + + Cancel + Peruuta + + + + Ok + Ok + + + + Executable files (*.exe);;All files(*.*) + Suoritettavat tiedostot (*.exe);;Kaikki tiedostot(*.*) + + + + Select viewer application + Valitse ohjelma jolla avata virhetiedosto + + + + Cppcheck + Cppcheck + + + + You must specify a name and a path for the application! + Suoritettava ohjelma tulee määrittää! + + + + FileViewDialog + + + Close + Sulje + + + + Could not find the file: %1 + Could not find the file: + + Tiedostoa %1 ei löytynyt + + + + + Cppcheck + Cppcheck + + + + Could not read the file: %1 + Tiedoston %1 lukeminen epäonnistui + + + + MainWindow + + + + + + + Cppcheck + Cppcheck + + + + Show possible false positives + Näytä epävarmat virheet + + + + &File + &Tiedosto + + + + &View + &Näytä + + + + &Check + &Tarkista + + + + &Edit + &Muokkaa + + + + toolBar + työkalupalkki + + + + &License... + &Lisenssi... + + + + A&uthors... + &Tekijät... + + + + &About... + &Tietoa ohjelmasta Cppcheck... + + + + &Files... + &Tiedostot... + + + + Ctrl+F + Ctrl+F + + + + &Directory... + &Hakemisto... + + + + Ctrl+D + Ctrl+D + + + + &Recheck files + Tarkista tiedostot &uudelleen + + + + Ctrl+R + Ctrl+R + + + + &Stop + &Pysäytä + + + + Esc + Esc + + + + &Save results to file... + &Tallenna tulokset tiedostoon... + + + + Ctrl+S + Ctrl+S + + + + &Quit + &Lopeta + + + + &Clear results + &Tyhjennä tulokset + + + + &Preferences + &Asetukset + + + + Show security errors + Näytä tietoturvavirheet + + + + Show style errors + Näytä tyylivirheet + + + + Show common errors + Näytä yleiset virheet + + + + &Check all + &Valitse kaikki + + + + &Uncheck all + &Poista kaikista valinta + + + + Collapse &all + &Pienennä kaikki + + + + &Expand all + &Laajenna kaikki + + + + &Toolbar + &Työkalupalkki + + + + &Language + &Kieli + + + + &Help + &Ohje + + + + Select files to check + Valitse tarkistettavat tiedostot + + + + Select directory to check + Valitse tarkistettava hakemisto + + + + No suitable files found to check! + Tarkistettavaksi sopivia tiedostoja ei löytynyt! + + + + Cannot exit while checking. + +Stop the checking before exiting. + Ohjelmaa ei voi sammuttaa tarkistuksen ollessa käynnissä. + +Lopeta tarkistus ennen ohjelman sammuttamista. + + + + 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 + Kielen %1 vaihto epäonnistui + + + + QObject + + + English + Englanti + + + + Finnish + Suomi + + + + Swedish + Ruotsi + + + + German + Saksa + + + + Russian + Venäjä + + + + Incorrect language specified! + Virheellinen kieli valittu! + + + + Failed to load language from file %1 + Kielen lataaminen tiedostosta %1 epäonnistui + + + + ResultsTree + + + + File + Tiedosto + + + + + Severity + Tyyppi + + + + + Line + Rivi + + + + + Message + Virhe + + + + Copy filename + Kopioi tiedostonimi + + + + Copy full path + Kopioi tiedoston koko polku + + + + Cppcheck + Cppcheck + + + + You can open this error by specifying applications in program's settings. + Voit asetuksista määritellä muita ohjelmia joilla avata tämän virheen sisältävän tiedoston. + + + + Could not start %1 + +Please check the application path and parameters are correct. + Ohjelman %1 käynnistäminen epäonnistui + +Tarkista että ohjelman polku ja parametrit ovat oikeat. + + + + ResultsView + + + + Cppcheck + Cppcheck + + + + No errors found. + Virheitä ei löytynyt. + + + + Errors were found, but they are configured to be hidden. +To toggle what kind of errors are shown, open view menu. + Virheitä löytyi, mutta asetuksissa kyseiset virheet on määritelty piilotettavaksi. +Määrittääksesi minkä tyyppisiä virheitä näytetään, avaa näkymä valikko. + + + + Results + Tulokset + + + + SettingsDialog + + + Cancel + Peruuta + + + + Ok + Ok + + + + General + Yleiset + + + + Number of threads: + Säikeiden lukumäärä: + + + + Check all #ifdef configurations + Tarkista kaikki #ifdef kombinaatiot + + + + Show full path of files + Näytä tiedostojen täysi polku + + + + Show "No errors found" message when no errors found + Näytä "virheitä ei löytynyt"-viesti jos virheitä ei löydy + + + + Applications + Ohjelmat + + + + Add application + Lisää ohjelma + + + + Delete application + Poista ohjelma + + + + Modify application + Muokkaa ohjelmaa + + + + Set as default application + Aseta oletusohjelmaksi + + + + Reports + Raportit + + + + Save all errors when creating report + Tallenna kaikki virheet raporttia luodessa + + + + Save full path to files in reports + Tallenna tiedostojen koko polku raportteihin + + + + Settings + Asetukset + + + + Add a new application + Lisää uusi ohjelma + + + + Modify an application + Muokkaa ohjelmaa + + + diff --git a/gui/cppcheck_ru.ts b/gui/cppcheck_ru.ts new file mode 100644 index 000000000..36eecc994 --- /dev/null +++ b/gui/cppcheck_ru.ts @@ -0,0 +1,552 @@ + + + + + AboutDialog + + + About cppcheck + + + + + Cppcheck - A tool for static C/C++ code analysis. + + + + + Version %1 + + + + + This program is licensed under the terms of the GNU General Public License version 3 + + + + + Close + + + + + ApplicationDialog + + + Here you can add applications that can open error files. +Specify a name for the application and the application to execute. + +The following texts are replaced with appriproate values when application is executed: +(file) - Filename containing the error +(line) - Line number containing the error +(message) - Error message +(severity) - Error severity + +Example opening a file with Kate and make Kate scroll to the correct line: +kate -l(line) (file) + + + + + Application's name + + + + + Application to execute + + + + + Browse + + + + + Cancel + + + + + Ok + + + + + Executable files (*.exe);;All files(*.*) + + + + + Select viewer application + + + + + Cppcheck + + + + + You must specify a name and a path for the application! + + + + + FileViewDialog + + + Close + + + + + Could not find the file: %1 + Could not find the file: + + + + + + + Cppcheck + + + + + Could not read the file: %1 + + + + + MainWindow + + + + + + + Cppcheck + + + + + Show possible false positives + + + + + &File + + + + + &View + + + + + &Check + + + + + &Edit + + + + + toolBar + + + + + &License... + + + + + A&uthors... + + + + + &About... + + + + + &Files... + + + + + Ctrl+F + + + + + &Directory... + + + + + Ctrl+D + + + + + &Recheck files + + + + + Ctrl+R + + + + + &Stop + + + + + Esc + + + + + &Save results to file... + + + + + Ctrl+S + + + + + &Quit + + + + + &Clear results + + + + + &Preferences + + + + + Show security errors + + + + + Show style errors + + + + + Show common errors + + + + + &Check all + + + + + &Uncheck all + + + + + Collapse &all + + + + + &Expand all + + + + + &Toolbar + + + + + &Language + + + + + &Help + + + + + Select files to check + + + + + Select directory to check + + + + + No suitable files found to check! + + + + + Cannot exit while checking. + +Stop the checking before exiting. + + + + + XML files (*.xml);;Text files (*.txt) + + + + + Save the report file + + + + + XML files (*.xml) + + + + + Cppcheck - %1 + + + + + Failed to change language: + +%1 + + + + + QObject + + + English + + + + + Finnish + + + + + Swedish + + + + + German + + + + + Russian + + + + + Incorrect language specified! + + + + + Failed to load language from file %1 + + + + + ResultsTree + + + + File + + + + + + Severity + + + + + + Line + + + + + + Message + + + + + Copy filename + + + + + Copy full path + + + + + Cppcheck + + + + + You can open this error by specifying applications in program's settings. + + + + + Could not start %1 + +Please check the application path and parameters are correct. + + + + + ResultsView + + + + Cppcheck + + + + + No errors found. + + + + + Errors were found, but they are configured to be hidden. +To toggle what kind of errors are shown, open view menu. + + + + + Results + + + + + SettingsDialog + + + Cancel + + + + + Ok + + + + + General + + + + + Number of threads: + + + + + Check all #ifdef configurations + + + + + Show full path of files + + + + + Show "No errors found" message when no errors found + + + + + Applications + + + + + Add application + + + + + Delete application + + + + + Modify application + + + + + Set as default application + + + + + Reports + + + + + Save all errors when creating report + + + + + Save full path to files in reports + + + + + Settings + + + + + Add a new application + + + + + Modify an application + + + + diff --git a/gui/cppcheck_se.ts b/gui/cppcheck_se.ts new file mode 100644 index 000000000..36eecc994 --- /dev/null +++ b/gui/cppcheck_se.ts @@ -0,0 +1,552 @@ + + + + + AboutDialog + + + About cppcheck + + + + + Cppcheck - A tool for static C/C++ code analysis. + + + + + Version %1 + + + + + This program is licensed under the terms of the GNU General Public License version 3 + + + + + Close + + + + + ApplicationDialog + + + Here you can add applications that can open error files. +Specify a name for the application and the application to execute. + +The following texts are replaced with appriproate values when application is executed: +(file) - Filename containing the error +(line) - Line number containing the error +(message) - Error message +(severity) - Error severity + +Example opening a file with Kate and make Kate scroll to the correct line: +kate -l(line) (file) + + + + + Application's name + + + + + Application to execute + + + + + Browse + + + + + Cancel + + + + + Ok + + + + + Executable files (*.exe);;All files(*.*) + + + + + Select viewer application + + + + + Cppcheck + + + + + You must specify a name and a path for the application! + + + + + FileViewDialog + + + Close + + + + + Could not find the file: %1 + Could not find the file: + + + + + + + Cppcheck + + + + + Could not read the file: %1 + + + + + MainWindow + + + + + + + Cppcheck + + + + + Show possible false positives + + + + + &File + + + + + &View + + + + + &Check + + + + + &Edit + + + + + toolBar + + + + + &License... + + + + + A&uthors... + + + + + &About... + + + + + &Files... + + + + + Ctrl+F + + + + + &Directory... + + + + + Ctrl+D + + + + + &Recheck files + + + + + Ctrl+R + + + + + &Stop + + + + + Esc + + + + + &Save results to file... + + + + + Ctrl+S + + + + + &Quit + + + + + &Clear results + + + + + &Preferences + + + + + Show security errors + + + + + Show style errors + + + + + Show common errors + + + + + &Check all + + + + + &Uncheck all + + + + + Collapse &all + + + + + &Expand all + + + + + &Toolbar + + + + + &Language + + + + + &Help + + + + + Select files to check + + + + + Select directory to check + + + + + No suitable files found to check! + + + + + Cannot exit while checking. + +Stop the checking before exiting. + + + + + XML files (*.xml);;Text files (*.txt) + + + + + Save the report file + + + + + XML files (*.xml) + + + + + Cppcheck - %1 + + + + + Failed to change language: + +%1 + + + + + QObject + + + English + + + + + Finnish + + + + + Swedish + + + + + German + + + + + Russian + + + + + Incorrect language specified! + + + + + Failed to load language from file %1 + + + + + ResultsTree + + + + File + + + + + + Severity + + + + + + Line + + + + + + Message + + + + + Copy filename + + + + + Copy full path + + + + + Cppcheck + + + + + You can open this error by specifying applications in program's settings. + + + + + Could not start %1 + +Please check the application path and parameters are correct. + + + + + ResultsView + + + + Cppcheck + + + + + No errors found. + + + + + Errors were found, but they are configured to be hidden. +To toggle what kind of errors are shown, open view menu. + + + + + Results + + + + + SettingsDialog + + + Cancel + + + + + Ok + + + + + General + + + + + Number of threads: + + + + + Check all #ifdef configurations + + + + + Show full path of files + + + + + Show "No errors found" message when no errors found + + + + + Applications + + + + + Add application + + + + + Delete application + + + + + Modify application + + + + + Set as default application + + + + + Reports + + + + + Save all errors when creating report + + + + + Save full path to files in reports + + + + + Settings + + + + + Add a new application + + + + + Modify an application + + + + diff --git a/gui/fileviewdialog.cpp b/gui/fileviewdialog.cpp index f8c393416..d2c309152 100644 --- a/gui/fileviewdialog.cpp +++ b/gui/fileviewdialog.cpp @@ -54,8 +54,9 @@ void FileViewDialog::LoadTextFile(const QString &filename, QTextEdit *edit) QFile file(filename); if (!file.exists()) { - QString msg(tr("Could not find the file:\n")); - msg += filename; + QString msg(tr("Could not find the file: %1")); + msg = msg.arg(filename); + QMessageBox msgbox(QMessageBox::Critical, tr("Cppcheck"), msg, @@ -68,8 +69,9 @@ void FileViewDialog::LoadTextFile(const QString &filename, QTextEdit *edit) file.open(QIODevice::ReadOnly | QIODevice::Text); if (!file.isReadable()) { - QString msg(tr("Could not read the file:\n")); - msg += filename; + QString msg(tr("Could not read the file: %1")); + msg = msg.arg(filename); + QMessageBox msgbox(QMessageBox::Critical, tr("Cppcheck"), msg, diff --git a/gui/gui.pro b/gui/gui.pro index 733025363..6ca450488 100644 --- a/gui/gui.pro +++ b/gui/gui.pro @@ -11,6 +11,14 @@ MOC_DIR = temp OBJECTS_DIR = temp CONFIG += warn_on debug RESOURCES = gui.qrc +FORMS = main.ui \ + resultsview.ui + +TRANSLATIONS = cppcheck_fi.ts \ + cppcheck_en.ts \ + cppcheck_se.ts \ + cppcheck_de.ts \ + cppcheck_ru.ts # Windows-specific options CONFIG += embed_manifest_exe @@ -32,6 +40,7 @@ HEADERS += mainwindow.h \ report.h \ txtreport.h \ xmlreport.h \ + translationhandler.h \ ../src/checkautovariables.h \ ../src/checkdangerousfunctions.h \ ../src/checkheaders.h \ @@ -71,6 +80,7 @@ SOURCES += main.cpp \ report.cpp \ txtreport.cpp \ xmlreport.cpp \ + translationhandler.cpp \ ../src/checkautovariables.cpp \ ../src/checkdangerousfunctions.cpp \ ../src/checkmemoryleak.cpp \ diff --git a/gui/main.cpp b/gui/main.cpp index c77f2652d..45b8fd255 100644 --- a/gui/main.cpp +++ b/gui/main.cpp @@ -19,6 +19,7 @@ #include #include +#include #include "mainwindow.h" int main(int argc, char *argv[]) @@ -30,6 +31,8 @@ int main(int argc, char *argv[]) QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8")); QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8")); + + MainWindow window; window.show(); return app.exec(); diff --git a/gui/main.ui b/gui/main.ui new file mode 100644 index 000000000..242819969 --- /dev/null +++ b/gui/main.ui @@ -0,0 +1,321 @@ + + + MainWindow + + + + 0 + 0 + 640 + 480 + + + + + 0 + 0 + + + + + 640 + 480 + + + + Cppcheck + + + + 22 + 22 + + + + + + 0 + 0 + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + + + + + + + + + + + + + 0 + 0 + 640 + 24 + + + + + &File + + + + + + + &View + + + + + + + + + + + + + + + + &Language + + + + + &Help + + + + + + + + &Check + + + + + + + + + &Edit + + + + + + + + + + + + + + + toolBar + + + TopToolBarArea + + + false + + + + + + + + + + + + &License... + + + + + A&uthors... + + + + + + :/images/help-browser.png:/images/help-browser.png + + + &About... + + + + + &Files... + + + Ctrl+F + + + + + + :/icon.png:/icon.png + + + &Directory... + + + Ctrl+D + + + + + + :/images/view-refresh.png:/images/view-refresh.png + + + &Recheck files + + + Ctrl+R + + + + + + :/images/process-stop.png:/images/process-stop.png + + + &Stop + + + Esc + + + + + + :/images/media-floppy.png:/images/media-floppy.png + + + &Save results to file... + + + Ctrl+S + + + + + &Quit + + + + + + :/images/edit-clear.png:/images/edit-clear.png + + + &Clear results + + + + + + :/images/preferences-system.png:/images/preferences-system.png + + + &Preferences + + + + + true + + + Show possible false positives + + + + + true + + + Show security errors + + + + + true + + + Show style errors + + + + + true + + + Show common errors + + + + + &Check all + + + + + &Uncheck all + + + + + Collapse &all + + + + + &Expand all + + + + + true + + + &Toolbar + + + + + + ResultsView + QWidget +
resultsview.h
+ 1 +
+
+ + + + +
diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 12546099d..d5d4e02f8 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -35,84 +35,62 @@ #include "../src/cppcheckexecutor.h" MainWindow::MainWindow() : - mSettings("Cppcheck", "Cppcheck-GUI"), - mActionExit(tr("E&xit"), this), - mActionCheckFiles(tr("&Check files(s)"), this), - mActionClearResults(tr("Clear &results"), this), - mActionReCheck(tr("Recheck files"), this), - mActionCheckDirectory(tr("Check &directory"), this), - mActionSettings(tr("&Settings"), this), - mActionViewStandardToolbar(tr("Toolbar"), this), - mActionShowAll(tr("Show possible false positives"), this), - mActionShowSecurity(tr("Show &security errors"), this), - mActionShowStyle(tr("Show s&tyle errors"), this), - mActionShowErrors(tr("Show &common errors"), this), - mActionShowCheckAll(tr("Show all"), this), - mActionShowUncheckAll(tr("Hide all"), this), - mActionShowCollapseAll(tr("Collapse all"), this), - mActionShowExpandAll(tr("Expand all"), this), - mActionAbout(tr("About"), this), - mActionShowLicense(tr("License..."), this), - mActionShowAuthors(tr("Authors..."), this), - mActionStop(tr("Stop checking"), this), - mActionSave(tr("Save results to a file"), this), - mResults(mSettings, mApplications) + mSettings(new QSettings("Cppcheck", "Cppcheck-GUI", this)), + mApplications(new ApplicationList(this)), + mTranslation(new TranslationHandler(this)), + mLanguages(new QActionGroup(this)) { - CreateMenus(); - CreateToolbar(); + mUI.setupUi(this); + mUI.mResults->Initialize(mSettings, mApplications); + + mThread = new ThreadHandler(this); - setCentralWidget(&mResults); - connect(&mActionExit, SIGNAL(triggered()), this, SLOT(close())); - connect(&mActionCheckFiles, SIGNAL(triggered()), this, SLOT(CheckFiles())); - connect(&mActionCheckDirectory, SIGNAL(triggered()), this, SLOT(CheckDirectory())); - connect(&mActionSettings, SIGNAL(triggered()), this, SLOT(ProgramSettings())); - connect(&mActionClearResults, SIGNAL(triggered()), this, SLOT(ClearResults())); - connect(&mActionViewStandardToolbar, SIGNAL(toggled(bool)), this, SLOT(ViewStandardToolbar(bool))); - connect(&mActionShowAll, SIGNAL(toggled(bool)), this, SLOT(ShowAll(bool))); - connect(&mActionShowSecurity, SIGNAL(toggled(bool)), this, SLOT(ShowSecurity(bool))); - connect(&mActionShowStyle, SIGNAL(toggled(bool)), this, SLOT(ShowStyle(bool))); - connect(&mActionShowErrors, SIGNAL(toggled(bool)), this, SLOT(ShowErrors(bool))); - connect(&mActionShowCheckAll, SIGNAL(triggered()), this, SLOT(CheckAll())); - connect(&mActionShowUncheckAll, SIGNAL(triggered()), this, SLOT(UncheckAll())); - connect(&mActionShowCollapseAll, SIGNAL(triggered()), &mResults, SLOT(CollapseAllResults())); - connect(&mActionShowExpandAll, SIGNAL(triggered()), &mResults, SLOT(ExpandAllResults())); + connect(mUI.mActionQuit, SIGNAL(triggered()), this, SLOT(close())); + connect(mUI.mActionCheckFiles, SIGNAL(triggered()), this, SLOT(CheckFiles())); + connect(mUI.mActionCheckDirectory, SIGNAL(triggered()), this, SLOT(CheckDirectory())); + connect(mUI.mActionSettings, SIGNAL(triggered()), this, SLOT(ProgramSettings())); + connect(mUI.mActionClearResults, SIGNAL(triggered()), this, SLOT(ClearResults())); - connect(&mActionReCheck, SIGNAL(triggered()), this, SLOT(ReCheck())); + connect(mUI.mActionShowAll, SIGNAL(toggled(bool)), this, SLOT(ShowAll(bool))); + connect(mUI.mActionShowSecurity, SIGNAL(toggled(bool)), this, SLOT(ShowSecurity(bool))); + connect(mUI.mActionShowStyle, SIGNAL(toggled(bool)), this, SLOT(ShowStyle(bool))); + connect(mUI.mActionShowErrors, SIGNAL(toggled(bool)), this, SLOT(ShowErrors(bool))); + connect(mUI.mActionCheckAll, SIGNAL(triggered()), this, SLOT(CheckAll())); + connect(mUI.mActionUncheckAll, SIGNAL(triggered()), this, SLOT(UncheckAll())); + connect(mUI.mActionCollapseAll, SIGNAL(triggered()), mUI.mResults, SLOT(CollapseAllResults())); + connect(mUI.mActionExpandAll, SIGNAL(triggered()), mUI.mResults, SLOT(ExpandAllResults())); - connect(&mActionStop, SIGNAL(triggered()), mThread, SLOT(Stop())); - connect(&mActionSave, SIGNAL(triggered()), this, SLOT(Save())); + connect(mUI.mActionRecheck, SIGNAL(triggered()), this, SLOT(ReCheck())); - connect(&mActionAbout, SIGNAL(triggered()), this, SLOT(About())); - connect(&mActionShowLicense, SIGNAL(triggered()), this, SLOT(ShowLicense())); - connect(&mActionShowAuthors, SIGNAL(triggered()), this, SLOT(ShowAuthors())); + connect(mUI.mActionStop, SIGNAL(triggered()), mThread, SLOT(Stop())); + connect(mUI.mActionSave, SIGNAL(triggered()), this, SLOT(Save())); + + connect(mUI.mActionAbout, SIGNAL(triggered()), this, SLOT(About())); + connect(mUI.mActionLicense, SIGNAL(triggered()), this, SLOT(ShowLicense())); + connect(mUI.mActionAuthors, SIGNAL(triggered()), this, SLOT(ShowAuthors())); connect(mThread, SIGNAL(Done()), this, SLOT(CheckDone())); - connect(&mResults, SIGNAL(GotResults()), this, SLOT(ResultsAdded())); + connect(mUI.mResults, SIGNAL(GotResults()), this, SLOT(ResultsAdded())); + - mActionCheckDirectory.setIcon(QIcon(":icon.png")); - mActionReCheck.setIcon(QIcon(":images/view-refresh.png")); - mActionSettings.setIcon(QIcon(":images/preferences-system.png")); - mActionAbout.setIcon(QIcon(":images/help-browser.png")); - mActionStop.setIcon(QIcon(":images/process-stop.png")); - mActionSave.setIcon(QIcon(":images/media-floppy.png")); - mActionClearResults.setIcon(QIcon(":images/edit-clear.png")); - mActionReCheck.setShortcut(QKeySequence(Qt::CTRL + Qt::Key_R)); - mActionCheckDirectory.setShortcut(QKeySequence(Qt::CTRL + Qt::Key_D)); - mActionSave.setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S)); - mActionAbout.setShortcut(QKeySequence(Qt::Key_F1)); LoadSettings(); - mThread->Initialize(&mResults); + + mThread->Initialize(mUI.mResults); FormatAndSetTitle(); EnableCheckButtons(true); - mActionClearResults.setEnabled(false); - mActionSave.setEnabled(false); + mUI.mActionClearResults->setEnabled(false); + mUI.mActionSave->setEnabled(false); + + + CreateLanguageMenuItems(); + } MainWindow::~MainWindow() @@ -120,109 +98,98 @@ MainWindow::~MainWindow() SaveSettings(); } -void MainWindow::CreateMenus() +void MainWindow::CreateLanguageMenuItems() { - // File-menu - QMenu *menu = menuBar()->addMenu(tr("&File")); - menu->addAction(&mActionCheckFiles); - menu->addAction(&mActionCheckDirectory); - menu->addAction(&mActionReCheck); - menu->addAction(&mActionStop); - menu->addAction(&mActionClearResults); - menu->addAction(&mActionSave); - menu->addSeparator(); - menu->addAction(&mActionExit); - // View-menu - QMenu *menuview = menuBar()->addMenu(tr("&View")); - menuview->addAction(&mActionViewStandardToolbar); - menuview->addSeparator(); - menuview->addAction(&mActionShowAll); - menuview->addAction(&mActionShowSecurity); - menuview->addAction(&mActionShowStyle); - menuview->addAction(&mActionShowErrors); - menuview->addSeparator(); - menuview->addAction(&mActionShowCheckAll); - menuview->addAction(&mActionShowUncheckAll); - menuview->addSeparator(); - menuview->addAction(&mActionShowCollapseAll); - menuview->addAction(&mActionShowExpandAll); - mActionViewStandardToolbar.setCheckable(true); - mActionShowAll.setCheckable(true); - mActionShowSecurity.setCheckable(true); - mActionShowStyle.setCheckable(true); - mActionShowErrors.setCheckable(true); - connect(menuview, SIGNAL(aboutToShow()), this, SLOT(AboutToShowViewMenu())); - // Program-menu - QMenu *menuprogram = menuBar()->addMenu(tr("&Program")); - menuprogram->addAction(&mActionSettings); + QStringList languages = mTranslation->GetNames(); - // Help-menu - QMenu *menuHelp = menuBar()->addMenu(tr("&Help")); - menuHelp->addAction(&mActionShowLicense); - menuHelp->addAction(&mActionShowAuthors); - menuHelp->addSeparator(); - menuHelp->addAction(&mActionAbout); + for (int i = 0;i < languages.size();i++) + { + //Create an action for each language + //Language name is pre translated + QAction *temp = new QAction(languages[i], this); + + temp->setCheckable(true); + + //Add the action to menu + mUI.menu_Language->addAction(temp); + + //Add action to the group + mLanguages->addAction(temp); + + //Check it if it's the value stored to settings + if (i == mSettings->value(SETTINGS_LANGUAGE, 0).toInt()) + { + temp->setChecked(true); + } + else + { + temp->setChecked(false); + } + } + + connect(mLanguages, SIGNAL(triggered(QAction *)), + this, SLOT(MapLanguage(QAction *))); } -void MainWindow::CreateToolbar() -{ - mStandardToolbar = addToolBar("Standard"); - mStandardToolbar->setIconSize(QSize(22, 22)); - mStandardToolbar->addAction(&mActionCheckDirectory); - mStandardToolbar->addAction(&mActionSave); - mStandardToolbar->addAction(&mActionReCheck); - mStandardToolbar->addAction(&mActionStop); - mStandardToolbar->addAction(&mActionClearResults); - mStandardToolbar->addAction(&mActionSettings); - mStandardToolbar->addAction(&mActionAbout); -} void MainWindow::LoadSettings() { - if (mSettings.value("Window maximized", false).toBool()) + + if (mSettings->value(SETTINGS_WINDOW_MAXIMIZED, false).toBool()) { showMaximized(); } else { - resize(mSettings.value("Window width", 800).toInt(), - mSettings.value("Window height", 600).toInt()); + resize(mSettings->value(SETTINGS_WINDOW_WIDTH, 800).toInt(), + mSettings->value(SETTINGS_WINDOW_HEIGHT, 600).toInt()); } - mActionShowAll.setChecked(mSettings.value("Show all", true).toBool()); - mActionShowSecurity.setChecked(mSettings.value("Show security", true).toBool()); - mActionShowStyle.setChecked(mSettings.value("Show style", true).toBool()); - mActionShowErrors.setChecked(mSettings.value("Show errors", true).toBool()); - mResults.ShowResults(SHOW_ALL, mActionShowAll.isChecked()); - mResults.ShowResults(SHOW_ERRORS, mActionShowErrors.isChecked()); - mResults.ShowResults(SHOW_SECURITY, mActionShowSecurity.isChecked()); - mResults.ShowResults(SHOW_STYLE, mActionShowStyle.isChecked()); + mUI.mActionShowAll->setChecked(mSettings->value(SETTINGS_SHOW_ALL, true).toBool()); + mUI.mActionShowSecurity->setChecked(mSettings->value(SETTINGS_SHOW_SECURITY, true).toBool()); + mUI.mActionShowStyle->setChecked(mSettings->value(SETTINGS_SHOW_STYLE, true).toBool()); + mUI.mActionShowErrors->setChecked(mSettings->value(SETTINGS_SHOW_ERRORS, true).toBool()); - mStandardToolbar->setVisible(mSettings.value("Toolbars/ShowStandard", true).toBool()); - mApplications.LoadSettings(mSettings); + mUI.mResults->ShowResults(SHOW_ALL, mUI.mActionShowAll->isChecked()); + mUI.mResults->ShowResults(SHOW_ERRORS, mUI.mActionShowErrors->isChecked()); + mUI.mResults->ShowResults(SHOW_SECURITY, mUI.mActionShowSecurity->isChecked()); + mUI.mResults->ShowResults(SHOW_STYLE, mUI.mActionShowStyle->isChecked()); + + mUI.mActionToolbar->setChecked(mSettings->value(SETTINGS_TOOLBARS_SHOW, true).toBool()); + mUI.toolBar->setVisible(mSettings->value(SETTINGS_TOOLBARS_SHOW, true).toBool()); + + + mApplications->LoadSettings(mSettings); + + QString error = ""; + + SetLanguage(mSettings->value(SETTINGS_LANGUAGE, 0).toInt()); } void MainWindow::SaveSettings() { - mSettings.setValue("Window width", size().width()); - mSettings.setValue("Window height", size().height()); - mSettings.setValue("Window maximized", isMaximized()); + mSettings->setValue(SETTINGS_WINDOW_WIDTH, size().width()); + mSettings->setValue(SETTINGS_WINDOW_HEIGHT, size().height()); + mSettings->setValue(SETTINGS_WINDOW_MAXIMIZED, isMaximized()); - mSettings.setValue("Show all", mActionShowAll.isChecked()); - mSettings.setValue("Show security", mActionShowSecurity.isChecked()); - mSettings.setValue("Show style", mActionShowStyle.isChecked()); - mSettings.setValue("Show errors", mActionShowErrors.isChecked()); - mSettings.setValue("Toolbars/ShowStandard", mActionViewStandardToolbar.isChecked()); + mSettings->setValue(SETTINGS_SHOW_ALL, mUI.mActionShowAll->isChecked()); + mSettings->setValue(SETTINGS_SHOW_SECURITY, mUI.mActionShowSecurity->isChecked()); + mSettings->setValue(SETTINGS_SHOW_STYLE, mUI.mActionShowStyle->isChecked()); + mSettings->setValue(SETTINGS_SHOW_ERRORS, mUI.mActionShowErrors->isChecked()); + mSettings->setValue(SETTINGS_TOOLBARS_SHOW, mUI.mActionToolbar->isChecked()); - mApplications.SaveSettings(mSettings); + mApplications->SaveSettings(mSettings); + + mSettings->setValue(SETTINGS_LANGUAGE, mTranslation->GetCurrentLanguage()); + mUI.mResults->SaveSettings(); } void MainWindow::DoCheckFiles(QFileDialog::FileMode mode) @@ -236,7 +203,7 @@ void MainWindow::DoCheckFiles(QFileDialog::FileMode mode) { selected = QFileDialog::getOpenFileNames(this, tr("Select files to check"), - mSettings.value("Check path", "").toString()); + mSettings->value(SETTINGS_CHECK_PATH, "").toString()); if (selected.isEmpty()) mCurrentDirectory.clear(); FormatAndSetTitle(); @@ -245,7 +212,7 @@ void MainWindow::DoCheckFiles(QFileDialog::FileMode mode) { QString dir = QFileDialog::getExistingDirectory(this, tr("Select directory to check"), - mSettings.value("Check path", "").toString()); + mSettings->value(SETTINGS_CHECK_PATH, "").toString()); if (!dir.isEmpty()) { mCurrentDirectory = dir; @@ -266,7 +233,7 @@ void MainWindow::DoCheckFiles(QFileDialog::FileMode mode) fileNames << RemoveUnacceptedFiles(GetFilesRecursively(selection)); } - mResults.Clear(); + mUI.mResults->Clear(); mThread->ClearFiles(); if (fileNames.isEmpty()) @@ -280,15 +247,16 @@ void MainWindow::DoCheckFiles(QFileDialog::FileMode mode) return; } - mResults.CheckingStarted(); + mUI.mResults->CheckingStarted(); mThread->SetFiles(RemoveUnacceptedFiles(fileNames)); QFileInfo inf(fileNames[0]); QString absDirectory = inf.absoluteDir().path(); - mSettings.setValue("Check path", absDirectory); + mSettings->setValue(SETTINGS_CHECK_PATH, absDirectory); EnableCheckButtons(false); - mActionSettings.setEnabled(false); - mResults.SetCheckDirectory(absDirectory); + mUI.mActionSettings->setEnabled(false); + + mUI.mResults->SetCheckDirectory(absDirectory); Settings checkSettings = GetCppcheckSettings(); mThread->Check(checkSettings, false); @@ -336,11 +304,11 @@ Settings MainWindow::GetCppcheckSettings() result._checkCodingStyle = true; result._errorsOnly = false; result._verbose = true; - result._force = mSettings.value("Check force", 1).toBool(); + result._force = mSettings->value(SETTINGS_CHECK_FORCE, 1).toBool(); result._xml = false; result._unusedFunctions = false; result._security = true; - result._jobs = mSettings.value("Check threads", 1).toInt(); + result._jobs = mSettings->value(SETTINGS_CHECK_THREADS, 1).toInt(); if (result._jobs <= 0) { @@ -390,11 +358,11 @@ QStringList MainWindow::RemoveUnacceptedFiles(const QStringList &list) void MainWindow::CheckDone() { EnableCheckButtons(true); - mActionSettings.setEnabled(true); - if (mResults.HasResults()) + mUI.mActionSettings->setEnabled(true); + if (mUI.mResults->HasResults()) { - mActionClearResults.setEnabled(true); - mActionSave.setEnabled(true); + mUI.mActionClearResults->setEnabled(true); + mUI.mActionSave->setEnabled(true); } // Notify user - if the window is not active - that check is ready @@ -407,10 +375,10 @@ void MainWindow::ProgramSettings() if (dialog.exec() == QDialog::Accepted) { dialog.SaveCheckboxValues(); - mResults.UpdateSettings(dialog.ShowFullPath(), - dialog.SaveFullPath(), - dialog.SaveAllErrors(), - dialog.ShowNoErrorsMessage()); + mUI.mResults->UpdateSettings(dialog.ShowFullPath(), + dialog.SaveFullPath(), + dialog.SaveAllErrors(), + dialog.ShowNoErrorsMessage()); } } @@ -423,38 +391,38 @@ void MainWindow::ReCheck() void MainWindow::ClearResults() { - mResults.Clear(); - mActionClearResults.setEnabled(false); - mActionSave.setEnabled(false); + mUI.mResults->Clear(); + mUI.mActionClearResults->setEnabled(false); + mUI.mActionSave->setEnabled(false); } void MainWindow::EnableCheckButtons(bool enable) { - mActionStop.setEnabled(!enable); - mActionCheckFiles.setEnabled(enable); - mActionReCheck.setEnabled(enable); - mActionCheckDirectory.setEnabled(enable); + mUI.mActionStop->setEnabled(!enable); + mUI.mActionCheckFiles->setEnabled(enable); + mUI.mActionRecheck->setEnabled(enable); + mUI.mActionCheckDirectory->setEnabled(enable); } void MainWindow::ShowAll(bool checked) { - mResults.ShowResults(SHOW_ALL, checked); + mUI.mResults->ShowResults(SHOW_ALL, checked); } void MainWindow::ShowSecurity(bool checked) { - mResults.ShowResults(SHOW_SECURITY, checked); + mUI.mResults->ShowResults(SHOW_SECURITY, checked); } void MainWindow::ShowStyle(bool checked) { - mResults.ShowResults(SHOW_STYLE, checked); + mUI.mResults->ShowResults(SHOW_STYLE, checked); } void MainWindow::ShowErrors(bool checked) { - mResults.ShowResults(SHOW_ERRORS, checked); + mUI.mResults->ShowResults(SHOW_ERRORS, checked); } void MainWindow::CheckAll() @@ -492,16 +460,16 @@ void MainWindow::closeEvent(QCloseEvent *event) void MainWindow::ToggleAllChecked(bool checked) { - mActionShowAll.setChecked(checked); + mUI.mActionShowAll->setChecked(checked); ShowAll(checked); - mActionShowSecurity.setChecked(checked); + mUI.mActionShowSecurity->setChecked(checked); ShowSecurity(checked); - mActionShowStyle.setChecked(checked); + mUI.mActionShowStyle->setChecked(checked); ShowStyle(checked); - mActionShowErrors.setChecked(checked); + mUI.mActionShowErrors->setChecked(checked); ShowErrors(checked); } @@ -559,7 +527,7 @@ void MainWindow::Save() selectedFile += ".txt"; } - mResults.Save(selectedFile, xml); + mUI.mResults->Save(selectedFile, xml); } } @@ -567,12 +535,9 @@ void MainWindow::ResultsAdded() { } -void MainWindow::ViewStandardToolbar(bool view) +void MainWindow::ToggleToolbar() { - if (view) - mStandardToolbar->show(); - else - mStandardToolbar->hide(); + mUI.toolBar->setVisible(mUI.mActionToolbar->isChecked()); } void MainWindow::FormatAndSetTitle(const QString &text) @@ -585,10 +550,42 @@ void MainWindow::FormatAndSetTitle(const QString &text) setWindowTitle(title); } -void MainWindow::AboutToShowViewMenu() + +void MainWindow::SetLanguage(int index) { - if (mStandardToolbar->isVisible()) - mActionViewStandardToolbar.setChecked(true); + if (mTranslation->GetCurrentLanguage() == index) + { + return; + } + + QString error; + if (!mTranslation->SetLanguage(index, error)) + { + QMessageBox msg(QMessageBox::Warning, + tr("Cppcheck"), + QString(tr("Failed to change language:\n\n%1")).arg(error), + QMessageBox::Ok, + this); + + msg.exec(); + } else - mActionViewStandardToolbar.setChecked(false); + { + mUI.retranslateUi(this); + } } + + +void MainWindow::MapLanguage(QAction *action) +{ + //Find the action that has the language that user clicked + QList actions = mLanguages->actions(); + for (int i = 0;i < actions.size();i++) + { + if (actions[i] == action) + { + SetLanguage(i); + } + } +} + diff --git a/gui/mainwindow.h b/gui/mainwindow.h index b6d0bb891..f01bad8d8 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -22,13 +22,16 @@ #include #include -#include #include +#include +#include #include #include "resultsview.h" #include "settingsdialog.h" +#include "translationhandler.h" +#include "ui_main.h" class ThreadHandler; /** @@ -44,6 +47,8 @@ public: public slots: + + /** * @brief Slot for check files menu item * @@ -146,27 +151,32 @@ protected slots: */ void ResultsAdded(); + + /** + * @brief Slot for changing the program's language + * + */ + void MapLanguage(QAction *); + /** * @brief Slot for showing/hiding standard toolbar */ - void ViewStandardToolbar(bool view); + void ToggleToolbar(); - /** - * @brief Slot for updating View-menu before it is shown. - */ - void AboutToShowViewMenu(); protected: /** - * @brief Create main window menus. + * @brief Create menu items to change language + * */ - void CreateMenus(); + void CreateLanguageMenuItems(); /** - * @brief Create main window toolbar. + * @brief Set current language + * @param index Index of the language to set */ - void CreateToolbar(); + void SetLanguage(const int index); /** * @brief Event coming when application is about to close. @@ -239,132 +249,16 @@ protected: * @brief Program settings * */ - QSettings mSettings; + QSettings *mSettings; - /** - * @brief Menu action to exit program - * - */ - QAction mActionExit; - /** - * @brief Menu action to check files - * - */ - QAction mActionCheckFiles; - /** - * @brief Menu action to clear results - * - */ - QAction mActionClearResults; - - /** - * @brief Menu action to re check - * - */ - QAction mActionReCheck; - - /** - * @brief Menu action to check a directory - * - */ - QAction mActionCheckDirectory; - - /** - * @brief Menu action to open settings dialog - * - */ - QAction mActionSettings; - - /** - * @brief Menu action to show/hide standard toolbar - */ - QAction mActionViewStandardToolbar; - - /** - * @brief Action to show errors with type "all" - * - */ - QAction mActionShowAll; - - /** - * @brief Action to show errors with type "security" - * - */ - QAction mActionShowSecurity; - - /** - * @brief Action to show errors with type "style" - * - */ - QAction mActionShowStyle; - - /** - * @brief Action to show errors with type "error" - * - */ - QAction mActionShowErrors; - - /** - * @brief Action to check all "show error" menu items - * - */ - QAction mActionShowCheckAll; - - /** - * @brief Action to uncheck all "show error" menu items - * - */ - QAction mActionShowUncheckAll; - - /** - * @brief Action to collapse all items in the result tree. - * - */ - QAction mActionShowCollapseAll; - - /** - * @brief Action to expand all items in the result tree. - * - */ - QAction mActionShowExpandAll; - - /** - * @brief Action to show about dialog - * - */ - QAction mActionAbout; - - /** - * @brief Action to show license text - * - */ - QAction mActionShowLicense; - - /** - * @brief Action to show authors list - * - */ - QAction mActionShowAuthors; - - /** - * @brief Action stop checking files - * - */ - QAction mActionStop; - - /** - * @brief Action save found errors to a file - * - */ - QAction mActionSave; /** * @brief Results for checking * */ - ResultsView mResults; +// ResultsView mResults; /** * @brief Thread to check files @@ -376,19 +270,31 @@ protected: * @brief List of user defined applications to open errors with * */ - ApplicationList mApplications; + ApplicationList *mApplications; -private: + /** + * @brief Class to handle translation changes + * + */ + TranslationHandler *mTranslation; + + /** + * @brief Class holding all UI components + * + */ + Ui::MainWindow mUI; + + /** + * @brief Group holding all supported languages + * + */ + QActionGroup *mLanguages; /** * @brief Current checked directory. */ QString mCurrentDirectory; - /** - * @brief Standard toolbar (currently only one). - */ - QToolBar *mStandardToolbar; }; #endif // MAINWINDOW_H diff --git a/gui/resultstree.cpp b/gui/resultstree.cpp index 55a9dfe32..adc9064fe 100644 --- a/gui/resultstree.cpp +++ b/gui/resultstree.cpp @@ -28,9 +28,8 @@ #include "resultstree.h" #include "xmlreport.h" -ResultsTree::ResultsTree(QSettings &settings, ApplicationList &list) : - mSettings(settings), - mApplications(list), +ResultsTree::ResultsTree(QWidget * parent) : + QTreeView(parent), mContextItem(0), mCheckPath(""), mVisibleErrors(false) @@ -41,16 +40,23 @@ ResultsTree::ResultsTree(QSettings &settings, ApplicationList &list) : mModel.setHorizontalHeaderLabels(labels); setExpandsOnDoubleClick(false); setSortingEnabled(true); - LoadSettings(); + connect(this, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(QuickStartApplication(const QModelIndex &))); } ResultsTree::~ResultsTree() { - SaveSettings(); } +void ResultsTree::Initialize(QSettings *settings, ApplicationList *list) +{ + mSettings = settings; + mApplications = list; + LoadSettings(); +} + + QStandardItem *ResultsTree::CreateItem(const QString &name) { QStandardItem *item = new QStandardItem(name); @@ -207,21 +213,21 @@ void ResultsTree::LoadSettings() for (int i = 0; i < mModel.columnCount(); i++) { //mFileTree.columnWidth(i); - QString temp = QString(tr("Result column %1 width")).arg(i); - setColumnWidth(i, mSettings.value(temp, 800 / mModel.columnCount()).toInt()); + QString temp = QString(SETTINGS_RESULT_COLUMN_WIDTH).arg(i); + setColumnWidth(i, mSettings->value(temp, 800 / mModel.columnCount()).toInt()); } - mSaveFullPath = mSettings.value("Save full path", false).toBool(); - mSaveAllErrors = mSettings.value("Save all errors", false).toBool(); - mShowFullPath = mSettings.value("Show full path", false).toBool(); + mSaveFullPath = mSettings->value(SETTINGS_SAVE_FULL_PATH, false).toBool(); + mSaveAllErrors = mSettings->value(SETTINGS_SAVE_ALL_ERRORS, false).toBool(); + mShowFullPath = mSettings->value(SETTINGS_SHOW_FULL_PATH, false).toBool(); } void ResultsTree::SaveSettings() { for (int i = 0; i < mModel.columnCount(); i++) { - QString temp = QString(tr("Result column %1 width")).arg(i); - mSettings.setValue(temp, columnWidth(i)); + QString temp = QString(SETTINGS_RESULT_COLUMN_WIDTH).arg(i); + mSettings->setValue(temp, columnWidth(i)); } } @@ -343,13 +349,13 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e) //member variables QSignalMapper *signalMapper = new QSignalMapper(this); - if (mContextItem && mApplications.GetApplicationCount() > 0 && mContextItem->parent()) + if (mContextItem && mApplications->GetApplicationCount() > 0 && mContextItem->parent()) { //Go through all applications and add them to the context menu - for (int i = 0; i < mApplications.GetApplicationCount(); i++) + for (int i = 0;i < mApplications->GetApplicationCount();i++) { //Create an action for the application - QAction *start = new QAction(mApplications.GetApplicationName(i), &menu); + QAction *start = new QAction(mApplications->GetApplicationName(i), &menu); //Add it to our list so we can disconnect later on actions << start; @@ -371,7 +377,7 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e) // Add menuitems to copy full path/filename to clipboard if (mContextItem) { - if (mApplications.GetApplicationCount() > 0) + if (mApplications->GetApplicationCount() > 0) { menu.addSeparator(); } @@ -390,7 +396,7 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e) //Start the menu menu.exec(e->globalPos()); - if (mContextItem && mApplications.GetApplicationCount() > 0 && mContextItem->parent()) + if (mContextItem && mApplications->GetApplicationCount() > 0 && mContextItem->parent()) { //Disconnect all signals for (int i = 0; i < actions.size(); i++) @@ -411,7 +417,7 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e) void ResultsTree::StartApplication(QStandardItem *target, int application) { //If there are now application's specified, tell the user about it - if (mApplications.GetApplicationCount() == 0) + if (mApplications->GetApplicationCount() == 0) { QMessageBox msg(QMessageBox::Warning, tr("Cppcheck"), @@ -422,11 +428,11 @@ void ResultsTree::StartApplication(QStandardItem *target, int application) return; } - if (target && application >= 0 && application < mApplications.GetApplicationCount() && target->parent()) + if (target && application >= 0 && application < mApplications->GetApplicationCount() && target->parent()) { QVariantMap data = target->data().toMap(); - QString program = mApplications.GetApplicationPath(application); + QString program = mApplications->GetApplicationPath(application); //TODO Check which line was actually right clicked, now defaults to 0 unsigned int index = 0; @@ -459,9 +465,8 @@ void ResultsTree::StartApplication(QStandardItem *target, int application) bool success = QProcess::startDetached(program); if (!success) { - QString app = mApplications.GetApplicationName(application); - QString text = tr("Could not start ") + app + "\n\n"; - text += tr("Please check the application path and parameters are correct."); + QString app = mApplications->GetApplicationName(application); + QString text = tr("Could not start %1\n\nPlease check the application path and parameters are correct.").arg(app); QMessageBox msgbox(this); msgbox.setWindowTitle("Cppcheck"); @@ -740,3 +745,12 @@ bool ResultsTree::HasResults() const { return mModel.rowCount() > 0; } + +void ResultsTree::LanguageChanged() +{ + QStringList labels; + labels << tr("File") << tr("Severity") << tr("Line") << tr("Message"); + mModel.setHorizontalHeaderLabels(labels); + +} + diff --git a/gui/resultstree.h b/gui/resultstree.h index cfca313c6..1f593fb3d 100644 --- a/gui/resultstree.h +++ b/gui/resultstree.h @@ -39,8 +39,9 @@ class ResultsTree : public QTreeView { Q_OBJECT public: - ResultsTree(QSettings &settings, ApplicationList &list); + ResultsTree(QWidget * parent = 0); virtual ~ResultsTree(); + void Initialize(QSettings *settings, ApplicationList *list); /** * @brief Add a new item to the tree @@ -108,6 +109,17 @@ public: */ bool HasResults() const; + /** + * @brief Save all settings + * Colum widths + */ + void SaveSettings(); + + /** + * @brief Change all visible texts language + * + */ + void LanguageChanged(); protected slots: /** * @brief Slot to quickstart an error with default application @@ -253,11 +265,6 @@ protected: */ void LoadSettings(); - /** - * @brief Save all settings - * Colum widths - */ - void SaveSettings(); /** * @brief Create a new QStandardItem @@ -302,7 +309,7 @@ protected: * @brief Program settings * */ - QSettings &mSettings; + QSettings *mSettings; /** * @brief List of bools to determine which of ShowTypes to display on the tree @@ -315,7 +322,7 @@ protected: * @brief List of applications to open errors with * */ - ApplicationList &mApplications; + ApplicationList *mApplications; /** * @brief Right clicked item (used by context menu slots) diff --git a/gui/resultsview.cpp b/gui/resultsview.cpp index 61d02880b..b429730e2 100644 --- a/gui/resultsview.cpp +++ b/gui/resultsview.cpp @@ -24,25 +24,25 @@ #include "txtreport.h" #include "xmlreport.h" -ResultsView::ResultsView(QSettings &settings, ApplicationList &list) : +ResultsView::ResultsView(QWidget * parent) : + QWidget(parent), mErrorsFound(false), mShowNoErrorsMessage(true) { - QVBoxLayout *layout = new QVBoxLayout(); - setLayout(layout); - - mProgress = new QProgressBar(); - layout->addWidget(mProgress); - mProgress->setMinimum(0); - mProgress->setVisible(false); - - mTree = new ResultsTree(settings, list); - layout->addWidget(mTree); - - mShowNoErrorsMessage = settings.value(tr("Show no errors message"), true).toBool(); - + mUI.setupUi(this); } +void ResultsView::Initialize(QSettings *settings, ApplicationList *list) +{ + + mUI.mProgress->setMinimum(0); + mUI.mProgress->setVisible(false); + mShowNoErrorsMessage = settings->value(SETTINGS_SHOW_NO_ERRORS, true).toBool(); + + mUI.mTree->Initialize(settings, list); +} + + ResultsView::~ResultsView() { //dtor @@ -51,23 +51,23 @@ ResultsView::~ResultsView() void ResultsView::Clear() { - mTree->Clear(); + mUI.mTree->Clear(); mErrorsFound = false; //Clear the progressbar - mProgress->setMaximum(100); - mProgress->setValue(0); + mUI.mProgress->setMaximum(100); + mUI.mProgress->setValue(0); } void ResultsView::Progress(int value, int max) { - mProgress->setMaximum(max); - mProgress->setValue(value); + mUI.mProgress->setMaximum(max); + mUI.mProgress->setValue(value); if (value >= max) { - mProgress->setVisible(false); + mUI.mProgress->setVisible(false); //Should we inform user of non visible/not found errors? if (mShowNoErrorsMessage) { //Tell user that we found no errors @@ -81,7 +81,7 @@ void ResultsView::Progress(int value, int max) msg.exec(); } //If we have errors but they aren't visible, tell user about it - else if (!mTree->HasVisibleResults()) + else if (!mUI.mTree->HasVisibleResults()) { QString text = tr("Errors were found, but they are configured to be hidden.\n"\ "To toggle what kind of errors are shown, open view menu."); @@ -97,7 +97,7 @@ void ResultsView::Progress(int value, int max) } else { - mProgress->setVisible(true); + mUI.mProgress->setVisible(true); } } @@ -109,23 +109,23 @@ void ResultsView::Error(const QString &file, const QString &id) { mErrorsFound = true; - mTree->AddErrorItem(file, severity, message, files, lines, id); + mUI.mTree->AddErrorItem(file, severity, message, files, lines, id); emit GotResults(); } void ResultsView::ShowResults(ShowTypes type, bool show) { - mTree->ShowResults(type, show); + mUI.mTree->ShowResults(type, show); } void ResultsView::CollapseAllResults() { - mTree->collapseAll(); + mUI.mTree->collapseAll(); } void ResultsView::ExpandAllResults() { - mTree->expandAll(); + mUI.mTree->expandAll(); } void ResultsView::Save(const QString &filename, bool xml) @@ -141,7 +141,7 @@ void ResultsView::Save(const QString &filename, bool xml) { XmlReport report(filename); if (report.Create()) - mTree->SaveResults(&report); + mUI.mTree->SaveResults(&report); else { QMessageBox msgBox; @@ -153,7 +153,7 @@ void ResultsView::Save(const QString &filename, bool xml) { TxtReport report(filename); if (report.Create()) - mTree->SaveResults(&report); + mUI.mTree->SaveResults(&report); else { QMessageBox msgBox; @@ -168,26 +168,32 @@ void ResultsView::UpdateSettings(bool showFullPath, bool saveAllErrors, bool showNoErrorsMessage) { - mTree->UpdateSettings(showFullPath, saveFullPath, saveAllErrors); + mUI.mTree->UpdateSettings(showFullPath, saveFullPath, saveAllErrors); mShowNoErrorsMessage = showNoErrorsMessage; } void ResultsView::SetCheckDirectory(const QString &dir) { - mTree->SetCheckDirectory(dir); + mUI.mTree->SetCheckDirectory(dir); } void ResultsView::CheckingStarted() { - mProgress->setVisible(true); + mUI.mProgress->setVisible(true); } bool ResultsView::HasVisibleResults() const { - return mTree->HasVisibleResults(); + return mUI.mTree->HasVisibleResults(); } bool ResultsView::HasResults() const { - return mTree->HasResults(); + return mUI.mTree->HasResults(); } + +void ResultsView::SaveSettings() +{ + mUI.mTree->SaveSettings(); +} + diff --git a/gui/resultsview.h b/gui/resultsview.h index 1dd27be7f..f10a50c47 100644 --- a/gui/resultsview.h +++ b/gui/resultsview.h @@ -26,7 +26,7 @@ #include "../src/errorlogger.h" #include "resultstree.h" #include "common.h" - +#include "ui_resultsview.h" /** * @brief Widget to show cppcheck progressbar and result @@ -37,7 +37,8 @@ class ResultsView : public QWidget Q_OBJECT public: - ResultsView(QSettings &settings, ApplicationList &list); + ResultsView(QWidget * parent = 0); + void Initialize(QSettings *settings, ApplicationList *list); virtual ~ResultsView(); /** @@ -104,6 +105,11 @@ public: */ bool HasResults() const; + /** + * @brief Save View's settings + * + */ + void SaveSettings(); signals: /** @@ -150,18 +156,6 @@ public slots: void ExpandAllResults(); protected: - /** - * @brief Tree to show cppcheck's results - * - */ - ResultsTree *mTree; - - /** - * @brief Progressbar to show cppcheck's progress - * - */ - QProgressBar *mProgress; - /** * @brief Have any errors been found */ @@ -172,6 +166,8 @@ protected: */ bool mShowNoErrorsMessage; + Ui::ResultsView mUI; + private: }; diff --git a/gui/resultsview.ui b/gui/resultsview.ui new file mode 100644 index 000000000..e56a480ba --- /dev/null +++ b/gui/resultsview.ui @@ -0,0 +1,63 @@ + + + ResultsView + + + + 0 + 0 + 459 + 357 + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + Results + + + + + + + 0 + 0 + + + + 24 + + + + + + + + 0 + 0 + + + + + + + + + ResultsTree + QTreeView +
resultstree.h
+
+
+ + +
diff --git a/gui/settingsdialog.cpp b/gui/settingsdialog.cpp index 56d2274e3..c744cbc28 100644 --- a/gui/settingsdialog.cpp +++ b/gui/settingsdialog.cpp @@ -24,14 +24,17 @@ #include #include #include "applicationdialog.h" +#include "common.h" -SettingsDialog::SettingsDialog(QSettings &programSettings, ApplicationList &list, +SettingsDialog::SettingsDialog(QSettings *programSettings, + ApplicationList *list, QWidget *parent) : QDialog(parent), mSettings(programSettings), - mApplications(list) + mApplications(list), + mTempApplications(new ApplicationList(this)) { - mTempApplications.Copy(list); + mTempApplications->Copy(list); //Create a layout for the settings dialog QVBoxLayout *dialoglayout = new QVBoxLayout(); @@ -69,7 +72,7 @@ SettingsDialog::SettingsDialog(QSettings &programSettings, ApplicationList &list //Number of jobs QHBoxLayout *jobsLayout = new QHBoxLayout(); - mJobs = new QLineEdit(programSettings.value(tr("Check threads"), 1).toString()); + mJobs = new QLineEdit(programSettings->value(SETTINGS_CHECK_THREADS, 1).toString()); mJobs->setValidator(new QIntValidator(1, 9999, this)); jobsLayout->addWidget(new QLabel(tr("Number of threads: "))); @@ -80,17 +83,17 @@ SettingsDialog::SettingsDialog(QSettings &programSettings, ApplicationList &list //Force mForce = AddCheckbox(layout, tr("Check all #ifdef configurations"), - tr("Check force"), + SETTINGS_CHECK_FORCE, false); mShowFullPath = AddCheckbox(layout, tr("Show full path of files"), - tr("Show full path"), + SETTINGS_SHOW_FULL_PATH, false); mShowNoErrorsMessage = AddCheckbox(layout, tr("Show \"No errors found\" message when no errors found"), - tr("Show no errors message"), + SETTINGS_SHOW_NO_ERRORS, true); layout->addStretch(); @@ -138,12 +141,12 @@ SettingsDialog::SettingsDialog(QSettings &programSettings, ApplicationList &list QVBoxLayout *reportlayout = new QVBoxLayout(); mSaveAllErrors = AddCheckbox(reportlayout, tr("Save all errors when creating report"), - tr("Save all errors"), + SETTINGS_SAVE_ALL_ERRORS, false); mSaveFullPath = AddCheckbox(reportlayout, tr("Save full path to files in reports"), - tr("Save full path"), + SETTINGS_SAVE_FULL_PATH, false); reportlayout->addStretch(); report->setLayout(reportlayout); @@ -181,21 +184,21 @@ QCheckBox* SettingsDialog::AddCheckbox(QVBoxLayout *layout, bool value) { QCheckBox *result = new QCheckBox(label); - result->setCheckState(BoolToCheckState(mSettings.value(settings, value).toBool())); + result->setCheckState(BoolToCheckState(mSettings->value(settings, value).toBool())); layout->addWidget(result); return result; } void SettingsDialog::LoadSettings() { - resize(mSettings.value("Check dialog width", 800).toInt(), - mSettings.value("Check dialog height", 600).toInt()); + resize(mSettings->value(SETTINGS_CHECK_DIALOG_WIDTH, 800).toInt(), + mSettings->value(SETTINGS_CHECK_DIALOG_HEIGHT, 600).toInt()); } void SettingsDialog::SaveSettings() { - mSettings.setValue("Check dialog width", size().width()); - mSettings.setValue("Check dialog height", size().height()); + mSettings->setValue(SETTINGS_CHECK_DIALOG_WIDTH, size().width()); + mSettings->setValue(SETTINGS_CHECK_DIALOG_HEIGHT, size().height()); } void SettingsDialog::SaveCheckboxValues() @@ -206,17 +209,17 @@ void SettingsDialog::SaveCheckboxValues() jobs = 1; } - mSettings.setValue("Check threads", jobs); - SaveCheckboxValue(mForce, "Check force"); - SaveCheckboxValue(mSaveAllErrors, "Save all errors"); - SaveCheckboxValue(mSaveFullPath, "Save full path"); - SaveCheckboxValue(mShowFullPath, "Show full path"); - SaveCheckboxValue(mShowNoErrorsMessage, "Show no errors message"); + mSettings->setValue(SETTINGS_CHECK_THREADS, jobs); + SaveCheckboxValue(mForce, SETTINGS_CHECK_FORCE); + SaveCheckboxValue(mSaveAllErrors, SETTINGS_SAVE_ALL_ERRORS); + SaveCheckboxValue(mSaveFullPath, SETTINGS_SAVE_FULL_PATH); + SaveCheckboxValue(mShowFullPath, SETTINGS_SHOW_FULL_PATH); + SaveCheckboxValue(mShowNoErrorsMessage, SETTINGS_SHOW_NO_ERRORS); } void SettingsDialog::SaveCheckboxValue(QCheckBox *box, const QString &name) { - mSettings.setValue(name, CheckStateToBool(box->checkState())); + mSettings->setValue(name, CheckStateToBool(box->checkState())); } void SettingsDialog::AddApplication() @@ -225,7 +228,7 @@ void SettingsDialog::AddApplication() if (dialog.exec() == QDialog::Accepted) { - mTempApplications.AddApplicationType(dialog.GetName(), dialog.GetPath()); + mTempApplications->AddApplicationType(dialog.GetName(), dialog.GetPath()); mListWidget->addItem(dialog.GetName()); } } @@ -238,7 +241,7 @@ void SettingsDialog::DeleteApplication() foreach(item, selected) { - mTempApplications.RemoveApplication(mListWidget->row(item)); + mTempApplications->RemoveApplication(mListWidget->row(item)); mListWidget->clear(); PopulateListWidget(); } @@ -252,13 +255,13 @@ void SettingsDialog::ModifyApplication() { int row = mListWidget->row(item); - ApplicationDialog dialog(mTempApplications.GetApplicationName(row), - mTempApplications.GetApplicationPath(row), + ApplicationDialog dialog(mTempApplications->GetApplicationName(row), + mTempApplications->GetApplicationPath(row), tr("Modify an application")); if (dialog.exec() == QDialog::Accepted) { - mTempApplications.SetApplicationType(row, dialog.GetName(), dialog.GetPath()); + mTempApplications->SetApplicationType(row, dialog.GetName(), dialog.GetPath()); item->setText(dialog.GetName()); } } @@ -270,7 +273,7 @@ void SettingsDialog::DefaultApplication() if (selected.size() > 0) { int index = mListWidget->row(selected[0]); - mTempApplications.MoveFirst(index); + mTempApplications->MoveFirst(index); mListWidget->clear(); PopulateListWidget(); } @@ -278,13 +281,13 @@ void SettingsDialog::DefaultApplication() void SettingsDialog::PopulateListWidget() { - for (int i = 0; i < mTempApplications.GetApplicationCount(); i++) + for (int i = 0; i < mTempApplications->GetApplicationCount(); i++) { - mListWidget->addItem(mTempApplications.GetApplicationName(i)); + mListWidget->addItem(mTempApplications->GetApplicationName(i)); } // If list contains items select first item - if (mTempApplications.GetApplicationCount()) + if (mTempApplications->GetApplicationCount()) { mListWidget->setCurrentRow(0); } @@ -292,7 +295,7 @@ void SettingsDialog::PopulateListWidget() void SettingsDialog::Ok() { - mApplications.Copy(mTempApplications); + mApplications->Copy(mTempApplications); accept(); } diff --git a/gui/settingsdialog.h b/gui/settingsdialog.h index ccd3ab1c3..8e88a191e 100644 --- a/gui/settingsdialog.h +++ b/gui/settingsdialog.h @@ -41,7 +41,9 @@ class SettingsDialog : public QDialog { Q_OBJECT public: - SettingsDialog(QSettings &programSettings, ApplicationList &list, QWidget *parent = 0); + SettingsDialog(QSettings *programSettings, + ApplicationList *list, + QWidget *parent = 0); virtual ~SettingsDialog(); /** @@ -216,20 +218,20 @@ protected: * @brief Settings * */ - QSettings &mSettings; + QSettings *mSettings; /** * @brief List of applications user has specified * */ - ApplicationList &mApplications; + ApplicationList *mApplications; /** * @brief Temporary list of applications * This will be copied to actual list of applications (mApplications) * when user clicks ok. */ - ApplicationList mTempApplications; + ApplicationList *mTempApplications; private: }; diff --git a/gui/threadhandler.cpp b/gui/threadhandler.cpp index 6be57aac7..0480ef692 100644 --- a/gui/threadhandler.cpp +++ b/gui/threadhandler.cpp @@ -158,11 +158,11 @@ void ThreadHandler::Initialize(ResultsView *view) void ThreadHandler::LoadSettings(QSettings &settings) { - SetThreadCount(settings.value("Check threads", 1).toInt()); + SetThreadCount(settings.value(SETTINGS_CHECK_THREADS, 1).toInt()); } void ThreadHandler::SaveSettings(QSettings &settings) { - settings.setValue("Check threads", mThreads.size()); + settings.setValue(SETTINGS_CHECK_THREADS, mThreads.size()); } diff --git a/gui/translationhandler.cpp b/gui/translationhandler.cpp new file mode 100644 index 000000000..e1340e207 --- /dev/null +++ b/gui/translationhandler.cpp @@ -0,0 +1,93 @@ +#include "translationhandler.h" + +#include +#include + +TranslationHandler::TranslationHandler(QObject *parent) : + QObject(parent), + mCurrentLanguage(-1), + mTranslator(new QTranslator(this)) +{ + //Add our default languages + mNames << QObject::tr("English") + << QObject::tr("Finnish") + << QObject::tr("Swedish") + << QObject::tr("German") + << QObject::tr("Russian"); + + mFiles << "cppcheck_en" + << "cppcheck_fi" + << "cppcheck_se" + << "cppcheck_de" + << "cppcheck_ru"; + + //Load english as a fallback language + QTranslator *english = new QTranslator(); + if (english->load("cppcheck_en")) + { + qApp->installTranslator(english); + } + else + { + qDebug() << "Failed to load english translation!"; + delete english; + } +} + +TranslationHandler::~TranslationHandler() +{ +} + +const QStringList TranslationHandler::GetNames() +{ + return mNames; +} + +const QStringList TranslationHandler::GetFiles() +{ + return mFiles; +} + +bool TranslationHandler::SetLanguage(const int index, QString &error) +{ + //If english is the language + if (index == 0) + { + //Just remove all extra translators + if (mTranslator) + { + qApp->removeTranslator(mTranslator); + } + + mCurrentLanguage = index; + return true; + } + + //Make sure the translator is otherwise valid + if (index >= mNames.size()) + { + error = QObject::tr("Incorrect language specified!"); + return false; + } + + + //Load the new language + if (!mTranslator->load(mFiles[index])) + { + error = QObject::tr("Failed to load language from file %1"); + error = error.arg(mFiles[index]); + return false; + } + + qApp->installTranslator(mTranslator); + + mCurrentLanguage = index; + + return true; +} + +int TranslationHandler::GetCurrentLanguage() const +{ + return mCurrentLanguage; +} + diff --git a/gui/translationhandler.h b/gui/translationhandler.h new file mode 100644 index 000000000..b3bb21714 --- /dev/null +++ b/gui/translationhandler.h @@ -0,0 +1,26 @@ +#ifndef TRANSLATIONHANDLER_H +#define TRANSLATIONHANDLER_H + +#include +#include +#include + +class TranslationHandler : QObject +{ + Q_OBJECT +public: + TranslationHandler(QObject *parent); + virtual ~TranslationHandler(); + const QStringList GetNames(); + const QStringList GetFiles(); + bool SetLanguage(const int index, QString &error); + int GetCurrentLanguage() const; +protected: + int mCurrentLanguage; + QStringList mNames; + QStringList mFiles; + QTranslator *mTranslator; +private: +}; + +#endif // TRANSLATIONHANDLER_H