2009-03-01 08:38:21 +01:00
|
|
|
/*
|
|
|
|
* Cppcheck - A tool for static C/C++ code analysis
|
2022-02-05 11:45:17 +01:00
|
|
|
* Copyright (C) 2007-2022 Cppcheck team.
|
2009-03-01 08:38:21 +01:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2009-09-27 17:08:31 +02:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2009-03-01 08:38:21 +01:00
|
|
|
*/
|
|
|
|
|
2013-03-01 19:11:27 +01:00
|
|
|
#include "cppcheck.h"
|
|
|
|
#include "common.h"
|
2009-03-01 08:38:21 +01:00
|
|
|
#include "mainwindow.h"
|
2010-07-14 13:24:46 +02:00
|
|
|
#include "erroritem.h"
|
2013-03-01 19:11:27 +01:00
|
|
|
#include "translationhandler.h"
|
2013-03-01 17:43:53 +01:00
|
|
|
|
2022-02-02 16:17:28 +01:00
|
|
|
#ifdef _WIN32
|
|
|
|
#include "aboutdialog.h"
|
|
|
|
|
|
|
|
#include <QMessageBox>
|
|
|
|
#else
|
|
|
|
#include <iostream>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QCoreApplication>
|
|
|
|
#include <QStringList>
|
|
|
|
#include <QSettings>
|
|
|
|
|
2009-03-01 08:38:21 +01:00
|
|
|
|
2015-01-05 01:20:33 +01:00
|
|
|
static void ShowUsage();
|
|
|
|
static void ShowVersion();
|
|
|
|
static bool CheckArgs(const QStringList &args);
|
2011-04-07 15:07:55 +02:00
|
|
|
|
2009-03-01 08:38:21 +01:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2017-12-08 09:16:34 +01:00
|
|
|
|
2017-12-05 21:51:58 +01:00
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
|
|
|
|
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
2018-10-22 19:07:02 +02:00
|
|
|
QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
|
2017-12-05 21:51:58 +01:00
|
|
|
#endif
|
2017-12-08 09:16:34 +01:00
|
|
|
|
2009-03-01 08:38:21 +01:00
|
|
|
QApplication app(argc, argv);
|
2011-04-07 15:07:55 +02:00
|
|
|
|
2011-05-13 09:09:17 +02:00
|
|
|
QCoreApplication::setOrganizationName("Cppcheck");
|
|
|
|
QCoreApplication::setApplicationName("Cppcheck-GUI");
|
|
|
|
|
2013-03-01 19:11:27 +01:00
|
|
|
QSettings* settings = new QSettings("Cppcheck", "Cppcheck-GUI", &app);
|
2014-05-01 14:21:17 +02:00
|
|
|
|
|
|
|
// Set data dir..
|
2015-12-17 15:40:54 +01:00
|
|
|
foreach (const QString arg, app.arguments()) {
|
2014-05-01 14:21:17 +02:00
|
|
|
if (arg.startsWith("--data-dir=")) {
|
|
|
|
settings->setValue("DATADIR", arg.mid(11));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TranslationHandler* th = new TranslationHandler(&app);
|
2017-07-28 13:43:49 +02:00
|
|
|
th->setLanguage(settings->value(SETTINGS_LANGUAGE, th->suggestLanguage()).toString());
|
2013-03-01 19:11:27 +01:00
|
|
|
|
2021-01-02 19:10:25 +01:00
|
|
|
if (!CheckArgs(QApplication::arguments()))
|
2013-03-01 19:11:27 +01:00
|
|
|
return 0;
|
|
|
|
|
2021-01-02 19:10:25 +01:00
|
|
|
QApplication::setWindowIcon(QIcon(":cppcheck-gui.png"));
|
2009-05-25 15:00:42 +02:00
|
|
|
|
2010-07-11 00:04:53 +02:00
|
|
|
// Register this metatype that is used to transfer error info
|
2010-07-14 13:24:46 +02:00
|
|
|
qRegisterMetaType<ErrorItem>("ErrorItem");
|
2010-07-11 00:04:53 +02:00
|
|
|
|
2013-03-01 19:11:27 +01:00
|
|
|
MainWindow window(th, settings);
|
2009-03-01 08:38:21 +01:00
|
|
|
window.show();
|
2021-01-02 19:10:25 +01:00
|
|
|
return QApplication::exec();
|
2009-03-01 08:38:21 +01:00
|
|
|
}
|
2011-04-07 15:07:55 +02:00
|
|
|
|
|
|
|
// Check only arguments needing action before GUI is shown.
|
|
|
|
// Rest of the arguments are handled in MainWindow::HandleCLIParams()
|
2015-01-05 01:20:33 +01:00
|
|
|
static bool CheckArgs(const QStringList &args)
|
2011-04-07 15:07:55 +02:00
|
|
|
{
|
2011-10-13 20:53:06 +02:00
|
|
|
if (args.contains("-h") || args.contains("--help")) {
|
2011-04-07 15:07:55 +02:00
|
|
|
ShowUsage();
|
|
|
|
return false;
|
|
|
|
}
|
2013-03-01 17:43:53 +01:00
|
|
|
if (args.contains("-v") || args.contains("--version")) {
|
|
|
|
ShowVersion();
|
|
|
|
return false;
|
|
|
|
}
|
2011-04-07 15:07:55 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-01-05 01:20:33 +01:00
|
|
|
static void ShowUsage()
|
2011-04-07 15:07:55 +02:00
|
|
|
{
|
2013-03-01 19:11:27 +01:00
|
|
|
QString helpMessage = MainWindow::tr(
|
2021-08-07 20:51:18 +02:00
|
|
|
"Cppcheck GUI.\n\n"
|
|
|
|
"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\n"
|
|
|
|
" --data-dir=<directory> This option is for installation scripts so they can configure the directory where\n"
|
|
|
|
" datafiles are located (translations, cfg). The GUI is not started when this option\n"
|
|
|
|
" is used.");
|
2012-09-26 20:26:46 +02:00
|
|
|
#if defined(_WIN32)
|
|
|
|
QMessageBox msgBox(QMessageBox::Information,
|
2013-03-01 19:11:27 +01:00
|
|
|
MainWindow::tr("Cppcheck GUI - Command line parameters"),
|
2012-09-26 20:26:46 +02:00
|
|
|
helpMessage,
|
|
|
|
QMessageBox::Ok
|
2021-08-07 20:51:18 +02:00
|
|
|
);
|
2012-09-26 20:26:46 +02:00
|
|
|
(void)msgBox.exec();
|
|
|
|
#else
|
2013-03-01 19:11:27 +01:00
|
|
|
std::cout << helpMessage.toStdString() << std::endl;
|
2012-09-26 20:26:46 +02:00
|
|
|
#endif
|
2011-04-07 15:07:55 +02:00
|
|
|
}
|
2013-03-01 17:43:53 +01:00
|
|
|
|
2015-01-05 01:20:33 +01:00
|
|
|
static void ShowVersion()
|
2013-03-01 17:43:53 +01:00
|
|
|
{
|
2013-03-01 19:11:27 +01:00
|
|
|
#if defined(_WIN32)
|
|
|
|
AboutDialog *dlg = new AboutDialog(CppCheck::version(), CppCheck::extraVersion(), 0);
|
|
|
|
dlg->exec();
|
|
|
|
delete dlg;
|
|
|
|
#else
|
2013-03-01 17:43:53 +01:00
|
|
|
std::string versionMessage("Cppcheck ");
|
|
|
|
versionMessage += CppCheck::version();
|
|
|
|
const char * extraVersion = CppCheck::extraVersion();
|
|
|
|
if (*extraVersion != 0)
|
|
|
|
versionMessage += std::string(" (") + extraVersion + ")";
|
|
|
|
|
|
|
|
std::cout << versionMessage << std::endl;
|
|
|
|
#endif
|
|
|
|
}
|