diff options
| author | Tannin <sherb@gmx.net> | 2016-05-27 14:04:00 +0200 |
|---|---|---|
| committer | Tannin <sherb@gmx.net> | 2016-05-27 14:04:00 +0200 |
| commit | bfbb19099839019c785dc81c83b07dadbd394168 (patch) | |
| tree | e84d45b9e7d58c2f3ab649b919ac93fb5207131e /src | |
| parent | c3b7737ae46ad4770532e3380c9ceb6ed4d14cf7 (diff) | |
moved button to switch instance (and to portable mode) to the main window
Diffstat (limited to 'src')
| -rw-r--r-- | src/instancemanager.cpp | 98 | ||||
| -rw-r--r-- | src/instancemanager.h | 15 | ||||
| -rw-r--r-- | src/main.cpp | 4 | ||||
| -rw-r--r-- | src/mainwindow.cpp | 12 | ||||
| -rw-r--r-- | src/mainwindow.h | 3 | ||||
| -rw-r--r-- | src/mainwindow.ui | 13 | ||||
| -rw-r--r-- | src/nxmaccessmanager.cpp | 2 | ||||
| -rw-r--r-- | src/resources.qrc | 3 | ||||
| -rw-r--r-- | src/resources/mo_icon.png | bin | 0 -> 1011 bytes | |||
| -rw-r--r-- | src/resources/package.png | bin | 0 -> 1067 bytes | |||
| -rw-r--r-- | src/settingsdialog.cpp | 12 | ||||
| -rw-r--r-- | src/settingsdialog.h | 23 | ||||
| -rw-r--r-- | src/settingsdialog.ui | 52 |
13 files changed, 108 insertions, 129 deletions
diff --git a/src/instancemanager.cpp b/src/instancemanager.cpp index c74f3c1a..f7b953ad 100644 --- a/src/instancemanager.cpp +++ b/src/instancemanager.cpp @@ -27,6 +27,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>. #include <QStandardPaths> #include <QInputDialog> #include <QMessageBox> +#include <cstdint> static const char COMPANY_NAME[] = "Tannin"; @@ -40,6 +41,11 @@ InstanceManager::InstanceManager() { } +InstanceManager &InstanceManager::instance() +{ + static InstanceManager s_Instance; + return s_Instance; +} QString InstanceManager::currentInstance() const { @@ -49,6 +55,7 @@ QString InstanceManager::currentInstance() const void InstanceManager::clearCurrentInstance() { setCurrentInstance(""); + m_Reset = true; } void InstanceManager::setCurrentInstance(const QString &name) @@ -81,26 +88,51 @@ QString InstanceManager::queryInstanceName() const QString InstanceManager::chooseInstance(const QStringList &instanceList) const { - SelectionDialog selection(QObject::tr("Choose Instance"), nullptr); + enum class Special : uint8_t { + NewInstance, + Portable + }; + + SelectionDialog selection( + QString("<h3>%1</h3><br>%2") + .arg(QObject::tr("Choose Instance")) + .arg(QObject::tr( + "Each Instance is a full set of MO data files (mods, " + "downloads, profiles, configuration, ...). Use multiple " + "instances for different games. If your MO folder is " + "writable, you can also store a single instance locally (called " + "a portable install).")), + nullptr); selection.disableCancel(); for (const QString &instance : instanceList) { selection.addChoice(instance, "", instance); } - selection.addChoice(QObject::tr("New"), + selection.addChoice(QIcon(":/MO/gui/add"), QObject::tr("New"), QObject::tr("Create a new instance."), - ""); + static_cast<uint8_t>(Special::NewInstance)); + + if (QFileInfo(qApp->applicationDirPath()).isWritable()) { + selection.addChoice(QIcon(":/MO/gui/package"), QObject::tr("Portable"), + QObject::tr("Use MO folder for data."), + static_cast<uint8_t>(Special::Portable)); + } + if (selection.exec() == QDialog::Rejected) { qDebug("rejected"); throw MOBase::MyException(QObject::tr("Canceled")); } - QString choice = selection.getChoiceData().toString(); + QVariant choice = selection.getChoiceData(); - if (choice.isEmpty()) { - return queryInstanceName(); + if (choice.type() == QVariant::String) { + return choice.toString(); } else { - return choice; + switch (choice.value<uint8_t>()) { + case Special::NewInstance: return queryInstanceName(); + case Special::Portable: return QString(); + default: throw std::runtime_error("invalid selection"); + } } } @@ -125,27 +157,6 @@ bool InstanceManager::portableInstall() const } -InstanceManager::InstallationMode InstanceManager::queryInstallMode() const -{ - SelectionDialog selection(QObject::tr("Installation Mode"), nullptr); - selection.disableCancel(); - selection.addChoice(QObject::tr("Portable"), - QObject::tr("Everything in one directory, only one game per installation."), - 0); - selection.addChoice(QObject::tr("Regular"), - QObject::tr("Data in separate directory, multiple games supported."), - 1); - if (selection.exec() == QDialog::Rejected) { - throw MOBase::MyException(QObject::tr("Canceled")); - } - - switch (selection.getChoiceData().toInt()) { - case 0: return InstallationMode::PORTABLE; - default: return InstallationMode::REGULAR; - } -} - - void InstanceManager::createDataPath(const QString &dataPath) const { if (!QDir(dataPath).exists()) { @@ -166,31 +177,22 @@ void InstanceManager::createDataPath(const QString &dataPath) const QString InstanceManager::determineDataPath() { QString instanceId = currentInstance(); + if (instanceId.isEmpty() && portableInstall() && !m_Reset) { + // startup, apparently using portable mode before + return qApp->applicationDirPath(); + } + QString dataPath = QDir::fromNativeSeparators( QStandardPaths::writableLocation(QStandardPaths::DataLocation) + "/" + instanceId); - if ((instanceId.isEmpty() || !QFileInfo::exists(dataPath)) && !portableInstall()) { - // no portable install and no selected instance - - QStringList instanceList = instances(); - if (instanceList.size() == 0) { - if (QFileInfo(qApp->applicationDirPath()).isWritable()) { - switch (queryInstallMode()) { - case InstallationMode::PORTABLE: { - instanceId = QString(); - } break; - case InstallationMode::REGULAR: { - instanceId = queryInstanceName(); - } break; - } - } else { - instanceId = queryInstanceName(); - } - } else { - // don't offer portable instance if we can't set one up. - instanceId = chooseInstance(instanceList); + if (instanceId.isEmpty() || !QFileInfo::exists(dataPath)) { + instanceId = chooseInstance(instances()); + if (!instanceId.isEmpty()) { + dataPath = QDir::fromNativeSeparators( + QStandardPaths::writableLocation(QStandardPaths::DataLocation) + + "/" + instanceId); } } diff --git a/src/instancemanager.h b/src/instancemanager.h index 2e17d1c0..a0a5df09 100644 --- a/src/instancemanager.h +++ b/src/instancemanager.h @@ -27,25 +27,21 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>. class InstanceManager { - enum class InstallationMode { - PORTABLE, - REGULAR - }; - public: - InstanceManager(); + static InstanceManager &instance(); QString determineDataPath(); - QStringList instances() const; void clearCurrentInstance(); private: + InstanceManager(); + QString currentInstance() const; QString instancePath() const; - bool portableInstall() const; + QStringList instances() const; void setCurrentInstance(const QString &name); @@ -53,10 +49,11 @@ private: QString chooseInstance(const QStringList &instanceList) const; void createDataPath(const QString &dataPath) const; - InstallationMode queryInstallMode() const; + bool portableInstall() const; private: QSettings m_AppSettings; + bool m_Reset {false}; }; diff --git a/src/main.cpp b/src/main.cpp index 6940e288..e289453c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -630,13 +630,12 @@ int main(int argc, char *argv[]) QString dataPath;
try {
- dataPath = InstanceManager().determineDataPath();
+ dataPath = InstanceManager::instance().determineDataPath();
} catch (const std::exception &e) {
QMessageBox::critical(nullptr, QObject::tr("Failed to set up instance"),
e.what());
return 1;
}
-
application.setProperty("dataPath", dataPath);
LogBuffer::init(100, QtDebugMsg, qApp->property("dataPath").toString() + "/logs/mo_interface.log");
@@ -647,7 +646,6 @@ int main(int argc, char *argv[]) }
int result = runApplication(application, instance, splash);
-
if (result != INT_MAX) {
return result;
}
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index dcff139a..66c2b557 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -37,6 +37,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>. #include "savegameinfo.h"
#include "spawn.h"
#include "versioninfo.h"
+#include "instancemanager.h"
#include "report.h"
#include "modlist.h"
@@ -3883,6 +3884,17 @@ void MainWindow::on_actionProblems_triggered() }
}
+void MainWindow::on_actionChange_Game_triggered()
+{
+ if (QMessageBox::question(this, tr("Are you sure?"),
+ tr("This will restart MO, continue?"),
+ QMessageBox::Yes | QMessageBox::Cancel)
+ == QMessageBox::Yes) {
+ InstanceManager::instance().clearCurrentInstance();
+ qApp->exit(INT_MAX);
+ }
+}
+
void MainWindow::setCategoryListVisible(bool visible)
{
if (visible) {
diff --git a/src/mainwindow.h b/src/mainwindow.h index 43b2bede..3364bb37 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -184,6 +184,9 @@ protected: virtual void dropEvent(QDropEvent *event);
private slots:
+ void on_actionChange_Game_triggered();
+
+private slots:
void on_clickBlankButton_clicked();
private:
diff --git a/src/mainwindow.ui b/src/mainwindow.ui index f504994a..e30a165d 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -1197,6 +1197,7 @@ p, li { white-space: pre-wrap; } <attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
+ <addaction name="actionChange_Game"/>
<addaction name="actionInstallMod"/>
<addaction name="actionNexus"/>
<addaction name="actionAdd_Profile"/>
@@ -1383,6 +1384,18 @@ Right now this has very limited functionality</string> <string>Ctrl+C</string>
</property>
</action>
+ <action name="actionChange_Game">
+ <property name="icon">
+ <iconset resource="resources.qrc">
+ <normaloff>:/MO/gui/app_icon</normaloff>:/MO/gui/app_icon</iconset>
+ </property>
+ <property name="text">
+ <string>Change Game</string>
+ </property>
+ <property name="toolTip">
+ <string>Open the game selection dialog</string>
+ </property>
+ </action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
diff --git a/src/nxmaccessmanager.cpp b/src/nxmaccessmanager.cpp index 3f90647b..17c50e35 100644 --- a/src/nxmaccessmanager.cpp +++ b/src/nxmaccessmanager.cpp @@ -215,7 +215,6 @@ void NXMAccessManager::login(const QString &username, const QString &password) emit loginSuccessful(false);
return;
}
-
m_Username = username;
m_Password = password;
pageLogin();
@@ -237,7 +236,6 @@ QString NXMAccessManager::userAgent(const QString &subModule) const void NXMAccessManager::pageLogin()
{
qDebug("logging %s in on Nexus", qPrintable(m_Username));
-
QString requestString = (Nexus_Management_URL + "/Sessions/?Login&uri=%1")
.arg(QString(QUrl::toPercentEncoding(Nexus_Management_URL)));
diff --git a/src/resources.qrc b/src/resources.qrc index 8434b367..d357801c 100644 --- a/src/resources.qrc +++ b/src/resources.qrc @@ -26,7 +26,6 @@ <file alias="update_available">resources/software-update-available.png</file> <file alias="important">resources/emblem-important.png</file> <file alias="check">resources/check.png</file> - <file>mo_icon.ico</file> <file alias="warning">resources/dialog-warning.png</file> <file alias="emblem_backup">resources/symbol-backup.png</file> <file alias="icon_tools">resources/applications-accessories.png</file> @@ -68,6 +67,8 @@ <file alias="active">resources/status_active.png</file> <file alias="awaiting">resources/status_awaiting.png</file> <file alias="inactive">resources/status_inactive.png</file> + <file alias="app_icon">resources/mo_icon.png</file> + <file alias="package">resources/package.png</file> </qresource> <qresource prefix="/MO/gui/content"> <file alias="plugin">resources/contents/jigsaw-piece.png</file> diff --git a/src/resources/mo_icon.png b/src/resources/mo_icon.png Binary files differnew file mode 100644 index 00000000..c926d722 --- /dev/null +++ b/src/resources/mo_icon.png diff --git a/src/resources/package.png b/src/resources/package.png Binary files differnew file mode 100644 index 00000000..4b55b504 --- /dev/null +++ b/src/resources/package.png diff --git a/src/settingsdialog.cpp b/src/settingsdialog.cpp index c66cc243..0d86018c 100644 --- a/src/settingsdialog.cpp +++ b/src/settingsdialog.cpp @@ -217,18 +217,6 @@ void SettingsDialog::on_associateButton_clicked() Settings::instance().registerAsNXMHandler(true); } -void SettingsDialog::on_changeInstanceButton_clicked() -{ - if (QMessageBox::question(this, tr("Are you sure?"), - tr("This will restart MO, continue?"), - QMessageBox::Yes | QMessageBox::Cancel) - == QMessageBox::Yes) { - InstanceManager().clearCurrentInstance(); - this->reject(); - qApp->exit(INT_MAX); - } -} - void SettingsDialog::on_clearCacheButton_clicked() { QDir(Settings::instance().getCacheDirectory()).removeRecursively(); diff --git a/src/settingsdialog.h b/src/settingsdialog.h index 1ae21015..658fbce4 100644 --- a/src/settingsdialog.h +++ b/src/settingsdialog.h @@ -52,21 +52,6 @@ signals: void resetDialogs();
-private slots:
- void on_clearCacheButton_clicked();
-
-private slots:
- void on_browseBaseDirBtn_clicked();
-
-private slots:
- void on_browseOverwriteDirBtn_clicked();
-
-private slots:
- void on_browseProfilesDirBtn_clicked();
-
-private slots:
- void on_changeInstanceButton_clicked();
-
private:
void storeSettings(QListWidgetItem *pluginItem);
@@ -92,6 +77,14 @@ private slots: void on_associateButton_clicked();
+ void on_clearCacheButton_clicked();
+
+ void on_browseBaseDirBtn_clicked();
+
+ void on_browseOverwriteDirBtn_clicked();
+
+ void on_browseProfilesDirBtn_clicked();
+
private:
Ui::SettingsDialog *ui;
};
diff --git a/src/settingsdialog.ui b/src/settingsdialog.ui index 9ebed3b8..1f751da8 100644 --- a/src/settingsdialog.ui +++ b/src/settingsdialog.ui @@ -125,19 +125,6 @@ If you use pre-releases, never contact me directly by e-mail or via private mess </widget>
</item>
<item>
- <spacer name="verticalSpacer_7">
- <property name="orientation">
- <enum>Qt::Vertical</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>20</width>
- <height>40</height>
- </size>
- </property>
- </spacer>
- </item>
- <item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>User interface</string>
@@ -183,6 +170,19 @@ If you use pre-releases, never contact me directly by e-mail or via private mess </widget>
</item>
<item>
+ <spacer name="verticalSpacer">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
<widget class="QPushButton" name="categoriesBtn">
<property name="toolTip">
<string>Modify the categories available to arrange your mods.</string>
@@ -198,32 +198,6 @@ If you use pre-releases, never contact me directly by e-mail or via private mess </layout>
</widget>
</item>
- <item>
- <spacer name="verticalSpacer">
- <property name="orientation">
- <enum>Qt::Vertical</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>20</width>
- <height>40</height>
- </size>
- </property>
- </spacer>
- </item>
- <item>
- <widget class="QPushButton" name="changeInstanceButton">
- <property name="toolTip">
- <string>Restart MO and choose a different set of data paths.</string>
- </property>
- <property name="whatsThis">
- <string>This will restart MO and give you opportunity to switch to a different set of data paths.</string>
- </property>
- <property name="text">
- <string>Change Instance</string>
- </property>
- </widget>
- </item>
</layout>
</widget>
<widget class="QWidget" name="pathsTab">
|
