diff options
| author | Mikaël Capelle <capelle.mikael@gmail.com> | 2020-12-31 02:36:41 +0100 |
|---|---|---|
| committer | Mikaël Capelle <capelle.mikael@gmail.com> | 2021-01-02 15:38:17 +0100 |
| commit | 51281ac304f64170d310ae543d50879614c550d3 (patch) | |
| tree | bb1e03edaafd2525bbac002169b9bd0d9dcd1fb6 /src | |
| parent | 6e4b1790ae4057dfafd39dadff04c8d9b5f2eaeb (diff) | |
Clean visitOnX methods.
Diffstat (limited to 'src')
| -rw-r--r-- | src/modlistviewactions.cpp | 98 | ||||
| -rw-r--r-- | src/modlistviewactions.h | 1 |
2 files changed, 52 insertions, 47 deletions
diff --git a/src/modlistviewactions.cpp b/src/modlistviewactions.cpp index 9a00353f..f8fd0e4c 100644 --- a/src/modlistviewactions.cpp +++ b/src/modlistviewactions.cpp @@ -590,73 +590,77 @@ void ModListViewActions::markConverted(const QModelIndexList& indices) const void ModListViewActions::visitOnNexus(const QModelIndexList& indices) const { - if (indices.size() > 1) { - if (indices.size() > 10) { - if (QMessageBox::question(m_view, tr("Opening Nexus Links"), - tr("You are trying to open %1 links to Nexus Mods. Are you sure you want to do this?").arg(indices.size()), - QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) { - return; - } - } - int row_idx; - ModInfo::Ptr info; - QString gameName; - - for (auto& idx : indices) { - row_idx = idx.data(ModList::IndexRole).toInt(); - info = ModInfo::getByIndex(row_idx); - int modID = info->nexusId(); - gameName = info->gameName(); - if (modID > 0) { - shell::Open(QUrl(NexusInterface::instance().getModURL(modID, gameName))); - } - else { - log::error("mod '{}' has no nexus id", info->name()); - } + if (indices.size() > 10) { + if (QMessageBox::question(m_view, tr("Opening Nexus Links"), + tr("You are trying to open %1 links to Nexus Mods. Are you sure you want to do this?").arg(indices.size()), + QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) { + return; } } - else if (!indices.isEmpty()) { - int modID = indices[0].data(Qt::UserRole).toInt(); - QString gameName = indices[0].data(Qt::UserRole + 4).toString(); + + for (auto& idx : indices) { + ModInfo::Ptr info = ModInfo::getByIndex(idx.data(ModList::IndexRole).toInt()); + int modID = info->nexusId(); + QString gameName = info->gameName(); if (modID > 0) { shell::Open(QUrl(NexusInterface::instance().getModURL(modID, gameName))); } else { - MessageDialog::showMessage(tr("Nexus ID for this mod is unknown"), m_view); + log::error("mod '{}' has no nexus id", info->name()); } } } void ModListViewActions::visitWebPage(const QModelIndexList& indices) const { - if (indices.size() > 1) { - if (indices.size() > 10) { - if (QMessageBox::question(m_view, tr("Opening Web Pages"), - tr("You are trying to open %1 Web Pages. Are you sure you want to do this?").arg(indices.size()), - QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) { - return; - } + if (indices.size() > 10) { + if (QMessageBox::question(m_view, tr("Opening Web Pages"), + tr("You are trying to open %1 Web Pages. Are you sure you want to do this?").arg(indices.size()), + QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) { + return; } - int row_idx; - ModInfo::Ptr info; - QString gameName; - for (auto& idx : indices) { - row_idx = idx.data(ModList::IndexRole).toInt(); - info = ModInfo::getByIndex(row_idx); + } - const auto url = info->parseCustomURL(); - if (url.isValid()) { - shell::Open(url); - } + for (auto& idx : indices) { + ModInfo::Ptr info = ModInfo::getByIndex(idx.data(ModList::IndexRole).toInt()); + + const auto url = info->parseCustomURL(); + if (url.isValid()) { + shell::Open(url); + } + } +} + +void ModListViewActions::visitNexusOrWebPage(const QModelIndexList& indices) const +{ + if (indices.size() > 10) { + if (QMessageBox::question(m_view, tr("Opening Web Pages"), + tr("You are trying to open %1 Web Pages. Are you sure you want to do this?").arg(indices.size()), + QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) { + return; } } - else if (!indices.isEmpty()) { - ModInfo::Ptr info = ModInfo::getByIndex(indices[0].data(ModList::IndexRole).toInt()); + for (auto& idx : indices) { + ModInfo::Ptr info = ModInfo::getByIndex(idx.data(ModList::IndexRole).toInt()); + if (!info) { + log::error("mod {} not found", idx.data(ModList::IndexRole).toInt()); + continue; + } + + int modID = info->nexusId(); + QString gameName = info->gameName(); const auto url = info->parseCustomURL(); - if (url.isValid()) { + + if (modID > 0) { + shell::Open(QUrl(NexusInterface::instance().getModURL(modID, gameName))); + } + else if (url.isValid()) { shell::Open(url); } + else { + log::error("mod '{}' has no valid link", info->name()); + } } } diff --git a/src/modlistviewactions.h b/src/modlistviewactions.h index 33442ce7..52db019c 100644 --- a/src/modlistviewactions.h +++ b/src/modlistviewactions.h @@ -68,6 +68,7 @@ public: void markConverted(const QModelIndexList& indices) const; void visitOnNexus(const QModelIndexList& indices) const; void visitWebPage(const QModelIndexList& indices) const; + void visitNexusOrWebPage(const QModelIndexList& indices) const; // set/reset color of the given selection, using the given reference index (index // at which the context menu was shown) |
