2009-03-01 08:38:21 +01:00
|
|
|
/*
|
|
|
|
* Cppcheck - A tool for static C/C++ code analysis
|
2015-01-03 12:14:58 +01:00
|
|
|
* Copyright (C) 2007-2015 Daniel Marjamäki and 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
|
|
|
*/
|
|
|
|
|
|
|
|
#include <QApplication>
|
2011-05-13 09:09:17 +02:00
|
|
|
#include <QCoreApplication>
|
2009-06-06 09:51:50 +02:00
|
|
|
#include <QTextCodec>
|
2010-07-11 00:04:53 +02:00
|
|
|
#include <QMetaType>
|
2011-04-07 15:07:55 +02:00
|
|
|
#include <QStringList>
|
2013-03-01 19:11:27 +01:00
|
|
|
#include <QSettings>
|
2012-10-06 12:19:01 +02:00
|
|
|
#ifdef _WIN32
|
|
|
|
#include <QMessageBox>
|
|
|
|
#else
|
2011-04-07 15:07:55 +02:00
|
|
|
#include <iostream>
|
2012-10-06 12:19:01 +02:00
|
|
|
#endif
|
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 "aboutdialog.h"
|
|
|
|
#include "translationhandler.h"
|
2013-03-01 17:43:53 +01:00
|
|
|
|
2009-03-01 08:38:21 +01:00
|
|
|
|
2011-04-07 15:07:55 +02:00
|
|
|
void ShowUsage();
|
2013-03-01 17:43:53 +01:00
|
|
|
void ShowVersion();
|
2014-05-03 17:30:56 +02:00
|
|
|
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[])
|
|
|
|
{
|
|
|
|
QApplication app(argc, argv);
|
2011-04-07 15:07:55 +02:00
|
|
|
|
2013-07-13 09:16:15 +02:00
|
|
|
#if QT_VERSION < 0x050000
|
2013-03-01 19:11:27 +01:00
|
|
|
// Set codecs so that UTF-8 strings in sources are handled correctly.
|
2013-07-13 09:16:15 +02:00
|
|
|
// This is ONLY needed for Qt versions 4.x.
|
|
|
|
// Qt 5.x assumes UTF-8 by default.
|
2013-03-01 19:11:27 +01:00
|
|
|
QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
|
|
|
|
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
|
2013-07-13 09:16:15 +02:00
|
|
|
#endif
|
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..
|
2014-11-20 14:20:09 +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);
|
2013-03-01 19:11:27 +01:00
|
|
|
th->SetLanguage(settings->value(SETTINGS_LANGUAGE, th->SuggestLanguage()).toString());
|
|
|
|
|
2014-05-03 17:30:56 +02:00
|
|
|
if (!CheckArgs(app.arguments()))
|
2013-03-01 19:11:27 +01:00
|
|
|
return 0;
|
|
|
|
|
2009-05-28 10:32:32 +02:00
|
|
|
app.setWindowIcon(QIcon(":icon.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();
|
|
|
|
return app.exec();
|
|
|
|
}
|
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()
|
2014-05-03 17:30:56 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShowUsage()
|
|
|
|
{
|
2013-03-01 19:11:27 +01:00
|
|
|
QString helpMessage = MainWindow::tr(
|
|
|
|
"Cppcheck GUI.\n\n"
|
|
|
|
"Syntax:\n"
|
|
|
|
" cppcheck-gui [OPTIONS] [files or paths]\n\n"
|
|
|
|
"Options:\n"
|
2014-03-19 19:34:20 +01:00
|
|
|
" -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> Specify directory where GUI datafiles are located (translations, cfg)");
|
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
|
|
|
|
);
|
|
|
|
(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
|
|
|
|
|
|
|
void ShowVersion()
|
|
|
|
{
|
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
|
|
|
|
}
|