From 5e5681709ab878f3aa6cf1344af44e8ae9544987 Mon Sep 17 00:00:00 2001
From: isanae <14251494+isanae@users.noreply.github.com>
Date: Thu, 11 Jul 2019 01:55:31 -0400
Subject: reworked the nexus connection panel moved most of the stuff into a
new NexusSSOLogin class
---
src/settingsdialog.ui | 351 ++++++++++++++++++++++++++++++++++----------------
1 file changed, 242 insertions(+), 109 deletions(-)
(limited to 'src/settingsdialog.ui')
diff --git a/src/settingsdialog.ui b/src/settingsdialog.ui
index faaf1653..dfbde943 100644
--- a/src/settingsdialog.ui
+++ b/src/settingsdialog.ui
@@ -451,111 +451,244 @@ If you use pre-releases, never contact me directly by e-mail or via private mess
Nexus
-
+
-
-
-
- Allows Mod Organizer to connect to the Nexus for downloading mods, checking for updates, and other such things.
-
-
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
-<html><head><meta name="qrichtext" content="1" /><style type="text/css">
-p, li { white-space: pre-wrap; }
-</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8pt; font-weight:400; font-style:normal;">
-<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Allows Mod Organizer to connect to the Nexus for downloading mods, checking for updates, and other such things. Clicking "Connect to Nexus" will open a Nexus webpage to authorise Mod Organizer. You will need to be logged into your Nexus account. The authorisation is stored in the Windows Credential Manager. Your Nexus username and password are not required or stored by Mod Organizer.</p></body></html>
-
+
- Nexus
+ Nexus Connection
-
+
-
-
-
-
-
-
- Connect to Nexus
-
-
-
-
+
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+ -
+
+
+ Connect to Nexus
+
+
+
+ -
+
+
+ Manually enter the API key and try to login
+
+
+ Enter API Key Manually
+
+
+
+ -
+
+
+ Clear the stored Nexus API key and force reauthorization.
+
+
+ Disconnect from Nexus
+
+
+
+ :/MO/gui/edit_clear:/MO/gui/edit_clear
+
+
+
+ -
+
+
+ Qt::Vertical
+
+
+
+ 0
+ 0
+
+
+
+
+
+
-
-
-
-
-
-
- Qt::Horizontal
-
-
-
- 40
- 20
-
-
-
-
- -
-
-
-
- 0
- 0
-
-
-
- Manually enter the API key and try to login
-
-
- Enter API Key Manually
-
-
-
- -
-
-
- Clear the stored Nexus API key and force reauthorization.
-
-
- Disconnect from Nexus
-
-
-
- :/MO/gui/edit_clear:/MO/gui/edit_clear
-
-
-
- -
-
-
- Remove cache and cookies.
-
-
- Clear Cache
-
-
-
- :/MO/gui/edit_clear:/MO/gui/edit_clear
-
-
-
- -
-
-
- Qt::Horizontal
-
-
-
- 40
- 20
-
-
-
-
-
+
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+ -
+
+
+ QAbstractScrollArea::AdjustToContents
+
+
+
+
+
+
+
+
+
+ -
+
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
-
+
+
+ Nexus Account
+
+
+
-
+
+
+ User ID
+
+
+ Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse
+
+
+
+ -
+
+
+ id
+
+
+
+ -
+
+
+ Username
+
+
+
+ -
+
+
+ username
+
+
+
+ -
+
+
+ Account
+
+
+
+ -
+
+
+ account
+
+
+
+
+
+
+ -
+
+
+ Statistics
+
+
+
-
+
+
+ Daily requests
+
+
+
+ -
+
+
+ Hourly requests
+
+
+
+ -
+
+
+ hourly requests
+
+
+
+ -
+
+
+ Requests queued
+
+
+
+ -
+
+
+ queued
+
+
+
+ -
+
+
+ daily requests
+
+
+
+
+
+ -
+
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
+
+
-
-
@@ -618,6 +751,20 @@ p, li { white-space: pre-wrap; }
+ -
+
+
+ Remove cache and cookies.
+
+
+ Clear Cache
+
+
+
+ :/MO/gui/edit_clear:/MO/gui/edit_clear
+
+
+
-
@@ -682,19 +829,6 @@ p, li { white-space: pre-wrap; }
- -
-
-
- Qt::Vertical
-
-
-
- 20
- 40
-
-
-
-
@@ -1359,7 +1493,6 @@ programs you are intentionally running.
browseProfilesDirBtn
overwriteDirEdit
browseOverwriteDirBtn
- clearCacheButton
associateButton
knownServersList
preferredServersList
--
cgit v1.3.1
From 45f0a9e78ac876a2a956bc538c6d34358703e338 Mon Sep 17 00:00:00 2001
From: isanae <14251494+isanae@users.noreply.github.com>
Date: Fri, 12 Jul 2019 02:46:31 -0400
Subject: nexus info and stats in settings cleaned up double logging for github
reset validation progress dialog parent just before the main window dies
removed unused APIStats from APIUserAccount, added isValid()
---
src/apiuseraccount.cpp | 22 +++++
src/apiuseraccount.h | 8 +-
src/main.cpp | 8 +-
src/nxmaccessmanager.cpp | 2 +-
src/organizercore.cpp | 2 +-
src/selfupdater.cpp | 2 +-
src/settingsdialog.cpp | 98 ++++++++++++++++-----
src/settingsdialog.h | 6 ++
src/settingsdialog.ui | 218 +++++++++++++++++++++++------------------------
9 files changed, 226 insertions(+), 140 deletions(-)
(limited to 'src/settingsdialog.ui')
diff --git a/src/apiuseraccount.cpp b/src/apiuseraccount.cpp
index 596f8aa7..35a868d5 100644
--- a/src/apiuseraccount.cpp
+++ b/src/apiuseraccount.cpp
@@ -1,10 +1,32 @@
#include "apiuseraccount.h"
+QString localizedUserAccountType(APIUserAccountTypes t)
+{
+ switch (t)
+ {
+ case APIUserAccountTypes::Regular:
+ return QObject::tr("Regular");
+
+ case APIUserAccountTypes::Premium:
+ return QObject::tr("Premium");
+
+ case APIUserAccountTypes::None: // fall-through
+ default:
+ return QObject::tr("None");
+ }
+}
+
+
APIUserAccount::APIUserAccount()
: m_type(APIUserAccountTypes::None)
{
}
+bool APIUserAccount::isValid() const
+{
+ return !m_key.isEmpty();
+}
+
const QString& APIUserAccount::apiKey() const
{
return m_key;
diff --git a/src/apiuseraccount.h b/src/apiuseraccount.h
index 7dd16128..ea4e8685 100644
--- a/src/apiuseraccount.h
+++ b/src/apiuseraccount.h
@@ -18,6 +18,8 @@ enum class APIUserAccountTypes
Premium
};
+QString localizedUserAccountType(APIUserAccountTypes t);
+
/**
* current limits imposed on the user account
@@ -61,6 +63,11 @@ public:
APIUserAccount();
+ /**
+ * whether the user is logged in
+ */
+ bool isValid() const;
+
/**
* api key
*/
@@ -134,7 +141,6 @@ private:
QString m_key, m_id, m_name;
APIUserAccountTypes m_type;
APILimits m_limits;
- APIStats m_stats;
};
#endif // APIUSERACCOUNT_H
diff --git a/src/main.cpp b/src/main.cpp
index 0b078f03..4359c645 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -713,7 +713,13 @@ int runApplication(MOApplication &application, SingleInstance &instance,
mainWindow.activateWindow();
splash.finish(&mainWindow);
- return application.exec();
+
+ const auto ret = application.exec();
+
+ NexusInterface::instance(&pluginContainer)
+ ->getAccessManager()->setTopLevelWidget(nullptr);
+
+ return ret;
}
} catch (const std::exception &e) {
reportError(e.what());
diff --git a/src/nxmaccessmanager.cpp b/src/nxmaccessmanager.cpp
index a331b2e8..196368fd 100644
--- a/src/nxmaccessmanager.cpp
+++ b/src/nxmaccessmanager.cpp
@@ -167,7 +167,7 @@ QString NexusSSOLogin::stateToString(States s, const QString& e)
return QObject::tr("Opened browser, waiting for user...");
case Finished:
- return QObject::tr("Connected.");
+ return QObject::tr("Finished.");
case Timeout:
return QObject::tr(
diff --git a/src/organizercore.cpp b/src/organizercore.cpp
index 87668f4b..eeb69e61 100644
--- a/src/organizercore.cpp
+++ b/src/organizercore.cpp
@@ -2484,7 +2484,7 @@ void OrganizerCore::loginSuccessfulUpdate(bool necessary)
void OrganizerCore::loginFailed(const QString &message)
{
- qDebug().nospace().noquote()
+ qCritical().nospace().noquote()
<< "Nexus API validation failed: " << message;
if (QMessageBox::question(qApp->activeWindow(), tr("Login failed"),
diff --git a/src/selfupdater.cpp b/src/selfupdater.cpp
index 271c621b..e967b27c 100644
--- a/src/selfupdater.cpp
+++ b/src/selfupdater.cpp
@@ -130,7 +130,7 @@ void SelfUpdater::testForUpdate()
m_GitHub.releases(GitHub::Repository("Modorganizer2", "modorganizer"),
[this](const QJsonArray &releases) {
if (releases.isEmpty()) {
- qDebug("Unable to connect to github.com to check version");
+ // error message already logged
return;
}
diff --git a/src/settingsdialog.cpp b/src/settingsdialog.cpp
index df957f87..0dae31ac 100644
--- a/src/settingsdialog.cpp
+++ b/src/settingsdialog.cpp
@@ -55,6 +55,7 @@ public:
: QDialog(parent), ui(new Ui::NexusManualKeyDialog)
{
ui->setupUi(this);
+ ui->key->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont));
connect(ui->openBrowser, &QPushButton::clicked, [&]{ openBrowser(); });
connect(ui->paste, &QPushButton::clicked, [&]{ paste(); });
@@ -111,7 +112,7 @@ SettingsDialog::SettingsDialog(PluginContainer *pluginContainer, Settings* setti
QKeySequence(Qt::Key_Delete), ui->pluginBlacklist);
connect(delShortcut, SIGNAL(activated()), this, SLOT(deleteBlacklistItem()));
- updateNexusButtons();
+ updateNexusState();
}
SettingsDialog::~SettingsDialog()
@@ -399,7 +400,7 @@ void SettingsDialog::on_nexusConnect_clicked()
ui->nexusLog->clear();
m_nexusLogin->start();
- updateNexusButtons();
+ updateNexusState();
}
void SettingsDialog::on_nexusManualKey_clicked()
@@ -421,8 +422,18 @@ void SettingsDialog::on_nexusManualKey_clicked()
}
ui->nexusLog->clear();
- ui->nexusLog->addItem(tr("Checking API key..."));
+ validateKey(key);
+}
+
+void SettingsDialog::on_nexusDisconnect_clicked()
+{
+ clearKey();
+ ui->nexusLog->clear();
+ addNexusLog(tr("Disconnected."));
+}
+void SettingsDialog::validateKey(const QString& key)
+{
if (!m_nexusValidator) {
m_nexusValidator.reset(new NexusKeyValidator(
*NexusInterface::instance(m_PluginContainer)->getAccessManager()));
@@ -436,6 +447,7 @@ void SettingsDialog::on_nexusManualKey_clicked()
};
}
+ addNexusLog(tr("Checking API key..."));
m_nexusValidator->start(key);
}
@@ -444,45 +456,62 @@ void SettingsDialog::onSSOKeyChanged(const QString& key)
if (key.isEmpty()) {
clearKey();
} else {
- setKey(key);
+ addNexusLog(tr("Received API key."));
+ validateKey(key);
}
}
void SettingsDialog::onSSOStateChanged(NexusSSOLogin::States s, const QString& e)
{
- const auto log = NexusSSOLogin::stateToString(s, e);
+ if (s != NexusSSOLogin::Finished) {
+ // finished state is handled in onSSOKeyChanged()
+ const auto log = NexusSSOLogin::stateToString(s, e);
- for (auto&& line : log.split("\n")) {
- ui->nexusLog->addItem(line);
+ for (auto&& line : log.split("\n")) {
+ addNexusLog(line);
+ }
}
- updateNexusButtons();
+ updateNexusState();
}
void SettingsDialog::onValidatorStateChanged(
NexusKeyValidator::States s, const QString& e)
{
- const auto log = NexusKeyValidator::stateToString(s, e);
+ if (s != NexusKeyValidator::Finished) {
+ // finished state is handled in onValidatorFinished()
+ const auto log = NexusKeyValidator::stateToString(s, e);
- for (auto&& line : log.split("\n")) {
- ui->nexusLog->addItem(line);
+ for (auto&& line : log.split("\n")) {
+ addNexusLog(line);
+ }
}
- updateNexusButtons();
+ updateNexusState();
}
void SettingsDialog::onValidatorFinished(const APIUserAccount& user)
{
+ NexusInterface::instance(m_PluginContainer)->setUserAccount(user);
+
if (!user.apiKey().isEmpty()) {
- setKey(user.apiKey());
+ if (setKey(user.apiKey())) {
+ addNexusLog(tr("Linked with Nexus successfully."));
+ }
}
}
+void SettingsDialog::addNexusLog(const QString& s)
+{
+ ui->nexusLog->addItem(s);
+ ui->nexusLog->scrollToBottom();
+}
+
bool SettingsDialog::setKey(const QString& key)
{
m_keyChanged = true;
const bool ret = m_settings->setNexusApiKey(key);
- updateNexusButtons();
+ updateNexusState();
return ret;
}
@@ -490,13 +519,19 @@ bool SettingsDialog::clearKey()
{
m_keyChanged = true;
const auto ret = m_settings->clearNexusApiKey();
- updateNexusButtons();
NexusInterface::instance(m_PluginContainer)->getAccessManager()->clearApiKey();
+ updateNexusState();
return ret;
}
+void SettingsDialog::updateNexusState()
+{
+ updateNexusButtons();
+ updateNexusData();
+}
+
void SettingsDialog::updateNexusButtons()
{
if (m_nexusLogin && m_nexusLogin->isActive()) {
@@ -532,6 +567,32 @@ void SettingsDialog::updateNexusButtons()
}
}
+void SettingsDialog::updateNexusData()
+{
+ const auto user = NexusInterface::instance(m_PluginContainer)
+ ->getAPIUserAccount();
+
+ if (user.isValid()) {
+ ui->nexusUserID->setText(user.id());
+ ui->nexusName->setText(user.name());
+ ui->nexusAccount->setText(localizedUserAccountType(user.type()));
+
+ ui->nexusDailyRequests->setText(QString("%1/%2")
+ .arg(user.limits().remainingDailyRequests)
+ .arg(user.limits().maxDailyRequests));
+
+ ui->nexusHourlyRequests->setText(QString("%1/%2")
+ .arg(user.limits().remainingHourlyRequests)
+ .arg(user.limits().maxHourlyRequests));
+ } else {
+ ui->nexusUserID->setText(tr("N/A"));
+ ui->nexusName->setText(tr("N/A"));
+ ui->nexusAccount->setText(tr("N/A"));
+ ui->nexusDailyRequests->setText(tr("N/A"));
+ ui->nexusHourlyRequests->setText(tr("N/A"));
+ }
+}
+
void SettingsDialog::storeSettings(QListWidgetItem *pluginItem)
{
if (pluginItem != nullptr) {
@@ -599,13 +660,6 @@ void SettingsDialog::on_clearCacheButton_clicked()
NexusInterface::instance(m_PluginContainer)->clearCache();
}
-void SettingsDialog::on_nexusDisconnect_clicked()
-{
- clearKey();
- ui->nexusLog->clear();
- ui->nexusLog->addItem(tr("Disconnected."));
-}
-
void SettingsDialog::normalizePath(QLineEdit *lineEdit)
{
QString text = lineEdit->text();
diff --git a/src/settingsdialog.h b/src/settingsdialog.h
index 1741fc13..c5f487fd 100644
--- a/src/settingsdialog.h
+++ b/src/settingsdialog.h
@@ -145,15 +145,21 @@ private:
std::unique_ptr m_nexusLogin;
std::unique_ptr m_nexusValidator;
+ void validateKey(const QString& key);
bool setKey(const QString& key);
bool clearKey();
+
+ void updateNexusState();
void updateNexusButtons();
+ void updateNexusData();
void onSSOKeyChanged(const QString& key);
void onSSOStateChanged(NexusSSOLogin::States s, const QString& e);
void onValidatorStateChanged(NexusKeyValidator::States s, const QString& e);
void onValidatorFinished(const APIUserAccount& user);
+
+ void addNexusLog(const QString& s);
};
#endif // SETTINGSDIALOG_H
diff --git a/src/settingsdialog.ui b/src/settingsdialog.ui
index dfbde943..fccc8be0 100644
--- a/src/settingsdialog.ui
+++ b/src/settingsdialog.ui
@@ -451,103 +451,7 @@ If you use pre-releases, never contact me directly by e-mail or via private mess
Nexus
-
- -
-
-
- Nexus Connection
-
-
-
-
-
-
-
- 0
-
-
- 0
-
-
- 0
-
-
- 0
-
-
-
-
-
- Connect to Nexus
-
-
-
- -
-
-
- Manually enter the API key and try to login
-
-
- Enter API Key Manually
-
-
-
- -
-
-
- Clear the stored Nexus API key and force reauthorization.
-
-
- Disconnect from Nexus
-
-
-
- :/MO/gui/edit_clear:/MO/gui/edit_clear
-
-
-
- -
-
-
- Qt::Vertical
-
-
-
- 0
- 0
-
-
-
-
-
-
-
- -
-
-
-
- 0
-
-
- 0
-
-
- 0
-
-
- 0
-
-
-
-
-
- QAbstractScrollArea::AdjustToContents
-
-
-
-
-
-
-
-
-
+
-
@@ -569,10 +473,13 @@ If you use pre-releases, never contact me directly by e-mail or via private mess
Nexus Account
+
+ 10
+
-
- User ID
+ User ID:
Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse
@@ -589,21 +496,21 @@ If you use pre-releases, never contact me directly by e-mail or via private mess
-
- Username
+ Name:
-
-
+
- username
+ name
-
- Account
+ Account:
@@ -623,17 +530,27 @@ If you use pre-releases, never contact me directly by e-mail or via private mess
Statistics
+
+ 10
+
-
- Daily requests
+ Daily requests:
+
+
+
+ -
+
+
+ daily requests
-
- Hourly requests
+ Hourly requests:
@@ -644,24 +561,99 @@ If you use pre-releases, never contact me directly by e-mail or via private mess
- -
-
+
+
+
+
+
+
+ -
+
+
+ Nexus Connection
+
+
+
-
+
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
-
+
- Requests queued
+ Connect to Nexus
- -
-
+
-
+
+
+ Manually enter the API key and try to login
+
- queued
+ Enter API Key Manually
- -
-
+
-
+
+
+ Clear the stored Nexus API key and force reauthorization.
+
- daily requests
+ Disconnect from Nexus
+
+
+
+ :/MO/gui/edit_clear:/MO/gui/edit_clear
+
+
+
+ -
+
+
+ Qt::Vertical
+
+
+
+ 0
+ 0
+
+
+
+
+
+
+
+ -
+
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
-
+
+
+ QAbstractScrollArea::AdjustToContents
--
cgit v1.3.1