summaryrefslogtreecommitdiffstats
path: root/api/logic
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2019-07-15 01:07:21 +0200
committerPetr Mrázek <peterix@gmail.com>2019-07-15 01:07:21 +0200
commit80b3efff11a34e2df7d1bc4cc3187e6aaf57e687 (patch)
tree0e09e162ccc24decf6e10397b2fb3963da1d364d /api/logic
parente4273d6a174ffb771728f32b5e2a8a36096c4e21 (diff)
downloadMultiMC-80b3efff11a34e2df7d1bc4cc3187e6aaf57e687.tar
MultiMC-80b3efff11a34e2df7d1bc4cc3187e6aaf57e687.tar.gz
MultiMC-80b3efff11a34e2df7d1bc4cc3187e6aaf57e687.tar.lz
MultiMC-80b3efff11a34e2df7d1bc4cc3187e6aaf57e687.tar.xz
MultiMC-80b3efff11a34e2df7d1bc4cc3187e6aaf57e687.zip
NOISSUE Do not hide mods list pages when the instance is running.
Instead, disable (most of) the controls.
Diffstat (limited to 'api/logic')
-rw-r--r--api/logic/minecraft/MinecraftInstance.cpp12
-rw-r--r--api/logic/minecraft/SimpleModList.cpp39
-rw-r--r--api/logic/minecraft/SimpleModList.h4
3 files changed, 46 insertions, 9 deletions
diff --git a/api/logic/minecraft/MinecraftInstance.cpp b/api/logic/minecraft/MinecraftInstance.cpp
index 35f692c4..617d7431 100644
--- a/api/logic/minecraft/MinecraftInstance.cpp
+++ b/api/logic/minecraft/MinecraftInstance.cpp
@@ -897,8 +897,9 @@ std::shared_ptr<SimpleModList> MinecraftInstance::loaderModList() const
if (!m_loader_mod_list)
{
m_loader_mod_list.reset(new SimpleModList(loaderModsDir()));
+ m_loader_mod_list->disableInteraction(isRunning());
+ connect(this, &BaseInstance::runningStatusChanged, m_loader_mod_list.get(), &SimpleModList::disableInteraction);
}
- m_loader_mod_list->update();
return m_loader_mod_list;
}
@@ -907,8 +908,9 @@ std::shared_ptr<SimpleModList> MinecraftInstance::coreModList() const
if (!m_core_mod_list)
{
m_core_mod_list.reset(new SimpleModList(coreModsDir()));
+ m_core_mod_list->disableInteraction(isRunning());
+ connect(this, &BaseInstance::runningStatusChanged, m_core_mod_list.get(), &SimpleModList::disableInteraction);
}
- m_core_mod_list->update();
return m_core_mod_list;
}
@@ -917,8 +919,9 @@ std::shared_ptr<SimpleModList> MinecraftInstance::resourcePackList() const
if (!m_resource_pack_list)
{
m_resource_pack_list.reset(new SimpleModList(resourcePacksDir()));
+ m_resource_pack_list->disableInteraction(isRunning());
+ connect(this, &BaseInstance::runningStatusChanged, m_resource_pack_list.get(), &SimpleModList::disableInteraction);
}
- m_resource_pack_list->update();
return m_resource_pack_list;
}
@@ -927,8 +930,9 @@ std::shared_ptr<SimpleModList> MinecraftInstance::texturePackList() const
if (!m_texture_pack_list)
{
m_texture_pack_list.reset(new SimpleModList(texturePacksDir()));
+ m_texture_pack_list->disableInteraction(isRunning());
+ connect(this, &BaseInstance::runningStatusChanged, m_texture_pack_list.get(), &SimpleModList::disableInteraction);
}
- m_texture_pack_list->update();
return m_texture_pack_list;
}
diff --git a/api/logic/minecraft/SimpleModList.cpp b/api/logic/minecraft/SimpleModList.cpp
index 6f4011a9..bdcf01b7 100644
--- a/api/logic/minecraft/SimpleModList.cpp
+++ b/api/logic/minecraft/SimpleModList.cpp
@@ -86,6 +86,17 @@ bool SimpleModList::update()
return true;
}
+void SimpleModList::disableInteraction(bool disabled)
+{
+ if (interaction_disabled == disabled) {
+ return;
+ }
+ interaction_disabled = disabled;
+ if(size()) {
+ emit dataChanged(index(0), index(size() - 1));
+ }
+}
+
void SimpleModList::directoryChanged(QString path)
{
update();
@@ -99,6 +110,10 @@ bool SimpleModList::isValid()
// FIXME: this does not take disabled mod (with extra .disable extension) into account...
bool SimpleModList::installMod(const QString &filename)
{
+ if(interaction_disabled) {
+ return false;
+ }
+
// NOTE: fix for GH-1178: remove trailing slash to avoid issues with using the empty result of QFileInfo::fileName
auto originalPath = FS::NormalizePath(filename);
QFileInfo fileinfo(originalPath);
@@ -177,6 +192,10 @@ bool SimpleModList::installMod(const QString &filename)
bool SimpleModList::enableMods(const QModelIndexList& indexes, bool enable)
{
+ if(interaction_disabled) {
+ return false;
+ }
+
if(indexes.isEmpty())
return true;
@@ -192,6 +211,10 @@ bool SimpleModList::enableMods(const QModelIndexList& indexes, bool enable)
bool SimpleModList::deleteMods(const QModelIndexList& indexes)
{
+ if(interaction_disabled) {
+ return false;
+ }
+
if(indexes.isEmpty())
return true;
@@ -313,11 +336,17 @@ QVariant SimpleModList::headerData(int section, Qt::Orientation orientation, int
Qt::ItemFlags SimpleModList::flags(const QModelIndex &index) const
{
Qt::ItemFlags defaultFlags = QAbstractListModel::flags(index);
- if (index.isValid())
- return Qt::ItemIsUserCheckable | Qt::ItemIsDropEnabled |
- defaultFlags;
- else
- return Qt::ItemIsDropEnabled | defaultFlags;
+ auto flags = defaultFlags;
+ if(index.isValid()) {
+ if(interaction_disabled) {
+ flags &= ~Qt::ItemIsDropEnabled;
+ flags &= ~Qt::ItemIsUserCheckable;
+ } else {
+ flags |= Qt::ItemIsUserCheckable;
+ flags |= Qt::ItemIsDropEnabled;
+ }
+ }
+ return flags;
}
Qt::DropActions SimpleModList::supportedDropActions() const
diff --git a/api/logic/minecraft/SimpleModList.h b/api/logic/minecraft/SimpleModList.h
index 3ed2edfe..8cb57727 100644
--- a/api/logic/minecraft/SimpleModList.h
+++ b/api/logic/minecraft/SimpleModList.h
@@ -106,6 +106,9 @@ public:
return mods;
}
+public slots:
+ void disableInteraction(bool disabled);
+
private
slots:
void directoryChanged(QString path);
@@ -116,6 +119,7 @@ signals:
protected:
QFileSystemWatcher *m_watcher;
bool is_watching = false;
+ bool interaction_disabled = false;
QDir m_dir;
QList<Mod> mods;
};