summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorisanae <14251494+isanae@users.noreply.github.com>2019-05-28 10:14:15 -0400
committerisanae <14251494+isanae@users.noreply.github.com>2019-05-28 10:14:15 -0400
commitadb5ace7997c4cf8ed5e0bee726478c8e1593524 (patch)
tree5201005514cb268f7d66fdecdaf63eff7d849732 /src
parent2d52299743d056ae6da3c98ca9dc34abca3138bf (diff)
added selectedOrigin to previewFileWithAlternatives()
this is so that an origin other than the primary can be shown first and is used from previewDataFile() in ModInfoDialog since showing a preview for a conflicting file could initially show the file from the wrong mod removed unused, uninitialized and dangerous ModInfoDialog::m_OriginID
Diffstat (limited to 'src')
-rw-r--r--src/modinfodialog.cpp4
-rw-r--r--src/modinfodialog.h1
-rw-r--r--src/organizercore.cpp41
-rw-r--r--src/organizercore.h2
4 files changed, 41 insertions, 7 deletions
diff --git a/src/modinfodialog.cpp b/src/modinfodialog.cpp
index 024679f3..fd8093d1 100644
--- a/src/modinfodialog.cpp
+++ b/src/modinfodialog.cpp
@@ -1740,8 +1740,10 @@ void ModInfoDialog::previewDataFile(const QTreeWidgetItem* item)
return;
}
+ const int originId = (m_Origin ? m_Origin->getID() : -1);
+
QString fileName = QDir::fromNativeSeparators(item->data(0, Qt::UserRole).toString());
- m_OrganizerCore->previewFileWithAlternatives(this, fileName);
+ m_OrganizerCore->previewFileWithAlternatives(this, fileName, originId);
}
bool ModInfoDialog::canPreviewFile(bool isArchive, const QString& filename) const
diff --git a/src/modinfodialog.h b/src/modinfodialog.h
index 983da8d4..5f7d831b 100644
--- a/src/modinfodialog.h
+++ b/src/modinfodialog.h
@@ -397,7 +397,6 @@ private:
Ui::ModInfoDialog *ui;
ModInfo::Ptr m_ModInfo;
- int m_OriginID;
QSignalMapper m_ThumbnailMapper;
QString m_RootPath;
diff --git a/src/organizercore.cpp b/src/organizercore.cpp
index 19b53b8d..00292e32 100644
--- a/src/organizercore.cpp
+++ b/src/organizercore.cpp
@@ -1319,7 +1319,7 @@ bool OrganizerCore::executeFileVirtualized(
}
bool OrganizerCore::previewFileWithAlternatives(
- QWidget* parent, QString fileName)
+ QWidget* parent, QString fileName, int selectedOrigin)
{
// what we have is an absolute path to the file in its actual location (for the primary origin)
// what we want is the path relative to the virtual data directory
@@ -1370,9 +1370,42 @@ bool OrganizerCore::previewFileWithAlternatives(
}
};
- addFunc(file->getOrigin());
- for (auto alt : file->getAlternatives()) {
- addFunc(alt.first);
+ if (selectedOrigin == -1) {
+ // don't bother with the vector of origins, just add them as they come
+ addFunc(file->getOrigin());
+ for (auto alt : file->getAlternatives()) {
+ addFunc(alt.first);
+ }
+ } else {
+ std::vector<int> origins;
+
+ // start with the primary origin
+ origins.push_back(file->getOrigin());
+
+ // add other origins, push to front if it's the selected one
+ for (auto alt : file->getAlternatives()) {
+ if (alt.first == selectedOrigin) {
+ origins.insert(origins.begin(), alt.first);
+ } else {
+ origins.push_back(alt.first);
+ }
+ }
+
+ // can't be empty; either the primary origin was the selected one, or it
+ // was one of the alternatives, which got inserted in front
+
+ if (origins[0] != selectedOrigin) {
+ // sanity check, this shouldn't happen unless the caller passed an
+ // incorrect id
+
+ qWarning().nospace()
+ << "selected preview origin " << selectedOrigin << " not found in "
+ << "list of alternatives";
+ }
+
+ for (int id : origins) {
+ addFunc(id);
+ }
}
if (preview.numVariants() > 0) {
diff --git a/src/organizercore.h b/src/organizercore.h
index e24227b7..8ed34e24 100644
--- a/src/organizercore.h
+++ b/src/organizercore.h
@@ -152,7 +152,7 @@ public:
QFileInfo &binaryInfo, QString &arguments, FileExecutionTypes& type);
bool executeFileVirtualized(QWidget* parent, const QFileInfo& targetInfo);
- bool previewFileWithAlternatives(QWidget* parent, QString filename);
+ bool previewFileWithAlternatives(QWidget* parent, QString filename, int selectedOrigin=-1);
bool previewFile(QWidget* parent, const QString& originName, const QString& path);
void spawnBinary(const QFileInfo &binary, const QString &arguments = "",