diff options
Diffstat (limited to 'api/logic/minecraft/ModList.cpp')
-rw-r--r-- | api/logic/minecraft/ModList.cpp | 32 |
1 files changed, 8 insertions, 24 deletions
diff --git a/api/logic/minecraft/ModList.cpp b/api/logic/minecraft/ModList.cpp index d1ad75ab..20963729 100644 --- a/api/logic/minecraft/ModList.cpp +++ b/api/logic/minecraft/ModList.cpp @@ -29,14 +29,16 @@ ModList::ModList(const QString &dir) : QAbstractListModel(), m_dir(dir) QDir::NoSymLinks); m_dir.setSorting(QDir::Name | QDir::IgnoreCase | QDir::LocaleAware); m_watcher = new QFileSystemWatcher(this); - is_watching = false; - connect(m_watcher, SIGNAL(directoryChanged(QString)), this, - SLOT(directoryChanged(QString))); + connect(m_watcher, SIGNAL(directoryChanged(QString)), this, SLOT(directoryChanged(QString))); } void ModList::startWatching() { + if(is_watching) + return; + update(); + is_watching = m_watcher->addPath(m_dir.absolutePath()); if (is_watching) { @@ -50,6 +52,9 @@ void ModList::startWatching() void ModList::stopWatching() { + if(!is_watching) + return; + is_watching = !m_watcher->removePath(m_dir.absolutePath()); if (!is_watching) { @@ -61,19 +66,6 @@ void ModList::stopWatching() } } -void ModList::internalSort(QList<Mod> &what) -{ - auto predicate = [](const Mod &left, const Mod &right) - { - if (left.name() == right.name()) - { - return left.mmc_id().localeAwareCompare(right.mmc_id()) < 0; - } - return left.name().localeAwareCompare(right.name()) < 0; - }; - std::sort(what.begin(), what.end(), predicate); -} - bool ModList::update() { if (!isValid()) @@ -93,7 +85,6 @@ bool ModList::update() { newMods.append(Mod(entry)); } - internalSort(newMods); orderedMods.append(newMods); orderOrStateChanged = true; } @@ -363,13 +354,6 @@ bool ModList::dropMimeData(const QMimeData* data, Qt::DropAction action, int, in added = true; } } - if(added) - { - // re-sort the list - beginResetModel(); - internalSort(mods); - endResetModel(); - } if (was_watching) { startWatching(); |