GUI: Added DATADIR setting. Related with #5513
This commit is contained in:
parent
d939aa63a6
commit
f3622f729c
|
@ -40,9 +40,6 @@ win32 {
|
|||
}
|
||||
}
|
||||
|
||||
# Generate the translations before we embed them
|
||||
system("lrelease gui.pro")
|
||||
|
||||
RESOURCES = gui.qrc
|
||||
FORMS = about.ui \
|
||||
application.ui \
|
||||
|
|
19
gui/gui.qrc
19
gui/gui.qrc
|
@ -26,24 +26,5 @@
|
|||
<file>images/go-previous.png</file>
|
||||
<file>images/applications-development.png</file>
|
||||
<file>images/applications-system.png</file>
|
||||
|
||||
<file alias="cfg/gtk.cfg">../cfg/gtk.cfg</file>
|
||||
<file alias="cfg/qt.cfg">../cfg/qt.cfg</file>
|
||||
<file alias="cfg/posix.cfg">../cfg/posix.cfg</file>
|
||||
<file alias="cfg/std.cfg">../cfg/std.cfg</file>
|
||||
<file alias="cfg/windows.cfg">../cfg/windows.cfg</file>
|
||||
|
||||
<file>cppcheck_de.qm</file>
|
||||
<file>cppcheck_es.qm</file>
|
||||
<file>cppcheck_fi.qm</file>
|
||||
<file>cppcheck_fr.qm</file>
|
||||
<file>cppcheck_it.qm</file>
|
||||
<file>cppcheck_ja.qm</file>
|
||||
<file>cppcheck_ko.qm</file>
|
||||
<file>cppcheck_nl.qm</file>
|
||||
<file>cppcheck_ru.qm</file>
|
||||
<file>cppcheck_sr.qm</file>
|
||||
<file>cppcheck_sv.qm</file>
|
||||
<file>cppcheck_zh_CN.qm</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
|
23
gui/main.cpp
23
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 <file> Open given project file and start checking it\n"
|
||||
" -l <file> Open given results xml file\n"
|
||||
" -d <directory> 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 <file> Open given project file and start checking it\n"
|
||||
" -l <file> Open given results xml file\n"
|
||||
" -d <directory> Specify the directory that was checked to generate the results xml specified with -l\n"
|
||||
" -v, --version Show program version\n"
|
||||
" --data-dir=<directory> Specify directory where GUI datafiles are located (translations, cfg)");
|
||||
#if defined(_WIN32)
|
||||
QMessageBox msgBox(QMessageBox::Information,
|
||||
MainWindow::tr("Cppcheck GUI - Command line parameters"),
|
||||
|
|
|
@ -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=<directory> at the command line to specify where this file is located.").arg(!std ? "std.cfg" : "posix.cfg"));
|
||||
|
||||
if (result._jobs <= 1) {
|
||||
result._jobs = 1;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -21,6 +21,8 @@
|
|||
#include <QDebug>
|
||||
#include <QLocale>
|
||||
#include <QMessageBox>
|
||||
#include <QSettings>
|
||||
#include <QFileInfo>
|
||||
#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";
|
||||
|
|
Loading…
Reference in New Issue