From 9c31cfa915f71adee8579aa97c12b64903ec9446 Mon Sep 17 00:00:00 2001 From: Tannin Date: Fri, 30 Aug 2013 20:59:12 +0200 Subject: - 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 --- src/settings.cpp | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) (limited to 'src/settings.cpp') 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(bytesPerSecond); + m_Settings.setValue(serverKey, data); + } + } + + m_Settings.endGroup(); + m_Settings.sync(); +} + std::map Settings::getPreferredServers() { std::map result; @@ -293,8 +311,11 @@ void Settings::updateServers(const QList &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(key + " " + type, Qt::UserRole + 1); + + QString descriptor = key + " " + type; + if (val.contains("downloadSpeed") && val.contains("downloadCount") && (val["downloadCount"].toInt() > 0)) { + int bps = static_cast(val["downloadSpeed"].toDouble() / val["downloadCount"].toInt()); + descriptor += QString(" (%1 kbps)").arg(bps / 1024); + } + + QListWidgetItem *newItem = new QListWidgetItemEx(descriptor, Qt::UserRole + 1); + newItem->setData(Qt::UserRole, key); newItem->setData(Qt::UserRole + 1, val["preferred"].toInt()); if (val["preferred"].toInt() > 0) { -- cgit v1.3.1