summaryrefslogtreecommitdiff
path: root/src/instancemanagerdialog.h
blob: 884beaa53e3cb8551030137fb03d0d17acb8d488 (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
#ifndef MODORGANIZER_INSTANCEMANAGERDIALOG_INCLUDED
#define MODORGANIZER_INSTANCEMANAGERDIALOG_INCLUDED

#include <QDialog>
#include <filterwidget.h>

namespace Ui
{
class InstanceManagerDialog;
};

class Instance;
class PluginContainer;

// a dialog to manage existing instances
//
class InstanceManagerDialog : public QDialog
{
  Q_OBJECT

public:
  explicit InstanceManagerDialog(PluginContainer& pc, QWidget* parent = nullptr);

  ~InstanceManagerDialog();

  // selects the instance having the given index in the list
  //
  void select(std::size_t i);

  // selects the instance by name
  //
  void select(const QString& name);

  // select the instance that is currently in use in MO
  //
  void selectActiveInstance();

  // switches to the selected instance; restarts MO, unless
  // was called setRestartOnSelect(false)
  //
  void openSelectedInstance();

  // renames the currently selected instance
  //
  void rename();

  // explores the directory of the selected instance
  //
  void exploreLocation();

  // explores the base directory of the selected instance
  //
  void exploreBaseDirectory();

  // explores the game directory of the selected instance
  //
  void exploreGame();

  // converts the selected, portable instance to a global one; not implemented
  //
  void convertToGlobal();

  // converts the selected, global instance to a portable one; not implemented
  //
  void convertToPortable();

  // opens the ini of the selected instance in the shell
  //
  void openINI();

  // deletes the selected instance
  //
  void deleteInstance();

  // sets whether the dialog should restart MO when selecting an instance; this
  // is false on startup when no instances exist
  //
  void setRestartOnSelect(bool b);

  // saves geometry
  //
  void done(int r) override;

protected:
  // restores geometry
  //
  void showEvent(QShowEvent* e) override;

private:
  static const std::size_t NoSelection = -1;

  std::unique_ptr<Ui::InstanceManagerDialog> ui;
  PluginContainer& m_pc;
  std::vector<std::unique_ptr<Instance>> m_instances;
  MOBase::FilterWidget m_filter;
  QStandardItemModel* m_model;
  bool m_restartOnSelect;

  // refreshes the list instances from disk
  //
  void updateInstances();

  // updates the ui for the selected instance
  //
  void onSelection();

  // opens the create instance dialog
  //
  void createNew();

  // shows a confirmation to the user before switching
  //
  bool confirmSwitch(const Instance& to);

  // returns the index of selected instance, NoSelection if none
  //
  std::size_t singleSelectionIndex() const;

  // returns the InstanceInfo associated with the selected instance, null if
  // none
  //
  const Instance* singleSelection() const;

  // fills the instance list on the ui
  //
  void updateList();

  // fills the ui for the selected instance
  //
  void fillData(const Instance& ii);

  // clears the ui when there's no selection
  //
  void clearData();

  // enables/disables buttons like rename, explore...
  //
  void setButtonsEnabled(bool b);

  // deletes the given files, returns false on error
  //
  bool doDelete(const QStringList& files, bool recycle);
};

#endif  // MODORGANIZER_INSTANCEMANAGERDIALOG_INCLUDED