diff options
| author | Tannin <devnull@localhost> | 2013-08-30 20:59:12 +0200 |
|---|---|---|
| committer | Tannin <devnull@localhost> | 2013-08-30 20:59:12 +0200 |
| commit | 9c31cfa915f71adee8579aa97c12b64903ec9446 (patch) | |
| tree | 63f1b92b8a596df17849f1c5d2ee7e911d879a61 /src/settings.cpp | |
| parent | 91dd38cb292035b5ca23c531f0383bb283c8700e (diff) | |
- the download manager now registers download speed. Right now this is only used
to display an average speed on the settings menu
- added a python27.dll compiled with vc100. This can now be bundled without introducing more dependencies
- bugfix: extracting now stops after an error
- bugfix: the way hook.dll caused CREATE_ALWAYS/CREATE_NEW to always write into overwrite could lead to the
file being created when the call should have failed (because the file existed and was protected)
- bugfix: GetPrivateProfileString does NOT properly report files as missing. This means that
the ini-query optimization could optimize away requests that should work
- bugfix: fomod installer couldn't display images because they were unpacked to the wrong temporary location
- bugfix: When disabling local saves and choosing to delete the saves nothing happened
- bugfix: the python plugin couldn't find the pyqt libraries
Diffstat (limited to 'src/settings.cpp')
| -rw-r--r-- | src/settings.cpp | 41 |
1 files changed, 31 insertions, 10 deletions
diff --git a/src/settings.cpp b/src/settings.cpp index 61c8dd6d..39b6dba7 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -153,6 +153,24 @@ QString Settings::getDownloadDirectory() const return QDir::toNativeSeparators(m_Settings.value("Settings/download_directory", ToQString(GameInfo::instance().getDownloadDir())).toString()); } + +void Settings::setDownloadSpeed(const QString &serverName, int bytesPerSecond) +{ + m_Settings.beginGroup("Servers"); + + foreach (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; @@ -293,8 +311,11 @@ void Settings::updateServers(const QList<ServerInfo> &servers) // not yet known server QVariantMap newVal; newVal["premium"] = server.premium; - newVal["preferred"] = server.preferred; + newVal["preferred"] = server.preferred ? 1 : 0; newVal["lastSeen"] = server.lastSeen; + newVal["downloadCount"] = 0; + newVal["downloadSpeed"] = 0.0; + m_Settings.setValue(server.name, newVal); } else { QVariantMap data = m_Settings.value(server.name).toMap(); @@ -493,14 +514,6 @@ void Settings::query(QWidget *parent) passwordEdit->setText(deObfuscate(m_Settings.value("Settings/nexus_password", "").toString())); } -/* bool registryWritable = false; - bool nxmHandler = isNXMHandler(®istryWritable); - handleNXMBox->setChecked(nxmHandler); - if (!registryWritable) { - handleNXMBox->setIcon(QIcon(":/MO/gui/locked")); - handleNXMBox->setToolTip(tr("Administrative rights required to change this.")); - }*/ - downloadDirEdit->setText(getDownloadDirectory()); modDirEdit->setText(getModDirectory()); cacheDirEdit->setText(getCacheDirectory()); @@ -520,7 +533,15 @@ void Settings::query(QWidget *parent) foreach (const QString &key, m_Settings.childKeys()) { QVariantMap val = m_Settings.value(key).toMap(); QString type = val["premium"].toBool() ? "(premium)" : "(free)"; - QListWidgetItem *newItem = new QListWidgetItemEx<int>(key + " " + type, Qt::UserRole + 1); + + QString descriptor = key + " " + type; + if (val.contains("downloadSpeed") && val.contains("downloadCount") && (val["downloadCount"].toInt() > 0)) { + int bps = static_cast<int>(val["downloadSpeed"].toDouble() / val["downloadCount"].toInt()); + descriptor += QString(" (%1 kbps)").arg(bps / 1024); + } + + QListWidgetItem *newItem = new QListWidgetItemEx<int>(descriptor, Qt::UserRole + 1); + newItem->setData(Qt::UserRole, key); newItem->setData(Qt::UserRole + 1, val["preferred"].toInt()); if (val["preferred"].toInt() > 0) { |
