From e071dfdfaa369a475a2d93df623c1696feee56ba Mon Sep 17 00:00:00 2001
From: isanae <14251494+isanae@users.noreply.github.com>
Date: Fri, 19 Jul 2019 02:47:13 -0400
Subject: changed qCritical() to log::error() removed now unused vlog()
---
src/downloadlist.cpp | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
(limited to 'src/downloadlist.cpp')
diff --git a/src/downloadlist.cpp b/src/downloadlist.cpp
index 5e698e0e..36bc2b7f 100644
--- a/src/downloadlist.cpp
+++ b/src/downloadlist.cpp
@@ -19,12 +19,13 @@ along with Mod Organizer. If not, see .
#include "downloadlist.h"
#include "downloadmanager.h"
+#include
#include
#include
#include
-
#include
+using namespace MOBase;
DownloadList::DownloadList(DownloadManager *manager, QObject *parent)
: QAbstractTableModel(parent), m_Manager(manager)
@@ -192,7 +193,7 @@ void DownloadList::update(int row)
else if (row < this->rowCount())
emit dataChanged(this->index(row, 0, QModelIndex()), this->index(row, this->columnCount(QModelIndex())-1, QModelIndex()));
else
- qCritical("invalid row %d in download list, update failed", row);
+ log::error("invalid row {} in download list, update failed", row);
}
QString DownloadList::sizeFormat(quint64 size) const
--
cgit v1.3.1
From 2eee72da6815f9d5c643b58c95f633e69da5150a Mon Sep 17 00:00:00 2001
From: isanae <14251494+isanae@users.noreply.github.com>
Date: Mon, 26 Aug 2019 04:21:06 -0400
Subject: moved code for byte sizes and speed to uibase added scoped classes
for QSettings groups and arrays servers logged on startup
---
src/downloadlist.cpp | 21 +---
src/downloadlist.h | 2 -
src/downloadmanager.cpp | 19 +---
src/settings.cpp | 270 +++++++++++++++++++++++++++++---------------
src/settingsdialognexus.cpp | 2 +-
5 files changed, 184 insertions(+), 130 deletions(-)
(limited to 'src/downloadlist.cpp')
diff --git a/src/downloadlist.cpp b/src/downloadlist.cpp
index 36bc2b7f..6957f270 100644
--- a/src/downloadlist.cpp
+++ b/src/downloadlist.cpp
@@ -19,6 +19,7 @@ along with Mod Organizer. If not, see .
#include "downloadlist.h"
#include "downloadmanager.h"
+#include
#include
#include
#include
@@ -121,7 +122,7 @@ QVariant DownloadList::data(const QModelIndex &index, int role) const
return QString("%1").arg(m_Manager->getModID(index.row()));
}
}
- case COL_SIZE: return sizeFormat(m_Manager->getFileSize(index.row()));
+ case COL_SIZE: return MOBase::localizedByteSize(m_Manager->getFileSize(index.row()));
case COL_FILETIME: return m_Manager->getFileTime(index.row());
case COL_STATUS:
switch (m_Manager->getState(index.row())) {
@@ -195,21 +196,3 @@ void DownloadList::update(int row)
else
log::error("invalid row {} in download list, update failed", row);
}
-
-QString DownloadList::sizeFormat(quint64 size) const
-{
- qreal calc = size;
- QStringList list;
- list << "MB" << "GB" << "TB";
-
- QStringListIterator i(list);
- QString unit("KB");
-
- calc /= 1024.0;
- while (calc >= 1024.0 && i.hasNext()) {
- unit = i.next();
- calc /= 1024.0;
- }
-
- return QString().setNum(calc, 'f', 2) + " " + unit;
-}
diff --git a/src/downloadlist.h b/src/downloadlist.h
index 6f63f0c8..51ab4541 100644
--- a/src/downloadlist.h
+++ b/src/downloadlist.h
@@ -99,8 +99,6 @@ private:
DownloadManager *m_Manager;
bool m_MetaDisplay;
-
- QString sizeFormat(quint64 size) const;
};
#endif // DOWNLOADLIST_H
diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp
index 93ca1608..a5dc164c 100644
--- a/src/downloadmanager.cpp
+++ b/src/downloadmanager.cpp
@@ -1441,22 +1441,11 @@ void DownloadManager::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
std::get<4>(info->m_SpeedDiff) = ((calc*0.5) + (std::get<4>(info->m_SpeedDiff)*1.5)) / 2;
// calculate the download speed
- double speed = (std::get<4>(info->m_SpeedDiff) * 1000.0) / (5 * 1000);
+ const double speed = (std::get<4>(info->m_SpeedDiff) * 1000.0) / (5 * 1000);
- QString unit;
- if (speed < 1000) {
- unit = "B/s";
- }
- else if (speed < 1000*1024) {
- speed /= 1024;
- unit = "KB/s";
- }
- else {
- speed /= 1024 * 1024;
- unit = "MB/s";
- }
-
- info->m_Progress.second = QString::fromLatin1("%1% - %2 %3").arg(info->m_Progress.first).arg(QString::number(speed, 'f', 1)).arg(unit);
+ info->m_Progress.second = QString::fromLatin1("%1% - %2")
+ .arg(info->m_Progress.first)
+ .arg(MOBase::localizedByteSpeed(speed));
TaskProgressManager::instance().updateProgress(info->m_TaskProgressId, bytesReceived, bytesTotal);
emit update(index);
diff --git a/src/settings.cpp b/src/settings.cpp
index b11bc61c..406544f7 100644
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -27,6 +27,78 @@ along with Mod Organizer. If not, see .
using namespace MOBase;
+class ScopedGroup
+{
+public:
+ ScopedGroup(QSettings& s, const QString& name)
+ : m_settings(s)
+ {
+ m_settings.beginGroup(name);
+ }
+
+ ~ScopedGroup()
+ {
+ m_settings.endGroup();
+ }
+
+ ScopedGroup(const ScopedGroup&) = delete;
+ ScopedGroup& operator=(const ScopedGroup&) = delete;
+
+private:
+ QSettings& m_settings;
+};
+
+
+class ScopedReadArray
+{
+public:
+ ScopedReadArray(QSettings& s, const QString& name)
+ : m_settings(s), m_count(0)
+ {
+ m_count = m_settings.beginReadArray(name);
+ }
+
+ ~ScopedReadArray()
+ {
+ m_settings.endArray();
+ }
+
+ ScopedReadArray(const ScopedReadArray&) = delete;
+ ScopedReadArray& operator=(const ScopedReadArray&) = delete;
+
+ int count() const
+ {
+ return m_count;
+ }
+
+private:
+ QSettings& m_settings;
+ int m_count;
+};
+
+
+class ScopedWriteArray
+{
+public:
+ ScopedWriteArray(QSettings& s, const QString& name)
+ : m_settings(s)
+ {
+ m_settings.beginWriteArray(name);
+ }
+
+ ~ScopedWriteArray()
+ {
+ m_settings.endArray();
+ }
+
+ ScopedWriteArray(const ScopedWriteArray&) = delete;
+ ScopedWriteArray& operator=(const ScopedWriteArray&) = delete;
+
+private:
+ QSettings& m_settings;
+};
+
+
template
std::optional getOptional(
const QSettings& s, const QString& name, std::optional def={})
@@ -206,19 +278,21 @@ void Settings::processUpdates(
}
if (lastVersion < QVersionNumber(2, 2, 0)) {
- m_Settings.beginGroup("Settings");
- m_Settings.remove("steam_password");
- m_Settings.remove("nexus_username");
- m_Settings.remove("nexus_password");
- m_Settings.remove("nexus_login");
- m_Settings.remove("nexus_api_key");
- m_Settings.remove("ask_for_nexuspw");
- m_Settings.remove("nmm_version");
- m_Settings.endGroup();
-
- m_Settings.beginGroup("Servers");
- m_Settings.remove("");
- m_Settings.endGroup();
+ {
+ ScopedGroup sg(m_Settings, "Settings");
+ m_Settings.remove("steam_password");
+ m_Settings.remove("nexus_username");
+ m_Settings.remove("nexus_password");
+ m_Settings.remove("nexus_login");
+ m_Settings.remove("nexus_api_key");
+ m_Settings.remove("ask_for_nexuspw");
+ m_Settings.remove("nmm_version");
+ }
+
+ {
+ ScopedGroup sg(m_Settings, "Servers");
+ m_Settings.remove("");
+ }
}
if (lastVersion < QVersionNumber(2, 2, 1)) {
@@ -251,12 +325,12 @@ void Settings::clearPlugins()
m_PluginSettings.clear();
m_PluginBlacklist.clear();
- int count = m_Settings.beginReadArray("pluginBlacklist");
- for (int i = 0; i < count; ++i) {
+
+ ScopedReadArray sra(m_Settings, "pluginBlacklist");
+ for (int i = 0; i < sra.count(); ++i) {
m_Settings.setArrayIndex(i);
m_PluginBlacklist.insert(m_Settings.value("name").toString());
}
- m_Settings.endArray();
}
bool Settings::pluginBlacklisted(const QString &fileName) const
@@ -876,46 +950,50 @@ ServerList Settings::getServers() const
// in 2.2.1, one key per server is returned
// getting the keys
- m_Settings.beginGroup("Servers");
- const auto keys = m_Settings.childKeys();
- m_Settings.endGroup();
+ QStringList keys;
+
+ {
+ ScopedGroup sg(m_Settings, "Servers");
+ keys = m_Settings.childKeys();
+ }
if (!keys.empty() && keys[0] != "size") {
// old format
return getServersFromOldMap();
}
+
// post 2.2.1 format, array of values
ServerList list;
- const int size = m_Settings.beginReadArray("Servers");
+ {
+ ScopedReadArray sra(m_Settings, "Servers");
- for (int i=0; i 0) {
- lastDownloads.push_back(bytesPerSecond);
+ const auto lastDownloadsString = m_Settings.value("lastDownloads").toString();
+ for (const auto& s : lastDownloadsString.split(" ")) {
+ const auto bytesPerSecond = s.toInt();
+ if (bytesPerSecond > 0) {
+ lastDownloads.push_back(bytesPerSecond);
+ }
}
- }
- ServerInfo server(
- m_Settings.value("name").toString(),
- m_Settings.value("premium").toBool(),
- QDate::fromString(m_Settings.value("lastSeen").toString(), Qt::ISODate),
- m_Settings.value("preferred").toInt(),
- lastDownloads);
+ ServerInfo server(
+ m_Settings.value("name").toString(),
+ m_Settings.value("premium").toBool(),
+ QDate::fromString(m_Settings.value("lastSeen").toString(), Qt::ISODate),
+ m_Settings.value("preferred").toInt(),
+ lastDownloads);
- list.add(std::move(server));
+ list.add(std::move(server));
+ }
}
- m_Settings.endArray();
-
return list;
}
@@ -924,8 +1002,7 @@ ServerList Settings::getServersFromOldMap() const
// for 2.2.1 and before
ServerList list;
-
- m_Settings.beginGroup("Servers");
+ ScopedGroup sg(m_Settings, "Servers");
for (const QString &serverKey : m_Settings.childKeys()) {
QVariantMap data = m_Settings.value(serverKey).toMap();
@@ -943,8 +1020,6 @@ ServerList Settings::getServersFromOldMap() const
list.add(std::move(server));
}
- m_Settings.endGroup();
-
return list;
}
@@ -953,34 +1028,35 @@ void Settings::updateServers(ServerList servers)
// clean up unavailable servers
servers.cleanup();
- m_Settings.beginGroup("Servers");
- m_Settings.remove("");
- m_Settings.endGroup();
-
- m_Settings.beginWriteArray("Servers");
-
- int i=0;
- for (const auto& server : servers) {
- m_Settings.setArrayIndex(i);
-
- m_Settings.setValue("name", server.name());
- m_Settings.setValue("premium", server.isPremium());
- m_Settings.setValue("lastSeen", server.lastSeen().toString(Qt::ISODate));
- m_Settings.setValue("preferred", server.preferred());
+ {
+ ScopedGroup sg(m_Settings, "Servers");
+ m_Settings.remove("");
+ }
- QString lastDownloads;
- for (const auto& speed : server.lastDownloads()) {
- if (speed > 0) {
- lastDownloads += QString("%1 ").arg(speed);
+ {
+ ScopedWriteArray swa(m_Settings, "Servers");
+
+ int i=0;
+ for (const auto& server : servers) {
+ m_Settings.setArrayIndex(i);
+
+ m_Settings.setValue("name", server.name());
+ m_Settings.setValue("premium", server.isPremium());
+ m_Settings.setValue("lastSeen", server.lastSeen().toString(Qt::ISODate));
+ m_Settings.setValue("preferred", server.preferred());
+
+ QString lastDownloads;
+ for (const auto& speed : server.lastDownloads()) {
+ if (speed > 0) {
+ lastDownloads += QString("%1 ").arg(speed);
+ }
}
- }
- m_Settings.setValue("lastDownloads", lastDownloads.trimmed());
+ m_Settings.setValue("lastDownloads", lastDownloads.trimmed());
- ++i;
+ ++i;
+ }
}
-
- m_Settings.endArray();
}
void Settings::addBlacklistPlugin(const QString &fileName)
@@ -992,23 +1068,22 @@ void Settings::addBlacklistPlugin(const QString &fileName)
void Settings::writePluginBlacklist()
{
m_Settings.remove("pluginBlacklist");
- m_Settings.beginWriteArray("pluginBlacklist");
+
+ ScopedWriteArray swa(m_Settings, "pluginBlacklist");
int idx = 0;
for (const QString &plugin : m_PluginBlacklist) {
m_Settings.setArrayIndex(idx++);
m_Settings.setValue("name", plugin);
}
-
- m_Settings.endArray();
}
std::map Settings::getRecentDirectories() const
{
std::map map;
- const int size = m_Settings.beginReadArray("recentDirectories");
+ ScopedReadArray sra(m_Settings, "recentDirectories");
- for (int i=0; i Settings::getRecentDirectories() const
}
}
- m_Settings.endArray();
-
return map;
}
void Settings::setRecentDirectories(const std::map& map)
{
m_Settings.remove("recentDirectories");
- m_Settings.beginWriteArray("recentDirectories");
+
+ ScopedWriteArray swa(m_Settings, "recentDirectories");
int index = 0;
for (auto&& p : map) {
@@ -1037,16 +1111,14 @@ void Settings::setRecentDirectories(const std::map& map)
++index;
}
-
- m_Settings.endArray();
}
std::vector> Settings::getExecutables() const
{
- const int count = m_Settings.beginReadArray("customExecutables");
+ ScopedReadArray sra(m_Settings, "customExecutables");
std::vector> v;
- for (int i=0; i map;
@@ -1059,15 +1131,14 @@ std::vector> Settings::getExecutables() const
v.push_back(map);
}
- m_Settings.endArray();
-
return v;
}
void Settings::setExecutables(const std::vector>& v)
{
m_Settings.remove("customExecutables");
- m_Settings.beginWriteArray("customExecutables");
+
+ ScopedWriteArray swa(m_Settings, "customExecutables");
int i = 0;
@@ -1080,8 +1151,6 @@ void Settings::setExecutables(const std::vector>& v)
++i;
}
-
- m_Settings.endArray();
}
bool Settings::isTutorialCompleted(const QString& windowName) const
@@ -1154,9 +1223,8 @@ void Settings::setQuestionFileButton(
void Settings::resetQuestionButtons()
{
- m_Settings.beginGroup("DialogChoices");
+ ScopedGroup sg(m_Settings, "DialogChoices");
m_Settings.remove("");
- m_Settings.endGroup();
}
std::optional Settings::getIndex(const QComboBox* cb) const
@@ -1248,17 +1316,34 @@ void Settings::dump() const
log::debug("settings:");
- m_Settings.beginGroup("Settings");
+ {
+ ScopedGroup sg(m_Settings, "Settings");
- for (auto k : m_Settings.allKeys()) {
- if (ignore.contains(k, Qt::CaseInsensitive)) {
- continue;
- }
+ for (auto k : m_Settings.allKeys()) {
+ if (ignore.contains(k, Qt::CaseInsensitive)) {
+ continue;
+ }
- log::debug(" . {}={}", k, m_Settings.value(k).toString());
+ log::debug(" . {}={}", k, m_Settings.value(k).toString());
+ }
}
- m_Settings.endGroup();
+ log::debug("servers:");
+
+ for (const auto& server : getServers()) {
+ QString lastDownloads;
+ for (auto speed : server.lastDownloads()) {
+ lastDownloads += QString("%1 ").arg(speed);
+ }
+
+ log::debug(
+ " . {} premium={} lastSeen={} preferred={} lastDownloads={}",
+ server.name(),
+ server.isPremium() ? "yes" : "no",
+ server.lastSeen().toString(Qt::ISODate),
+ server.preferred(),
+ lastDownloads.trimmed());
+ }
}
@@ -1278,9 +1363,8 @@ void GeometrySettings::resetIfNeeded()
return;
}
- m_Settings.beginGroup("geometry");
+ ScopedGroup sg(m_Settings, "geometry");
m_Settings.remove("");
- m_Settings.endGroup();
}
void GeometrySettings::saveGeometry(const QWidget* w)
diff --git a/src/settingsdialognexus.cpp b/src/settingsdialognexus.cpp
index f2bd3ab5..3de1a6ba 100644
--- a/src/settingsdialognexus.cpp
+++ b/src/settingsdialognexus.cpp
@@ -89,7 +89,7 @@ NexusSettingsTab::NexusSettingsTab(Settings& s, SettingsDialog& d)
const auto averageSpeed = server.averageSpeed();
if (averageSpeed > 0) {
- descriptor += QString(" (%1 kbps)").arg(averageSpeed / 1024);
+ descriptor += QString(" (%1)").arg(MOBase::localizedByteSpeed(averageSpeed));
}
QListWidgetItem *newItem = new ServerItem(descriptor, Qt::UserRole + 1);
--
cgit v1.3.1
From 2c5603092af9cdce1748870176c5f4cd49a87b8d Mon Sep 17 00:00:00 2001
From: LostDragonist
Date: Fri, 6 Dec 2019 11:06:50 -0700
Subject: Add source game column to the download list
---
src/downloadlist.cpp | 9 ++++++++-
src/downloadlist.h | 1 +
src/downloadlistsortproxy.cpp | 2 ++
src/downloadlistwidget.cpp | 1 +
src/downloadmanager.cpp | 13 +++++++++++++
src/downloadmanager.h | 8 ++++++++
6 files changed, 33 insertions(+), 1 deletion(-)
(limited to 'src/downloadlist.cpp')
diff --git a/src/downloadlist.cpp b/src/downloadlist.cpp
index 6957f270..99347a79 100644
--- a/src/downloadlist.cpp
+++ b/src/downloadlist.cpp
@@ -77,6 +77,7 @@ QVariant DownloadList::headerData(int section, Qt::Orientation orientation, int
case COL_SIZE: return tr("Size");
case COL_STATUS: return tr("Status");
case COL_FILETIME: return tr("Filetime");
+ case COL_SOURCEGAME: return tr("Source Game");
default: return QVariant();
}
} else {
@@ -118,10 +119,16 @@ QVariant DownloadList::data(const QModelIndex &index, int role) const
if (m_Manager->isInfoIncomplete(index.row())) {
return {};
} else {
- const MOBase::ModRepositoryFileInfo *info = m_Manager->getFileInfo(index.row());
return QString("%1").arg(m_Manager->getModID(index.row()));
}
}
+ case COL_SOURCEGAME: {
+ if (m_Manager->isInfoIncomplete(index.row())) {
+ return {};
+ } else {
+ return QString("%1").arg(m_Manager->getDisplayGameName(index.row()));
+ }
+ }
case COL_SIZE: return MOBase::localizedByteSize(m_Manager->getFileSize(index.row()));
case COL_FILETIME: return m_Manager->getFileTime(index.row());
case COL_STATUS:
diff --git a/src/downloadlist.h b/src/downloadlist.h
index 51ab4541..eb2bbc55 100644
--- a/src/downloadlist.h
+++ b/src/downloadlist.h
@@ -43,6 +43,7 @@ public:
COL_MODNAME,
COL_VERSION,
COL_ID,
+ COL_SOURCEGAME,
// number of columns
COL_COUNT
diff --git a/src/downloadlistsortproxy.cpp b/src/downloadlistsortproxy.cpp
index a69993c0..6209a721 100644
--- a/src/downloadlistsortproxy.cpp
+++ b/src/downloadlistsortproxy.cpp
@@ -96,6 +96,8 @@ bool DownloadListSortProxy::lessThan(const QModelIndex &left,
return m_Manager->getFileSize(left.row()) < m_Manager->getFileSize(right.row());
} else if (left.column() == DownloadList::COL_FILETIME) {
return m_Manager->getFileTime(left.row()) < m_Manager->getFileTime(right.row());
+ } else if (left.column() == DownloadList::COL_SOURCEGAME) {
+ return m_Manager->getDisplayGameName(left.row()) < m_Manager->getDisplayGameName(right.row());
} else {
return leftIndex < rightIndex;
}
diff --git a/src/downloadlistwidget.cpp b/src/downloadlistwidget.cpp
index 85d27831..ac37b0ee 100644
--- a/src/downloadlistwidget.cpp
+++ b/src/downloadlistwidget.cpp
@@ -135,6 +135,7 @@ void DownloadListWidget::setManager(DownloadManager *manager)
header()->hideSection(DownloadList::COL_MODNAME);
header()->hideSection(DownloadList::COL_VERSION);
header()->hideSection(DownloadList::COL_ID);
+ header()->hideSection(DownloadList::COL_SOURCEGAME);
}
void DownloadListWidget::setSourceModel(DownloadList *sourceModel)
diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp
index 361e7164..adfbc84d 100644
--- a/src/downloadmanager.cpp
+++ b/src/downloadmanager.cpp
@@ -1239,6 +1239,19 @@ int DownloadManager::getModID(int index) const
return m_ActiveDownloads.at(index)->m_FileInfo->modID;
}
+QString DownloadManager::getDisplayGameName(int index) const
+{
+ if ((index < 0) || (index >= m_ActiveDownloads.size())) {
+ throw MyException(tr("mod id: invalid download index %1").arg(index));
+ }
+ QString gameName = m_ActiveDownloads.at(index)->m_FileInfo->gameName;
+ IPluginGame* gamePlugin = m_OrganizerCore->getGame(gameName);
+ if (gamePlugin) {
+ gameName = gamePlugin->gameName();
+ }
+ return gameName;
+}
+
QString DownloadManager::getGameName(int index) const
{
if ((index < 0) || (index >= m_ActiveDownloads.size())) {
diff --git a/src/downloadmanager.h b/src/downloadmanager.h
index f2ad15f4..4fc61cad 100644
--- a/src/downloadmanager.h
+++ b/src/downloadmanager.h
@@ -312,6 +312,14 @@ public:
**/
int getModID(int index) const;
+ /**
+ * @brief retrieve the displayable game name of the download specified by the index
+ *
+ * @param index index of the file to look up
+ * @return the displayable game name
+ **/
+ QString getDisplayGameName(int index) const;
+
/**
* @brief retrieve the game name of the downlaod specified by the index
*
--
cgit v1.3.1