summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mainwindow.cpp52
-rw-r--r--src/settings.cpp55
-rw-r--r--src/settings.h8
3 files changed, 99 insertions, 16 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index f0e2fe56..6e77f507 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -1194,7 +1194,7 @@ void MainWindow::hookUpWindowTutorials()
QString firstLine = QString::fromUtf8(file.readLine());
if (firstLine.startsWith("//WIN")) {
QString windowName = firstLine.mid(6).trimmed();
- if (!m_OrganizerCore.settings().directInterface().value("CompletedWindowTutorials/" + windowName, false).toBool()) {
+ if (!m_OrganizerCore.settings().isTutorialCompleted(windowName)) {
TutorialManager::instance().activateTutorial(windowName, fileName);
}
}
@@ -3017,7 +3017,7 @@ void MainWindow::untrack_clicked()
void MainWindow::windowTutorialFinished(const QString &windowName)
{
- m_OrganizerCore.settings().directInterface().setValue(QString("CompletedWindowTutorials/") + windowName, true);
+ m_OrganizerCore.settings().setTutorialCompleted(windowName);
}
void MainWindow::overwriteClosed(int)
@@ -5636,7 +5636,9 @@ void MainWindow::nxmEndorsementsAvailable(QVariant userData, QVariant resultData
if (Settings::instance().endorsementIntegration()) {
if (result->first == "skyrimspecialedition" && result->second.first == gamePlugin->nexusModOrganizerID()) {
- Settings::instance().directInterface().setValue("endorse_state", result->second.second);
+ m_OrganizerCore.settings().setEndorsementState(
+ endorsementStateFromString(result->second.second));
+
toggleMO2EndorseState();
}
}
@@ -5649,7 +5651,9 @@ void MainWindow::nxmEndorsementsAvailable(QVariant userData, QVariant resultData
auto iter = sorted.equal_range(gamePlugin->gameNexusName());
for (auto result = iter.first; result != iter.second; ++result) {
if (result->second.first == gamePlugin->nexusModOrganizerID()) {
- Settings::instance().directInterface().setValue("endorse_state", result->second.second);
+ m_OrganizerCore.settings().setEndorsementState(
+ endorsementStateFromString(result->second.second));
+
toggleMO2EndorseState();
break;
}
@@ -5829,15 +5833,41 @@ void MainWindow::nxmModInfoAvailable(QString gameName, int modID, QVariant userD
void MainWindow::nxmEndorsementToggled(QString, int, QVariant, QVariant resultData, int)
{
- QMap results = resultData.toMap();
- if (results["status"].toString().compare("Endorsed") == 0) {
- QMessageBox::information(this, tr("Thank you!"), tr("Thank you for your endorsement!"));
- Settings::instance().directInterface().setValue("endorse_state", "Endorsed");
- } else if (results["status"].toString().compare("Abstained") == 0) {
- QMessageBox::information(this, tr("Okay."), tr("This mod will not be endorsed and will no longer ask you to endorse."));
- Settings::instance().directInterface().setValue("endorse_state", "Abstained");
+ const QMap results = resultData.toMap();
+
+ auto itor = results.find("status");
+ if (itor == results.end()) {
+ log::error("endorsement response has no status");
+ return;
+ }
+
+ const auto s = endorsementStateFromString(itor->toString());
+
+ switch (s)
+ {
+ case EndorsementState::Accepted:
+ {
+ QMessageBox::information(this, tr("Thank you!"), tr("Thank you for your endorsement!"));
+ break;
+ }
+
+ case EndorsementState::Refused:
+ {
+ // don't spam message boxes if the user doesn't want to endorse
+ log::info("Mod Organizer will not be endorsed and will no longer ask you to endorse.");
+ break;
+ }
+
+ case EndorsementState::NoDecision:
+ {
+ log::error("bad status '{}' in endorsement response", itor->toString());
+ return;
+ }
}
+
+ m_OrganizerCore.settings().setEndorsementState(s);
toggleMO2EndorseState();
+
if (!disconnect(sender(), SIGNAL(nxmEndorsementToggled(QString, int, QVariant, QVariant, int)),
this, SLOT(nxmEndorsementToggled(QString, int, QVariant, QVariant, int)))) {
log::error("failed to disconnect endorsement slot");
diff --git a/src/settings.cpp b/src/settings.cpp
index 882984f3..af32a082 100644
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -39,6 +39,34 @@ std::optional<T> getOptional(
}
+EndorsementState endorsementStateFromString(const QString& s)
+{
+ if (s == "Endorsed") {
+ return EndorsementState::Accepted;
+ } else if (s == "Abstained") {
+ return EndorsementState::Refused;
+ } else {
+ return EndorsementState::NoDecision;
+ }
+}
+
+QString toString(EndorsementState s)
+{
+ switch (s)
+ {
+ case EndorsementState::Accepted:
+ return "Endorsed";
+
+ case EndorsementState::Refused:
+ return "Abstained";
+
+ case EndorsementState::NoDecision: // fall-through
+ default:
+ return {};
+ }
+}
+
+
QString widgetNameWithTopLevel(const QWidget* widget)
{
QStringList components;
@@ -697,13 +725,17 @@ bool Settings::endorsementIntegration() const
EndorsementState Settings::endorsementState() const
{
const auto v = getOptional<QString>(m_Settings, "endorse_state");
+ return endorsementStateFromString(v.value_or(""));
+}
- if (!v) {
- return EndorsementState::NoDecision;
- } else if (*v == "Abstained") {
- return EndorsementState::Refused;
+void Settings::setEndorsementState(EndorsementState s)
+{
+ const auto v = toString(s);
+
+ if (v.isEmpty()) {
+ m_Settings.remove("endorse_state");
} else {
- return EndorsementState::Accepted;
+ m_Settings.setValue("endorse_state", v);
}
}
@@ -935,6 +967,19 @@ void Settings::setExecutables(const std::vector<std::map<QString, QVariant>>& v)
m_Settings.endArray();
}
+bool Settings::isTutorialCompleted(const QString& windowName) const
+{
+ const auto v = getOptional<bool>(
+ m_Settings, "CompletedWindowTutorials/" + windowName);
+
+ return v.value_or(false);
+}
+
+void Settings::setTutorialCompleted(const QString& windowName, bool b)
+{
+ m_Settings.setValue("CompletedWindowTutorials/" + windowName, true);
+}
+
std::optional<int> Settings::getIndex(QComboBox* cb) const
{
return getOptional<int>(m_Settings, indexSettingName(cb));
diff --git a/src/settings.h b/src/settings.h
index 167c74fc..5044af98 100644
--- a/src/settings.h
+++ b/src/settings.h
@@ -98,6 +98,10 @@ enum class EndorsementState
NoDecision
};
+EndorsementState endorsementStateFromString(const QString& s);
+QString toString(EndorsementState s);
+
+
/**
* manages the settings for Mod Organizer. The settings are not cached
* inside the class but read/written directly from/to disc
@@ -226,6 +230,8 @@ public:
std::vector<std::map<QString, QVariant>> getExecutables() const;
void setExecutables(const std::vector<std::map<QString, QVariant>>& v);
+ bool isTutorialCompleted(const QString& windowName) const;
+ void setTutorialCompleted(const QString& windowName, bool b=true);
std::optional<int> getIndex(QComboBox* cb) const;
void saveIndex(const QComboBox* cb);
@@ -364,6 +370,8 @@ public:
bool endorsementIntegration() const;
EndorsementState endorsementState() const;
+ void setEndorsementState(EndorsementState s);
+ void setEndorsementState(const QString& s);
/**
* @return true if the API counter should be hidden