Skip to content

Commit 9134523

Browse files
committed
GUI: Refactoring application definition.
Using Application class as method parameters instead of separate application attributes.
1 parent f82021d commit 9134523

File tree

5 files changed

+77
-101
lines changed

5 files changed

+77
-101
lines changed

gui/application.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,26 @@
2424
/**
2525
* @brief A class containing information of the application to execute.
2626
*
27+
* Each application has a name and a path. Name is displayed to the user
28+
* and has no other meaning. It isn't used to start the application.
29+
* Path contains the full path to the application containing the executable name.
30+
* Parameters contains the command line arguments for the executable.
31+
*
32+
* User can also specify certain predefined strings to parameters. These strings
33+
* will be replaced with appropriate values concerning the error. Strings are:
34+
* (file) - Filename containing the error
35+
* (line) - Line number containing the error
36+
* (message) - Error message
37+
* (severity) - Error severity
38+
*
39+
* Example opening a file with Kate and make Kate scroll to the correct line.
40+
* Executable: kate
41+
* Parameters: -l(line) (file)
2742
*/
2843
class Application
2944
{
3045
public:
46+
Application() { }
3147
Application(const QString &name, const QString &path, const QString &params);
3248

3349
/**

gui/applicationlist.cpp

Lines changed: 37 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <stdlib.h>
2525
#include "common.h"
2626
#include "applicationlist.h"
27+
#include "application.h"
2728

2829

2930
ApplicationList::ApplicationList(QObject *parent) :
@@ -63,14 +64,22 @@ bool ApplicationList::LoadSettings(QSettings *programSettings)
6364
// use as default for gnome environments
6465
if (QFileInfo("/usr/bin/gedit").isExecutable())
6566
{
66-
AddApplication("gedit", "/usr/bin/gedit", "+(line) (file)");
67+
Application app;
68+
app.setName("gedit");
69+
app.setPath("/usr/bin/gedit");
70+
app.setParameters("+(line) (file)");
71+
AddApplication(app);
6772
defapp = 0;
6873
break;
6974
}
7075
// use as default for kde environments
7176
if (QFileInfo("/usr/bin/kate").isExecutable())
7277
{
73-
AddApplication("kate", "/usr/bin/kate", "-l(line) (file)");
78+
Application app;
79+
app.setName("kate");
80+
app.setPath("/usr/bin/kate");
81+
app.setParameters("-l(line) (file)");
82+
AddApplication(app);
7483
defapp = 0;
7584
break;
7685
}
@@ -86,7 +95,10 @@ bool ApplicationList::LoadSettings(QSettings *programSettings)
8695
if (names.size() > 0 && (names.size() == paths.size()))
8796
{
8897
for (int i = 0; i < names.size(); i++)
89-
AddApplication(names[i], paths[i], params[i]);
98+
{
99+
const Application app(names[i], paths[i], params[i]);
100+
AddApplication(app);
101+
}
90102

91103
if (defapp == -1)
92104
mDefaultApplicationIndex = 0;
@@ -106,9 +118,10 @@ void ApplicationList::SaveSettings(QSettings *programSettings)
106118

107119
for (int i = 0; i < GetApplicationCount(); i++)
108120
{
109-
names << GetApplicationName(i);
110-
paths << GetApplicationPath(i);
111-
params << GetApplicationParameters(i);
121+
Application app = GetApplication(i);
122+
names << app.getName();
123+
paths << app.getPath();
124+
params << app.getParameters();
112125
}
113126

114127
programSettings->setValue(SETTINGS_APPLICATION_NAMES, names);
@@ -123,58 +136,30 @@ int ApplicationList::GetApplicationCount() const
123136
return mApplications.size();
124137
}
125138

126-
QString ApplicationList::GetApplicationName(const int index) const
127-
{
128-
if (index >= 0 && index < mApplications.size())
129-
{
130-
return mApplications[index].getName();
131-
}
132-
133-
return QString();
134-
}
135-
136-
QString ApplicationList::GetApplicationPath(const int index) const
139+
Application ApplicationList::GetApplication(const int index) const
137140
{
138141
if (index >= 0 && index < mApplications.size())
139142
{
140-
return mApplications[index].getPath();
143+
return mApplications[index];
141144
}
142145

143-
return QString();
146+
return Application(QString(), QString(), QString());
144147
}
145148

146-
QString ApplicationList::GetApplicationParameters(const int index) const
149+
void ApplicationList::SetApplication(int index, const Application &app)
147150
{
148151
if (index >= 0 && index < mApplications.size())
149152
{
150-
return mApplications[index].getParameters();
151-
}
152-
153-
return QString();
154-
}
155-
156-
void ApplicationList::SetApplication(const int index,
157-
const QString &name,
158-
const QString &path,
159-
const QString &parameters)
160-
{
161-
if (index >= 0 && index < mApplications.size())
162-
{
163-
Application app(name, path, parameters);
164153
mApplications.replace(index, app);
165154
}
166155
}
167156

168-
void ApplicationList::AddApplication(const QString &name,
169-
const QString &path,
170-
const QString &parameters)
157+
void ApplicationList::AddApplication(const Application &app)
171158
{
172-
if (name.isEmpty() || path.isEmpty())
159+
if (app.getName().isEmpty() || app.getPath().isEmpty())
173160
{
174161
return;
175162
}
176-
177-
Application app(name, path, parameters);
178163
mApplications << app;
179164
}
180165

@@ -201,8 +186,8 @@ void ApplicationList::Copy(const ApplicationList *list)
201186
Clear();
202187
for (int i = 0; i < list->GetApplicationCount(); i++)
203188
{
204-
AddApplication(list->GetApplicationName(i), list->GetApplicationPath(i),
205-
list->GetApplicationParameters(i));
189+
const Application app = list->GetApplication(i);
190+
AddApplication(app);
206191
}
207192
mDefaultApplicationIndex = list->GetDefaultApplication();
208193
}
@@ -219,15 +204,23 @@ bool ApplicationList::FindDefaultWindowsEditor()
219204
const QString notepadppPath = appPath + "\\Notepad++\\notepad++.exe";
220205
if (QFileInfo(notepadppPath).isExecutable())
221206
{
222-
AddApplication("Notepad++", "\"" + notepadppPath + "\"", "-n(line) (file)");
207+
Application app;
208+
app.setName("Notepad++");
209+
app.setPath("\"" + notepadppPath + "\"");
210+
app.setParameters("-n(line) (file)");
211+
AddApplication(app);
223212
return true;
224213
}
225214

226215
const QString windowsPath(getenv("windir"));
227216
const QString notepadPath = windowsPath + "\\system32\\notepad.exe";
228217
if (QFileInfo(notepadPath).isExecutable())
229218
{
230-
AddApplication("Notepad", notepadPath, "(file)");
219+
Application app;
220+
app.setName("Notepad");
221+
app.setPath(notepadPath);
222+
app.setParameters("(file)");
223+
AddApplication(app);
231224
return true;
232225
}
233226
return false;

gui/applicationlist.h

Lines changed: 6 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,7 @@
2828

2929

3030
/**
31-
* @brief List of applications user has specified to open errors with
32-
* Each application has a name and a path. Name is displayed to the user
33-
* and has no other meaning. It isn't used to start the application.
34-
* Path contains the path to the application as well as the executable itself and
35-
* any possible argument user might want to specify.
36-
*
37-
* User can also specify certain predefined strings to path. These strings
38-
* will be replaced with appropriate values concerning the error. Strings are:
39-
* (file) - Filename containing the error
40-
* (line) - Line number containing the error
41-
* (message) - Error message
42-
* (severity) - Error severity
43-
*
44-
* Example opening a file with Kate and make Kate scroll to the correct line:
45-
* kate -l(line) (file)
46-
*
31+
* @brief List of applications user has specified to open errors with.
4732
*/
4833
class ApplicationList : public QObject
4934
{
@@ -81,23 +66,7 @@ class ApplicationList : public QObject
8166
* @param index Index of the application whose name to get
8267
* @return Name of the application
8368
*/
84-
QString GetApplicationName(const int index) const;
85-
86-
/**
87-
* @brief Get Application's path
88-
*
89-
* @param index of the application whose path to get
90-
* @return Application's path
91-
*/
92-
QString GetApplicationPath(const int index) const;
93-
94-
/**
95-
* @brief Get Application's parameters
96-
*
97-
* @param index of the application whose parameters to get
98-
* @return Application's parameters
99-
*/
100-
QString GetApplicationParameters(const int index) const;
69+
Application GetApplication(const int index) const;
10170

10271
/**
10372
* @brief Return the default application.
@@ -112,22 +81,16 @@ class ApplicationList : public QObject
11281
* @brief Modify an application
11382
*
11483
* @param index Index of the application to modify
115-
* @param name New name for the application
116-
* @param path New path for the application
117-
* @param parameters New parameters for the application
84+
* @param app Application with new data.
11885
*/
119-
void SetApplication(const int index, const QString &name,
120-
const QString &path, const QString &parameters);
86+
void SetApplication(int index, const Application &app);
12187

12288
/**
12389
* @brief Add a new application
12490
*
125-
* @param name Name of the application
126-
* @param path Path to the application
127-
* @param parameters Parameters for the application
91+
* @param app Application to add.
12892
*/
129-
void AddApplication(const QString &name, const QString &path,
130-
const QString &parameters);
93+
void AddApplication(const Application &app);
13194

13295
/**
13396
* @brief Remove an application from the list

gui/resultstree.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include "resultstree.h"
4545
#include "report.h"
4646
#include "xmlreport.h"
47+
#include "application.h"
4748

4849
ResultsTree::ResultsTree(QWidget * parent) :
4950
QTreeView(parent),
@@ -560,7 +561,8 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e)
560561
for (int i = 0; i < mApplications->GetApplicationCount(); i++)
561562
{
562563
//Create an action for the application
563-
QAction *start = new QAction(mApplications->GetApplicationName(i), &menu);
564+
const Application app = mApplications->GetApplication(i);
565+
QAction *start = new QAction(app.getName(), &menu);
564566
if (multipleSelection)
565567
start->setDisabled(true);
566568

@@ -659,8 +661,6 @@ void ResultsTree::StartApplication(QStandardItem *target, int application)
659661

660662
QVariantMap data = target->data().toMap();
661663

662-
QString params = mApplications->GetApplicationParameters(application);
663-
664664
//Replace (file) with filename
665665
QString file = data["file"].toString();
666666

@@ -697,6 +697,8 @@ void ResultsTree::StartApplication(QStandardItem *target, int application)
697697
file.append("\"");
698698
}
699699

700+
const Application app = mApplications->GetApplication(application);
701+
QString params = app.getParameters();
700702
params.replace("(file)", file, Qt::CaseInsensitive);
701703

702704
QVariant line = data["line"];
@@ -705,7 +707,7 @@ void ResultsTree::StartApplication(QStandardItem *target, int application)
705707
params.replace("(message)", data["message"].toString(), Qt::CaseInsensitive);
706708
params.replace("(severity)", data["severity"].toString(), Qt::CaseInsensitive);
707709

708-
QString program = mApplications->GetApplicationPath(application);
710+
QString program = app.getPath();
709711

710712
// In Windows we must surround paths including spaces with quotation marks.
711713
#ifdef Q_WS_WIN

gui/settingsdialog.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,9 @@ void SettingsDialog::AddApplication()
202202

203203
if (dialog.exec() == QDialog::Accepted)
204204
{
205-
mTempApplications->AddApplication(dialog.GetName(), dialog.GetPath(),
206-
dialog.GetParams());
205+
const Application app(dialog.GetName(), dialog.GetPath(),
206+
dialog.GetParams());
207+
mTempApplications->AddApplication(app);
207208
mUI.mListWidget->addItem(dialog.GetName());
208209
}
209210
}
@@ -234,17 +235,17 @@ void SettingsDialog::EditApplication()
234235
foreach(item, selected)
235236
{
236237
int row = mUI.mListWidget->row(item);
237-
238-
ApplicationDialog dialog(mTempApplications->GetApplicationName(row),
239-
mTempApplications->GetApplicationPath(row),
240-
mTempApplications->GetApplicationParameters(row),
238+
const Application app = mTempApplications->GetApplication(row);
239+
ApplicationDialog dialog(app.getName(), app.getPath(),
240+
app.getParameters(),
241241
tr("Modify an application"), this);
242242

243243
if (dialog.exec() == QDialog::Accepted)
244244
{
245-
mTempApplications->SetApplication(row, dialog.GetName(),
246-
dialog.GetPath(),
247-
dialog.GetParams());
245+
const Application app2(dialog.GetName(),
246+
dialog.GetPath(),
247+
dialog.GetParams());
248+
mTempApplications->SetApplication(row, app2);
248249
item->setText(dialog.GetName());
249250
}
250251
}
@@ -267,7 +268,8 @@ void SettingsDialog::PopulateApplicationList()
267268
const int defapp = mTempApplications->GetDefaultApplication();
268269
for (int i = 0; i < mTempApplications->GetApplicationCount(); i++)
269270
{
270-
QString name = mTempApplications->GetApplicationName(i);
271+
Application app = mTempApplications->GetApplication(i);
272+
QString name = app.getName();
271273
if (i == defapp)
272274
{
273275
name += " ";

0 commit comments

Comments
 (0)