summaryrefslogtreecommitdiff
path: root/src/executableslist.h
blob: e35cb55095920e9ea7186b93ae27ee0f381418f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*
Copyright (C) 2012 Sebastian Herbord. All rights reserved.

This file is part of Mod Organizer.

Mod Organizer 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.

Mod Organizer 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 Mod Organizer.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef EXECUTABLESLIST_H
#define EXECUTABLESLIST_H

#include "executableinfo.h"

#include <vector>

#include <QFileInfo>
#include <QMetaType>

namespace MOBase { class IPluginGame; }

/*!
 * @brief Information about an executable
 **/
class Executable
{
public:
  enum Flag
  {
    CustomExecutable = 0x01,
    ShowInToolbar = 0x02,
    UseApplicationIcon = 0x04
  };

  Q_DECLARE_FLAGS(Flags, Flag);

  Executable(
    QString title, QFileInfo binaryInfo, QString arguments,
    QString steamAppID, QString workingDirectory, Flags flags);

  const QString& title() const;
  const QFileInfo& binaryInfo() const;
  const QString& arguments() const;
  const QString& steamAppID() const;
  const QString& workingDirectory() const;
  Flags flags() const;

  bool isCustom() const;
  bool isShownOnToolbar() const;
  void setShownOnToolbar(bool state);
  bool usesOwnIcon() const;

  void mergeFrom(const Executable& other);

private:
  QString m_title;
  QFileInfo m_binaryInfo;
  QString m_arguments;
  QString m_steamAppID;
  QString m_workingDirectory;
  Flags m_flags;
};


/*!
 * @brief List of executables configured to by started from MO
 **/
class ExecutablesList {
public:
  using vector_type = std::vector<Executable>;
  using iterator = vector_type::iterator;
  using const_iterator = vector_type::const_iterator;

  /**
   * standard container interface
   */
  iterator begin();
  const_iterator begin() const;
  iterator end();
  const_iterator end() const;
  std::size_t size() const;
  bool empty() const;

  /**
   * @brief initializes the list from the settings and the given plugin
   */
  void load(const MOBase::IPluginGame* game, QSettings& settings);

  /**
   * @brief writes the current list to the settings
   */
  void store(QSettings& settings);

  /**
   * @brief get an executable by name
   *
   * @param title the title of the executable to look up
   * @return the executable
   * @exception runtime_error will throw an exception if the executable is not found
   **/
  const Executable &get(const QString &title) const;

  /**
   * @brief find an executable by its name
   *
   * @param title the title of the executable to look up
   * @return the executable
   * @exception runtime_error will throw an exception if the name is not correct
   **/
  Executable &get(const QString &title);

  /**
   * @brief find an executable by a fileinfo structure
   * @param info the info object to search for
   * @return the executable
   * @exception runtime_error will throw an exception if the name is not correct
   */
  Executable &getByBinary(const QFileInfo &info);

  /**
   * @brief returns an iterator for the given executable by title, or end()
   */
  iterator find(const QString &title);
  const_iterator find(const QString &title) const;

  /**
   * @brief determine if an executable exists
   * @param title the title of the executable to look up
   * @return true if the executable exists, false otherwise
   **/
  bool titleExists(const QString &title) const;

  /**
   * @brief add a new executable to the list
   * @param executable
   */
  void setExecutable(const Executable &executable);

  /**
   * @brief remove the executable with the specified file name. This needs to
   *        be an absolute file path
   *
   * @param title title of the executable to remove
   * @note if the executable name is invalid, nothing happens. There is no way
   *       to determine if this was successful
   **/
  void remove(const QString &title);

private:
  std::vector<Executable> m_Executables;

  /**
  * @brief add the executables preconfigured for this game
  **/
  void addFromPlugin(MOBase::IPluginGame const *game);
};

Q_DECLARE_OPERATORS_FOR_FLAGS(Executable::Flags)

#endif // EXECUTABLESLIST_H