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
|
RESOURCES = gui.qrc
|
||||||
FORMS = about.ui \
|
FORMS = about.ui \
|
||||||
application.ui \
|
application.ui \
|
||||||
|
|
19
gui/gui.qrc
19
gui/gui.qrc
|
@ -26,24 +26,5 @@
|
||||||
<file>images/go-previous.png</file>
|
<file>images/go-previous.png</file>
|
||||||
<file>images/applications-development.png</file>
|
<file>images/applications-development.png</file>
|
||||||
<file>images/applications-system.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>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|
15
gui/main.cpp
15
gui/main.cpp
|
@ -37,7 +37,7 @@
|
||||||
|
|
||||||
void ShowUsage();
|
void ShowUsage();
|
||||||
void ShowVersion();
|
void ShowVersion();
|
||||||
bool CheckArgs(const QStringList &args);
|
bool CheckArgs(const QStringList &args, QSettings * const settings);
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
@ -58,7 +58,7 @@ int main(int argc, char *argv[])
|
||||||
QSettings* settings = new QSettings("Cppcheck", "Cppcheck-GUI", &app);
|
QSettings* settings = new QSettings("Cppcheck", "Cppcheck-GUI", &app);
|
||||||
th->SetLanguage(settings->value(SETTINGS_LANGUAGE, th->SuggestLanguage()).toString());
|
th->SetLanguage(settings->value(SETTINGS_LANGUAGE, th->SuggestLanguage()).toString());
|
||||||
|
|
||||||
if (!CheckArgs(app.arguments()))
|
if (!CheckArgs(app.arguments(), settings))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
app.setWindowIcon(QIcon(":icon.png"));
|
app.setWindowIcon(QIcon(":icon.png"));
|
||||||
|
@ -73,7 +73,7 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
// Check only arguments needing action before GUI is shown.
|
// Check only arguments needing action before GUI is shown.
|
||||||
// Rest of the arguments are handled in MainWindow::HandleCLIParams()
|
// 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")) {
|
if (args.contains("-h") || args.contains("--help")) {
|
||||||
ShowUsage();
|
ShowUsage();
|
||||||
|
@ -83,6 +83,12 @@ bool CheckArgs(const QStringList &args)
|
||||||
ShowVersion();
|
ShowVersion();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
foreach(const QString arg, args) {
|
||||||
|
if (arg.startsWith("--data-dir=")) {
|
||||||
|
settings->setValue("DATADIR", arg.mid(11));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,7 +103,8 @@ void ShowUsage()
|
||||||
" -p <file> Open given project file and start checking it\n"
|
" -p <file> Open given project file and start checking it\n"
|
||||||
" -l <file> Open given results xml file\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"
|
" -d <directory> Specify the directory that was checked to generate the results xml specified with -l\n"
|
||||||
" -v, --version Show program version");
|
" -v, --version Show program version\n"
|
||||||
|
" --data-dir=<directory> Specify directory where GUI datafiles are located (translations, cfg)");
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
QMessageBox msgBox(QMessageBox::Information,
|
QMessageBox msgBox(QMessageBox::Information,
|
||||||
MainWindow::tr("Cppcheck GUI - Command line parameters"),
|
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..
|
// Try to load the library from the application folder..
|
||||||
QString path = QFileInfo(QCoreApplication::applicationFilePath()).canonicalPath();
|
const QString appPath = QFileInfo(QCoreApplication::applicationFilePath()).canonicalPath();
|
||||||
if (library->load(NULL, (path+"/"+filename).toLatin1()))
|
if (library->load(NULL, (appPath+"/"+filename).toLatin1()))
|
||||||
|
return true;
|
||||||
|
if (library->load(NULL, (appPath+"/cfg/"+filename).toLatin1()))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// Try to load the library from the cfg subfolder..
|
// Try to load the library from the cfg subfolder..
|
||||||
path = path + "/cfg";
|
const QString datadir = mSettings->value("DATADIR", QString()).toString();
|
||||||
if (library->load(NULL, (path+"/"+filename).toLatin1()))
|
if (!datadir.isEmpty()) {
|
||||||
|
if (library->load(NULL, (datadir+"/"+filename).toLatin1()))
|
||||||
return true;
|
return true;
|
||||||
|
if (library->load(NULL, (datadir+"/cfg/"+filename).toLatin1()))
|
||||||
// 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()))
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -613,7 +611,7 @@ Settings MainWindow::GetCppcheckSettings()
|
||||||
posix = LoadLibrary(&result.library, "posix.cfg");
|
posix = LoadLibrary(&result.library, "posix.cfg");
|
||||||
|
|
||||||
if (!std || !posix)
|
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) {
|
if (result._jobs <= 1) {
|
||||||
result._jobs = 1;
|
result._jobs = 1;
|
||||||
|
|
|
@ -46,10 +46,15 @@ ProjectFileDialog::ProjectFileDialog(const QString &path, QWidget *parent)
|
||||||
// Checkboxes for the libraries..
|
// Checkboxes for the libraries..
|
||||||
const QString applicationFilePath = QCoreApplication::applicationFilePath();
|
const QString applicationFilePath = QCoreApplication::applicationFilePath();
|
||||||
const QString appPath = QFileInfo(applicationFilePath).canonicalPath();
|
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;
|
QStringList libs;
|
||||||
for (int i = 0; i < sizeof(searchPaths) / sizeof(searchPaths[0]); i++) {
|
foreach(const QString sp, searchPaths) {
|
||||||
QDir dir(searchPaths[i]);
|
QDir dir(sp);
|
||||||
dir.setSorting(QDir::Name);
|
dir.setSorting(QDir::Name);
|
||||||
dir.setNameFilters(QStringList("*.cfg"));
|
dir.setNameFilters(QStringList("*.cfg"));
|
||||||
dir.setFilter(QDir::Files | QDir::NoDotAndDotDot);
|
dir.setFilter(QDir::Files | QDir::NoDotAndDotDot);
|
||||||
|
|
|
@ -21,6 +21,8 @@
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QLocale>
|
#include <QLocale>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
#include <QSettings>
|
||||||
|
#include <QFileInfo>
|
||||||
#include "translationhandler.h"
|
#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"
|
// 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);
|
mTranslator = new QTranslator(this);
|
||||||
|
|
||||||
//Load the new language
|
//Load the new language
|
||||||
QString translationFile = "lang/" + mTranslations[index].mFilename;
|
const QString appPath = QFileInfo(QCoreApplication::applicationFilePath()).canonicalPath();
|
||||||
|
|
||||||
if (!QFile::exists(translationFile + ".qm")) {
|
QSettings settings;
|
||||||
translationFile = ":/" + mTranslations[index].mFilename;
|
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) {
|
if (!mTranslator->load(translationFile) && !failure) {
|
||||||
translationFile += ".qm";
|
translationFile += ".qm";
|
||||||
|
|
Loading…
Reference in New Issue