From 4365704f14e5fbb75360d459f6a288df61498162 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 24 Mar 2022 22:44:47 +0100 Subject: [PATCH] cppcheck.cfg: support custom productname and about message --- cli/cmdlineparser.cpp | 1 + cli/cppcheckexecutor.cpp | 16 ++++++++++------ gui/mainwindow.cpp | 24 ++++++++++++++++++++++-- gui/mainwindow.h | 3 +++ lib/settings.cpp | 4 ++++ lib/settings.h | 6 ++++++ 6 files changed, 46 insertions(+), 8 deletions(-) diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index 86421efbf..67524bc46 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -896,6 +896,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) else if (std::strcmp(argv[i], "--version") == 0) { mShowVersion = true; mExitAfterPrint = true; + mSettings->loadCppcheckCfg(); return true; } diff --git a/cli/cppcheckexecutor.cpp b/cli/cppcheckexecutor.cpp index f3128a466..784884f61 100644 --- a/cli/cppcheckexecutor.cpp +++ b/cli/cppcheckexecutor.cpp @@ -109,12 +109,16 @@ bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* c if (success) { if (parser.getShowVersion() && !parser.getShowErrorMessages()) { - const char * const extraVersion = CppCheck::extraVersion(); - if (*extraVersion != 0) - std::cout << "Cppcheck " << CppCheck::version() << " (" - << extraVersion << ')' << std::endl; - else - std::cout << "Cppcheck " << CppCheck::version() << std::endl; + if (!settings.cppcheckCfgProductName.empty()) { + std::cout << settings.cppcheckCfgProductName << std::endl; + } else { + const char * const extraVersion = CppCheck::extraVersion(); + if (*extraVersion != 0) + std::cout << "Cppcheck " << CppCheck::version() << " (" + << extraVersion << ')' << std::endl; + else + std::cout << "Cppcheck " << CppCheck::version() << std::endl; + } } if (parser.getShowErrorMessages()) { diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index c62040990..7696bc45c 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -72,6 +72,13 @@ MainWindow::MainWindow(TranslationHandler* th, QSettings* settings) : mExiting(false), mIsLogfileLoaded(false) { + { + Settings tempSettings; + tempSettings.loadCppcheckCfg(); + mCppcheckCfgProductName = QString::fromStdString(tempSettings.cppcheckCfgProductName); + mCppcheckCfgAbout = QString::fromStdString(tempSettings.cppcheckCfgAbout); + } + mUI->setupUi(this); mThread = new ThreadHandler(this); mUI->mResults->initialize(mSettings, mApplications, mThread); @@ -1353,8 +1360,18 @@ void MainWindow::toggleAllChecked(bool checked) void MainWindow::about() { - AboutDialog *dlg = new AboutDialog(CppCheck::version(), CppCheck::extraVersion(), this); - dlg->exec(); + if (!mCppcheckCfgAbout.isEmpty()) { + QMessageBox msg(QMessageBox::Information, + tr("About"), + mCppcheckCfgAbout, + QMessageBox::Ok, + this); + msg.exec(); + } + else { + AboutDialog *dlg = new AboutDialog(CppCheck::version(), CppCheck::extraVersion(), this); + dlg->exec(); + } } void MainWindow::showLicense() @@ -1442,6 +1459,9 @@ void MainWindow::formatAndSetTitle(const QString &text) nameWithVersion += " (" + extraVersion + ")"; } + if (!mCppcheckCfgProductName.isEmpty()) + nameWithVersion = mCppcheckCfgProductName; + QString title; if (text.isEmpty()) title = nameWithVersion; diff --git a/gui/mainwindow.h b/gui/mainwindow.h index 7f19045dc..de83d9e99 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -475,6 +475,9 @@ private: * List of MRU menu actions. Needs also to store the separator. */ QAction *mRecentProjectActs[MaxRecentProjects + 1]; + + QString mCppcheckCfgAbout; + QString mCppcheckCfgProductName; }; /// @} #endif // MAINWINDOW_H diff --git a/lib/settings.cpp b/lib/settings.cpp index 2f57d5a38..53f9486fc 100644 --- a/lib/settings.cpp +++ b/lib/settings.cpp @@ -94,6 +94,10 @@ void Settings::loadCppcheckCfg() if (!picojson::get_last_error().empty()) return; picojson::object obj = json.get(); + if (obj.count("productName") && obj["productName"].is()) + cppcheckCfgProductName = obj["productName"].get(); + if (obj.count("about") && obj["about"].is()) + cppcheckCfgAbout = obj["about"].get(); if (obj.count("addons") && obj["addons"].is()) { for (const picojson::value &v : obj["addons"].get()) { const std::string &s = v.get(); diff --git a/lib/settings.h b/lib/settings.h index 4b6dd4600..0b3abd7e4 100644 --- a/lib/settings.h +++ b/lib/settings.h @@ -153,6 +153,12 @@ public: /** @brief include paths excluded from checking the configuration */ std::set configExcludePaths; + /** cppcheck.cfg: Custom product name */ + std::string cppcheckCfgProductName; + + /** cppcheck.cfg: About text */ + std::string cppcheckCfgAbout; + /** @brief Are we running from DACA script? */ bool daca;