From 154d19bb74f4c5fc1519aa40cd9dfd20244273a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 1 Feb 2015 03:08:25 +0100 Subject: SCRATCH eliminate InstanceFactory --- logic/InstanceList.h | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 2 deletions(-) (limited to 'logic/InstanceList.h') diff --git a/logic/InstanceList.h b/logic/InstanceList.h index b7f2b997..1d52663e 100644 --- a/logic/InstanceList.h +++ b/logic/InstanceList.h @@ -23,7 +23,6 @@ #include "logic/BaseInstance.h" class BaseInstance; - class QDir; class InstanceList : public QAbstractListModel @@ -37,7 +36,7 @@ slots: void saveGroupList(); public: - explicit InstanceList(const QString &instDir, QObject *parent = 0); + explicit InstanceList(SettingsObjectPtr globalSettings, const QString &instDir, QObject *parent = 0); virtual ~InstanceList(); public: @@ -62,6 +61,22 @@ public: UnknownError }; + enum InstLoadError + { + NoLoadError = 0, + UnknownLoadError, + NotAnInstance + }; + + enum InstCreateError + { + NoCreateError = 0, + NoSuchVersion, + UnknownCreateError, + InstExists, + CantCreateDir + }; + QString instDir() const { return m_instDir; @@ -98,6 +113,43 @@ public: // FIXME: instead of iterating through all instances and forming a set, keep the set around QStringList getGroups(); + + /*! + * \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); + + /*! + * \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(); @@ -127,6 +179,7 @@ protected: QString m_instDir; QList m_instances; QSet m_groups; + SettingsObjectPtr m_globalSettings; }; class InstanceProxyModel : public GroupedProxyModel -- cgit v1.2.3