diff --git a/gui/gui.pro b/gui/gui.pro index 85e3ff06f..880b5c782 100644 --- a/gui/gui.pro +++ b/gui/gui.pro @@ -40,9 +40,6 @@ win32 { } } -# Generate the translations before we embed them -system("lrelease gui.pro") - RESOURCES = gui.qrc FORMS = about.ui \ application.ui \ diff --git a/gui/gui.qrc b/gui/gui.qrc index 35c3167d4..c6d12b84c 100644 --- a/gui/gui.qrc +++ b/gui/gui.qrc @@ -26,24 +26,5 @@ images/go-previous.png images/applications-development.png images/applications-system.png - - ../cfg/gtk.cfg - ../cfg/qt.cfg - ../cfg/posix.cfg - ../cfg/std.cfg - ../cfg/windows.cfg - - cppcheck_de.qm - cppcheck_es.qm - cppcheck_fi.qm - cppcheck_fr.qm - cppcheck_it.qm - cppcheck_ja.qm - cppcheck_ko.qm - cppcheck_nl.qm - cppcheck_ru.qm - cppcheck_sr.qm - cppcheck_sv.qm - cppcheck_zh_CN.qm diff --git a/gui/main.cpp b/gui/main.cpp index b34d46d98..7f5ce2219 100644 --- a/gui/main.cpp +++ b/gui/main.cpp @@ -37,7 +37,7 @@ void ShowUsage(); void ShowVersion(); -bool CheckArgs(const QStringList &args); +bool CheckArgs(const QStringList &args, QSettings * const settings); int main(int argc, char *argv[]) { @@ -58,7 +58,7 @@ int main(int argc, char *argv[]) QSettings* settings = new QSettings("Cppcheck", "Cppcheck-GUI", &app); th->SetLanguage(settings->value(SETTINGS_LANGUAGE, th->SuggestLanguage()).toString()); - if (!CheckArgs(app.arguments())) + if (!CheckArgs(app.arguments(), settings)) return 0; app.setWindowIcon(QIcon(":icon.png")); @@ -73,7 +73,7 @@ int main(int argc, char *argv[]) // Check only arguments needing action before GUI is shown. // Rest of the arguments are handled in MainWindow::HandleCLIParams() -bool CheckArgs(const QStringList &args) +bool CheckArgs(const QStringList &args, QSettings * const settings) { if (args.contains("-h") || args.contains("--help")) { ShowUsage(); @@ -83,6 +83,12 @@ bool CheckArgs(const QStringList &args) ShowVersion(); return false; } + foreach(const QString arg, args) { + if (arg.startsWith("--data-dir=")) { + settings->setValue("DATADIR", arg.mid(11)); + return false; + } + } return true; } @@ -93,11 +99,12 @@ void ShowUsage() "Syntax:\n" " cppcheck-gui [OPTIONS] [files or paths]\n\n" "Options:\n" - " -h, --help Print this help\n" - " -p Open given project file and start checking it\n" - " -l Open given results xml file\n" - " -d Specify the directory that was checked to generate the results xml specified with -l\n" - " -v, --version Show program version"); + " -h, --help Print this help\n" + " -p Open given project file and start checking it\n" + " -l Open given results xml file\n" + " -d Specify the directory that was checked to generate the results xml specified with -l\n" + " -v, --version Show program version\n" + " --data-dir= Specify directory where GUI datafiles are located (translations, cfg)"); #if defined(_WIN32) QMessageBox msgBox(QMessageBox::Information, MainWindow::tr("Cppcheck GUI - Command line parameters"), diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 6ba9c1397..482ef76ca 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -523,20 +523,18 @@ bool MainWindow::LoadLibrary(Library *library, QString filename) } // Try to load the library from the application folder.. - QString path = QFileInfo(QCoreApplication::applicationFilePath()).canonicalPath(); - if (library->load(NULL, (path+"/"+filename).toLatin1())) + const QString appPath = QFileInfo(QCoreApplication::applicationFilePath()).canonicalPath(); + if (library->load(NULL, (appPath+"/"+filename).toLatin1())) + return true; + if (library->load(NULL, (appPath+"/cfg/"+filename).toLatin1())) return true; // Try to load the library from the cfg subfolder.. - path = path + "/cfg"; - if (library->load(NULL, (path+"/"+filename).toLatin1())) - return true; - - // Try to load resource.. - QFile f(":/cfg/" + filename); - if (f.open(QIODevice::ReadOnly | QIODevice::Text)) { - QString data = f.readAll(); - if (library->loadxmldata(data.toLatin1(), data.length())) + const QString datadir = mSettings->value("DATADIR", QString()).toString(); + if (!datadir.isEmpty()) { + if (library->load(NULL, (datadir+"/"+filename).toLatin1())) + return true; + if (library->load(NULL, (datadir+"/cfg/"+filename).toLatin1())) return true; } @@ -613,7 +611,7 @@ Settings MainWindow::GetCppcheckSettings() posix = LoadLibrary(&result.library, "posix.cfg"); if (!std || !posix) - QMessageBox::warning(this, tr("Error"), tr("Failed to load %1. Your Cppcheck installation is broken.").arg(!std ? "std.cfg" : "posix.cfg")); + QMessageBox::warning(this, tr("Error"), tr("Failed to load %1. Your Cppcheck installation is broken. You can use --data-dir= at the command line to specify where this file is located.").arg(!std ? "std.cfg" : "posix.cfg")); if (result._jobs <= 1) { result._jobs = 1; diff --git a/gui/projectfiledialog.cpp b/gui/projectfiledialog.cpp index e8565faf8..24307be14 100644 --- a/gui/projectfiledialog.cpp +++ b/gui/projectfiledialog.cpp @@ -46,10 +46,15 @@ ProjectFileDialog::ProjectFileDialog(const QString &path, QWidget *parent) // Checkboxes for the libraries.. const QString applicationFilePath = QCoreApplication::applicationFilePath(); const QString appPath = QFileInfo(applicationFilePath).canonicalPath(); - const QString searchPaths[] = { ":/cfg", appPath, appPath + "/cfg", inf.canonicalPath() }; + QSettings settings; + const QString datadir = settings.value("DATADIR",QString()).toString(); + QStringList searchPaths; + searchPaths << appPath << appPath + "/cfg" << inf.canonicalPath(); + if (!datadir.isEmpty()) + searchPaths << datadir << datadir + "/cfg"; QStringList libs; - for (int i = 0; i < sizeof(searchPaths) / sizeof(searchPaths[0]); i++) { - QDir dir(searchPaths[i]); + foreach(const QString sp, searchPaths) { + QDir dir(sp); dir.setSorting(QDir::Name); dir.setNameFilters(QStringList("*.cfg")); dir.setFilter(QDir::Files | QDir::NoDotAndDotDot); diff --git a/gui/translationhandler.cpp b/gui/translationhandler.cpp index 86eb294eb..97ed15067 100644 --- a/gui/translationhandler.cpp +++ b/gui/translationhandler.cpp @@ -21,6 +21,8 @@ #include #include #include +#include +#include #include "translationhandler.h" // Provide own translations for standard buttons. This (garbage) code is needed to enforce them to appear in .ts files even after "lupdate gui.pro" @@ -97,11 +99,22 @@ bool TranslationHandler::SetLanguage(const QString &code) mTranslator = new QTranslator(this); //Load the new language - QString translationFile = "lang/" + mTranslations[index].mFilename; + const QString appPath = QFileInfo(QCoreApplication::applicationFilePath()).canonicalPath(); - if (!QFile::exists(translationFile + ".qm")) { - translationFile = ":/" + mTranslations[index].mFilename; - } + QSettings settings; + QString datadir = settings.value("DATADIR").toString(); + if (datadir.isEmpty()) + datadir = appPath; + + QString translationFile; + if (QFile::exists(datadir + "/lang/" + mTranslations[index].mFilename + ".qm")) + translationFile = datadir + "/lang/" + mTranslations[index].mFilename + ".qm"; + + else if (QFile::exists(datadir + "/" + mTranslations[index].mFilename + ".qm")) + translationFile = datadir + "/" + mTranslations[index].mFilename + ".qm"; + + else + translationFile = appPath + "/" + mTranslations[index].mFilename + ".qm"; if (!mTranslator->load(translationFile) && !failure) { translationFile += ".qm";