Conflicts:
	gui/mainwindow.ui
This commit is contained in:
Petr Mrázek
2013-02-06 07:09:32 +01:00
42 changed files with 2112 additions and 495 deletions
+20 -2
View File
@@ -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);
}
+94 -2
View File
@@ -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
+94 -40
View File
@@ -16,15 +16,18 @@
#include "instancemodel.h"
#include <QString>
#include <QDir>
#include <QFile>
#include <QDirIterator>
#include "stdinstance.h"
#include <QTextStream>
#include "../util/pathutils.h"
#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();
}
}
}
+1 -1
View File
@@ -129,7 +129,7 @@ signals:
public slots:
private:
QString groupFile;
QString groupFileName;
QVector<InstanceGroup*> groups;
InstanceGroup * implicitGroup;
};
+69
View File
@@ -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;
}
+47
View File
@@ -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
-35
View File
@@ -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
+2 -2
View File
@@ -15,8 +15,8 @@
#include "stdinstance.h"
StdInstance::StdInstance(QString rootDir) :
InstanceBase(rootDir)
StdInstance::StdInstance(QString rootDir, QObject* parent) :
InstanceBase(rootDir, parent)
{
}
+1 -1
View File
@@ -22,7 +22,7 @@
class StdInstance : public InstanceBase
{
public:
explicit StdInstance(QString rootDir);
explicit StdInstance(QString rootDir, QObject *parent = 0);
};
#endif // STDINSTANCE_H
+31 -4
View File
@@ -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;
}
+21 -8
View File
@@ -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
+46
View File
@@ -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));
}
+17 -10
View File
@@ -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