From 535623693e63569f485c15984274ea65c4d0c872 Mon Sep 17 00:00:00 2001 From: Jeremy Rimpo Date: Fri, 30 Jul 2021 21:29:16 -0500 Subject: Add menu item to auto-assign categories based on nexus assignments --- src/modlistviewactions.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/modlistviewactions.cpp') diff --git a/src/modlistviewactions.cpp b/src/modlistviewactions.cpp index a6f0f07e..21079f1d 100644 --- a/src/modlistviewactions.cpp +++ b/src/modlistviewactions.cpp @@ -12,6 +12,7 @@ #include "categories.h" #include "csvbuilder.h" #include "directoryrefresher.h" +#include "downloadmanager.h" #include "filedialogmemory.h" #include "filterlist.h" #include "listdialog.h" @@ -259,6 +260,23 @@ void ModListViewActions::checkModsForUpdates() const } } +void ModListViewActions::assignCategories() const +{ + for (auto mod : m_core.modList()->allMods()) { + ModInfo::Ptr modInfo = ModInfo::getByName(mod); + for (auto category : modInfo->categories()) { + modInfo->removeCategory(category); + } + QString file = modInfo->installationFile(); + auto download = m_core.downloadManager()->getDownloadIndex(file); + if (download >= 0) { + int nexusCategory = m_core.downloadManager()->getCategoryID(download); + int category = CategoryFactory::instance()->resolveNexusID(nexusCategory); + modInfo->setCategory(CategoryFactory::instance()->getCategoryID(category), true); + } + } +} + void ModListViewActions::checkModsForUpdates( std::multimap const& IDs) const { -- cgit v1.3.1 From b9f05672b9692c96d39b8ff27e571a30cb82cd44 Mon Sep 17 00:00:00 2001 From: Jeremy Rimpo Date: Fri, 24 Dec 2021 17:54:55 -0600 Subject: Allow remapping category from context menu --- src/categoriesdialog.cpp | 7 +++++++ src/categoriesdialog.h | 1 + src/modlistcontextmenu.cpp | 4 ++++ src/modlistviewactions.cpp | 14 ++++++++++++++ src/modlistviewactions.h | 1 + src/nexusinterface.cpp | 4 ++-- 6 files changed, 29 insertions(+), 2 deletions(-) (limited to 'src/modlistviewactions.cpp') diff --git a/src/categoriesdialog.cpp b/src/categoriesdialog.cpp index 4019f197..92afda60 100644 --- a/src/categoriesdialog.cpp +++ b/src/categoriesdialog.cpp @@ -23,6 +23,7 @@ along with Mod Organizer. If not, see . #include "ui_categoriesdialog.h" #include "utility.h" #include "nexusinterface.h" +#include "messagedialog.h" #include #include #include @@ -321,6 +322,12 @@ void CategoriesDialog::nxmGameInfoAvailable(QString gameName, QVariant, QVariant } +void CategoriesDialog::nxmRequestFailed(QString, int, int, QVariant, int, int errorCode, const QString& errorMessage) +{ + MessageDialog::showMessage(tr("Error %1: Request to Nexus failed: %2").arg(errorCode).arg(errorMessage), this); +} + + void CategoriesDialog::on_categoriesTable_customContextMenuRequested(const QPoint& pos) { m_ContextRow = ui->categoriesTable->rowAt(pos.y()); diff --git a/src/categoriesdialog.h b/src/categoriesdialog.h index 49749a0f..a2bd7240 100644 --- a/src/categoriesdialog.h +++ b/src/categoriesdialog.h @@ -54,6 +54,7 @@ public: public slots: void nxmGameInfoAvailable(QString gameName, QVariant, QVariant resultData, int); + void nxmRequestFailed(QString, int, int, QVariant, int, int errorCode, const QString& errorMessage); signals: void refreshNexusCategories(); diff --git a/src/modlistcontextmenu.cpp b/src/modlistcontextmenu.cpp index 66766b0e..096976c1 100644 --- a/src/modlistcontextmenu.cpp +++ b/src/modlistcontextmenu.cpp @@ -561,6 +561,10 @@ void ModListContextMenu::addRegularActions(ModInfo::Ptr mod) } } + if (mod->nexusId() > 0 && !mod->installationFile().isEmpty()) { + addAction(tr("Remap Category (From Nexus)"), [=]() { m_actions.remapCategory(m_selected); }); + } + if (mod->nexusId() > 0 && Settings::instance().nexus().trackedIntegration()) { switch (mod->trackedState()) { case TrackedState::TRACKED_FALSE: { diff --git a/src/modlistviewactions.cpp b/src/modlistviewactions.cpp index 21079f1d..b9d0f419 100644 --- a/src/modlistviewactions.cpp +++ b/src/modlistviewactions.cpp @@ -1100,6 +1100,20 @@ void ModListViewActions::willNotEndorsed(const QModelIndexList& indices) const } } +void ModListViewActions::remapCategory(const QModelIndexList& indices) const +{ + for (auto& idx : indices) { + ModInfo::Ptr modInfo = ModInfo::getByIndex(idx.data(ModList::IndexRole).toInt()); + + int downloadIndex = m_core.downloadManager()->getDownloadIndex(modInfo->installationFile()); + if (downloadIndex >= 0) { + auto downloadInfo = m_core.downloadManager()->getFileInfo(downloadIndex); + unsigned int categoryIndex = CategoryFactory::instance()->resolveNexusID(downloadInfo->categoryID); + modInfo->setPrimaryCategory(CategoryFactory::instance()->getCategoryID(categoryIndex)); + } + } +} + void ModListViewActions::setColor(const QModelIndexList& indices, const QModelIndex& refIndex) const { diff --git a/src/modlistviewactions.h b/src/modlistviewactions.h index 3805f98b..ad20e784 100644 --- a/src/modlistviewactions.h +++ b/src/modlistviewactions.h @@ -98,6 +98,7 @@ public: void setTracked(const QModelIndexList& indices, bool tracked) const; void setEndorsed(const QModelIndexList& indices, bool endorsed) const; void willNotEndorsed(const QModelIndexList& indices) const; + void remapCategory(const QModelIndexList& indices) const; // set/reset color of the given selection, using the given reference index (index // at which the context menu was shown) diff --git a/src/nexusinterface.cpp b/src/nexusinterface.cpp index cece6745..9db78791 100644 --- a/src/nexusinterface.cpp +++ b/src/nexusinterface.cpp @@ -762,8 +762,8 @@ int NexusInterface::requestGameInfo(QString gameName, QObject* receiver, QVarian connect(this, SIGNAL(nxmGameInfoAvailable(QString, QVariant, QVariant, int)), receiver, SLOT(nxmGameInfoAvailable(QString, QVariant, QVariant, int)), Qt::UniqueConnection); - connect(this, SIGNAL(nxmRequestFailed(QString, int, int, QVariant, int, QNetworkReply::NetworkError, QString)), - receiver, SLOT(nxmRequestFailed(QString, int, int, QVariant, int, QNetworkReply::NetworkError, QString)), Qt::UniqueConnection); + connect(this, SIGNAL(nxmRequestFailed(QString, int, int, QVariant, int, int, QString)), + receiver, SLOT(nxmRequestFailed(QString, int, int, QVariant, int, int, QString)), Qt::UniqueConnection); nextRequest(); return requestInfo.m_ID; -- cgit v1.3.1 From fba3d52f5645bf2b0ec4a61f9b7fed9c4d481637 Mon Sep 17 00:00:00 2001 From: Jeremy Rimpo Date: Thu, 20 Oct 2022 22:54:29 -0500 Subject: Preserve old category if Nexus category can't be mapped --- src/modlistviewactions.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src/modlistviewactions.cpp') diff --git a/src/modlistviewactions.cpp b/src/modlistviewactions.cpp index b9d0f419..5fc2aea9 100644 --- a/src/modlistviewactions.cpp +++ b/src/modlistviewactions.cpp @@ -264,15 +264,17 @@ void ModListViewActions::assignCategories() const { for (auto mod : m_core.modList()->allMods()) { ModInfo::Ptr modInfo = ModInfo::getByName(mod); - for (auto category : modInfo->categories()) { - modInfo->removeCategory(category); - } QString file = modInfo->installationFile(); auto download = m_core.downloadManager()->getDownloadIndex(file); if (download >= 0) { int nexusCategory = m_core.downloadManager()->getCategoryID(download); - int category = CategoryFactory::instance()->resolveNexusID(nexusCategory); - modInfo->setCategory(CategoryFactory::instance()->getCategoryID(category), true); + int newCategory = CategoryFactory::instance()->resolveNexusID(nexusCategory); + if (newCategory != 0) { + for (auto category : modInfo->categories()) { + modInfo->removeCategory(category); + } + } + modInfo->setCategory(CategoryFactory::instance()->getCategoryID(newCategory), true); } } } @@ -1109,7 +1111,8 @@ void ModListViewActions::remapCategory(const QModelIndexList& indices) const if (downloadIndex >= 0) { auto downloadInfo = m_core.downloadManager()->getFileInfo(downloadIndex); unsigned int categoryIndex = CategoryFactory::instance()->resolveNexusID(downloadInfo->categoryID); - modInfo->setPrimaryCategory(CategoryFactory::instance()->getCategoryID(categoryIndex)); + if (categoryIndex != 0) + modInfo->setPrimaryCategory(CategoryFactory::instance()->getCategoryID(categoryIndex)); } } } -- cgit v1.3.1 From f6bb73deb21228acf0e7f74500f50421143aa739 Mon Sep 17 00:00:00 2001 From: Jeremy Rimpo Date: Mon, 18 Sep 2023 21:44:45 -0500 Subject: Clang cleanup --- src/categories.cpp | 62 ++++---- src/categories.h | 36 +++-- src/categoriestable.cpp | 15 +- src/categoriestable.h | 8 +- src/downloadmanager.cpp | 10 +- src/modinfo.cpp | 3 +- src/modinforegular.cpp | 2 +- src/modlistcontextmenu.cpp | 4 +- src/modlistviewactions.cpp | 18 ++- src/nexusinterface.cpp | 320 ++++++++++++++++++++++++------------------ src/nexusinterface.h | 26 ++-- src/organizer_en.ts | 260 +++++++++++++++++----------------- src/profile.cpp | 3 +- src/settingsdialog.cpp | 3 +- src/settingsdialoggeneral.cpp | 5 +- src/settingsdialoggeneral.h | 6 +- 16 files changed, 428 insertions(+), 353 deletions(-) (limited to 'src/modlistviewactions.cpp') diff --git a/src/categories.cpp b/src/categories.cpp index 7fd60c50..61cd6334 100644 --- a/src/categories.cpp +++ b/src/categories.cpp @@ -90,23 +90,25 @@ void CategoryFactory::loadCategories() int id = cells[0].toInt(&cell0Ok); int parentID = cells[3].trimmed().toInt(&cell3Ok); if (!cell0Ok || !cell3Ok) { - log::error(tr("invalid category line {}: {}").toStdString(), lineNum, line.constData()); + log::error(tr("invalid category line {}: {}").toStdString(), lineNum, + line.constData()); } addCategory(id, QString::fromUtf8(cells[1].constData()), nexusCats, parentID); } else if (cells.count() == 3) { - bool cell0Ok = true; - bool cell3Ok = true; - int id = cells[0].toInt(&cell0Ok); - int parentID = cells[2].trimmed().toInt(&cell3Ok); - if (!cell0Ok || !cell3Ok) { - log::error(tr("invalid category line {}: {}").toStdString(), lineNum, line.constData()); - } + bool cell0Ok = true; + bool cell3Ok = true; + int id = cells[0].toInt(&cell0Ok); + int parentID = cells[2].trimmed().toInt(&cell3Ok); + if (!cell0Ok || !cell3Ok) { + log::error(tr("invalid category line {}: {}").toStdString(), lineNum, + line.constData()); + } - addCategory(id, QString::fromUtf8(cells[1].constData()), std::vector(), parentID); + addCategory(id, QString::fromUtf8(cells[1].constData()), + std::vector(), parentID); } else { - log::error( - tr("invalid category line {}: {} ({} cells)").toStdString(), - lineNum, line.constData(), cells.count()); + log::error(tr("invalid category line {}: {} ({} cells)").toStdString(), lineNum, + line.constData(), cells.count()); } } categoryFile.close(); @@ -123,21 +125,22 @@ void CategoryFactory::loadCategories() if (nexCells.count() == 3) { std::vector nexusCats; QString nexName = nexCells[1]; - bool ok = false; - int nexID = nexCells[2].toInt(&ok); + bool ok = false; + int nexID = nexCells[2].toInt(&ok); if (!ok) { - log::error(tr("invalid nexus ID {}").toStdString(), nexCells[2].constData()); + log::error(tr("invalid nexus ID {}").toStdString(), + nexCells[2].constData()); } int catID = nexCells[0].toInt(&ok); if (!ok) { - log::error(tr("invalid category id {}").toStdString(), nexCells[0].constData()); + log::error(tr("invalid category id {}").toStdString(), + nexCells[0].constData()); } m_NexusMap.insert_or_assign(nexID, NexusCategory(nexName, nexID)); m_NexusMap.at(nexID).m_CategoryID = catID; } else { - log::error( - tr("invalid nexus category line {}: {} ({} cells)").toStdString(), - lineNum, nexLine.constData(), nexCells.count()); + log::error(tr("invalid nexus category line {}: {} ({} cells)").toStdString(), + lineNum, nexLine.constData(), nexCells.count()); } } } @@ -145,7 +148,8 @@ void CategoryFactory::loadCategories() } std::sort(m_Categories.begin(), m_Categories.end()); setParents(); - if (needLoad) loadDefaultCategories(); + if (needLoad) + loadDefaultCategories(); } CategoryFactory* CategoryFactory::instance() @@ -249,7 +253,9 @@ CategoryFactory::countCategories(std::function f return result; } -int CategoryFactory::addCategory(const QString& name, const std::vector& nexusCats, int parentID) +int CategoryFactory::addCategory(const QString& name, + const std::vector& nexusCats, + int parentID) { int id = 1; while (m_IDMap.find(id) != m_IDMap.end()) { @@ -264,11 +270,14 @@ int CategoryFactory::addCategory(const QString& name, const std::vector(m_Categories.size()); - m_Categories.push_back(Category(index, id, name, parentID, std::vector())); + m_Categories.push_back( + Category(index, id, name, parentID, std::vector())); m_IDMap[id] = index; } -void CategoryFactory::addCategory(int id, const QString& name, const std::vector& nexusCats, int parentID) +void CategoryFactory::addCategory(int id, const QString& name, + const std::vector& nexusCats, + int parentID) { for (auto nexusCat : nexusCats) { m_NexusMap.insert_or_assign(nexusCat.m_ID, nexusCat); @@ -279,7 +288,8 @@ void CategoryFactory::addCategory(int id, const QString& name, const std::vector m_IDMap[id] = index; } -void CategoryFactory::setNexusCategories(std::vector& nexusCats) +void CategoryFactory::setNexusCategories( + std::vector& nexusCats) { m_NexusMap.empty(); for (auto nexusCat : nexusCats) { @@ -289,7 +299,6 @@ void CategoryFactory::setNexusCategories(std::vectorsecond.m_CategoryID)) { - log::debug(tr("nexus category id {} maps to internal {}").toStdString(), nexusID, m_IDMap.at(result->second.m_CategoryID)); + log::debug(tr("nexus category id {} maps to internal {}").toStdString(), nexusID, + m_IDMap.at(result->second.m_CategoryID)); return m_IDMap.at(result->second.m_CategoryID); } } diff --git a/src/categories.h b/src/categories.h index 86e66b1c..3f91e6c5 100644 --- a/src/categories.h +++ b/src/categories.h @@ -31,7 +31,8 @@ along with Mod Organizer. If not, see . *to look up categories, optimized to where the request comes from. Therefore be very *careful which of the two you have available **/ -class CategoryFactory : public QObject { +class CategoryFactory : public QObject +{ Q_OBJECT; friend class CategoriesDialog; @@ -53,30 +54,37 @@ public: }; public: - struct NexusCategory { - NexusCategory(const QString& name, const int nexusID) - : m_Name(name), m_ID(nexusID) {} + struct NexusCategory + { + NexusCategory(const QString& name, const int nexusID) : m_Name(name), m_ID(nexusID) + {} QString m_Name; int m_ID; int m_CategoryID = -1; - friend bool operator==(const NexusCategory& LHS, const NexusCategory& RHS) { + friend bool operator==(const NexusCategory& LHS, const NexusCategory& RHS) + { return LHS.m_ID == RHS.m_ID; } - friend bool operator==(const NexusCategory& LHS, const int RHS) { + friend bool operator==(const NexusCategory& LHS, const int RHS) + { return LHS.m_ID == RHS; } - friend bool operator<(const NexusCategory& LHS, const NexusCategory& RHS) { + friend bool operator<(const NexusCategory& LHS, const NexusCategory& RHS) + { return LHS.m_ID < RHS.m_ID; } }; - struct Category { - Category(int sortValue, int id, const QString& name, int parentID, std::vector nexusCats) - : m_SortValue(sortValue), m_ID(id), m_Name(name), m_HasChildren(false), m_ParentID(parentID) - , m_NexusCats(nexusCats) {} + struct Category + { + Category(int sortValue, int id, const QString& name, int parentID, + std::vector nexusCats) + : m_SortValue(sortValue), m_ID(id), m_Name(name), m_HasChildren(false), + m_ParentID(parentID), m_NexusCats(nexusCats) + {} int m_SortValue; int m_ID; int m_ParentID; @@ -108,7 +116,8 @@ public: void setNexusCategories(std::vector& nexusCats); - int addCategory(const QString& name, const std::vector& nexusCats, int parentID); + int addCategory(const QString& name, const std::vector& nexusCats, + int parentID); /** * @brief retrieve the number of available categories @@ -222,7 +231,8 @@ private: void loadDefaultCategories(); - void addCategory(int id, const QString& name, const std::vector& nexusCats, int parentID); + void addCategory(int id, const QString& name, + const std::vector& nexusCats, int parentID); void addCategory(int id, const QString& name, int parentID); void setParents(); diff --git a/src/categoriestable.cpp b/src/categoriestable.cpp index ed45826f..fc53fb58 100644 --- a/src/categoriestable.cpp +++ b/src/categoriestable.cpp @@ -21,7 +21,8 @@ along with Mod Organizer. If not, see . CategoriesTable::CategoriesTable(QWidget* parent) : QTableWidget(parent) {} -bool CategoriesTable::dropMimeData(int row, int column, const QMimeData* data, Qt::DropAction action) +bool CategoriesTable::dropMimeData(int row, int column, const QMimeData* data, + Qt::DropAction action) { if (row == -1) return false; @@ -35,15 +36,15 @@ bool CategoriesTable::dropMimeData(int row, int column, const QMimeData* data, Q QByteArray encoded = data->data("application/x-qabstractitemmodeldatalist"); QDataStream stream(&encoded, QIODevice::ReadOnly); - while (!stream.atEnd()) - { + while (!stream.atEnd()) { int curRow, curCol; QMap roleDataMap; stream >> curRow >> curCol >> roleDataMap; - for (auto item : findItems(roleDataMap.value(Qt::DisplayRole).toString(), Qt::MatchContains | Qt::MatchWrap)) - { - if (item->column() != 3) continue; + for (auto item : findItems(roleDataMap.value(Qt::DisplayRole).toString(), + Qt::MatchContains | Qt::MatchWrap)) { + if (item->column() != 3) + continue; QVariantList newData; for (auto nexData : item->data(Qt::UserRole).toList()) { if (nexData.toList()[1].toInt() != roleDataMap.value(Qt::UserRole)) { @@ -59,7 +60,7 @@ bool CategoriesTable::dropMimeData(int row, int column, const QMimeData* data, Q } auto nexusItem = item(row, 3); - auto itemData = nexusItem->data(Qt::UserRole).toList(); + auto itemData = nexusItem->data(Qt::UserRole).toList(); QVariantList newData; newData.append(roleDataMap.value(Qt::DisplayRole).toString()); newData.append(roleDataMap.value(Qt::UserRole).toInt()); diff --git a/src/categoriestable.h b/src/categoriestable.h index 7aaf62a9..8ec797de 100644 --- a/src/categoriestable.h +++ b/src/categoriestable.h @@ -27,11 +27,11 @@ class CategoriesTable : public QTableWidget { Q_OBJECT public: - CategoriesTable(QWidget *parent = 0); + CategoriesTable(QWidget* parent = 0); protected: - virtual bool dropMimeData(int row, int column, const QMimeData* data, Qt::DropAction action); - + virtual bool dropMimeData(int row, int column, const QMimeData* data, + Qt::DropAction action); }; -#endif // CATEGORIESTABLE_H +#endif // CATEGORIESTABLE_H diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp index 6cf3a95c..3e5303c6 100644 --- a/src/downloadmanager.cpp +++ b/src/downloadmanager.cpp @@ -1323,10 +1323,12 @@ QString DownloadManager::getFileName(int index) const int DownloadManager::getDownloadIndex(QString filename) const { - auto file = std::find_if(m_ActiveDownloads.begin(), m_ActiveDownloads.end(), [=](DownloadManager::DownloadInfo *const val) { - if (val->m_FileName == filename) return true; - return false; - }); + auto file = std::find_if(m_ActiveDownloads.begin(), m_ActiveDownloads.end(), + [=](DownloadManager::DownloadInfo* const val) { + if (val->m_FileName == filename) + return true; + return false; + }); if (file != m_ActiveDownloads.end()) { int fileIndex = m_ActiveDownloads.indexOf(*file); return fileIndex; diff --git a/src/modinfo.cpp b/src/modinfo.cpp index 5ef36ef0..0ae28e73 100644 --- a/src/modinfo.cpp +++ b/src/modinfo.cpp @@ -495,7 +495,8 @@ void ModInfo::addCategory(const QString& categoryName) { int id = CategoryFactory::instance()->getCategoryID(categoryName); if (id == -1) { - id = CategoryFactory::instance()->addCategory(categoryName, std::vector(), 0); + id = CategoryFactory::instance()->addCategory( + categoryName, std::vector(), 0); } setCategory(id, true); } diff --git a/src/modinforegular.cpp b/src/modinforegular.cpp index 275b76a3..9cb89307 100644 --- a/src/modinforegular.cpp +++ b/src/modinforegular.cpp @@ -738,7 +738,7 @@ QString ModInfoRegular::getDescription() const } categoryString << "" << ToWString(categoryFactory->getCategoryName( - categoryFactory->getCategoryIndex(*catIter))) + categoryFactory->getCategoryIndex(*catIter))) << ""; } diff --git a/src/modlistcontextmenu.cpp b/src/modlistcontextmenu.cpp index 096976c1..6954652e 100644 --- a/src/modlistcontextmenu.cpp +++ b/src/modlistcontextmenu.cpp @@ -562,7 +562,9 @@ void ModListContextMenu::addRegularActions(ModInfo::Ptr mod) } if (mod->nexusId() > 0 && !mod->installationFile().isEmpty()) { - addAction(tr("Remap Category (From Nexus)"), [=]() { m_actions.remapCategory(m_selected); }); + addAction(tr("Remap Category (From Nexus)"), [=]() { + m_actions.remapCategory(m_selected); + }); } if (mod->nexusId() > 0 && Settings::instance().nexus().trackedIntegration()) { diff --git a/src/modlistviewactions.cpp b/src/modlistviewactions.cpp index 5fc2aea9..aa962c1e 100644 --- a/src/modlistviewactions.cpp +++ b/src/modlistviewactions.cpp @@ -264,17 +264,18 @@ void ModListViewActions::assignCategories() const { for (auto mod : m_core.modList()->allMods()) { ModInfo::Ptr modInfo = ModInfo::getByName(mod); - QString file = modInfo->installationFile(); - auto download = m_core.downloadManager()->getDownloadIndex(file); + QString file = modInfo->installationFile(); + auto download = m_core.downloadManager()->getDownloadIndex(file); if (download >= 0) { int nexusCategory = m_core.downloadManager()->getCategoryID(download); - int newCategory = CategoryFactory::instance()->resolveNexusID(nexusCategory); + int newCategory = CategoryFactory::instance()->resolveNexusID(nexusCategory); if (newCategory != 0) { for (auto category : modInfo->categories()) { modInfo->removeCategory(category); } } - modInfo->setCategory(CategoryFactory::instance()->getCategoryID(newCategory), true); + modInfo->setCategory(CategoryFactory::instance()->getCategoryID(newCategory), + true); } } } @@ -1107,12 +1108,15 @@ void ModListViewActions::remapCategory(const QModelIndexList& indices) const for (auto& idx : indices) { ModInfo::Ptr modInfo = ModInfo::getByIndex(idx.data(ModList::IndexRole).toInt()); - int downloadIndex = m_core.downloadManager()->getDownloadIndex(modInfo->installationFile()); + int downloadIndex = + m_core.downloadManager()->getDownloadIndex(modInfo->installationFile()); if (downloadIndex >= 0) { auto downloadInfo = m_core.downloadManager()->getFileInfo(downloadIndex); - unsigned int categoryIndex = CategoryFactory::instance()->resolveNexusID(downloadInfo->categoryID); + unsigned int categoryIndex = + CategoryFactory::instance()->resolveNexusID(downloadInfo->categoryID); if (categoryIndex != 0) - modInfo->setPrimaryCategory(CategoryFactory::instance()->getCategoryID(categoryIndex)); + modInfo->setPrimaryCategory( + CategoryFactory::instance()->getCategoryID(categoryIndex)); } } } diff --git a/src/nexusinterface.cpp b/src/nexusinterface.cpp index 9db78791..6a39128f 100644 --- a/src/nexusinterface.cpp +++ b/src/nexusinterface.cpp @@ -93,7 +93,8 @@ void NexusBridge::requestToggleTracking(QString gameName, int modID, bool track, void NexusBridge::requestGameInfo(QString gameName, QVariant userData) { - m_RequestIDs.insert(m_Interface->requestGameInfo(gameName, this, userData, m_SubModule)); + m_RequestIDs.insert( + m_Interface->requestGameInfo(gameName, this, userData, m_SubModule)); } void NexusBridge::nxmDescriptionAvailable(QString gameName, int modID, @@ -199,7 +200,8 @@ void NexusBridge::nxmTrackingToggled(QString gameName, int modID, QVariant userD } } -void NexusBridge::nxmGameInfoAvailable(QString gameName, QVariant userData, QVariant resultData, int requestID) +void NexusBridge::nxmGameInfoAvailable(QString gameName, QVariant userData, + QVariant resultData, int requestID) { std::set::iterator iter = m_RequestIDs.find(requestID); if (iter != m_RequestIDs.end()) { @@ -749,7 +751,9 @@ int NexusInterface::requestToggleTracking(QString gameName, int modID, bool trac return requestInfo.m_ID; } -int NexusInterface::requestGameInfo(QString gameName, QObject* receiver, QVariant userData, const QString& subModule, MOBase::IPluginGame const* game) +int NexusInterface::requestGameInfo(QString gameName, QObject* receiver, + QVariant userData, const QString& subModule, + MOBase::IPluginGame const* game) { if (m_User.shouldThrottle()) { throttledWarning(m_User); @@ -760,10 +764,13 @@ int NexusInterface::requestGameInfo(QString gameName, QObject* receiver, QVarian m_RequestQueue.enqueue(requestInfo); connect(this, SIGNAL(nxmGameInfoAvailable(QString, QVariant, QVariant, int)), - receiver, SLOT(nxmGameInfoAvailable(QString, QVariant, QVariant, int)), Qt::UniqueConnection); + receiver, SLOT(nxmGameInfoAvailable(QString, QVariant, QVariant, int)), + Qt::UniqueConnection); - connect(this, SIGNAL(nxmRequestFailed(QString, int, int, QVariant, int, int, QString)), - receiver, SLOT(nxmRequestFailed(QString, int, int, QVariant, int, int, QString)), Qt::UniqueConnection); + connect( + this, SIGNAL(nxmRequestFailed(QString, int, int, QVariant, int, int, QString)), + receiver, SLOT(nxmRequestFailed(QString, int, int, QVariant, int, int, QString)), + Qt::UniqueConnection); nextRequest(); return requestInfo.m_ID; @@ -868,72 +875,104 @@ void NexusInterface::nextRequest() if (!info.m_Reroute) { bool hasParams = false; switch (info.m_Type) { - case NXMRequestInfo::TYPE_DESCRIPTION: - case NXMRequestInfo::TYPE_MODINFO: { - url = QString("%1/games/%2/mods/%3") + case NXMRequestInfo::TYPE_DESCRIPTION: + case NXMRequestInfo::TYPE_MODINFO: { + url = QString("%1/games/%2/mods/%3") + .arg(info.m_URL) + .arg(info.m_GameName) + .arg(info.m_ModID); + } break; + case NXMRequestInfo::TYPE_CHECKUPDATES: { + QString period; + switch (info.m_UpdatePeriod) { + case UpdatePeriod::DAY: + period = "1d"; + break; + case UpdatePeriod::WEEK: + period = "1w"; + break; + case UpdatePeriod::MONTH: + period = "1m"; + break; + } + url = QString("%1/games/%2/mods/updated?period=%3") + .arg(info.m_URL) + .arg(info.m_GameName) + .arg(period); + } break; + case NXMRequestInfo::TYPE_FILES: + case NXMRequestInfo::TYPE_GETUPDATES: { + url = QString("%1/games/%2/mods/%3/files") + .arg(info.m_URL) + .arg(info.m_GameName) + .arg(info.m_ModID); + } break; + case NXMRequestInfo::TYPE_FILEINFO: { + url = QString("%1/games/%2/mods/%3/files/%4") + .arg(info.m_URL) + .arg(info.m_GameName) + .arg(info.m_ModID) + .arg(info.m_FileID); + } break; + case NXMRequestInfo::TYPE_DOWNLOADURL: { + ModRepositoryFileInfo* fileInfo = qobject_cast( + qvariant_cast(info.m_UserData)); + if (m_User.type() == APIUserAccountTypes::Premium) { + url = QString("%1/games/%2/mods/%3/files/%4/download_link") .arg(info.m_URL) .arg(info.m_GameName) - .arg(info.m_ModID); - } break; - case NXMRequestInfo::TYPE_CHECKUPDATES: { - QString period; - switch (info.m_UpdatePeriod) { - case UpdatePeriod::DAY: - period = "1d"; - break; - case UpdatePeriod::WEEK: - period = "1w"; - break; - case UpdatePeriod::MONTH: - period = "1m"; - break; - } - url = QString("%1/games/%2/mods/updated?period=%3").arg(info.m_URL).arg(info.m_GameName).arg(period); - } break; - case NXMRequestInfo::TYPE_FILES: - case NXMRequestInfo::TYPE_GETUPDATES: { - url = QString("%1/games/%2/mods/%3/files").arg(info.m_URL).arg(info.m_GameName).arg(info.m_ModID); - } break; - case NXMRequestInfo::TYPE_FILEINFO: { - url = QString("%1/games/%2/mods/%3/files/%4").arg(info.m_URL).arg(info.m_GameName).arg(info.m_ModID).arg(info.m_FileID); - } break; - case NXMRequestInfo::TYPE_DOWNLOADURL: { - ModRepositoryFileInfo *fileInfo = qobject_cast(qvariant_cast(info.m_UserData)); - if (m_User.type() == APIUserAccountTypes::Premium) { - url = QString("%1/games/%2/mods/%3/files/%4/download_link").arg(info.m_URL).arg(info.m_GameName).arg(info.m_ModID).arg(info.m_FileID); - } else if (!fileInfo->nexusKey.isEmpty() && fileInfo->nexusExpires && fileInfo->nexusDownloadUser == m_User.id().toInt()) { - url = QString("%1/games/%2/mods/%3/files/%4/download_link?key=%5&expires=%6") - .arg(info.m_URL).arg(info.m_GameName).arg(info.m_ModID).arg(info.m_FileID).arg(fileInfo->nexusKey).arg(fileInfo->nexusExpires); - } else { - log::warn("{}", tr("Aborting download: Either you clicked on a premium-only link and your account is not premium, " - "or the download link was generated by a different account than the one stored in Mod Organizer.")); - return; - } - } break; - case NXMRequestInfo::TYPE_ENDORSEMENTS: { - url = QString("%1/user/endorsements").arg(info.m_URL); - } break; - case NXMRequestInfo::TYPE_TOGGLEENDORSEMENT: { - QString endorse = info.m_Endorse ? "endorse" : "abstain"; - url = QString("%1/games/%2/mods/%3/%4").arg(info.m_URL).arg(info.m_GameName).arg(info.m_ModID).arg(endorse); - postObject.insert("Version", info.m_ModVersion); - postData.setObject(postObject); - } break; - case NXMRequestInfo::TYPE_TOGGLETRACKING: { - url = QStringLiteral("%1/user/tracked_mods?domain_name=%2").arg(info.m_URL).arg(info.m_GameName); - postObject.insert("mod_id", info.m_ModID); - postData.setObject(postObject); - requestIsDelete = !info.m_Track; - } break; - case NXMRequestInfo::TYPE_TRACKEDMODS: { - url = QStringLiteral("%1/user/tracked_mods").arg(info.m_URL); - } break; - case NXMRequestInfo::TYPE_FILEINFO_MD5: { - url = QStringLiteral("%1/games/%2/mods/md5_search/%3").arg(info.m_URL).arg(info.m_GameName).arg(QString(info.m_Hash.toHex())); - } break; - case NXMRequestInfo::TYPE_GAMEINFO: { - url = QStringLiteral("%1/games/%2").arg(info.m_URL).arg(info.m_GameName); - } break; + .arg(info.m_ModID) + .arg(info.m_FileID); + } else if (!fileInfo->nexusKey.isEmpty() && fileInfo->nexusExpires && + fileInfo->nexusDownloadUser == m_User.id().toInt()) { + url = QString("%1/games/%2/mods/%3/files/%4/download_link?key=%5&expires=%6") + .arg(info.m_URL) + .arg(info.m_GameName) + .arg(info.m_ModID) + .arg(info.m_FileID) + .arg(fileInfo->nexusKey) + .arg(fileInfo->nexusExpires); + } else { + log::warn("{}", tr("Aborting download: Either you clicked on a premium-only " + "link and your account is not premium, " + "or the download link was generated by a different account " + "than the one stored in Mod Organizer.")); + return; + } + } break; + case NXMRequestInfo::TYPE_ENDORSEMENTS: { + url = QString("%1/user/endorsements").arg(info.m_URL); + } break; + case NXMRequestInfo::TYPE_TOGGLEENDORSEMENT: { + QString endorse = info.m_Endorse ? "endorse" : "abstain"; + url = QString("%1/games/%2/mods/%3/%4") + .arg(info.m_URL) + .arg(info.m_GameName) + .arg(info.m_ModID) + .arg(endorse); + postObject.insert("Version", info.m_ModVersion); + postData.setObject(postObject); + } break; + case NXMRequestInfo::TYPE_TOGGLETRACKING: { + url = QStringLiteral("%1/user/tracked_mods?domain_name=%2") + .arg(info.m_URL) + .arg(info.m_GameName); + postObject.insert("mod_id", info.m_ModID); + postData.setObject(postObject); + requestIsDelete = !info.m_Track; + } break; + case NXMRequestInfo::TYPE_TRACKEDMODS: { + url = QStringLiteral("%1/user/tracked_mods").arg(info.m_URL); + } break; + case NXMRequestInfo::TYPE_FILEINFO_MD5: { + url = QStringLiteral("%1/games/%2/mods/md5_search/%3") + .arg(info.m_URL) + .arg(info.m_GameName) + .arg(QString(info.m_Hash.toHex())); + } break; + case NXMRequestInfo::TYPE_GAMEINFO: { + url = QStringLiteral("%1/games/%2").arg(info.m_URL).arg(info.m_GameName); + } } } else { url = info.m_URL; @@ -1045,53 +1084,69 @@ void NexusInterface::requestFinished(std::list::iterator iter) if (!responseDoc.isNull()) { QVariant result = responseDoc.toVariant(); switch (iter->m_Type) { - case NXMRequestInfo::TYPE_DESCRIPTION: { - emit nxmDescriptionAvailable(iter->m_GameName, iter->m_ModID, iter->m_UserData, result, iter->m_ID); - } break; - case NXMRequestInfo::TYPE_MODINFO: { - emit nxmModInfoAvailable(iter->m_GameName, iter->m_ModID, iter->m_UserData, result, iter->m_ID); - } break; - case NXMRequestInfo::TYPE_CHECKUPDATES: { - emit nxmUpdateInfoAvailable(iter->m_GameName, iter->m_UserData, result, iter->m_ID); - } break; - case NXMRequestInfo::TYPE_FILES: { - emit nxmFilesAvailable(iter->m_GameName, iter->m_ModID, iter->m_UserData, result, iter->m_ID); - } break; - case NXMRequestInfo::TYPE_GETUPDATES: { - emit nxmUpdatesAvailable(iter->m_GameName, iter->m_ModID, iter->m_UserData, result, iter->m_ID); - } break; - case NXMRequestInfo::TYPE_FILEINFO: { - emit nxmFileInfoAvailable(iter->m_GameName, iter->m_ModID, iter->m_FileID, iter->m_UserData, result, iter->m_ID); - } break; - case NXMRequestInfo::TYPE_DOWNLOADURL: { - emit nxmDownloadURLsAvailable(iter->m_GameName, iter->m_ModID, iter->m_FileID, iter->m_UserData, result, iter->m_ID); - } break; - case NXMRequestInfo::TYPE_ENDORSEMENTS: { - emit nxmEndorsementsAvailable(iter->m_UserData, result, iter->m_ID); - } break; - case NXMRequestInfo::TYPE_TOGGLEENDORSEMENT: { - emit nxmEndorsementToggled(iter->m_GameName, iter->m_ModID, iter->m_UserData, result, iter->m_ID); - } break; - case NXMRequestInfo::TYPE_TOGGLETRACKING: { - auto results = result.toMap(); - auto message = results["message"].toString(); - if (message.contains(QRegularExpression("User [0-9]+ is already Tracking Mod: [0-9]+")) || - message.contains(QRegularExpression("User [0-9]+ is now Tracking Mod: [0-9]+"))) { - emit nxmTrackingToggled(iter->m_GameName, iter->m_ModID, iter->m_UserData, true, iter->m_ID); - } else if (message.contains(QRegularExpression("User [0-9]+ is no longer tracking [0-9]+")) || - message.contains(QRegularExpression("Users is not tracking mod. Unable to untrack."))) { - emit nxmTrackingToggled(iter->m_GameName, iter->m_ModID, iter->m_UserData, false, iter->m_ID); - } - } break; - case NXMRequestInfo::TYPE_TRACKEDMODS: { - emit nxmTrackedModsAvailable(iter->m_UserData, result, iter->m_ID); - } break; - case NXMRequestInfo::TYPE_FILEINFO_MD5: { - emit nxmFileInfoFromMd5Available(iter->m_GameName, iter->m_UserData, result, iter->m_ID); - } break; - case NXMRequestInfo::TYPE_GAMEINFO: { - emit nxmGameInfoAvailable(iter->m_GameName, iter->m_UserData, result, iter->m_ID); - } break; + case NXMRequestInfo::TYPE_DESCRIPTION: { + emit nxmDescriptionAvailable(iter->m_GameName, iter->m_ModID, + iter->m_UserData, result, iter->m_ID); + } break; + case NXMRequestInfo::TYPE_MODINFO: { + emit nxmModInfoAvailable(iter->m_GameName, iter->m_ModID, iter->m_UserData, + result, iter->m_ID); + } break; + case NXMRequestInfo::TYPE_CHECKUPDATES: { + emit nxmUpdateInfoAvailable(iter->m_GameName, iter->m_UserData, result, + iter->m_ID); + } break; + case NXMRequestInfo::TYPE_FILES: { + emit nxmFilesAvailable(iter->m_GameName, iter->m_ModID, iter->m_UserData, + result, iter->m_ID); + } break; + case NXMRequestInfo::TYPE_GETUPDATES: { + emit nxmUpdatesAvailable(iter->m_GameName, iter->m_ModID, iter->m_UserData, + result, iter->m_ID); + } break; + case NXMRequestInfo::TYPE_FILEINFO: { + emit nxmFileInfoAvailable(iter->m_GameName, iter->m_ModID, iter->m_FileID, + iter->m_UserData, result, iter->m_ID); + } break; + case NXMRequestInfo::TYPE_DOWNLOADURL: { + emit nxmDownloadURLsAvailable(iter->m_GameName, iter->m_ModID, iter->m_FileID, + iter->m_UserData, result, iter->m_ID); + } break; + case NXMRequestInfo::TYPE_ENDORSEMENTS: { + emit nxmEndorsementsAvailable(iter->m_UserData, result, iter->m_ID); + } break; + case NXMRequestInfo::TYPE_TOGGLEENDORSEMENT: { + emit nxmEndorsementToggled(iter->m_GameName, iter->m_ModID, iter->m_UserData, + result, iter->m_ID); + } break; + case NXMRequestInfo::TYPE_TOGGLETRACKING: { + auto results = result.toMap(); + auto message = results["message"].toString(); + if (message.contains( + QRegularExpression("User [0-9]+ is already Tracking Mod: [0-9]+")) || + message.contains( + QRegularExpression("User [0-9]+ is now Tracking Mod: [0-9]+"))) { + emit nxmTrackingToggled(iter->m_GameName, iter->m_ModID, iter->m_UserData, + true, iter->m_ID); + } else if (message.contains(QRegularExpression( + "User [0-9]+ is no longer tracking [0-9]+")) || + message.contains(QRegularExpression( + "Users is not tracking mod. Unable to untrack."))) { + emit nxmTrackingToggled(iter->m_GameName, iter->m_ModID, iter->m_UserData, + false, iter->m_ID); + } + } break; + case NXMRequestInfo::TYPE_TRACKEDMODS: { + emit nxmTrackedModsAvailable(iter->m_UserData, result, iter->m_ID); + } break; + case NXMRequestInfo::TYPE_FILEINFO_MD5: { + emit nxmFileInfoFromMd5Available(iter->m_GameName, iter->m_UserData, result, + iter->m_ID); + } break; + case NXMRequestInfo::TYPE_GAMEINFO: { + emit nxmGameInfoAvailable(iter->m_GameName, iter->m_UserData, result, + iter->m_ID); + } break; } m_User.limits(parseLimits(reply)); @@ -1194,28 +1249,15 @@ NexusInterface::NXMRequestInfo::NXMRequestInfo( m_Endorse(false), m_Track(false), m_Hash(QByteArray()) {} -NexusInterface::NXMRequestInfo::NXMRequestInfo(Type type - , QVariant userData - , const QString & subModule - , MOBase::IPluginGame const *game -) - : m_ModID(0) - , m_ModVersion("0") - , m_FileID(0) - , m_Reply(nullptr) - , m_Type(type) - , m_UpdatePeriod(UpdatePeriod::NONE) - , m_UserData(userData) - , m_Timeout(nullptr) - , m_Reroute(false) - , m_ID(s_NextID.fetchAndAddAcquire(1)) - , m_URL(get_management_url()) - , m_SubModule(subModule) - , m_NexusGameID(game->nexusGameID()) - , m_GameName(game->gameNexusName()) - , m_Endorse(false) - , m_Track(false) - , m_Hash(QByteArray()) +NexusInterface::NXMRequestInfo::NXMRequestInfo(Type type, QVariant userData, + const QString& subModule, + MOBase::IPluginGame const* game) + : m_ModID(0), m_ModVersion("0"), m_FileID(0), m_Reply(nullptr), m_Type(type), + m_UpdatePeriod(UpdatePeriod::NONE), m_UserData(userData), m_Timeout(nullptr), + m_Reroute(false), m_ID(s_NextID.fetchAndAddAcquire(1)), + m_URL(get_management_url()), m_SubModule(subModule), + m_NexusGameID(game->nexusGameID()), m_GameName(game->gameNexusName()), + m_Endorse(false), m_Track(false), m_Hash(QByteArray()) {} NexusInterface::NXMRequestInfo::NXMRequestInfo( diff --git a/src/nexusinterface.h b/src/nexusinterface.h index 95e46168..b79127af 100644 --- a/src/nexusinterface.h +++ b/src/nexusinterface.h @@ -467,17 +467,18 @@ public: } /** - * @param gameName the game short name to support multiple game sources - * @brief toggle tracking state of the mod - * @param modID id of the mod - * @param track true if the mod should be tracked, false for not tracked - * @param receiver the object to receive the result asynchronously via a signal (nxmFilesAvailable) - * @param userData user data to be returned with the result - * @param game the game with which the mods are associated - * @return int an id to identify the request - */ - int requestGameInfo(QString gameName, QObject* receiver, QVariant userData, const QString& subModule, - MOBase::IPluginGame const* game); + * @param gameName the game short name to support multiple game sources + * @brief toggle tracking state of the mod + * @param modID id of the mod + * @param track true if the mod should be tracked, false for not tracked + * @param receiver the object to receive the result asynchronously via a signal + * (nxmFilesAvailable) + * @param userData user data to be returned with the result + * @param game the game with which the mods are associated + * @return int an id to identify the request + */ + int requestGameInfo(QString gameName, QObject* receiver, QVariant userData, + const QString& subModule, MOBase::IPluginGame const* game); /** * @@ -651,7 +652,8 @@ private: const QString& subModule, MOBase::IPluginGame const* game); NXMRequestInfo(int modID, int fileID, Type type, QVariant userData, const QString& subModule, MOBase::IPluginGame const* game); - NXMRequestInfo(Type type, QVariant userData, const QString &subModule, MOBase::IPluginGame const *game); + NXMRequestInfo(Type type, QVariant userData, const QString& subModule, + MOBase::IPluginGame const* game); NXMRequestInfo(Type type, QVariant userData, const QString& subModule); NXMRequestInfo(UpdatePeriod period, Type type, QVariant userData, const QString& subModule, MOBase::IPluginGame const* game); diff --git a/src/organizer_en.ts b/src/organizer_en.ts index 389d84ae..71be4187 100644 --- a/src/organizer_en.ts +++ b/src/organizer_en.ts @@ -330,67 +330,67 @@ p, li { white-space: pre-wrap; } CategoryFactory - - + + invalid category id {} - + invalid category line {}: {} - + invalid category line {}: {} ({} cells) - + invalid nexus ID {} - + invalid nexus category line {}: {} ({} cells) - + Failed to save custom categories - + Failed to save nexus category mappings - - - - + + + + invalid category index: %1 - + {} is no valid category id - + invalid category id: %1 - + nexus category id {} maps to internal {} - + nexus category id {} not mapped @@ -1334,126 +1334,126 @@ File %3: %4 - + file time: invalid download index %1 - + file size: invalid download index %1 - + progress: invalid download index %1 - + state: invalid download index %1 - + infocomplete: invalid download index %1 - - - - + + + + mod id: invalid download index %1 - + ishidden: invalid download index %1 - + file info: invalid download index %1 - + mark installed: invalid download index %1 - + mark uninstalled: invalid download index %1 - + %1% - %2 - ~%3 - + Memory allocation error (in processing progress event). - + Memory allocation error (in processing downloaded data). - + Information updated - - + + No matching file found on Nexus! Maybe this file is no longer available or it was renamed? - + No file on Nexus matches the selected file by name. Please manually choose the correct one. - + No download server available. Please try again later. - + Failed to request file info from nexus: %1 - + Warning: Content type is: %1 - + Download header content length: %1 downloaded file size: %2 - + Download failed: %1 (%2) - + We were unable to download the file due to errors after four retries. There may be an issue with the Nexus servers. - + failed to re-open %1 - + Unable to write download to drive (return %1). Check the drive's available storage. @@ -4995,7 +4995,7 @@ p, li { white-space: pre-wrap; } - + Open in Explorer @@ -5033,25 +5033,25 @@ p, li { white-space: pre-wrap; } - + Ignore missing data - + Mark as converted/working - + Visit on Nexus - + Visit on %1 @@ -5137,17 +5137,17 @@ p, li { white-space: pre-wrap; } - + Start tracking - + Stop tracking - + Tracked state unknown @@ -5313,68 +5313,68 @@ Please enter the name: ModListViewActions - + Choose Mod - + Mod Archive - - + + Create Mod... - + This will create an empty mod. Please enter a name: - - + + A mod with this name already exists - + Create Separator... - + This will create a new separator. Please enter a name: - + A separator with this name already exists - + Really enable %1 mod(s)? - + Really disable %1 mod(s)? - + Confirm - + You are not currently authenticated with Nexus. Please do so under Settings -> Nexus. @@ -5572,7 +5572,7 @@ This function will guess the versioning scheme under the assumption that the ins - + Are you sure? @@ -5588,38 +5588,38 @@ This function will guess the versioning scheme under the assumption that the ins - + Overwrite? - + This will replace the existing mod "%1". Continue? - + failed to remove mod "%1" - + failed to rename "%1" to "%2" - + Move successful. - + This will move all files from overwrite into a new, regular mod. Please enter a name: - + About to recursively delete: @@ -5684,32 +5684,32 @@ Please enter a name: NexusInterface - + Please pick the mod ID for "%1" - + You must authorize MO2 in Settings -> Nexus to use the Nexus API. - + You've exceeded the Nexus API rate limit and requests are now being throttled. Your next batch of requests will be available in approximately %1 minutes and %2 seconds. - + Aborting download: Either you clicked on a premium-only link and your account is not premium, or the download link was generated by a different account than the one stored in Mod Organizer. - + empty response - + invalid response @@ -6555,61 +6555,61 @@ p, li { white-space: pre-wrap; } - + failed to write mod list: %1 - + failed to update tweaked ini file, wrong settings may be used: %1 - + failed to create tweaked ini: %1 - + failed to open %1 - + "%1" is missing or inaccessible - - - - - + + + + + invalid mod index: %1 - + A mod named "overwrite" was detected, disabled, and moved to the highest priority on the mod list. You may want to rename this mod and enable it again. - + Delete profile-specific save games? - + Do you want to delete the profile-specific save games? (If you select "No", the save games will show up again if you re-enable profile-specific save games) - + Missing profile-specific game INI files! - + Some of your profile-specific game INI files were missing. They will now be copied from the vanilla game folder. You might want to double-check your settings. Missing files: @@ -6617,12 +6617,12 @@ Missing files: - + Delete profile-specific game INI files? - + Do you want to delete the profile-specific game INI files? (If you select "No", the INI files will be used again if you re-enable profile-specific game INI files.) @@ -6912,57 +6912,57 @@ p, li { white-space: pre-wrap; } - + Active - + Update available - + Has category - + Conflicted - + Has hidden files - + Endorsed - + Has backup - + Managed - + Has valid game data - + Has Nexus ID - + Tracked on Nexus @@ -7045,7 +7045,7 @@ p, li { white-space: pre-wrap; } - + Instance type: %1 @@ -7166,82 +7166,82 @@ p, li { white-space: pre-wrap; } - + Instance location: %1 - + Instance name: %1 - + Profile settings: - + Local INIs: %1 - + + - yes - - - + + + no - + Local Saves: %1 - + Automatic Archive Invalidation: %1 - - + + Base directory: %1 - + Downloads - + Mods - + Profiles - + Overwrite - + Game: %1 - + Game location: %1 @@ -7773,12 +7773,12 @@ This program is known to cause issues with Mod Organizer, such as freezing or bl - + Confirm? - + This will reset all the choices you made to dialogs and make them all visible again. Continue? diff --git a/src/profile.cpp b/src/profile.cpp index 13ce41c7..d4299a7b 100644 --- a/src/profile.cpp +++ b/src/profile.cpp @@ -177,8 +177,7 @@ void Profile::findProfileSettings() } } - if (setting("", "LocalSettings") == - QVariant()) { + if (setting("", "LocalSettings") == QVariant()) { QString backupFile = getIniFileName() + "_"; if (m_Directory.exists(backupFile)) { storeSetting("", "LocalSettings", true); diff --git a/src/settingsdialog.cpp b/src/settingsdialog.cpp index 6ad6fdea..67c9dd5d 100644 --- a/src/settingsdialog.cpp +++ b/src/settingsdialog.cpp @@ -37,7 +37,8 @@ SettingsDialog::SettingsDialog(PluginContainer* pluginContainer, Settings& setti { ui->setupUi(this); - m_tabs.push_back(std::unique_ptr(new GeneralSettingsTab(settings, m_pluginContainer, *this))); + m_tabs.push_back(std::unique_ptr( + new GeneralSettingsTab(settings, m_pluginContainer, *this))); m_tabs.push_back(std::unique_ptr(new ThemeSettingsTab(settings, *this))); m_tabs.push_back( std::unique_ptr(new ModListSettingsTab(settings, *this))); diff --git a/src/settingsdialoggeneral.cpp b/src/settingsdialoggeneral.cpp index 95580723..4ce72110 100644 --- a/src/settingsdialoggeneral.cpp +++ b/src/settingsdialoggeneral.cpp @@ -8,8 +8,9 @@ using namespace MOBase; -GeneralSettingsTab::GeneralSettingsTab(Settings& s, PluginContainer* pluginContainer, SettingsDialog& d) - : SettingsTab(s, d), m_PluginContainer(pluginContainer) +GeneralSettingsTab::GeneralSettingsTab(Settings& s, PluginContainer* pluginContainer, + SettingsDialog& d) + : SettingsTab(s, d), m_PluginContainer(pluginContainer) { // language addLanguages(); diff --git a/src/settingsdialoggeneral.h b/src/settingsdialoggeneral.h index ffbeb50c..aa11edbb 100644 --- a/src/settingsdialoggeneral.h +++ b/src/settingsdialoggeneral.h @@ -1,14 +1,15 @@ #ifndef SETTINGSDIALOGGENERAL_H #define SETTINGSDIALOGGENERAL_H +#include "plugincontainer.h" #include "settings.h" #include "settingsdialog.h" -#include "plugincontainer.h" class GeneralSettingsTab : public SettingsTab { public: - GeneralSettingsTab(Settings& settings, PluginContainer *pluginContainer, SettingsDialog& dialog); + GeneralSettingsTab(Settings& settings, PluginContainer* pluginContainer, + SettingsDialog& dialog); void update(); @@ -23,7 +24,6 @@ private: private: PluginContainer* m_PluginContainer; - }; #endif // SETTINGSDIALOGGENERAL_H -- cgit v1.3.1 From c50ad588432a27612fe5be39b1520e2962d5eef7 Mon Sep 17 00:00:00 2001 From: Jeremy Rimpo Date: Tue, 19 Sep 2023 02:37:24 -0500 Subject: Add nexus category ID to mod info - We will check the mod info first then fall back to the download file - Add category field in the info dialog nexus tab --- src/mainwindow.cpp | 2 + src/modinfo.h | 10 ++ src/modinfobackup.h | 2 + src/modinfodialog.ui | 25 ++++- src/modinfodialognexus.cpp | 16 ++++ src/modinfodialognexus.h | 1 + src/modinfoforeign.h | 2 + src/modinfooverwrite.h | 2 + src/modinforegular.cpp | 23 ++++- src/modinforegular.h | 11 +++ src/modinfoseparator.h | 2 + src/modlistviewactions.cpp | 44 +++++---- src/organizer_en.ts | 233 +++++++++++++++++++++++---------------------- src/version.rc | 53 ++++------- 14 files changed, 255 insertions(+), 171 deletions(-) (limited to 'src/modlistviewactions.cpp') diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 18a288c6..ac4e093d 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -4476,6 +4476,8 @@ void MainWindow::nxmModInfoAvailable(QString gameName, int modID, QVariant userD mod->setNexusDescription(result["description"].toString()); + mod->setNexusCategory(result["category_id"].toInt()); + if ((mod->endorsedState() != EndorsedState::ENDORSED_NEVER) && (result.contains("endorsement"))) { QVariantMap endorsement = result["endorsement"].toMap(); diff --git a/src/modinfo.h b/src/modinfo.h index 9895d44c..0736aa20 100644 --- a/src/modinfo.h +++ b/src/modinfo.h @@ -887,6 +887,16 @@ public: // Nexus stuff * @brief Set the last time the mod was updated on Nexus. */ virtual void setNexusLastModified(QDateTime time) = 0; + + /** + * @return the assigned nexus category ID + */ + virtual int getNexusCategory() const = 0; + + /** + * @brief Assigns the given Nexus category ID + */ + virtual void setNexusCategory(int category) = 0; public: // Conflicts // retrieve the list of mods (as mod index) that are overwritten by this one. diff --git a/src/modinfobackup.h b/src/modinfobackup.h index 01abf184..0c3c29d7 100644 --- a/src/modinfobackup.h +++ b/src/modinfobackup.h @@ -38,6 +38,8 @@ public: virtual QDateTime getNexusLastModified() const override { return QDateTime(); } virtual void setNexusLastModified(QDateTime) override {} virtual QString getNexusDescription() const override { return QString(); } + virtual void setNexusCategory(int) override {} + virtual int getNexusCategory() const override { return 0; } virtual bool isBackup() const override { return true; } virtual void addInstalledFile(int, int) override {} diff --git a/src/modinfodialog.ui b/src/modinfodialog.ui index 269aebe3..53655aa5 100644 --- a/src/modinfodialog.ui +++ b/src/modinfodialog.ui @@ -966,7 +966,7 @@ text-align: left; 0 - + @@ -1026,6 +1026,29 @@ p, li { white-space: pre-wrap; } + + + + Category + + + + + + + + 1 + 0 + + + + + 0 + 0 + + + + diff --git a/src/modinfodialognexus.cpp b/src/modinfodialognexus.cpp index 56636145..485f138a 100644 --- a/src/modinfodialognexus.cpp +++ b/src/modinfodialognexus.cpp @@ -32,6 +32,9 @@ NexusTab::NexusTab(ModInfoDialogTabContext cx) connect(ui->version, &QLineEdit::editingFinished, [&] { onVersionChanged(); }); + connect(ui->category, &QLineEdit::editingFinished, [&] { + onCategoryChanged(); + }); connect(ui->refresh, &QPushButton::clicked, [&] { onRefreshBrowser(); @@ -75,6 +78,7 @@ void NexusTab::clear() ui->modID->clear(); ui->sourceGame->clear(); ui->version->clear(); + ui->category->clear(); ui->browser->setPage(new NexusTabWebpage(ui->browser)); ui->hasCustomURL->setChecked(false); ui->customURL->clear(); @@ -108,6 +112,8 @@ void NexusTab::update() ui->sourceGame->setCurrentIndex(ui->sourceGame->findData(gameName)); + ui->category->setText(QString("%1").arg(mod().getNexusCategory())); + auto* page = new NexusTabWebpage(ui->browser); ui->browser->setPage(page); @@ -360,6 +366,16 @@ void NexusTab::onVersionChanged() updateVersionColor(); } +void NexusTab::onCategoryChanged() +{ + if (m_loading) { + return; + } + + int category = ui->category->text().toInt(); + mod().setNexusCategory(category); +} + void NexusTab::onRefreshBrowser() { const auto modID = mod().nexusId(); diff --git a/src/modinfodialognexus.h b/src/modinfodialognexus.h index e9a8720f..e752018a 100644 --- a/src/modinfodialognexus.h +++ b/src/modinfodialognexus.h @@ -57,6 +57,7 @@ private: void onModIDChanged(); void onSourceGameChanged(); void onVersionChanged(); + void onCategoryChanged(); void onRefreshBrowser(); void onVisitNexus(); diff --git a/src/modinfoforeign.h b/src/modinfoforeign.h index 2c956fb7..dc66e1b0 100644 --- a/src/modinfoforeign.h +++ b/src/modinfoforeign.h @@ -60,6 +60,8 @@ public: virtual void setNexusFileStatus(int) override {} virtual QDateTime getLastNexusUpdate() const override { return QDateTime(); } virtual void setLastNexusUpdate(QDateTime) override {} + virtual int getNexusCategory() const override { return 0; } + virtual void setNexusCategory(int) override {} virtual QDateTime getLastNexusQuery() const override { return QDateTime(); } virtual void setLastNexusQuery(QDateTime) override {} virtual QDateTime getNexusLastModified() const override { return QDateTime(); } diff --git a/src/modinfooverwrite.h b/src/modinfooverwrite.h index 02154902..45b5bbdd 100644 --- a/src/modinfooverwrite.h +++ b/src/modinfooverwrite.h @@ -68,6 +68,8 @@ public: virtual QDateTime getNexusLastModified() const override { return QDateTime(); } virtual void setNexusLastModified(QDateTime) override {} virtual QString getNexusDescription() const override { return QString(); } + virtual void setNexusCategory(int) override {} + virtual int getNexusCategory() const override { return 0; } virtual QStringList archives(bool checkOnDisk = false) override; virtual void addInstalledFile(int, int) override {} virtual std::set> installedFiles() const override { return {}; } diff --git a/src/modinforegular.cpp b/src/modinforegular.cpp index 9cb89307..e238075a 100644 --- a/src/modinforegular.cpp +++ b/src/modinforegular.cpp @@ -97,6 +97,7 @@ void ModInfoRegular::readMeta() m_InstallationFile = metaFile.value("installationFile", "").toString(); m_NexusDescription = metaFile.value("nexusDescription", "").toString(); m_NexusFileStatus = metaFile.value("nexusFileStatus", "1").toInt(); + m_NexusCategory = metaFile.value("nexusCategory", 0).toInt(); m_Repository = metaFile.value("repository", "Nexus").toString(); m_Converted = metaFile.value("converted", false).toBool(); m_Validated = metaFile.value("validated", false).toBool(); @@ -171,10 +172,11 @@ void ModInfoRegular::readMeta() m_NexusLastModified = QDateTime::fromString( metaFile.value("nexusLastModified", QDateTime::currentDateTimeUtc()).toString(), Qt::ISODate); - m_Color = metaFile.value("color", QColor()).value(); - m_TrackedState = metaFile.value("tracked", false).toBool() - ? TrackedState::TRACKED_TRUE - : TrackedState::TRACKED_FALSE; + m_NexusCategory = metaFile.value("nexusCategory", 0).toInt(); + m_Color = metaFile.value("color", QColor()).value(); + m_TrackedState = metaFile.value("tracked", false).toBool() + ? TrackedState::TRACKED_TRUE + : TrackedState::TRACKED_FALSE; if (metaFile.contains("endorsed")) { if (metaFile.value("endorsed").canConvert()) { using ut = std::underlying_type_t; @@ -266,6 +268,7 @@ void ModInfoRegular::saveMeta() metaFile.setValue("lastNexusQuery", m_LastNexusQuery.toString(Qt::ISODate)); metaFile.setValue("lastNexusUpdate", m_LastNexusUpdate.toString(Qt::ISODate)); metaFile.setValue("nexusLastModified", m_NexusLastModified.toString(Qt::ISODate)); + metaFile.setValue("nexusCategory", m_NexusCategory); metaFile.setValue("converted", m_Converted); metaFile.setValue("validated", m_Validated); metaFile.setValue("color", m_Color); @@ -833,6 +836,18 @@ void ModInfoRegular::setNexusLastModified(QDateTime time) emit modDetailsUpdated(true); } +int ModInfoRegular::getNexusCategory() const +{ + return m_NexusCategory; +} + +void ModInfoRegular::setNexusCategory(int category) +{ + m_NexusCategory = category; + m_MetaInfoChanged = true; + saveMeta(); +} + void ModInfoRegular::setCustomURL(QString const& url) { m_CustomURL = url; diff --git a/src/modinforegular.h b/src/modinforegular.h index 6c85d66c..a408d966 100644 --- a/src/modinforegular.h +++ b/src/modinforegular.h @@ -379,6 +379,16 @@ public: */ virtual void setNexusLastModified(QDateTime time) override; + /** + * @return the assigned nexus category ID + */ + virtual int getNexusCategory() const override; + + /** + * @brief Assigns the given Nexus category ID + */ + virtual void setNexusCategory(int category) override; + virtual QStringList archives(bool checkOnDisk = false) override; virtual void setColor(QColor color) override; @@ -457,6 +467,7 @@ private: QDateTime m_LastNexusQuery; QDateTime m_LastNexusUpdate; QDateTime m_NexusLastModified; + int m_NexusCategory; QColor m_Color; diff --git a/src/modinfoseparator.h b/src/modinfoseparator.h index c34dd92b..67bc3d56 100644 --- a/src/modinfoseparator.h +++ b/src/modinfoseparator.h @@ -45,6 +45,8 @@ public: virtual void setLastNexusQuery(QDateTime) override {} virtual QDateTime getNexusLastModified() const override { return QDateTime(); } virtual void setNexusLastModified(QDateTime) override {} + virtual int getNexusCategory() const override { return 0; } + virtual void setNexusCategory(int) override {} virtual QDateTime creationTime() const override { return QDateTime(); } virtual QString getNexusDescription() const override { return QString(); } virtual void addInstalledFile(int /*modId*/, int /*fileId*/) override {} diff --git a/src/modlistviewactions.cpp b/src/modlistviewactions.cpp index aa962c1e..a86c9067 100644 --- a/src/modlistviewactions.cpp +++ b/src/modlistviewactions.cpp @@ -265,18 +265,20 @@ void ModListViewActions::assignCategories() const for (auto mod : m_core.modList()->allMods()) { ModInfo::Ptr modInfo = ModInfo::getByName(mod); QString file = modInfo->installationFile(); - auto download = m_core.downloadManager()->getDownloadIndex(file); - if (download >= 0) { - int nexusCategory = m_core.downloadManager()->getCategoryID(download); - int newCategory = CategoryFactory::instance()->resolveNexusID(nexusCategory); - if (newCategory != 0) { - for (auto category : modInfo->categories()) { - modInfo->removeCategory(category); - } + int nexusCategory = modInfo->getNexusCategory(); + if (!nexusCategory) { + auto download = m_core.downloadManager()->getDownloadIndex(file); + if (download >= 0) { + int nexusCategory = m_core.downloadManager()->getCategoryID(download); + } + } + int newCategory = CategoryFactory::instance()->resolveNexusID(nexusCategory); + if (newCategory != 0) { + for (auto category : modInfo->categories()) { + modInfo->removeCategory(category); } - modInfo->setCategory(CategoryFactory::instance()->getCategoryID(newCategory), - true); } + modInfo->setCategory(CategoryFactory::instance()->getCategoryID(newCategory), true); } } @@ -1108,16 +1110,20 @@ void ModListViewActions::remapCategory(const QModelIndexList& indices) const for (auto& idx : indices) { ModInfo::Ptr modInfo = ModInfo::getByIndex(idx.data(ModList::IndexRole).toInt()); - int downloadIndex = - m_core.downloadManager()->getDownloadIndex(modInfo->installationFile()); - if (downloadIndex >= 0) { - auto downloadInfo = m_core.downloadManager()->getFileInfo(downloadIndex); - unsigned int categoryIndex = - CategoryFactory::instance()->resolveNexusID(downloadInfo->categoryID); - if (categoryIndex != 0) - modInfo->setPrimaryCategory( - CategoryFactory::instance()->getCategoryID(categoryIndex)); + int categoryID = modInfo->getNexusCategory(); + if (!categoryID) { + int downloadIndex = + m_core.downloadManager()->getDownloadIndex(modInfo->installationFile()); + if (downloadIndex >= 0) { + auto downloadInfo = m_core.downloadManager()->getFileInfo(downloadIndex); + categoryID = downloadInfo->categoryID; + } } + unsigned int categoryIndex = + CategoryFactory::instance()->resolveNexusID(categoryID); + if (categoryIndex != 0) + modInfo->setPrimaryCategory( + CategoryFactory::instance()->getCategoryID(categoryIndex)); } } diff --git a/src/organizer_en.ts b/src/organizer_en.ts index 71be4187..228b275a 100644 --- a/src/organizer_en.ts +++ b/src/organizer_en.ts @@ -4048,115 +4048,115 @@ You will have to visit the mod page on the %1 Nexus site to change your mind. - + Thank you! - + Thank you for your endorsement! - + Mod ID %1 no longer seems to be available on Nexus. - + Error %1: Request to Nexus failed: %2 - - + + failed to read %1: %2 - + Error - + failed to extract %1 (errorcode %2) - + Extract BSA - + This archive contains invalid hashes. Some files may be broken. - + Extract... - + Remove '%1' from the toolbar - + Backup of load order created - + Choose backup to restore - + No Backups - + There are no backups to restore - - + + Restore failed - - + + Failed to restore the backup. Errorcode: %1 - + Backup of mod list created - + A file with the same name has already been downloaded. What would you like to do? - + Overwrite - + Rename new file - + Ignore file @@ -4480,88 +4480,93 @@ p, li { white-space: pre-wrap; } - - + + Category + + + + + Refresh - + Refresh all information from Nexus. - - + + Open in Browser - + Endorse - + Track - + about:blank - + Use Custom URL - + Notes - - - + + + Enter comments about the mod here. These are displayed in the notes column of the mod list. - + Set Color - + Reset Color - - - + + + Enter notes about the mod here. These can be viewed in the mod list by hovering over the notes column or the flags column. - + Filetree - + Open Mod in Explorer - + A directory view of this mod - + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li { white-space: pre-wrap; } @@ -4571,17 +4576,17 @@ p, li { white-space: pre-wrap; } - + Previous - + Next - + Close @@ -4620,12 +4625,12 @@ p, li { white-space: pre-wrap; } ModInfoRegular - + %1 contains no esp/esm/esl and no asset (textures, meshes, interface, ...) directory - + Categories: <br> @@ -5324,7 +5329,7 @@ Please enter the name: - + Create Mod... @@ -5336,7 +5341,7 @@ Please enter a name: - + A mod with this name already exists @@ -5368,258 +5373,258 @@ Please enter a name: - - + + Confirm - + You are not currently authenticated with Nexus. Please do so under Settings -> Nexus. - + Export to csv - + CSV (Comma Separated Values) is a format that can be imported in programs like Excel to create a spreadsheet. You can also use online editors and converters instead. - + Select what mods you want export: - + All installed mods - + Only active (checked) mods from your current profile - + All currently visible mods in the mod list - + Choose what Columns to export: - + Mod_Priority - + Mod_Name - + Notes_column - + Mod_Status - + Primary_Category - + Nexus_ID - + Mod_Nexus_URL - + Mod_Version - + Install_Date - + Download_File_Name - + export failed: %1 - + Failed to display overwrite dialog: %1 - + Set Priority - + Set the priority of the selected mods - + failed to rename mod: %1 - + Remove the following mods?<br><ul>%1</ul> - + failed to remove mod: %1 - + Continue? - + The versioning scheme decides which version is considered newer than another. This function will guess the versioning scheme under the assumption that the installed version is outdated. - + Sorry - + I don't know a versioning scheme where %1 is newer than %2. - + Opening Nexus Links - + You are trying to open %1 links to Nexus Mods. Are you sure you want to do this? - - + + Opening Web Pages - - + + You are trying to open %1 Web Pages. Are you sure you want to do this? - - - + + + Failed - + Installation file no longer exists - + Mods installed with old versions of MO can't be reinstalled in this way. - + Failed to create backup. - + Restore all hidden files in the following mods?<br><ul>%1</ul> - - + + Are you sure? - + About to restore all hidden files in: - + Endorsing multiple mods will take a while. Please wait... - + Overwrite? - + This will replace the existing mod "%1". Continue? - + failed to remove mod "%1" - + failed to rename "%1" to "%2" - + Move successful. - + This will move all files from overwrite into a new, regular mod. Please enter a name: - + About to recursively delete: @@ -5760,27 +5765,27 @@ Please enter a name: NexusTab - + Current Version: %1 - + No update available - + Tracked - + Untracked - + <div style="text-align: center;"> <p>This mod does not have a valid Nexus ID. You can add a custom web diff --git a/src/version.rc b/src/version.rc index 0db83d44..aa92aee1 100644 --- a/src/version.rc +++ b/src/version.rc @@ -1,37 +1,24 @@ #include "Winver.h" -// If VS_FF_PRERELEASE is not set, MO labels the build as a release and uses VER_FILEVERSION to determine version number. -// Otherwise, if letters are used in VER_FILEVERSION_STR, uses the full MOBase::VersionInfo parser -// Otherwise, uses the numbers from VER_FILEVERSION and sets the release type as pre-alpha -#define VER_FILEVERSION 2,5,0 -#define VER_FILEVERSION_STR "2.5.0-beta7\0" +// If VS_FF_PRERELEASE is not set, MO labels the build as a release and uses +// VER_FILEVERSION to determine version number. Otherwise, if letters are used in +// VER_FILEVERSION_STR, uses the full MOBase::VersionInfo parser Otherwise, uses the +// numbers from VER_FILEVERSION and sets the release type as pre-alpha +#define VER_FILEVERSION 2, 5, 0 +#define VER_FILEVERSION_STR "2.5.0-beta9\0" -VS_VERSION_INFO VERSIONINFO -FILEVERSION VER_FILEVERSION -PRODUCTVERSION VER_FILEVERSION -FILEFLAGSMASK VS_FFI_FILEFLAGSMASK -FILEFLAGS VS_FF_PRERELEASE -FILEOS VOS__WINDOWS32 -FILETYPE VFT_APP -FILESUBTYPE (0) -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "040904B0" - BEGIN - VALUE "FileVersion", VER_FILEVERSION_STR - VALUE "CompanyName", "Mod Organizer 2 Team\0" - VALUE "FileDescription", "Mod Organizer 2 GUI\0" - VALUE "OriginalFilename", "ModOrganizer.exe\0" - VALUE "InternalName", "ModOrganizer2\0" - VALUE "LegalCopyright", "Copyright 2011-2016 Sebastian Herbord\r\nCopyright 2016-2023 Mod Organizer 2 contributors\0" - VALUE "ProductName", "Mod Organizer 2\0" - VALUE "ProductVersion", VER_FILEVERSION_STR - END - END +VS_VERSION_INFO VERSIONINFO FILEVERSION VER_FILEVERSION PRODUCTVERSION VER_FILEVERSION + FILEFLAGSMASK VS_FFI_FILEFLAGSMASK FILEFLAGS VS_FF_PRERELEASE FILEOS VOS__WINDOWS32 + FILETYPE VFT_APP FILESUBTYPE(0) BEGIN BLOCK + "StringFileInfo" BEGIN BLOCK "040904B0" BEGIN VALUE "FileVersion", + VER_FILEVERSION_STR VALUE "CompanyName", + "Mod Organizer 2 Team\0" VALUE "FileDescription", + "Mod Organizer 2 GUI\0" VALUE "OriginalFilename", + "ModOrganizer.exe\0" VALUE "InternalName", "ModOrganizer2\0" VALUE "LegalCopyright", + "Copyright 2011-2016 Sebastian Herbord\r\nCopyright 2016-2023 Mod Organizer 2 " + "contributors\0" VALUE "ProductName", + "Mod Organizer 2\0" VALUE "ProductVersion", + VER_FILEVERSION_STR END END - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x0409, 1200 - END -END + BLOCK "VarFileInfo" BEGIN VALUE "Translation", + 0x0409, 1200 END END -- cgit v1.3.1 From 049a7e2efd4a42437cc6e06b59d9a28cc65457bc Mon Sep 17 00:00:00 2001 From: Jeremy Rimpo Date: Wed, 20 Sep 2023 20:44:20 -0500 Subject: Dialogs and bugfixes --- src/installationmanager.cpp | 19 ++++++++++--------- src/modlistviewactions.cpp | 17 ++++++++++++++++- src/settings.cpp | 10 ++++++++++ src/settings.h | 3 +++ 4 files changed, 39 insertions(+), 10 deletions(-) (limited to 'src/modlistviewactions.cpp') diff --git a/src/installationmanager.cpp b/src/installationmanager.cpp index 901c636c..3f247b38 100644 --- a/src/installationmanager.cpp +++ b/src/installationmanager.cpp @@ -667,20 +667,21 @@ InstallationResult InstallationManager::install(const QString& fileName, if (category != 0 && categoryIndex == 0U && Settings::instance().nexus().categoryMappings()) { QMessageBox nexusQuery; + nexusQuery.setWindowTitle(tr("No category found")); nexusQuery.setText(tr( "This Nexus category has not yet been mapped. Do you wish to proceed without " "setting a category, proceed and disable automatic Nexus mappings, or stop " "and configure your category mappings?")); - nexusQuery.addButton(tr("&Proceed"), QMessageBox::YesRole); - nexusQuery.addButton(tr("&Disable"), QMessageBox::AcceptRole); - nexusQuery.addButton(tr("&Stop && Configure"), QMessageBox::DestructiveRole); - auto ret = nexusQuery.exec(); - switch (ret) { - case 1: + QPushButton* proceedButton = + nexusQuery.addButton(tr("&Proceed"), QMessageBox::YesRole); + QPushButton* disableButton = + nexusQuery.addButton(tr("&Disable"), QMessageBox::AcceptRole); + QPushButton* stopButton = + nexusQuery.addButton(tr("&Stop && Configure"), QMessageBox::DestructiveRole); + nexusQuery.exec(); + if (nexusQuery.clickedButton() == disableButton) { Settings::instance().nexus().setCategoryMappings(false); - case 0: - break; - case 2: + } else if (nexusQuery.clickedButton() == stopButton) { return MOBase::IPluginInstaller::RESULT_CATEGORYREQUESTED; } } else { diff --git a/src/modlistviewactions.cpp b/src/modlistviewactions.cpp index a86c9067..fd2f5c68 100644 --- a/src/modlistviewactions.cpp +++ b/src/modlistviewactions.cpp @@ -262,6 +262,21 @@ void ModListViewActions::checkModsForUpdates() const void ModListViewActions::assignCategories() const { + if (!GlobalSettings::hideAssignCategoriesQuestion()) { + QMessageBox warning; + warning.setWindowTitle(tr("Are you sure?")); + warning.setText( + tr("This action will remove any existing categories on any mod with a valid " + "Nexus category mapping. Are you certain you want to proceed?")); + warning.setStandardButtons(QMessageBox::Yes | QMessageBox::Cancel); + QCheckBox dontShow(tr("&Don't show this again")); + warning.setCheckBox(&dontShow); + auto result = warning.exec(); + if (dontShow.isChecked()) + GlobalSettings::setHideAssignCategoriesQuestion(true); + if (result == QMessageBox::Cancel) + return; + } for (auto mod : m_core.modList()->allMods()) { ModInfo::Ptr modInfo = ModInfo::getByName(mod); QString file = modInfo->installationFile(); @@ -269,7 +284,7 @@ void ModListViewActions::assignCategories() const if (!nexusCategory) { auto download = m_core.downloadManager()->getDownloadIndex(file); if (download >= 0) { - int nexusCategory = m_core.downloadManager()->getCategoryID(download); + nexusCategory = m_core.downloadManager()->getCategoryID(download); } } int newCategory = CategoryFactory::instance()->resolveNexusID(nexusCategory); diff --git a/src/settings.cpp b/src/settings.cpp index 17de38ea..04a09467 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -2450,6 +2450,16 @@ void GlobalSettings::setHideCategoryReminder(bool b) settings().setValue("HideCategoryReminder", b); } +bool GlobalSettings::hideAssignCategoriesQuestion() +{ + return settings().value("HideAssignCategoriesQuestion", false).toBool(); +} + +void GlobalSettings::setHideAssignCategoriesQuestion(bool b) +{ + settings().setValue("HideAssignCategoriesQuestion", b); +} + bool GlobalSettings::nexusApiKey(QString& apiKey) { QString tempKey = getWindowsCredential("APIKEY"); diff --git a/src/settings.h b/src/settings.h index e7ca47a9..30254c06 100644 --- a/src/settings.h +++ b/src/settings.h @@ -931,6 +931,9 @@ public: static bool hideCategoryReminder(); static void setHideCategoryReminder(bool b); + static bool hideAssignCategoriesQuestion(); + static void setHideAssignCategoriesQuestion(bool b); + // if the key exists from the credentials store, puts it in `apiKey` and // returns true; otherwise, returns false and leaves `apiKey` untouched // -- cgit v1.3.1 From 133c072eb7f63e807f2a211804537f59d1f8b0ed Mon Sep 17 00:00:00 2001 From: Jeremy Rimpo Date: Thu, 21 Sep 2023 00:08:58 -0500 Subject: Rework download category parsing - Bypasses issue where hidden downloads are not accessible - getCategoryID no longer necessary --- src/downloadmanager.cpp | 8 -------- src/downloadmanager.h | 8 -------- src/modlistviewactions.cpp | 19 ++++++++++--------- 3 files changed, 10 insertions(+), 25 deletions(-) (limited to 'src/modlistviewactions.cpp') diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp index 3e5303c6..3c9e776e 100644 --- a/src/downloadmanager.cpp +++ b/src/downloadmanager.cpp @@ -1404,14 +1404,6 @@ int DownloadManager::getModID(int index) const return m_ActiveDownloads.at(index)->m_FileInfo->modID; } -int DownloadManager::getCategoryID(int index) const -{ - if ((index < 0) || (index >= m_ActiveDownloads.size())) { - throw MyException(tr("mod id: invalid download index %1").arg(index)); - } - return m_ActiveDownloads.at(index)->m_FileInfo->categoryID; -} - QString DownloadManager::getDisplayGameName(int index) const { if ((index < 0) || (index >= m_ActiveDownloads.size())) { diff --git a/src/downloadmanager.h b/src/downloadmanager.h index 359455d9..d264ec87 100644 --- a/src/downloadmanager.h +++ b/src/downloadmanager.h @@ -356,14 +356,6 @@ public: **/ int getModID(int index) const; - /** - * @brief retrieve the nexus category id of the download specified by index - * - * @param index index of the file to look up - * @return the nexus category id - */ - int getCategoryID(int index) const; - /** * @brief retrieve the displayable game name of the download specified by the index * diff --git a/src/modlistviewactions.cpp b/src/modlistviewactions.cpp index fd2f5c68..d82dca87 100644 --- a/src/modlistviewactions.cpp +++ b/src/modlistviewactions.cpp @@ -279,12 +279,13 @@ void ModListViewActions::assignCategories() const } for (auto mod : m_core.modList()->allMods()) { ModInfo::Ptr modInfo = ModInfo::getByName(mod); - QString file = modInfo->installationFile(); int nexusCategory = modInfo->getNexusCategory(); if (!nexusCategory) { - auto download = m_core.downloadManager()->getDownloadIndex(file); - if (download >= 0) { - nexusCategory = m_core.downloadManager()->getCategoryID(download); + QSettings downloadMeta(m_core.downloadsPath() + "/" + + modInfo->installationFile() + ".meta", + QSettings::IniFormat); + if (downloadMeta.contains("category")) { + nexusCategory = downloadMeta.value("category", 0).toInt(); } } int newCategory = CategoryFactory::instance()->resolveNexusID(nexusCategory); @@ -1127,11 +1128,11 @@ void ModListViewActions::remapCategory(const QModelIndexList& indices) const int categoryID = modInfo->getNexusCategory(); if (!categoryID) { - int downloadIndex = - m_core.downloadManager()->getDownloadIndex(modInfo->installationFile()); - if (downloadIndex >= 0) { - auto downloadInfo = m_core.downloadManager()->getFileInfo(downloadIndex); - categoryID = downloadInfo->categoryID; + QSettings downloadMeta(m_core.downloadsPath() + "/" + + modInfo->installationFile() + ".meta", + QSettings::IniFormat); + if (downloadMeta.contains("category")) { + categoryID = downloadMeta.value("category", 0).toInt(); } } unsigned int categoryIndex = -- cgit v1.3.1 From e22331fa0305d8a0a2b8b6d37203dac1ed3524e9 Mon Sep 17 00:00:00 2001 From: Jeremy Rimpo Date: Sat, 23 Sep 2023 19:00:41 -0500 Subject: Restructure category refresh action - Remove plugins class - Route signals to run Nexus API call from MainWindow - Pass Dialog instance to route response data - Revert CategoryFactory::instance to return reference --- src/categories.cpp | 11 ++++++++--- src/categories.h | 7 ++++++- src/categoriesdialog.cpp | 38 +++++++++++++++++--------------------- src/categoriesdialog.h | 7 +------ src/downloadmanager.cpp | 37 ++++++++++++++++++++----------------- src/downloadmanager.h | 9 +++++++++ src/filterlist.cpp | 2 +- src/installationmanager.cpp | 4 ++-- src/mainwindow.cpp | 33 +++++++++++++++++++++------------ src/mainwindow.h | 3 ++- src/moapplication.cpp | 2 +- src/modinfo.cpp | 12 ++++++------ src/modinfodialogcategories.cpp | 12 ++++++------ src/modinfodialogcategories.h | 2 +- src/modinforegular.cpp | 10 +++++----- src/modlist.cpp | 18 +++++++++--------- src/modlistsortproxy.cpp | 10 +++++----- src/modlistviewactions.cpp | 8 ++++---- src/organizercore.cpp | 3 ++- src/settingsdialoggeneral.cpp | 2 +- 20 files changed, 127 insertions(+), 103 deletions(-) (limited to 'src/modlistviewactions.cpp') diff --git a/src/categories.cpp b/src/categories.cpp index 18cee4f9..5d0d2bb7 100644 --- a/src/categories.cpp +++ b/src/categories.cpp @@ -146,10 +146,10 @@ void CategoryFactory::loadCategories() loadDefaultCategories(); } -CategoryFactory* CategoryFactory::instance() +CategoryFactory& CategoryFactory::instance() { static CategoryFactory s_Instance; - return &s_Instance; + return s_Instance; } void CategoryFactory::reset() @@ -285,7 +285,7 @@ void CategoryFactory::addCategory(int id, const QString& name, void CategoryFactory::setNexusCategories( std::vector& nexusCats) { - m_NexusMap.empty(); + m_NexusMap.clear(); for (auto nexusCat : nexusCats) { m_NexusMap.emplace(nexusCat.m_ID, nexusCat); } @@ -293,6 +293,11 @@ void CategoryFactory::setNexusCategories( saveCategories(); } +void CategoryFactory::refreshNexusCategories(CategoriesDialog* dialog) +{ + emit nexusCategoryRefresh(dialog); +} + void CategoryFactory::loadDefaultCategories() { // the order here is relevant as it defines the order in which the diff --git a/src/categories.h b/src/categories.h index 3f91e6c5..b7a9c214 100644 --- a/src/categories.h +++ b/src/categories.h @@ -25,6 +25,8 @@ along with Mod Organizer. If not, see . #include #include +class CategoriesDialog; + /** * @brief Manage the available mod categories * @warning member functions of this class currently use a wild mix of ids and indexes @@ -116,6 +118,8 @@ public: void setNexusCategories(std::vector& nexusCats); + void refreshNexusCategories(CategoriesDialog* dialog); + int addCategory(const QString& name, const std::vector& nexusCats, int parentID); @@ -211,7 +215,7 @@ public: * * @return the reference to the singleton **/ - static CategoryFactory* instance(); + static CategoryFactory& instance(); /** * @return path to the file that contains the categories list @@ -224,6 +228,7 @@ public: static QString nexusMappingFilePath(); signals: + void nexusCategoryRefresh(CategoriesDialog*); void categoriesSaved(); private: diff --git a/src/categoriesdialog.cpp b/src/categoriesdialog.cpp index 5b6270f8..53c930f3 100644 --- a/src/categoriesdialog.cpp +++ b/src/categoriesdialog.cpp @@ -105,9 +105,8 @@ private: QValidator* m_Validator; }; -CategoriesDialog::CategoriesDialog(PluginContainer* pluginContainer, QWidget* parent) - : TutorableDialog("Categories", parent), ui(new Ui::CategoriesDialog), - m_PluginContainer(pluginContainer) +CategoriesDialog::CategoriesDialog(QWidget* parent) + : TutorableDialog("Categories", parent), ui(new Ui::CategoriesDialog) { ui->setupUi(this); fillTable(); @@ -144,8 +143,8 @@ void CategoriesDialog::cellChanged(int row, int) void CategoriesDialog::commitChanges() { - CategoryFactory* categories = CategoryFactory::instance(); - categories->reset(); + CategoryFactory& categories = CategoryFactory::instance(); + categories.reset(); for (int i = 0; i < ui->categoriesTable->rowCount(); ++i) { int index = ui->categoriesTable->verticalHeader()->logicalIndex(i); @@ -157,12 +156,12 @@ void CategoriesDialog::commitChanges() nexusCat.toList()[0].toString(), nexusCat.toList()[1].toInt())); } - categories->addCategory(ui->categoriesTable->item(index, 0)->text().toInt(), - ui->categoriesTable->item(index, 1)->text(), nexusCats, - ui->categoriesTable->item(index, 2)->text().toInt()); + categories.addCategory(ui->categoriesTable->item(index, 0)->text().toInt(), + ui->categoriesTable->item(index, 1)->text(), nexusCats, + ui->categoriesTable->item(index, 2)->text().toInt()); } - categories->setParents(); + categories.setParents(); std::vector nexusCats; for (int i = 0; i < ui->nexusCategoryList->count(); ++i) { @@ -171,9 +170,9 @@ void CategoriesDialog::commitChanges() ui->nexusCategoryList->item(i)->data(Qt::UserRole).toInt())); } - categories->setNexusCategories(nexusCats); + categories.setNexusCategories(nexusCats); - categories->saveCategories(); + categories.saveCategories(); } void CategoriesDialog::refreshIDs() @@ -190,7 +189,7 @@ void CategoriesDialog::refreshIDs() void CategoriesDialog::fillTable() { - CategoryFactory* categories = CategoryFactory::instance(); + CategoryFactory& categories = CategoryFactory::instance(); QTableWidget* table = ui->categoriesTable; QListWidget* list = ui->nexusCategoryList; @@ -211,8 +210,8 @@ void CategoriesDialog::fillTable() int row = 0; for (std::vector::const_iterator iter = - categories->m_Categories.begin(); - iter != categories->m_Categories.end(); ++iter, ++row) { + categories.m_Categories.begin(); + iter != categories.m_Categories.end(); ++iter, ++row) { const CategoryFactory::Category& category = *iter; if (category.m_ID == 0) { --row; @@ -235,12 +234,12 @@ void CategoriesDialog::fillTable() table->setItem(row, 3, nexusCatItem.take()); } - for (auto nexusCat : categories->m_NexusMap) { + for (auto nexusCat : categories.m_NexusMap) { QScopedPointer nexusItem(new QListWidgetItem()); nexusItem->setData(Qt::DisplayRole, nexusCat.second.m_Name); nexusItem->setData(Qt::UserRole, nexusCat.second.m_ID); list->addItem(nexusItem.take()); - auto item = table->item(categories->resolveNexusID(nexusCat.first) - 1, 3); + auto item = table->item(categories.resolveNexusID(nexusCat.first) - 1, 3); if (item != nullptr) { auto itemData = item->data(Qt::UserRole).toList(); QVariantList newData; @@ -285,10 +284,7 @@ void CategoriesDialog::removeNexusMap_clicked() void CategoriesDialog::nexusRefresh_clicked() { - NexusInterface& nexus = NexusInterface::instance(); - nexus.setPluginContainer(m_PluginContainer); - nexus.requestGameInfo(Settings::instance().game().plugin()->gameShortName(), this, - QVariant(), QString()); + CategoryFactory::instance().refreshNexusCategories(this); } void CategoriesDialog::nexusImport_clicked() @@ -356,7 +352,7 @@ void CategoriesDialog::nxmGameInfoAvailable(QString gameName, QVariant, { QVariantMap result = resultData.toMap(); QVariantList categories = result["categories"].toList(); - CategoryFactory* catFactory = CategoryFactory::instance(); + CategoryFactory& catFactory = CategoryFactory::instance(); QListWidget* list = ui->nexusCategoryList; list->clear(); for (auto category : categories) { diff --git a/src/categoriesdialog.h b/src/categoriesdialog.h index 1bcf273c..94f390b0 100644 --- a/src/categoriesdialog.h +++ b/src/categoriesdialog.h @@ -38,7 +38,7 @@ class CategoriesDialog : public MOBase::TutorableDialog Q_OBJECT public: - explicit CategoriesDialog(PluginContainer* pluginContainer, QWidget* parent = 0); + explicit CategoriesDialog(QWidget* parent = 0); ~CategoriesDialog(); // also saves and restores geometry @@ -52,16 +52,11 @@ public: void commitChanges(); public slots: - void nxmGameInfoAvailable(QString gameName, QVariant, QVariant resultData, int); void nxmRequestFailed(QString, int, int, QVariant, int, int errorCode, const QString& errorMessage); -signals: - void refreshNexusCategories(); - private slots: - void on_categoriesTable_customContextMenuRequested(const QPoint& pos); void addCategory_clicked(); void removeCategory_clicked(); diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp index 3c9e776e..d7a72c0b 100644 --- a/src/downloadmanager.cpp +++ b/src/downloadmanager.cpp @@ -153,6 +153,20 @@ DownloadManager::DownloadInfo::createFromMeta(const QString& filePath, bool show return info; } +ScopedDisableDirWatcher::ScopedDisableDirWatcher(DownloadManager* downloadManager) +{ + m_downloadManager = downloadManager; + m_downloadManager->startDisableDirWatcher(); + log::debug("Scoped Disable DirWatcher: Started"); +} + +ScopedDisableDirWatcher::~ScopedDisableDirWatcher() +{ + m_downloadManager->endDisableDirWatcher(); + m_downloadManager = nullptr; + log::debug("Scoped Disable DirWatcher: Stopped"); +} + void DownloadManager::startDisableDirWatcher() { DownloadManager::m_DirWatcherDisabler++; @@ -317,10 +331,9 @@ void DownloadManager::refreshList() { TimeThis tt("DownloadManager::refreshList()"); + // avoid triggering other refreshes + ScopedDisableDirWatcher scopedDirWatcher(this); try { - // avoid triggering other refreshes - startDisableDirWatcher(); - int downloadsBefore = m_ActiveDownloads.size(); // remove finished downloads @@ -419,10 +432,7 @@ void DownloadManager::refreshList() log::debug("saw {} downloads", m_ActiveDownloads.size()); - emit update(-1); - - // let watcher trigger refreshes again - endDisableDirWatcher(); + emit update(-1); } catch (const std::bad_alloc&) { reportError(tr("Memory allocation error (in refreshing directory).")); @@ -758,7 +768,7 @@ void DownloadManager::addNXMDownload(const QString& url) void DownloadManager::removeFile(int index, bool deleteFile) { // Avoid triggering refreshes from DirWatcher - startDisableDirWatcher(); + ScopedDisableDirWatcher scopedDirWatcher(this); if (index >= m_ActiveDownloads.size()) { throw MyException(tr("remove: invalid download index %1").arg(index)); @@ -770,7 +780,6 @@ void DownloadManager::removeFile(int index, bool deleteFile) (download->m_State == STATE_DOWNLOADING)) { // shouldn't have been possible log::error("tried to remove active download"); - endDisableDirWatcher(); return; } @@ -781,7 +790,6 @@ void DownloadManager::removeFile(int index, bool deleteFile) if (deleteFile) { if (!shellDelete(QStringList(filePath), true)) { reportError(tr("failed to delete %1").arg(filePath)); - endDisableDirWatcher(); return; } @@ -795,8 +803,6 @@ void DownloadManager::removeFile(int index, bool deleteFile) metaSettings.setValue("removed", true); } m_DownloadRemoved(index); - - endDisableDirWatcher(); } class LessThanWrapper @@ -1449,15 +1455,13 @@ void DownloadManager::markInstalled(int index) } // Avoid triggering refreshes from DirWatcher - startDisableDirWatcher(); + ScopedDisableDirWatcher scopedDirWatcher(this); DownloadInfo* info = m_ActiveDownloads.at(index); QSettings metaFile(info->m_Output.fileName() + ".meta", QSettings::IniFormat); metaFile.setValue("installed", true); metaFile.setValue("uninstalled", false); - endDisableDirWatcher(); - setState(m_ActiveDownloads.at(index), STATE_INSTALLED); } @@ -1686,7 +1690,7 @@ void DownloadManager::downloadReadyRead() void DownloadManager::createMetaFile(DownloadInfo* info) { // Avoid triggering refreshes from DirWatcher - startDisableDirWatcher(); + ScopedDisableDirWatcher scopedDirWatcher(this); QSettings metaFile(QString("%1.meta").arg(info->m_Output.fileName()), QSettings::IniFormat); @@ -1710,7 +1714,6 @@ void DownloadManager::createMetaFile(DownloadInfo* info) (info->m_State == DownloadManager::STATE_ERROR)); metaFile.setValue("removed", info->m_Hidden); - endDisableDirWatcher(); // slightly hackish... for (int i = 0; i < m_ActiveDownloads.size(); ++i) { if (m_ActiveDownloads[i] == info) { diff --git a/src/downloadmanager.h b/src/downloadmanager.h index d264ec87..618c2813 100644 --- a/src/downloadmanager.h +++ b/src/downloadmanager.h @@ -634,4 +634,13 @@ private: QTimer m_TimeoutTimer; }; +class ScopedDisableDirWatcher +{ +public: + ScopedDisableDirWatcher(DownloadManager* downloadManager); + ~ScopedDisableDirWatcher(); + +private: + DownloadManager* m_downloadManager; +}; #endif // DOWNLOADMANAGER_H diff --git a/src/filterlist.cpp b/src/filterlist.cpp index c88945f8..3be67def 100644 --- a/src/filterlist.cpp +++ b/src/filterlist.cpp @@ -425,7 +425,7 @@ void FilterList::checkCriteria() void FilterList::editCategories() { - CategoriesDialog dialog(&m_core.pluginContainer(), qApp->activeWindow()); + CategoriesDialog dialog(qApp->activeWindow()); if (dialog.exec() == QDialog::Accepted) { dialog.commitChanges(); diff --git a/src/installationmanager.cpp b/src/installationmanager.cpp index 3f247b38..37c86c7e 100644 --- a/src/installationmanager.cpp +++ b/src/installationmanager.cpp @@ -663,7 +663,7 @@ InstallationResult InstallationManager::install(const QString& fileName, version = metaFile.value("version", "").toString(); newestVersion = metaFile.value("newestVersion", "").toString(); category = metaFile.value("category", 0).toInt(); - unsigned int categoryIndex = CategoryFactory::instance()->resolveNexusID(category); + unsigned int categoryIndex = CategoryFactory::instance().resolveNexusID(category); if (category != 0 && categoryIndex == 0U && Settings::instance().nexus().categoryMappings()) { QMessageBox nexusQuery; @@ -685,7 +685,7 @@ InstallationResult InstallationManager::install(const QString& fileName, return MOBase::IPluginInstaller::RESULT_CATEGORYREQUESTED; } } else { - categoryID = CategoryFactory::instance()->getCategoryID(categoryIndex); + categoryID = CategoryFactory::instance().getCategoryID(categoryIndex); } repository = metaFile.value("repository", "").toString(); fileCategoryID = metaFile.value("fileCategory", 1).toInt(); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 74504ed6..ce2c4dd0 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -290,7 +290,7 @@ MainWindow::MainWindow(Settings& settings, OrganizerCore& organizerCore, ui->statusBar->setAPI(ni.getAPIStats(), ni.getAPIUserAccount()); } - m_CategoryFactory->loadCategories(); + m_CategoryFactory.loadCategories(); ui->logList->setCore(m_OrganizerCore); @@ -455,8 +455,9 @@ MainWindow::MainWindow(Settings& settings, OrganizerCore& organizerCore, connect(&m_OrganizerCore, &OrganizerCore::modInstalled, this, &MainWindow::modInstalled); - connect(m_CategoryFactory, &CategoryFactory::categoriesSaved, this, - &MainWindow::categoriesSaved); + connect(&m_CategoryFactory, SIGNAL(nexusCategoryRefresh(CategoriesDialog*)), this, + SLOT(refreshNexusCategories(CategoriesDialog*))); + connect(&m_CategoryFactory, SIGNAL(categoriesSaved()), this, SLOT(categoriesSaved())); m_CheckBSATimer.setSingleShot(true); connect(&m_CheckBSATimer, SIGNAL(timeout()), this, SLOT(checkBSAList())); @@ -540,7 +541,7 @@ MainWindow::MainWindow(Settings& settings, OrganizerCore& organizerCore, void MainWindow::setupModList() { - ui->modList->setup(m_OrganizerCore, *m_CategoryFactory, this, ui); + ui->modList->setup(m_OrganizerCore, m_CategoryFactory, this, ui); connect(&ui->modList->actions(), &ModListViewActions::overwriteCleared, [=]() { scheduleCheckForProblems(); @@ -1291,11 +1292,11 @@ void MainWindow::showEvent(QShowEvent* event) if (newCatDialog.clickedButton() == &importBtn) { importCategories(false); } else if (newCatDialog.clickedButton() == &cancelBtn) { - m_CategoryFactory->reset(); + m_CategoryFactory.reset(); } else if (newCatDialog.clickedButton() == &defaultBtn) { - m_CategoryFactory->loadCategories(); + m_CategoryFactory.loadCategories(); } - m_CategoryFactory->saveCategories(); + m_CategoryFactory.saveCategories(); m_OrganizerCore.settings().setFirstStart(false); } else { @@ -2087,7 +2088,7 @@ void MainWindow::fixCategories() std::set categories = modInfo->getCategories(); for (std::set::iterator iter = categories.begin(); iter != categories.end(); ++iter) { - if (!m_CategoryFactory->categoryExists(*iter)) { + if (!m_CategoryFactory.categoryExists(*iter)) { modInfo->setCategory(*iter, false); } } @@ -2831,12 +2832,20 @@ void MainWindow::onPluginRegistrationChanged() m_DownloadsTab->update(); } +void MainWindow::refreshNexusCategories(CategoriesDialog* dialog) +{ + NexusInterface& nexus = NexusInterface::instance(); + nexus.setPluginContainer(&m_PluginContainer); + nexus.requestGameInfo(Settings::instance().game().plugin()->gameShortName(), dialog, + QVariant(), QString()); +} + void MainWindow::categoriesSaved() { for (auto modName : m_OrganizerCore.modList()->allMods()) { auto mod = ModInfo::getByName(modName); for (auto category : mod->getCategories()) { - if (!m_CategoryFactory->categoryExists(category)) + if (!m_CategoryFactory.categoryExists(category)) mod->setCategory(category, false); } } @@ -3457,14 +3466,14 @@ void MainWindow::nxmGameInfoAvailable(QString gameName, QVariant, QVariant resul { QVariantMap result = resultData.toMap(); QVariantList categories = result["categories"].toList(); - CategoryFactory* catFactory = CategoryFactory::instance(); - catFactory->reset(); + CategoryFactory& catFactory = CategoryFactory::instance(); + catFactory.reset(); for (auto category : categories) { auto catMap = category.toMap(); std::vector nexusCat; nexusCat.push_back(CategoryFactory::NexusCategory(catMap["name"].toString(), catMap["category_id"].toInt())); - catFactory->addCategory(catMap["name"].toString(), nexusCat, 0); + catFactory.addCategory(catMap["name"].toString(), nexusCat, 0); } } diff --git a/src/mainwindow.h b/src/mainwindow.h index eae50aa0..99feca83 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -283,7 +283,7 @@ private: QAction* m_ContextAction; - CategoryFactory* m_CategoryFactory; + CategoryFactory& m_CategoryFactory; QTimer m_CheckBSATimer; QTimer m_SaveMetaTimer; @@ -363,6 +363,7 @@ private slots: void importCategories(bool); + void refreshNexusCategories(CategoriesDialog* dialog); void categoriesSaved(); // update info diff --git a/src/moapplication.cpp b/src/moapplication.cpp index 7e95217e..e131d3d9 100644 --- a/src/moapplication.cpp +++ b/src/moapplication.cpp @@ -296,7 +296,7 @@ int MOApplication::setup(MOMultiProcess& multiProcess, bool forceSelect) m_instance->gamePlugin()->steamAPPId(), m_instance->gamePlugin()->gameDirectory().absolutePath()); - CategoryFactory::instance()->loadCategories(); + CategoryFactory::instance().loadCategories(); m_core->updateExecutablesList(); m_core->updateModInfoFromDisc(); m_core->setCurrentProfile(m_instance->profileName()); diff --git a/src/modinfo.cpp b/src/modinfo.cpp index 0ae28e73..1028c66f 100644 --- a/src/modinfo.cpp +++ b/src/modinfo.cpp @@ -493,9 +493,9 @@ void ModInfo::setPluginSelected(const bool& isSelected) void ModInfo::addCategory(const QString& categoryName) { - int id = CategoryFactory::instance()->getCategoryID(categoryName); + int id = CategoryFactory::instance().getCategoryID(categoryName); if (id == -1) { - id = CategoryFactory::instance()->addCategory( + id = CategoryFactory::instance().addCategory( categoryName, std::vector(), 0); } setCategory(id, true); @@ -503,7 +503,7 @@ void ModInfo::addCategory(const QString& categoryName) bool ModInfo::removeCategory(const QString& categoryName) { - int id = CategoryFactory::instance()->getCategoryID(categoryName); + int id = CategoryFactory::instance().getCategoryID(categoryName); if (id == -1) { return false; } @@ -518,9 +518,9 @@ QStringList ModInfo::categories() const { QStringList result; - CategoryFactory* catFac = CategoryFactory::instance(); + CategoryFactory& catFac = CategoryFactory::instance(); for (int id : m_Categories) { - result.append(catFac->getCategoryName(catFac->getCategoryIndex(id))); + result.append(catFac.getCategoryName(catFac.getCategoryIndex(id))); } return result; @@ -550,7 +550,7 @@ bool ModInfo::categorySet(int categoryID) const for (std::set::const_iterator iter = m_Categories.begin(); iter != m_Categories.end(); ++iter) { if ((*iter == categoryID) || - (CategoryFactory::instance()->isDescendantOf(*iter, categoryID))) { + (CategoryFactory::instance().isDescendantOf(*iter, categoryID))) { return true; } } diff --git a/src/modinfodialogcategories.cpp b/src/modinfodialogcategories.cpp index 5665df9f..a7a4ce1e 100644 --- a/src/modinfodialogcategories.cpp +++ b/src/modinfodialogcategories.cpp @@ -44,19 +44,19 @@ bool CategoriesTab::usesOriginFiles() const return false; } -void CategoriesTab::add(const CategoryFactory* factory, +void CategoriesTab::add(const CategoryFactory& factory, const std::set& enabledCategories, QTreeWidgetItem* root, int rootLevel) { - for (int i = 0; i < static_cast(factory->numCategories()); ++i) { - if (factory->getParentID(i) != rootLevel) { + for (int i = 0; i < static_cast(factory.numCategories()); ++i) { + if (factory.getParentID(i) != rootLevel) { continue; } - int categoryID = factory->getCategoryID(i); + int categoryID = factory.getCategoryID(i); QTreeWidgetItem* newItem = - new QTreeWidgetItem(QStringList(factory->getCategoryName(i))); + new QTreeWidgetItem(QStringList(factory.getCategoryName(i))); newItem->setFlags(newItem->flags() | Qt::ItemIsUserCheckable); @@ -67,7 +67,7 @@ void CategoriesTab::add(const CategoryFactory* factory, newItem->setData(0, Qt::UserRole, categoryID); - if (factory->hasChildren(i)) { + if (factory.hasChildren(i)) { add(factory, enabledCategories, newItem, categoryID); } diff --git a/src/modinfodialogcategories.h b/src/modinfodialogcategories.h index b390146c..03b3555b 100644 --- a/src/modinfodialogcategories.h +++ b/src/modinfodialogcategories.h @@ -13,7 +13,7 @@ public: bool usesOriginFiles() const override; private: - void add(const CategoryFactory* factory, const std::set& enabledCategories, + void add(const CategoryFactory& factory, const std::set& enabledCategories, QTreeWidgetItem* root, int rootLevel); void updatePrimary(); diff --git a/src/modinforegular.cpp b/src/modinforegular.cpp index 58590477..c79fc574 100644 --- a/src/modinforegular.cpp +++ b/src/modinforegular.cpp @@ -213,7 +213,7 @@ void ModInfoRegular::readMeta() continue; } if (ok && (categoryID != 0) && - (CategoryFactory::instance()->categoryExists(categoryID))) { + (CategoryFactory::instance().categoryExists(categoryID))) { m_Categories.insert(categoryID); if (iter == categories.begin()) { m_PrimaryCategory = categoryID; @@ -578,7 +578,7 @@ void ModInfoRegular::setInstallationFile(const QString& fileName) void ModInfoRegular::addNexusCategory(int categoryID) { - m_Categories.insert(CategoryFactory::instance()->resolveNexusID(categoryID)); + m_Categories.insert(CategoryFactory::instance().resolveNexusID(categoryID)); } void ModInfoRegular::setIsEndorsed(bool endorsed) @@ -734,15 +734,15 @@ QString ModInfoRegular::getDescription() const const std::set& categories = getCategories(); std::wostringstream categoryString; categoryString << ToWString(tr("Categories:
")); - CategoryFactory* categoryFactory = CategoryFactory::instance(); + CategoryFactory& categoryFactory = CategoryFactory::instance(); for (std::set::const_iterator catIter = categories.begin(); catIter != categories.end(); ++catIter) { if (catIter != categories.begin()) { categoryString << " , "; } categoryString << "" - << ToWString(categoryFactory->getCategoryName( - categoryFactory->getCategoryIndex(*catIter))) + << ToWString(categoryFactory.getCategoryName( + categoryFactory.getCategoryIndex(*catIter))) << ""; } diff --git a/src/modlist.cpp b/src/modlist.cpp index 9f64cc71..7a951369 100644 --- a/src/modlist.cpp +++ b/src/modlist.cpp @@ -232,11 +232,11 @@ QVariant ModList::data(const QModelIndex& modelIndex, int role) const } else { int category = modInfo->primaryCategory(); if (category != -1) { - CategoryFactory* categoryFactory = CategoryFactory::instance(); - if (categoryFactory->categoryExists(category)) { + CategoryFactory& categoryFactory = CategoryFactory::instance(); + if (categoryFactory.categoryExists(category)) { try { - int categoryIdx = categoryFactory->getCategoryIndex(category); - return categoryFactory->getCategoryName(categoryIdx); + int categoryIdx = categoryFactory.getCategoryIndex(category); + return categoryFactory.getCategoryName(categoryIdx); } catch (const std::exception& e) { log::error("failed to retrieve category name: {}", e.what()); return QString(); @@ -286,10 +286,10 @@ QVariant ModList::data(const QModelIndex& modelIndex, int role) const if (column == COL_CATEGORY) { QVariantList categoryNames; std::set categories = modInfo->getCategories(); - CategoryFactory* categoryFactory = CategoryFactory::instance(); + CategoryFactory& categoryFactory = CategoryFactory::instance(); for (auto iter = categories.begin(); iter != categories.end(); ++iter) { categoryNames.append( - categoryFactory->getCategoryName(categoryFactory->getCategoryIndex(*iter))); + categoryFactory.getCategoryName(categoryFactory.getCategoryIndex(*iter))); } if (categoryNames.count() != 0) { return categoryNames; @@ -447,7 +447,7 @@ QVariant ModList::data(const QModelIndex& modelIndex, int role) const const std::set& categories = modInfo->getCategories(); std::wostringstream categoryString; categoryString << ToWString(tr("Categories:
")); - CategoryFactory* categoryFactory = CategoryFactory::instance(); + CategoryFactory& categoryFactory = CategoryFactory::instance(); for (std::set::const_iterator catIter = categories.begin(); catIter != categories.end(); ++catIter) { if (catIter != categories.begin()) { @@ -455,8 +455,8 @@ QVariant ModList::data(const QModelIndex& modelIndex, int role) const } try { categoryString << "" - << ToWString(categoryFactory->getCategoryName( - categoryFactory->getCategoryIndex(*catIter))) + << ToWString(categoryFactory.getCategoryName( + categoryFactory.getCategoryIndex(*catIter))) << ""; } catch (const std::exception& e) { log::error("failed to generate tooltip: {}", e.what()); diff --git a/src/modlistsortproxy.cpp b/src/modlistsortproxy.cpp index e61f9494..704ec10b 100644 --- a/src/modlistsortproxy.cpp +++ b/src/modlistsortproxy.cpp @@ -171,11 +171,11 @@ bool ModListSortProxy::lessThan(const QModelIndex& left, const QModelIndex& righ lt = true; else { try { - CategoryFactory* categories = CategoryFactory::instance(); - QString leftCatName = categories->getCategoryName( - categories->getCategoryIndex(leftMod->primaryCategory())); - QString rightCatName = categories->getCategoryName( - categories->getCategoryIndex(rightMod->primaryCategory())); + CategoryFactory& categories = CategoryFactory::instance(); + QString leftCatName = categories.getCategoryName( + categories.getCategoryIndex(leftMod->primaryCategory())); + QString rightCatName = categories.getCategoryName( + categories.getCategoryIndex(rightMod->primaryCategory())); lt = leftCatName < rightCatName; } catch (const std::exception& e) { log::error("failed to compare categories: {}", e.what()); diff --git a/src/modlistviewactions.cpp b/src/modlistviewactions.cpp index d82dca87..983574ab 100644 --- a/src/modlistviewactions.cpp +++ b/src/modlistviewactions.cpp @@ -288,13 +288,13 @@ void ModListViewActions::assignCategories() const nexusCategory = downloadMeta.value("category", 0).toInt(); } } - int newCategory = CategoryFactory::instance()->resolveNexusID(nexusCategory); + int newCategory = CategoryFactory::instance().resolveNexusID(nexusCategory); if (newCategory != 0) { for (auto category : modInfo->categories()) { modInfo->removeCategory(category); } } - modInfo->setCategory(CategoryFactory::instance()->getCategoryID(newCategory), true); + modInfo->setCategory(CategoryFactory::instance().getCategoryID(newCategory), true); } } @@ -1136,10 +1136,10 @@ void ModListViewActions::remapCategory(const QModelIndexList& indices) const } } unsigned int categoryIndex = - CategoryFactory::instance()->resolveNexusID(categoryID); + CategoryFactory::instance().resolveNexusID(categoryID); if (categoryIndex != 0) modInfo->setPrimaryCategory( - CategoryFactory::instance()->getCategoryID(categoryIndex)); + CategoryFactory::instance().getCategoryID(categoryIndex)); } } diff --git a/src/organizercore.cpp b/src/organizercore.cpp index 3781a4e1..dda731ba 100644 --- a/src/organizercore.cpp +++ b/src/organizercore.cpp @@ -804,7 +804,7 @@ OrganizerCore::doInstall(const QString& archivePath, GuessedValue modNa return {modIndex, modInfo}; } else { if (result.result() == MOBase::IPluginInstaller::RESULT_CATEGORYREQUESTED) { - CategoriesDialog dialog(&pluginContainer(), qApp->activeWindow()); + CategoriesDialog dialog(qApp->activeWindow()); if (dialog.exec() == QDialog::Accepted) { dialog.commitChanges(); @@ -831,6 +831,7 @@ OrganizerCore::doInstall(const QString& archivePath, GuessedValue modNa ModInfo::Ptr OrganizerCore::installDownload(int index, int priority) { + ScopedDisableDirWatcher scopedDirwatcher(&m_DownloadManager); try { QString fileName = m_DownloadManager.getFilePath(index); QString gameName = m_DownloadManager.getGameName(index); diff --git a/src/settingsdialoggeneral.cpp b/src/settingsdialoggeneral.cpp index 6a666437..62b26c2f 100644 --- a/src/settingsdialoggeneral.cpp +++ b/src/settingsdialoggeneral.cpp @@ -160,7 +160,7 @@ void GeneralSettingsTab::resetDialogs() void GeneralSettingsTab::onEditCategories() { - CategoriesDialog catDialog(m_PluginContainer, &dialog()); + CategoriesDialog catDialog(&dialog()); if (catDialog.exec() == QDialog::Accepted) { catDialog.commitChanges(); -- cgit v1.3.1 From efdff42d5f6cdf5044e741ad7aa00bf73991c422 Mon Sep 17 00:00:00 2001 From: Jeremy Rimpo Date: Sat, 23 Sep 2023 20:59:40 -0500 Subject: Make category struct attributes private --- src/categories.cpp | 61 +++++++++++++++++++++------------------------- src/categories.h | 44 ++++++++++++++++++++++----------- src/categoriesdialog.cpp | 16 ++++++------ src/downloadmanager.cpp | 2 +- src/modlistviewactions.cpp | 3 +-- 5 files changed, 68 insertions(+), 58 deletions(-) (limited to 'src/modlistviewactions.cpp') diff --git a/src/categories.cpp b/src/categories.cpp index 5d0d2bb7..1e2997fb 100644 --- a/src/categories.cpp +++ b/src/categories.cpp @@ -131,7 +131,7 @@ void CategoryFactory::loadCategories() nexCells[0].constData()); } m_NexusMap.insert_or_assign(nexID, NexusCategory(nexName, nexID)); - m_NexusMap.at(nexID).m_CategoryID = catID; + m_NexusMap.at(nexID).setCategoryID(catID); } else { log::error(tr("invalid nexus category line {}: {} ({} cells)").toStdString(), lineNum, nexLine.constData(), nexCells.count()); @@ -157,10 +157,6 @@ void CategoryFactory::reset() m_Categories.clear(); m_NexusMap.clear(); m_IDMap.clear(); - // 28 = - // 43 = Savegames (makes no sense to install them through MO) - // 45 = Videos and trailers - // 87 = Miscelanous addCategory(0, "None", std::vector(), 0); } @@ -168,16 +164,16 @@ void CategoryFactory::setParents() { for (std::vector::iterator iter = m_Categories.begin(); iter != m_Categories.end(); ++iter) { - iter->m_HasChildren = false; + iter->setHasChildren(false); } for (std::vector::const_iterator categoryIter = m_Categories.begin(); categoryIter != m_Categories.end(); ++categoryIter) { - if (categoryIter->m_ParentID != 0) { + if (categoryIter->parentID() != 0) { std::map::const_iterator iter = - m_IDMap.find(categoryIter->m_ParentID); + m_IDMap.find(categoryIter->parentID()); if (iter != m_IDMap.end()) { - m_Categories[iter->second].m_HasChildren = true; + m_Categories[iter->second].setHasChildren(true); } } } @@ -201,15 +197,15 @@ void CategoryFactory::saveCategories() categoryFile.resize(0); for (std::vector::const_iterator iter = m_Categories.begin(); iter != m_Categories.end(); ++iter) { - if (iter->m_ID == 0) { + if (iter->ID() == 0) { continue; } QByteArray line; - line.append(QByteArray::number(iter->m_ID)) + line.append(QByteArray::number(iter->ID())) .append("|") - .append(iter->m_Name.toUtf8()) + .append(iter->name().toUtf8()) .append("|") - .append(QByteArray::number(iter->m_ParentID)) + .append(QByteArray::number(iter->parentID())) .append("\n"); categoryFile.write(line); } @@ -225,9 +221,9 @@ void CategoryFactory::saveCategories() nexusMapFile.resize(0); for (auto iter = m_NexusMap.begin(); iter != m_NexusMap.end(); ++iter) { QByteArray line; - line.append(QByteArray::number(iter->second.m_CategoryID)).append("|"); - line.append(iter->second.m_Name.toUtf8()).append("|"); - line.append(QByteArray::number(iter->second.m_ID)).append("\n"); + line.append(QByteArray::number(iter->second.categoryID())).append("|"); + line.append(iter->second.name().toUtf8()).append("|"); + line.append(QByteArray::number(iter->second.ID())).append("\n"); nexusMapFile.write(line); } nexusMapFile.close(); @@ -274,8 +270,8 @@ void CategoryFactory::addCategory(int id, const QString& name, int parentID) { for (auto nexusCat : nexusCats) { - m_NexusMap.insert_or_assign(nexusCat.m_ID, nexusCat); - m_NexusMap.at(nexusCat.m_ID).m_CategoryID = id; + m_NexusMap.insert_or_assign(nexusCat.ID(), nexusCat); + m_NexusMap.at(nexusCat.ID()).setCategoryID(id); } int index = static_cast(m_Categories.size()); m_Categories.push_back(Category(index, id, name, parentID, nexusCats)); @@ -285,9 +281,8 @@ void CategoryFactory::addCategory(int id, const QString& name, void CategoryFactory::setNexusCategories( std::vector& nexusCats) { - m_NexusMap.clear(); for (auto nexusCat : nexusCats) { - m_NexusMap.emplace(nexusCat.m_ID, nexusCat); + m_NexusMap.emplace(nexusCat.ID(), nexusCat); } saveCategories(); @@ -367,7 +362,7 @@ int CategoryFactory::getParentID(unsigned int index) const throw MyException(tr("invalid category index: %1").arg(index)); } - return m_Categories[index].m_ParentID; + return m_Categories[index].parentID(); } bool CategoryFactory::categoryExists(int id) const @@ -394,12 +389,12 @@ bool CategoryFactory::isDescendantOfImpl(int id, int parentID, if (iter != m_IDMap.end()) { unsigned int index = iter->second; - if (m_Categories[index].m_ParentID == 0) { + if (m_Categories[index].parentID() == 0) { return false; - } else if (m_Categories[index].m_ParentID == parentID) { + } else if (m_Categories[index].parentID() == parentID) { return true; } else { - return isDescendantOfImpl(m_Categories[index].m_ParentID, parentID, seen); + return isDescendantOfImpl(m_Categories[index].parentID(), parentID, seen); } } else { log::warn(tr("{} is no valid category id").toStdString(), id); @@ -413,7 +408,7 @@ bool CategoryFactory::hasChildren(unsigned int index) const throw MyException(tr("invalid category index: %1").arg(index)); } - return m_Categories[index].m_HasChildren; + return m_Categories[index].hasChildren(); } QString CategoryFactory::getCategoryName(unsigned int index) const @@ -422,7 +417,7 @@ QString CategoryFactory::getCategoryName(unsigned int index) const throw MyException(tr("invalid category index: %1").arg(index)); } - return m_Categories[index].m_Name; + return m_Categories[index].name(); } QString CategoryFactory::getSpecialCategoryName(SpecialCategories type) const @@ -480,7 +475,7 @@ QString CategoryFactory::getCategoryNameByID(int id) const return {}; } - return m_Categories[index].m_Name; + return m_Categories[index].name(); } } @@ -490,7 +485,7 @@ int CategoryFactory::getCategoryID(unsigned int index) const throw MyException(tr("invalid category index: %1").arg(index)); } - return m_Categories[index].m_ID; + return m_Categories[index].ID(); } int CategoryFactory::getCategoryIndex(int ID) const @@ -506,11 +501,11 @@ int CategoryFactory::getCategoryID(const QString& name) const { auto iter = std::find_if(m_Categories.begin(), m_Categories.end(), [name](const Category& cat) -> bool { - return cat.m_Name == name; + return cat.name() == name; }); if (iter != m_Categories.end()) { - return iter->m_ID; + return iter->ID(); } else { return -1; } @@ -520,10 +515,10 @@ unsigned int CategoryFactory::resolveNexusID(int nexusID) const { auto result = m_NexusMap.find(nexusID); if (result != m_NexusMap.end()) { - if (m_IDMap.count(result->second.m_CategoryID)) { + if (m_IDMap.count(result->second.categoryID())) { log::debug(tr("nexus category id {} maps to internal {}").toStdString(), nexusID, - m_IDMap.at(result->second.m_CategoryID)); - return m_IDMap.at(result->second.m_CategoryID); + m_IDMap.at(result->second.categoryID())); + return m_IDMap.at(result->second.categoryID()); } } log::debug(tr("nexus category id {} not mapped").toStdString(), nexusID); diff --git a/src/categories.h b/src/categories.h index b7a9c214..a6ee2e24 100644 --- a/src/categories.h +++ b/src/categories.h @@ -58,46 +58,62 @@ public: public: struct NexusCategory { - NexusCategory(const QString& name, const int nexusID) : m_Name(name), m_ID(nexusID) + NexusCategory(const QString name, const int nexusID) : m_Name(name), m_ID(nexusID) {} - QString m_Name; - int m_ID; - int m_CategoryID = -1; friend bool operator==(const NexusCategory& LHS, const NexusCategory& RHS) { - return LHS.m_ID == RHS.m_ID; + return LHS.ID() == RHS.ID(); } friend bool operator==(const NexusCategory& LHS, const int RHS) { - return LHS.m_ID == RHS; + return LHS.ID() == RHS; } friend bool operator<(const NexusCategory& LHS, const NexusCategory& RHS) { - return LHS.m_ID < RHS.m_ID; + return LHS.ID() < RHS.ID(); } + + QString name() const { return m_Name; } + int ID() const { return m_ID; } + int categoryID() const { return m_CategoryID; } + void setCategoryID(int categoryID) { m_CategoryID = categoryID; } + + private: + QString m_Name; + int m_ID; + int m_CategoryID = -1; }; struct Category { - Category(int sortValue, int id, const QString& name, int parentID, + Category(int sortValue, int id, const QString name, int parentID, std::vector nexusCats) : m_SortValue(sortValue), m_ID(id), m_Name(name), m_HasChildren(false), m_ParentID(parentID), m_NexusCats(nexusCats) {} + + friend bool operator<(const Category& LHS, const Category& RHS) + { + return LHS.sortValue() < RHS.sortValue(); + } + + int sortValue() const { return m_SortValue; } + int ID() const { return m_ID; } + int parentID() const { return m_ParentID; } + QString name() const { return m_Name; } + bool hasChildren() const { return m_HasChildren; } + void setHasChildren(bool b) { m_HasChildren = b; } + + private: int m_SortValue; int m_ID; int m_ParentID; - bool m_HasChildren; QString m_Name; std::vector m_NexusCats; - - friend bool operator<(const Category& LHS, const Category& RHS) - { - return LHS.m_SortValue < RHS.m_SortValue; - } + bool m_HasChildren; }; public: diff --git a/src/categoriesdialog.cpp b/src/categoriesdialog.cpp index 53c930f3..b770fa0b 100644 --- a/src/categoriesdialog.cpp +++ b/src/categoriesdialog.cpp @@ -213,7 +213,7 @@ void CategoriesDialog::fillTable() categories.m_Categories.begin(); iter != categories.m_Categories.end(); ++iter, ++row) { const CategoryFactory::Category& category = *iter; - if (category.m_ID == 0) { + if (category.ID() == 0) { --row; continue; } @@ -221,11 +221,11 @@ void CategoriesDialog::fillTable() // table->setVerticalHeaderItem(row, new QTableWidgetItem(" ")); QScopedPointer idItem(new QTableWidgetItem()); - idItem->setData(Qt::DisplayRole, category.m_ID); + idItem->setData(Qt::DisplayRole, category.ID()); - QScopedPointer nameItem(new QTableWidgetItem(category.m_Name)); + QScopedPointer nameItem(new QTableWidgetItem(category.name())); QScopedPointer parentIDItem(new QTableWidgetItem()); - parentIDItem->setData(Qt::DisplayRole, category.m_ParentID); + parentIDItem->setData(Qt::DisplayRole, category.parentID()); QScopedPointer nexusCatItem(new QTableWidgetItem()); table->setItem(row, 0, idItem.take()); @@ -236,15 +236,15 @@ void CategoriesDialog::fillTable() for (auto nexusCat : categories.m_NexusMap) { QScopedPointer nexusItem(new QListWidgetItem()); - nexusItem->setData(Qt::DisplayRole, nexusCat.second.m_Name); - nexusItem->setData(Qt::UserRole, nexusCat.second.m_ID); + nexusItem->setData(Qt::DisplayRole, nexusCat.second.name()); + nexusItem->setData(Qt::UserRole, nexusCat.second.ID()); list->addItem(nexusItem.take()); auto item = table->item(categories.resolveNexusID(nexusCat.first) - 1, 3); if (item != nullptr) { auto itemData = item->data(Qt::UserRole).toList(); QVariantList newData; - newData.append(nexusCat.second.m_Name); - newData.append(nexusCat.second.m_ID); + newData.append(nexusCat.second.name()); + newData.append(nexusCat.second.ID()); itemData.insert(itemData.length(), newData); QStringList names; for (auto cat : itemData) { diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp index d7a72c0b..6894b401 100644 --- a/src/downloadmanager.cpp +++ b/src/downloadmanager.cpp @@ -432,7 +432,7 @@ void DownloadManager::refreshList() log::debug("saw {} downloads", m_ActiveDownloads.size()); - emit update(-1); + emit update(-1); } catch (const std::bad_alloc&) { reportError(tr("Memory allocation error (in refreshing directory).")); diff --git a/src/modlistviewactions.cpp b/src/modlistviewactions.cpp index 983574ab..cbac9c6c 100644 --- a/src/modlistviewactions.cpp +++ b/src/modlistviewactions.cpp @@ -1135,8 +1135,7 @@ void ModListViewActions::remapCategory(const QModelIndexList& indices) const categoryID = downloadMeta.value("category", 0).toInt(); } } - unsigned int categoryIndex = - CategoryFactory::instance().resolveNexusID(categoryID); + unsigned int categoryIndex = CategoryFactory::instance().resolveNexusID(categoryID); if (categoryIndex != 0) modInfo->setPrimaryCategory( CategoryFactory::instance().getCategoryID(categoryIndex)); -- cgit v1.3.1