clean up watchers

This commit is contained in:
Ice Yeti 2026-05-27 16:48:14 -04:00
parent 66b20c990f
commit c295055279
2 changed files with 40 additions and 26 deletions

View file

@ -48,7 +48,7 @@
MultiWorldList::MultiWorldList(const QList<QString>& dirs, QList<BaseInstance*> instances) : QAbstractListModel(), m_instances(instances) MultiWorldList::MultiWorldList(const QList<QString>& dirs, QList<BaseInstance*> instances) : QAbstractListModel(), m_instances(instances)
{ {
for (int i = 0; i < dirs.length(); i++) { // better way to do this? iy for (int i = 0; i < dirs.length(); i++) {
m_dirs[i] = dirs[i]; m_dirs[i] = dirs[i];
} }
@ -63,30 +63,40 @@ MultiWorldList::MultiWorldList(const QList<QString>& dirs, QList<BaseInstance*>
connect(m_watcher, &QFileSystemWatcher::directoryChanged, this, &MultiWorldList::directoryChanged); connect(m_watcher, &QFileSystemWatcher::directoryChanged, this, &MultiWorldList::directoryChanged);
} }
void MultiWorldList::startWatching() //figure out what watchers do / if necessary and do all paths iy void MultiWorldList::startWatching()
{ {
if (m_isWatching) { if (m_isWatching) {
return; return;
} }
update(); update();
m_isWatching = m_watcher->addPath(m_dirs[0].absolutePath());
if (m_isWatching) { m_isWatching = true;
qDebug() << "Started watching" << m_dirs[0].absolutePath();
} else { for (QDir dir : m_dirs) {
qDebug() << "Failed to start watching" << m_dirs[0].absolutePath(); if (m_watcher->addPath(dir.absolutePath())) {
qDebug() << "Started watching" << dir.absolutePath();
} else {
m_isWatching = false;
qDebug() << "Failed to start watching" << dir.absolutePath();
}
} }
} }
void MultiWorldList::stopWatching() //same as above function iy void MultiWorldList::stopWatching()
{ {
if (!m_isWatching) { if (!m_isWatching) {
return; return;
} }
m_isWatching = !m_watcher->removePath(m_dirs[0].absolutePath());
if (!m_isWatching) { m_isWatching = false;
qDebug() << "Stopped watching" << m_dirs[0].absolutePath();
} else { for (QDir dir : m_dirs) {
qDebug() << "Failed to stop watching" << m_dirs[0].absolutePath(); if (m_watcher->removePath(dir.absolutePath())) {
qDebug() << "Stopped watching" << dir.absolutePath();
} else {
m_isWatching = true;
qDebug() << "Failed to stop watching" << dir.absolutePath();
}
} }
} }
@ -216,8 +226,10 @@ QVariant MultiWorldList::data(const QModelIndex& index, int role) const
return locale.formattedDataSize(world.bytes()); return locale.formattedDataSize(world.bytes());
case InfoColumn: case InfoColumn:
if (world.isSymLinkUnder(instDirPaths()[0])) { //FIX THIS--NO INDEX 0 iy for (QString path : instDirPaths()) { //use canonical paths instead of for loops? iy
return tr("This world is symbolically linked from elsewhere."); if (world.isSymLinkUnder(path)) {
return tr("This world is symbolically linked from elsewhere.");
}
} }
if (world.isMoreThanOneHardLink()) { if (world.isMoreThanOneHardLink()) {
return tr("\nThis world is hard linked elsewhere."); return tr("\nThis world is hard linked elsewhere.");
@ -234,10 +246,12 @@ QVariant MultiWorldList::data(const QModelIndex& index, int role) const
case Qt::ToolTipRole: { case Qt::ToolTipRole: {
if (column == InfoColumn) { if (column == InfoColumn) {
if (world.isSymLinkUnder(instDirPaths()[0])) { //SAME HERE iy for (QString path : instDirPaths()) { //use canonical paths instead of for loops? iy
return tr("Warning: This world is symbolically linked from elsewhere. Editing it will also change the original." if (world.isSymLinkUnder(path)) {
return tr("Warning: This world is symbolically linked from elsewhere. Editing it will also change the original."
"\nCanonical Path: %1") "\nCanonical Path: %1")
.arg(world.canonicalFilePath()); .arg(world.canonicalFilePath());
}
} }
if (world.isMoreThanOneHardLink()) { if (world.isMoreThanOneHardLink()) {
return tr("Warning: This world is hard linked elsewhere. Editing it will also change the original."); return tr("Warning: This world is hard linked elsewhere. Editing it will also change the original.");
@ -249,7 +263,7 @@ QVariant MultiWorldList::data(const QModelIndex& index, int role) const
return QVariant::fromValue<void*>((void*)&world); return QVariant::fromValue<void*>((void*)&world);
} }
case FolderRole: { case FolderRole: {
return QDir::toNativeSeparators(dirs()[0].absoluteFilePath(world.folderName())); //SAME HERE iy return QDir::toNativeSeparators(QDir(world.canonicalFilePath()).absoluteFilePath(world.folderName())); //test if canonical file path works iy
} }
case SeedRole: { case SeedRole: {
return QVariant::fromValue<qlonglong>(world.seed()); return QVariant::fromValue<qlonglong>(world.seed());
@ -374,7 +388,7 @@ void MultiWorldList::installWorld(QFileInfo filename)
if (!w.isValid()) { if (!w.isValid()) {
return; return;
} }
w.install(m_dirs[0].absolutePath()); //more directory stuff iy w.install(m_dirs[0].absolutePath()); //add option for which instance to install to iy
} }
bool MultiWorldList::dropMimeData(const QMimeData* data, bool MultiWorldList::dropMimeData(const QMimeData* data,
@ -402,7 +416,7 @@ bool MultiWorldList::dropMimeData(const QMimeData* data,
QFileInfo worldInfo(filename); QFileInfo worldInfo(filename);
if (!m_dirs[0].entryInfoList().contains(worldInfo)) { //more stuff to fix iy if (!m_dirs[0].entryInfoList().contains(worldInfo)) { //same as above, add option for which instance to install to iy
installWorld(worldInfo); installWorld(worldInfo);
} }
} }

View file

@ -38,7 +38,7 @@
#include "MultiWorldListPage.h" #include "MultiWorldListPage.h"
#include "minecraft/MultiWorldList.h" #include "minecraft/MultiWorldList.h"
#include "ui/dialogs/CustomMessageBox.h" #include "ui/dialogs/CustomMessageBox.h"
#include "ui_MultiWorldListPage.h" //fix this iy #include "ui_MultiWorldListPage.h"
#include <ui/widgets/PageContainer.h> #include <ui/widgets/PageContainer.h>
#include <QClipboard> #include <QClipboard>
@ -87,7 +87,7 @@ class MultiWorldListProxyModel : public QSortFilterProxyModel {
}; };
MultiWorldListPage::MultiWorldListPage(MinecraftInstance* inst, MultiWorldList* worlds, QWidget* parent) MultiWorldListPage::MultiWorldListPage(MinecraftInstance* inst, MultiWorldList* worlds, QWidget* parent)
: QMainWindow(parent), m_inst(inst), ui(new Ui::MultiWorldListPage), m_worlds(worlds) //use MultiWorldListPage.ui to have separate ui from normal world list page iy : QMainWindow(parent), m_inst(inst), ui(new Ui::MultiWorldListPage), m_worlds(worlds)
{ {
ui->setupUi(this); ui->setupUi(this);
@ -209,7 +209,7 @@ void MultiWorldListPage::on_actionRemove_triggered()
void MultiWorldListPage::on_actionView_Folder_triggered() void MultiWorldListPage::on_actionView_Folder_triggered()
{ {
DesktopServices::openPath(m_worlds->dirs()[0].absolutePath(), true); //change this iy DesktopServices::openPath(m_worlds->dirs()[0].absolutePath(), true); //remove view folder option for all worlds (make it world specific) iy
} }
void MultiWorldListPage::on_actionData_Packs_triggered() void MultiWorldListPage::on_actionData_Packs_triggered()
@ -433,7 +433,7 @@ void MultiWorldListPage::on_actionCopy_triggered()
QInputDialog::getText(this, tr("World name"), tr("Enter a new name for the copy."), QLineEdit::Normal, world->name(), &ok); QInputDialog::getText(this, tr("World name"), tr("Enter a new name for the copy."), QLineEdit::Normal, world->name(), &ok);
if (ok && name.length() > 0) { if (ok && name.length() > 0) {
world->install(m_worlds->dirs()[0].absolutePath(), name); //you know what to do iy world->install(m_worlds->dirs()[0].absolutePath(), name); //ask which instance iy
} }
} }
@ -474,4 +474,4 @@ void MultiWorldListPage::on_actionJoin_triggered()
APPLICATION->launch(m_inst, LaunchMode::Normal, std::make_shared<MinecraftTarget>(MinecraftTarget::parse(world->folderName(), true))); APPLICATION->launch(m_inst, LaunchMode::Normal, std::make_shared<MinecraftTarget>(MinecraftTarget::parse(world->folderName(), true)));
} }
#include "MultiWorldListPage.moc" //change this iy #include "MultiWorldListPage.moc"