diff --git a/gui/applicationdialog.cpp b/gui/applicationdialog.cpp new file mode 100644 index 000000000..35510174c --- /dev/null +++ b/gui/applicationdialog.cpp @@ -0,0 +1,106 @@ +/* + * Cppcheck - A tool for static C/C++ code analysis + * Copyright (C) 2007-2009 Daniel Marjamäki, Reijo Tomperi, Nicolas Le Cam, + * Leandro Penz, Kimmo Varis, Vesa Pikki + * + * 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 + * along with this program. If not, see +#include +#include +#include +#include +#include + +ApplicationDialog::ApplicationDialog(const QString &name, +const QString &path, +const QString &title) +{ + QVBoxLayout *layout = new QVBoxLayout(); + mName = new QLineEdit(name); + mPath = new QLineEdit(path); + + QString guide = tr("Here you can add applications that can open error files.\n" \ + "Specify a name for the application and the application to execute.\n\n" \ + "The following texts are replaced with appriproate values when application is executed:\n" \ + "(file) - Filename containing the error\n" \ + "(line) - Line number containing the error\n" \ + "(message) - Error message\n" \ + "(severity) - Error severity\n" \ + "\n" \ + "Example opening a file with Kate and make Kate scroll to the corret line:\n" \ + "kate -l(line) (file)"); + + layout->addWidget(new QLabel(guide)); + + layout->addWidget(new QLabel(tr("Application's name"))); + layout->addWidget(mName); + layout->addWidget(new QLabel(tr("Application to execute"))); + layout->addWidget(mPath); + QPushButton *browse = new QPushButton(tr("Browse")); + connect(browse,SIGNAL(clicked()), this, SLOT(Browse())); + layout->addWidget(browse); + + QPushButton *cancel = new QPushButton(tr("Cancel")); + QPushButton *ok = new QPushButton(tr("Ok")); + + //Add a layout for ok/cancel buttons + QHBoxLayout *buttonLayout = new QHBoxLayout(); + buttonLayout->addWidget(ok); + buttonLayout->addWidget(cancel); + layout->addLayout(buttonLayout); + + //Connect OK buttons + connect(ok, SIGNAL(clicked()), + this, SLOT(accept())); + connect(cancel, SIGNAL(clicked()), + this, SLOT(reject())); + setLayout(layout); + setWindowTitle(title); +} + + +ApplicationDialog::~ApplicationDialog() +{ + //dtor +} + + +void ApplicationDialog::Browse() +{ + QFileDialog dialog(this); + dialog.setFileMode(QFileDialog::ExistingFiles); + + if (dialog.exec()) + { + QStringList list = dialog.selectedFiles(); + if (list.size() > 0) + { + mPath->setText(list[0]); + } + } +} + +QString ApplicationDialog::GetName() +{ + return mName->text(); +} + + +QString ApplicationDialog::GetPath() +{ + return mPath->text(); +} diff --git a/gui/applicationdialog.h b/gui/applicationdialog.h new file mode 100644 index 000000000..25d88eafa --- /dev/null +++ b/gui/applicationdialog.h @@ -0,0 +1,45 @@ +/* + * Cppcheck - A tool for static C/C++ code analysis + * Copyright (C) 2007-2009 Daniel Marjamäki, Reijo Tomperi, Nicolas Le Cam, + * Leandro Penz, Kimmo Varis, Vesa Pikki + * + * 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 + * along with this program. If not, see +#include + + +class ApplicationDialog : public QDialog +{ + Q_OBJECT +public: + ApplicationDialog(const QString &name, + const QString &path, + const QString &title); + virtual ~ApplicationDialog(); + QString GetName(); + QString GetPath(); +protected slots: + void Browse(); +protected: + QLineEdit *mName; + QLineEdit *mPath; +private: +}; + +#endif // APPLICATIONDIALOG_H diff --git a/gui/applicationlist.cpp b/gui/applicationlist.cpp new file mode 100644 index 000000000..f10a96074 --- /dev/null +++ b/gui/applicationlist.cpp @@ -0,0 +1,110 @@ +/* + * Cppcheck - A tool for static C/C++ code analysis + * Copyright (C) 2007-2009 Daniel Marjamäki, Reijo Tomperi, Nicolas Le Cam, + * Leandro Penz, Kimmo Varis, Vesa Pikki + * + * 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 + * along with this program. If not, see + +ApplicationList::ApplicationList() +{ + //ctor +} + +ApplicationList::~ApplicationList() +{ + //dtor +} + +void ApplicationList::LoadSettings(QSettings &programSettings) +{ + + QStringList names = programSettings.value(tr("Application names"), QStringList()).toStringList(); + QStringList paths = programSettings.value(tr("Application paths"), QStringList()).toStringList(); + if (names.size() == paths.size()) { + for(int i=0;i= 0 && index < mApplications.size()) + { + return mApplications[index].Name; + } + + return QString(); +} + +QString ApplicationList::GetApplicationPath(const int index) +{ + if (index >= 0 && index < mApplications.size()) + { + return mApplications[index].Path; + } + + return QString(); + +} + + +void ApplicationList::SetApplicationType(const int index, + const QString &name, + const QString &path) +{ + if (index >= 0 && index < mApplications.size()) + { + mApplications[index].Name = name; + mApplications[index].Path = path; + } +} + +void ApplicationList::AddApplicationType(const QString &name, const QString &path) +{ + ApplicationType type; + type.Name = name; + type.Path = path; + mApplications< +#include + + +class ApplicationList : public QObject +{ +public: + typedef struct + { + QString Name; + QString Path; + }ApplicationType; + + ApplicationList(); + virtual ~ApplicationList(); + + void LoadSettings(QSettings &programSettings); + + void SaveSettings(QSettings &programSettings); + + int GetApplicationCount(); + + QString GetApplicationName(const int index); + + QString GetApplicationPath(const int index); + + void SetApplicationType(const int index, + const QString &name, + const QString &path); + + void AddApplicationType(const QString &name, const QString &path); + + void RemoveApplication(const int index); +protected: + + + QList mApplications; +private: +}; + +#endif // APPLICATIONLIST_H diff --git a/gui/gui.pro b/gui/gui.pro index f305ccc59..4c13a4dc6 100644 --- a/gui/gui.pro +++ b/gui/gui.pro @@ -18,6 +18,8 @@ HEADERS += mainwindow.h \ settingsdialog.h \ threadresult.h \ threadhandler.h \ + applicationlist.h \ + applicationdialog.h \ ../src/checkautovariables.h \ ../src/checkdangerousfunctions.h \ ../src/checkheaders.h \ @@ -50,6 +52,8 @@ SOURCES += main.cpp \ threadresult.cpp \ threadhandler.cpp \ settingsdialog.cpp \ + applicationlist.cpp \ + applicationdialog.cpp \ ../src/checkautovariables.cpp \ ../src/checkdangerousfunctions.cpp \ ../src/checkmemoryleak.cpp \ diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index c714a97ee..6999f8c75 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -121,6 +121,7 @@ void MainWindow::LoadSettings() mResults.ShowResults(SHOW_SECURITY, mActionShowSecurity.isChecked()); mResults.ShowResults(SHOW_STYLE, mActionShowStyle.isChecked()); mResults.ShowResults(SHOW_UNUSED, mActionShowUnused.isChecked()); + mApplications.LoadSettings(mSettings); } void MainWindow::SaveSettings() @@ -134,6 +135,7 @@ void MainWindow::SaveSettings() mSettings.setValue(tr("Show style"), mActionShowStyle.isChecked()); mSettings.setValue(tr("Show unused"), mActionShowUnused.isChecked()); mSettings.setValue(tr("Show errors"), mActionShowErrors.isChecked()); + mApplications.SaveSettings(mSettings); } @@ -247,7 +249,7 @@ void MainWindow::CheckDone() void MainWindow::ProgramSettings() { - SettingsDialog dialog(mSettings); + SettingsDialog dialog(mSettings,mApplications); if (dialog.exec() == QDialog::Accepted) { dialog.SaveCheckboxValues(); diff --git a/gui/mainwindow.h b/gui/mainwindow.h index 62eeac076..dfe457ebb 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -161,6 +161,8 @@ protected: */ ThreadHandler mThread; + ApplicationList mApplications; + private: }; diff --git a/gui/settingsdialog.cpp b/gui/settingsdialog.cpp index 0180699be..c0d517a2e 100644 --- a/gui/settingsdialog.cpp +++ b/gui/settingsdialog.cpp @@ -21,18 +21,49 @@ #include "settingsdialog.h" #include #include +#include +#include "applicationdialog.h" -SettingsDialog::SettingsDialog(QSettings &programSettings) : - mSettings(programSettings) +SettingsDialog::SettingsDialog(QSettings &programSettings, ApplicationList &list) : + mSettings(programSettings), + mApplications(list) { + //Create a layout for the settings dialog + QVBoxLayout *dialoglayout = new QVBoxLayout(); + + //Create a tabwidget and add it to dialogs layout + QTabWidget *tabs = new QTabWidget(); + dialoglayout->addWidget(tabs); + + //Add ok and cancel buttons QPushButton *cancel = new QPushButton(tr("Cancel")); QPushButton *ok = new QPushButton(tr("Ok")); - //Main layout + //Add a layout for ok/cancel buttons + QHBoxLayout *buttonLayout = new QHBoxLayout(); + + buttonLayout->addWidget(ok); + buttonLayout->addWidget(cancel); + //Add button layout to the main dialog layout + dialoglayout->addLayout(buttonLayout); + + //Connect OK buttons + connect(ok, SIGNAL(clicked()), + this, SLOT(accept())); + connect(cancel, SIGNAL(clicked()), + this, SLOT(reject())); + + + //Begin adding tabs and tab content + + //General tab + QWidget *general = new QWidget(); + tabs->addTab(general,tr("General")); + + + //layout for general tab QVBoxLayout *layout = new QVBoxLayout(); - //Layout for ok/cancel buttons - QHBoxLayout *buttonLayout = new QHBoxLayout(); //Number of jobs QHBoxLayout *jobsLayout = new QHBoxLayout(); @@ -48,21 +79,41 @@ SettingsDialog::SettingsDialog(QSettings &programSettings) : tr("Check force"), false); + general->setLayout(layout); + + //Add tab for setting user startable applications + QWidget *applications = new QWidget(); + tabs->addTab(applications,tr("Applications")); + + QVBoxLayout *appslayout = new QVBoxLayout(); + mListWidget = new QListWidget(); + appslayout->addWidget(mListWidget); + applications->setLayout(appslayout); + + QPushButton *add = new QPushButton(tr("Add application")); + appslayout->addWidget(add); + connect(add, SIGNAL(clicked()), + this, SLOT(AddApplication())); + + QPushButton *del = new QPushButton(tr("Delete application")); + appslayout->addWidget(del); + connect(del, SIGNAL(clicked()), + this, SLOT(DeleteApplication())); + + QPushButton *modify = new QPushButton(tr("Modify application")); + appslayout->addWidget(modify); + connect(modify, SIGNAL(clicked()), + this, SLOT(ModifyApplication())); + + connect(mListWidget,SIGNAL(itemDoubleClicked(QListWidgetItem *)), + this,SLOT(ModifyApplication())); - - buttonLayout->addWidget(ok); - buttonLayout->addWidget(cancel); - layout->addLayout(buttonLayout); + PopulateListWidget(); - connect(ok, SIGNAL(clicked()), - this, SLOT(accept())); - connect(cancel, SIGNAL(clicked()), - this, SLOT(reject())); - + setLayout(dialoglayout); setWindowTitle(tr("Settings")); - setLayout(layout); LoadSettings(); } @@ -121,3 +172,58 @@ void SettingsDialog::SaveCheckboxValue(QCheckBox *box, const QString &name) { mSettings.setValue(name, CheckStateToBool(box->checkState())); } + +void SettingsDialog::AddApplication() +{ + ApplicationDialog dialog("","",tr("Add a new application")); + + if (dialog.exec() == QDialog::Accepted) + { + mApplications.AddApplicationType(dialog.GetName(),dialog.GetPath()); + mListWidget->addItem(dialog.GetName()); + } +} + +void SettingsDialog::DeleteApplication() +{ + + QList selected = mListWidget->selectedItems(); + QListWidgetItem *item = 0; + + foreach(item,selected) + { + qDebug()<row(item)); + mListWidget->clear(); + PopulateListWidget(); + } +} + +void SettingsDialog::ModifyApplication() +{ + QList selected = mListWidget->selectedItems(); + QListWidgetItem *item = 0; + foreach(item,selected) + { + int row = mListWidget->row(item); + + ApplicationDialog dialog(mApplications.GetApplicationName(row), + mApplications.GetApplicationPath(row), + tr("Modify an application")); + + if (dialog.exec() == QDialog::Accepted) + { + mApplications.SetApplicationType(row,dialog.GetName(),dialog.GetPath()); + item->setText(dialog.GetName()); + } + } +} + +void SettingsDialog::PopulateListWidget() +{ + for (int i=0;iaddItem(mApplications.GetApplicationName(i)); + } +} + diff --git a/gui/settingsdialog.h b/gui/settingsdialog.h index 078ecb613..3c5591469 100644 --- a/gui/settingsdialog.h +++ b/gui/settingsdialog.h @@ -28,7 +28,10 @@ #include #include #include +#include "applicationlist.h" +#include +#include /** @@ -37,11 +40,18 @@ */ class SettingsDialog : public QDialog { + Q_OBJECT public: - SettingsDialog(QSettings &programSettings); + SettingsDialog(QSettings &programSettings, ApplicationList &list); virtual ~SettingsDialog(); void SaveCheckboxValues(); + +protected slots: + void AddApplication(); + void DeleteApplication(); + void ModifyApplication(); protected: + void PopulateListWidget(); /** * @brief Load saved values * Loads dialog size and column widths. @@ -106,12 +116,19 @@ protected: */ QCheckBox *mForce; + /** + * @brief List of all applications that can be started when right clicking + * an error + */ + QListWidget *mListWidget; + /** * @brief Settings * */ QSettings &mSettings; + ApplicationList &mApplications; private: };