Skip to content

Commit 78d4318

Browse files
committed
Added the ability to add/remove/modify applications to open errors with.
Only the list of applications added, errors cant be opened yet.
1 parent ae7fc7f commit 78d4318

9 files changed

Lines changed: 470 additions & 15 deletions

gui/applicationdialog.cpp

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*
2+
* Cppcheck - A tool for static C/C++ code analysis
3+
* Copyright (C) 2007-2009 Daniel Marjamäki, Reijo Tomperi, Nicolas Le Cam,
4+
* Leandro Penz, Kimmo Varis, Vesa Pikki
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program. If not, see <http://www.gnu.org/licenses/
18+
*/
19+
20+
#include "applicationdialog.h"
21+
#include <QVBoxLayout>
22+
#include <QPushButton>
23+
#include <QHBoxLayout>
24+
#include <QLabel>
25+
#include <QFileDialog>
26+
#include <QDebug>
27+
28+
ApplicationDialog::ApplicationDialog(const QString &name,
29+
const QString &path,
30+
const QString &title)
31+
{
32+
QVBoxLayout *layout = new QVBoxLayout();
33+
mName = new QLineEdit(name);
34+
mPath = new QLineEdit(path);
35+
36+
QString guide = tr("Here you can add applications that can open error files.\n" \
37+
"Specify a name for the application and the application to execute.\n\n" \
38+
"The following texts are replaced with appriproate values when application is executed:\n" \
39+
"(file) - Filename containing the error\n" \
40+
"(line) - Line number containing the error\n" \
41+
"(message) - Error message\n" \
42+
"(severity) - Error severity\n" \
43+
"\n" \
44+
"Example opening a file with Kate and make Kate scroll to the corret line:\n" \
45+
"kate -l(line) (file)");
46+
47+
layout->addWidget(new QLabel(guide));
48+
49+
layout->addWidget(new QLabel(tr("Application's name")));
50+
layout->addWidget(mName);
51+
layout->addWidget(new QLabel(tr("Application to execute")));
52+
layout->addWidget(mPath);
53+
QPushButton *browse = new QPushButton(tr("Browse"));
54+
connect(browse,SIGNAL(clicked()), this, SLOT(Browse()));
55+
layout->addWidget(browse);
56+
57+
QPushButton *cancel = new QPushButton(tr("Cancel"));
58+
QPushButton *ok = new QPushButton(tr("Ok"));
59+
60+
//Add a layout for ok/cancel buttons
61+
QHBoxLayout *buttonLayout = new QHBoxLayout();
62+
buttonLayout->addWidget(ok);
63+
buttonLayout->addWidget(cancel);
64+
layout->addLayout(buttonLayout);
65+
66+
//Connect OK buttons
67+
connect(ok, SIGNAL(clicked()),
68+
this, SLOT(accept()));
69+
connect(cancel, SIGNAL(clicked()),
70+
this, SLOT(reject()));
71+
setLayout(layout);
72+
setWindowTitle(title);
73+
}
74+
75+
76+
ApplicationDialog::~ApplicationDialog()
77+
{
78+
//dtor
79+
}
80+
81+
82+
void ApplicationDialog::Browse()
83+
{
84+
QFileDialog dialog(this);
85+
dialog.setFileMode(QFileDialog::ExistingFiles);
86+
87+
if (dialog.exec())
88+
{
89+
QStringList list = dialog.selectedFiles();
90+
if (list.size() > 0)
91+
{
92+
mPath->setText(list[0]);
93+
}
94+
}
95+
}
96+
97+
QString ApplicationDialog::GetName()
98+
{
99+
return mName->text();
100+
}
101+
102+
103+
QString ApplicationDialog::GetPath()
104+
{
105+
return mPath->text();
106+
}

gui/applicationdialog.h

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Cppcheck - A tool for static C/C++ code analysis
3+
* Copyright (C) 2007-2009 Daniel Marjamäki, Reijo Tomperi, Nicolas Le Cam,
4+
* Leandro Penz, Kimmo Varis, Vesa Pikki
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program. If not, see <http://www.gnu.org/licenses/
18+
*/
19+
20+
#ifndef APPLICATIONDIALOG_H
21+
#define APPLICATIONDIALOG_H
22+
23+
#include <QDialog>
24+
#include <QLineEdit>
25+
26+
27+
class ApplicationDialog : public QDialog
28+
{
29+
Q_OBJECT
30+
public:
31+
ApplicationDialog(const QString &name,
32+
const QString &path,
33+
const QString &title);
34+
virtual ~ApplicationDialog();
35+
QString GetName();
36+
QString GetPath();
37+
protected slots:
38+
void Browse();
39+
protected:
40+
QLineEdit *mName;
41+
QLineEdit *mPath;
42+
private:
43+
};
44+
45+
#endif // APPLICATIONDIALOG_H

gui/applicationlist.cpp

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*
2+
* Cppcheck - A tool for static C/C++ code analysis
3+
* Copyright (C) 2007-2009 Daniel Marjamäki, Reijo Tomperi, Nicolas Le Cam,
4+
* Leandro Penz, Kimmo Varis, Vesa Pikki
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program. If not, see <http://www.gnu.org/licenses/
18+
*/
19+
20+
#include "applicationlist.h"
21+
#include <QStringList>
22+
23+
ApplicationList::ApplicationList()
24+
{
25+
//ctor
26+
}
27+
28+
ApplicationList::~ApplicationList()
29+
{
30+
//dtor
31+
}
32+
33+
void ApplicationList::LoadSettings(QSettings &programSettings)
34+
{
35+
36+
QStringList names = programSettings.value(tr("Application names"), QStringList()).toStringList();
37+
QStringList paths = programSettings.value(tr("Application paths"), QStringList()).toStringList();
38+
if (names.size() == paths.size()) {
39+
for(int i=0;i<names.size();i++) {
40+
AddApplicationType(names[i],paths[i]);
41+
}
42+
}
43+
}
44+
45+
void ApplicationList::SaveSettings(QSettings &programSettings)
46+
{
47+
QStringList names;
48+
QStringList paths;
49+
50+
for(int i=0;i<GetApplicationCount();i++) {
51+
names<<GetApplicationName(i);
52+
paths<<GetApplicationPath(i);
53+
}
54+
55+
programSettings.setValue(tr("Application names"),names);
56+
programSettings.setValue(tr("Application paths"),paths);
57+
58+
}
59+
60+
int ApplicationList::GetApplicationCount()
61+
{
62+
return mApplications.size();
63+
}
64+
65+
QString ApplicationList::GetApplicationName(const int index)
66+
{
67+
if (index >= 0 && index < mApplications.size())
68+
{
69+
return mApplications[index].Name;
70+
}
71+
72+
return QString();
73+
}
74+
75+
QString ApplicationList::GetApplicationPath(const int index)
76+
{
77+
if (index >= 0 && index < mApplications.size())
78+
{
79+
return mApplications[index].Path;
80+
}
81+
82+
return QString();
83+
84+
}
85+
86+
87+
void ApplicationList::SetApplicationType(const int index,
88+
const QString &name,
89+
const QString &path)
90+
{
91+
if (index >= 0 && index < mApplications.size())
92+
{
93+
mApplications[index].Name = name;
94+
mApplications[index].Path = path;
95+
}
96+
}
97+
98+
void ApplicationList::AddApplicationType(const QString &name, const QString &path)
99+
{
100+
ApplicationType type;
101+
type.Name = name;
102+
type.Path = path;
103+
mApplications<<type;
104+
}
105+
106+
void ApplicationList::RemoveApplication(const int index)
107+
{
108+
mApplications.removeAt(index);
109+
}
110+

gui/applicationlist.h

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Cppcheck - A tool for static C/C++ code analysis
3+
* Copyright (C) 2007-2009 Daniel Marjamäki, Reijo Tomperi, Nicolas Le Cam,
4+
* Leandro Penz, Kimmo Varis, Vesa Pikki
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program. If not, see <http://www.gnu.org/licenses/
18+
*/
19+
20+
#ifndef APPLICATIONLIST_H
21+
#define APPLICATIONLIST_H
22+
23+
#include <QObject>
24+
#include <QSettings>
25+
26+
27+
class ApplicationList : public QObject
28+
{
29+
public:
30+
typedef struct
31+
{
32+
QString Name;
33+
QString Path;
34+
}ApplicationType;
35+
36+
ApplicationList();
37+
virtual ~ApplicationList();
38+
39+
void LoadSettings(QSettings &programSettings);
40+
41+
void SaveSettings(QSettings &programSettings);
42+
43+
int GetApplicationCount();
44+
45+
QString GetApplicationName(const int index);
46+
47+
QString GetApplicationPath(const int index);
48+
49+
void SetApplicationType(const int index,
50+
const QString &name,
51+
const QString &path);
52+
53+
void AddApplicationType(const QString &name, const QString &path);
54+
55+
void RemoveApplication(const int index);
56+
protected:
57+
58+
59+
QList<ApplicationType> mApplications;
60+
private:
61+
};
62+
63+
#endif // APPLICATIONLIST_H

gui/gui.pro

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ HEADERS += mainwindow.h \
1818
settingsdialog.h \
1919
threadresult.h \
2020
threadhandler.h \
21+
applicationlist.h \
22+
applicationdialog.h \
2123
../src/checkautovariables.h \
2224
../src/checkdangerousfunctions.h \
2325
../src/checkheaders.h \
@@ -50,6 +52,8 @@ SOURCES += main.cpp \
5052
threadresult.cpp \
5153
threadhandler.cpp \
5254
settingsdialog.cpp \
55+
applicationlist.cpp \
56+
applicationdialog.cpp \
5357
../src/checkautovariables.cpp \
5458
../src/checkdangerousfunctions.cpp \
5559
../src/checkmemoryleak.cpp \

gui/mainwindow.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ void MainWindow::LoadSettings()
121121
mResults.ShowResults(SHOW_SECURITY, mActionShowSecurity.isChecked());
122122
mResults.ShowResults(SHOW_STYLE, mActionShowStyle.isChecked());
123123
mResults.ShowResults(SHOW_UNUSED, mActionShowUnused.isChecked());
124+
mApplications.LoadSettings(mSettings);
124125
}
125126

126127
void MainWindow::SaveSettings()
@@ -134,6 +135,7 @@ void MainWindow::SaveSettings()
134135
mSettings.setValue(tr("Show style"), mActionShowStyle.isChecked());
135136
mSettings.setValue(tr("Show unused"), mActionShowUnused.isChecked());
136137
mSettings.setValue(tr("Show errors"), mActionShowErrors.isChecked());
138+
mApplications.SaveSettings(mSettings);
137139
}
138140

139141

@@ -247,7 +249,7 @@ void MainWindow::CheckDone()
247249

248250
void MainWindow::ProgramSettings()
249251
{
250-
SettingsDialog dialog(mSettings);
252+
SettingsDialog dialog(mSettings,mApplications);
251253
if (dialog.exec() == QDialog::Accepted)
252254
{
253255
dialog.SaveCheckboxValues();

gui/mainwindow.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ protected slots:
161161
*/
162162
ThreadHandler mThread;
163163

164+
ApplicationList mApplications;
165+
164166
private:
165167
};
166168

0 commit comments

Comments
 (0)