1 /*
2  * Cppcheck - A tool for static C/C++ code analysis
3  * Copyright (C) 2007-2021 Cppcheck team.
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef APPLICATIONLIST_H
20 #define APPLICATIONLIST_H
21 
22 #include <QObject>
23 #include "application.h"
24 
25 /// @addtogroup GUI
26 /// @{
27 
28 
29 /**
30  * @brief List of applications user has specified to open errors with.
31  */
32 class ApplicationList : public QObject {
33     Q_OBJECT
34 public:
35 
36     explicit ApplicationList(QObject *parent = nullptr);
37     virtual ~ApplicationList();
38 
39     /**
40      * @brief Load all applications
41      *
42      * @return true if loading succeeded, false if there is problem with
43      *  application list. Most probably because of older version settings need
44      *  to be upgraded.
45      */
46     bool loadSettings();
47 
48     /**
49      * @brief Save all applications
50      */
51     void saveSettings() const;
52 
53     /**
54      * @brief Get the amount of applications in the list
55      * @return The count of applications
56      */
57     int getApplicationCount() const;
58 
59     /**
60      * @brief Get specific application's name
61      *
62      * @param index Index of the application whose name to get
63      * @return Name of the application
64      */
65     const Application& getApplication(const int index) const;
66     Application& getApplication(const int index);
67 
68     /**
69      * @brief Return the default application.
70      * @return Index of the default application.
71      */
getDefaultApplication()72     int getDefaultApplication() const {
73         return mDefaultApplicationIndex;
74     }
75 
76     /**
77      * @brief Add a new application
78      *
79      * @param app Application to add.
80      */
81     void addApplication(const Application &app);
82 
83     /**
84      * @brief Remove an application from the list
85      *
86      * @param index Index of the application to remove.
87      */
88     void removeApplication(const int index);
89 
90     /**
91      * @brief Set application as default application.
92      * @param index Index of the application to make the default one
93      */
94     void setDefault(const int index);
95 
96     /**
97      * @brief Remove all applications from this list and copy all applications from
98      * list given as a parameter.
99      * @param list Copying source
100      */
101     void copy(const ApplicationList *list);
102 
103 protected:
104 
105     /**
106      * @brief Clear the list
107      *
108      */
109     void clear();
110 
111     /**
112      * @brief Find editor used by default in Windows.
113      * Check if Notepad++ is installed and use it. If not, use Notepad.
114      */
115     bool findDefaultWindowsEditor();
116 
117 private:
118 
119     bool checkAndAddApplication(const QString& appPath, const QString& name, const QString& parameters);
120 
121     /**
122      * @brief List of applications
123      *
124      */
125     QList<Application> mApplications;
126 
127     /**
128      * @brief Index of the default application.
129      *
130      */
131     int mDefaultApplicationIndex;
132 };
133 /// @}
134 #endif // APPLICATIONLIST_H
135