From d66fdcd4cc6913508d2987c14cd9fc4d6760b8a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Mon, 3 Oct 2016 00:55:54 +0200 Subject: NOISSUE Granular instance reload --- api/logic/InstanceList.h | 111 +++++++---------------------------------------- 1 file changed, 16 insertions(+), 95 deletions(-) (limited to 'api/logic/InstanceList.h') diff --git a/api/logic/InstanceList.h b/api/logic/InstanceList.h index 074cca7c..b643de85 100644 --- a/api/logic/InstanceList.h +++ b/api/logic/InstanceList.h @@ -18,24 +18,22 @@ #include #include #include +#include #include "BaseInstance.h" +#include "BaseInstanceProvider.h" #include "multimc_logic_export.h" +#include "QObjectPtr.h" + +class QFileSystemWatcher; class BaseInstance; class QDir; class MULTIMC_LOGIC_EXPORT InstanceList : public QAbstractListModel { Q_OBJECT -private: - void loadGroupList(QMap &groupList); - void suspendGroupSaving(); - void resumeGroupSaving(); - -public slots: - void saveGroupList(); public: explicit InstanceList(SettingsObjectPtr globalSettings, const QString &instDir, QObject *parent = 0); @@ -64,124 +62,47 @@ public: UnknownError }; - enum InstLoadError - { - NoLoadError = 0, - UnknownLoadError, - NotAnInstance - }; - - enum InstCreateError - { - NoCreateError = 0, - NoSuchVersion, - UnknownCreateError, - InstExists, - CantCreateDir - }; - - QString instDir() const - { - return m_instDir; - } - - /*! - * \brief Get the instance at index - */ InstancePtr at(int i) const { return m_instances.at(i); } - ; - /*! - * \brief Get the count of loaded instances - */ int count() const { return m_instances.count(); } - ; - /// Clear all instances. Triggers notifications. - void clear(); + InstListError loadList(bool complete = false); - /// Add an instance. Triggers notifications, returns the new index - int add(InstancePtr t); + /// Add an instance provider. Takes ownership of it. Should only be done before the first load. + void addInstanceProvider(BaseInstanceProvider * provider); - /// Get an instance by ID InstancePtr getInstanceById(QString id) const; - QModelIndex getInstanceIndexById(const QString &id) const; - - // FIXME: instead of iterating through all instances and forming a set, keep the set around QStringList getGroups(); void deleteGroup(const QString & name); - /*! - * \brief Creates a stub instance - * - * \param inst Pointer to store the created instance in. - * \param version Game version to use for the instance - * \param instDir The new instance's directory. - * \return An InstCreateError error code. - * - InstExists if the given instance directory is already an instance. - * - CantCreateDir if the given instance directory cannot be created. - */ - InstCreateError createInstance(InstancePtr &inst, BaseVersionPtr version, - const QString &instDir); - - /*! - * \brief Creates a copy of an existing instance with a new name - * - * \param newInstance Pointer to store the created instance in. - * \param oldInstance The instance to copy - * \param instDir The new instance's directory. - * \return An InstCreateError error code. - * - InstExists if the given instance directory is already an instance. - * - CantCreateDir if the given instance directory cannot be created. - */ - InstCreateError copyInstance(InstancePtr &newInstance, InstancePtr &oldInstance, - const QString &instDir, bool copySaves); - - /*! - * \brief Loads an instance from the given directory. - * Checks the instance's INI file to figure out what the instance's type is first. - * \param inst Pointer to store the loaded instance in. - * \param instDir The instance's directory. - * \return An InstLoadError error code. - * - NotAnInstance if the given instance directory isn't a valid instance. - */ - InstLoadError loadInstance(InstancePtr &inst, const QString &instDir); - signals: void dataIsInvalid(); -public slots: - void on_InstFolderChanged(const Setting &setting, QVariant value); - - /*! - * \brief Loads the instance list. Triggers notifications. - */ - InstListError loadList(); - private slots: void propertiesChanged(BaseInstance *inst); - void instanceNuked(BaseInstance *inst); - void groupChanged(); + void groupsPublished(QSet); + void providerUpdated(); private: int getInstIndex(BaseInstance *inst) const; - -public: - static bool continueProcessInstance(InstancePtr instPtr, const int error, const QDir &dir, QMap &groupMap); + void suspendWatch(); + void resumeWatch(); + void add(const QList &list); protected: + int m_watchLevel = 0; + QSet m_updatedProviders; QString m_instDir; QList m_instances; QSet m_groups; SettingsObjectPtr m_globalSettings; - bool suspendedGroupSave = false; - bool queuedGroupSave = false; + QVector> m_providers; }; -- cgit v1.2.3