summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorisanae <14251494+isanae@users.noreply.github.com>2019-08-26 00:21:41 -0400
committerisanae <14251494+isanae@users.noreply.github.com>2019-08-26 00:21:41 -0400
commit7395fbb7544740a136884e103cb0829bd10b5655 (patch)
tree06131c395344d1bd08eb3a8b40e4f22a66b66e69 /src
parentb1687380c5c10342699f95361e30f18a32bad585 (diff)
made ServerInfo a class
moved server functions together in Settings
Diffstat (limited to 'src')
-rw-r--r--src/mainwindow.cpp10
-rw-r--r--src/serverinfo.cpp31
-rw-r--r--src/serverinfo.h20
-rw-r--r--src/settings.cpp86
-rw-r--r--src/settings.h26
5 files changed, 107 insertions, 66 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index f1a2047f..b6ae59a1 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -5909,11 +5909,11 @@ void MainWindow::nxmDownloadURLs(QString, int, int, QVariant, QVariant resultDat
QList<ServerInfo> servers;
for (const QVariant &server : serverList) {
QVariantMap serverInfo = server.toMap();
- ServerInfo info;
- info.name = serverInfo["short_name"].toString();
- info.premium = serverInfo["name"].toString().contains("Premium", Qt::CaseInsensitive);
- info.lastSeen = QDate::currentDate();
- info.preferred = serverInfo["short_name"].toString().contains("CDN", Qt::CaseInsensitive);
+ ServerInfo info(
+ serverInfo["short_name"].toString(),
+ serverInfo["name"].toString().contains("Premium", Qt::CaseInsensitive),
+ QDate::currentDate(),
+ serverInfo["short_name"].toString().contains("CDN", Qt::CaseInsensitive));
servers.append(info);
}
m_OrganizerCore.settings().updateServers(servers);
diff --git a/src/serverinfo.cpp b/src/serverinfo.cpp
index e96b69d2..5912c226 100644
--- a/src/serverinfo.cpp
+++ b/src/serverinfo.cpp
@@ -1 +1,32 @@
#include "serverinfo.h"
+
+ServerInfo::ServerInfo()
+ : ServerInfo({}, false, {}, false)
+{
+}
+
+ServerInfo::ServerInfo(QString n, bool premium, QDate last, bool preferred) :
+ m_name(std::move(n)), m_premium(premium), m_lastSeen(std::move(last)),
+ m_preferred(preferred)
+{
+}
+
+const QString& ServerInfo::name() const
+{
+ return m_name;
+}
+
+bool ServerInfo::isPremium() const
+{
+ return m_premium;
+}
+
+const QDate& ServerInfo::lastSeen() const
+{
+ return m_lastSeen;
+}
+
+bool ServerInfo::isPreferred() const
+{
+ return m_preferred;
+}
diff --git a/src/serverinfo.h b/src/serverinfo.h
index 8e5e935a..79b90e77 100644
--- a/src/serverinfo.h
+++ b/src/serverinfo.h
@@ -5,12 +5,22 @@
#include <QDate>
#include <QMetaType>
-struct ServerInfo
+class ServerInfo
{
- QString name;
- bool premium;
- QDate lastSeen;
- bool preferred;
+public:
+ ServerInfo();
+ ServerInfo(QString name, bool premium, QDate lastSeen, bool preferred);
+
+ const QString& name() const;
+ bool isPremium() const;
+ const QDate& lastSeen() const;
+ bool isPreferred() const;
+
+private:
+ QString m_name;
+ bool m_premium;
+ QDate m_lastSeen;
+ bool m_preferred;
};
Q_DECLARE_METATYPE(ServerInfo)
diff --git a/src/settings.cpp b/src/settings.cpp
index 9c9e4c4d..9975642b 100644
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -414,40 +414,6 @@ void Settings::setUsePrereleases(bool b)
m_Settings.setValue("Settings/use_prereleases", b);
}
-void Settings::setDownloadSpeed(const QString &serverName, int bytesPerSecond)
-{
- m_Settings.beginGroup("Servers");
-
- for (const QString &serverKey : m_Settings.childKeys()) {
- QVariantMap data = m_Settings.value(serverKey).toMap();
- if (serverKey == serverName) {
- data["downloadCount"] = data["downloadCount"].toInt() + 1;
- data["downloadSpeed"] = data["downloadSpeed"].toDouble() + static_cast<double>(bytesPerSecond);
- m_Settings.setValue(serverKey, data);
- }
- }
-
- m_Settings.endGroup();
- m_Settings.sync();
-}
-
-std::map<QString, int> Settings::getPreferredServers()
-{
- std::map<QString, int> result;
- m_Settings.beginGroup("Servers");
-
- for (const QString &serverKey : m_Settings.childKeys()) {
- QVariantMap data = m_Settings.value(serverKey).toMap();
- int preference = data["preferred"].toInt();
- if (preference > 0) {
- result[serverKey] = preference;
- }
- }
- m_Settings.endGroup();
-
- return result;
-}
-
QString Settings::getConfigurablePath(const QString &key,
const QString &def,
bool resolve) const
@@ -884,28 +850,62 @@ void Settings::setLanguage(const QString& name)
m_Settings.setValue("Settings/language", name);
}
+void Settings::setDownloadSpeed(const QString &serverName, int bytesPerSecond)
+{
+ m_Settings.beginGroup("Servers");
+
+ for (const QString &serverKey : m_Settings.childKeys()) {
+ QVariantMap data = m_Settings.value(serverKey).toMap();
+ if (serverKey == serverName) {
+ data["downloadCount"] = data["downloadCount"].toInt() + 1;
+ data["downloadSpeed"] = data["downloadSpeed"].toDouble() + static_cast<double>(bytesPerSecond);
+ m_Settings.setValue(serverKey, data);
+ }
+ }
+
+ m_Settings.endGroup();
+ m_Settings.sync();
+}
+
+std::map<QString, int> Settings::getPreferredServers()
+{
+ std::map<QString, int> result;
+ m_Settings.beginGroup("Servers");
+
+ for (const QString &serverKey : m_Settings.childKeys()) {
+ QVariantMap data = m_Settings.value(serverKey).toMap();
+ int preference = data["preferred"].toInt();
+ if (preference > 0) {
+ result[serverKey] = preference;
+ }
+ }
+ m_Settings.endGroup();
+
+ return result;
+}
+
void Settings::updateServers(const QList<ServerInfo> &servers)
{
m_Settings.beginGroup("Servers");
QStringList oldServerKeys = m_Settings.childKeys();
for (const ServerInfo &server : servers) {
- if (!oldServerKeys.contains(server.name)) {
+ if (!oldServerKeys.contains(server.name())) {
// not yet known server
QVariantMap newVal;
- newVal["premium"] = server.premium;
- newVal["preferred"] = server.preferred ? 1 : 0;
- newVal["lastSeen"] = server.lastSeen;
+ newVal["premium"] = server.isPremium();
+ newVal["preferred"] = server.isPreferred() ? 1 : 0;
+ newVal["lastSeen"] = server.lastSeen();
newVal["downloadCount"] = 0;
newVal["downloadSpeed"] = 0.0;
- m_Settings.setValue(server.name, newVal);
+ m_Settings.setValue(server.name(), newVal);
} else {
- QVariantMap data = m_Settings.value(server.name).toMap();
- data["lastSeen"] = server.lastSeen;
- data["premium"] = server.premium;
+ QVariantMap data = m_Settings.value(server.name()).toMap();
+ data["lastSeen"] = server.lastSeen();
+ data["premium"] = server.isPremium();
- m_Settings.setValue(server.name, data);
+ m_Settings.setValue(server.name(), data);
}
}
diff --git a/src/settings.h b/src/settings.h
index 21776169..4662ed19 100644
--- a/src/settings.h
+++ b/src/settings.h
@@ -33,7 +33,7 @@ namespace MOBase {
class QSplitter;
class PluginContainer;
-struct ServerInfo;
+class ServerInfo;
class Settings;
class ExpanderWidget;
@@ -191,13 +191,6 @@ public:
bool lockGUI() const;
/**
- * @brief register download speed
- * @param url complete download url
- * @param bytesPerSecond download size in bytes per second
- */
- void setDownloadSpeed(const QString &serverName, int bytesPerSecond);
-
- /**
* the steam appid is assigned by the steam platform to each product sold there.
* The appid may differ between different versions of a game so it may be impossible
* for Mod Organizer to automatically recognize it, though usually it does
@@ -217,11 +210,6 @@ public:
QString getDownloadDirectory(bool resolve = true) const;
/**
- * retrieve a sorted list of preferred servers
- */
- std::map<QString, int> getPreferredServers();
-
- /**
* retrieve the directory where mods are stored (with native separators)
**/
QString getModDirectory(bool resolve = true) const;
@@ -494,6 +482,18 @@ public:
void setLanguage(const QString& name);
/**
+ * @brief register download speed
+ * @param url complete download url
+ * @param bytesPerSecond download size in bytes per second
+ */
+ void setDownloadSpeed(const QString &serverName, int bytesPerSecond);
+
+ /**
+ * retrieve a sorted list of preferred servers
+ */
+ std::map<QString, int> getPreferredServers();
+
+ /**
* @brief updates the list of known servers
* @param list of servers from a recent query
*/