GUI: If DATADIR is not configured try to guess it. Try to use application path. Or look if there is a cppcheck path.
This commit is contained in:
parent
c6d2e0fae1
commit
51a6f154e0
|
@ -66,3 +66,17 @@ QString toFilterString(const QMap<QString,QString>& filters, bool addAllSupporte
|
||||||
|
|
||||||
return entries.join(";;");
|
return entries.join(";;");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString getDataDir()
|
||||||
|
{
|
||||||
|
QSettings settings;
|
||||||
|
const QString dataDir = settings.value("DATADIR", QString()).toString();
|
||||||
|
if (!dataDir.isEmpty())
|
||||||
|
return dataDir;
|
||||||
|
const QString appPath = QFileInfo(QCoreApplication::applicationFilePath()).canonicalPath();
|
||||||
|
if (QFileInfo(appPath + "/std.cfg").exists())
|
||||||
|
return appPath;
|
||||||
|
if (appPath.indexOf("/cppcheck/", 0, Qt::CaseInsensitive) > 0)
|
||||||
|
return appPath.left(appPath.indexOf("/cppcheck/", 0, Qt::CaseInsensitive) + 9);
|
||||||
|
return appPath;
|
||||||
|
}
|
||||||
|
|
|
@ -147,5 +147,10 @@ void setPath(const QString &type, const QString &value);
|
||||||
*/
|
*/
|
||||||
QString toFilterString(const QMap<QString,QString>& filters, bool addAllSupported=true, bool addAll=true);
|
QString toFilterString(const QMap<QString,QString>& filters, bool addAllSupported=true, bool addAll=true);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get configured data dir. If not configured then it will try to determine that from exe path.
|
||||||
|
*/
|
||||||
|
QString getDataDir();
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
#include "helpdialog.h"
|
#include "helpdialog.h"
|
||||||
#include "ui_helpdialog.h"
|
#include "ui_helpdialog.h"
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QHelpEngine>
|
#include <QHelpEngine>
|
||||||
#include <QHelpContentWidget>
|
#include <QHelpContentWidget>
|
||||||
#include <QHelpIndexWidget>
|
#include <QHelpIndexWidget>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QSettings>
|
|
||||||
|
|
||||||
void HelpBrowser::setHelpEngine(QHelpEngine *helpEngine)
|
void HelpBrowser::setHelpEngine(QHelpEngine *helpEngine)
|
||||||
{
|
{
|
||||||
|
@ -26,8 +26,7 @@ QVariant HelpBrowser::loadResource(int type, const QUrl &name)
|
||||||
|
|
||||||
static QString getHelpFile()
|
static QString getHelpFile()
|
||||||
{
|
{
|
||||||
QSettings settings;
|
const QString datadir = getDataDir();
|
||||||
const QString datadir = settings.value("DATADIR", QString()).toString();
|
|
||||||
|
|
||||||
QStringList paths;
|
QStringList paths;
|
||||||
paths << (datadir + "/help")
|
paths << (datadir + "/help")
|
||||||
|
|
|
@ -20,10 +20,10 @@
|
||||||
#include "ui_librarydialog.h"
|
#include "ui_librarydialog.h"
|
||||||
#include "libraryaddfunctiondialog.h"
|
#include "libraryaddfunctiondialog.h"
|
||||||
#include "libraryeditargdialog.h"
|
#include "libraryeditargdialog.h"
|
||||||
|
#include "common.h"
|
||||||
#include "path.h"
|
#include "path.h"
|
||||||
|
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QSettings>
|
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
#include <QInputDialog>
|
#include <QInputDialog>
|
||||||
|
@ -75,8 +75,7 @@ CppcheckLibraryData::Function *LibraryDialog::currentFunction()
|
||||||
|
|
||||||
void LibraryDialog::openCfg()
|
void LibraryDialog::openCfg()
|
||||||
{
|
{
|
||||||
const QSettings settings;
|
const QString datadir = getDataDir();
|
||||||
const QString datadir = settings.value("DATADIR",QString()).toString();
|
|
||||||
|
|
||||||
QString selectedFilter;
|
QString selectedFilter;
|
||||||
const QString filter(tr("Library files (*.cfg)"));
|
const QString filter(tr("Library files (*.cfg)"));
|
||||||
|
|
|
@ -54,13 +54,6 @@
|
||||||
static const QString OnlineHelpURL("http://cppcheck.net/manual.html");
|
static const QString OnlineHelpURL("http://cppcheck.net/manual.html");
|
||||||
static const QString compile_commands_json("compile_commands.json");
|
static const QString compile_commands_json("compile_commands.json");
|
||||||
|
|
||||||
static QString getDataDir(const QSettings *settings)
|
|
||||||
{
|
|
||||||
const QString dataDir = settings->value("DATADIR", QString()).toString();
|
|
||||||
const QString appPath = QFileInfo(QCoreApplication::applicationFilePath()).canonicalPath();
|
|
||||||
return dataDir.isEmpty() ? appPath : dataDir;
|
|
||||||
}
|
|
||||||
|
|
||||||
MainWindow::MainWindow(TranslationHandler* th, QSettings* settings) :
|
MainWindow::MainWindow(TranslationHandler* th, QSettings* settings) :
|
||||||
mSettings(settings),
|
mSettings(settings),
|
||||||
mApplications(new ApplicationList(this)),
|
mApplications(new ApplicationList(this)),
|
||||||
|
@ -76,7 +69,7 @@ MainWindow::MainWindow(TranslationHandler* th, QSettings* settings) :
|
||||||
{
|
{
|
||||||
mUI.setupUi(this);
|
mUI.setupUi(this);
|
||||||
mThread = new ThreadHandler(this);
|
mThread = new ThreadHandler(this);
|
||||||
mThread->setDataDir(getDataDir(settings));
|
mThread->setDataDir(getDataDir());
|
||||||
mUI.mResults->initialize(mSettings, mApplications, mThread);
|
mUI.mResults->initialize(mSettings, mApplications, mThread);
|
||||||
|
|
||||||
// Filter timer to delay filtering results slightly while typing
|
// Filter timer to delay filtering results slightly while typing
|
||||||
|
@ -786,7 +779,7 @@ Library::Error MainWindow::loadLibrary(Library *library, const QString &filename
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Try to load the library from the cfg subfolder..
|
// Try to load the library from the cfg subfolder..
|
||||||
const QString datadir = mSettings->value("DATADIR", QString()).toString();
|
const QString datadir = getDataDir();
|
||||||
if (!datadir.isEmpty()) {
|
if (!datadir.isEmpty()) {
|
||||||
ret = library->load(nullptr, (datadir+"/"+filename).toLatin1());
|
ret = library->load(nullptr, (datadir+"/"+filename).toLatin1());
|
||||||
if (ret.errorcode != Library::ErrorCode::FILE_NOT_FOUND)
|
if (ret.errorcode != Library::ErrorCode::FILE_NOT_FOUND)
|
||||||
|
@ -943,7 +936,7 @@ Settings MainWindow::getCppcheckSettings()
|
||||||
foreach (QString s, mProjectFile->getCheckUnknownFunctionReturn())
|
foreach (QString s, mProjectFile->getCheckUnknownFunctionReturn())
|
||||||
result.checkUnknownFunctionReturn.insert(s.toStdString());
|
result.checkUnknownFunctionReturn.insert(s.toStdString());
|
||||||
|
|
||||||
QString filesDir(getDataDir(mSettings));
|
QString filesDir(getDataDir());
|
||||||
const QString pythonCmd = mSettings->value(SETTINGS_PYTHON_PATH).toString();
|
const QString pythonCmd = mSettings->value(SETTINGS_PYTHON_PATH).toString();
|
||||||
foreach (QString addon, mProjectFile->getAddons()) {
|
foreach (QString addon, mProjectFile->getAddons()) {
|
||||||
QString addonFilePath = ProjectFile::getAddonFilePath(filesDir, addon);
|
QString addonFilePath = ProjectFile::getAddonFilePath(filesDir, addon);
|
||||||
|
|
|
@ -90,8 +90,7 @@ ProjectFileDialog::ProjectFileDialog(ProjectFile *projectFile, 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();
|
||||||
QSettings settings;
|
const QString datadir = getDataDir();
|
||||||
const QString datadir = settings.value("DATADIR",QString()).toString();
|
|
||||||
QStringList searchPaths;
|
QStringList searchPaths;
|
||||||
searchPaths << appPath << appPath + "/cfg" << inf.canonicalPath();
|
searchPaths << appPath << appPath + "/cfg" << inf.canonicalPath();
|
||||||
#ifdef FILESDIR
|
#ifdef FILESDIR
|
||||||
|
@ -332,7 +331,7 @@ void ProjectFileDialog::loadFromProjectFile(const ProjectFile *projectFile)
|
||||||
|
|
||||||
// Addons..
|
// Addons..
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
const QString dataDir = settings.value("DATADIR", QString()).toString();
|
const QString dataDir = getDataDir();
|
||||||
updateAddonCheckBox(mUI.mAddonThreadSafety, projectFile, dataDir, "threadsafety");
|
updateAddonCheckBox(mUI.mAddonThreadSafety, projectFile, dataDir, "threadsafety");
|
||||||
updateAddonCheckBox(mUI.mAddonY2038, projectFile, dataDir, "y2038");
|
updateAddonCheckBox(mUI.mAddonY2038, projectFile, dataDir, "y2038");
|
||||||
updateAddonCheckBox(mUI.mAddonCert, projectFile, dataDir, "cert");
|
updateAddonCheckBox(mUI.mAddonCert, projectFile, dataDir, "cert");
|
||||||
|
@ -837,6 +836,6 @@ void ProjectFileDialog::browseMisraFile()
|
||||||
|
|
||||||
mUI.mAddonMisra->setText("MISRA C 2012");
|
mUI.mAddonMisra->setText("MISRA C 2012");
|
||||||
mUI.mAddonMisra->setEnabled(true);
|
mUI.mAddonMisra->setEnabled(true);
|
||||||
updateAddonCheckBox(mUI.mAddonMisra, nullptr, settings.value("DATADIR", QString()).toString(), "misra");
|
updateAddonCheckBox(mUI.mAddonMisra, nullptr, getDataDir(), "misra");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,9 +21,9 @@
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QLocale>
|
#include <QLocale>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QSettings>
|
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include "translationhandler.h"
|
#include "translationhandler.h"
|
||||||
|
#include "common.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"
|
||||||
|
@ -111,10 +111,7 @@ bool TranslationHandler::setLanguage(const QString &code)
|
||||||
//Load the new language
|
//Load the new language
|
||||||
const QString appPath = QFileInfo(QCoreApplication::applicationFilePath()).canonicalPath();
|
const QString appPath = QFileInfo(QCoreApplication::applicationFilePath()).canonicalPath();
|
||||||
|
|
||||||
QSettings settings;
|
QString datadir = getDataDir();
|
||||||
QString datadir = settings.value("DATADIR").toString();
|
|
||||||
if (datadir.isEmpty())
|
|
||||||
datadir = appPath;
|
|
||||||
|
|
||||||
QString translationFile;
|
QString translationFile;
|
||||||
if (QFile::exists(datadir + "/lang/" + mTranslations[index].mFilename + ".qm"))
|
if (QFile::exists(datadir + "/lang/" + mTranslations[index].mFilename + ".qm"))
|
||||||
|
|
Loading…
Reference in New Issue