diff options
author | Petr Mrázek <peterix@gmail.com> | 2013-03-18 23:00:46 +0100 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2013-03-18 23:00:46 +0100 |
commit | 65faabeed48584c461ca21d784c3f1d46f67f832 (patch) | |
tree | e814006279d0c56246e61e5c8f3bd29bc0e1c541 /libmultimc/src | |
parent | b84dfddd1b24e82dccb5a20d9c30570d26846e76 (diff) | |
download | MultiMC-65faabeed48584c461ca21d784c3f1d46f67f832.tar MultiMC-65faabeed48584c461ca21d784c3f1d46f67f832.tar.gz MultiMC-65faabeed48584c461ca21d784c3f1d46f67f832.tar.lz MultiMC-65faabeed48584c461ca21d784c3f1d46f67f832.tar.xz MultiMC-65faabeed48584c461ca21d784c3f1d46f67f832.zip |
Connect instance list to model.
Diffstat (limited to 'libmultimc/src')
-rw-r--r-- | libmultimc/src/instancelist.cpp | 40 |
1 files changed, 35 insertions, 5 deletions
diff --git a/libmultimc/src/instancelist.cpp b/libmultimc/src/instancelist.cpp index 78650634..83a72afb 100644 --- a/libmultimc/src/instancelist.cpp +++ b/libmultimc/src/instancelist.cpp @@ -15,11 +15,10 @@ #include "include/instancelist.h" -#include "siglist_impl.h" - #include <QDir> #include <QFile> #include <QDirIterator> +#include <QThread> #include "include/instance.h" #include "include/instanceloader.h" @@ -37,7 +36,7 @@ InstanceList::InstListError InstanceList::loadList() { QDir dir(m_instDir); QDirIterator iter(dir); - + m_instances.clear(); while (iter.hasNext()) { QString subDir = iter.next(); @@ -78,10 +77,41 @@ InstanceList::InstListError InstanceList::loadList() qDebug(QString("Loaded instance %1").arg(inst->name()).toUtf8()); inst->setParent(this); - append(QSharedPointer<Instance>(inst)); + m_instances.append(inst); } } } - + emit invalidated(); return NoError; } + +/// Clear all instances. Triggers notifications. +void InstanceList::clear() +{ + m_instances.clear(); + emit invalidated(); +}; + +/// Add an instance. Triggers notifications, returns the new index +int InstanceList::add(InstancePtr t) +{ + m_instances.append(t); + emit instanceAdded(count() - 1); + return count() - 1; +} + +InstancePtr InstanceList::getInstanceById(QString instId) +{ + QListIterator<InstancePtr> iter(m_instances); + InstancePtr inst; + while(iter.hasNext()) + { + inst = iter.next(); + if (inst->id() == instId) + break; + } + if (inst->id() != instId) + return InstancePtr(); + else + return iter.peekPrevious(); +}
\ No newline at end of file |