Skip to content

Commit bfbb190

Browse files
committed
moved button to switch instance (and to portable mode) to the main window
1 parent c3b7737 commit bfbb190

13 files changed

+109
-130
lines changed

src/instancemanager.cpp

+51-49
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
2727
#include <QStandardPaths>
2828
#include <QInputDialog>
2929
#include <QMessageBox>
30+
#include <cstdint>
3031

3132

3233
static const char COMPANY_NAME[] = "Tannin";
@@ -40,6 +41,11 @@ InstanceManager::InstanceManager()
4041
{
4142
}
4243

44+
InstanceManager &InstanceManager::instance()
45+
{
46+
static InstanceManager s_Instance;
47+
return s_Instance;
48+
}
4349

4450
QString InstanceManager::currentInstance() const
4551
{
@@ -49,6 +55,7 @@ QString InstanceManager::currentInstance() const
4955
void InstanceManager::clearCurrentInstance()
5056
{
5157
setCurrentInstance("");
58+
m_Reset = true;
5259
}
5360

5461
void InstanceManager::setCurrentInstance(const QString &name)
@@ -81,26 +88,51 @@ QString InstanceManager::queryInstanceName() const
8188

8289
QString InstanceManager::chooseInstance(const QStringList &instanceList) const
8390
{
84-
SelectionDialog selection(QObject::tr("Choose Instance"), nullptr);
91+
enum class Special : uint8_t {
92+
NewInstance,
93+
Portable
94+
};
95+
96+
SelectionDialog selection(
97+
QString("<h3>%1</h3><br>%2")
98+
.arg(QObject::tr("Choose Instance"))
99+
.arg(QObject::tr(
100+
"Each Instance is a full set of MO data files (mods, "
101+
"downloads, profiles, configuration, ...). Use multiple "
102+
"instances for different games. If your MO folder is "
103+
"writable, you can also store a single instance locally (called "
104+
"a portable install).")),
105+
nullptr);
85106
selection.disableCancel();
86107
for (const QString &instance : instanceList) {
87108
selection.addChoice(instance, "", instance);
88109
}
89110

90-
selection.addChoice(QObject::tr("New"),
111+
selection.addChoice(QIcon(":/MO/gui/add"), QObject::tr("New"),
91112
QObject::tr("Create a new instance."),
92-
"");
113+
static_cast<uint8_t>(Special::NewInstance));
114+
115+
if (QFileInfo(qApp->applicationDirPath()).isWritable()) {
116+
selection.addChoice(QIcon(":/MO/gui/package"), QObject::tr("Portable"),
117+
QObject::tr("Use MO folder for data."),
118+
static_cast<uint8_t>(Special::Portable));
119+
}
120+
93121
if (selection.exec() == QDialog::Rejected) {
94122
qDebug("rejected");
95123
throw MOBase::MyException(QObject::tr("Canceled"));
96124
}
97125

98-
QString choice = selection.getChoiceData().toString();
126+
QVariant choice = selection.getChoiceData();
99127

100-
if (choice.isEmpty()) {
101-
return queryInstanceName();
128+
if (choice.type() == QVariant::String) {
129+
return choice.toString();
102130
} else {
103-
return choice;
131+
switch (choice.value<uint8_t>()) {
132+
case Special::NewInstance: return queryInstanceName();
133+
case Special::Portable: return QString();
134+
default: throw std::runtime_error("invalid selection");
135+
}
104136
}
105137
}
106138

@@ -125,27 +157,6 @@ bool InstanceManager::portableInstall() const
125157
}
126158

127159

128-
InstanceManager::InstallationMode InstanceManager::queryInstallMode() const
129-
{
130-
SelectionDialog selection(QObject::tr("Installation Mode"), nullptr);
131-
selection.disableCancel();
132-
selection.addChoice(QObject::tr("Portable"),
133-
QObject::tr("Everything in one directory, only one game per installation."),
134-
0);
135-
selection.addChoice(QObject::tr("Regular"),
136-
QObject::tr("Data in separate directory, multiple games supported."),
137-
1);
138-
if (selection.exec() == QDialog::Rejected) {
139-
throw MOBase::MyException(QObject::tr("Canceled"));
140-
}
141-
142-
switch (selection.getChoiceData().toInt()) {
143-
case 0: return InstallationMode::PORTABLE;
144-
default: return InstallationMode::REGULAR;
145-
}
146-
}
147-
148-
149160
void InstanceManager::createDataPath(const QString &dataPath) const
150161
{
151162
if (!QDir(dataPath).exists()) {
@@ -166,31 +177,22 @@ void InstanceManager::createDataPath(const QString &dataPath) const
166177
QString InstanceManager::determineDataPath()
167178
{
168179
QString instanceId = currentInstance();
180+
if (instanceId.isEmpty() && portableInstall() && !m_Reset) {
181+
// startup, apparently using portable mode before
182+
return qApp->applicationDirPath();
183+
}
184+
169185
QString dataPath = QDir::fromNativeSeparators(
170186
QStandardPaths::writableLocation(QStandardPaths::DataLocation)
171187
+ "/" + instanceId);
172188

173-
if ((instanceId.isEmpty() || !QFileInfo::exists(dataPath)) && !portableInstall()) {
174-
// no portable install and no selected instance
175-
176-
QStringList instanceList = instances();
177-
178-
if (instanceList.size() == 0) {
179-
if (QFileInfo(qApp->applicationDirPath()).isWritable()) {
180-
switch (queryInstallMode()) {
181-
case InstallationMode::PORTABLE: {
182-
instanceId = QString();
183-
} break;
184-
case InstallationMode::REGULAR: {
185-
instanceId = queryInstanceName();
186-
} break;
187-
}
188-
} else {
189-
instanceId = queryInstanceName();
190-
}
191-
} else {
192-
// don't offer portable instance if we can't set one up.
193-
instanceId = chooseInstance(instanceList);
189+
190+
if (instanceId.isEmpty() || !QFileInfo::exists(dataPath)) {
191+
instanceId = chooseInstance(instances());
192+
if (!instanceId.isEmpty()) {
193+
dataPath = QDir::fromNativeSeparators(
194+
QStandardPaths::writableLocation(QStandardPaths::DataLocation)
195+
+ "/" + instanceId);
194196
}
195197
}
196198

src/instancemanager.h

+6-9
Original file line numberDiff line numberDiff line change
@@ -27,36 +27,33 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
2727

2828
class InstanceManager {
2929

30-
enum class InstallationMode {
31-
PORTABLE,
32-
REGULAR
33-
};
34-
3530
public:
3631

37-
InstanceManager();
32+
static InstanceManager &instance();
3833

3934
QString determineDataPath();
40-
QStringList instances() const;
4135
void clearCurrentInstance();
4236

4337
private:
4438

39+
InstanceManager();
40+
4541
QString currentInstance() const;
4642
QString instancePath() const;
4743

48-
bool portableInstall() const;
44+
QStringList instances() const;
4945

5046
void setCurrentInstance(const QString &name);
5147

5248
QString queryInstanceName() const;
5349
QString chooseInstance(const QStringList &instanceList) const;
5450

5551
void createDataPath(const QString &dataPath) const;
56-
InstallationMode queryInstallMode() const;
52+
bool portableInstall() const;
5753

5854
private:
5955

6056
QSettings m_AppSettings;
57+
bool m_Reset {false};
6158

6259
};

src/main.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -630,13 +630,12 @@ int main(int argc, char *argv[])
630630
QString dataPath;
631631

632632
try {
633-
dataPath = InstanceManager().determineDataPath();
633+
dataPath = InstanceManager::instance().determineDataPath();
634634
} catch (const std::exception &e) {
635635
QMessageBox::critical(nullptr, QObject::tr("Failed to set up instance"),
636636
e.what());
637637
return 1;
638638
}
639-
640639
application.setProperty("dataPath", dataPath);
641640

642641
LogBuffer::init(100, QtDebugMsg, qApp->property("dataPath").toString() + "/logs/mo_interface.log");
@@ -647,7 +646,6 @@ int main(int argc, char *argv[])
647646
}
648647

649648
int result = runApplication(application, instance, splash);
650-
651649
if (result != INT_MAX) {
652650
return result;
653651
}

src/mainwindow.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
3737
#include "savegameinfo.h"
3838
#include "spawn.h"
3939
#include "versioninfo.h"
40+
#include "instancemanager.h"
4041

4142
#include "report.h"
4243
#include "modlist.h"
@@ -3883,6 +3884,17 @@ void MainWindow::on_actionProblems_triggered()
38833884
}
38843885
}
38853886

3887+
void MainWindow::on_actionChange_Game_triggered()
3888+
{
3889+
if (QMessageBox::question(this, tr("Are you sure?"),
3890+
tr("This will restart MO, continue?"),
3891+
QMessageBox::Yes | QMessageBox::Cancel)
3892+
== QMessageBox::Yes) {
3893+
InstanceManager::instance().clearCurrentInstance();
3894+
qApp->exit(INT_MAX);
3895+
}
3896+
}
3897+
38863898
void MainWindow::setCategoryListVisible(bool visible)
38873899
{
38883900
if (visible) {

src/mainwindow.h

+3
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ public slots:
183183
virtual void dragEnterEvent(QDragEnterEvent *event);
184184
virtual void dropEvent(QDropEvent *event);
185185

186+
private slots:
187+
void on_actionChange_Game_triggered();
188+
186189
private slots:
187190
void on_clickBlankButton_clicked();
188191

src/mainwindow.ui

+13
Original file line numberDiff line numberDiff line change
@@ -1197,6 +1197,7 @@ p, li { white-space: pre-wrap; }
11971197
<attribute name="toolBarBreak">
11981198
<bool>false</bool>
11991199
</attribute>
1200+
<addaction name="actionChange_Game"/>
12001201
<addaction name="actionInstallMod"/>
12011202
<addaction name="actionNexus"/>
12021203
<addaction name="actionAdd_Profile"/>
@@ -1383,6 +1384,18 @@ Right now this has very limited functionality</string>
13831384
<string>Ctrl+C</string>
13841385
</property>
13851386
</action>
1387+
<action name="actionChange_Game">
1388+
<property name="icon">
1389+
<iconset resource="resources.qrc">
1390+
<normaloff>:/MO/gui/app_icon</normaloff>:/MO/gui/app_icon</iconset>
1391+
</property>
1392+
<property name="text">
1393+
<string>Change Game</string>
1394+
</property>
1395+
<property name="toolTip">
1396+
<string>Open the game selection dialog</string>
1397+
</property>
1398+
</action>
13861399
</widget>
13871400
<layoutdefault spacing="6" margin="11"/>
13881401
<customwidgets>

src/nxmaccessmanager.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,6 @@ void NXMAccessManager::login(const QString &username, const QString &password)
215215
emit loginSuccessful(false);
216216
return;
217217
}
218-
219218
m_Username = username;
220219
m_Password = password;
221220
pageLogin();
@@ -237,7 +236,6 @@ QString NXMAccessManager::userAgent(const QString &subModule) const
237236
void NXMAccessManager::pageLogin()
238237
{
239238
qDebug("logging %s in on Nexus", qPrintable(m_Username));
240-
241239
QString requestString = (Nexus_Management_URL + "/Sessions/?Login&uri=%1")
242240
.arg(QString(QUrl::toPercentEncoding(Nexus_Management_URL)));
243241

src/resources.qrc

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
<file alias="update_available">resources/software-update-available.png</file>
2727
<file alias="important">resources/emblem-important.png</file>
2828
<file alias="check">resources/check.png</file>
29-
<file>mo_icon.ico</file>
3029
<file alias="warning">resources/dialog-warning.png</file>
3130
<file alias="emblem_backup">resources/symbol-backup.png</file>
3231
<file alias="icon_tools">resources/applications-accessories.png</file>
@@ -68,6 +67,8 @@
6867
<file alias="active">resources/status_active.png</file>
6968
<file alias="awaiting">resources/status_awaiting.png</file>
7069
<file alias="inactive">resources/status_inactive.png</file>
70+
<file alias="app_icon">resources/mo_icon.png</file>
71+
<file alias="package">resources/package.png</file>
7172
</qresource>
7273
<qresource prefix="/MO/gui/content">
7374
<file alias="plugin">resources/contents/jigsaw-piece.png</file>

src/resources/mo_icon.png

1011 Bytes
Loading

src/resources/package.png

1.04 KB
Loading

src/settingsdialog.cpp

-12
Original file line numberDiff line numberDiff line change
@@ -217,18 +217,6 @@ void SettingsDialog::on_associateButton_clicked()
217217
Settings::instance().registerAsNXMHandler(true);
218218
}
219219

220-
void SettingsDialog::on_changeInstanceButton_clicked()
221-
{
222-
if (QMessageBox::question(this, tr("Are you sure?"),
223-
tr("This will restart MO, continue?"),
224-
QMessageBox::Yes | QMessageBox::Cancel)
225-
== QMessageBox::Yes) {
226-
InstanceManager().clearCurrentInstance();
227-
this->reject();
228-
qApp->exit(INT_MAX);
229-
}
230-
}
231-
232220
void SettingsDialog::on_clearCacheButton_clicked()
233221
{
234222
QDir(Settings::instance().getCacheDirectory()).removeRecursively();

src/settingsdialog.h

+8-15
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,6 @@ public slots:
5252

5353
void resetDialogs();
5454

55-
private slots:
56-
void on_clearCacheButton_clicked();
57-
58-
private slots:
59-
void on_browseBaseDirBtn_clicked();
60-
61-
private slots:
62-
void on_browseOverwriteDirBtn_clicked();
63-
64-
private slots:
65-
void on_browseProfilesDirBtn_clicked();
66-
67-
private slots:
68-
void on_changeInstanceButton_clicked();
69-
7055
private:
7156

7257
void storeSettings(QListWidgetItem *pluginItem);
@@ -92,6 +77,14 @@ private slots:
9277

9378
void on_associateButton_clicked();
9479

80+
void on_clearCacheButton_clicked();
81+
82+
void on_browseBaseDirBtn_clicked();
83+
84+
void on_browseOverwriteDirBtn_clicked();
85+
86+
void on_browseProfilesDirBtn_clicked();
87+
9588
private:
9689
Ui::SettingsDialog *ui;
9790
};

0 commit comments

Comments
 (0)