gui: Check CFGDIR if it's defined.

For quite a while, cppcheck-gui hasn't shown any of the standard
library packages on my Gentoo system. It turns out that cppcheck-gui
doesn't use CFGDIR, but it does use a DATADIR variable stored in
QSettings. Problem is, DATADIR isn't set unless you manually specify
--data-dir, which isn't very intuitive.

This commit adds CFGDIR to the default list of cfg paths if the
CFGDIR macro is defined during the build.
This commit is contained in:
David Korth 2016-10-15 19:08:04 -04:00 committed by PKEuS
parent 2d24d5ce01
commit 310226bb6b
2 changed files with 20 additions and 0 deletions

View File

@ -657,6 +657,19 @@ Library::Error MainWindow::LoadLibrary(Library *library, QString filename)
if (ret.errorcode != Library::ErrorCode::FILE_NOT_FOUND)
return ret;
#ifdef CFGDIR
// Try to load the library from CFGDIR..
const QString cfgdir = CFGDIR;
if (!cfgdir.isEmpty()) {
ret = library->load(NULL, (cfgdir+"/"+filename).toLatin1());
if (ret.errorcode != Library::ErrorCode::FILE_NOT_FOUND)
return ret;
ret = library->load(NULL, (cfgdir+"/cfg/"+filename).toLatin1());
if (ret.errorcode != Library::ErrorCode::FILE_NOT_FOUND)
return ret;
}
#endif
// Try to load the library from the cfg subfolder..
const QString datadir = mSettings->value("DATADIR", QString()).toString();
if (!datadir.isEmpty()) {

View File

@ -48,9 +48,16 @@ ProjectFileDialog::ProjectFileDialog(const QString &path, QWidget *parent)
const QString applicationFilePath = QCoreApplication::applicationFilePath();
const QString appPath = QFileInfo(applicationFilePath).canonicalPath();
QSettings settings;
#ifdef CFGDIR
const QString cfgdir = CFGDIR;
#endif
const QString datadir = settings.value("DATADIR",QString()).toString();
QStringList searchPaths;
searchPaths << appPath << appPath + "/cfg" << inf.canonicalPath();
#ifdef CFGDIR
if (!cfgdir.isEmpty())
searchPaths << cfgdir << cfgdir + "/cfg";
#endif
if (!datadir.isEmpty())
searchPaths << datadir << datadir + "/cfg";
QStringList libs;