summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mainwindow.cpp112
-rw-r--r--src/mainwindow.h7
-rw-r--r--src/modlistcontextmenu.cpp264
-rw-r--r--src/modlistcontextmenu.h18
-rw-r--r--src/modlistview.h4
-rw-r--r--src/modlistviewactions.cpp103
-rw-r--r--src/modlistviewactions.h19
7 files changed, 192 insertions, 335 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 58061c96..265cc5c2 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -2629,70 +2629,9 @@ void MainWindow::overwriteClosed(int)
m_OrganizerCore.refreshDirectoryStructure();
}
-
-void MainWindow::displayModInformation(
- ModInfo::Ptr modInfo, unsigned int modIndex, ModInfoTabIDs tabID)
+void MainWindow::displayModInformation(ModInfo::Ptr modInfo, unsigned int modIndex, ModInfoTabIDs tabID)
{
- if (!m_OrganizerCore.modList()->modInfoAboutToChange(modInfo)) {
- log::debug("A different mod information dialog is open. If this is incorrect, please restart MO");
- return;
- }
- std::vector<ModInfo::EFlag> flags = modInfo->getFlags();
- if (std::find(flags.begin(), flags.end(), ModInfo::FLAG_OVERWRITE) != flags.end()) {
- QDialog *dialog = this->findChild<QDialog*>("__overwriteDialog");
- try {
- if (dialog == nullptr) {
- dialog = new OverwriteInfoDialog(modInfo, this);
- dialog->setObjectName("__overwriteDialog");
- } else {
- qobject_cast<OverwriteInfoDialog*>(dialog)->setModInfo(modInfo);
- }
-
- dialog->show();
- dialog->raise();
- dialog->activateWindow();
- connect(dialog, SIGNAL(finished(int)), this, SLOT(overwriteClosed(int)));
- } catch (const std::exception &e) {
- reportError(tr("Failed to display overwrite dialog: %1").arg(e.what()));
- }
- } else {
- modInfo->saveMeta();
-
- ModInfoDialog dialog(this, &m_OrganizerCore, &m_PluginContainer, modInfo);
- connect(&dialog, SIGNAL(originModified(int)), this, SLOT(originModified(int)));
-
- //Open the tab first if we want to use the standard indexes of the tabs.
- if (tabID != ModInfoTabIDs::None) {
- dialog.selectTab(tabID);
- }
-
- dialog.exec();
-
- modInfo->saveMeta();
- emit modInfoDisplayed();
- m_OrganizerCore.modList()->modInfoChanged(modInfo);
- }
-
- if (m_OrganizerCore.currentProfile()->modEnabled(modIndex)
- && !modInfo->hasFlag(ModInfo::FLAG_FOREIGN)) {
- FilesOrigin& origin = m_OrganizerCore.directoryStructure()->getOriginByName(ToWString(modInfo->name()));
- origin.enable(false);
-
- if (m_OrganizerCore.directoryStructure()->originExists(ToWString(modInfo->name()))) {
- FilesOrigin& origin = m_OrganizerCore.directoryStructure()->getOriginByName(ToWString(modInfo->name()));
- origin.enable(false);
-
- m_OrganizerCore.directoryRefresher()->addModToStructure(m_OrganizerCore.directoryStructure()
- , modInfo->name()
- , m_OrganizerCore.currentProfile()->getModPriority(modIndex)
- , modInfo->absolutePath()
- , modInfo->stealFiles()
- , modInfo->archives());
- DirectoryRefresher::cleanStructure(m_OrganizerCore.directoryStructure());
- m_OrganizerCore.directoryStructure()->getFileRegister()->sortOrigins();
- m_OrganizerCore.refreshLists();
- }
- }
+ ui->modList->actions().displayModInformation(modInfo, modIndex, tabID);
}
bool MainWindow::closeWindow()
@@ -2723,26 +2662,6 @@ ModInfo::Ptr MainWindow::previousModInList(int modIndex)
return ModInfo::getByIndex(modIndex);
}
-void MainWindow::displayModInformation(const QString &modName, ModInfoTabIDs tabID)
-{
- unsigned int index = ModInfo::getIndex(modName);
- if (index == UINT_MAX) {
- log::error("failed to resolve mod name {}", modName);
- return;
- }
-
- ModInfo::Ptr modInfo = ModInfo::getByIndex(index);
- displayModInformation(modInfo, index, tabID);
-}
-
-
-void MainWindow::displayModInformation(int row, ModInfoTabIDs tabID)
-{
- ModInfo::Ptr modInfo = ModInfo::getByIndex(row);
- displayModInformation(modInfo, row, tabID);
-}
-
-
void MainWindow::ignoreMissingData_clicked(int modIndex)
{
const auto rows = ui->modList->selectionModel()->selectedRows();
@@ -3141,7 +3060,7 @@ void MainWindow::updatePluginCount()
void MainWindow::information_clicked(int modIndex)
{
try {
- displayModInformation(modIndex);
+ ui->modList->actions().displayModInformation(modIndex);
} catch (const std::exception &e) {
reportError(e.what());
}
@@ -3388,7 +3307,7 @@ void MainWindow::on_modList_doubleClicked(const QModelIndex &index)
case ModList::COL_CONFLICTFLAGS: tab = ModInfoTabIDs::Conflicts; break;
}
- displayModInformation(modIndex, tab);
+ ui->modList->actions().displayModInformation(modIndex, tab);
// workaround to cancel the editor that might have opened because of
// selection-click
ui->modList->closePersistentEditor(index);
@@ -3424,7 +3343,7 @@ void MainWindow::openOriginInformation_clicked()
std::vector<ModInfo::EFlag> flags = modInfo->getFlags();
if (modInfo->isRegular() || (std::find(flags.begin(), flags.end(), ModInfo::FLAG_OVERWRITE) != flags.end())) {
- displayModInformation(ModInfo::getIndex(m_OrganizerCore.pluginList()->origin(fileName)));
+ ui->modList->actions().displayModInformation(ModInfo::getIndex(m_OrganizerCore.pluginList()->origin(fileName)));
}
}
catch (const std::exception &e) {
@@ -3473,7 +3392,7 @@ void MainWindow::on_espList_doubleClicked(const QModelIndex &index)
}
else {
- displayModInformation(ModInfo::getIndex(m_OrganizerCore.pluginList()->origin(fileName)));
+ ui->modList->actions().displayModInformation(ModInfo::getIndex(m_OrganizerCore.pluginList()->origin(fileName)));
// workaround to cancel the editor that might have opened because of
// selection-click
ui->espList->closePersistentEditor(index);
@@ -3950,27 +3869,16 @@ void MainWindow::on_modList_customContextMenuRequested(const QPoint &pos)
QTreeView *modList = findChild<QTreeView*>("modList");
QModelIndex contextIdx = mapToModel(m_OrganizerCore.modList(), ui->modList->indexAt(pos));
- int modIndex = ui->modList->indexAt(pos).data(ModList::IndexRole).toInt();
-
- int contextColumn = contextIdx.column();
- if (modIndex == -1) {
+ if (!contextIdx.isValid()) {
// no selection
ModListGlobalContextMenu(m_OrganizerCore, ui->modList).exec(modList->viewport()->mapToGlobal(pos));
}
else {
- QMenu menu(this);
-
- QMenu *allMods = new ModListGlobalContextMenu(m_OrganizerCore, ui->modList, this);
- allMods->setTitle(tr("All Mods"));
- menu.addMenu(allMods);
-
- if (ui->modList->hasCollapsibleSeparators()) {
- menu.addAction(tr("Collapse all"), ui->modList, &QTreeView::collapseAll);
- menu.addAction(tr("Expand all"), ui->modList, &QTreeView::expandAll);
- }
+ int modIndex = ui->modList->indexAt(pos).data(ModList::IndexRole).toInt();
+ int contextColumn = contextIdx.column();
- menu.addSeparator();
+ ModListContextMenu menu(m_OrganizerCore, contextIdx, ui->modList);
ModInfo::Ptr info = ModInfo::getByIndex(modIndex);
std::vector<ModInfo::EFlag> flags = info->getFlags();
diff --git a/src/mainwindow.h b/src/mainwindow.h
index a49c12fe..57f26220 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -154,11 +154,6 @@ public slots:
signals:
/**
- * @brief emitted after the information dialog has been closed
- */
- void modInfoDisplayed();
-
- /**
* @brief emitted when the selected style changes
*/
void styleChanged(const QString &styleFile);
@@ -209,7 +204,6 @@ private:
void refreshExecutablesList();
bool modifyExecutablesDialog(int selection);
- void displayModInformation(int row, ModInfoTabIDs tab=ModInfoTabIDs::None);
/**
* Sets category selections from menu; for multiple mods, this will only apply
@@ -455,7 +449,6 @@ private slots:
void onFiltersOptions(
ModListSortProxy::FilterMode mode, ModListSortProxy::SeparatorsMode sep);
- void displayModInformation(const QString &modName, ModInfoTabIDs tabID);
void visitNexusOrWebPage(const QModelIndex& idx);
void modRenamed(const QString &oldName, const QString &newName);
diff --git a/src/modlistcontextmenu.cpp b/src/modlistcontextmenu.cpp
index 5b45a217..41031eaa 100644
--- a/src/modlistcontextmenu.cpp
+++ b/src/modlistcontextmenu.cpp
@@ -41,233 +41,77 @@ ModListGlobalContextMenu::ModListGlobalContextMenu(OrganizerCore& core, ModListV
addAction(tr("Export to csv..."), [=]() { view->actions().exportModListCSV(); });
}
-ModListContextMenu::ModListContextMenu(OrganizerCore& core, const QModelIndexList& index, ModListView* modListView) :
- QMenu(modListView)
+ModListContextMenu::ModListContextMenu(OrganizerCore& core, const QModelIndex& index, ModListView* view) :
+ QMenu(view)
, m_core(core)
- , m_index(index)
+ , m_index()
{
- // TODO: Change this.
- QModelIndex contextIdx = index.at(0);
- int contextColumn = contextIdx.column();
- int modIndex = contextIdx.data(ModList::IndexRole).toInt();
-
- try {
- /*
- if (modIndex == -1) {
- // no selection
- QMenu menu(this);
- initModListContextMenu(&menu);
- menu.exec(modList->viewport()->mapToGlobal(pos));
- }
- else {
- QMenu menu(this);
-
- QMenu* allMods = new QMenu(&menu);
- initModListContextMenu(allMods);
- allMods->setTitle(tr("All Mods"));
- menu.addMenu(allMods);
-
- if (ui->modList->hasCollapsibleSeparators()) {
- menu.addAction(tr("Collapse all"), ui->modList, &QTreeView::collapseAll);
- menu.addAction(tr("Expand all"), ui->modList, &QTreeView::expandAll);
- }
-
- menu.addSeparator();
-
- ModInfo::Ptr info = ModInfo::getByIndex(modIndex);
- std::vector<ModInfo::EFlag> flags = info->getFlags();
-
- // context menu for overwrites
- if (std::find(flags.begin(), flags.end(), ModInfo::FLAG_OVERWRITE) != flags.end()) {
- if (QDir(info->absolutePath()).count() > 2) {
- menu.addAction(tr("Sync to Mods..."), [=]() { m_OrganizerCore.syncOverwrite(); });
- menu.addAction(tr("Create Mod..."), [=]() { createModFromOverwrite(); });
- menu.addAction(tr("Move content to Mod..."), [=]() { moveOverwriteContentToExistingMod(); });
- menu.addAction(tr("Clear Overwrite..."), [=]() { clearOverwrite(); });
- }
- menu.addAction(tr("Open in Explorer"), [=]() { openExplorer_clicked(modIndex); });
- }
-
- // context menu for mod backups
- else if (std::find(flags.begin(), flags.end(), ModInfo::FLAG_BACKUP) != flags.end()) {
- menu.addAction(tr("Restore Backup"), [=]() { restoreBackup_clicked(modIndex); });
- menu.addAction(tr("Remove Backup..."), [=]() { removeMod_clicked(modIndex); });
- menu.addSeparator();
- if (std::find(flags.begin(), flags.end(), ModInfo::FLAG_INVALID) != flags.end()) {
- menu.addAction(tr("Ignore missing data"), [=]() { ignoreMissingData_clicked(modIndex); });
- }
- if (std::find(flags.begin(), flags.end(), ModInfo::FLAG_ALTERNATE_GAME) != flags.end()) {
- menu.addAction(tr("Mark as converted/working"), [=]() { markConverted_clicked(modIndex); });
- }
- menu.addSeparator();
- if (info->nexusId() > 0) {
- menu.addAction(tr("Visit on Nexus"), [=]() { visitOnNexus_clicked(modIndex); });
- }
-
- const auto url = info->parseCustomURL();
- if (url.isValid()) {
- menu.addAction(tr("Visit on %1").arg(url.host()), [=]() { visitWebPage_clicked(modIndex); });
- }
-
- menu.addAction(tr("Open in Explorer"), [=]() { openExplorer_clicked(modIndex); });
- }
-
- // separator
- else if (std::find(flags.begin(), flags.end(), ModInfo::FLAG_SEPARATOR) != flags.end()) {
- menu.addSeparator();
- QMenu* addRemoveCategoriesMenu = new QMenu(tr("Change Categories"), &menu);
- populateMenuCategories(modIndex, addRemoveCategoriesMenu, 0);
- connect(addRemoveCategoriesMenu, &QMenu::aboutToHide, [=]() { addRemoveCategories_MenuHandler(addRemoveCategoriesMenu, modIndex, contextIdx); });
- addMenuAsPushButton(&menu, addRemoveCategoriesMenu);
- QMenu* primaryCategoryMenu = new QMenu(tr("Primary Category"), &menu);
- connect(primaryCategoryMenu, &QMenu::aboutToShow, [=]() { setPrimaryCategoryCandidates(primaryCategoryMenu, info); });
- addMenuAsPushButton(&menu, primaryCategoryMenu);
- menu.addSeparator();
- menu.addAction(tr("Rename Separator..."), [=]() { renameMod_clicked(); });
- menu.addAction(tr("Remove Separator..."), [=]() { removeMod_clicked(modIndex); });
- menu.addSeparator();
- addModSendToContextMenu(&menu);
- menu.addAction(tr("Select Color..."), [=]() { setColor_clicked(modIndex); });
-
- if (info->color().isValid()) {
- menu.addAction(tr("Reset Color"), [=]() { resetColor_clicked(modIndex); });
- }
-
- menu.addSeparator();
- }
-
- // foregin
- else if (std::find(flags.begin(), flags.end(), ModInfo::FLAG_FOREIGN) != flags.end()) {
- addModSendToContextMenu(&menu);
- }
-
- // regular
- else {
- QMenu* addRemoveCategoriesMenu = new QMenu(tr("Change Categories"), &menu);
- populateMenuCategories(modIndex, addRemoveCategoriesMenu, 0);
- connect(addRemoveCategoriesMenu, &QMenu::aboutToHide, [=]() { addRemoveCategories_MenuHandler(addRemoveCategoriesMenu, modIndex, contextIdx); });
- addMenuAsPushButton(&menu, addRemoveCategoriesMenu);
-
- QMenu* primaryCategoryMenu = new QMenu(tr("Primary Category"), &menu);
- connect(primaryCategoryMenu, &QMenu::aboutToShow, [=]() { setPrimaryCategoryCandidates(primaryCategoryMenu, info); });
- addMenuAsPushButton(&menu, primaryCategoryMenu);
-
- menu.addSeparator();
-
- if (info->downgradeAvailable()) {
- menu.addAction(tr("Change versioning scheme"), [=]() { changeVersioningScheme(modIndex); });
- }
-
- if (info->nexusId() > 0)
- menu.addAction(tr("Force-check updates"), [=]() { checkModUpdates_clicked(modIndex); });
- if (info->updateIgnored()) {
- menu.addAction(tr("Un-ignore update"), [=]() { unignoreUpdate(modIndex); });
- }
- else {
- if (info->updateAvailable() || info->downgradeAvailable()) {
- menu.addAction(tr("Ignore update"), [=]() { ignoreUpdate(modIndex); });
- }
- }
- menu.addSeparator();
+ if (view->selectionModel()->hasSelection()) {
+ m_index = view->indexViewToModel(view->selectionModel()->selectedRows());
+ }
+ else {
+ m_index = { index };
+ }
- menu.addAction(tr("Enable selected"), [=]() { enableSelectedMods_clicked(); });
- menu.addAction(tr("Disable selected"), [=]() { disableSelectedMods_clicked(); });
- menu.addSeparator();
+ QMenu* allMods = new ModListGlobalContextMenu(core, view, view);
+ allMods->setTitle(tr("All Mods"));
+ addMenu(allMods);
- addModSendToContextMenu(&menu);
+ if (view->hasCollapsibleSeparators()) {
+ addAction(tr("Collapse all"), view, &QTreeView::collapseAll);
+ addAction(tr("Expand all"), view, &QTreeView::expandAll);
+ }
- menu.addAction(tr("Rename Mod..."), [=]() { renameMod_clicked(); });
- menu.addAction(tr("Reinstall Mod"), [=]() { reinstallMod_clicked(modIndex); });
- menu.addAction(tr("Remove Mod..."), [=]() { removeMod_clicked(modIndex); });
- menu.addAction(tr("Create Backup"), [=]() { backupMod_clicked(modIndex); });
+ addSeparator();
- if (std::find(flags.begin(), flags.end(), ModInfo::FLAG_HIDDEN_FILES) != flags.end()) {
- menu.addAction(tr("Restore hidden files"), [=]() { restoreHiddenFiles_clicked(modIndex); });
- }
+ // Add type-specific items
+ ModInfo::Ptr info = ModInfo::getByIndex(index.data(ModList::IndexRole).toInt());
- menu.addSeparator();
+ if (info->isOverwrite()) {
+ addOverwriteActions(core, view);
+ }
+ else if (info->isBackup()) {
+ addBackupActions(core, view);
+ }
+ else if (info->isSeparator()) {
+ addSeparatorActions(core, view);
+ }
+ else if (info->isForeign()) {
+ addForeignActions(core, view);
+ }
+ else {
+ addRegularActions(core, view);
+ }
- if (contextColumn == ModList::COL_NOTES) {
- menu.addAction(tr("Select Color..."), [=]() { setColor_clicked(modIndex); });
- if (info->color().isValid()) {
- menu.addAction(tr("Reset Color"), [=]() { resetColor_clicked(modIndex); });
- }
- menu.addSeparator();
- }
+ // add information for all except foreign
+ if (!info->isForeign()) {
+ QAction* infoAction = addAction(tr("Information..."), [=]() { view->actions().displayModInformation(m_index[0].row()); });
+ setDefaultAction(infoAction);
+ }
+}
- if (info->nexusId() > 0 && Settings::instance().nexus().endorsementIntegration()) {
- switch (info->endorsedState()) {
- case EndorsedState::ENDORSED_TRUE: {
- menu.addAction(tr("Un-Endorse"), [=]() { unendorse_clicked(); });
- } break;
- case EndorsedState::ENDORSED_FALSE: {
- menu.addAction(tr("Endorse"), [=]() { endorse_clicked(); });
- menu.addAction(tr("Won't endorse"), [=]() { dontendorse_clicked(modIndex); });
- } break;
- case EndorsedState::ENDORSED_NEVER: {
- menu.addAction(tr("Endorse"), [=]() { endorse_clicked(); });
- } break;
- default: {
- QAction* action = new QAction(tr("Endorsement state unknown"), &menu);
- action->setEnabled(false);
- menu.addAction(action);
- } break;
- }
- }
+void ModListContextMenu::addOverwriteActions(OrganizerCore& core, ModListView* modListView)
+{
- if (info->nexusId() > 0 && Settings::instance().nexus().trackedIntegration()) {
- switch (info->trackedState()) {
- case TrackedState::TRACKED_FALSE: {
- menu.addAction(tr("Start tracking"), [=]() { track_clicked(); });
- } break;
- case TrackedState::TRACKED_TRUE: {
- menu.addAction(tr("Stop tracking"), [=]() { untrack_clicked(); });
- } break;
- default: {
- QAction* action = new QAction(tr("Tracked state unknown"), &menu);
- action->setEnabled(false);
- menu.addAction(action);
- } break;
- }
- }
+}
- menu.addSeparator();
+void ModListContextMenu::addSeparatorActions(OrganizerCore& core, ModListView* modListView)
+{
- std::vector<ModInfo::EFlag> flags = info->getFlags();
- if (std::find(flags.begin(), flags.end(), ModInfo::FLAG_INVALID) != flags.end()) {
- menu.addAction(tr("Ignore missing data"), [=]() { ignoreMissingData_clicked(modIndex); });
- }
+}
- if (std::find(flags.begin(), flags.end(), ModInfo::FLAG_ALTERNATE_GAME) != flags.end()) {
- menu.addAction(tr("Mark as converted/working"), [=]() { markConverted_clicked(modIndex); });
- }
+void ModListContextMenu::addForeignActions(OrganizerCore& core, ModListView* modListView)
+{
- menu.addSeparator();
+}
- if (info->nexusId() > 0) {
- menu.addAction(tr("Visit on Nexus"), [=]() { visitOnNexus_clicked(modIndex); });
- }
+void ModListContextMenu::addBackupActions(OrganizerCore& core, ModListView* modListView)
+{
- const auto url = info->parseCustomURL();
- if (url.isValid()) {
- menu.addAction(tr("Visit on %1").arg(url.host()), [=]() { visitWebPage_clicked(modIndex); });
- }
+}
- menu.addAction(tr("Open in Explorer"), [&, modIndex]() { openExplorer_clicked(modIndex); });
- }
+void ModListContextMenu::addRegularActions(OrganizerCore& core, ModListView* modListView)
+{
- if (std::find(flags.begin(), flags.end(), ModInfo::FLAG_FOREIGN) == flags.end()) {
- QAction* infoAction = menu.addAction(tr("Information..."), [=]() { information_clicked(modIndex); });
- menu.setDefaultAction(infoAction);
- }
- }
- */
- }
- catch (const std::exception& e) {
- reportError(tr("Exception: ").arg(e.what()));
- }
- catch (...) {
- reportError(tr("Unknown exception"));
- }
}
diff --git a/src/modlistcontextmenu.h b/src/modlistcontextmenu.h
index bc72fbdf..9d015afc 100644
--- a/src/modlistcontextmenu.h
+++ b/src/modlistcontextmenu.h
@@ -23,13 +23,21 @@ class ModListContextMenu : public QMenu
{
Q_OBJECT
-private:
+public:
- friend class ModListView;
+ // creates a new context menu, the given index is the one for the click and should be valid
+ //
+ ModListContextMenu(OrganizerCore& core, const QModelIndex& index, ModListView* modListView);
+
+private:
- // creates a new context menu that will act on the given mod list
- // index (those should be index from the modlist)
- ModListContextMenu(OrganizerCore& core, const QModelIndexList& index, ModListView* modListView);
+ // add actions/menus to this menu for each type of mod
+ //
+ void addOverwriteActions(OrganizerCore& core, ModListView* modListView);
+ void addSeparatorActions(OrganizerCore& core, ModListView* modListView);
+ void addForeignActions(OrganizerCore& core, ModListView* modListView);
+ void addBackupActions(OrganizerCore& core, ModListView* modListView);
+ void addRegularActions(OrganizerCore& core, ModListView* modListView);
OrganizerCore& m_core;
QModelIndexList m_index;
diff --git a/src/modlistview.h b/src/modlistview.h
index d5eea54f..0f131631 100644
--- a/src/modlistview.h
+++ b/src/modlistview.h
@@ -105,8 +105,6 @@ public slots:
//
void updateModCount();
-protected:
-
// map from/to the view indexes to the model
//
QModelIndex indexModelToView(const QModelIndex& index) const;
@@ -114,6 +112,8 @@ protected:
QModelIndex indexViewToModel(const QModelIndex& index) const;
QModelIndexList indexViewToModel(const QModelIndexList& index) const;
+protected:
+
// returns the next/previous index of the given index
//
QModelIndex nextIndex(const QModelIndex& index) const;
diff --git a/src/modlistviewactions.cpp b/src/modlistviewactions.cpp
index 8b234b81..6faebc15 100644
--- a/src/modlistviewactions.cpp
+++ b/src/modlistviewactions.cpp
@@ -5,28 +5,37 @@
#include <QInputDialog>
#include <QLabel>
+#include <log.h>
#include <report.h>
#include "categories.h"
#include "filedialogmemory.h"
#include "filterlist.h"
+#include "modinfodialog.h"
#include "modlist.h"
#include "modlistview.h"
+#include "mainwindow.h"
#include "nexusinterface.h"
#include "nxmaccessmanager.h"
#include "savetextasdialog.h"
#include "organizercore.h"
+#include "overwriteinfodialog.h"
#include "csvbuilder.h"
+#include "shared/filesorigin.h"
+#include "shared/directoryentry.h"
+#include "shared/fileregister.h"
+#include "directoryrefresher.h"
using namespace MOBase;
+using namespace MOShared;
ModListViewActions::ModListViewActions(
- OrganizerCore& core, FilterList& filters, CategoryFactory& categoryFactory, QObject* nxmReceiver, ModListView* view) :
+ OrganizerCore& core, FilterList& filters, CategoryFactory& categoryFactory, MainWindow* mainWindow, ModListView* view) :
QObject(view)
, m_core(core)
, m_filters(filters)
, m_categories(categoryFactory)
- , m_receiver(nxmReceiver)
+ , m_main(mainWindow)
, m_view(view)
{
@@ -143,9 +152,9 @@ void ModListViewActions::checkModsForUpdates() const
{
bool checkingModsForUpdate = false;
if (NexusInterface::instance().getAccessManager()->validated()) {
- checkingModsForUpdate = ModInfo::checkAllForUpdate(&m_core.pluginContainer(), m_receiver);
- NexusInterface::instance().requestEndorsementInfo(m_receiver, QVariant(), QString());
- NexusInterface::instance().requestTrackingInfo(m_receiver, QVariant(), QString());
+ checkingModsForUpdate = ModInfo::checkAllForUpdate(&m_core.pluginContainer(), m_main);
+ NexusInterface::instance().requestEndorsementInfo(m_main, QVariant(), QString());
+ NexusInterface::instance().requestTrackingInfo(m_main, QVariant(), QString());
} else {
QString apiKey;
if (GlobalSettings::nexusApiKey(apiKey)) {
@@ -337,3 +346,87 @@ void ModListViewActions::exportModListCSV() const
}
}
}
+
+void ModListViewActions::displayModInformation(const QString& modName, ModInfoTabIDs tab) const
+{
+ unsigned int index = ModInfo::getIndex(modName);
+ if (index == UINT_MAX) {
+ log::error("failed to resolve mod name {}", modName);
+ return;
+ }
+
+ ModInfo::Ptr modInfo = ModInfo::getByIndex(index);
+ displayModInformation(modInfo, index, tab);
+}
+
+void ModListViewActions::displayModInformation(unsigned int index, ModInfoTabIDs tab) const
+{
+ ModInfo::Ptr modInfo = ModInfo::getByIndex(index);
+ displayModInformation(modInfo, index, tab);
+}
+
+void ModListViewActions::displayModInformation(ModInfo::Ptr modInfo, unsigned int modIndex, ModInfoTabIDs tab) const
+{
+ if (!m_core.modList()->modInfoAboutToChange(modInfo)) {
+ log::debug("a different mod information dialog is open. If this is incorrect, please restart MO");
+ return;
+ }
+ std::vector<ModInfo::EFlag> flags = modInfo->getFlags();
+ if (std::find(flags.begin(), flags.end(), ModInfo::FLAG_OVERWRITE) != flags.end()) {
+ QDialog* dialog = m_main->findChild<QDialog*>("__overwriteDialog");
+ try {
+ if (dialog == nullptr) {
+ dialog = new OverwriteInfoDialog(modInfo, m_main);
+ dialog->setObjectName("__overwriteDialog");
+ }
+ else {
+ qobject_cast<OverwriteInfoDialog*>(dialog)->setModInfo(modInfo);
+ }
+
+ dialog->show();
+ dialog->raise();
+ dialog->activateWindow();
+ connect(dialog, SIGNAL(finished(int)), this, SLOT(overwriteClosed(int)));
+ }
+ catch (const std::exception& e) {
+ reportError(tr("Failed to display overwrite dialog: %1").arg(e.what()));
+ }
+ }
+ else {
+ modInfo->saveMeta();
+
+ ModInfoDialog dialog(m_main, &m_core, &m_core.pluginContainer(), modInfo);
+ connect(&dialog, SIGNAL(originModified(int)), this, SLOT(originModified(int)));
+
+ //Open the tab first if we want to use the standard indexes of the tabs.
+ if (tab != ModInfoTabIDs::None) {
+ dialog.selectTab(tab);
+ }
+
+ dialog.exec();
+
+ modInfo->saveMeta();
+ m_core.modList()->modInfoChanged(modInfo);
+ }
+
+ if (m_core.currentProfile()->modEnabled(modIndex)
+ && !modInfo->hasFlag(ModInfo::FLAG_FOREIGN)) {
+ FilesOrigin& origin = m_core.directoryStructure()->getOriginByName(ToWString(modInfo->name()));
+ origin.enable(false);
+
+ if (m_core.directoryStructure()->originExists(ToWString(modInfo->name()))) {
+ FilesOrigin& origin = m_core.directoryStructure()->getOriginByName(ToWString(modInfo->name()));
+ origin.enable(false);
+
+ m_core.directoryRefresher()->addModToStructure(m_core.directoryStructure()
+ , modInfo->name()
+ , m_core.currentProfile()->getModPriority(modIndex)
+ , modInfo->absolutePath()
+ , modInfo->stealFiles()
+ , modInfo->archives());
+ DirectoryRefresher::cleanStructure(m_core.directoryStructure());
+ m_core.directoryStructure()->getFileRegister()->sortOrigins();
+ m_core.refreshLists();
+ }
+ }
+}
diff --git a/src/modlistviewactions.h b/src/modlistviewactions.h
index 49cffaef..b01b8e79 100644
--- a/src/modlistviewactions.h
+++ b/src/modlistviewactions.h
@@ -4,8 +4,12 @@
#include <QObject>
#include <QString>
+#include "modinfo.h"
+#include "modinfodialogfwd.h"
+
class CategoryFactory;
class FilterList;
+class MainWindow;
class ModListView;
class OrganizerCore;
@@ -15,14 +19,14 @@ class ModListViewActions : public QObject
public:
- // the nxmReceiver is a (hopefully temporary) "hack" because it would require a lots of change
- // to do otherwise since NXM is mostly based on the old Qt signal-slot system
+ // currently passing the main window itself because a lots of stuff needs it but
+ // it would be nice to avoid passing it at some point
//
ModListViewActions(
OrganizerCore& core,
FilterList& filters,
CategoryFactory& categoryFactory,
- QObject* nxmReceiver,
+ MainWindow* mainWindow,
ModListView* view);
// install the mod from the given archive
@@ -43,12 +47,19 @@ public:
//
void exportModListCSV() const;
+ // display mod information
+ //
+ void displayModInformation(const QString& modName, ModInfoTabIDs tabID = ModInfoTabIDs::None) const;
+ void displayModInformation(unsigned int index, ModInfoTabIDs tab = ModInfoTabIDs::None) const;
+ void displayModInformation(ModInfo::Ptr modInfo, unsigned int modIndex, ModInfoTabIDs tabID = ModInfoTabIDs::None) const;
+
+
private:
OrganizerCore& m_core;
FilterList& m_filters;
CategoryFactory& m_categories;
- QObject* m_receiver; // receiver for NXM signals (temporary)
+ MainWindow* m_main;
ModListView* m_view;
};