summaryrefslogtreecommitdiff
path: root/src/editexecutablesdialog.h
diff options
context:
space:
mode:
authorSilarn <jrim@rimpo.org>2019-07-22 01:00:42 -0500
committerSilarn <jrim@rimpo.org>2019-07-22 01:00:42 -0500
commitdcd6d624672019727d7effd17aac86f72bff438b (patch)
tree1e8d3856f657d898c5992631599cf272d785f973 /src/editexecutablesdialog.h
parent179a73857125ee604f42b0d5c2d765183c86d2c7 (diff)
parente73c309f08eff98f0dbd2590f594a83b67431eac (diff)
Merge branch 'Develop'
Diffstat (limited to 'src/editexecutablesdialog.h')
-rw-r--r--src/editexecutablesdialog.h199
1 files changed, 147 insertions, 52 deletions
diff --git a/src/editexecutablesdialog.h b/src/editexecutablesdialog.h
index bee3cba6..9715489e 100644
--- a/src/editexecutablesdialog.h
+++ b/src/editexecutablesdialog.h
@@ -22,106 +22,201 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
#include "tutorabledialog.h"
#include <QListWidgetItem>
-#include <QTimer>
#include "executableslist.h"
#include "profile.h"
#include "iplugingame.h"
+#include <QTimer>
+#include <QAbstractButton>
+#include <optional>
namespace Ui {
class EditExecutablesDialog;
}
-
class ModList;
+class OrganizerCore;
-
-/**
- * @brief Dialog to manage the list of executables
+/** helper class to manage custom overwrites within the edit executables
+ * dialog, stores a T and a bool in map indexed by a QString
**/
-class EditExecutablesDialog : public MOBase::TutorableDialog
+template <class T>
+class ToggableMap
{
- Q_OBJECT
-
public:
+ struct Value
+ {
+ bool enabled;
+ T value;
+
+ Value(bool b, T&& v)
+ : enabled(b), value(std::forward<T>(v))
+ {
+ }
+ };
/**
- * @brief constructor
- *
- * @param executablesList current list of executables
- * @param parent parent widget
+ * returns the Value associated with the given title, or empty
**/
- explicit EditExecutablesDialog(const ExecutablesList &executablesList,
- const ModList &modList,
- Profile *profile,
- const MOBase::IPluginGame *game,
- QWidget *parent = 0);
+ std::optional<Value> find(const QString& title) const
+ {
+ auto itor = m_map.find(title);
+ if (itor == m_map.end()) {
+ return {};
+ }
- ~EditExecutablesDialog();
+ return itor->second;
+ }
/**
- * @brief retrieve the updated list of executables
- *
- * @return updated list of executables
+ * sets the given value, adds it if not found
**/
- ExecutablesList getExecutablesList() const;
+ void set(QString title, bool b, T value)
+ {
+ m_map.insert_or_assign(std::move(title), Value(b, std::move(value)));
+ }
- void saveExecutable();
+ /**
+ * sets whether the given value is enabled, inserts it if not found
+ **/
+ void setEnabled(const QString& title, bool b)
+ {
+ auto itor = m_map.find(title);
-private slots:
- void on_newFilesModCheckBox_toggled(bool checked);
+ if (itor == m_map.end()) {
+ m_map.emplace(title, Value(b, {}));
+ } else {
+ itor->second.enabled = b;
+ }
+ }
-private slots:
+ /**
+ * sets the given value, inserts it enabled if not found
+ **/
+ void setValue(const QString& title, T value)
+ {
+ auto itor = m_map.find(title);
- void on_binaryEdit_textChanged(const QString &arg1);
+ if (itor == m_map.end()) {
+ m_map.emplace(title, Value(true, std::move(value)));
+ } else {
+ itor->second.value = std::move(value);
+ }
+ }
- void on_workingDirEdit_textChanged(const QString &arg1);
+ /**
+ * renames the given value, ignored if not found
+ **/
+ void rename(const QString& oldTitle, QString newTitle)
+ {
+ auto itor = m_map.find(oldTitle);
+ if (itor == m_map.end()) {
+ return;
+ }
- void on_addButton_clicked();
+ // move to new title, erase old
+ m_map.emplace(std::move(newTitle), std::move(itor->second));
+ m_map.erase(itor);
+ }
- void on_browseButton_clicked();
+ /**
+ * removes the given value, ignored if not found
+ **/
+ void remove(const QString& title)
+ {
+ auto itor = m_map.find(title);
+ if (itor == m_map.end()) {
+ return;
+ }
- void on_removeButton_clicked();
+ m_map.erase(itor);
+ }
- void on_titleEdit_textChanged(const QString &arg1);
+private:
+ std::map<QString, Value> m_map;
+};
- void on_overwriteAppIDBox_toggled(bool checked);
- void on_browseDirButton_clicked();
+/**
+ * @brief Dialog to manage the list of executables
+ **/
+class EditExecutablesDialog : public MOBase::TutorableDialog
+{
+ Q_OBJECT
- void on_closeButton_clicked();
+public:
+ using CustomOverwrites = ToggableMap<QString>;
+ using ForcedLibraries = ToggableMap<QList<MOBase::ExecutableForcedLoadSetting>>;
- void delayedRefresh();
+ explicit EditExecutablesDialog(OrganizerCore& oc, QWidget* parent=nullptr);
- void on_executablesListBox_itemSelectionChanged();
+ ~EditExecutablesDialog();
- void on_executablesListBox_clicked(const QModelIndex &index);
+ ExecutablesList getExecutablesList() const;
+ const CustomOverwrites& getCustomOverwrites() const;
+ const ForcedLibraries& getForcedLibraries() const;
- void on_forceLoadButton_clicked();
+private slots:
+ void on_list_itemSelectionChanged();
- void on_forceLoadCheckBox_toggled();
+ void on_reset_clicked();
+ void on_add_clicked();
+ void on_remove_clicked();
+ void on_up_clicked();
+ void on_down_clicked();
-private:
+ void on_title_textChanged(const QString& s);
+ void on_overwriteSteamAppID_toggled(bool checked);
+ void on_createFilesInMod_toggled(bool checked);
+ void on_forceLoadLibraries_toggled(bool checked);
- void resetInput();
+ void on_browseBinary_clicked();
+ void on_browseWorkingDirectory_clicked();
+ void on_configureLibraries_clicked();
- void refreshExecutablesWidget();
+ void on_buttons_clicked(QAbstractButton* b);
- bool executableChanged();
+private:
+ std::unique_ptr<Ui::EditExecutablesDialog> ui;
+ OrganizerCore& m_organizerCore;
- void updateButtonStates();
+ // copy of the original executables, used to clear the current settings when
+ // committing changes
+ const ExecutablesList m_originalExecutables;
-private:
- Ui::EditExecutablesDialog *ui;
+ // current executable list
+ ExecutablesList m_executablesList;
+
+ // custom overwrites set in the dialog
+ CustomOverwrites m_customOverwrites;
+
+ // forced libraries set in the dialog
+ ForcedLibraries m_forcedLibraries;
- QListWidgetItem *m_CurrentItem;
+ // true when the change events being triggered are in response to loading
+ // the executable's data into the UI, not from a user change
+ bool m_settingUI;
- ExecutablesList m_ExecutablesList;
- Profile *m_Profile;
+ void loadCustomOverwrites();
+ void loadForcedLibraries();
- QList<MOBase::ExecutableForcedLoadSetting> m_ForcedLibraries;
+ QListWidgetItem* selectedItem();
+ Executable* selectedExe();
- const MOBase::IPluginGame *m_GamePlugin;
+ void fillList();
+ QListWidgetItem* createListItem(const Executable& exe);
+ void updateUI(const QListWidgetItem* item, const Executable* e);
+ void clearEdits();
+ void setEdits(const Executable& e);
+ void setButtons(const QListWidgetItem* item, const Executable* e);
+ void save();
+ void saveOrder();
+ bool canMove(const QListWidgetItem* item, int direction);
+ void move(QListWidgetItem* item, int direction);
+ void setJarBinary(const QString& binaryName);
+ bool isTitleConflicting(const QString& s);
+ void commitChanges();
+ void setDirty(bool b);
};
#endif // EDITEXECUTABLESDIALOG_H