diff options
| author | isanae <14251494+isanae@users.noreply.github.com> | 2019-08-26 00:21:41 -0400 |
|---|---|---|
| committer | isanae <14251494+isanae@users.noreply.github.com> | 2019-08-26 00:21:41 -0400 |
| commit | 7395fbb7544740a136884e103cb0829bd10b5655 (patch) | |
| tree | 06131c395344d1bd08eb3a8b40e4f22a66b66e69 /src/settings.cpp | |
| parent | b1687380c5c10342699f95361e30f18a32bad585 (diff) | |
made ServerInfo a class
moved server functions together in Settings
Diffstat (limited to 'src/settings.cpp')
| -rw-r--r-- | src/settings.cpp | 86 |
1 files changed, 43 insertions, 43 deletions
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); } } |
