From 4b1680f2428f33dc8ecbf3f4f4b964b0a02e7e06 Mon Sep 17 00:00:00 2001 From: Andrew Date: Thu, 14 Feb 2013 22:40:00 -0600 Subject: Started reworking the instance system. --- CMakeLists.txt | 20 ++- data/appsettings.h | 7 +- data/inst/instance.cpp | 21 +++ data/inst/instance.h | 320 +++++++++++++++++++++++++++++++++++++++ data/inst/instancelist.cpp | 23 +++ data/inst/instancelist.h | 39 +++++ data/instancebase.cpp | 109 ------------- data/instancebase.h | 58 ------- data/instancemodel.h | 6 +- data/siglist_imp.h | 156 ------------------- data/siglist_impl.h | 156 +++++++++++++++++++ data/stdinstance.cpp | 22 --- data/stdinstance.h | 28 ---- data/version/instversion.cpp | 32 ++++ data/version/instversion.h | 51 +++++++ data/version/instversionlist.cpp | 21 +++ data/version/instversionlist.h | 43 ++++++ 17 files changed, 725 insertions(+), 387 deletions(-) create mode 100644 data/inst/instance.cpp create mode 100644 data/inst/instance.h create mode 100644 data/inst/instancelist.cpp create mode 100644 data/inst/instancelist.h delete mode 100644 data/instancebase.cpp delete mode 100644 data/instancebase.h delete mode 100644 data/siglist_imp.h create mode 100644 data/siglist_impl.h delete mode 100644 data/stdinstance.cpp delete mode 100644 data/stdinstance.h create mode 100644 data/version/instversion.cpp create mode 100644 data/version/instversion.h create mode 100644 data/version/instversionlist.cpp create mode 100644 data/version/instversionlist.h diff --git a/CMakeLists.txt b/CMakeLists.txt index dbe86a83..1fcff14a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -93,13 +93,17 @@ main.cpp data/appsettings.cpp data/inifile.cpp -data/instancebase.cpp -data/instancemodel.cpp -data/stdinstance.cpp +#data/instancemodel.cpp data/version.cpp data/userinfo.cpp data/loginresponse.cpp +data/inst/instance.cpp +data/inst/instancelist.cpp + +data/version/instversion.cpp +data/version/instversionlist.cpp + gui/mainwindow.cpp gui/modeditwindow.cpp gui/settingsdialog.cpp @@ -127,14 +131,18 @@ gui/taskdialog.h data/appsettings.h data/inifile.h -data/instancebase.h data/instancemodel.h -data/stdinstance.h data/version.h data/userinfo.h data/loginresponse.h data/siglist.h -data/siglist_imp.h +data/siglist_impl.h + +data/inst/instance.h +data/inst/instancelist.h + +data/version/instversion.h +data/version/instversionlist.h util/apputils.h util/pathutils.h diff --git a/data/appsettings.h b/data/appsettings.h index a9068bfd..8a786db0 100644 --- a/data/appsettings.h +++ b/data/appsettings.h @@ -39,8 +39,6 @@ #define DEFINE_SETTING(name, valType, defVal) \ DEFINE_SETTING_ADVANCED(name, STR_VAL(name), valType, defVal) -#define DEFINE_OVERRIDE_SETTING(overrideName) \ - class SettingsBase : public QObject { @@ -91,7 +89,6 @@ public: DEFINE_SETTING(PreLaunchCommand, QString, "") DEFINE_SETTING(PostExitCommand, QString, "") -protected: virtual QVariant getValue(const QString& name, QVariant defVal = QVariant()) const = 0; virtual void setValue(const QString& name, QVariant val) = 0; }; @@ -104,10 +101,10 @@ public: QSettings& getConfig() { return config; } -protected: virtual QVariant getValue(const QString &name, QVariant defVal = QVariant()) const; virtual void setValue(const QString& name, QVariant val); - + +protected: QSettings config; }; diff --git a/data/inst/instance.cpp b/data/inst/instance.cpp new file mode 100644 index 00000000..5cde2233 --- /dev/null +++ b/data/inst/instance.cpp @@ -0,0 +1,21 @@ +/* Copyright 2013 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "instance.h" + +Instance::Instance(QObject *parent) : + SettingsBase(parent) +{ +} diff --git a/data/inst/instance.h b/data/inst/instance.h new file mode 100644 index 00000000..6b1991b6 --- /dev/null +++ b/data/inst/instance.h @@ -0,0 +1,320 @@ +/* Copyright 2013 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef INSTANCE_H +#define INSTANCE_H + +#include +#include + +#include "data/appsettings.h" +#include "data/inifile.h" + +#define DEFINE_OVERRIDDEN_SETTING_ADVANCED(funcName, cfgEntryName, typeName) \ + typeName get ## funcName() const { return getField(cfgEntryName, settings->get ## funcName()).value(); } + +#define DEFINE_OVERRIDDEN_SETTING(funcName, typeName) \ + DEFINE_OVERRIDDEN_SETTING_ADVANCED(funcName, STR_VAL(funcName), typeName) + +class InstanceList; + +/*! + * \brief Base class for instances. + * This class implements many functions that are common between instances and + * provides a standard interface for all instances. + * + * To create a new instance type, create a new class inheriting from this class + * and implement the pure virtual functions. + */ +class Instance : public SettingsBase +{ + Q_OBJECT +public: + explicit Instance(QObject *parent = 0); + + // Please, for the sake of my (and everyone else's) sanity, at least keep this shit + // *somewhat* organized. Also, documentation is semi-important here. Please don't + // leave undocumented stuff behind. + + + //////// STUFF //////// + + /*! + * \brief Get the instance's ID. + * This is a unique identifier string that is, by default, set to the + * instance's folder name. It's not always the instance's folder name, + * however, as any class deriving from Instance can override the id() + * method and change how the ID is determined. The instance's ID + * should always remain constant. Undefined behavior results if an + * already loaded instance's ID changes. + * + * \return The instance's ID. + */ + virtual QString id(); + + /*! + * \brief Gets the path to the instance's root directory. + * \return The path to the instance's root directory. + */ + virtual QString rootDir(); + + /*! + * \brief Gets the instance list that this instance is a part of. + * Returns NULL if this instance is not in a list + * (the parent is not an InstanceList). + * \return A pointer to the InstanceList containing this instance. + */ + virtual InstanceList *instList(); + + + /*! + * \brief Gets this instance's group. + * This function is used by the instance grouping system and should + * not be touched by classes deriving from Instance. + * \return The instance's group name. + * \sa setGroup() + */ + QString group() const { return m_group; } + + /*! + * \brief Sets the instance's group. + * \param group The instance's new group name. + * \sa group() + */ + void setGroup(const QString &group) { m_group = group; emit groupChanged(this, group); } + + + //////// FIELDS AND SETTINGS //////// + // Fields are options stored in the instance's config file that are specific + // to instances (not a part of SettingsBase). Settings are things overridden + // from SettingsBase. + + + ////// Fields ////// + + //// General Info //// + + /*! + * \brief Gets this instance's name. + * This is the name that will be displayed to the user. + * \return The instance's name. + * \sa setName + */ + virtual QString name() { return getField("name", "Unnamed Instance").value(); } + + /*! + * \brief Sets the instance's name + * \param val The instance's new name. + */ + virtual void setName(QString val) { setField("name", val); } + + /*! + * \brief Gets the instance's icon key. + * \return The instance's icon key. + * \sa setIconKey() + */ + virtual QString iconKey() const { return getField("iconKey", "default").value(); } + + /*! + * \brief Sets the instance's icon key. + * \param val The new icon key. + */ + virtual void setIconKey(QString val) { setField("iconKey", val); } + + + /*! + * \brief Gets the instance's notes. + * \return The instances notes. + */ + virtual QString notes() const { return getField("notes", "").value(); } + + /*! + * \brief Sets the instance's notes. + * \param val The instance's new notes. + */ + virtual void setNotes(QString val) { setField("notes", val); } + + + /*! + * \brief Checks if the instance's minecraft.jar needs to be rebuilt. + * If this is true, the instance's mods will be reinstalled to its + * minecraft.jar file. This value is automatically set to true when + * the jar mod list changes. + * \return Whether or not the instance's jar file should be rebuilt. + */ + virtual bool shouldRebuild() const { return getField("NeedsRebuild", false).value(); } + + /*! + * \brief Sets whether or not the instance's minecraft.jar needs to be rebuilt. + * \param val Whether the instance's minecraft needs to be rebuilt or not. + */ + virtual void setShouldRebuild(bool val) { setField("NeedsRebuild", val); } + + + //// Version Stuff //// + + /*! + * \brief Sets the instance's current version. + * This value represents the instance's current version. If this value + * is different from intendedVersion(), the instance should be updated. + * This value is updated by the updateCurrentVersion() function. + * \return A string representing the instance's current version. + */ + virtual QString currentVersion() { return getField("JarVersion", "Unknown").value(); } + + /*! + * \brief Sets the instance's current version. + * This is used to keep track of the instance's current version. Don't + * mess with this unless you know what you're doing. + * \param val The new value. + */ + virtual void setCurrentVersion(QString val) { setField("JarVersion", val); } + + + /*! + * \brief Gets the version of LWJGL that this instance should use. + * If no LWJGL version is specified in the instance's config file, + * defaults to "Mojang" + * \return The instance's LWJGL version. + */ + virtual QString lwjglVersion() { return getField("LwjglVersion", "Mojang").value(); } + + /*! + * \brief Sets the version of LWJGL that this instance should use. + * \param val The LWJGL version to use + */ + virtual void setLWJGLVersion(QString val) { setField("LwjglVersion", val); } + + + /*! + * \brief Gets the version that this instance should try to update to. + * If this value differs from currentVersion(), the instance will + * download the intended version when it launches. + * \return The instance's intended version. + */ + virtual QString intendedVersion() { return getField("IntendedJarVersion", currentVersion()).value(); } + + /*! + * \brief Sets the version that this instance should try to update to. + * \param val The instance's new intended version. + */ + virtual void setIntendedVersion(QString val) { setField("IntendedJarVersion", val); } + + + + //// Timestamps //// + + /*! + * \brief Gets the time that the instance was last launched. + * Measured in milliseconds since epoch. QDateTime::currentMSecsSinceEpoch() + * \return The time that the instance was last launched. + */ + virtual qint64 lastLaunch() { return getField("lastLaunchTime", 0).value(); } + + /*! + * \brief Sets the time that the instance was last launched. + * \param val The time to set. Defaults to QDateTime::currentMSecsSinceEpoch() + */ + virtual void setLastLaunch(qint64 val = QDateTime::currentMSecsSinceEpoch()) + { setField("lastLaunchTime", val); } + + + ////// Settings ////// + + //// Java Settings //// + DEFINE_OVERRIDDEN_SETTING_ADVANCED(JavaPath, JPATHKEY, QString) + DEFINE_OVERRIDDEN_SETTING(JvmArgs, QString) + + //// Custom Commands //// + DEFINE_OVERRIDDEN_SETTING(PreLaunchCommand, QString) + DEFINE_OVERRIDDEN_SETTING(PostExitCommand, QString) + + //// Memory //// + DEFINE_OVERRIDDEN_SETTING(MinMemAlloc, int) + DEFINE_OVERRIDDEN_SETTING(MaxMemAlloc, int) + + //// Auto login //// + DEFINE_OVERRIDDEN_SETTING(AutoLogin, bool) + + // This little guy here is to keep Qt Creator from being a dumbass and + // auto-indenting the lines below the macros. Seriously, it's really annoying. + ; + + + //////// OTHER FUNCTIONS //////// + + //// Version System //// + + /*! + * \brief Checks whether or not the currentVersion of the instance needs to be updated. + * If this returns true, updateCurrentVersion is called. In the + * standard instance, this is determined by checking a timestamp + * stored in the instance config file against the last modified time of Minecraft.jar. + * \return True if updateCurrentVersion() should be called. + */ + virtual bool shouldUpdateCurrentVersion() = 0; + + /*! + * \brief Updates the current version. + * This function should first set the current version timestamp + * (setCurrentVersionTimestamp()) to the current time. Next, if + * keepCurrent is false, this function should check what the + * instance's current version is and call setCurrentVersion() to + * update it. This function will automatically be called when the + * instance is loaded if shouldUpdateCurrentVersion returns true. + * \param keepCurrent If true, only the version timestamp will be updated. + */ + virtual void updateCurrentVersion(bool keepCurrent = false) = 0; + +signals: + /*! + * \brief Signal emitted when the instance's group changes. + * \param inst Pointer to the instance whose group changed. + * \param newGroup The instance's new group. + */ + void groupChanged(Instance *inst, QString newGroup); + +protected: + /*! + * \brief Gets the value of the given field in the instance's config file. + * If the value isn't in the config file, defVal is returned instead. + * \param name The name of the field in the config file. + * \param defVal The default value. + * \return The value of the given field or defVal if the field doesn't exist. + * \sa setField() + */ + virtual QVariant getField(const QString &name, QVariant defVal = QVariant()) const; + + /*! + * \brief Sets the value of the given field in the config file. + * \param name The name of the field in the config file. + * \param val The value to set the field to. + * \sa getField() + */ + virtual void setField(const QString &name, QVariant val); + + // Overrides for SettingBase stuff. + virtual QVariant getValue(const QString &name, QVariant defVal = QVariant()) const + { return settings->getValue(name, defVal); } + virtual void setValue(const QString &name, QVariant val) + { setField(name, val); } + + INIFile config; + +private: + QString m_group; +}; + +#endif // INSTANCE_H diff --git a/data/inst/instancelist.cpp b/data/inst/instancelist.cpp new file mode 100644 index 00000000..62367ed6 --- /dev/null +++ b/data/inst/instancelist.cpp @@ -0,0 +1,23 @@ +/* Copyright 2013 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "instancelist.h" + +#include "data/siglist_impl.h" + +InstanceList::InstanceList(QObject *parent) : + QObject(parent) +{ +} diff --git a/data/inst/instancelist.h b/data/inst/instancelist.h new file mode 100644 index 00000000..72dec5f0 --- /dev/null +++ b/data/inst/instancelist.h @@ -0,0 +1,39 @@ +/* Copyright 2013 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef INSTANCELIST_H +#define INSTANCELIST_H + +#include + +#include + +#include "data/siglist.h" + +class Instance; + +class InstanceList : public QObject, SigList> +{ + Q_OBJECT +public: + explicit InstanceList(QObject *parent = 0); + +signals: + +public slots: + +}; + +#endif // INSTANCELIST_H diff --git a/data/instancebase.cpp b/data/instancebase.cpp deleted file mode 100644 index a5ef35a2..00000000 --- a/data/instancebase.cpp +++ /dev/null @@ -1,109 +0,0 @@ -/* Copyright 2013 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "instancebase.h" - -#include -#include - -#include "../util/pathutils.h" - -InstanceBase::InstanceBase(QString dir, QObject *parent) : - QObject(parent), - rootDir(dir) -{ - QFileInfo cfgFile(PathCombine(rootDir, "instance.cfg")); - - if (cfgFile.exists()) - { - if(!config.loadFile(cfgFile.absoluteFilePath())) - { - QString debugmsg("Can't load instance config file for instance "); - debugmsg+= getInstID(); - qDebug(debugmsg.toLocal8Bit()); - } - } - else - { - QString debugmsg("Can't find instance config file for instance "); - debugmsg+= getInstID(); - debugmsg += " : "; - debugmsg += - debugmsg+=" ... is this an instance even?"; - qDebug(debugmsg.toLocal8Bit()); - } - currentGroup = nullptr; -} - -QString InstanceBase::getRootDir() const -{ - return rootDir; -} - - -///////////// Config Values ///////////// - -// Name -QString InstanceBase::getInstName() const -{ - return config.get("name", "Unnamed").toString(); -} - -void InstanceBase::setInstName(QString name) -{ - config.set("name", name); -} - -QString InstanceBase::getInstID() const -{ - return QDir(rootDir).dirName(); -} - -InstanceModelItem* InstanceBase::getParent() const -{ - return currentGroup; -} - -QVariant InstanceBase::data ( int role ) const -{ - switch(role) - { - case Qt::DisplayRole: - return getInstName(); - default: - return QVariant(); - } -} -int InstanceBase::getRow() const -{ - return currentGroup->getIndexOf((InstanceBase*)this); -} - -InstanceModelItem* InstanceBase::getChild ( int index ) const -{ - return nullptr; -} -InstanceModel* InstanceBase::getModel() const -{ - return currentGroup->getModel(); -} -IMI_type InstanceBase::getModelItemType() const -{ - return IMI_Instance; -} -int InstanceBase::numChildren() const -{ - return 0; -} diff --git a/data/instancebase.h b/data/instancebase.h deleted file mode 100644 index fa043c5f..00000000 --- a/data/instancebase.h +++ /dev/null @@ -1,58 +0,0 @@ -/* Copyright 2013 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef INSTANCEBASE_H -#define INSTANCEBASE_H - -#include -#include - -#include "../data/inifile.h" -#include "instancemodel.h" - -class InstanceBase : public QObject, public InstanceModelItem -{ - friend class InstanceGroup; - Q_OBJECT -public: - explicit InstanceBase(QString rootDir, QObject *parent = 0); - - QString getRootDir() const; - - QString getInstName() const; - void setInstName(QString name); - - QString getInstID() const; - - virtual IMI_type getModelItemType() const; - virtual InstanceModelItem* getParent() const; - virtual int numChildren() const; - virtual InstanceModelItem* getChild ( int index ) const; - virtual InstanceModel* getModel() const; - virtual QVariant data ( int column ) const; - virtual int getRow() const; - -private: - void setGroup ( InstanceGroup* group ) - { - currentGroup = group; - }; - - QString rootDir; - INIFile config; - InstanceGroup * currentGroup; -}; - -#endif // INSTANCEBASE_H diff --git a/data/instancemodel.h b/data/instancemodel.h index 4bd34831..9678fef0 100644 --- a/data/instancemodel.h +++ b/data/instancemodel.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef INSTANCELIST_H -#define INSTANCELIST_H +#ifndef INSTANCEMODEL_H +#define INSTANCEMODEL_H #include #include @@ -134,4 +134,4 @@ private: InstanceGroup * implicitGroup; }; -#endif // INSTANCELIST_H +#endif // INSTANCEMODEL_H diff --git a/data/siglist_imp.h b/data/siglist_imp.h deleted file mode 100644 index 16ddd9b0..00000000 --- a/data/siglist_imp.h +++ /dev/null @@ -1,156 +0,0 @@ -/* Copyright 2013 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "siglist.h" - -template -void SigList::append(const T &value) -{ - QList::append(value); - onItemAdded(value, length() - 1); -} - -template -void SigList::prepend(const T &value) -{ - QList::prepend(value); - onItemAdded(value, 0); -} - -template -void SigList::append(const QList &other) -{ - int index = length(); - QList::append(other); - onItemsAdded(other, index); -} - -template -void SigList::clear() -{ - QList::clear(); - onInvalidated(); -} - -template -void SigList::erase(QList::iterator pos) -{ - T value = *pos; - int index = indexOf(*pos); - QList::erase(pos); - onItemRemoved(value, index); -} - -template -void SigList::erase(QList::iterator first, QList::iterator last) -{ - QList removedValues; - int firstIndex = indexOf(*first); - - for (QList::iterator iter = first; iter < last; iter++) - { - removedValues << *iter; - QList::erase(iter); - } - - onItemsRemoved(removedValues, firstIndex); -} - -template -void SigList::insert(int i, const T &t) -{ - QList::insert(i, t); - onItemAdded(t, i); -} - -template -void SigList::insert(QList::iterator before, const T &t) -{ - QList::insert(before, t); - onItemAdded(t, indexOf(t)); -} - -template -void SigList::move(int from, int to) -{ - const T &item = at(from); - QList::move(from, to); - onItemMoved(item, from, to); -} - -template -int SigList::removeAll(const T &t) -{ - int retVal = QList::removeAll(t); - onInvalidated(); - return retVal; -} - -template -bool SigList::removeOne(const T &t) -{ - int index = indexOf(t); - if (QList::removeOne(t)) - { - onItemRemoved(t, index); - return true; - } - return false; -} - -template -void SigList::swap(QList &other) -{ - QList::swap(other); - onInvalidated(); -} - -template -void SigList::swap(int i, int j) -{ - const T &item1 = at(i); - const T &item2 = at(j); - QList::swap(i, j); - onItemMoved(item1, i, j); - onItemMoved(item2, j, i); -} - -template -T SigList::takeAt(int i) -{ - T val = QList::takeAt(i); - onItemRemoved(val, i); - return val; -} - -template -T SigList::takeFirst() -{ - return takeAt(0); -} - -template -T SigList::takeLast() -{ - return takeAt(length() - 1); -} - -template -QList &SigList::operator =(const QList &other) -{ - QList::operator =(other); - onInvalidated(); - return *this; -} diff --git a/data/siglist_impl.h b/data/siglist_impl.h new file mode 100644 index 00000000..16ddd9b0 --- /dev/null +++ b/data/siglist_impl.h @@ -0,0 +1,156 @@ +/* Copyright 2013 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "siglist.h" + +template +void SigList::append(const T &value) +{ + QList::append(value); + onItemAdded(value, length() - 1); +} + +template +void SigList::prepend(const T &value) +{ + QList::prepend(value); + onItemAdded(value, 0); +} + +template +void SigList::append(const QList &other) +{ + int index = length(); + QList::append(other); + onItemsAdded(other, index); +} + +template +void SigList::clear() +{ + QList::clear(); + onInvalidated(); +} + +template +void SigList::erase(QList::iterator pos) +{ + T value = *pos; + int index = indexOf(*pos); + QList::erase(pos); + onItemRemoved(value, index); +} + +template +void SigList::erase(QList::iterator first, QList::iterator last) +{ + QList removedValues; + int firstIndex = indexOf(*first); + + for (QList::iterator iter = first; iter < last; iter++) + { + removedValues << *iter; + QList::erase(iter); + } + + onItemsRemoved(removedValues, firstIndex); +} + +template +void SigList::insert(int i, const T &t) +{ + QList::insert(i, t); + onItemAdded(t, i); +} + +template +void SigList::insert(QList::iterator before, const T &t) +{ + QList::insert(before, t); + onItemAdded(t, indexOf(t)); +} + +template +void SigList::move(int from, int to) +{ + const T &item = at(from); + QList::move(from, to); + onItemMoved(item, from, to); +} + +template +int SigList::removeAll(const T &t) +{ + int retVal = QList::removeAll(t); + onInvalidated(); + return retVal; +} + +template +bool SigList::removeOne(const T &t) +{ + int index = indexOf(t); + if (QList::removeOne(t)) + { + onItemRemoved(t, index); + return true; + } + return false; +} + +template +void SigList::swap(QList &other) +{ + QList::swap(other); + onInvalidated(); +} + +template +void SigList::swap(int i, int j) +{ + const T &item1 = at(i); + const T &item2 = at(j); + QList::swap(i, j); + onItemMoved(item1, i, j); + onItemMoved(item2, j, i); +} + +template +T SigList::takeAt(int i) +{ + T val = QList::takeAt(i); + onItemRemoved(val, i); + return val; +} + +template +T SigList::takeFirst() +{ + return takeAt(0); +} + +template +T SigList::takeLast() +{ + return takeAt(length() - 1); +} + +template +QList &SigList::operator =(const QList &other) +{ + QList::operator =(other); + onInvalidated(); + return *this; +} diff --git a/data/stdinstance.cpp b/data/stdinstance.cpp deleted file mode 100644 index 4618f5ca..00000000 --- a/data/stdinstance.cpp +++ /dev/null @@ -1,22 +0,0 @@ -/* Copyright 2013 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "stdinstance.h" - -StdInstance::StdInstance(QString rootDir, QObject* parent) : - InstanceBase(rootDir, parent) -{ - -} diff --git a/data/stdinstance.h b/data/stdinstance.h deleted file mode 100644 index 79b87601..00000000 --- a/data/stdinstance.h +++ /dev/null @@ -1,28 +0,0 @@ -/* Copyright 2013 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef STDINSTANCE_H -#define STDINSTANCE_H - -#include "instancebase.h" - -// Standard client instance. -class StdInstance : public InstanceBase -{ -public: - explicit StdInstance(QString rootDir, QObject *parent = 0); -}; - -#endif // STDINSTANCE_H diff --git a/data/version/instversion.cpp b/data/version/instversion.cpp new file mode 100644 index 00000000..1493153a --- /dev/null +++ b/data/version/instversion.cpp @@ -0,0 +1,32 @@ +/* Copyright 2013 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "instversion.h" +#include "instversionlist.h" + +InstVersion::InstVersion(InstVersionList *parent) : + QObject(parent) +{ + +} + +InstVersionList *InstVersion::versionList() const +{ + // Parent should *always* be an InstVersionList + if (!parent() || !parent()->inherits("InstVersionList")) + return NULL; + else + return (InstVersionList *)parent(); +} diff --git a/data/version/instversion.h b/data/version/instversion.h new file mode 100644 index 00000000..361563fd --- /dev/null +++ b/data/version/instversion.h @@ -0,0 +1,51 @@ +/* Copyright 2013 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef INSTVERSION_H +#define INSTVERSION_H + +#include + +class InstVersionList; + +class InstVersion : public QObject +{ + Q_OBJECT +public: + // Constructs a new InstVersion with the given parent. The parent *must* + // be the InstVersionList that contains this InstVersion. The InstVersion + // should be added to the list immediately after being created as any calls + // to id() will likely fail unless the InstVersion is in a list. + explicit InstVersion(InstVersionList *parent = 0); + + // Returns this InstVersion's ID. This is usually just the InstVersion's index + // within its InstVersionList, but not always. + // If this InstVersion is not in an InstVersionList, returns -1. + virtual int id() const = 0; + + // Returns this InstVersion's name. This is displayed to the user in the GUI + // and is usually just the version number ("1.4.7"), for example. + virtual QString name() const = 0; + + // Returns this InstVersion's name. This is usually displayed to the user + // in the GUI and specifies what kind of version this is. For example: it + // could be "Snapshot", "Latest Version", "MCNostalgia", etc. + virtual QString type() const = 0; + + // Returns the version list that this InstVersion is a part of. + virtual InstVersionList *versionList() const; +}; + +#endif // INSTVERSION_H diff --git a/data/version/instversionlist.cpp b/data/version/instversionlist.cpp new file mode 100644 index 00000000..ab57f94c --- /dev/null +++ b/data/version/instversionlist.cpp @@ -0,0 +1,21 @@ +/* Copyright 2013 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "instversionlist.h" + +InstVersionList::InstVersionList() : + QObject(NULL) +{ +} diff --git a/data/version/instversionlist.h b/data/version/instversionlist.h new file mode 100644 index 00000000..f79bc1b0 --- /dev/null +++ b/data/version/instversionlist.h @@ -0,0 +1,43 @@ +/* Copyright 2013 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef INSTVERSIONLIST_H +#define INSTVERSIONLIST_H + +#include + +class InstVersion; + +// Class that each instance type's version list derives from. Version lists are +// the lists that keep track of the available game versions for that instance. +// This list will not be loaded on startup. It will be loaded when the list's +// load function is called. +class InstVersionList : public QObject +{ + Q_OBJECT +public: + explicit InstVersionList(); + + // Reloads the version list. + virtual void loadVersionList() = 0; + + // Gets the version at the given index. + virtual const InstVersion *at(int i) const = 0; + + // Returns the number of versions in the list. + virtual int count() const = 0; +}; + +#endif // INSTVERSIONLIST_H -- cgit v1.2.3