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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
|
/*
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 WORKAROUNDS_H
#define WORKAROUNDS_H
#include "loadmechanism.h"
#include "serverinfo.h"
#include <iplugin.h>
#include <QSettings>
#include <QListWidget>
#include <QComboBox>
namespace MOBase {
class IPluginGame;
}
/**
* manages the settings for Mod Organizer. The settings are not cached
* inside the class but read/written directly from/to disc
**/
class Settings : public QObject
{
Q_OBJECT
public:
/**
* @brief constructor
**/
Settings(const QSettings &settingsSource);
virtual ~Settings();
static Settings &instance();
/**
* unregister all plugins from settings
*/
void clearPlugins();
/**
* @brief register plugin to be configurable
* @param plugin the plugin to register
* @return true if the plugin may be registered, false if it is blacklisted
*/
void registerPlugin(MOBase::IPlugin *plugin);
/**
* displays a SettingsDialog that allows the user to change settings. If the
* user accepts the changes, the settings are immediately written
**/
void query(QWidget *parent);
/**
* set up the settings for the specified plugins
**/
void addPluginSettings(const std::vector<MOBase::IPlugin*> &plugins);
/**
* @return true if the user wants unchecked plugins (esp, esm) should be hidden from
* the virtual dat adirectory
**/
bool hideUncheckedPlugins() const;
/**
* @return true if files of the core game are forced-enabled so the user can't accidentally disable them
*/
bool forceEnableCoreFiles() const;
/**
* @brief register download speed
* @param url complete download url
* @param bytesPerSecond download size in bytes per second
*/
void setDownloadSpeed(const QString &serverName, int bytesPerSecond);
/**
* the steam appid is assigned by the steam platform to each product sold there.
* The appid may differ between different versions of a game so it may be impossible
* for Mod Organizer to automatically recognize it, though usually it does
* @return the steam appid for the game
**/
QString getSteamAppID() const;
/**
* retrieve the directory where downloads are stored (with native separators)
**/
QString getDownloadDirectory() const;
/**
* retrieve a sorted list of preferred servers
*/
std::map<QString, int> getPreferredServers();
/**
* retrieve the directory where mods are stored (with native separators)
**/
QString getModDirectory() const;
/**
* returns the version of nmm to impersonate when connecting to nexus
**/
QString getNMMVersion() const;
/**
* retrieve the directory where the web cache is stored (with native separators)
**/
QString getCacheDirectory() const;
/**
* @return true if the user has set up automatic login to nexus
**/
bool automaticLoginEnabled() const;
/**
* @brief retrieve the login information for nexus
*
* @param username (out) receives the user name for nexus
* @param password (out) received the password for nexus
* @return true if automatic login is active, false otherwise
**/
bool getNexusLogin(QString &username, QString &password) const;
/**
* @brief retrieve the login information for steam
*
* @param username (out) receives the user name for nexus
* @param password (out) received the password for nexus
* @return true if a username has been specified, false otherwise
**/
bool getSteamLogin(QString &username, QString &password) const;
/**
* @return true if the user disabled internet features
*/
bool offlineMode() const;
/**
* @return true if the user chose compact downloads
*/
bool compactDownloads() const;
/**
* @return true if the user chose meta downloads
*/
bool metaDownloads() const;
/**
* @return the configured log level
*/
int logLevel() const;
/**
* @brief set the nexus login information
*
* @param username username
* @param password password
*/
void setNexusLogin(QString username, QString password);
/**
* @brief set the steam login information
*
* @param username username
* @param password password
*/
void setSteamLogin(QString username, QString password);
/**
* @return the load mechanism to be used
**/
LoadMechanism::EMechanism getLoadMechanism() const;
/**
* @brief activate the load mechanism selected by the user
**/
void setupLoadMechanism();
/**
* @return true if the user configured the use of a network proxy
*/
bool useProxy();
/**
* @return true if the user wants to see non-official plugins installed outside MO in his mod list
*/
bool displayForeign();
/**
* @brief sets the new motd hash
**/
void setMotDHash(uint hash);
/**
* @return hash of the last displayed message of the day
**/
uint getMotDHash() const;
/**
* @brief allows direct access to the wrapped QSettings object
* @return the wrapped QSettings object
*/
QSettings &directInterface() { return m_Settings; }
/**
* @brief retrieve a setting for one of the installed plugins
* @param pluginName name of the plugin
* @param key name of the setting to retrieve
* @return the requested value as a QVariant
* @note an invalid QVariant is returned if the the plugin/setting is not declared
*/
QVariant pluginSetting(const QString &pluginName, const QString &key) const;
/**
* @brief set a setting for one of the installed mods
* @param pluginName name of the plugin
* @param key name of the setting to change
* @param value the new value to set
* @throw an exception is thrown if pluginName is invalid
*/
void setPluginSetting(const QString &pluginName, const QString &key, const QVariant &value);
/**
* @brief retrieve a persistent value for a plugin
* @param pluginName name of the plugin to store data for
* @param key id of the value to retrieve
* @param def default value to return if the value is not set
* @return the requested value
*/
QVariant pluginPersistent(const QString &pluginName, const QString &key, const QVariant &def) const;
/**
* @brief set a persistent value for a plugin
* @param pluginName name of the plugin to store data for
* @param key id of the value to retrieve
* @param value value to set
* @throw an exception is thrown if pluginName is invalid
*/
void setPluginPersistent(const QString &pluginName, const QString &key, const QVariant &value, bool sync);
/**
* @return short code of the configured language (corresponding to the translation files)
*/
QString language();
/**
* @brief updates the list of known servers
* @param list of servers from a recent query
*/
void updateServers(const QList<ServerInfo> &servers);
/**
* @brief add a plugin that is to be blacklisted
* @param fileName name of the plugin to blacklist
*/
void addBlacklistPlugin(const QString &fileName);
/**
* @brief test if a plugin is blacklisted and shouldn't be loaded
* @param fileName name of the plugin
* @return true if the file is blacklisted
*/
bool pluginBlacklisted(const QString &fileName) const;
/**
* @return all loaded MO plugins
*/
std::vector<MOBase::IPlugin*> plugins() const { return m_Plugins; }
/**
* @brief register MO as the handler for nxm links
* @param force set to true to enforce the registration dialog to show up,
* even if the user said earlier not to
*/
void registerAsNXMHandler(bool force);
public slots:
void managedGameChanged(MOBase::IPluginGame *gamePlugin);
private:
QString obfuscate(const QString &password) const;
QString deObfuscate(const QString &password) const;
void addLanguages(QComboBox *languageBox);
void addStyles(QComboBox *styleBox);
void readPluginBlacklist();
void writePluginBlacklist();
QString getConfigurablePath(const QString &key, const QString &def) const;
private slots:
void resetDialogs();
signals:
void languageChanged(const QString &newLanguage);
void styleChanged(const QString &newStyle);
private:
static Settings *s_Instance;
MOBase::IPluginGame *m_GamePlugin;
QSettings m_Settings;
LoadMechanism m_LoadMechanism;
std::vector<MOBase::IPlugin*> m_Plugins;
QMap<QString, QMap<QString, QVariant>> m_PluginSettings;
QMap<QString, QMap<QString, QVariant>> m_PluginDescriptions;
QSet<QString> m_PluginBlacklist;
};
#endif // WORKAROUNDS_H
|