diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/executableslist.cpp | 54 | ||||
| -rw-r--r-- | src/executableslist.h | 21 | ||||
| -rw-r--r-- | src/organizercore.cpp | 47 |
3 files changed, 72 insertions, 50 deletions
diff --git a/src/executableslist.cpp b/src/executableslist.cpp index 2ea9c3d9..43a30f02 100644 --- a/src/executableslist.cpp +++ b/src/executableslist.cpp @@ -63,6 +63,60 @@ bool ExecutablesList::empty() const return m_Executables.empty();
}
+void ExecutablesList::load(const MOBase::IPluginGame* game, QSettings& settings)
+{
+ addFromPlugin(game);
+
+ qDebug("setting up configured executables");
+
+ int numCustomExecutables = settings.beginReadArray("customExecutables");
+ for (int i = 0; i < numCustomExecutables; ++i) {
+ settings.setArrayIndex(i);
+
+ Executable::Flags flags;
+ if (settings.value("custom", true).toBool())
+ flags |= Executable::CustomExecutable;
+ if (settings.value("toolbar", false).toBool())
+ flags |= Executable::ShowInToolbar;
+ if (settings.value("ownicon", false).toBool())
+ flags |= Executable::UseApplicationIcon;
+
+ addExecutable(
+ settings.value("title").toString(), settings.value("binary").toString(),
+ settings.value("arguments").toString(),
+ settings.value("workingDirectory", "").toString(),
+ settings.value("steamAppID", "").toString(), flags);
+ }
+
+ settings.endArray();
+}
+
+void ExecutablesList::store(QSettings& settings)
+{
+ settings.remove("customExecutables");
+ settings.beginWriteArray("customExecutables");
+
+ int count = 0;
+
+ for (const auto& item : *this) {
+ settings.setArrayIndex(count++);
+
+ settings.setValue("title", item.title());
+ settings.setValue("custom", item.isCustom());
+ settings.setValue("toolbar", item.isShownOnToolbar());
+ settings.setValue("ownicon", item.usesOwnIcon());
+
+ if (item.isCustom()) {
+ settings.setValue("binary", item.binaryInfo().absoluteFilePath());
+ settings.setValue("arguments", item.arguments());
+ settings.setValue("workingDirectory", item.workingDirectory());
+ settings.setValue("steamAppID", item.steamAppID());
+ }
+ }
+
+ settings.endArray();
+}
+
void ExecutablesList::addFromPlugin(IPluginGame const *game)
{
Q_ASSERT(game != nullptr);
diff --git a/src/executableslist.h b/src/executableslist.h index b8e4cf77..136f70bf 100644 --- a/src/executableslist.h +++ b/src/executableslist.h @@ -103,9 +103,14 @@ public: bool empty() const;
/**
- * @brief add the executables preconfigured for this game
- **/
- void addFromPlugin(MOBase::IPluginGame const *game);
+ * @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
@@ -195,14 +200,16 @@ public: void remove(const QString &title);
private:
+ std::vector<Executable> m_Executables;
+
void addExecutableInternal(const QString &title, const QString &executableName, const QString &arguments,
const QString &workingDirectory,
const QString &steamAppID);
-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)
diff --git a/src/organizercore.cpp b/src/organizercore.cpp index 4d11a35f..2172538e 100644 --- a/src/organizercore.cpp +++ b/src/organizercore.cpp @@ -365,33 +365,17 @@ QString OrganizerCore::commitSettings(const QString &iniFile) QSettings::Status OrganizerCore::storeSettings(const QString &fileName) { QSettings settings(fileName, QSettings::IniFormat); + if (m_UserInterface != nullptr) { m_UserInterface->storeSettings(settings); } + if (m_CurrentProfile != nullptr) { settings.setValue("selected_profile", m_CurrentProfile->name().toUtf8().constData()); } - settings.remove("customExecutables"); - settings.beginWriteArray("customExecutables"); - - int count = 0; - - for (const auto& item : m_ExecutablesList) { - settings.setArrayIndex(count++); - settings.setValue("title", item.title()); - settings.setValue("custom", item.isCustom()); - settings.setValue("toolbar", item.isShownOnToolbar()); - settings.setValue("ownicon", item.usesOwnIcon()); - if (item.isCustom()) { - settings.setValue("binary", item.binaryInfo().absoluteFilePath()); - settings.setValue("arguments", item.arguments()); - settings.setValue("workingDirectory", item.workingDirectory()); - settings.setValue("steamAppID", item.steamAppID()); - } - } - settings.endArray(); + m_ExecutablesList.store(settings); FileDialogMemory::save(settings); @@ -507,30 +491,7 @@ void OrganizerCore::updateExecutablesList(QSettings &settings) return; } - m_ExecutablesList.addFromPlugin(managedGame()); - - qDebug("setting up configured executables"); - - int numCustomExecutables = settings.beginReadArray("customExecutables"); - for (int i = 0; i < numCustomExecutables; ++i) { - settings.setArrayIndex(i); - - Executable::Flags flags; - if (settings.value("custom", true).toBool()) - flags |= Executable::CustomExecutable; - if (settings.value("toolbar", false).toBool()) - flags |= Executable::ShowInToolbar; - if (settings.value("ownicon", false).toBool()) - flags |= Executable::UseApplicationIcon; - - m_ExecutablesList.addExecutable( - settings.value("title").toString(), settings.value("binary").toString(), - settings.value("arguments").toString(), - settings.value("workingDirectory", "").toString(), - settings.value("steamAppID", "").toString(), flags); - } - - settings.endArray(); + m_ExecutablesList.load(managedGame(), settings); // TODO this has nothing to do with executables list move to an appropriate // function! |
