From 51281ac304f64170d310ae543d50879614c550d3 Mon Sep 17 00:00:00 2001 From: Mikaƫl Capelle Date: Thu, 31 Dec 2020 02:36:41 +0100 Subject: Clean visitOnX methods. --- src/modlistviewactions.cpp | 98 ++++++++++++++++++++++++---------------------- 1 file changed, 51 insertions(+), 47 deletions(-) (limited to 'src/modlistviewactions.cpp') 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()); + } } } -- cgit v1.3.1