2424#include < stdlib.h>
2525#include " common.h"
2626#include " applicationlist.h"
27+ #include " application.h"
2728
2829
2930ApplicationList::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 ¶meters)
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 ¶meters)
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 ;
0 commit comments