aboutsummaryrefslogtreecommitdiff
path: root/data
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2013-02-06 07:09:32 +0100
committerPetr Mrázek <peterix@gmail.com>2013-02-06 07:09:32 +0100
commit18b087e99280d2c8d5a6115a178f9e6f03606656 (patch)
treefbf58928dabbae4540de3d7725f9ac70274fa586 /data
parent4e9006769e3554524096d45f8a1ce16ccfa78bfc (diff)
parente475f5d51251ae57da0480bbadc9cb32a8bc72b2 (diff)
downloadPrismLauncher-18b087e99280d2c8d5a6115a178f9e6f03606656.tar.gz
PrismLauncher-18b087e99280d2c8d5a6115a178f9e6f03606656.tar.bz2
PrismLauncher-18b087e99280d2c8d5a6115a178f9e6f03606656.zip
Merge https://github.com/Forkk/MultiMC5
Conflicts: gui/mainwindow.ui
Diffstat (limited to 'data')
-rw-r--r--data/appsettings.cpp22
-rw-r--r--data/appsettings.h96
-rw-r--r--data/instancemodel.cpp134
-rw-r--r--data/instancemodel.h2
-rw-r--r--data/loginresponse.cpp69
-rw-r--r--data/loginresponse.h47
-rw-r--r--data/settingsmacros.h35
-rw-r--r--data/stdinstance.cpp4
-rw-r--r--data/stdinstance.h2
-rw-r--r--data/userinfo.cpp (renamed from data/settingsbase.cpp)35
-rw-r--r--data/userinfo.h (renamed from data/settingsmacrosundef.h)29
-rw-r--r--data/version.cpp46
-rw-r--r--data/version.h (renamed from data/settingsbase.h)27
13 files changed, 443 insertions, 105 deletions
diff --git a/data/appsettings.cpp b/data/appsettings.cpp
index 525def6e..1d9c4312 100644
--- a/data/appsettings.cpp
+++ b/data/appsettings.cpp
@@ -15,8 +15,26 @@
#include "appsettings.h"
-AppSettings::AppSettings(QString fileName) :
- SettingsBase(fileName)
+AppSettings* settings;
+
+SettingsBase::SettingsBase(QObject *parent) :
+ QObject(parent)
+{
+
+}
+
+AppSettings::AppSettings(QObject *parent) :
+ SettingsBase(parent)
{
}
+
+QVariant AppSettings::getValue(const QString& name, QVariant defVal) const
+{
+ return config.value(name, defVal);
+}
+
+void AppSettings::setValue(const QString& name, QVariant val)
+{
+ config.setValue(name, val);
+}
diff --git a/data/appsettings.h b/data/appsettings.h
index f8c7ff73..a9068bfd 100644
--- a/data/appsettings.h
+++ b/data/appsettings.h
@@ -16,12 +16,104 @@
#ifndef APPSETTINGS_H
#define APPSETTINGS_H
-#include "settingsbase.h"
+#include <QObject>
+#include <QSettings>
+#include <QColor>
+#include <QPoint>
+
+#include "util/apputils.h"
+#include "util/osutils.h"
+
+#if WINDOWS
+#define JPATHKEY "JavaPathWindows"
+#elif OSX
+#define JPATHKEY "JavaPathOSX"
+#else
+#define JPATHKEY "JavaPathLinux"
+#endif
+
+#define DEFINE_SETTING_ADVANCED(funcName, name, valType, defVal) \
+ virtual valType get ## funcName() const { return getValue(name, defVal).value<valType>(); } \
+ virtual void set ## funcName(valType value) { setValue(name, value); }
+
+#define DEFINE_SETTING(name, valType, defVal) \
+ DEFINE_SETTING_ADVANCED(name, STR_VAL(name), valType, defVal)
+
+#define DEFINE_OVERRIDE_SETTING(overrideName) \
+
+
+class SettingsBase : public QObject
+{
+ Q_OBJECT
+public:
+ explicit SettingsBase(QObject *parent = 0);
+
+ // Updates
+ DEFINE_SETTING(UseDevBuilds, bool, false)
+ DEFINE_SETTING(AutoUpdate, bool, true)
+
+ // Folders
+ DEFINE_SETTING(InstanceDir, QString, "instances")
+ DEFINE_SETTING(CentralModsDir, QString, "mods")
+ DEFINE_SETTING(LWJGLDir, QString, "lwjgl")
+
+ // Console
+ DEFINE_SETTING(ShowConsole, bool, true)
+ DEFINE_SETTING(AutoCloseConsole, bool, true)
+
+ // Toolbar settings
+ DEFINE_SETTING(InstanceToolbarVisible, bool, true)
+ DEFINE_SETTING(InstanceToolbarPosition, QPoint, QPoint())
+
+ // Console Colors
+ DEFINE_SETTING(SysMessageColor, QColor, QColor(Qt::blue))
+ DEFINE_SETTING(StdOutColor, QColor, QColor(Qt::black))
+ DEFINE_SETTING(StdErrColor, QColor, QColor(Qt::red))
+
+ // Window Size
+ DEFINE_SETTING(LaunchCompatMode, bool, false)
+ DEFINE_SETTING(LaunchMaximized, bool, false)
+ DEFINE_SETTING(MinecraftWinWidth, int, 854)
+ DEFINE_SETTING(MinecraftWinHeight, int, 480)
+
+ // Auto login
+ DEFINE_SETTING(AutoLogin, bool, false)
+
+ // Memory
+ DEFINE_SETTING(MinMemAlloc, int, 512)
+ DEFINE_SETTING(MaxMemAlloc, int, 1024)
+
+ // Java Settings
+ DEFINE_SETTING_ADVANCED(JavaPath, JPATHKEY, QString, "java")
+ DEFINE_SETTING(JvmArgs, QString, "")
+
+ // Custom Commands
+ 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;
+};
class AppSettings : public SettingsBase
{
+ Q_OBJECT
public:
- AppSettings(QString fileName);
+ explicit AppSettings(QObject *parent = 0);
+
+ QSettings& getConfig() { return config; }
+
+protected:
+ virtual QVariant getValue(const QString &name, QVariant defVal = QVariant()) const;
+ virtual void setValue(const QString& name, QVariant val);
+
+ QSettings config;
};
+#undef DEFINE_SETTING_ADVANCED
+#undef DEFINE_SETTING
+
+extern AppSettings* settings;
+
#endif // APPSETTINGS_H
diff --git a/data/instancemodel.cpp b/data/instancemodel.cpp
index 44d2844b..0f1e59f6 100644
--- a/data/instancemodel.cpp
+++ b/data/instancemodel.cpp
@@ -16,15 +16,18 @@
#include "instancemodel.h"
#include <QString>
+
#include <QDir>
+#include <QFile>
#include <QDirIterator>
-#include "stdinstance.h"
-
-#include "../util/pathutils.h"
+#include <QTextStream>
-#include <boost/property_tree/json_parser.hpp>
-#include <boost/foreach.hpp>
+#include <QJsonDocument>
+#include <QJsonObject>
+#include <QJsonArray>
+#include "data/stdinstance.h"
+#include "util/pathutils.h"
#define GROUP_FILE_FORMAT_VERSION 1
@@ -58,54 +61,105 @@ void InstanceGroup::addInstance ( InstanceBase* inst )
void InstanceModel::initialLoad(QString dir)
{
- groupFile = dir + "/instgroups.json";
+ groupFileName = dir + "/instgroups.json";
implicitGroup = new InstanceGroup("Ungrouped", this);
groups.append(implicitGroup);
// temporary map from instance ID to group name
QMap<QString, QString> groupMap;
- using namespace boost::property_tree;
- ptree pt;
-
- try
+ if (QFileInfo(groupFileName).exists())
{
- read_json(groupFile.toStdString(), pt);
-
- if (pt.get_optional<int>("formatVersion") != GROUP_FILE_FORMAT_VERSION)
+ QFile groupFile(groupFileName);
+
+ if (!groupFile.open(QIODevice::ReadOnly))
{
- // TODO: Discard old formats.
+ // An error occurred. Ignore it.
+ qDebug("Failed to read instance group file.");
+ goto groupParseFail;
}
-
- BOOST_FOREACH(const ptree::value_type& vp, pt.get_child("groups"))
+
+ QTextStream in(&groupFile);
+ QString jsonStr = in.readAll();
+ groupFile.close();
+
+ QJsonParseError error;
+ QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonStr.toUtf8(), &error);
+
+ if (error.error != QJsonParseError::NoError)
{
- ptree gPt = vp.second;
- QString groupName = QString::fromUtf8(vp.first.c_str());
-
- InstanceGroup *group = new InstanceGroup(groupName, this);
- groups.push_back(group);
-
- if (gPt.get_child_optional("hidden"))
- group->setHidden(gPt.get<bool>("hidden"));
-
- QVector<QString> groupInstances;
- BOOST_FOREACH(const ptree::value_type& v, gPt.get_child("instances"))
+ qWarning(QString("Failed to parse instance group file: %1 at offset %2").
+ arg(error.errorString(), QString::number(error.offset)).toUtf8());
+ goto groupParseFail;
+ }
+
+ if (!jsonDoc.isObject())
+ {
+ qWarning("Invalid group file. Root entry should be an object.");
+ goto groupParseFail;
+ }
+
+ QJsonObject rootObj = jsonDoc.object();
+
+ // Make sure the format version matches.
+ if (rootObj.value("formatVersion").toVariant().toInt() == GROUP_FILE_FORMAT_VERSION)
+ {
+ // Get the group list.
+ if (!rootObj.value("groups").isObject())
{
- QString key = QString::fromUtf8(v.second.data().c_str());
- groupMap[key] = groupName;
+ qWarning("Invalid group list JSON: 'groups' should be an object.");
+ goto groupParseFail;
+ }
+
+ // Iterate through the list.
+ QJsonObject groupList = rootObj.value("groups").toObject();
+
+ for (QJsonObject::iterator iter = groupList.begin();
+ iter != groupList.end(); iter++)
+ {
+ QString groupName = iter.key();
+
+ // If not an object, complain and skip to the next one.
+ if (!iter.value().isObject())
+ {
+ qWarning(QString("Group '%1' in the group list should "
+ "be an object.").arg(groupName).toUtf8());
+ continue;
+ }
+
+ QJsonObject groupObj = iter.value().toObject();
+
+ // Create the group object.
+ InstanceGroup *group = new InstanceGroup(groupName, this);
+ groups.push_back(group);
+
+ // If 'hidden' isn't a bool value, just assume it's false.
+ if (groupObj.value("hidden").isBool() && groupObj.value("hidden").toBool())
+ {
+ group->setHidden(groupObj.value("hidden").toBool());
+ }
+
+ if (!groupObj.value("instances").isArray())
+ {
+ qWarning(QString("Group '%1' in the group list is invalid. "
+ "It should contain an array "
+ "called 'instances'.").arg(groupName).toUtf8());
+ continue;
+ }
+
+ // Iterate through the list of instances in the group.
+ QJsonArray instancesArray = groupObj.value("instances").toArray();
+
+ for (QJsonArray::iterator iter2 = instancesArray.begin();
+ iter2 != instancesArray.end(); iter2++)
+ {
+ groupMap[(*iter2).toString()] = groupName;
+ }
}
}
}
- catch (json_parser_error e)
- {
- qDebug("Failed to read group list. JSON parser error.");
-// wxLogError(_(),
-// e.line(), wxStr(e.message()).c_str());
- }
- catch (ptree_error e)
- {
- qDebug("Failed to read group list. Unknown ptree error.");
- }
+
+groupParseFail:
qDebug("Loading instances");
QDir instDir(dir);
@@ -397,4 +451,4 @@ QVariant InstanceGroup::data ( int role ) const
default:
return QVariant();
}
-} \ No newline at end of file
+}
diff --git a/data/instancemodel.h b/data/instancemodel.h
index 7b6cb8c6..4bd34831 100644
--- a/data/instancemodel.h
+++ b/data/instancemodel.h
@@ -129,7 +129,7 @@ signals:
public slots:
private:
- QString groupFile;
+ QString groupFileName;
QVector<InstanceGroup*> groups;
InstanceGroup * implicitGroup;
};
diff --git a/data/loginresponse.cpp b/data/loginresponse.cpp
new file mode 100644
index 00000000..44bc80eb
--- /dev/null
+++ b/data/loginresponse.cpp
@@ -0,0 +1,69 @@
+/* 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 "loginresponse.h"
+
+LoginResponse::LoginResponse(const QString& username, const QString& sessionID,
+ qint64 latestVersion, QObject *parent) :
+ QObject(parent)
+{
+ this->username = username;
+ this->sessionID = sessionID;
+ this->latestVersion = latestVersion;
+}
+
+LoginResponse::LoginResponse()
+{
+ this->username = "";
+ this->sessionID = "";
+ this->latestVersion = 0;
+}
+
+LoginResponse::LoginResponse(const LoginResponse &other)
+{
+ this->username = other.getUsername();
+ this->sessionID = other.getSessionID();
+ this->latestVersion = other.getLatestVersion();
+}
+
+QString LoginResponse::getUsername() const
+{
+ return username;
+}
+
+void LoginResponse::setUsername(const QString& username)
+{
+ this->username = username;
+}
+
+QString LoginResponse::getSessionID() const
+{
+ return sessionID;
+}
+
+void LoginResponse::setSessionID(const QString& sessionID)
+{
+ this->sessionID = sessionID;
+}
+
+qint64 LoginResponse::getLatestVersion() const
+{
+ return latestVersion;
+}
+
+void LoginResponse::setLatestVersion(qint64 v)
+{
+ this->latestVersion = v;
+}
diff --git a/data/loginresponse.h b/data/loginresponse.h
new file mode 100644
index 00000000..bcb77d56
--- /dev/null
+++ b/data/loginresponse.h
@@ -0,0 +1,47 @@
+/* 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 LOGINRESPONSE_H
+#define LOGINRESPONSE_H
+
+#include <QObject>
+
+class LoginResponse : public QObject
+{
+ Q_OBJECT
+public:
+ explicit LoginResponse(const QString &username, const QString &sessionID,
+ qint64 latestVersion, QObject *parent = 0);
+ LoginResponse();
+ LoginResponse(const LoginResponse& other);
+
+ QString getUsername() const;
+ void setUsername(const QString& username);
+
+ QString getSessionID() const;
+ void setSessionID(const QString& sessionID);
+
+ qint64 getLatestVersion() const;
+ void setLatestVersion(qint64 v);
+
+private:
+ QString username;
+ QString sessionID;
+ qint64 latestVersion;
+};
+
+Q_DECLARE_METATYPE(LoginResponse)
+
+#endif // LOGINRESPONSE_H
diff --git a/data/settingsmacros.h b/data/settingsmacros.h
deleted file mode 100644
index 94e52155..00000000
--- a/data/settingsmacros.h
+++ /dev/null
@@ -1,35 +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 SETTINGSMACROS_H
-#define SETTINGSMACROS_H
-
-#define STR_VAL(val) # val
-
-#define DEFINE_SETTING(funcName, name, defVal, typeName, toFunc) \
- virtual typeName Get ## funcName() const { return value(name). ## toFunc(); } \
- virtual void Set ## funcName(typeName value) { setValue(name, value); } \
- virtual void Reset ## funcName() {
-
-#define DEFINE_SETTING_STR(name, defVal) \
- DEFINE_SETTING(name, STR_VAL(name), defVal, QString, toString)
-
-#define DEFINE_SETTING_BOOL(name, defVal) \
- DEFINE_SETTING(name, STR_VAL(name), defVal, bool, toBool)
-
-#define DEFINE_SETTING_INT(name, defVal) \
- DEFINE_SETTING(name, STR_VAL(name), defVal, int, toInt)
-
-#endif // SETTINGSMACROS_H
diff --git a/data/stdinstance.cpp b/data/stdinstance.cpp
index 1324b510..4618f5ca 100644
--- a/data/stdinstance.cpp
+++ b/data/stdinstance.cpp
@@ -15,8 +15,8 @@
#include "stdinstance.h"
-StdInstance::StdInstance(QString rootDir) :
- InstanceBase(rootDir)
+StdInstance::StdInstance(QString rootDir, QObject* parent) :
+ InstanceBase(rootDir, parent)
{
}
diff --git a/data/stdinstance.h b/data/stdinstance.h
index 59b1c8ab..79b87601 100644
--- a/data/stdinstance.h
+++ b/data/stdinstance.h
@@ -22,7 +22,7 @@
class StdInstance : public InstanceBase
{
public:
- explicit StdInstance(QString rootDir);
+ explicit StdInstance(QString rootDir, QObject *parent = 0);
};
#endif // STDINSTANCE_H
diff --git a/data/settingsbase.cpp b/data/userinfo.cpp
index 66195603..907f93a2 100644
--- a/data/settingsbase.cpp
+++ b/data/userinfo.cpp
@@ -13,10 +13,37 @@
* limitations under the License.
*/
-#include "settingsbase.h"
+#include "userinfo.h"
-SettingsBase::SettingsBase(QString fileName) :
- QSettings(fileName, QSettings::IniFormat)
+UserInfo::UserInfo(const QString &username, const QString &password, QObject *parent) :
+ QObject(parent)
{
-
+ this->username = username;
+ this->password = password;
+}
+
+UserInfo::UserInfo(const UserInfo &other)
+{
+ this->username = other.username;
+ this->password = other.password;
+}
+
+QString UserInfo::getUsername() const
+{
+ return username;
+}
+
+void UserInfo::setUsername(const QString &username)
+{
+ this->username = username;
+}
+
+QString UserInfo::getPassword() const
+{
+ return password;
+}
+
+void UserInfo::setPassword(const QString &password)
+{
+ this->password = password;
}
diff --git a/data/settingsmacrosundef.h b/data/userinfo.h
index 85b13bac..ccfc741e 100644
--- a/data/settingsmacrosundef.h
+++ b/data/userinfo.h
@@ -13,14 +13,27 @@
* limitations under the License.
*/
-#ifndef SETTINGSMACROSUNDEF_H
-#define SETTINGSMACROSUNDEF_H
+#ifndef USERINFO_H
+#define USERINFO_H
-#undef DEFINE_SETTING
-#undef DEFINE_SETTING_STR
-#undef DEFINE_SETTING_BOOL
-#undef DEFINE_SETTING_INT
+#include <QObject>
-#undef STR_VAL
+class UserInfo : public QObject
+{
+ Q_OBJECT
+public:
+ explicit UserInfo(const QString& username, const QString& password, QObject *parent = 0);
+ explicit UserInfo(const UserInfo& other);
+
+ QString getUsername() const;
+ void setUsername(const QString& username);
+
+ QString getPassword() const;
+ void setPassword(const QString& password);
+
+protected:
+ QString username;
+ QString password;
+};
-#endif // SETTINGSMACROSUNDEF_H
+#endif // USERINFO_H
diff --git a/data/version.cpp b/data/version.cpp
new file mode 100644
index 00000000..eec50e13
--- /dev/null
+++ b/data/version.cpp
@@ -0,0 +1,46 @@
+/* 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 "version.h"
+
+#include "config.h"
+
+Version Version::current(VERSION_MAJOR, VERSION_MINOR, VERSION_REVISION, VERSION_BUILD);
+
+Version::Version(int major, int minor, int revision, int build, QObject *parent) :
+ QObject(parent)
+{
+ this->major = major;
+ this->minor = minor;
+ this->revision = revision;
+ this->build = build;
+}
+
+Version::Version(const Version& ver)
+{
+ this->major = ver.major;
+ this->minor = ver.minor;
+ this->revision = ver.revision;
+ this->build = ver.build;
+}
+
+QString Version::toString() const
+{
+ return QString("%1.%2.%3.%4").arg(
+ QString::number(major),
+ QString::number(minor),
+ QString::number(revision),
+ QString::number(build));
+}
diff --git a/data/settingsbase.h b/data/version.h
index 71f0e30d..321b1680 100644
--- a/data/settingsbase.h
+++ b/data/version.h
@@ -13,21 +13,28 @@
* limitations under the License.
*/
-#ifndef SETTINGSBASE_H
-#define SETTINGSBASE_H
+#ifndef VERSION_H
+#define VERSION_H
-#include <QSettings>
+#include <QObject>
-#include "settingsmacros.h"
-
-class SettingsBase : public QSettings
+class Version : public QObject
{
+ Q_OBJECT
public:
- SettingsBase(QString fileName);
+ explicit Version(int major = 0, int minor = 0, int revision = 0,
+ int build = 0, QObject *parent = 0);
+
+ Version(const Version& ver);
+ QString toString() const;
+ int major;
+ int minor;
+ int revision;
+ int build;
+
+ static Version current;
};
-#include "settingsmacrosundef.h"
-
-#endif // SETTINGSBASE_H
+#endif // VERSION_H