diff --git a/gui/applicationdialog.cpp b/gui/applicationdialog.cpp index 77d55ced1..97a73cd54 100644 --- a/gui/applicationdialog.cpp +++ b/gui/applicationdialog.cpp @@ -24,6 +24,7 @@ #include #include #include +#include ApplicationDialog::ApplicationDialog(const QString &name, @@ -66,7 +67,7 @@ ApplicationDialog::ApplicationDialog(const QString &name, //Connect OK buttons connect(ok, SIGNAL(clicked()), - this, SLOT(accept())); + this, SLOT(Ok())); connect(cancel, SIGNAL(clicked()), this, SLOT(reject())); setLayout(layout); @@ -105,3 +106,15 @@ QString ApplicationDialog::GetPath() { return mPath->text(); } + +void ApplicationDialog::Ok() +{ + if (mName->text().isEmpty() || mPath->text().isEmpty()) { + QMessageBox msgBox; + msgBox.setText("You must specify a name and a path for the application!"); + msgBox.exec(); + } else { + accept(); + } +} + diff --git a/gui/applicationdialog.h b/gui/applicationdialog.h index 027cba12d..7c32667d6 100644 --- a/gui/applicationdialog.h +++ b/gui/applicationdialog.h @@ -61,6 +61,7 @@ public: */ QString GetPath(); protected slots: + void Ok(); /** * @brief Slot to browse for an application diff --git a/gui/applicationlist.cpp b/gui/applicationlist.cpp index ec51845c7..4accf7c47 100644 --- a/gui/applicationlist.cpp +++ b/gui/applicationlist.cpp @@ -100,6 +100,10 @@ void ApplicationList::SetApplicationType(const int index, void ApplicationList::AddApplicationType(const QString &name, const QString &path) { + if (name.isEmpty() || path.isEmpty()) { + return; + } + ApplicationType type; type.Name = name; type.Path = path; diff --git a/gui/checkthread.cpp b/gui/checkthread.cpp index 1a4ecb5db..edc9943b1 100644 --- a/gui/checkthread.cpp +++ b/gui/checkthread.cpp @@ -23,7 +23,7 @@ CheckThread::CheckThread(ThreadResult &result) : mResult(result), - mCppCheck(result) + mCppcheck(result) { //ctor } @@ -35,7 +35,7 @@ CheckThread::~CheckThread() void CheckThread::Check(Settings settings) { - mCppCheck.settings(settings); + mCppcheck.settings(settings); start(); } @@ -47,9 +47,9 @@ void CheckThread::run() while (!file.isEmpty()) { qDebug() << "Checking file" << file; - mCppCheck.addFile(file.toStdString()); - mCppCheck.check(); - mCppCheck.clearFiles(); + mCppcheck.addFile(file.toStdString()); + mCppcheck.check(); + mCppcheck.clearFiles(); emit FileChecked(file); file = mResult.GetNextFile(); diff --git a/gui/checkthread.h b/gui/checkthread.h index 0f1c8e7c9..44b0f18e5 100644 --- a/gui/checkthread.h +++ b/gui/checkthread.h @@ -63,10 +63,10 @@ signals: protected: ThreadResult &mResult; /** - * @brief CppCheck itself + * @brief Cppcheck itself * */ - CppCheck mCppCheck; + CppCheck mCppcheck; private: }; diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index ef5dccefa..23f39600e 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -23,24 +23,26 @@ #include #include #include +#include #include "../src/filelister.h" - +#include "../src/cppcheckexecutor.h" MainWindow::MainWindow() : - mSettings(tr("CppCheck"), tr("CppCheck-GUI")), + mSettings(tr("Cppcheck"), tr("Cppcheck-GUI")), mActionExit(tr("E&xit"), this), mActionCheckFiles(tr("&Check files(s)"), this), mActionClearResults(tr("Clear &results"), this), mActionReCheck(tr("Recheck files"), this), mActionCheckDirectory(tr("Check &directory"), this), mActionSettings(tr("&Settings"), this), - mActionShowAll(tr("Show &more errors"), this), + mActionShowAll(tr("show possible false positives"), this), mActionShowSecurity(tr("Show &security errors"), this), mActionShowStyle(tr("Show s&tyle errors"), this), mActionShowUnused(tr("Show errors on &unused functions"), this), mActionShowErrors(tr("Show &common errors"), this), mActionShowCheckAll(tr("Check all"), this), mActionShowUncheckAll(tr("Uncheck all"), this), + mActionAbout(tr("About"), this), mResults(mSettings, mApplications) { QMenu *menu = menuBar()->addMenu(tr("&File")); @@ -69,6 +71,9 @@ MainWindow::MainWindow() : QMenu *menuprogram = menuBar()->addMenu(tr("&Program")); menuprogram->addAction(&mActionSettings); + QMenu *menuHelp = menuBar()->addMenu(tr("&Help")); + menuHelp->addAction(&mActionAbout); + setCentralWidget(&mResults); @@ -87,10 +92,13 @@ MainWindow::MainWindow() : connect(&mActionShowUncheckAll, SIGNAL(triggered()), this, SLOT(UncheckAll())); connect(&mActionReCheck, SIGNAL(triggered()), this, SLOT(ReCheck())); + + connect(&mActionAbout, SIGNAL(triggered()), this, SLOT(About())); + connect(&mThread, SIGNAL(Done()), this, SLOT(CheckDone())); LoadSettings(); mThread.Initialize(&mResults); - setWindowTitle(tr("CppCheck")); + setWindowTitle(tr("Cppcheck")); } MainWindow::~MainWindow() @@ -161,7 +169,7 @@ void MainWindow::DoCheckFiles(QFileDialog::FileMode mode) mThread.SetFiles(RemoveUnacceptedFiles(fileNames)); mSettings.setValue(tr("Check path"), dialog.directory().absolutePath()); EnableCheckButtons(false); - mThread.Check(GetCppCheckSettings(), false); + mThread.Check(GetCppcheckSettings(), false); } } @@ -175,7 +183,7 @@ void MainWindow::CheckDirectory() DoCheckFiles(QFileDialog::DirectoryOnly); } -Settings MainWindow::GetCppCheckSettings() +Settings MainWindow::GetCppcheckSettings() { Settings result; result._debug = false; @@ -188,6 +196,11 @@ Settings MainWindow::GetCppCheckSettings() result._unusedFunctions = true; result._security = true; result._jobs = mSettings.value(tr("Check threads"), 1).toInt(); + + if (result._jobs <= 0) { + result._jobs = 1; + } + return result; } @@ -248,7 +261,7 @@ void MainWindow::ReCheck() { ClearResults(); EnableCheckButtons(false); - mThread.Check(GetCppCheckSettings(), true); + mThread.Check(GetCppcheckSettings(), true); } void MainWindow::ClearResults() @@ -316,3 +329,23 @@ void MainWindow::ToggleAllChecked(bool checked) mActionShowErrors.setChecked(checked); ShowErrors(checked); } + +void MainWindow::About() +{ + //TODO make a "GetVersionNumber" function to core cppcheck + CppCheckExecutor exec; + CppCheck check(exec); + const char *argv[] = {"","--version"}; + QString version = check.parseFromArgs(2, argv).c_str(); + version.replace("Cppcheck ",""); + + QMessageBox msgBox; + msgBox.setWindowTitle(tr("About...")); + msgBox.setText(QString("Cppcheck - A tool for static C/C++ code analysis.\nVersion %1\n\n" \ + "This program is licensed under the terms\n" \ + "of the GNU General Public License version 3\n" \ + "Available online under:\n" \ + "http://www.gnu.org/licenses/gpl-3.0.html\n\nSee AUTHORS file for the list of developers." \ + ).arg(version)); + msgBox.exec(); +} diff --git a/gui/mainwindow.h b/gui/mainwindow.h index 587e3b807..aac0e676d 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -114,6 +114,12 @@ public slots: */ void ProgramSettings(); + /** + * @brief Slot to open program's about dialog + * + */ + void About(); + protected slots: /** @@ -155,7 +161,7 @@ protected: * * @return Default cppcheck settings */ - Settings GetCppCheckSettings(); + Settings GetCppcheckSettings(); /** * @brief Removes all unaccepted (by cppcheck core) files from the list @@ -262,6 +268,12 @@ protected: */ QAction mActionShowUncheckAll; + /** + * @brief Action show about dialog + * + */ + QAction mActionAbout; + /** diff --git a/gui/resultstree.cpp b/gui/resultstree.cpp index f0556470e..c07bf8fcf 100644 --- a/gui/resultstree.cpp +++ b/gui/resultstree.cpp @@ -348,7 +348,7 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e) void ResultsTree::StartApplication(QStandardItem *target, int application) { - if (target && application >= 0 && application < mApplications.GetApplicationCount()) + if (target && application >= 0 && application < mApplications.GetApplicationCount() && target->parent()) { QVariantMap data = target->data().toMap(); diff --git a/gui/settingsdialog.cpp b/gui/settingsdialog.cpp index c9837c677..6d6f8cfc6 100644 --- a/gui/settingsdialog.cpp +++ b/gui/settingsdialog.cpp @@ -68,9 +68,13 @@ SettingsDialog::SettingsDialog(QSettings &programSettings, ApplicationList &list //Number of jobs QHBoxLayout *jobsLayout = new QHBoxLayout(); mJobs = new QLineEdit(programSettings.value(tr("Check threads"), 1).toString()); + mJobs->setValidator(new QIntValidator(1,9999,this)); + jobsLayout->addWidget(new QLabel(tr("Number of threads: "))); jobsLayout->addWidget(mJobs); - mJobs->setValidator(new QIntValidator(this)); + + + layout->addLayout(jobsLayout); //Force @@ -169,7 +173,12 @@ void SettingsDialog::SaveSettings() void SettingsDialog::SaveCheckboxValues() { - mSettings.setValue(tr("Check threads"), mJobs->text().toInt()); + int jobs = mJobs->text().toInt(); + if (jobs <= 0) { + jobs = 1; + } + + mSettings.setValue(tr("Check threads"), jobs); SaveCheckboxValue(mForce, tr("Check force")); } @@ -197,7 +206,6 @@ void SettingsDialog::DeleteApplication() foreach(item, selected) { - qDebug() << item; mApplications.RemoveApplication(mListWidget->row(item)); mListWidget->clear(); PopulateListWidget();